diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-31 10:34:48 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-31 10:34:48 +0000 |
commit | d498131168005ccc4768b9c92d7e3c3547e390df (patch) | |
tree | 899ee471e327b9aea2889b599ed0b01290c5289c | |
parent | f173607520e0455d267a7a4100e5018f30000c56 (diff) | |
download | busybox-w32-d498131168005ccc4768b9c92d7e3c3547e390df.tar.gz busybox-w32-d498131168005ccc4768b9c92d7e3c3547e390df.tar.bz2 busybox-w32-d498131168005ccc4768b9c92d7e3c3547e390df.zip |
hush: support $_NUMBERS variable names
-rw-r--r-- | shell/hush.c | 17 | ||||
-rw-r--r-- | shell/hush_test/hush-vars/var1.right (renamed from shell/hush_test/hush-vars/var.right) | 0 | ||||
-rwxr-xr-x | shell/hush_test/hush-vars/var1.tests (renamed from shell/hush_test/hush-vars/var.tests) | 0 | ||||
-rw-r--r-- | shell/hush_test/hush-vars/var2.right | 2 | ||||
-rwxr-xr-x | shell/hush_test/hush-vars/var2.tests | 4 |
5 files changed, 19 insertions, 4 deletions
diff --git a/shell/hush.c b/shell/hush.c index 8be0ecf1c..b6393865b 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -587,7 +587,7 @@ static int glob_needed(const char *s) | |||
587 | 587 | ||
588 | static int is_assignment(const char *s) | 588 | static int is_assignment(const char *s) |
589 | { | 589 | { |
590 | if (!s || !isalpha(*s)) | 590 | if (!s || !(isalpha(*s) || *s == '_')) |
591 | return 0; | 591 | return 0; |
592 | s++; | 592 | s++; |
593 | while (isalnum(*s) || *s == '_') | 593 | while (isalnum(*s) || *s == '_') |
@@ -3529,22 +3529,24 @@ static int handle_dollar(o_string *dest, struct in_str *input) | |||
3529 | 3529 | ||
3530 | debug_printf_parse("handle_dollar entered: ch='%c'\n", ch); | 3530 | debug_printf_parse("handle_dollar entered: ch='%c'\n", ch); |
3531 | if (isalpha(ch)) { | 3531 | if (isalpha(ch)) { |
3532 | i_getch(input); | ||
3533 | make_var: | ||
3532 | o_addchr(dest, SPECIAL_VAR_SYMBOL); | 3534 | o_addchr(dest, SPECIAL_VAR_SYMBOL); |
3533 | while (1) { | 3535 | while (1) { |
3534 | debug_printf_parse(": '%c'\n", ch); | 3536 | debug_printf_parse(": '%c'\n", ch); |
3535 | i_getch(input); | ||
3536 | o_addchr(dest, ch | quote_mask); | 3537 | o_addchr(dest, ch | quote_mask); |
3537 | quote_mask = 0; | 3538 | quote_mask = 0; |
3538 | ch = i_peek(input); | 3539 | ch = i_peek(input); |
3539 | if (!isalnum(ch) && ch != '_') | 3540 | if (!isalnum(ch) && ch != '_') |
3540 | break; | 3541 | break; |
3542 | i_getch(input); | ||
3541 | } | 3543 | } |
3542 | o_addchr(dest, SPECIAL_VAR_SYMBOL); | 3544 | o_addchr(dest, SPECIAL_VAR_SYMBOL); |
3543 | } else if (isdigit(ch)) { | 3545 | } else if (isdigit(ch)) { |
3544 | make_one_char_var: | 3546 | make_one_char_var: |
3547 | i_getch(input); | ||
3545 | o_addchr(dest, SPECIAL_VAR_SYMBOL); | 3548 | o_addchr(dest, SPECIAL_VAR_SYMBOL); |
3546 | debug_printf_parse(": '%c'\n", ch); | 3549 | debug_printf_parse(": '%c'\n", ch); |
3547 | i_getch(input); | ||
3548 | o_addchr(dest, ch | quote_mask); | 3550 | o_addchr(dest, ch | quote_mask); |
3549 | o_addchr(dest, SPECIAL_VAR_SYMBOL); | 3551 | o_addchr(dest, SPECIAL_VAR_SYMBOL); |
3550 | } else switch (ch) { | 3552 | } else switch (ch) { |
@@ -3586,8 +3588,15 @@ static int handle_dollar(o_string *dest, struct in_str *input) | |||
3586 | break; | 3588 | break; |
3587 | } | 3589 | } |
3588 | #endif | 3590 | #endif |
3589 | case '-': | ||
3590 | case '_': | 3591 | case '_': |
3592 | i_getch(input); | ||
3593 | ch = i_peek(input); | ||
3594 | if (isalnum(ch)) { /* it's $_name or $_123 */ | ||
3595 | ch = '_'; | ||
3596 | goto make_var; | ||
3597 | } | ||
3598 | /* else: it's $_ */ | ||
3599 | case '-': | ||
3591 | /* still unhandled, but should be eventually */ | 3600 | /* still unhandled, but should be eventually */ |
3592 | bb_error_msg("unhandled syntax: $%c", ch); | 3601 | bb_error_msg("unhandled syntax: $%c", ch); |
3593 | return 1; | 3602 | return 1; |
diff --git a/shell/hush_test/hush-vars/var.right b/shell/hush_test/hush-vars/var1.right index 14b2314d9..14b2314d9 100644 --- a/shell/hush_test/hush-vars/var.right +++ b/shell/hush_test/hush-vars/var1.right | |||
diff --git a/shell/hush_test/hush-vars/var.tests b/shell/hush_test/hush-vars/var1.tests index 0a63696c9..0a63696c9 100755 --- a/shell/hush_test/hush-vars/var.tests +++ b/shell/hush_test/hush-vars/var1.tests | |||
diff --git a/shell/hush_test/hush-vars/var2.right b/shell/hush_test/hush-vars/var2.right new file mode 100644 index 000000000..40bf4bff4 --- /dev/null +++ b/shell/hush_test/hush-vars/var2.right | |||
@@ -0,0 +1,2 @@ | |||
1 | http://busybox.net | ||
2 | http://busybox.net_abc | ||
diff --git a/shell/hush_test/hush-vars/var2.tests b/shell/hush_test/hush-vars/var2.tests new file mode 100755 index 000000000..1292410f3 --- /dev/null +++ b/shell/hush_test/hush-vars/var2.tests | |||
@@ -0,0 +1,4 @@ | |||
1 | _1=http://busybox.net | ||
2 | |||
3 | echo $_1 | ||
4 | echo ${_1}_abc | ||