hush: support "pattern1|pattern2...)" in case statements

parse_stream                                        1847    1861     +14
run_list                                            1995    2006     +11
This commit is contained in:
Denis Vlasenko 2008-07-31 00:17:01 +00:00
parent 20be63fe71
commit fbeeb328b8

View File

@ -2202,17 +2202,23 @@ static int run_list(struct pipe *pi)
continue; continue;
} }
if (rword == RES_MATCH) { if (rword == RES_MATCH) {
char *pattern; char **argv;
if (!case_word) /* "case ... matched_word) ... WORD)": we executed selected branch, stop */ if (!case_word) /* "case ... matched_word) ... WORD)": we executed selected branch, stop */
break; break;
/* all prev words didn't match, does this one match? */ /* all prev words didn't match, does this one match? */
pattern = expand_strvec_to_string(pi->progs->argv); argv = pi->progs->argv;
/* TODO: which FNM_xxx flags to use? */ while (*argv) {
cond_code = (fnmatch(pattern, case_word, /*flags:*/ 0) != 0); char *pattern = expand_string_to_string(*argv);
free(pattern); /* TODO: which FNM_xxx flags to use? */
if (cond_code == 0) { /* match! we will execute this branch */ cond_code = (fnmatch(pattern, case_word, /*flags:*/ 0) != 0);
free(case_word); /* make future "word)" stop */ free(pattern);
case_word = NULL; if (cond_code == 0) { /* match! we will execute this branch */
free(case_word); /* make future "word)" stop */
case_word = NULL;
break;
}
argv++;
} }
continue; continue;
} }
@ -3831,6 +3837,10 @@ static int parse_stream(o_string *dest, struct p_context *ctx,
break; break;
case '|': case '|':
done_word(dest, ctx); done_word(dest, ctx);
#if ENABLE_HUSH_CASE
if (ctx->ctx_res_w == RES_MATCH)
break;
#endif
if (next == '|') { if (next == '|') {
i_getch(input); i_getch(input);
done_pipe(ctx, PIPE_OR); done_pipe(ctx, PIPE_OR);