From aee575262a9c70fe537bc1cda72c1b00931f87b0 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Wed, 8 Feb 2023 15:15:32 -0800 Subject: Add -help and -version options Signed-off-by: Alan Coopersmith --- listres.c | 33 ++++++++++++++++++++++++++++----- man/listres.man | 6 ++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/listres.c b/listres.c index 2b73181..7f7a0c5 100644 --- a/listres.c +++ b/listres.c @@ -29,6 +29,10 @@ in this Software without prior written authorization from the X Consortium. */ /* $XFree86: xc/programs/listres/listres.c,v 1.3 2000/02/17 14:00:32 dawes Exp $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include #include @@ -83,7 +87,7 @@ static XtResource Resources[] = { static const char *ProgramName; static void -usage (void) +usage (int exitval) { fprintf(stderr, "usage: %s [-options...]\n%s\n", ProgramName, "\nwhere options include:\n" @@ -92,8 +96,11 @@ usage (void) " -nosuper do not print superclass resources\n" " -variable show variable name instead of class name\n" " -top name object to be top of tree\n" - " -format string printf format for instance, class, type\n"); - exit (1); + " -format string printf format for instance, class, type\n" + " -help print this message and exit\n" + " -version print version info and exit\n" + ); + exit (exitval); } static void print_tree_level (register XmuWidgetNode *wn, register int level) @@ -234,6 +241,22 @@ main (int argc, char **argv) XtSetLanguageProc(NULL, (XtLanguageProc) NULL, NULL); + /* 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 (&appcon, "Listres", Options, XtNumber(Options), &argc, argv, NULL, NULL, 0); container = XtCreateWidget ("dummy", widgetClass, toplevel, NULL, ZERO); @@ -264,7 +287,7 @@ main (int argc, char **argv) } } else { fprintf(stderr, "Unknown argument: %s\n", argv[0]); - usage(); + usage(1); } } else { for (; argc > 0; argc--, argv++) { @@ -272,7 +295,7 @@ main (int argc, char **argv) if (argv[0][0] == '-') { fprintf(stderr, "Unknown argument: %s\n", argv[0]); - usage(); + usage(1); } node = XmuWnNameToNode (widget_list, nwidgets, *argv); if (!node) { diff --git a/man/listres.man b/man/listres.man index d5c6d25..ac0522f 100644 --- a/man/listres.man +++ b/man/listres.man @@ -67,6 +67,12 @@ variable name or the class name. The default is ``core''. .B \-format \fIprintf\-string\fP This option specifies the \fIprintf\fP-style format string to be used to print out the name, instance, class, and type of each resource. +.TP 8 +.B \-help +This option indicates that \fIlistres\fP should print a usage message and exit. +.TP 8 +.B \-version +This option indicates that \fIlistres\fP should print version info and exit. .SH "X DEFAULTS" To be written. .SH "SEE ALSO" -- cgit v1.2.3