aboutsummaryrefslogtreecommitdiff
path: root/shell/hush.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-04-10 13:13:10 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2018-04-10 14:23:49 +0200
commite8b1bc0481828d84cea2862eab0ad13a73b0caca (patch)
tree802d2103a8374f6b3d3be0370c9263e69caf8fc4 /shell/hush.c
parent1c57269b5d1891aef5093e7a5824f1adfbb33847 (diff)
downloadbusybox-w32-e8b1bc0481828d84cea2862eab0ad13a73b0caca.tar.gz
busybox-w32-e8b1bc0481828d84cea2862eab0ad13a73b0caca.tar.bz2
busybox-w32-e8b1bc0481828d84cea2862eab0ad13a73b0caca.zip
hush: simplify \<newline> code, part 2
function old new delta parse_stream 2787 2780 -7 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to '')
-rw-r--r--shell/hush.c60
1 files changed, 30 insertions, 30 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 94ab45053..3c6718648 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -5364,7 +5364,7 @@ static struct pipe *parse_stream(char **pstring,
5364 case '#': 5364 case '#':
5365 /* non-comment #: "echo a#b" etc */ 5365 /* non-comment #: "echo a#b" etc */
5366 o_addchr(&ctx.word, ch); 5366 o_addchr(&ctx.word, ch);
5367 break; 5367 continue; /* get next char */
5368 case '\\': 5368 case '\\':
5369 if (next == EOF) { 5369 if (next == EOF) {
5370//TODO: in ". FILE" containing "cmd\" (no newline) bash ignores last "\" 5370//TODO: in ". FILE" containing "cmd\" (no newline) bash ignores last "\"
@@ -5380,51 +5380,51 @@ static struct pipe *parse_stream(char **pstring,
5380 /* Example: echo Hello \2>file 5380 /* Example: echo Hello \2>file
5381 * we need to know that word 2 is quoted */ 5381 * we need to know that word 2 is quoted */
5382 ctx.word.has_quoted_part = 1; 5382 ctx.word.has_quoted_part = 1;
5383 break; 5383 continue; /* get next char */
5384 case '$': 5384 case '$':
5385 if (!parse_dollar(&ctx.as_string, &ctx.word, input, /*quote_mask:*/ 0)) { 5385 if (!parse_dollar(&ctx.as_string, &ctx.word, input, /*quote_mask:*/ 0)) {
5386 debug_printf_parse("parse_stream parse error: " 5386 debug_printf_parse("parse_stream parse error: "
5387 "parse_dollar returned 0 (error)\n"); 5387 "parse_dollar returned 0 (error)\n");
5388 goto parse_error; 5388 goto parse_error;
5389 } 5389 }
5390 break; 5390 continue; /* get next char */
5391 case '\'': 5391 case '\'':
5392 ctx.word.has_quoted_part = 1; 5392 ctx.word.has_quoted_part = 1;
5393 if (next == '\'' && !ctx.pending_redirect) { 5393 if (next == '\'' && !ctx.pending_redirect)
5394 goto insert_empty_quoted_str_marker;
5395 while (1) {
5396 ch = i_getch(input);
5397 if (ch == EOF) {
5398 syntax_error_unterm_ch('\'');
5399 goto parse_error;
5400 }
5401 nommu_addchr(&ctx.as_string, ch);
5402 if (ch == '\'')
5403 break;
5404 if (ch == SPECIAL_VAR_SYMBOL) {
5405 /* Convert raw ^C to corresponding special variable reference */
5406 o_addchr(&ctx.word, SPECIAL_VAR_SYMBOL);
5407 o_addchr(&ctx.word, SPECIAL_VAR_QUOTED_SVS);
5408 }
5409 o_addqchr(&ctx.word, ch);
5410 }
5411 continue; /* get next char */
5412 case '"':
5413 ctx.word.has_quoted_part = 1;
5414 if (next == '"' && !ctx.pending_redirect) {
5394 insert_empty_quoted_str_marker: 5415 insert_empty_quoted_str_marker:
5395 nommu_addchr(&ctx.as_string, next); 5416 nommu_addchr(&ctx.as_string, next);
5396 i_getch(input); /* eat second ' */ 5417 i_getch(input); /* eat second ' */
5397 o_addchr(&ctx.word, SPECIAL_VAR_SYMBOL); 5418 o_addchr(&ctx.word, SPECIAL_VAR_SYMBOL);
5398 o_addchr(&ctx.word, SPECIAL_VAR_SYMBOL); 5419 o_addchr(&ctx.word, SPECIAL_VAR_SYMBOL);
5399 } else { 5420 continue; /* get next char */
5400 while (1) {
5401 ch = i_getch(input);
5402 if (ch == EOF) {
5403 syntax_error_unterm_ch('\'');
5404 goto parse_error;
5405 }
5406 nommu_addchr(&ctx.as_string, ch);
5407 if (ch == '\'')
5408 break;
5409 if (ch == SPECIAL_VAR_SYMBOL) {
5410 /* Convert raw ^C to corresponding special variable reference */
5411 o_addchr(&ctx.word, SPECIAL_VAR_SYMBOL);
5412 o_addchr(&ctx.word, SPECIAL_VAR_QUOTED_SVS);
5413 }
5414 o_addqchr(&ctx.word, ch);
5415 }
5416 } 5421 }
5417 break;
5418 case '"':
5419 ctx.word.has_quoted_part = 1;
5420 if (next == '"' && !ctx.pending_redirect)
5421 goto insert_empty_quoted_str_marker;
5422 if (ctx.is_assignment == NOT_ASSIGNMENT) 5422 if (ctx.is_assignment == NOT_ASSIGNMENT)
5423 ctx.word.o_expflags |= EXP_FLAG_ESC_GLOB_CHARS; 5423 ctx.word.o_expflags |= EXP_FLAG_ESC_GLOB_CHARS;
5424 if (!encode_string(&ctx.as_string, &ctx.word, input, '"', /*process_bkslash:*/ 1)) 5424 if (!encode_string(&ctx.as_string, &ctx.word, input, '"', /*process_bkslash:*/ 1))
5425 goto parse_error; 5425 goto parse_error;
5426 ctx.word.o_expflags &= ~EXP_FLAG_ESC_GLOB_CHARS; 5426 ctx.word.o_expflags &= ~EXP_FLAG_ESC_GLOB_CHARS;
5427 break; 5427 continue; /* get next char */
5428#if ENABLE_HUSH_TICK 5428#if ENABLE_HUSH_TICK
5429 case '`': { 5429 case '`': {
5430 USE_FOR_NOMMU(unsigned pos;) 5430 USE_FOR_NOMMU(unsigned pos;)
@@ -5440,7 +5440,7 @@ static struct pipe *parse_stream(char **pstring,
5440# endif 5440# endif
5441 o_addchr(&ctx.word, SPECIAL_VAR_SYMBOL); 5441 o_addchr(&ctx.word, SPECIAL_VAR_SYMBOL);
5442 //debug_printf_subst("SUBST RES3 '%s'\n", ctx.word.data + pos); 5442 //debug_printf_subst("SUBST RES3 '%s'\n", ctx.word.data + pos);
5443 break; 5443 continue; /* get next char */
5444 } 5444 }
5445#endif 5445#endif
5446 case ';': 5446 case ';':
@@ -5472,7 +5472,7 @@ static struct pipe *parse_stream(char **pstring,
5472 * with an assignment */ 5472 * with an assignment */
5473 ctx.is_assignment = MAYBE_ASSIGNMENT; 5473 ctx.is_assignment = MAYBE_ASSIGNMENT;
5474 debug_printf_parse("ctx.is_assignment='%s'\n", assignment_flag[ctx.is_assignment]); 5474 debug_printf_parse("ctx.is_assignment='%s'\n", assignment_flag[ctx.is_assignment]);
5475 break; 5475 continue; /* get next char */
5476 case '&': 5476 case '&':
5477 if (done_word(&ctx)) { 5477 if (done_word(&ctx)) {
5478 goto parse_error; 5478 goto parse_error;
@@ -5512,7 +5512,7 @@ static struct pipe *parse_stream(char **pstring,
5512 && ctx.word.length == 0 /* not word(... */ 5512 && ctx.word.length == 0 /* not word(... */
5513 && ctx.word.has_quoted_part == 0 /* not ""(... */ 5513 && ctx.word.has_quoted_part == 0 /* not ""(... */
5514 ) { 5514 ) {
5515 continue; 5515 continue; /* get next char */
5516 } 5516 }
5517#endif 5517#endif
5518 case '{': 5518 case '{':