diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2014-05-31 23:15:25 -0700 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2014-05-31 23:15:25 -0700 |
commit | a0b3cf16cdd208ca9b0c86631999df047cbe8817 (patch) | |
tree | 4a1470233ceaff649da7c4456ae3cc381beef4dd | |
parent | f37a5d583909db89059826cf3dcfe24e7b95164e (diff) |
Print which option was in error along with usage message
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r-- | dsimple.c | 2 | ||||
-rw-r--r-- | dsimple.h | 2 | ||||
-rw-r--r-- | xlsfonts.c | 31 |
3 files changed, 24 insertions, 11 deletions
@@ -75,7 +75,7 @@ Get_Display_Name(int *pargc/* MODIFIED */, char **argv/* MODIFIED */) char *arg = argv[i]; if (!strcmp (arg, "-display") || !strcmp (arg, "-d")) { - if (++i >= argc) usage (); + if (++i >= argc) usage ("-display requires an argument"); displayname = argv[i]; *pargc -= 2; @@ -62,7 +62,7 @@ extern int screen; /* The current screen */ void Setup_Display_And_Screen(int *, char **); void Close_Display(void); -void usage(void) _X_NORETURN; +void usage(const char *errmsg) _X_NORETURN; #define X_USAGE "[host:display]" /* X arguments handled by Get_Display_Name */ @@ -73,8 +73,11 @@ static void ComputeFontType(XFontStruct *fs); static void print_character_metrics(register XFontStruct *info); static void do_query_font (Display *dpy, char *name); -void usage(void) +void usage(const char *errmsg) { + if (errmsg != NULL) + fprintf (stderr, "%s: %s\n\n", program_name, errmsg); + fprintf (stderr, "usage: %s [-options] [-fn pattern]\n%s", program_name, "where options include:\n" " -l[l[l]] give long info about each font\n" @@ -103,7 +106,8 @@ int main(int argc, char **argv) for (argv++, argc--; argc; argv++, argc--) { if (argv[0][0] == '-') { - if (argcnt > 0) usage (); + if (argcnt > 0) + usage ("options may not be specified after font names"); for (i=1; argv[0][i]; i++) switch(argv[0][i]) { case 'l': @@ -119,19 +123,23 @@ int main(int argc, char **argv) columns = 1; break; case 'f': /* "-fn" */ - if (--argc <= 0) usage (); - if (argv[0][i+1] != 'n') usage (); + if (argv[0][i+1] != 'n') { + fprintf (stderr, "%s: unrecognized argument %s\n\n", + program_name, argv[0]); + usage(NULL); + } + if (--argc <= 0) usage ("-fn requires an argument"); argcnt++; argv++; get_list(argv[0]); goto next; case 'w': - if (--argc <= 0) usage (); + if (--argc <= 0) usage ("-w requires an argument"); argv++; max_output_line_width = atoi(argv[0]); goto next; case 'n': - if (--argc <= 0) usage (); + if (--argc <= 0) usage ("-n requires an argument"); argv++; columns = atoi(argv[0]); goto next; @@ -142,11 +150,16 @@ int main(int argc, char **argv) sort_output = False; break; default: - usage(); + fprintf (stderr, "%s: unrecognized argument -%c\n\n", + program_name, argv[0][i]); + usage(NULL); break; } - if (i == 1) - usage(); + if (i == 1) { + fprintf (stderr, "%s: unrecognized argument %s\n\n", + program_name, argv[0]); + usage(NULL); + } } else { argcnt++; get_list(argv[0]); |