summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2023-02-05 09:48:05 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2023-02-05 10:07:52 -0800
commit2f5f53c0d9c7114231de026f772cdfc877d61e49 (patch)
tree86640ebb8df5e2421410d96e26ccf938162771d2
parent851c85cba5ec8c0e59fba3aebed7c91e5711431b (diff)
Add -help option and usage message when unknown options are given
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--man/xconsole.man3
-rw-r--r--xconsole.c27
2 files changed, 29 insertions, 1 deletions
diff --git a/man/xconsole.man b/man/xconsole.man
index 07476c0..606d6bb 100644
--- a/man/xconsole.man
+++ b/man/xconsole.man
@@ -73,6 +73,9 @@ lines of message history instead of growing the text buffer without bound
.I count
of zero \- the default \- is treated as placing no limit on the history).
.TP 8
+.B \-help
+This option indicates that \fIxconsole\fP should print a usage message and exit.
+.TP 8
.B \-version
This option indicates that \fIxconsole\fP should print its version and exit.
.SH X DEFAULTS
diff --git a/xconsole.c b/xconsole.c
index 20cbacd..a4b3136 100644
--- a/xconsole.c
+++ b/xconsole.c
@@ -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);