diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-02-13 15:30:13 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-02-13 15:31:19 +0100 |
commit | aa617ac09703f31e9f80836f8d8f9349b52578ee (patch) | |
tree | 8fcfa982a5067107e514c3b299571bd5feb7099a | |
parent | 8de5b9f88ba9fe2f203abab9ca7d85129c3eb679 (diff) | |
download | busybox-w32-aa617ac09703f31e9f80836f8d8f9349b52578ee.tar.gz busybox-w32-aa617ac09703f31e9f80836f8d8f9349b52578ee.tar.bz2 busybox-w32-aa617ac09703f31e9f80836f8d8f9349b52578ee.zip |
hush: simplify process_command_subs()
Incidentally, this fixes LINENO bug here:
echo "1:${LINENO}"
echo "2:`echo; echo`" # was counting lines in the `cmd` output as LINENO++
echo "3:${LINENO}"
function old new delta
parse_and_run_file 53 71 +18
expand_vars_to_list 1187 1164 -23
setup_file_in_str 25 - -25
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/1 up/down: 18/-48) Total: -30 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/hush.c | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/shell/hush.c b/shell/hush.c index 8f1017e3c..e005b0a20 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -6614,24 +6614,22 @@ static void parse_and_run_stream(struct in_str *inp, int end_trigger) | |||
6614 | static void parse_and_run_string(const char *s) | 6614 | static void parse_and_run_string(const char *s) |
6615 | { | 6615 | { |
6616 | struct in_str input; | 6616 | struct in_str input; |
6617 | //IF_HUSH_LINENO_VAR(unsigned sv = G.lineno;) | ||
6618 | |||
6617 | setup_string_in_str(&input, s); | 6619 | setup_string_in_str(&input, s); |
6618 | parse_and_run_stream(&input, '\0'); | 6620 | parse_and_run_stream(&input, '\0'); |
6621 | //IF_HUSH_LINENO_VAR(G.lineno = sv;) | ||
6619 | } | 6622 | } |
6620 | 6623 | ||
6621 | static void parse_and_run_file(FILE *f) | 6624 | static void parse_and_run_file(FILE *f) |
6622 | { | 6625 | { |
6623 | struct in_str input; | 6626 | struct in_str input; |
6624 | #if ENABLE_HUSH_LINENO_VAR | 6627 | IF_HUSH_LINENO_VAR(unsigned sv = G.lineno;) |
6625 | unsigned sv; | ||
6626 | 6628 | ||
6627 | sv = G.lineno; | 6629 | IF_HUSH_LINENO_VAR(G.lineno = 1;) |
6628 | G.lineno = 1; | ||
6629 | #endif | ||
6630 | setup_file_in_str(&input, f); | 6630 | setup_file_in_str(&input, f); |
6631 | parse_and_run_stream(&input, ';'); | 6631 | parse_and_run_stream(&input, ';'); |
6632 | #if ENABLE_HUSH_LINENO_VAR | 6632 | IF_HUSH_LINENO_VAR(G.lineno = sv;) |
6633 | G.lineno = sv; | ||
6634 | #endif | ||
6635 | } | 6633 | } |
6636 | 6634 | ||
6637 | #if ENABLE_HUSH_TICK | 6635 | #if ENABLE_HUSH_TICK |
@@ -6744,16 +6742,16 @@ static FILE *generate_stream_from_string(const char *s, pid_t *pid_p) | |||
6744 | static int process_command_subs(o_string *dest, const char *s) | 6742 | static int process_command_subs(o_string *dest, const char *s) |
6745 | { | 6743 | { |
6746 | FILE *fp; | 6744 | FILE *fp; |
6747 | struct in_str pipe_str; | ||
6748 | pid_t pid; | 6745 | pid_t pid; |
6749 | int status, ch, eol_cnt; | 6746 | int status, ch, eol_cnt; |
6750 | 6747 | ||
6751 | fp = generate_stream_from_string(s, &pid); | 6748 | fp = generate_stream_from_string(s, &pid); |
6752 | 6749 | ||
6753 | /* Now send results of command back into original context */ | 6750 | /* Now send results of command back into original context */ |
6754 | setup_file_in_str(&pipe_str, fp); | ||
6755 | eol_cnt = 0; | 6751 | eol_cnt = 0; |
6756 | while ((ch = i_getch(&pipe_str)) != EOF) { | 6752 | while ((ch = getc(fp)) != EOF) { |
6753 | if (ch == '\0') | ||
6754 | continue; | ||
6757 | if (ch == '\n') { | 6755 | if (ch == '\n') { |
6758 | eol_cnt++; | 6756 | eol_cnt++; |
6759 | continue; | 6757 | continue; |