diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-28 00:01:16 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-28 00:01:16 +0000 |
commit | be709c24d40c2fb52d3f57faa25b9134c7d25270 (patch) | |
tree | 8a2d3d0281ab92d0d961c7a783e01ba501e8a418 /shell/hush.c | |
parent | 8d523cbcd79c5428f1ea5bcbec6b7d9fd3756dc3 (diff) | |
download | busybox-w32-be709c24d40c2fb52d3f57faa25b9134c7d25270.tar.gz busybox-w32-be709c24d40c2fb52d3f57faa25b9134c7d25270.tar.bz2 busybox-w32-be709c24d40c2fb52d3f57faa25b9134c7d25270.zip |
hush: finish and enable optional case...esac support. Code size cost:
function old new delta
run_list 1891 2075 +184
parse_stream 1764 1847 +83
expand_strvec_to_string - 83 +83
done_word 647 715 +68
static.reserved_list 144 168 +24
static.reserved_match - 12 +12
done_pipe 95 105 +10
builtin_exit 48 46 -2
builtin_eval 127 54 -73
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 5/2 up/down: 464/-75) Total: 389 bytes
Diffstat (limited to 'shell/hush.c')
-rw-r--r-- | shell/hush.c | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/shell/hush.c b/shell/hush.c index cf6a18f86..5a565b392 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -67,14 +67,12 @@ | |||
67 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. | 67 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. |
68 | */ | 68 | */ |
69 | 69 | ||
70 | |||
71 | #include <glob.h> /* glob, of course */ | ||
72 | /* #include <dmalloc.h> */ | ||
73 | |||
74 | #include "busybox.h" /* for APPLET_IS_NOFORK/NOEXEC */ | 70 | #include "busybox.h" /* for APPLET_IS_NOFORK/NOEXEC */ |
75 | 71 | #include <glob.h> | |
76 | // TEMP | 72 | /* #include <dmalloc.h> */ |
77 | #define ENABLE_HUSH_CASE 0 | 73 | #if ENABLE_HUSH_CASE |
74 | #include <fnmatch.h> | ||
75 | #endif | ||
78 | 76 | ||
79 | 77 | ||
80 | #if !BB_MMU && ENABLE_HUSH_TICK | 78 | #if !BB_MMU && ENABLE_HUSH_TICK |
@@ -2064,6 +2062,10 @@ static int run_list(struct pipe *pi) | |||
2064 | rpipe = NULL; | 2062 | rpipe = NULL; |
2065 | #endif | 2063 | #endif |
2066 | 2064 | ||
2065 | /* Past this point, all code paths should jump to ret: label | ||
2066 | * in order to return, no direct "return" statements. | ||
2067 | * This helps to ensure that no memory is leaked */ | ||
2068 | |||
2067 | #if ENABLE_HUSH_JOB | 2069 | #if ENABLE_HUSH_JOB |
2068 | /* Example of nested list: "while true; do { sleep 1 | exit 2; } done". | 2070 | /* Example of nested list: "while true; do { sleep 1 | exit 2; } done". |
2069 | * We are saving state before entering outermost list ("while...done") | 2071 | * We are saving state before entering outermost list ("while...done") |
@@ -2170,6 +2172,7 @@ static int run_list(struct pipe *pi) | |||
2170 | if (!*for_lcur) { | 2172 | if (!*for_lcur) { |
2171 | /* for loop is over, clean up */ | 2173 | /* for loop is over, clean up */ |
2172 | free(for_list); | 2174 | free(for_list); |
2175 | for_list = NULL; | ||
2173 | for_lcur = NULL; | 2176 | for_lcur = NULL; |
2174 | flag_rep = 0; | 2177 | flag_rep = 0; |
2175 | pi->progs->argv[0] = for_varname; | 2178 | pi->progs->argv[0] = for_varname; |
@@ -2195,14 +2198,21 @@ static int run_list(struct pipe *pi) | |||
2195 | #endif | 2198 | #endif |
2196 | #if ENABLE_HUSH_CASE | 2199 | #if ENABLE_HUSH_CASE |
2197 | if (rword == RES_CASE) { | 2200 | if (rword == RES_CASE) { |
2198 | case_word = pi->progs->argv[0]; | 2201 | case_word = expand_strvec_to_string(pi->progs->argv); |
2202 | //bb_error_msg("case: arg:'%s' case_word:'%s'", pi->progs->argv[0], case_word); | ||
2199 | continue; | 2203 | continue; |
2200 | } | 2204 | } |
2201 | if (rword == RES_MATCH) { | 2205 | if (rword == RES_MATCH) { |
2202 | if (case_word) { | 2206 | if (case_word) { |
2203 | next_if_code = strcmp(case_word, pi->progs->argv[0]); | 2207 | char *pattern = expand_strvec_to_string(pi->progs->argv); |
2204 | if (next_if_code == 0) | 2208 | /* TODO: which FNM_xxx flags to use? */ |
2209 | next_if_code = fnmatch(pattern, case_word, /*flags:*/ 0); | ||
2210 | //bb_error_msg("fnmatch('%s','%s'):%d", pattern, case_word, next_if_code); | ||
2211 | free(pattern); | ||
2212 | if (next_if_code == 0) { | ||
2213 | free(case_word); | ||
2205 | case_word = NULL; | 2214 | case_word = NULL; |
2215 | } | ||
2206 | continue; | 2216 | continue; |
2207 | } | 2217 | } |
2208 | break; | 2218 | break; |
@@ -2276,6 +2286,12 @@ static int run_list(struct pipe *pi) | |||
2276 | } | 2286 | } |
2277 | #endif | 2287 | #endif |
2278 | debug_printf_exec("run_list lvl %d return %d\n", run_list_level + 1, rcode); | 2288 | debug_printf_exec("run_list lvl %d return %d\n", run_list_level + 1, rcode); |
2289 | #if ENABLE_HUSH_LOOPS | ||
2290 | free(for_list); | ||
2291 | #endif | ||
2292 | #if ENABLE_HUSH_CASE | ||
2293 | free(case_word); | ||
2294 | #endif | ||
2279 | return rcode; | 2295 | return rcode; |
2280 | } | 2296 | } |
2281 | 2297 | ||