diff options
author | Denis Vlasenko | 2008-07-31 00:17:01 +0000 |
---|---|---|
committer | Denis Vlasenko | 2008-07-31 00:17:01 +0000 |
commit | fbeeb328b8a2e0006f9a53ddea6892f9c1a03132 (patch) | |
tree | 2ec304a2b3168c3421114ec0babda9ffac44a6d8 | |
parent | 20be63fe71466524c6110fcf02fb604a4010e1e0 (diff) | |
download | busybox-fbeeb328b8a2e0006f9a53ddea6892f9c1a03132.zip busybox-fbeeb328b8a2e0006f9a53ddea6892f9c1a03132.tar.gz |
hush: support "pattern1|pattern2...)" in case statements
parse_stream 1847 1861 +14
run_list 1995 2006 +11
-rw-r--r-- | shell/hush.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/shell/hush.c b/shell/hush.c index eab0079..564b62c 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -2202,17 +2202,23 @@ static int run_list(struct pipe *pi) continue; } if (rword == RES_MATCH) { - char *pattern; + char **argv; + if (!case_word) /* "case ... matched_word) ... WORD)": we executed selected branch, stop */ break; /* all prev words didn't match, does this one match? */ - pattern = expand_strvec_to_string(pi->progs->argv); - /* TODO: which FNM_xxx flags to use? */ - cond_code = (fnmatch(pattern, case_word, /*flags:*/ 0) != 0); - free(pattern); - if (cond_code == 0) { /* match! we will execute this branch */ - free(case_word); /* make future "word)" stop */ - case_word = NULL; + argv = pi->progs->argv; + while (*argv) { + char *pattern = expand_string_to_string(*argv); + /* TODO: which FNM_xxx flags to use? */ + cond_code = (fnmatch(pattern, case_word, /*flags:*/ 0) != 0); + free(pattern); + if (cond_code == 0) { /* match! we will execute this branch */ + free(case_word); /* make future "word)" stop */ + case_word = NULL; + break; + } + argv++; } continue; } @@ -3831,6 +3837,10 @@ static int parse_stream(o_string *dest, struct p_context *ctx, break; case '|': done_word(dest, ctx); +#if ENABLE_HUSH_CASE + if (ctx->ctx_res_w == RES_MATCH) + break; +#endif if (next == '|') { i_getch(input); done_pipe(ctx, PIPE_OR); |