From 9e800223f13edeb02412936c810e7ee79f35c27c Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 3 Oct 2010 14:28:04 +0200 Subject: 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 --- shell/hush.c | 25 ++++++++++++++++++++----- 1 file 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; \ -> \\ */ o_addchr(o, '\\'); if (len) { -- cgit v1.2.3