summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2023-02-09 18:30:48 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2023-02-09 18:31:32 -0800
commit5c1b311c8672f0dcbb7824a205f6b9c0a07584be (patch)
tree2b6a66bef520257c12f8bc275a98e2da29278120
parent1293789eca465dfec7c5874b65cafb70c4f90125 (diff)
Add -help and -version options
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--man/xditview.man6
-rw-r--r--xditview.c24
2 files changed, 26 insertions, 4 deletions
diff --git a/man/xditview.man b/man/xditview.man
index 14f410a..6705919 100644
--- a/man/xditview.man
+++ b/man/xditview.man
@@ -49,6 +49,12 @@ the server to save the window contents so that when it is scrolled around the
viewport, the window is painted from contents saved in backing store.
\fIbacking-store-type\fP can be one of \fBAlways\fP, \fPWhenMapped\fP or
\fPNotUseful\fP.
+.TP 8
+.B \-help
+This option indicates that \fIxditview\fP should print a usage message and exit.
+.TP 8
+.B \-version
+This option indicates that \fIxditview\fP should print version info and exit.
.PP
The following standard X Toolkit command line arguments are commonly used with
.I xditview:
diff --git a/xditview.c b/xditview.c
index 483a587..7e408da 100644
--- a/xditview.c
+++ b/xditview.c
@@ -83,14 +83,14 @@ static void MakePrompt(Widget, const char *, void (*)(char *), char *);
*/
static void
-Syntax(const char *call)
+Syntax(const char *call, int exitval)
{
(void) printf("Usage: %s [-fg <color>] [-bg <color>]\n%s\n", call,
- " [-bd <color>] [-bw <pixels>] [-help]\n"
+ " [-bd <color>] [-bw <pixels>] [-help] [-version]\n"
" [-display displayname] [-geometry geom]\n"
" [-page <page-number>] [-backing <backing-store>]\n"
" [-resolution <screen-resolution>]\n");
- exit(1);
+ exit(exitval);
}
static void NewResolution(char *resString);
@@ -167,6 +167,22 @@ 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) {
+ Syntax(argv[0], 0);
+ }
+ if (strcmp(argn, "-version") == 0) {
+ puts(PACKAGE_STRING);
+ exit(0);
+ }
+ }
+
toplevel = XtAppInitialize(&xtcontext, "Xditview",
options, XtNumber(options),
&argc, argv, NULL, NULL, 0);
@@ -178,7 +194,7 @@ main(int argc, char **argv)
}
}
fputs("\n\n", stderr);
- Syntax(argv[0]);
+ Syntax(argv[0], 1);
}
XtAppAddActions(xtcontext, xditview_actions, XtNumber(xditview_actions));