summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2023-02-11 11:27:51 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2023-02-11 11:27:51 -0800
commit48772e02a3067fb8450b98ddde5e1fed7a6ce80e (patch)
treecd5409ad5c72bac22ae52d4b896e1abb5c7779c3
parente7c9e106e65767598b786804dc7324adc50d7efc (diff)
Add -help and -version options
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--man/xfontsel.man18
-rw-r--r--xfontsel.c22
2 files changed, 30 insertions, 10 deletions
diff --git a/man/xfontsel.man b/man/xfontsel.man
index 8abe62f..9084479 100644
--- a/man/xfontsel.man
+++ b/man/xfontsel.man
@@ -42,13 +42,11 @@
xfontsel \- point and click selection of X11 font names
.SH SYNTAX
.PP
-\fBxfontsel\fP [-\fItoolkitoption\fP ...]
-[\fB-pattern \fIfontname\fP]
-[\fB-print\fP]
-[\fB-sample \fItext\fP]
-[\fB-sample16 \fItext16\fP]
-[\fB-sampleUCS \fItextUCS\fP]
-[\fB-scaled\fP]
+.nf
+\fBxfontsel\fP [-\fItoolkitoption\fP ...] [\fB-help\fP] [\fB-pattern\fP \fIfontname\fP] [\fB-print\fP]
+ [\fB-sample\fP \fItext\fP] [\fB-sample16\fP \fItext16\fP] [\fB-sampleUCS\fP \fItextUCS\fP]
+ [\fB-scaled\fP] [\fB-version\fP]
+.fi
.PP
.SH DESCRIPTION
.PP
@@ -85,6 +83,12 @@ CHARSET_REGISTRY of ISO10646, overriding the default.
The \fB-scaled\fP option enables the ability to select scaled fonts
at arbitrary pixel or point sizes.
.PP
+The \fB\-help\fP option specifies that \fIxfontsel\fP should
+print a usage message and exit.
+.PP
+The \fB\-version\fP option specifies that \fIxfontsel\fP should
+print version info and exit.
+.PP
.SH INTERACTIONS
.PP
Clicking any pointer button in one of the XLFD field names will pop up
diff --git a/xfontsel.c b/xfontsel.c
index 653d532..400eb09 100644
--- a/xfontsel.c
+++ b/xfontsel.c
@@ -187,7 +187,7 @@ static XrmOptionDescRec options[] = {
{"-scaled", "scaledFonts", XrmoptionNoArg, "True"},
};
-static void Syntax(const char *call)
+static void Syntax(const char *call, int exitval)
{
fprintf (stderr, "usage: %s [-options ...] -fn font\n\n%s\n", call,
gettext(
@@ -201,7 +201,7 @@ static void Syntax(const char *call)
" -sampleUCS string sample text to use for ISO10646 fonts\n"
" -scaled use scaled instances of fonts\n"
"plus any standard toolkit options\n"));
- exit (1);
+ exit (exitval);
}
@@ -297,6 +297,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(&appCtx, "XFontSel", options, XtNumber(options),
&argc, argv, NULL, NULL, 0);
@@ -325,7 +341,7 @@ main(int argc, char **argv)
fprintf(stderr, " %s", argv[n]);
}
fputs("\n\n", stderr);
- Syntax(argv[0]);
+ Syntax(argv[0], 1);
}
XtAppAddActions(appCtx, xfontsel_actions, XtNumber(xfontsel_actions));