diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2023-02-05 09:48:05 -0800 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2023-02-05 10:07:52 -0800 |
commit | 2f5f53c0d9c7114231de026f772cdfc877d61e49 (patch) | |
tree | 86640ebb8df5e2421410d96e26ccf938162771d2 /xconsole.c | |
parent | 851c85cba5ec8c0e59fba3aebed7c91e5711431b (diff) |
Add -help option and usage message when unknown options are given
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'xconsole.c')
-rw-r--r-- | xconsole.c | 27 |
1 files changed, 26 insertions, 1 deletions
@@ -608,6 +608,20 @@ InsertSelection(Widget w, XtPointer client_data, Atom *selection, Atom *type, OpenConsole (); } +static void _X_NORETURN +usage(int exitval) +{ + const char *usage_message = + "usage: xconsole [-toolkitoption ...] [-file file-name] [-notify|-nonotify]\n" + " [-stripNonprint] [-daemon] [-verbose] [-exitOnFail]\n" + " [-saveLines count]\n" + " xconsole -help\n" + " xconsole -version\n"; + + fputs(usage_message, stderr); + exit(exitval); +} + int main(int argc, char *argv[]) { @@ -619,10 +633,13 @@ main(int argc, char *argv[]) /* 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 -version */ + /* 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); @@ -631,6 +648,14 @@ main(int argc, char *argv[]) top = XtInitialize ("xconsole", "XConsole", options, XtNumber (options), &argc, argv); + if (argc != 1) { + fputs("Unknown argument(s):", stderr); + for (int n = 1; n < argc; n++) { + fprintf(stderr, " %s", argv[n]); + } + fputs("\n\n", stderr); + usage(1); + } XtGetApplicationResources (top, (XtPointer)&app_resources, resources, XtNumber (resources), NULL, 0); |