native_posix: command line parsing fix

Until now, command line options switches which matched the
begining of other options with argumentes needed to be listed
after those. After this fix this is not neccessary anymore.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
This commit is contained in:
Alberto Escolar Piedras 2018-07-15 15:12:07 +02:00 committed by Anas Nashif
parent 362e5ddb6b
commit ba45d54bf9

View file

@ -39,32 +39,35 @@ int cmd_is_option(const char *arg, const char *option, int with_value)
of++;
}
if (strncmp(&arg[of], option, to_match_len) != 0) {
return 0;
}
of += to_match_len;
if (with_value) {
if ((arg[of] == ':') || (arg[of] == '=')) {
of++;
if (arg[of] == 0) { /* we need a value to follow */
of = 0;
}
if (!with_value) {
if (strcmp(&arg[of], option) != 0) {
return 0;
} else {
of = 0;
}
} else {
if (arg[of] != 0) { /* we don't accept any extra characters */
of = 0;
return of + to_match_len;
}
}
if (of == 0) {
posix_print_error_and_exit("Incorrect option syntax '%s'. Run "
"with --help for more information\n",
while (!(arg[of] == 0 && *option == 0)) {
if (*option == 0) {
if ((arg[of] == ':') || (arg[of] == '=')) {
of++;
break;
}
return 0;
}
if (arg[of] != *option) {
return 0;
}
of++;
option++;
}
if (arg[of] == 0) { /* we need a value to follow */
posix_print_error_and_exit("Incorrect option syntax '%s'. The "
"value should follow the options. "
"For example --ratio=3\n",
arg);
}
return of;
}
@ -165,8 +168,8 @@ void cmd_read_option_value(const char *str, void *dest, const char type,
}
if (error) {
posix_print_error_and_exit("Error reading value %s '%s'. Use "
"--help for usage information\n",
posix_print_error_and_exit("Error reading value of %s '%s'. Use"
" --help for usage information\n",
option, str);
}
}
@ -367,7 +370,7 @@ static void cmd_handle_this_matched_arg(char *argv, int offset,
cmd_read_option_value(&argv[offset],
arg_element->dest,
arg_element->type,
arg_element->name);
arg_element->option);
}
}
@ -397,7 +400,7 @@ bool cmd_parse_one_arg(char *argv, struct args_struct_t args_struct[])
continue;
}
ret = cmd_is_option(argv, args_struct[count].option,
!args_struct[count].is_switch);
!args_struct[count].is_switch);
if (ret) {
cmd_handle_this_matched_arg(argv,
ret,