diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-10-03 14:28:04 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-10-03 14:28:04 +0200 |
commit | 9e800223f13edeb02412936c810e7ee79f35c27c (patch) | |
tree | a59d347da23cf42a77ae9e8b957cae2b2287c2a2 /shell | |
parent | 238081f750f442c1dd851ba70243bd0819f3ca04 (diff) | |
download | busybox-9e800223f13edeb02412936c810e7ee79f35c27c.tar.gz |
hush: implement brace expansion
When enabled:
function old new delta
glob_brace - 402 +402
next_brace_sub - 70 +70
expand_on_ifs 185 231 +46
bbconfig_config_bz2 4923 4929 +6
o_save_ptr 282 140 -142
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 2/1 up/down: 524/-142) Total: 382 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r-- | shell/hush.c | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/shell/hush.c b/shell/hush.c index 3b9362e10..5b73f0c53 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -129,6 +129,13 @@ //config: help //config: Enable bash-compatible extensions. //config: +//config:config HUSH_BRACE_EXPANSION +//config: bool "Brace expansion" +//config: default y +//config: depends on HUSH_BASH_COMPAT +//config: help +//config: Enable {abc,def} extension. +//config: //config:config HUSH_HELP //config: bool "help builtin" //config: default y @@ -2000,7 +2007,6 @@ static void o_addstr_with_NUL(o_string *o, const char *str) o_addblock(o, str, strlen(str) + 1); } -#undef HUSH_BRACE_EXPANSION /* * HUSH_BRACE_EXPANSION code needs corresponding quoting on variable expansion side. * Currently, "v='{q,w}'; echo $v" erroneously expands braces in $v. @@ -2012,7 +2018,7 @@ static void o_addstr_with_NUL(o_string *o, const char *str) * We have only second one. */ -#ifdef HUSH_BRACE_EXPANSION +#if ENABLE_HUSH_BRACE_EXPANSION # define MAYBE_BRACES "{}" #else # define MAYBE_BRACES "" @@ -2180,7 +2186,7 @@ static int o_get_last_ptr(o_string *o, int n) return ((int)(uintptr_t)list[n-1]) + string_start; } -#ifdef HUSH_BRACE_EXPANSION +#if ENABLE_HUSH_BRACE_EXPANSION /* There in a GNU extension, GLOB_BRACE, but it is not usable: * first, it processes even {a} (no commas), second, * I didn't manage to make it return strings when they don't match @@ -4375,8 +4381,17 @@ static int process_command_subs(o_string *dest, const char *s); static void o_addblock_duplicate_backslash(o_string *o, const char *str, int len) { while (--len >= 0) { - o_addchr(o, *str); - if (*str++ == '\\') { + char c = *str++; +#if ENABLE_HUSH_BRACE_EXPANSION + if (c == '{' || c == '}') { + /* { -> \{, } -> \} */ + o_addchr(o, '\\'); + o_addchr(o, c); + continue; + } +#endif + o_addchr(o, c); + if (c == '\\') { /* \z -> \\\z; \<eol> -> \\<eol> */ o_addchr(o, '\\'); if (len) { |