diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2019-06-04 19:05:29 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2019-06-04 19:08:54 -0400 |
commit | 83abce042d02274b7de0a2d6ebddd1c56fc44fd8 (patch) | |
tree | 8b452a89da78f940a208f0f02f8ae0197f5a1055 | |
parent | 014a7e95cc003350eaa2626233dab0693c2a4382 (diff) | |
download | bfs-83abce042d02274b7de0a2d6ebddd1c56fc44fd8.tar.xz |
parse: Reject unknown search strategies
-rw-r--r-- | parse.c | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -2161,11 +2161,12 @@ static struct expr *parse_search_strategy(struct parser_state *state, int arg1, const char *flag = state->argv[0]; const char *arg = state->argv[1]; if (!arg) { - parse_error(state, "%s needs an argument.\n\n", flag); + parse_error(state, "%s needs an argument.\n", flag); return NULL; } struct cmdline *cmdline = state->cmdline; + FILE *file = stderr; if (strcmp(arg, "bfs") == 0) { cmdline->strategy = BFTW_BFS; @@ -2173,9 +2174,24 @@ static struct expr *parse_search_strategy(struct parser_state *state, int arg1, cmdline->strategy = BFTW_DFS; } else if (strcmp(arg, "ids") == 0) { cmdline->strategy = BFTW_IDS; + } else if (strcmp(arg, "help") == 0) { + state->just_info = true; + file = stdout; + goto fail_list_strategies; + } else { + goto fail_bad_strategy; } return parse_unary_flag(state); + +fail_bad_strategy: + parse_error(state, "Unrecognized search strategy '%s'.\n\n", arg); +fail_list_strategies: + fputs("Supported search strategies:\n\n", file); + fputs(" bfs: breadth-first search\n", file); + fputs(" dfs: depth-first search\n", file); + fputs(" ids: iterative deepening search\n", file); + return NULL; } /** |