aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2025-11-22 02:33:29 -0500
committerB. Watson <urchlay@slackware.uk>2025-11-22 02:33:29 -0500
commitceb07d961981f1e553bb6ab0f6145c2aa84f9f5e (patch)
tree4660971724ffd4c5acffe2f87211ab12135cab09
parentbf5425f6ae2e3666e232d003c6a8a32b38079383 (diff)
downloadunalf-ceb07d961981f1e553bb6ab0f6145c2aa84f9f5e.tar.gz
Get rid of dup error messages for invalid getopt() options.
-rw-r--r--TODO.txt5
-rw-r--r--src/opts.c5
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);
}
}