summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2023-02-08 11:33:18 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2023-02-08 16:38:44 -0800
commitf48acd133b8deb7e035edc323e75df7a1c118975 (patch)
tree1dcb177f214ec0fdef15ecef867b41c03d10b67f
parent9c66a587f301a4e35b9de68bc6d7419247f0e062 (diff)
Add -help option
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--fslsfonts.c34
-rw-r--r--man/fslsfonts.man3
2 files changed, 26 insertions, 11 deletions
diff --git a/fslsfonts.c b/fslsfonts.c
index ce8f7ab..e31cd96 100644
--- a/fslsfonts.c
+++ b/fslsfonts.c
@@ -92,7 +92,7 @@ static FSServer *svr;
static char *program_name;
-static void usage (const char *msg) _X_NORETURN _X_COLD;
+static void usage (const char *msg, int exitval) _X_NORETURN _X_COLD;
static void get_list ( const char *pattern );
static int compare ( const void *f1, const void *f2 );
static void show_fonts ( void );
@@ -108,11 +108,11 @@ missing_arg (const char *option)
char msg[32];
snprintf(msg, sizeof(msg), "%s requires an argument", option);
- usage(msg);
+ usage(msg, 1);
}
static void
-usage(const char *msg)
+usage(const char *msg, int exitval)
{
if (msg)
fprintf(stderr, "%s: %s\n", program_name, msg);
@@ -126,9 +126,10 @@ usage(const char *msg)
" -w width maximum width for multiple columns\n"
" -n columns number of columns if multi column\n"
" -server servername font server to contact\n"
+ " -help print this message and exit\n"
" -version print command version and exit\n"
"\n");
- exit(1);
+ exit(exitval);
}
int
@@ -146,15 +147,26 @@ main(int argc, char *argv[])
missing_arg("-server");
servername = argv[i];
}
- else if (strcmp(argv[i], "-version") == 0) {
- printf("%s\n", PACKAGE_STRING);
- exit(0);
+ else {
+ const char *arg = argv[i];
+ /* accept single or double dash for -help & -version */
+ if (arg[0] == '-' && arg[1] == '-') {
+ arg++;
+ }
+
+ if (strcmp(arg, "-help") == 0) {
+ usage(NULL, 0);
+ }
+ else if (strcmp(arg, "-version") == 0) {
+ printf("%s\n", PACKAGE_STRING);
+ exit(0);
+ }
}
}
if ((svr = FSOpenServer(servername)) == NULL) {
if (FSServerName(servername) == NULL) {
- usage("no font server defined");
+ usage("no font server defined", 1);
}
fprintf(stderr, "%s: unable to open server \"%s\"\n",
program_name, FSServerName(servername));
@@ -164,7 +176,7 @@ main(int argc, char *argv[])
for (argv++, argc--; argc; argv++, argc--) {
if (argv[0][0] == '-') {
if (argcnt > 0)
- usage(NULL);
+ usage(NULL, 1);
for (i = 1; argv[0][i]; i++)
switch (argv[0][i]) {
case 'l':
@@ -209,10 +221,10 @@ main(int argc, char *argv[])
default:
fprintf(stderr, "%s: unrecognized option '%s'\n",
program_name, argv[0]);
- usage(NULL);
+ usage(NULL, 1);
}
if (i == 1)
- usage(NULL);
+ usage(NULL, 1);
} else {
argcnt++;
get_list(argv[0]);
diff --git a/man/fslsfonts.man b/man/fslsfonts.man
index 371d5ff..2c108ac 100644
--- a/man/fslsfonts.man
+++ b/man/fslsfonts.man
@@ -87,6 +87,9 @@ number of character specified by \fB\-w\fP \fIwidth\fP.
.B \-u
This option indicates that the output should be left unsorted.
.TP 8
+.B \-help
+This option prints a usage message and exits.
+.TP 8
.B \-version
This option prints the program version and exits.
.PP