This makes smatch arguments much easier to provide in Makefiles: an addition is enough to modify the behaviour of smatch. Signed-off-by: John Levon <levon@xxxxxxxxxxxxxxxxx> --- smatch.c | 80 ++++++++++++++++++++++++---------------------------------------- 1 file changed, 30 insertions(+), 50 deletions(-) diff --git a/smatch.c b/smatch.c index 8640def..bc2be4d 100644 --- a/smatch.c +++ b/smatch.c @@ -164,65 +164,49 @@ static int match_option(const char *arg, const char *option) } #define OPTION(_x) do { \ - if (!found && match_option((*argvp)[1], #_x)) { \ - found = 1; \ - option_##_x = 1; \ - (*argvp)[1] = (*argvp)[0]; \ + if (match_option((*argvp)[1], #_x)) { \ + option_##_x = 1; \ } \ } while (0) void parse_args(int *argcp, char ***argvp) { - while (*argcp >= 2) { - int found = 0; - if (!strcmp((*argvp)[1], "--help")) + int i; + + for (i = 1 ; i < *argcp; i++) { + if (!strcmp((*argvp)[i], "--help")) help(); - if (!strcmp((*argvp)[1], "--show-checks")) + if (!strcmp((*argvp)[i], "--show-checks")) show_checks(); - if (!found && !strncmp((*argvp)[1], "--project=", 10)) { - option_project_str = (*argvp)[1] + 10; - (*argvp)[1] = (*argvp)[0]; - found = 1; - } - if (!found && !strncmp((*argvp)[1], "-p=", 3)) { - option_project_str = (*argvp)[1] + 3; - (*argvp)[1] = (*argvp)[0]; - found = 1; - } - if (!found && !strncmp((*argvp)[1], "--db-file=", 10)) { - option_db_file = (*argvp)[1] + 10; - (*argvp)[1] = (*argvp)[0]; - found = 1; - } - if (!found && !strncmp((*argvp)[1], "--data=", 7)) { - option_datadir_str = (*argvp)[1] + 7; - (*argvp)[1] = (*argvp)[0]; - found = 1; - } - if (!found && !strncmp((*argvp)[1], "--debug=", 8)) { - option_debug_check = (*argvp)[1] + 8; - (*argvp)[1] = (*argvp)[0]; - found = 1; - } - if (!found && strncmp((*argvp)[1], "--trace=", 8) == 0) { - trace_variable = (*argvp)[1] + 8; - (*argvp)[1] = (*argvp)[0]; - found = 1; - } - if (!found && strncmp((*argvp)[1], "--enable=", 9) == 0) { - enable_disable_checks((*argvp)[1] + 9, 1); + if (!strncmp((*argvp)[i], "--project=", 10)) + option_project_str = (*argvp)[i] + 10; + + if (!strncmp((*argvp)[i], "-p=", 3)) + option_project_str = (*argvp)[i] + 3; + + if (!strncmp((*argvp)[i], "--db-file=", 10)) + option_db_file = (*argvp)[i] + 10; + + if (!strncmp((*argvp)[i], "--data=", 7)) + option_datadir_str = (*argvp)[i] + 7; + + if (!strncmp((*argvp)[i], "--debug=", 8)) + option_debug_check = (*argvp)[i] + 8; + + if (strncmp((*argvp)[i], "--trace=", 8) == 0) + trace_variable = (*argvp)[i] + 8; + + if (strncmp((*argvp)[i], "--enable=", 9) == 0) { + enable_disable_checks((*argvp)[i] + 9, 1); option_enable = 1; - (*argvp)[1] = (*argvp)[0]; - found = 1; } - if (!found && strncmp((*argvp)[1], "--disable=", 10) == 0) { - enable_disable_checks((*argvp)[1] + 10, 0); + + if (strncmp((*argvp)[i], "--disable=", 10) == 0) { + enable_disable_checks((*argvp)[i] + 10, 0); option_enable = 1; option_disable = 1; - (*argvp)[1] = (*argvp)[0]; - found = 1; } OPTION(spammy); @@ -240,10 +224,6 @@ void parse_args(int *argcp, char ***argvp) OPTION(time); OPTION(mem); OPTION(no_db); - if (!found) - break; - (*argcp)--; - (*argvp)++; } if (strcmp(option_project_str, "smatch_generic") != 0) -- 1.8.3.1