summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2023-02-08 16:27:53 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2023-02-08 16:31:23 -0800
commitc6b5813f7258bbccc8368fcdc0e1ba94219a7843 (patch)
tree41d91678d77dc50e277ec86408f8723272225f6c
parente43205f548795c2cab5c1f92ca839b72d25f2a10 (diff)
Add -help and -version options
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--man/oclock.man6
-rw-r--r--oclock.c28
2 files changed, 29 insertions, 5 deletions
diff --git a/man/oclock.man b/man/oclock.man
index bfe8ebb..2213d88 100644
--- a/man/oclock.man
+++ b/man/oclock.man
@@ -75,6 +75,12 @@ fit the outline of the clock.
.TP 8
.B \-transparent
causes the clock to consist only of the jewel, the hands, and the border.
+.TP 8
+.B \-help
+prints a usage message and exits.
+.TP 8
+.B \-version
+prints version info and exits.
.SH COLORS
If you would like your clock to be viewable in color, include the following
in the #ifdef COLOR section you read with xrdb:
diff --git a/oclock.c b/oclock.c
index b9273ba..2a436b1 100644
--- a/oclock.c
+++ b/oclock.c
@@ -46,7 +46,7 @@ in this Software without prior written authorization from The Open Group.
static void die ( Widget w, XtPointer client_data, XtPointer call_data );
static void save ( Widget w, XtPointer client_data, XtPointer call_data );
-static void usage ( void );
+static void usage ( int exitval );
static void quit ( Widget w, XEvent *event, String *params,
Cardinal *num_params );
@@ -70,7 +70,7 @@ static void save(Widget w, XtPointer client_data, XtPointer call_data)
/* Exit with message describing command line format */
-static void usage(void)
+static void usage(int exitval)
{
fprintf(stderr,
"usage: oclock\n"
@@ -78,8 +78,10 @@ static void usage(void)
" [-display [{host}]:[{vs}]]\n"
" [-fg {color}] [-bg {color}] [-bd {color}] [-bw {pixels}]\n"
" [-minute {color}] [-hour {color}] [-jewel {color}]\n"
-" [-backing {backing-store}] [-shape] [-noshape] [-transparent]\n");
- exit(1);
+" [-backing {backing-store}] [-shape] [-noshape] [-transparent]\n"
+" [-help] [-version]\n"
+ );
+ exit(exitval);
}
/* Command line options table. Only resources are entered here...there is a
@@ -107,6 +109,22 @@ main(int argc, char *argv[])
Arg arg[2];
int i;
+ /* Handle args that don't require opening a display */
+ for (int n = 1; n < argc; n++) {
+ const char *argn = argv[n];
+ /* accept single or double dash for -help & -version */
+ if (argn[0] == '-' && argn[1] == '-') {
+ argn++;
+ }
+ if (strcmp(argn, "-help") == 0) {
+ usage(0);
+ }
+ if (strcmp(argn, "-version") == 0) {
+ puts(PACKAGE_STRING);
+ exit(0);
+ }
+ }
+
toplevel = XtOpenApplication(&xtcontext, "Clock",
options, XtNumber(options), &argc, argv, NULL,
sessionShellWidgetClass, NULL, 0);
@@ -116,7 +134,7 @@ main(int argc, char *argv[])
fprintf(stderr, " %s", argv[n]);
}
fputs("\n\n", stderr);
- usage();
+ usage(1);
}
XtAddCallback(toplevel, XtNsaveCallback, save, NULL);
XtAddCallback(toplevel, XtNdieCallback, die, NULL);