diff options
-rw-r--r-- | xmore.c | 32 |
1 files changed, 30 insertions, 2 deletions
@@ -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, |