diff --git a/cli.c b/cli.c index 1b0d9b91..0b80c7bf 100644 --- a/cli.c +++ b/cli.c @@ -16,17 +16,6 @@ int cli_usage(const struct command_line_option *commands) { return 0; } -static const char * parsed_add_label_arg(struct parsed_command *parsed, const char *label, unsigned labellen, unsigned argi) -{ - if (parsed->labelc >= NELS(parsed->labelv)) - return "too many labeled args"; - parsed->labelv[parsed->labelc].label = label; - parsed->labelv[parsed->labelc].len = labellen; - parsed->labelv[parsed->labelc].argi = argi; - ++parsed->labelc; - return NULL; -} - int cli_parse(const int argc, const char *const *args, const struct command_line_option *commands, struct parsed_command *parsed) { int ambiguous = 0; @@ -40,45 +29,116 @@ int cli_parse(const int argc, const char *const *args, const struct command_line cmdpa.argc = argc; cmdpa.labelc = 0; cmdpa.varargi = -1; - const char *problem = NULL; const char *word = NULL; - int arg, opt; - for (arg = 0, opt = 0; !problem && (word = commands[cmd].words[opt]); ++opt) { - int wordlen = strlen(word); + unsigned arg = 0; + unsigned opt = 0; + while ((word = commands[cmd].words[opt])) { + //DEBUGF("cmd=%d opt=%d word='%s' args[arg=%d]='%s'", cmd, opt, word, arg, arg < argc ? args[arg] : ""); + unsigned wordlen = strlen(word); if (cmdpa.varargi != -1) - problem = "more words not allowed after \"...\""; - else if (wordlen > 4 && word[0] == '[' && word[1] == '<' && word[wordlen-2] == '>' && word[wordlen-1] == ']') { - // "[