From 48772e02a3067fb8450b98ddde5e1fed7a6ce80e Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 11 Feb 2023 11:27:51 -0800 Subject: Add -help and -version options Signed-off-by: Alan Coopersmith --- xfontsel.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'xfontsel.c') 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)); -- cgit v1.2.3