summaryrefslogtreecommitdiff
path: root/xlogo.c
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2023-02-11 14:17:24 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2023-02-11 14:17:24 -0800
commitd5410a70e91eb83697cbb833379298cf8d0599e3 (patch)
tree8298d34b9c8212ef3b235d2b08ca50a1c394623a /xlogo.c
parent18d485fcbce0f9f587b683756ee3fe78d7fd3372 (diff)
Add -help and -version optionsHEADmaster
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'xlogo.c')
-rw-r--r--xlogo.c38
1 files changed, 30 insertions, 8 deletions
diff --git a/xlogo.c b/xlogo.c
index 62bc2a3..91158fd 100644
--- a/xlogo.c
+++ b/xlogo.c
@@ -135,12 +135,11 @@ save(Widget w, XtPointer client_data, XtPointer call_data)
*/
static void
-Syntax(Widget toplevel, String message)
+Syntax(Widget toplevel, String message, int exitval)
{
- Arg arg;
SmcConn connection;
String reasons[10];
- int i, n = 0;
+ int n = 0;
if (message)
reasons[n++] = message;
@@ -157,15 +156,22 @@ Syntax(Widget toplevel, String message)
reasons[n++] = " [-shape]\n\n";
assert(n <= XtNumber(reasons));
- XtSetArg(arg, XtNconnection, &connection);
- XtGetValues(toplevel, &arg, (Cardinal)1);
+ if (toplevel != NULL) {
+ Arg arg;
+
+ XtSetArg(arg, XtNconnection, &connection);
+ XtGetValues(toplevel, &arg, (Cardinal)1);
+ }
+ else
+ connection = NULL;
+
if (connection)
SmcCloseConnection(connection, n, (char **) reasons);
else {
- for (i=0; i < n; i++)
+ for (int i = 0; i < n; i++)
printf("%s", reasons[i]);
}
- exit(EXIT_FAILURE);
+ exit(exitval);
}
int
@@ -176,6 +182,22 @@ main(int argc, char *argv[])
ProgramName = 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(NULL, NULL, EXIT_SUCCESS);
+ }
+ if (strcmp(argn, "-version") == 0) {
+ puts(PACKAGE_STRING);
+ exit(EXIT_SUCCESS);
+ }
+ }
+
toplevel = XtOpenApplication(&app_con, "XLogo",
options, XtNumber(options),
&argc, argv, fallback_resources,
@@ -196,7 +218,7 @@ main(int argc, char *argv[])
}
strlcat(message, "\n\n", len);
}
- Syntax(toplevel, message);
+ Syntax(toplevel, message, EXIT_FAILURE);
}
XtGetApplicationResources(toplevel, (XtPointer)&userOptions, resources,