summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2023-02-11 16:11:38 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2023-02-11 16:19:38 -0800
commita5da3e6589d6bfcdf4ed44cab0b1fac438224b60 (patch)
tree39204d70910afd32249321e8c1867df23c3a8ce5
parenta221346284192af4784a1140aef9f72e72e1167f (diff)
Add -version option
Also updates -help option to not require successfully opening a display Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--man/xmessage.man13
-rw-r--r--xmessage.c25
2 files changed, 34 insertions, 4 deletions
diff --git a/man/xmessage.man b/man/xmessage.man
index 4b6dfdc..6499d0a 100644
--- a/man/xmessage.man
+++ b/man/xmessage.man
@@ -27,6 +27,13 @@ xmessage \- display a message or query in a window (X-based /bin/echo)
]
.I message
\&.\|.\|.
+.br
+.B xmessage
+[
+.B \-help
+|
+.B \-version
+]
.SH DESCRIPTION
The
.I xmessage
@@ -101,6 +108,12 @@ Equivalent to setting the \fBnearMouse\fP resource to TRUE.
Exit with status 0 after \fIsecs\fP seconds if the user has not
clicked on a button yet.
The corresponding resource is \fBtimeout\fP.
+.TP 8
+.B \-help
+Print a usage message and exit.
+.TP 8
+.B \-version
+Print version info and exit.
.SH "WIDGET HIERARCHY"
Knowing the name and position in the hierarchy of each widget is
useful when specifying resources for them. In the following chart, the
diff --git a/xmessage.c b/xmessage.c
index a1082e6..3c8bc71 100644
--- a/xmessage.c
+++ b/xmessage.c
@@ -29,6 +29,10 @@ from the X Consortium.
*/
/* $XFree86: xc/programs/xmessage/xmessage.c,v 1.4 2000/02/17 16:53:03 dawes Exp $ */
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include <assert.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
@@ -307,6 +311,23 @@ 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) {
+ usage(stdout);
+ exit(0);
+ }
+ if (strcmp (argn, "-version") == 0) {
+ puts (PACKAGE_STRING);
+ exit (0);
+ }
+ }
+
top = XtAppInitialize (&app_con, "Xmessage",
optionList, XtNumber(optionList), &argc, argv,
fallback_resources, NULL, 0);
@@ -314,10 +335,6 @@ main (int argc, char *argv[])
XtGetApplicationResources (top, (XtPointer) &qres, resources,
XtNumber(resources), NULL, 0);
- if (argc > 1 && !strcmp(argv[1], "-help")) {
- usage(stdout);
- exit(0);
- }
if (argc == 1 && qres.file != NULL) {
message_str = read_file (qres.file, &message_len);
if (message_str == NULL) {