Mercurial > ~dholland > hg > tradcpp > index.cgi
diff main.c @ 137:0816803b22d1
Improve usage reporting.
Since imake is a principal application for tradcpp and imake carefully
hides what it's doing when you run it, when rejecting an invalid
option be sure to report *what* that option is.
author | David A. Holland |
---|---|
date | Tue, 09 Jul 2013 13:43:27 -0400 |
parents | 59680a727e9d |
children | 904f7a9827e3 |
line wrap: on
line diff
--- a/main.c Tue Jul 09 13:38:43 2013 -0400 +++ b/main.c Tue Jul 09 13:43:27 2013 -0400 @@ -909,13 +909,20 @@ DEAD static void -usage(const char *argv0) +usage(const char *argv0, const char *fmt, ...) { const char *progname; + va_list ap; progname = strrchr(argv0, '/'); progname = progname == NULL ? argv0 : progname + 1; + fprintf(stderr, "%s: ", progname); + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + fprintf(stderr, "\n"); + fprintf(stderr, "Usage: %s [options] [infile [outfile]]\n", progname); fprintf(stderr, "Common options:\n"); fprintf(stderr, " -C Retain comments\n"); @@ -1023,7 +1030,7 @@ i++; continue; } - usage(argv[0]); + usage(argv[0], "Invalid option %s", argv[i]); } if (i < argc) { inputfile = argv[i++]; @@ -1032,7 +1039,7 @@ outputfile = argv[i++]; } if (i < argc) { - usage(argv[0]); + usage(argv[0], "Extra non-option argument %s", argv[i]); } mode.output_file = outputfile;