diff options
Diffstat (limited to 'fslsfonts.c')
-rw-r--r-- | fslsfonts.c | 34 |
1 files changed, 23 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]); |