diff options
author | Denys Vlasenko <dvlasenk@redhat.com> | 2010-09-09 12:40:03 +0200 |
---|---|---|
committer | Denys Vlasenko <dvlasenk@redhat.com> | 2010-09-09 12:40:03 +0200 |
commit | 77a7b5519cace3722832d03ce09faa950841b509 (patch) | |
tree | ef31619a60d06f5b796e8179a5d7533a0b59adab | |
parent | 77d48726917e6493a8a077be93bb07b22fd2c209 (diff) | |
download | busybox-w32-77a7b5519cace3722832d03ce09faa950841b509.tar.gz busybox-w32-77a7b5519cace3722832d03ce09faa950841b509.tar.bz2 busybox-w32-77a7b5519cace3722832d03ce09faa950841b509.zip |
hush: straighten out the logic in parse_stream
function old new delta
parse_stream 2399 2354 -45
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
-rw-r--r-- | shell/hush.c | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/shell/hush.c b/shell/hush.c index 1ba72f0d7..d76fe85f6 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -3833,11 +3833,9 @@ static struct pipe *parse_stream(char **pstring, | |||
3833 | { | 3833 | { |
3834 | struct parse_context ctx; | 3834 | struct parse_context ctx; |
3835 | o_string dest = NULL_O_STRING; | 3835 | o_string dest = NULL_O_STRING; |
3836 | int is_in_dquote; | ||
3837 | int heredoc_cnt; | 3836 | int heredoc_cnt; |
3838 | 3837 | ||
3839 | /* Double-quote state is handled in the state variable is_in_dquote. | 3838 | /* Single-quote triggers a bypass of the main loop until its mate is |
3840 | * A single-quote triggers a bypass of the main loop until its mate is | ||
3841 | * found. When recursing, quote state is passed in via dest->o_expflags. | 3839 | * found. When recursing, quote state is passed in via dest->o_expflags. |
3842 | */ | 3840 | */ |
3843 | debug_printf_parse("parse_stream entered, end_trigger='%c'\n", | 3841 | debug_printf_parse("parse_stream entered, end_trigger='%c'\n", |
@@ -3851,15 +3849,17 @@ static struct pipe *parse_stream(char **pstring, | |||
3851 | 3849 | ||
3852 | /* We used to separate words on $IFS here. This was wrong. | 3850 | /* We used to separate words on $IFS here. This was wrong. |
3853 | * $IFS is used only for word splitting when $var is expanded, | 3851 | * $IFS is used only for word splitting when $var is expanded, |
3854 | * here we should use blank chars as separators, not $iFS | 3852 | * here we should use blank chars as separators, not $IFS |
3855 | */ | 3853 | */ |
3856 | reset: | 3854 | |
3855 | reset: /* we come back here only on syntax errors in interactive shell */ | ||
3856 | |||
3857 | #if ENABLE_HUSH_INTERACTIVE | 3857 | #if ENABLE_HUSH_INTERACTIVE |
3858 | input->promptmode = 0; /* PS1 */ | 3858 | input->promptmode = 0; /* PS1 */ |
3859 | #endif | 3859 | #endif |
3860 | /* dest.o_assignment = MAYBE_ASSIGNMENT; - already is */ | 3860 | if (MAYBE_ASSIGNMENT != 0) |
3861 | dest.o_assignment = MAYBE_ASSIGNMENT; | ||
3861 | initialize_context(&ctx); | 3862 | initialize_context(&ctx); |
3862 | is_in_dquote = 0; | ||
3863 | heredoc_cnt = 0; | 3863 | heredoc_cnt = 0; |
3864 | while (1) { | 3864 | while (1) { |
3865 | const char *is_blank; | 3865 | const char *is_blank; |
@@ -3869,14 +3869,6 @@ static struct pipe *parse_stream(char **pstring, | |||
3869 | int redir_fd; | 3869 | int redir_fd; |
3870 | redir_type redir_style; | 3870 | redir_type redir_style; |
3871 | 3871 | ||
3872 | if (is_in_dquote) { | ||
3873 | /* dest.has_quoted_part = 1; - already is (see below) */ | ||
3874 | if (parse_stream_dquoted(&ctx.as_string, &dest, input, '"')) { | ||
3875 | goto parse_error; | ||
3876 | } | ||
3877 | /* We reached closing '"' */ | ||
3878 | is_in_dquote = 0; | ||
3879 | } | ||
3880 | ch = i_getch(input); | 3872 | ch = i_getch(input); |
3881 | debug_printf_parse(": ch=%c (%d) escape=%d\n", | 3873 | debug_printf_parse(": ch=%c (%d) escape=%d\n", |
3882 | ch, ch, !!(dest.o_expflags & EXP_FLAG_ESC_GLOB_CHARS)); | 3874 | ch, ch, !!(dest.o_expflags & EXP_FLAG_ESC_GLOB_CHARS)); |
@@ -4176,9 +4168,10 @@ static struct pipe *parse_stream(char **pstring, | |||
4176 | break; | 4168 | break; |
4177 | case '"': | 4169 | case '"': |
4178 | dest.has_quoted_part = 1; | 4170 | dest.has_quoted_part = 1; |
4179 | is_in_dquote ^= 1; /* invert */ | ||
4180 | if (dest.o_assignment == NOT_ASSIGNMENT) | 4171 | if (dest.o_assignment == NOT_ASSIGNMENT) |
4181 | dest.o_expflags ^= EXP_FLAG_ESC_GLOB_CHARS; | 4172 | dest.o_expflags ^= EXP_FLAG_ESC_GLOB_CHARS; |
4173 | if (parse_stream_dquoted(&ctx.as_string, &dest, input, '"')) | ||
4174 | goto parse_error; | ||
4182 | break; | 4175 | break; |
4183 | #if ENABLE_HUSH_TICK | 4176 | #if ENABLE_HUSH_TICK |
4184 | case '`': { | 4177 | case '`': { |
@@ -4558,7 +4551,7 @@ static NOINLINE const char *expand_one_var(char **to_be_freed_pp, char *arg, cha | |||
4558 | 4551 | ||
4559 | /* Look up the variable in question */ | 4552 | /* Look up the variable in question */ |
4560 | if (isdigit(var[0])) { | 4553 | if (isdigit(var[0])) { |
4561 | /* parse_dollar() should have vetted var for us */ | 4554 | /* parse_dollar should have vetted var for us */ |
4562 | int n = xatoi_positive(var); | 4555 | int n = xatoi_positive(var); |
4563 | if (n < G.global_argc) | 4556 | if (n < G.global_argc) |
4564 | val = G.global_argv[n]; | 4557 | val = G.global_argv[n]; |