From b07b6c75c4bf22603bc52703202c7044e0ac2a30 Mon Sep 17 00:00:00 2001 From: anon Date: Fri, 24 Jan 2025 11:34:15 +0100 Subject: [PATCH] handle our own flag errors --- source/error.c | 1 + source/error.h | 1 + source/opts.c | 13 +++++++++---- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/source/error.c b/source/error.c index a239220..61e6ff2 100644 --- a/source/error.c +++ b/source/error.c @@ -32,6 +32,7 @@ void errorn(int i, ...) { case E_FILE_DELETE: verror("failed to delete file '%s'", argv); break; case E_FILE_MOVE: verror("failed to move '%s' to '%s'", argv); break; case E_FORMAT: verror("directive-file format violation", argv); break; + case E_FLAG: verror("unknown flag '%c'", argv); break; default: verror("unknown error encountered; this is an illegal inner state", 0); break; } diff --git a/source/error.h b/source/error.h index 7175f5b..a493847 100644 --- a/source/error.h +++ b/source/error.h @@ -7,6 +7,7 @@ enum { E_FILE_DELETE, E_FILE_MOVE, E_FORMAT, + E_FLAG, }; extern void errorn(int i, ...); diff --git a/source/opts.c b/source/opts.c index e7d2f45..27d67f5 100644 --- a/source/opts.c +++ b/source/opts.c @@ -5,9 +5,11 @@ #include #include #include "global.h" +#include "error.h" #include "dictate.h" -void usage() { +static +void usage(void) { dictate( "$B$gvimdir$0 $y[$boptions$y] <$bpath$y>$0\n" " $B$g-h$0 : print help\n" @@ -44,6 +46,9 @@ void get_env(void) { void parse_args(int argc, char * * argv) { int opt; + + opterr = 0; // suppress default getopt error messages + while ((opt = getopt(argc, argv, "hnpor")) != -1) { switch (opt) { case 'h': { @@ -62,11 +67,11 @@ void parse_args(int argc, char * * argv) { case 'r': { is_recursive = true; } break; - default: { - fprintf(stderr, "Unknown option: -%c\n", optopt); + case '?': { + errorn(E_FLAG, optopt); usage(); exit(1); - } break; + } } }