summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2023-02-09 18:14:53 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2023-02-09 18:14:53 -0800
commitebdc1504bc0be8c53a148934d0c50cb21f9373b1 (patch)
treee51adcaa0fcb5400d6333642aa799c37b030cf03
parent6c0e96db7bc9ac9052154430fe726c96745fa387 (diff)
Add -help and -version optionsHEADmaster
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--man/viewres.man6
-rw-r--r--viewres.c28
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 <stdio.h>
#include <stdlib.h>
#include <X11/StringDefs.h>
@@ -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,