diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-05-22 17:30:39 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-05-22 17:30:39 +0200 |
commit | 2e48d536cee3c2fb261780eb2a01972bd936a56c (patch) | |
tree | 5e716696dd24db63a95d2441797cf7f2b86444e6 /shell/hush.c | |
parent | 5ae8f1cdbecd3bdf502992c21a77aae65299c410 (diff) | |
download | busybox-w32-2e48d536cee3c2fb261780eb2a01972bd936a56c.tar.gz busybox-w32-2e48d536cee3c2fb261780eb2a01972bd936a56c.tar.bz2 busybox-w32-2e48d536cee3c2fb261780eb2a01972bd936a56c.zip |
hush: reduce #ifdef forest a bit, rename handle_dollar -> parse_dollar
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/hush.c')
-rw-r--r-- | shell/hush.c | 45 |
1 files changed, 20 insertions, 25 deletions
diff --git a/shell/hush.c b/shell/hush.c index 8125a63f1..e9d31b436 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -50,6 +50,7 @@ | |||
50 | * | 50 | * |
51 | * Bash compat TODO: | 51 | * Bash compat TODO: |
52 | * redirection of stdout+stderr: &> and >& | 52 | * redirection of stdout+stderr: &> and >& |
53 | * subst operator: ${var/[/]expr/expr} | ||
53 | * brace expansion: one/{two,three,four} | 54 | * brace expansion: one/{two,three,four} |
54 | * reserved words: function select | 55 | * reserved words: function select |
55 | * advanced test: [[ ]] | 56 | * advanced test: [[ ]] |
@@ -1830,6 +1831,7 @@ static void o_addstr(o_string *o, const char *str) | |||
1830 | { | 1831 | { |
1831 | o_addblock(o, str, strlen(str)); | 1832 | o_addblock(o, str, strlen(str)); |
1832 | } | 1833 | } |
1834 | |||
1833 | #if !BB_MMU | 1835 | #if !BB_MMU |
1834 | static void nommu_addchr(o_string *o, int ch) | 1836 | static void nommu_addchr(o_string *o, int ch) |
1835 | { | 1837 | { |
@@ -2618,7 +2620,7 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg, char | |||
2618 | 2620 | ||
2619 | /* lookup the variable in question */ | 2621 | /* lookup the variable in question */ |
2620 | if (isdigit(var[0])) { | 2622 | if (isdigit(var[0])) { |
2621 | /* handle_dollar() should have vetted var for us */ | 2623 | /* parse_dollar() should have vetted var for us */ |
2622 | i = xatoi_u(var); | 2624 | i = xatoi_u(var); |
2623 | if (i < G.global_argc) | 2625 | if (i < G.global_argc) |
2624 | val = G.global_argv[i]; | 2626 | val = G.global_argv[i]; |
@@ -4545,11 +4547,11 @@ static void debug_print_tree(struct pipe *pi, int lvl) | |||
4545 | fprintf(stderr, " group %s: (argv=%p)%s%s\n", | 4547 | fprintf(stderr, " group %s: (argv=%p)%s%s\n", |
4546 | CMDTYPE[command->cmd_type], | 4548 | CMDTYPE[command->cmd_type], |
4547 | argv | 4549 | argv |
4548 | #if !BB_MMU | 4550 | # if !BB_MMU |
4549 | , " group_as_string:", command->group_as_string | 4551 | , " group_as_string:", command->group_as_string |
4550 | #else | 4552 | # else |
4551 | , "", "" | 4553 | , "", "" |
4552 | #endif | 4554 | # endif |
4553 | ); | 4555 | ); |
4554 | debug_print_tree(command->group, lvl+1); | 4556 | debug_print_tree(command->group, lvl+1); |
4555 | prn++; | 4557 | prn++; |
@@ -5988,18 +5990,18 @@ static int add_till_closing_bracket(o_string *dest, struct in_str *input, unsign | |||
5988 | 5990 | ||
5989 | /* Return code: 0 for OK, 1 for syntax error */ | 5991 | /* Return code: 0 for OK, 1 for syntax error */ |
5990 | #if BB_MMU | 5992 | #if BB_MMU |
5991 | #define handle_dollar(as_string, dest, input) \ | 5993 | #define parse_dollar(as_string, dest, input) \ |
5992 | handle_dollar(dest, input) | 5994 | parse_dollar(dest, input) |
5993 | #define as_string NULL | 5995 | #define as_string NULL |
5994 | #endif | 5996 | #endif |
5995 | static int handle_dollar(o_string *as_string, | 5997 | static int parse_dollar(o_string *as_string, |
5996 | o_string *dest, | 5998 | o_string *dest, |
5997 | struct in_str *input) | 5999 | struct in_str *input) |
5998 | { | 6000 | { |
5999 | int ch = i_peek(input); /* first character after the $ */ | 6001 | int ch = i_peek(input); /* first character after the $ */ |
6000 | unsigned char quote_mask = dest->o_escape ? 0x80 : 0; | 6002 | unsigned char quote_mask = dest->o_escape ? 0x80 : 0; |
6001 | 6003 | ||
6002 | debug_printf_parse("handle_dollar entered: ch='%c'\n", ch); | 6004 | debug_printf_parse("parse_dollar entered: ch='%c'\n", ch); |
6003 | if (isalpha(ch)) { | 6005 | if (isalpha(ch)) { |
6004 | ch = i_getch(input); | 6006 | ch = i_getch(input); |
6005 | nommu_addchr(as_string, ch); | 6007 | nommu_addchr(as_string, ch); |
@@ -6047,7 +6049,7 @@ static int handle_dollar(o_string *as_string, | |||
6047 | if (!strchr(_SPECIAL_VARS_STR, ch) && !isalnum(ch)) { /* not one of those */ | 6049 | if (!strchr(_SPECIAL_VARS_STR, ch) && !isalnum(ch)) { /* not one of those */ |
6048 | bad_dollar_syntax: | 6050 | bad_dollar_syntax: |
6049 | syntax_error_unterm_str("${name}"); | 6051 | syntax_error_unterm_str("${name}"); |
6050 | debug_printf_parse("handle_dollar return 1: unterminated ${name}\n"); | 6052 | debug_printf_parse("parse_dollar return 1: unterminated ${name}\n"); |
6051 | return 1; | 6053 | return 1; |
6052 | } | 6054 | } |
6053 | ch |= quote_mask; | 6055 | ch |= quote_mask; |
@@ -6129,13 +6131,11 @@ static int handle_dollar(o_string *as_string, | |||
6129 | if (!BB_MMU) | 6131 | if (!BB_MMU) |
6130 | pos = dest->length; | 6132 | pos = dest->length; |
6131 | add_till_closing_bracket(dest, input, ')' | DOUBLE_CLOSE_CHAR_FLAG); | 6133 | add_till_closing_bracket(dest, input, ')' | DOUBLE_CLOSE_CHAR_FLAG); |
6132 | #if !BB_MMU | ||
6133 | if (as_string) { | 6134 | if (as_string) { |
6134 | o_addstr(as_string, dest->data + pos); | 6135 | o_addstr(as_string, dest->data + pos); |
6135 | o_addchr(as_string, ')'); | 6136 | o_addchr(as_string, ')'); |
6136 | o_addchr(as_string, ')'); | 6137 | o_addchr(as_string, ')'); |
6137 | } | 6138 | } |
6138 | #endif | ||
6139 | o_addchr(dest, SPECIAL_VAR_SYMBOL); | 6139 | o_addchr(dest, SPECIAL_VAR_SYMBOL); |
6140 | break; | 6140 | break; |
6141 | } | 6141 | } |
@@ -6146,12 +6146,10 @@ static int handle_dollar(o_string *as_string, | |||
6146 | if (!BB_MMU) | 6146 | if (!BB_MMU) |
6147 | pos = dest->length; | 6147 | pos = dest->length; |
6148 | add_till_closing_bracket(dest, input, ')'); | 6148 | add_till_closing_bracket(dest, input, ')'); |
6149 | #if !BB_MMU | ||
6150 | if (as_string) { | 6149 | if (as_string) { |
6151 | o_addstr(as_string, dest->data + pos); | 6150 | o_addstr(as_string, dest->data + pos); |
6152 | o_addchr(as_string, ')'); | 6151 | o_addchr(as_string, ')'); |
6153 | } | 6152 | } |
6154 | #endif | ||
6155 | o_addchr(dest, SPECIAL_VAR_SYMBOL); | 6153 | o_addchr(dest, SPECIAL_VAR_SYMBOL); |
6156 | # endif | 6154 | # endif |
6157 | break; | 6155 | break; |
@@ -6174,7 +6172,7 @@ static int handle_dollar(o_string *as_string, | |||
6174 | default: | 6172 | default: |
6175 | o_addQchr(dest, '$'); | 6173 | o_addQchr(dest, '$'); |
6176 | } | 6174 | } |
6177 | debug_printf_parse("handle_dollar return 0\n"); | 6175 | debug_printf_parse("parse_dollar return 0\n"); |
6178 | return 0; | 6176 | return 0; |
6179 | #undef as_string | 6177 | #undef as_string |
6180 | } | 6178 | } |
@@ -6237,9 +6235,9 @@ static int parse_stream_dquoted(o_string *as_string, | |||
6237 | goto again; | 6235 | goto again; |
6238 | } | 6236 | } |
6239 | if (ch == '$') { | 6237 | if (ch == '$') { |
6240 | if (handle_dollar(as_string, dest, input) != 0) { | 6238 | if (parse_dollar(as_string, dest, input) != 0) { |
6241 | debug_printf_parse("parse_stream_dquoted return 1: " | 6239 | debug_printf_parse("parse_stream_dquoted return 1: " |
6242 | "handle_dollar returned non-0\n"); | 6240 | "parse_dollar returned non-0\n"); |
6243 | return 1; | 6241 | return 1; |
6244 | } | 6242 | } |
6245 | goto again; | 6243 | goto again; |
@@ -6602,9 +6600,9 @@ static struct pipe *parse_stream(char **pstring, | |||
6602 | #endif | 6600 | #endif |
6603 | break; | 6601 | break; |
6604 | case '$': | 6602 | case '$': |
6605 | if (handle_dollar(&ctx.as_string, &dest, input) != 0) { | 6603 | if (parse_dollar(&ctx.as_string, &dest, input) != 0) { |
6606 | debug_printf_parse("parse_stream parse error: " | 6604 | debug_printf_parse("parse_stream parse error: " |
6607 | "handle_dollar returned non-0\n"); | 6605 | "parse_dollar returned non-0\n"); |
6608 | goto parse_error; | 6606 | goto parse_error; |
6609 | } | 6607 | } |
6610 | break; | 6608 | break; |
@@ -6630,19 +6628,16 @@ static struct pipe *parse_stream(char **pstring, | |||
6630 | break; | 6628 | break; |
6631 | #if ENABLE_HUSH_TICK | 6629 | #if ENABLE_HUSH_TICK |
6632 | case '`': { | 6630 | case '`': { |
6633 | #if !BB_MMU | 6631 | unsigned pos; |
6634 | int pos; | 6632 | |
6635 | #endif | ||
6636 | o_addchr(&dest, SPECIAL_VAR_SYMBOL); | 6633 | o_addchr(&dest, SPECIAL_VAR_SYMBOL); |
6637 | o_addchr(&dest, '`'); | 6634 | o_addchr(&dest, '`'); |
6638 | #if !BB_MMU | ||
6639 | pos = dest.length; | 6635 | pos = dest.length; |
6640 | #endif | ||
6641 | add_till_backquote(&dest, input); | 6636 | add_till_backquote(&dest, input); |
6642 | #if !BB_MMU | 6637 | # if !BB_MMU |
6643 | o_addstr(&ctx.as_string, dest.data + pos); | 6638 | o_addstr(&ctx.as_string, dest.data + pos); |
6644 | o_addchr(&ctx.as_string, '`'); | 6639 | o_addchr(&ctx.as_string, '`'); |
6645 | #endif | 6640 | # endif |
6646 | o_addchr(&dest, SPECIAL_VAR_SYMBOL); | 6641 | o_addchr(&dest, SPECIAL_VAR_SYMBOL); |
6647 | //debug_printf_subst("SUBST RES3 '%s'\n", dest.data + pos); | 6642 | //debug_printf_subst("SUBST RES3 '%s'\n", dest.data + pos); |
6648 | break; | 6643 | break; |