From d8e95b8b949970dbeeeeba73b1bc71d7f662e5cc Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 5 Feb 2023 11:13:41 -0800 Subject: Add -help option Signed-off-by: Alan Coopersmith --- man/xcalc.man | 12 +++++++++--- xcalc.c | 21 ++++++++++++++------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/man/xcalc.man b/man/xcalc.man index e286692..cb74d9b 100644 --- a/man/xcalc.man +++ b/man/xcalc.man @@ -43,8 +43,11 @@ .SH NAME xcalc \- scientific calculator for X .SH SYNOPSIS -.B xcalc -[-stipple] [-rpn] [-\fItoolkitoption...\fP] +.nf +\fBxcalc\fP [\fB-stipple\fP] [\fB-rpn\fP] [-\fItoolkitoption...\fP] +\fBxcalc -version\fP +\fBxcalc -help\fP +.fi .SH DESCRIPTION .I xcalc is a scientific calculator desktop accessory that can emulate a TI-30 @@ -52,7 +55,7 @@ or an HP-10C. .SH OPTIONS .PP \fIxcalc\fP accepts all of the standard toolkit command line options along -with two additional options: +with these additional options: .PP .TP 8 .B \-stipple @@ -66,6 +69,9 @@ This option indicates that Reverse Polish Notation should be used. In this mode the calculator will look and behave like an HP-10C. Without this flag, it will emulate a TI-30. .TP 8 +.B \-help +This option indicates that \fIxcalc\fP should print its usage message and exit. +.TP 8 .B \-version This option indicates that \fIxcalc\fP should print its version and exit. .SH OPERATION diff --git a/xcalc.c b/xcalc.c index 34fef53..381edff 100644 --- a/xcalc.c +++ b/xcalc.c @@ -120,10 +120,13 @@ main(int argc, char **argv) /* 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 -version */ + /* accept single or double dash for -help & -version */ if (argn[0] == '-' && argn[1] == '-') { argn++; } + if (strcmp(argn, "-help") == 0) { + Syntax(1, argv); + } if (strcmp(argn, "-version") == 0) { puts(PACKAGE_STRING); exit(0); @@ -325,17 +328,21 @@ void Quit(void) */ static void Syntax(int argc, char **argv) { - fprintf(stderr, "%s: unknown options:", argv[0]); - for (int i = 1; i 1) { + fprintf(stderr, "%s: unknown options:", argv[0]); + for (int i = 1; i 1) ? 1 : 0); } /* -- cgit v1.2.3