diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2023-02-11 16:33:50 -0800 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2023-02-11 16:33:50 -0800 |
commit | ef6cc7ce80c9ba3ff24bfd7b2374fb014efec279 (patch) | |
tree | fd70eb2613eb1197a68bbb9af59b52307e504ae3 | |
parent | c3f4b549c080a400f2fd2cb8daa8702f7f287e21 (diff) |
Add -help and -version options
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r-- | init.c | 28 | ||||
-rw-r--r-- | man/xmh.man | 7 |
2 files changed, 29 insertions, 6 deletions
@@ -173,11 +173,13 @@ static XrmOptionDescRec table[] = { }; /* Tell the user how to use this program. */ -static void Syntax(char *call) +static void Syntax(const char *call, int exitval) { - (void) fprintf(stderr, "usage: %s [-path <path>] [-initial <folder>]\n", - call); - exit(2); + fprintf(stderr, + "usage: %s [-path <path>] [-initial <folder>] [toolkit options]\n" + " %s [-help|-version]\n", + call, call); + exit(exitval); } @@ -368,6 +370,22 @@ void InitializeWorld(int argc, char **argv) if (ptr) progName = ptr + 1; else progName = argv[0]; + /* 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(progName, 0); + } + if (strcmp(argn, "-version") == 0) { + puts(PACKAGE_STRING); + exit(0); + } + } + shell_args[2].value = (XtArgVal)environ; toplevel = XtOpenApplication(&app, "Xmh", table, XtNumber(table), &argc, argv, FallbackResources, @@ -379,7 +397,7 @@ void InitializeWorld(int argc, char **argv) fprintf(stderr, " %s", argv[n]); } fputs("\n\n", stderr); - Syntax(progName); + Syntax(progName, 2); } XSetIOErrorHandler(_IOErrorHandler); diff --git a/man/xmh.man b/man/xmh.man index a87cd59..ef26eef 100644 --- a/man/xmh.man +++ b/man/xmh.man @@ -74,7 +74,12 @@ These three options have corresponding application-specific resources, can be specified in a resource file. .PP The standard toolkit command line options are given in \fIX(__miscmansuffix__)\fP. - +.TP 8 +.B \-help +This option indicates that \fIxmh\fP should print a usage message and exit. +.TP 8 +.B \-version +This option indicates that \fIxmh\fP should print version info and exit. .SH INSTALLATION .PP \fIxmh\fR requires that the user is already set up |