From ceb07d961981f1e553bb6ab0f6145c2aa84f9f5e Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Sat, 22 Nov 2025 02:33:29 -0500 Subject: Get rid of dup error messages for invalid getopt() options. --- TODO.txt | 5 ----- src/opts.c | 5 ++++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/TODO.txt b/TODO.txt index 33f810c..617c2b8 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,8 +1,3 @@ -- fix dup message for bad opts: - $ ./unalf -X - ./unalf: invalid option -- 'X' - unalf: fatal: invalid option (try -h or --help) - - include some of Alfred's email commentary in the doc dir. - create some alf archives and hexedit them to introduce errors, make diff --git a/src/opts.c b/src/opts.c index 72f5ce0..58a13c2 100644 --- a/src/opts.c +++ b/src/opts.c @@ -29,6 +29,9 @@ void parse_opts(int argc, char * const *argv) { int opt; char **ig; + /* don't let getopt() print error message for us. */ + opterr = 0; + while((opt = getopt(argc, argv, OPTIONS)) != -1) { switch(opt) { case 'a': opts.txtconv++; break; @@ -45,7 +48,7 @@ void parse_opts(int argc, char * const *argv) { case 'd': opts.outdir = optarg; break; case 'x': add_exclude(optarg); break; default: - fprintf(stderr, "%s: fatal: invalid option (try -h or --help)\n", self); + fprintf(stderr, "%s: fatal: invalid option '-%c' (try -h or --help)\n", self, optopt); exit(1); } } -- cgit v1.2.3