summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2023-02-11 16:50:24 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2023-02-11 16:50:24 -0800
commit76bf671666c5d5626287788df4e1e5ea9be7dbb2 (patch)
tree8fe2d1b48da084b8a03976425882d9cc642968b6
parent5c022b0f411e6cd7c35f2905b77fe2a1df2cd760 (diff)
Add -help and -version options
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--xmore.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/xmore.c b/xmore.c
index 4ff53f4..f2f00c4 100644
--- a/xmore.c
+++ b/xmore.c
@@ -25,6 +25,10 @@ in this Software without prior written authorization from The Open Group.
*
*/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
/* Force ANSI C prototypes from X11 headers */
#ifndef FUNCPROTO
#define FUNCPROTO 15
@@ -128,6 +132,15 @@ quitXtProc(Widget w, XtPointer client_data, XtPointer callData)
XtCallActionProc(w, "quit", NULL, NULL, 0);
}
+static void
+usage(FILE *out, int exitval)
+{
+ fprintf(out,
+ "usage: %s [ x options ] [-help|-version] filename\n",
+ ProgramName);
+ exit(exitval);
+}
+
int main( int argc, char *argv[] )
{
XtAppContext app;
@@ -138,6 +151,22 @@ int main( int argc, char *argv[] )
ProgramName = argv[0];
+ /* Handle args that don't require opening a display */
+ for (int i = 1; i < argc; i++) {
+ const char *argn = argv[i];
+ /* accept single or double dash for -help & -version */
+ if (argn[0] == '-' && argn[1] == '-') {
+ argn++;
+ }
+ if (strcmp (argn, "-help") == 0) {
+ usage(stdout, EXIT_SUCCESS);
+ }
+ if (strcmp (argn, "-version") == 0) {
+ puts(PACKAGE_STRING);
+ exit(EXIT_SUCCESS);
+ }
+ }
+
XtSetLanguageProc(NULL, NULL, NULL);
toplevel = XtOpenApplication(&app, "XMore",
options, XtNumber(options),
@@ -151,8 +180,7 @@ int main( int argc, char *argv[] )
fprintf(stderr, " %s", argv[i]);
}
fputs("\n\n", stderr);
- printf("usage: %s [ x options ] filename\n", argv[0]);
- exit(EXIT_FAILURE);
+ usage(stderr, EXIT_FAILURE);
}
XtGetApplicationResources(toplevel, (XtPointer)&userOptions, resources,