summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2023-02-11 10:44:16 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2023-02-11 10:44:16 -0800
commit7825f39cb7d6e1cbfe7fe86efc23e19148253149 (patch)
treef2eb9ec40fce64f4108035563b6a12c6e8cda616
parent9079fc7a7138aaaae6a4bc99e97c8eb073875a93 (diff)
Add -help and -version optionsHEADmaster
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--man/xfd.man6
-rw-r--r--xfd.c24
2 files changed, 26 insertions, 4 deletions
diff --git a/man/xfd.man b/man/xfd.man
index 20303b9..bb2edb2 100644
--- a/man/xfd.man
+++ b/man/xfd.man
@@ -115,6 +115,12 @@ the FontGrid \fBcellRows\fP resource.
This option specifies the number of columns in the grid.
This can also be set with
the FontGrid \fBcellColumns\fP resource.
+.TP 8
+.B \-help
+This option indicates that \fIxfd\fP should print a usage message and exit.
+.TP 8
+.B \-version
+This option indicates that \fIxfd\fP should print version info and exit.
.SH WIDGETS
In order to specify resources, it is useful to know the
widgets which compose \fIxfd\fR. In the notation below, indentation
diff --git a/xfd.c b/xfd.c
index 8108d19..4a12381 100644
--- a/xfd.c
+++ b/xfd.c
@@ -70,7 +70,7 @@ static XrmOptionDescRec xfd_options[] = {
{"-columns", "*grid.cellColumns", XrmoptionSepArg, (caddr_t) NULL },
};
-static void usage(void) _X_NORETURN _X_COLD;
+static void usage(int exitval) _X_NORETURN _X_COLD;
static void SelectChar(Widget w, XtPointer closure, XtPointer data);
static void do_quit(Widget w, XEvent *event, String *params,
Cardinal *num_params) _X_NORETURN;
@@ -134,7 +134,7 @@ static XtResource Resources[] = {
#undef Offset
static void
-usage(void)
+usage(int exitval)
{
fprintf (stderr, gettext("usage: %s [-options ...] "), ProgramName);
fprintf (stderr, "-fn ");
@@ -161,7 +161,7 @@ usage(void)
fprintf (stderr, gettext("number number of rows in grid\n"));
fprintf (stderr, " -columns ");
fprintf (stderr, gettext("number number of columns in grid\n"));
- exit (1);
+ exit (exitval);
}
@@ -190,6 +190,22 @@ main(int argc, char *argv[])
ProgramName = argv[0];
+ /* 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 = XtAppInitialize (&xtcontext, "Xfd",
xfd_options, XtNumber(xfd_options),
&argc, argv, NULL, NULL, 0);
@@ -200,7 +216,7 @@ main(int argc, char *argv[])
fprintf(stderr, " %s", argv[n]);
}
fputs("\n\n", stderr);
- usage ();
+ usage (1);
}
#ifdef USE_GETTEXT