From ebdc1504bc0be8c53a148934d0c50cb21f9373b1 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Thu, 9 Feb 2023 18:14:53 -0800 Subject: Add -help and -version options Signed-off-by: Alan Coopersmith --- man/viewres.man | 6 ++++++ viewres.c | 28 +++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/man/viewres.man b/man/viewres.man index c1fa2d2..3bab379 100644 --- a/man/viewres.man +++ b/man/viewres.man @@ -58,6 +58,12 @@ share the same name (such as \fIText\fP). .B \-vertical This option indicates that the tree should be displayed top to bottom rather left to right. +.TP 8 +.B \-help +This option indicates that \fIviewres\fP should print a usage message and exit. +.TP 8 +.B \-version +This option indicates that \fIviewres\fP should print version info and exit. .SH "VIEW MENU" The way in which the tree is displayed may be changed through the entries in the \fBView\fP menu: diff --git a/viewres.c b/viewres.c index 56ba828..4ef84d2 100644 --- a/viewres.c +++ b/viewres.c @@ -29,6 +29,10 @@ in this Software without prior written authorization from the X Consortium. */ /* $XFree86: xc/programs/viewres/viewres.c,v 1.6 2003/05/27 22:26:58 tsi Exp $ */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include #include #include @@ -100,6 +104,8 @@ static const char *help_message[] = { "-top name object to be top of tree", "-variable show variable name instead of class name", "-vertical list the tree vertically", + "-help print this message", + "-version print version info", NULL }; @@ -229,7 +235,7 @@ static Arg true_args[1] = {{ XtNstate, (XtArgVal) TRUE }}; * routines */ static void -usage(void) +usage(int exitval) { fprintf(stderr, "usage: %s [-options...]\n", ProgramName); fprintf(stderr, "\nwhere options include:\n"); @@ -237,7 +243,7 @@ usage(void) fprintf(stderr, " %s\n", *cpp); } fprintf(stderr, "\n"); - exit(1); + exit(exitval); } static XmuWidgetNode * @@ -891,6 +897,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(&app_con, "Viewres", Options, XtNumber(Options), &argc, argv, (String *) fallback_resources, @@ -901,7 +923,7 @@ main(int argc, char *argv[]) fprintf(stderr, " %s", argv[n]); } fputs("\n\n", stderr); - usage(); + usage(1); } initialize_widgetnode_list(&selected_list.elements, -- cgit v1.2.3