diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-07-20 14:24:56 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-07-20 16:27:26 +0200 |
commit | 18e8b6129298c02f7b5ccc17fee6bccc01a8968f (patch) | |
tree | 8b619c709da0259dc759ff6683dcd18fe89f5f72 /shell | |
parent | 168579a34c6fc6c2f2cd20256367ceb61f50bf68 (diff) | |
download | busybox-w32-18e8b6129298c02f7b5ccc17fee6bccc01a8968f.tar.gz busybox-w32-18e8b6129298c02f7b5ccc17fee6bccc01a8968f.tar.bz2 busybox-w32-18e8b6129298c02f7b5ccc17fee6bccc01a8968f.zip |
hush: remove pointless "next" var, simplify expand_vars_to_list()
function old new delta
o_addstr - 26 +26
expand_vars_to_list 1112 1117 +5
encode_then_expand_vararg 398 382 -16
parse_dollar 779 762 -17
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/2 up/down: 31/-33) Total: -2 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r-- | shell/hush.c | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/shell/hush.c b/shell/hush.c index 2d4e3fa66..fca67dc17 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -475,6 +475,7 @@ | |||
475 | #endif | 475 | #endif |
476 | 476 | ||
477 | #define SPECIAL_VAR_SYMBOL_STR "\3" | 477 | #define SPECIAL_VAR_SYMBOL_STR "\3" |
478 | #define SPECIAL_VAR_SYMBOL_CHR '\3' | ||
478 | #define SPECIAL_VAR_SYMBOL 3 | 479 | #define SPECIAL_VAR_SYMBOL 3 |
479 | /* The "variable" with name "\1" emits string "\3". Testcase: "echo ^C" */ | 480 | /* The "variable" with name "\1" emits string "\3". Testcase: "echo ^C" */ |
480 | #define SPECIAL_VAR_QUOTED_SVS 1 | 481 | #define SPECIAL_VAR_QUOTED_SVS 1 |
@@ -5797,7 +5798,6 @@ static char *encode_then_expand_vararg(const char *str, int handle_squotes, int | |||
5797 | 5798 | ||
5798 | for (;;) { | 5799 | for (;;) { |
5799 | int ch; | 5800 | int ch; |
5800 | int next; | ||
5801 | 5801 | ||
5802 | ch = i_getch(&input); | 5802 | ch = i_getch(&input); |
5803 | if (ch == EOF) { | 5803 | if (ch == EOF) { |
@@ -5837,10 +5837,6 @@ static char *encode_then_expand_vararg(const char *str, int handle_squotes, int | |||
5837 | o_addqchr(&dest, ch); | 5837 | o_addqchr(&dest, ch); |
5838 | continue; | 5838 | continue; |
5839 | } | 5839 | } |
5840 | next = '\0'; | ||
5841 | if (ch != '\n') { | ||
5842 | next = i_peek(&input); | ||
5843 | } | ||
5844 | if (ch == '$') { | 5840 | if (ch == '$') { |
5845 | if (!parse_dollar(NULL, &dest, &input, /*quote_mask:*/ 0x80)) { | 5841 | if (!parse_dollar(NULL, &dest, &input, /*quote_mask:*/ 0x80)) { |
5846 | debug_printf_parse("%s: error: parse_dollar returned 0 (error)\n", __func__); | 5842 | debug_printf_parse("%s: error: parse_dollar returned 0 (error)\n", __func__); |
@@ -5956,7 +5952,7 @@ static char *replace_pattern(char *val, const char *pattern, const char *repl, c | |||
5956 | #endif /* BASH_PATTERN_SUBST */ | 5952 | #endif /* BASH_PATTERN_SUBST */ |
5957 | 5953 | ||
5958 | static int append_str_maybe_ifs_split(o_string *output, int n, | 5954 | static int append_str_maybe_ifs_split(o_string *output, int n, |
5959 | int first_ch, const char *val) | 5955 | int first_ch, const char *val) |
5960 | { | 5956 | { |
5961 | if (!(first_ch & 0x80)) { /* unquoted $VAR */ | 5957 | if (!(first_ch & 0x80)) { /* unquoted $VAR */ |
5962 | debug_printf_expand("unquoted '%s', output->o_escape:%d\n", val, | 5958 | debug_printf_expand("unquoted '%s', output->o_escape:%d\n", val, |
@@ -6348,7 +6344,6 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg) | |||
6348 | 6344 | ||
6349 | while ((p = strchr(arg, SPECIAL_VAR_SYMBOL)) != NULL) { | 6345 | while ((p = strchr(arg, SPECIAL_VAR_SYMBOL)) != NULL) { |
6350 | char first_ch; | 6346 | char first_ch; |
6351 | const char *val = NULL; | ||
6352 | #if ENABLE_FEATURE_SH_MATH | 6347 | #if ENABLE_FEATURE_SH_MATH |
6353 | char arith_buf[sizeof(arith_t)*3 + 2]; | 6348 | char arith_buf[sizeof(arith_t)*3 + 2]; |
6354 | #endif | 6349 | #endif |
@@ -6424,19 +6419,23 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg) | |||
6424 | } | 6419 | } |
6425 | break; | 6420 | break; |
6426 | } | 6421 | } |
6427 | case SPECIAL_VAR_SYMBOL: /* <SPECIAL_VAR_SYMBOL><SPECIAL_VAR_SYMBOL> */ | 6422 | case SPECIAL_VAR_SYMBOL: { |
6423 | /* <SPECIAL_VAR_SYMBOL><SPECIAL_VAR_SYMBOL> */ | ||
6428 | /* "Empty variable", used to make "" etc to not disappear */ | 6424 | /* "Empty variable", used to make "" etc to not disappear */ |
6429 | output->has_quoted_part = 1; | 6425 | output->has_quoted_part = 1; |
6430 | arg++; | ||
6431 | cant_be_null = 0x80; | 6426 | cant_be_null = 0x80; |
6427 | arg++; | ||
6432 | break; | 6428 | break; |
6429 | } | ||
6433 | case SPECIAL_VAR_QUOTED_SVS: | 6430 | case SPECIAL_VAR_QUOTED_SVS: |
6434 | /* <SPECIAL_VAR_SYMBOL><SPECIAL_VAR_QUOTED_SVS><SPECIAL_VAR_SYMBOL> */ | 6431 | /* <SPECIAL_VAR_SYMBOL><SPECIAL_VAR_QUOTED_SVS><SPECIAL_VAR_SYMBOL> */ |
6432 | /* "^C variable", represents literal ^C char (possible in scripts) */ | ||
6433 | o_addchr(output, SPECIAL_VAR_SYMBOL_CHR); | ||
6435 | arg++; | 6434 | arg++; |
6436 | val = SPECIAL_VAR_SYMBOL_STR; | ||
6437 | break; | 6435 | break; |
6438 | #if ENABLE_HUSH_TICK | 6436 | #if ENABLE_HUSH_TICK |
6439 | case '`': { /* <SPECIAL_VAR_SYMBOL>`cmd<SPECIAL_VAR_SYMBOL> */ | 6437 | case '`': { |
6438 | /* <SPECIAL_VAR_SYMBOL>`cmd<SPECIAL_VAR_SYMBOL> */ | ||
6440 | o_string subst_result = NULL_O_STRING; | 6439 | o_string subst_result = NULL_O_STRING; |
6441 | 6440 | ||
6442 | *p = '\0'; /* replace trailing <SPECIAL_VAR_SYMBOL> */ | 6441 | *p = '\0'; /* replace trailing <SPECIAL_VAR_SYMBOL> */ |
@@ -6450,11 +6449,12 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg) | |||
6450 | debug_printf_subst("SUBST RES:%d '%s'\n", G.last_exitcode, subst_result.data); | 6449 | debug_printf_subst("SUBST RES:%d '%s'\n", G.last_exitcode, subst_result.data); |
6451 | n = append_str_maybe_ifs_split(output, n, first_ch, subst_result.data); | 6450 | n = append_str_maybe_ifs_split(output, n, first_ch, subst_result.data); |
6452 | o_free_unsafe(&subst_result); | 6451 | o_free_unsafe(&subst_result); |
6453 | goto restore; | 6452 | break; |
6454 | } | 6453 | } |
6455 | #endif | 6454 | #endif |
6456 | #if ENABLE_FEATURE_SH_MATH | 6455 | #if ENABLE_FEATURE_SH_MATH |
6457 | case '+': { /* <SPECIAL_VAR_SYMBOL>+cmd<SPECIAL_VAR_SYMBOL> */ | 6456 | case '+': { |
6457 | /* <SPECIAL_VAR_SYMBOL>+arith<SPECIAL_VAR_SYMBOL> */ | ||
6458 | arith_t res; | 6458 | arith_t res; |
6459 | 6459 | ||
6460 | arg++; /* skip '+' */ | 6460 | arg++; /* skip '+' */ |
@@ -6463,19 +6463,16 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg) | |||
6463 | res = expand_and_evaluate_arith(arg, NULL); | 6463 | res = expand_and_evaluate_arith(arg, NULL); |
6464 | debug_printf_subst("ARITH RES '"ARITH_FMT"'\n", res); | 6464 | debug_printf_subst("ARITH RES '"ARITH_FMT"'\n", res); |
6465 | sprintf(arith_buf, ARITH_FMT, res); | 6465 | sprintf(arith_buf, ARITH_FMT, res); |
6466 | val = arith_buf; | 6466 | o_addstr(output, arith_buf); |
6467 | break; | 6467 | break; |
6468 | } | 6468 | } |
6469 | #endif | 6469 | #endif |
6470 | default: | 6470 | default: |
6471 | /* <SPECIAL_VAR_SYMBOL>varname[ops]<SPECIAL_VAR_SYMBOL> */ | ||
6471 | n = expand_one_var(output, n, first_ch, arg, &p); | 6472 | n = expand_one_var(output, n, first_ch, arg, &p); |
6472 | goto restore; | 6473 | break; |
6473 | } /* switch (char after <SPECIAL_VAR_SYMBOL>) */ | 6474 | } /* switch (char after <SPECIAL_VAR_SYMBOL>) */ |
6474 | 6475 | ||
6475 | if (val && val[0]) { | ||
6476 | o_addQstr(output, val); | ||
6477 | } | ||
6478 | restore: | ||
6479 | /* Restore NULL'ed SPECIAL_VAR_SYMBOL. | 6476 | /* Restore NULL'ed SPECIAL_VAR_SYMBOL. |
6480 | * Do the check to avoid writing to a const string. */ | 6477 | * Do the check to avoid writing to a const string. */ |
6481 | if (*p != SPECIAL_VAR_SYMBOL) | 6478 | if (*p != SPECIAL_VAR_SYMBOL) |