Sun, 05 Jul 2020 11:47:24 +0200
adds support for option terminator '--'
also adds support for option arguments within the same cmd arg
e.g. -omyoutfile does now work
dav/optparser.c | file | annotate | diff | comparison | revisions |
--- a/dav/optparser.c Sun Apr 05 11:06:34 2020 +0200 +++ b/dav/optparser.c Sun Jul 05 11:47:24 2020 +0200 @@ -53,16 +53,27 @@ char *option = NULL; char optchar = 0; + int optterminated = 0; for(int i=0;i<argc;i++) { char *arg = argv[i]; size_t len = strlen(arg); - if(len > 1 && arg[0] == '-') { + if(len == 2 && arg[0] == '-' && arg[1] == '-') { + optterminated = 1; + } else if(!optterminated && len > 1 && arg[0] == '-') { + // argument is in next arg but starts with a dash + // we assume this is not intended and consider this an error + if(option) { + fprintf(stderr, + "Missing argument for option -%c\n\n", optchar); + cmd_args_free(a); + return NULL; + } for(int c=1;c<len;c++) { - if (option) { - fprintf(stderr, - "Missing argument for option -%c\n\n", optchar); - cmd_args_free(a); - return NULL; + // argument is in the same arg + if(option) { + ucx_map_cstr_put(a->options, option, &arg[c]); + option = NULL; + break; } switch(arg[c]) {