diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-31 00:17:01 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-31 00:17:01 +0000 |
commit | fbeeb328b8a2e0006f9a53ddea6892f9c1a03132 (patch) | |
tree | 2ec304a2b3168c3421114ec0babda9ffac44a6d8 | |
parent | 20be63fe71466524c6110fcf02fb604a4010e1e0 (diff) | |
download | busybox-w32-fbeeb328b8a2e0006f9a53ddea6892f9c1a03132.tar.gz busybox-w32-fbeeb328b8a2e0006f9a53ddea6892f9c1a03132.tar.bz2 busybox-w32-fbeeb328b8a2e0006f9a53ddea6892f9c1a03132.zip |
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 eab007943..564b62c54 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -2202,17 +2202,23 @@ static int run_list(struct pipe *pi) | |||
2202 | continue; | 2202 | continue; |
2203 | } | 2203 | } |
2204 | if (rword == RES_MATCH) { | 2204 | if (rword == RES_MATCH) { |
2205 | char *pattern; | 2205 | char **argv; |
2206 | |||
2206 | if (!case_word) /* "case ... matched_word) ... WORD)": we executed selected branch, stop */ | 2207 | if (!case_word) /* "case ... matched_word) ... WORD)": we executed selected branch, stop */ |
2207 | break; | 2208 | break; |
2208 | /* all prev words didn't match, does this one match? */ | 2209 | /* all prev words didn't match, does this one match? */ |
2209 | pattern = expand_strvec_to_string(pi->progs->argv); | 2210 | argv = pi->progs->argv; |
2210 | /* TODO: which FNM_xxx flags to use? */ | 2211 | while (*argv) { |
2211 | cond_code = (fnmatch(pattern, case_word, /*flags:*/ 0) != 0); | 2212 | char *pattern = expand_string_to_string(*argv); |
2212 | free(pattern); | 2213 | /* TODO: which FNM_xxx flags to use? */ |
2213 | if (cond_code == 0) { /* match! we will execute this branch */ | 2214 | cond_code = (fnmatch(pattern, case_word, /*flags:*/ 0) != 0); |
2214 | free(case_word); /* make future "word)" stop */ | 2215 | free(pattern); |
2215 | case_word = NULL; | 2216 | if (cond_code == 0) { /* match! we will execute this branch */ |
2217 | free(case_word); /* make future "word)" stop */ | ||
2218 | case_word = NULL; | ||
2219 | break; | ||
2220 | } | ||
2221 | argv++; | ||
2216 | } | 2222 | } |
2217 | continue; | 2223 | continue; |
2218 | } | 2224 | } |
@@ -3831,6 +3837,10 @@ static int parse_stream(o_string *dest, struct p_context *ctx, | |||
3831 | break; | 3837 | break; |
3832 | case '|': | 3838 | case '|': |
3833 | done_word(dest, ctx); | 3839 | done_word(dest, ctx); |
3840 | #if ENABLE_HUSH_CASE | ||
3841 | if (ctx->ctx_res_w == RES_MATCH) | ||
3842 | break; | ||
3843 | #endif | ||
3834 | if (next == '|') { | 3844 | if (next == '|') { |
3835 | i_getch(input); | 3845 | i_getch(input); |
3836 | done_pipe(ctx, PIPE_OR); | 3846 | done_pipe(ctx, PIPE_OR); |