Mercurial > ~dholland > hg > tradcpp > index.cgi
changeset 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 | 85b66cc0344e |
files | CHANGES main.c |
diffstat | 2 files changed, 13 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/CHANGES Tue Jul 09 13:38:43 2013 -0400 +++ b/CHANGES Tue Jul 09 13:43:27 2013 -0400 @@ -1,6 +1,9 @@ pending - Don't leak memory and assert if a bad command-line option comes after a -D or a -include foo. + - 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. release 0.3 (20130616) - Don't eval the control expression of the first #if of a block when
--- 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;