From 7825f39cb7d6e1cbfe7fe86efc23e19148253149 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 11 Feb 2023 10:44:16 -0800 Subject: Add -help and -version options Signed-off-by: Alan Coopersmith --- xfd.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'xfd.c') 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 -- cgit v1.2.3