summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2023-02-11 17:33:24 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2023-02-11 17:33:24 -0800
commit4c6626a0d6a2a3615713a44c2226028e37d68ec1 (patch)
tree5da80a56307a8424c33cd3797c9dc940ae1e4ab4
parent1958a53e86c2aad0cdeb03d588d6ea1d2616c4a2 (diff)
Add -help and -version options
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--man/xsm.man11
-rw-r--r--xsm.c24
2 files changed, 30 insertions, 5 deletions
diff --git a/man/xsm.man b/man/xsm.man
index 5da459a..205c474 100644
--- a/man/xsm.man
+++ b/man/xsm.man
@@ -31,7 +31,10 @@
xsm \- X Session Manager
.SH SYNOPSIS
.B xsm
-[-display \fIdisplay\fP] [-session \fIsessionName\fP] [-verbose]
+[\fB\-display\fP \fIdisplay\fP] [\fB\-session\fP \fIsessionName\fP] [\fB-verbose\fP]
+.br
+.B xsm
+[\fB\-help\fP | \fB-verbose\fP]
.SH DESCRIPTION
.PP
\fIxsm\fP is a session manager. A session is a group of applications, each
@@ -61,6 +64,12 @@ Causes \fIxsm\fP to load the specified session, bypassing the session menu.
.TP 8
.B \-verbose
Turns on debugging information.
+.TP 8
+.B \-help
+Prints usage message and exits.
+.TP 8
+.B \-version
+Prints version info and exits.
.SH SETUP
.SS .xsession file
Using \fIxsm\fP requires a change to your \fI.xsession\fP file:
diff --git a/xsm.c b/xsm.c
index a5a152d..5adcda0 100644
--- a/xsm.c
+++ b/xsm.c
@@ -170,6 +170,8 @@ main(int argc, char *argv[])
for (i = 1; i < argc; i++)
{
+ int exit_val = EXIT_FAILURE;
+
if (argv[i][0] == '-')
{
switch (argv[i][1])
@@ -183,6 +185,13 @@ main(int argc, char *argv[])
cmd_line_display = (char *) XtNewString (argv[i]);
continue;
+ case 'h':
+ if (strcmp (argv[i], "-help") == 0) {
+ exit_val = EXIT_SUCCESS;
+ goto usage;
+ }
+ break; /* goto unrecognized argument errror */
+
case 's': /* -session */
if (++i >= argc) {
fprintf (stderr, "%s: -session requires an argument\n",
@@ -192,8 +201,14 @@ main(int argc, char *argv[])
session_name = XtNewString (argv[i]);
continue;
- case 'v': /* -verbose */
- verbose = 1;
+ case 'v':
+ if (strcmp (argv[i], "-version") == 0) {
+ puts (PACKAGE_STRING);
+ exit (0);
+ }
+ else { /* -verbose */
+ verbose = 1;
+ }
continue;
}
}
@@ -202,8 +217,9 @@ main(int argc, char *argv[])
usage:
fprintf (stderr,
- "Usage: xsm [-display display] [-session sessionName] [-verbose]\n");
- exit (1);
+ "Usage: xsm [-display display] [-session sessionName] [-verbose]\n"
+ " xsm [-help|-version]\n");
+ exit (exit_val);
}
topLevel = XtVaAppInitialize (&appContext, "XSm", NULL, 0,