From a5da3e6589d6bfcdf4ed44cab0b1fac438224b60 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 11 Feb 2023 16:11:38 -0800 Subject: Add -version option Also updates -help option to not require successfully opening a display Signed-off-by: Alan Coopersmith --- man/xmessage.man | 13 +++++++++++++ xmessage.c | 25 +++++++++++++++++++++---- 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 #include #include @@ -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) { -- cgit v1.2.3