diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-10-03 14:26:26 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-10-03 14:26:26 +0200 |
commit | 238081f750f442c1dd851ba70243bd0819f3ca04 (patch) | |
tree | 400889a2d3a6b41d1a781dd5d5fd6a16750f3008 | |
parent | 0296fd3af1cb3f9cceabc31dd39b6a00b66cb65d (diff) | |
download | busybox-w32-238081f750f442c1dd851ba70243bd0819f3ca04.tar.gz busybox-w32-238081f750f442c1dd851ba70243bd0819f3ca04.tar.bz2 busybox-w32-238081f750f442c1dd851ba70243bd0819f3ca04.zip |
hush: preparatory patch, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/hush.c | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/shell/hush.c b/shell/hush.c index 4c597e1ed..3b9362e10 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -2000,26 +2000,9 @@ static void o_addstr_with_NUL(o_string *o, const char *str) | |||
2000 | o_addblock(o, str, strlen(str) + 1); | 2000 | o_addblock(o, str, strlen(str) + 1); |
2001 | } | 2001 | } |
2002 | 2002 | ||
2003 | static void o_addblock_duplicate_backslash(o_string *o, const char *str, int len) | 2003 | #undef HUSH_BRACE_EXPANSION |
2004 | { | ||
2005 | while (len) { | ||
2006 | len--; | ||
2007 | o_addchr(o, *str); | ||
2008 | if (*str++ == '\\') { | ||
2009 | /* \z -> \\\z; \<eol> -> \\<eol> */ | ||
2010 | o_addchr(o, '\\'); | ||
2011 | if (len) { | ||
2012 | len--; | ||
2013 | o_addchr(o, '\\'); | ||
2014 | o_addchr(o, *str++); | ||
2015 | } | ||
2016 | } | ||
2017 | } | ||
2018 | } | ||
2019 | |||
2020 | #undef HUSH_BRACE_EXP | ||
2021 | /* | 2004 | /* |
2022 | * HUSH_BRACE_EXP code needs corresponding quoting on variable expansion side. | 2005 | * HUSH_BRACE_EXPANSION code needs corresponding quoting on variable expansion side. |
2023 | * Currently, "v='{q,w}'; echo $v" erroneously expands braces in $v. | 2006 | * Currently, "v='{q,w}'; echo $v" erroneously expands braces in $v. |
2024 | * Apparently, on unquoted $v bash still does globbing | 2007 | * Apparently, on unquoted $v bash still does globbing |
2025 | * ("v='*.txt'; echo $v" prints all .txt files), | 2008 | * ("v='*.txt'; echo $v" prints all .txt files), |
@@ -2029,7 +2012,7 @@ static void o_addblock_duplicate_backslash(o_string *o, const char *str, int len | |||
2029 | * We have only second one. | 2012 | * We have only second one. |
2030 | */ | 2013 | */ |
2031 | 2014 | ||
2032 | #ifdef HUSH_BRACE_EXP | 2015 | #ifdef HUSH_BRACE_EXPANSION |
2033 | # define MAYBE_BRACES "{}" | 2016 | # define MAYBE_BRACES "{}" |
2034 | #else | 2017 | #else |
2035 | # define MAYBE_BRACES "" | 2018 | # define MAYBE_BRACES "" |
@@ -2197,7 +2180,7 @@ static int o_get_last_ptr(o_string *o, int n) | |||
2197 | return ((int)(uintptr_t)list[n-1]) + string_start; | 2180 | return ((int)(uintptr_t)list[n-1]) + string_start; |
2198 | } | 2181 | } |
2199 | 2182 | ||
2200 | #ifdef HUSH_BRACE_EXP | 2183 | #ifdef HUSH_BRACE_EXPANSION |
2201 | /* There in a GNU extension, GLOB_BRACE, but it is not usable: | 2184 | /* There in a GNU extension, GLOB_BRACE, but it is not usable: |
2202 | * first, it processes even {a} (no commas), second, | 2185 | * first, it processes even {a} (no commas), second, |
2203 | * I didn't manage to make it return strings when they don't match | 2186 | * I didn't manage to make it return strings when they don't match |
@@ -2393,7 +2376,7 @@ static int perform_glob(o_string *o, int n) | |||
2393 | return n; | 2376 | return n; |
2394 | } | 2377 | } |
2395 | 2378 | ||
2396 | #else /* !HUSH_BRACE_EXP */ | 2379 | #else /* !HUSH_BRACE_EXPANSION */ |
2397 | 2380 | ||
2398 | /* Helper */ | 2381 | /* Helper */ |
2399 | static int glob_needed(const char *s) | 2382 | static int glob_needed(const char *s) |
@@ -2470,7 +2453,7 @@ static int perform_glob(o_string *o, int n) | |||
2470 | return n; | 2453 | return n; |
2471 | } | 2454 | } |
2472 | 2455 | ||
2473 | #endif /* !HUSH_BRACE_EXP */ | 2456 | #endif /* !HUSH_BRACE_EXPANSION */ |
2474 | 2457 | ||
2475 | /* If o->o_expflags & EXP_FLAG_GLOB, glob the string so far remembered. | 2458 | /* If o->o_expflags & EXP_FLAG_GLOB, glob the string so far remembered. |
2476 | * Otherwise, just finish current list[] and start new */ | 2459 | * Otherwise, just finish current list[] and start new */ |
@@ -4387,6 +4370,24 @@ static int process_command_subs(o_string *dest, const char *s); | |||
4387 | * followed by strings themselves. | 4370 | * followed by strings themselves. |
4388 | * Caller can deallocate entire list by single free(list). */ | 4371 | * Caller can deallocate entire list by single free(list). */ |
4389 | 4372 | ||
4373 | /* A horde of its helpers come first: */ | ||
4374 | |||
4375 | static void o_addblock_duplicate_backslash(o_string *o, const char *str, int len) | ||
4376 | { | ||
4377 | while (--len >= 0) { | ||
4378 | o_addchr(o, *str); | ||
4379 | if (*str++ == '\\') { | ||
4380 | /* \z -> \\\z; \<eol> -> \\<eol> */ | ||
4381 | o_addchr(o, '\\'); | ||
4382 | if (len) { | ||
4383 | len--; | ||
4384 | o_addchr(o, '\\'); | ||
4385 | o_addchr(o, *str++); | ||
4386 | } | ||
4387 | } | ||
4388 | } | ||
4389 | } | ||
4390 | |||
4390 | /* Store given string, finalizing the word and starting new one whenever | 4391 | /* Store given string, finalizing the word and starting new one whenever |
4391 | * we encounter IFS char(s). This is used for expanding variable values. | 4392 | * we encounter IFS char(s). This is used for expanding variable values. |
4392 | * End-of-string does NOT finalize word: think about 'echo -$VAR-' */ | 4393 | * End-of-string does NOT finalize word: think about 'echo -$VAR-' */ |
@@ -4395,9 +4396,9 @@ static int expand_on_ifs(o_string *output, int n, const char *str) | |||
4395 | while (1) { | 4396 | while (1) { |
4396 | int word_len = strcspn(str, G.ifs); | 4397 | int word_len = strcspn(str, G.ifs); |
4397 | if (word_len) { | 4398 | if (word_len) { |
4398 | if (!(output->o_expflags & EXP_FLAG_GLOB)) | 4399 | if (!(output->o_expflags & EXP_FLAG_GLOB)) { |
4399 | o_addblock(output, str, word_len); | 4400 | o_addblock(output, str, word_len); |
4400 | else { | 4401 | } else { |
4401 | /* Protect backslashes against globbing up :) | 4402 | /* Protect backslashes against globbing up :) |
4402 | * Example: "v='\*'; echo b$v" prints "b\*" | 4403 | * Example: "v='\*'; echo b$v" prints "b\*" |
4403 | * (and does not try to glob on "*") | 4404 | * (and does not try to glob on "*") |