aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-10-03 14:28:04 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2010-10-03 14:28:04 +0200
commit9e800223f13edeb02412936c810e7ee79f35c27c (patch)
treea59d347da23cf42a77ae9e8b957cae2b2287c2a2
parent238081f750f442c1dd851ba70243bd0819f3ca04 (diff)
downloadbusybox-w32-9e800223f13edeb02412936c810e7ee79f35c27c.tar.gz
busybox-w32-9e800223f13edeb02412936c810e7ee79f35c27c.tar.bz2
busybox-w32-9e800223f13edeb02412936c810e7ee79f35c27c.zip
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>
-rw-r--r--shell/hush.c25
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 @@
129//config: help 129//config: help
130//config: Enable bash-compatible extensions. 130//config: Enable bash-compatible extensions.
131//config: 131//config:
132//config:config HUSH_BRACE_EXPANSION
133//config: bool "Brace expansion"
134//config: default y
135//config: depends on HUSH_BASH_COMPAT
136//config: help
137//config: Enable {abc,def} extension.
138//config:
132//config:config HUSH_HELP 139//config:config HUSH_HELP
133//config: bool "help builtin" 140//config: bool "help builtin"
134//config: default y 141//config: default y
@@ -2000,7 +2007,6 @@ static void o_addstr_with_NUL(o_string *o, const char *str)
2000 o_addblock(o, str, strlen(str) + 1); 2007 o_addblock(o, str, strlen(str) + 1);
2001} 2008}
2002 2009
2003#undef HUSH_BRACE_EXPANSION
2004/* 2010/*
2005 * HUSH_BRACE_EXPANSION code needs corresponding quoting on variable expansion side. 2011 * HUSH_BRACE_EXPANSION code needs corresponding quoting on variable expansion side.
2006 * Currently, "v='{q,w}'; echo $v" erroneously expands braces in $v. 2012 * 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)
2012 * We have only second one. 2018 * We have only second one.
2013 */ 2019 */
2014 2020
2015#ifdef HUSH_BRACE_EXPANSION 2021#if ENABLE_HUSH_BRACE_EXPANSION
2016# define MAYBE_BRACES "{}" 2022# define MAYBE_BRACES "{}"
2017#else 2023#else
2018# define MAYBE_BRACES "" 2024# define MAYBE_BRACES ""
@@ -2180,7 +2186,7 @@ static int o_get_last_ptr(o_string *o, int n)
2180 return ((int)(uintptr_t)list[n-1]) + string_start; 2186 return ((int)(uintptr_t)list[n-1]) + string_start;
2181} 2187}
2182 2188
2183#ifdef HUSH_BRACE_EXPANSION 2189#if ENABLE_HUSH_BRACE_EXPANSION
2184/* There in a GNU extension, GLOB_BRACE, but it is not usable: 2190/* There in a GNU extension, GLOB_BRACE, but it is not usable:
2185 * first, it processes even {a} (no commas), second, 2191 * first, it processes even {a} (no commas), second,
2186 * I didn't manage to make it return strings when they don't match 2192 * 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);
4375static void o_addblock_duplicate_backslash(o_string *o, const char *str, int len) 4381static void o_addblock_duplicate_backslash(o_string *o, const char *str, int len)
4376{ 4382{
4377 while (--len >= 0) { 4383 while (--len >= 0) {
4378 o_addchr(o, *str); 4384 char c = *str++;
4379 if (*str++ == '\\') { 4385#if ENABLE_HUSH_BRACE_EXPANSION
4386 if (c == '{' || c == '}') {
4387 /* { -> \{, } -> \} */
4388 o_addchr(o, '\\');
4389 o_addchr(o, c);
4390 continue;
4391 }
4392#endif
4393 o_addchr(o, c);
4394 if (c == '\\') {
4380 /* \z -> \\\z; \<eol> -> \\<eol> */ 4395 /* \z -> \\\z; \<eol> -> \\<eol> */
4381 o_addchr(o, '\\'); 4396 o_addchr(o, '\\');
4382 if (len) { 4397 if (len) {