diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2023-02-09 18:30:48 -0800 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2023-02-09 18:31:32 -0800 |
commit | 5c1b311c8672f0dcbb7824a205f6b9c0a07584be (patch) | |
tree | 2b6a66bef520257c12f8bc275a98e2da29278120 /xditview.c | |
parent | 1293789eca465dfec7c5874b65cafb70c4f90125 (diff) |
Add -help and -version options
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'xditview.c')
-rw-r--r-- | xditview.c | 24 |
1 files changed, 20 insertions, 4 deletions
@@ -83,14 +83,14 @@ static void MakePrompt(Widget, const char *, void (*)(char *), char *); */ static void -Syntax(const char *call) +Syntax(const char *call, int exitval) { (void) printf("Usage: %s [-fg <color>] [-bg <color>]\n%s\n", call, - " [-bd <color>] [-bw <pixels>] [-help]\n" + " [-bd <color>] [-bw <pixels>] [-help] [-version]\n" " [-display displayname] [-geometry geom]\n" " [-page <page-number>] [-backing <backing-store>]\n" " [-resolution <screen-resolution>]\n"); - exit(1); + exit(exitval); } static void NewResolution(char *resString); @@ -167,6 +167,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) { + Syntax(argv[0], 0); + } + if (strcmp(argn, "-version") == 0) { + puts(PACKAGE_STRING); + exit(0); + } + } + toplevel = XtAppInitialize(&xtcontext, "Xditview", options, XtNumber(options), &argc, argv, NULL, NULL, 0); @@ -178,7 +194,7 @@ main(int argc, char **argv) } } fputs("\n\n", stderr); - Syntax(argv[0]); + Syntax(argv[0], 1); } XtAppAddActions(xtcontext, xditview_actions, XtNumber(xditview_actions)); |