aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2025-08-14 11:08:08 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2025-08-14 11:08:08 +0200
commit4343ca9aa879cabc52ff82c0a46d3ba20d7fec5c (patch)
tree9c2b3135f6e8b8258e248134cfa1303f3875202d /shell
parent279371471e3c2476cfd6b54297a1b2a773112ac8 (diff)
downloadbusybox-w32-4343ca9aa879cabc52ff82c0a46d3ba20d7fec5c.tar.gz
busybox-w32-4343ca9aa879cabc52ff82c0a46d3ba20d7fec5c.tar.bz2
busybox-w32-4343ca9aa879cabc52ff82c0a46d3ba20d7fec5c.zip
hush: improve code readability, no logic changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r--shell/hush.c47
1 files changed, 25 insertions, 22 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 6a6c1c5a0..d65da3b98 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -5657,8 +5657,13 @@ static struct pipe *parse_stream(char **pstring,
5657 if (ch == '\'') { 5657 if (ch == '\'') {
5658 ctx.word.has_quoted_part = 1; 5658 ctx.word.has_quoted_part = 1;
5659 next = i_getch(input); 5659 next = i_getch(input);
5660 if (next == '\'' && !ctx.pending_redirect/*why?*/) 5660 if (next == '\'' && !ctx.pending_redirect/*why?*/) {
5661 goto insert_empty_quoted_str_marker; 5661 insert_empty_quoted_str_marker:
5662 nommu_addchr(&ctx.as_string, next);
5663 o_addchr(&ctx.word, SPECIAL_VAR_SYMBOL);
5664 o_addchr(&ctx.word, SPECIAL_VAR_SYMBOL);
5665 continue; /* get next char */
5666 }
5662 ch = next; 5667 ch = next;
5663 while (1) { 5668 while (1) {
5664 if (ch == EOF) { 5669 if (ch == EOF) {
@@ -5818,7 +5823,7 @@ static struct pipe *parse_stream(char **pstring,
5818 } 5823 }
5819 if (!IS_NULL_PIPE(ctx.pipe)) /* CMD | } */ 5824 if (!IS_NULL_PIPE(ctx.pipe)) /* CMD | } */
5820 /* Can't be an end of {CMD}, skip the check */ 5825 /* Can't be an end of {CMD}, skip the check */
5821 goto skip_end_trigger; 5826 goto rbrace_skips_end_trigger;
5822 /* else: } does terminate a group */ 5827 /* else: } does terminate a group */
5823 } 5828 }
5824 term_group: 5829 term_group:
@@ -5841,6 +5846,7 @@ static struct pipe *parse_stream(char **pstring,
5841 ctx.is_assignment = MAYBE_ASSIGNMENT; 5846 ctx.is_assignment = MAYBE_ASSIGNMENT;
5842 debug_printf_parse("ctx.is_assignment='%s'\n", assignment_flag[ctx.is_assignment]); 5847 debug_printf_parse("ctx.is_assignment='%s'\n", assignment_flag[ctx.is_assignment]);
5843 /* Do we sit outside of any if's, loops or case's? */ 5848 /* Do we sit outside of any if's, loops or case's? */
5849//TODO? just check ctx.stack != NULL instead?
5844 if (!HAS_KEYWORDS 5850 if (!HAS_KEYWORDS
5845 IF_HAS_KEYWORDS(|| (ctx.ctx_res_w == RES_NONE && ctx.old_flag == 0)) 5851 IF_HAS_KEYWORDS(|| (ctx.ctx_res_w == RES_NONE && ctx.old_flag == 0))
5846 ) { 5852 ) {
@@ -5940,7 +5946,7 @@ static struct pipe *parse_stream(char **pstring,
5940 } 5946 }
5941 break; 5947 break;
5942 } 5948 }
5943 skip_end_trigger: 5949 rbrace_skips_end_trigger:
5944 5950
5945 if (ctx.is_assignment == MAYBE_ASSIGNMENT 5951 if (ctx.is_assignment == MAYBE_ASSIGNMENT
5946 /* check that we are not in word in "a=1 2>word b=1": */ 5952 /* check that we are not in word in "a=1 2>word b=1": */
@@ -5978,11 +5984,7 @@ static struct pipe *parse_stream(char **pstring,
5978 ctx.word.has_quoted_part = 1; 5984 ctx.word.has_quoted_part = 1;
5979 if (next == '"' && !ctx.pending_redirect) { 5985 if (next == '"' && !ctx.pending_redirect) {
5980 i_getch(input); /* eat second " */ 5986 i_getch(input); /* eat second " */
5981 insert_empty_quoted_str_marker: 5987 goto insert_empty_quoted_str_marker;
5982 nommu_addchr(&ctx.as_string, next);
5983 o_addchr(&ctx.word, SPECIAL_VAR_SYMBOL);
5984 o_addchr(&ctx.word, SPECIAL_VAR_SYMBOL);
5985 continue; /* get next char */
5986 } 5988 }
5987 if (ctx.is_assignment == NOT_ASSIGNMENT) 5989 if (ctx.is_assignment == NOT_ASSIGNMENT)
5988 ctx.word.o_expflags |= EXP_FLAG_GLOBPROTECT_CHARS; 5990 ctx.word.o_expflags |= EXP_FLAG_GLOBPROTECT_CHARS;
@@ -6181,8 +6183,6 @@ static struct pipe *parse_stream(char **pstring,
6181 G.last_exitcode = 1; 6183 G.last_exitcode = 1;
6182 parse_error: 6184 parse_error:
6183 { 6185 {
6184 struct parse_context *pctx IF_HAS_KEYWORDS(, *p2;);
6185
6186 /* Clean up allocated tree. 6186 /* Clean up allocated tree.
6187 * Sample for finding leaks on syntax error recovery path. 6187 * Sample for finding leaks on syntax error recovery path.
6188 * Run it from interactive shell, watch pmap `pidof hush`. 6188 * Run it from interactive shell, watch pmap `pidof hush`.
@@ -6191,7 +6191,8 @@ static struct pipe *parse_stream(char **pstring,
6191 * while if (true | { true;}); then echo ok; fi; do break; done 6191 * while if (true | { true;}); then echo ok; fi; do break; done
6192 * while if (true | { true;}); then echo ok; fi; do (if echo ok; break; then :; fi) | cat; break; done 6192 * while if (true | { true;}); then echo ok; fi; do (if echo ok; break; then :; fi) | cat; break; done
6193 */ 6193 */
6194 pctx = &ctx; 6194 IF_HAS_KEYWORDS(struct parse_context *stk;)
6195 struct parse_context *pctx = &ctx;
6195 do { 6196 do {
6196 /* Update pipe/command counts, 6197 /* Update pipe/command counts,
6197 * otherwise freeing may miss some */ 6198 * otherwise freeing may miss some */
@@ -6203,20 +6204,19 @@ static struct pipe *parse_stream(char **pstring,
6203#if !BB_MMU 6204#if !BB_MMU
6204 o_free(&pctx->as_string); 6205 o_free(&pctx->as_string);
6205#endif 6206#endif
6206 IF_HAS_KEYWORDS(p2 = pctx->stack;) 6207 IF_HAS_KEYWORDS(stk = pctx->stack;)
6207 if (pctx != &ctx) 6208 if (pctx != &ctx)
6208 free(pctx); 6209 free(pctx);
6209 IF_HAS_KEYWORDS(pctx = p2;) 6210 IF_HAS_KEYWORDS(pctx = stk;)
6210 } while (HAS_KEYWORDS && pctx); 6211 } while (HAS_KEYWORDS && pctx);
6211 6212 }
6212 o_free(&ctx.word); 6213 o_free(&ctx.word);
6213#if !BB_MMU 6214#if !BB_MMU
6214 if (pstring) 6215 if (pstring)
6215 *pstring = NULL; 6216 *pstring = NULL;
6216#endif 6217#endif
6217 debug_leave(); 6218 debug_leave();
6218 return ERR_PTR; 6219 return ERR_PTR;
6219 }
6220} 6220}
6221 6221
6222/* 6222/*
@@ -6547,7 +6547,10 @@ static NOINLINE int encode_then_append_var_plusminus(o_string *output, int n,
6547 if (!dest.o_expflags) { 6547 if (!dest.o_expflags) {
6548 if (ch == EOF) 6548 if (ch == EOF)
6549 break; 6549 break;
6550 if (!dquoted && !(output->o_expflags & EXP_FLAG_SINGLEWORD) && strchr(G.ifs, ch)) { 6550 if (!dquoted
6551 && !(output->o_expflags & EXP_FLAG_SINGLEWORD)
6552 && strchr(G.ifs, ch)
6553 ) {
6551 /* PREFIX${x:d${e}f ...} and we met space: expand "d${e}f" and start new word. 6554 /* PREFIX${x:d${e}f ...} and we met space: expand "d${e}f" and start new word.
6552 * do not assume we are at the start of the word (PREFIX above). 6555 * do not assume we are at the start of the word (PREFIX above).
6553 */ 6556 */