From 77db999d354a18b7a068224bed2c1b5777df0648 Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Wed, 1 Oct 2025 09:42:52 +0200 Subject: [PATCH] process_options(): better error report if giving non existent short option(s) --- src/options.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/options.c b/src/options.c index e5038cee..fe701b51 100644 --- a/src/options.c +++ b/src/options.c @@ -24,8 +24,9 @@ #define SHORT 1 #define LONG 2 -static void check_opt(char *opt, char *optval, int type) +static int check_opt(char *opt, char *optval, int type) { + int valid = 1; if( (type == SHORT && *opt == 'd') || (type == LONG && !strcmp("debug", opt)) ) { if(optval) debug_var = atoi(optval); else debug_var = 0; @@ -179,7 +180,9 @@ static void check_opt(char *opt, char *optval, int type) has_x = 0; } else { fprintf(errfp, "Unknown option: %s\n", opt); + valid = 0; } + return valid; } int process_options(int argc, char *argv[]) @@ -258,7 +261,7 @@ int process_options(int argc, char *argv[]) else if(*opt == 'o') { optval = argv[++i]; } - check_opt(opt, optval, SHORT); + if(!check_opt(opt, optval, SHORT)) break; /* printf("opt: %c, value: %s\n", *opt, optval ? optval : "no value"); */ ++opt; }