diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-01-25 13:20:50 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-01-25 13:20:50 +0100 |
| commit | 0ca3198f9333b363ced46bfabf51c0d6b111c875 (patch) | |
| tree | 8b6d3b18ad914f25f741784ff82986014f58c60a /shell | |
| parent | a497231f537352c7ff7a80c07ef6191b00e7e30e (diff) | |
| download | busybox-w32-0ca3198f9333b363ced46bfabf51c0d6b111c875.tar.gz busybox-w32-0ca3198f9333b363ced46bfabf51c0d6b111c875.tar.bz2 busybox-w32-0ca3198f9333b363ced46bfabf51c0d6b111c875.zip | |
hush: fix handling of $_ (so far it's an ordinary variable, no special meaning)
function old new delta
parse_dollar 820 779 -41
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
| -rw-r--r-- | shell/hush.c | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/shell/hush.c b/shell/hush.c index 7b83c736c..a9183c82f 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
| @@ -4520,9 +4520,10 @@ static int parse_dollar(o_string *as_string, | |||
| 4520 | 4520 | ||
| 4521 | debug_printf_parse("parse_dollar entered: ch='%c'\n", ch); | 4521 | debug_printf_parse("parse_dollar entered: ch='%c'\n", ch); |
| 4522 | if (isalpha(ch)) { | 4522 | if (isalpha(ch)) { |
| 4523 | make_var: | ||
| 4523 | ch = i_getch(input); | 4524 | ch = i_getch(input); |
| 4524 | nommu_addchr(as_string, ch); | 4525 | nommu_addchr(as_string, ch); |
| 4525 | make_var: | 4526 | /*make_var1:*/ |
| 4526 | o_addchr(dest, SPECIAL_VAR_SYMBOL); | 4527 | o_addchr(dest, SPECIAL_VAR_SYMBOL); |
| 4527 | while (1) { | 4528 | while (1) { |
| 4528 | debug_printf_parse(": '%c'\n", ch); | 4529 | debug_printf_parse(": '%c'\n", ch); |
| @@ -4715,19 +4716,22 @@ static int parse_dollar(o_string *as_string, | |||
| 4715 | } | 4716 | } |
| 4716 | #endif | 4717 | #endif |
| 4717 | case '_': | 4718 | case '_': |
| 4719 | goto make_var; | ||
| 4720 | #if 0 | ||
| 4721 | /* TODO: $_ and $-: */ | ||
| 4722 | /* $_ Shell or shell script name; or last argument of last command | ||
| 4723 | * (if last command wasn't a pipe; if it was, bash sets $_ to ""); | ||
| 4724 | * but in command's env, set to full pathname used to invoke it */ | ||
| 4725 | /* $- Option flags set by set builtin or shell options (-i etc) */ | ||
| 4718 | ch = i_getch(input); | 4726 | ch = i_getch(input); |
| 4719 | nommu_addchr(as_string, ch); | 4727 | nommu_addchr(as_string, ch); |
| 4720 | ch = i_peek_and_eat_bkslash_nl(input); | 4728 | ch = i_peek_and_eat_bkslash_nl(input); |
| 4721 | if (isalnum(ch)) { /* it's $_name or $_123 */ | 4729 | if (isalnum(ch)) { /* it's $_name or $_123 */ |
| 4722 | ch = '_'; | 4730 | ch = '_'; |
| 4723 | goto make_var; | 4731 | goto make_var1; |
| 4724 | } | 4732 | } |
| 4725 | /* else: it's $_ */ | 4733 | /* else: it's $_ */ |
| 4726 | /* TODO: $_ and $-: */ | 4734 | #endif |
| 4727 | /* $_ Shell or shell script name; or last argument of last command | ||
| 4728 | * (if last command wasn't a pipe; if it was, bash sets $_ to ""); | ||
| 4729 | * but in command's env, set to full pathname used to invoke it */ | ||
| 4730 | /* $- Option flags set by set builtin or shell options (-i etc) */ | ||
| 4731 | default: | 4735 | default: |
| 4732 | o_addQchr(dest, '$'); | 4736 | o_addQchr(dest, '$'); |
| 4733 | } | 4737 | } |
| @@ -5669,9 +5673,9 @@ static char *replace_pattern(char *val, const char *pattern, const char *repl, c | |||
| 5669 | */ | 5673 | */ |
| 5670 | static NOINLINE const char *expand_one_var(char **to_be_freed_pp, char *arg, char **pp) | 5674 | static NOINLINE const char *expand_one_var(char **to_be_freed_pp, char *arg, char **pp) |
| 5671 | { | 5675 | { |
| 5672 | const char *val = NULL; | 5676 | const char *val; |
| 5673 | char *to_be_freed = NULL; | 5677 | char *to_be_freed; |
| 5674 | char *p = *pp; | 5678 | char *p; |
| 5675 | char *var; | 5679 | char *var; |
| 5676 | char first_char; | 5680 | char first_char; |
| 5677 | char exp_op; | 5681 | char exp_op; |
| @@ -5680,6 +5684,9 @@ static NOINLINE const char *expand_one_var(char **to_be_freed_pp, char *arg, cha | |||
| 5680 | char *exp_word = exp_word; /* for compiler */ | 5684 | char *exp_word = exp_word; /* for compiler */ |
| 5681 | char arg0; | 5685 | char arg0; |
| 5682 | 5686 | ||
| 5687 | val = NULL; | ||
| 5688 | to_be_freed = NULL; | ||
| 5689 | p = *pp; | ||
| 5683 | *p = '\0'; /* replace trailing SPECIAL_VAR_SYMBOL */ | 5690 | *p = '\0'; /* replace trailing SPECIAL_VAR_SYMBOL */ |
| 5684 | var = arg; | 5691 | var = arg; |
| 5685 | exp_saveptr = arg[1] ? strchr(VAR_ENCODED_SUBST_OPS, arg[1]) : NULL; | 5692 | exp_saveptr = arg[1] ? strchr(VAR_ENCODED_SUBST_OPS, arg[1]) : NULL; |
