diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-04-10 13:09:26 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-04-10 14:23:49 +0200 |
commit | 1c57269b5d1891aef5093e7a5824f1adfbb33847 (patch) | |
tree | 19d79abafd20f2498b699b3cda60f9cd9860cc37 /shell/hush.c | |
parent | 09b7a7ec0ea5ef602ff543dad1a90b6174a4f1c8 (diff) | |
download | busybox-w32-1c57269b5d1891aef5093e7a5824f1adfbb33847.tar.gz busybox-w32-1c57269b5d1891aef5093e7a5824f1adfbb33847.tar.bz2 busybox-w32-1c57269b5d1891aef5093e7a5824f1adfbb33847.zip |
hush: simplify \<newline> code, part 1
function old new delta
parse_stream 2919 2787 -132
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to '')
-rw-r--r-- | shell/hush.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/shell/hush.c b/shell/hush.c index 0c57803f1..94ab45053 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -4913,6 +4913,9 @@ static int encode_string(o_string *as_string, | |||
4913 | ch, ch, !!(dest->o_expflags & EXP_FLAG_ESC_GLOB_CHARS)); | 4913 | ch, ch, !!(dest->o_expflags & EXP_FLAG_ESC_GLOB_CHARS)); |
4914 | if (process_bkslash && ch == '\\') { | 4914 | if (process_bkslash && ch == '\\') { |
4915 | if (next == EOF) { | 4915 | if (next == EOF) { |
4916 | // TODO: what if in interactive shell a file with | ||
4917 | // echo "unterminated string\<eof> | ||
4918 | // is sourced? | ||
4916 | syntax_error("\\<eof>"); | 4919 | syntax_error("\\<eof>"); |
4917 | xfunc_die(); | 4920 | xfunc_die(); |
4918 | } | 4921 | } |
@@ -5051,12 +5054,14 @@ static struct pipe *parse_stream(char **pstring, | |||
5051 | 5054 | ||
5052 | next = '\0'; | 5055 | next = '\0'; |
5053 | if (ch != '\n') { | 5056 | if (ch != '\n') { |
5054 | next = i_peek(input); | 5057 | /* Do not break this case: |
5055 | /* Can't use i_peek_and_eat_bkslash_nl(input) here: | ||
5056 | * echo '\ | 5058 | * echo '\ |
5057 | * ' | 5059 | * ' |
5058 | * will break. | 5060 | * and |
5061 | * echo z\\ | ||
5059 | */ | 5062 | */ |
5063 | next = (ch == '\'' || ch == '\\') ? i_peek(input) : i_peek_and_eat_bkslash_nl(input); | ||
5064 | /// | ||
5060 | } | 5065 | } |
5061 | 5066 | ||
5062 | is_special = "{}<>;&|()#'" /* special outside of "str" */ | 5067 | is_special = "{}<>;&|()#'" /* special outside of "str" */ |
@@ -5260,8 +5265,6 @@ static struct pipe *parse_stream(char **pstring, | |||
5260 | goto parse_error; | 5265 | goto parse_error; |
5261 | } | 5266 | } |
5262 | redir_style = REDIRECT_OVERWRITE; | 5267 | redir_style = REDIRECT_OVERWRITE; |
5263 | if (next == '\\') | ||
5264 | next = i_peek_and_eat_bkslash_nl(input); | ||
5265 | if (next == '>') { | 5268 | if (next == '>') { |
5266 | redir_style = REDIRECT_APPEND; | 5269 | redir_style = REDIRECT_APPEND; |
5267 | ch = i_getch(input); | 5270 | ch = i_getch(input); |
@@ -5282,8 +5285,6 @@ static struct pipe *parse_stream(char **pstring, | |||
5282 | goto parse_error; | 5285 | goto parse_error; |
5283 | } | 5286 | } |
5284 | redir_style = REDIRECT_INPUT; | 5287 | redir_style = REDIRECT_INPUT; |
5285 | if (next == '\\') | ||
5286 | next = i_peek_and_eat_bkslash_nl(input); | ||
5287 | if (next == '<') { | 5288 | if (next == '<') { |
5288 | redir_style = REDIRECT_HEREDOC; | 5289 | redir_style = REDIRECT_HEREDOC; |
5289 | heredoc_cnt++; | 5290 | heredoc_cnt++; |
@@ -5327,6 +5328,7 @@ static struct pipe *parse_stream(char **pstring, | |||
5327 | continue; /* back to top of while (1) */ | 5328 | continue; /* back to top of while (1) */ |
5328 | } | 5329 | } |
5329 | break; | 5330 | break; |
5331 | #if 0 /* looks like we never reach this code */ | ||
5330 | case '\\': | 5332 | case '\\': |
5331 | if (next == '\n') { | 5333 | if (next == '\n') { |
5332 | /* It's "\<newline>" */ | 5334 | /* It's "\<newline>" */ |
@@ -5338,6 +5340,7 @@ static struct pipe *parse_stream(char **pstring, | |||
5338 | continue; /* back to top of while (1) */ | 5340 | continue; /* back to top of while (1) */ |
5339 | } | 5341 | } |
5340 | break; | 5342 | break; |
5343 | #endif | ||
5341 | } | 5344 | } |
5342 | 5345 | ||
5343 | if (ctx.is_assignment == MAYBE_ASSIGNMENT | 5346 | if (ctx.is_assignment == MAYBE_ASSIGNMENT |
@@ -5364,6 +5367,7 @@ static struct pipe *parse_stream(char **pstring, | |||
5364 | break; | 5367 | break; |
5365 | case '\\': | 5368 | case '\\': |
5366 | if (next == EOF) { | 5369 | if (next == EOF) { |
5370 | //TODO: in ". FILE" containing "cmd\" (no newline) bash ignores last "\" | ||
5367 | syntax_error("\\<eof>"); | 5371 | syntax_error("\\<eof>"); |
5368 | xfunc_die(); | 5372 | xfunc_die(); |
5369 | } | 5373 | } |
@@ -5473,8 +5477,6 @@ static struct pipe *parse_stream(char **pstring, | |||
5473 | if (done_word(&ctx)) { | 5477 | if (done_word(&ctx)) { |
5474 | goto parse_error; | 5478 | goto parse_error; |
5475 | } | 5479 | } |
5476 | if (next == '\\') | ||
5477 | next = i_peek_and_eat_bkslash_nl(input); | ||
5478 | if (next == '&') { | 5480 | if (next == '&') { |
5479 | ch = i_getch(input); | 5481 | ch = i_getch(input); |
5480 | nommu_addchr(&ctx.as_string, ch); | 5482 | nommu_addchr(&ctx.as_string, ch); |
@@ -5491,8 +5493,6 @@ static struct pipe *parse_stream(char **pstring, | |||
5491 | if (ctx.ctx_res_w == RES_MATCH) | 5493 | if (ctx.ctx_res_w == RES_MATCH) |
5492 | break; /* we are in case's "word | word)" */ | 5494 | break; /* we are in case's "word | word)" */ |
5493 | #endif | 5495 | #endif |
5494 | if (next == '\\') | ||
5495 | next = i_peek_and_eat_bkslash_nl(input); | ||
5496 | if (next == '|') { /* || */ | 5496 | if (next == '|') { /* || */ |
5497 | ch = i_getch(input); | 5497 | ch = i_getch(input); |
5498 | nommu_addchr(&ctx.as_string, ch); | 5498 | nommu_addchr(&ctx.as_string, ch); |