diff options
author | Denys Vlasenko <dvlasenk@redhat.com> | 2010-09-10 10:15:18 +0200 |
---|---|---|
committer | Denys Vlasenko <dvlasenk@redhat.com> | 2010-09-10 10:15:18 +0200 |
commit | 14e289b3246b4266499ffc5747dcc5c98bdaf5b9 (patch) | |
tree | 87c6997692ec13f317d91775adfebfbb1e563d6e | |
parent | a769e0225d965d7eced9f04d99c3a66b1c427ee3 (diff) | |
download | busybox-w32-14e289b3246b4266499ffc5747dcc5c98bdaf5b9.tar.gz busybox-w32-14e289b3246b4266499ffc5747dcc5c98bdaf5b9.tar.bz2 busybox-w32-14e289b3246b4266499ffc5747dcc5c98bdaf5b9.zip |
hush: fix var_bash3.tests failure
function old new delta
expand_one_var 1513 1538 +25
parse_stream_dquoted 233 241 +8
expand_pseudo_dquoted 118 126 +8
setup_heredoc 298 303 +5
expand_and_evaluate_arith 69 74 +5
parse_stream 2371 2374 +3
builtin_umask 132 133 +1
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 7/0 up/down: 55/0) Total: 55 bytes
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
-rw-r--r-- | shell/hush.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/shell/hush.c b/shell/hush.c index b7aeab28c..942e72ad0 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -3733,14 +3733,15 @@ static int parse_dollar(o_string *as_string, | |||
3733 | } | 3733 | } |
3734 | 3734 | ||
3735 | #if BB_MMU | 3735 | #if BB_MMU |
3736 | #define parse_stream_dquoted(as_string, dest, input, dquote_end) \ | 3736 | #define parse_stream_dquoted(as_string, dest, input, dquote_end, dquoted) \ |
3737 | parse_stream_dquoted(dest, input, dquote_end) | 3737 | parse_stream_dquoted(dest, input, dquote_end, dquoted) |
3738 | #define as_string NULL | 3738 | #define as_string NULL |
3739 | #endif | 3739 | #endif |
3740 | static int parse_stream_dquoted(o_string *as_string, | 3740 | static int parse_stream_dquoted(o_string *as_string, |
3741 | o_string *dest, | 3741 | o_string *dest, |
3742 | struct in_str *input, | 3742 | struct in_str *input, |
3743 | int dquote_end) | 3743 | int dquote_end, |
3744 | int dquoted) | ||
3744 | { | 3745 | { |
3745 | int ch; | 3746 | int ch; |
3746 | int next; | 3747 | int next; |
@@ -3764,7 +3765,7 @@ static int parse_stream_dquoted(o_string *as_string, | |||
3764 | } | 3765 | } |
3765 | debug_printf_parse("\" ch=%c (%d) escape=%d\n", | 3766 | debug_printf_parse("\" ch=%c (%d) escape=%d\n", |
3766 | ch, ch, !!(dest->o_expflags & EXP_FLAG_ESC_GLOB_CHARS)); | 3767 | ch, ch, !!(dest->o_expflags & EXP_FLAG_ESC_GLOB_CHARS)); |
3767 | if (ch == '\\') { | 3768 | if (dquoted && ch == '\\') { |
3768 | if (next == EOF) { | 3769 | if (next == EOF) { |
3769 | syntax_error("\\<eof>"); | 3770 | syntax_error("\\<eof>"); |
3770 | xfunc_die(); | 3771 | xfunc_die(); |
@@ -3786,6 +3787,7 @@ static int parse_stream_dquoted(o_string *as_string, | |||
3786 | goto again; | 3787 | goto again; |
3787 | } | 3788 | } |
3788 | if (ch == '$') { | 3789 | if (ch == '$') { |
3790 | //CHECK: 0x80? or dquoted? | ||
3789 | if (parse_dollar(as_string, dest, input, /*quote_mask:*/ 0x80) != 0) { | 3791 | if (parse_dollar(as_string, dest, input, /*quote_mask:*/ 0x80) != 0) { |
3790 | debug_printf_parse("parse_stream_dquoted return 1: " | 3792 | debug_printf_parse("parse_stream_dquoted return 1: " |
3791 | "parse_dollar returned non-0\n"); | 3793 | "parse_dollar returned non-0\n"); |
@@ -4160,7 +4162,7 @@ static struct pipe *parse_stream(char **pstring, | |||
4160 | dest.has_quoted_part = 1; | 4162 | dest.has_quoted_part = 1; |
4161 | if (dest.o_assignment == NOT_ASSIGNMENT) | 4163 | if (dest.o_assignment == NOT_ASSIGNMENT) |
4162 | dest.o_expflags |= EXP_FLAG_ESC_GLOB_CHARS; | 4164 | dest.o_expflags |= EXP_FLAG_ESC_GLOB_CHARS; |
4163 | if (parse_stream_dquoted(&ctx.as_string, &dest, input, '"')) | 4165 | if (parse_stream_dquoted(&ctx.as_string, &dest, input, '"', /*dquoted:*/ 1)) |
4164 | goto parse_error; | 4166 | goto parse_error; |
4165 | dest.o_expflags &= ~EXP_FLAG_ESC_GLOB_CHARS; | 4167 | dest.o_expflags &= ~EXP_FLAG_ESC_GLOB_CHARS; |
4166 | break; | 4168 | break; |
@@ -4385,7 +4387,7 @@ static int expand_on_ifs(o_string *output, int n, const char *str) | |||
4385 | * Returns malloced string. | 4387 | * Returns malloced string. |
4386 | * As an optimization, we return NULL if expansion is not needed. | 4388 | * As an optimization, we return NULL if expansion is not needed. |
4387 | */ | 4389 | */ |
4388 | static char *expand_pseudo_dquoted(const char *str) | 4390 | static char *expand_pseudo_dquoted(const char *str, int dquoted) |
4389 | { | 4391 | { |
4390 | char *exp_str; | 4392 | char *exp_str; |
4391 | struct in_str input; | 4393 | struct in_str input; |
@@ -4404,7 +4406,7 @@ static char *expand_pseudo_dquoted(const char *str) | |||
4404 | * echo $(($a + `echo 1`)) $((1 + $((2)) )) | 4406 | * echo $(($a + `echo 1`)) $((1 + $((2)) )) |
4405 | */ | 4407 | */ |
4406 | setup_string_in_str(&input, str); | 4408 | setup_string_in_str(&input, str); |
4407 | parse_stream_dquoted(NULL, &dest, &input, EOF); | 4409 | parse_stream_dquoted(NULL, &dest, &input, EOF, dquoted); |
4408 | //bb_error_msg("'%s' -> '%s'", str, dest.data); | 4410 | //bb_error_msg("'%s' -> '%s'", str, dest.data); |
4409 | exp_str = expand_string_to_string(dest.data); | 4411 | exp_str = expand_string_to_string(dest.data); |
4410 | //bb_error_msg("'%s' -> '%s'", dest.data, exp_str); | 4412 | //bb_error_msg("'%s' -> '%s'", dest.data, exp_str); |
@@ -4422,7 +4424,7 @@ static arith_t expand_and_evaluate_arith(const char *arg, int *errcode_p) | |||
4422 | hooks.lookupvar = get_local_var_value; | 4424 | hooks.lookupvar = get_local_var_value; |
4423 | hooks.setvar = set_local_var_from_halves; | 4425 | hooks.setvar = set_local_var_from_halves; |
4424 | //hooks.endofname = endofname; | 4426 | //hooks.endofname = endofname; |
4425 | exp_str = expand_pseudo_dquoted(arg); | 4427 | exp_str = expand_pseudo_dquoted(arg, /*dquoted:*/ 1); |
4426 | res = arith(exp_str ? exp_str : arg, errcode_p, &hooks); | 4428 | res = arith(exp_str ? exp_str : arg, errcode_p, &hooks); |
4427 | free(exp_str); | 4429 | free(exp_str); |
4428 | return res; | 4430 | return res; |
@@ -4593,7 +4595,7 @@ static NOINLINE const char *expand_one_var(char **to_be_freed_pp, char *arg, cha | |||
4593 | // (see HACK ALERT below for an example) | 4595 | // (see HACK ALERT below for an example) |
4594 | val = to_be_freed = xstrdup(val); | 4596 | val = to_be_freed = xstrdup(val); |
4595 | //TODO: fix expansion rules: | 4597 | //TODO: fix expansion rules: |
4596 | exp_exp_word = expand_pseudo_dquoted(exp_word); | 4598 | exp_exp_word = expand_pseudo_dquoted(exp_word, /*dquoted:*/ 1); |
4597 | if (exp_exp_word) | 4599 | if (exp_exp_word) |
4598 | exp_word = exp_exp_word; | 4600 | exp_word = exp_exp_word; |
4599 | loc = scan_and_match(to_be_freed, exp_word, scan_flags); | 4601 | loc = scan_and_match(to_be_freed, exp_word, scan_flags); |
@@ -4631,7 +4633,7 @@ static NOINLINE const char *expand_one_var(char **to_be_freed_pp, char *arg, cha | |||
4631 | */ | 4633 | */ |
4632 | //TODO: fix expansion rules: | 4634 | //TODO: fix expansion rules: |
4633 | char *pattern, *repl, *t; | 4635 | char *pattern, *repl, *t; |
4634 | pattern = expand_pseudo_dquoted(exp_word); | 4636 | pattern = expand_pseudo_dquoted(exp_word, /*dquoted:*/ 1); |
4635 | if (!pattern) | 4637 | if (!pattern) |
4636 | pattern = xstrdup(exp_word); | 4638 | pattern = xstrdup(exp_word); |
4637 | debug_printf_varexp("pattern:'%s'->'%s'\n", exp_word, pattern); | 4639 | debug_printf_varexp("pattern:'%s'->'%s'\n", exp_word, pattern); |
@@ -4639,7 +4641,7 @@ static NOINLINE const char *expand_one_var(char **to_be_freed_pp, char *arg, cha | |||
4639 | exp_word = p; | 4641 | exp_word = p; |
4640 | p = strchr(p, SPECIAL_VAR_SYMBOL); | 4642 | p = strchr(p, SPECIAL_VAR_SYMBOL); |
4641 | *p = '\0'; | 4643 | *p = '\0'; |
4642 | repl = expand_pseudo_dquoted(exp_word); | 4644 | repl = expand_pseudo_dquoted(exp_word, /*dquoted:*/ arg0 & 0x80); |
4643 | debug_printf_varexp("repl:'%s'->'%s'\n", exp_word, repl); | 4645 | debug_printf_varexp("repl:'%s'->'%s'\n", exp_word, repl); |
4644 | /* HACK ALERT. We depend here on the fact that | 4646 | /* HACK ALERT. We depend here on the fact that |
4645 | * G.global_argv and results of utoa and get_local_var_value | 4647 | * G.global_argv and results of utoa and get_local_var_value |
@@ -4724,7 +4726,7 @@ static NOINLINE const char *expand_one_var(char **to_be_freed_pp, char *arg, cha | |||
4724 | debug_printf_expand("expand: op:%c (null:%s) test:%i\n", exp_op, | 4726 | debug_printf_expand("expand: op:%c (null:%s) test:%i\n", exp_op, |
4725 | (exp_save == ':') ? "true" : "false", use_word); | 4727 | (exp_save == ':') ? "true" : "false", use_word); |
4726 | if (use_word) { | 4728 | if (use_word) { |
4727 | to_be_freed = expand_pseudo_dquoted(exp_word); | 4729 | to_be_freed = expand_pseudo_dquoted(exp_word, /*dquoted:*/ 1); |
4728 | if (to_be_freed) | 4730 | if (to_be_freed) |
4729 | exp_word = to_be_freed; | 4731 | exp_word = to_be_freed; |
4730 | if (exp_op == '?') { | 4732 | if (exp_op == '?') { |
@@ -5463,7 +5465,7 @@ static void setup_heredoc(struct redir_struct *redir) | |||
5463 | 5465 | ||
5464 | expanded = NULL; | 5466 | expanded = NULL; |
5465 | if (!(redir->rd_dup & HEREDOC_QUOTED)) { | 5467 | if (!(redir->rd_dup & HEREDOC_QUOTED)) { |
5466 | expanded = expand_pseudo_dquoted(heredoc); | 5468 | expanded = expand_pseudo_dquoted(heredoc, /*dquoted:*/ 1); |
5467 | if (expanded) | 5469 | if (expanded) |
5468 | heredoc = expanded; | 5470 | heredoc = expanded; |
5469 | } | 5471 | } |