summaryrefslogtreecommitdiff
path: root/xlsfonts.c
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2014-05-31 23:15:25 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2014-05-31 23:15:25 -0700
commita0b3cf16cdd208ca9b0c86631999df047cbe8817 (patch)
tree4a1470233ceaff649da7c4456ae3cc381beef4dd /xlsfonts.c
parentf37a5d583909db89059826cf3dcfe24e7b95164e (diff)
Print which option was in error along with usage message
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'xlsfonts.c')
-rw-r--r--xlsfonts.c31
1 files changed, 22 insertions, 9 deletions
diff --git a/xlsfonts.c b/xlsfonts.c
index e262cb6..0f45450 100644
--- a/xlsfonts.c
+++ b/xlsfonts.c
@@ -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]);