diff options
-rw-r--r-- | man/xcalc.man | 12 | ||||
-rw-r--r-- | 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 @@ -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 <argc; i++) - fprintf(stderr, " %s", argv[i]); - fprintf(stderr, "\n\n"); + if (argc > 1) { + fprintf(stderr, "%s: unknown options:", argv[0]); + for (int i = 1; i <argc; i++) + fprintf(stderr, " %s", argv[i]); + fprintf(stderr, "\n\n"); + } fprintf(stderr, "Usage: %s", argv[0]); for (Cardinal i = 0; i < XtNumber(Options); i++) fprintf(stderr, " [%s]", Options[i].option); fprintf(stderr, "\n"); + fprintf(stderr, " %s -help\n", argv[0]); fprintf(stderr, " %s -version\n", argv[0]); - XtDestroyApplicationContext(xtcontext); - exit(1); + if (xtcontext != NULL) + XtDestroyApplicationContext(xtcontext); + exit((argc > 1) ? 1 : 0); } /* |