diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-01-12 23:29:57 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-01-12 23:29:57 +0100 |
commit | 03dad22f8a1b8b1410fdcccf69af1bb5cce4de7c (patch) | |
tree | b134cbc7f0afbf76c54847624310e6a1d2774f83 | |
parent | 045f4ad92c07434625e168bc8c37aa0e89f6e58e (diff) | |
download | busybox-w32-03dad22f8a1b8b1410fdcccf69af1bb5cce4de7c.tar.gz busybox-w32-03dad22f8a1b8b1410fdcccf69af1bb5cce4de7c.tar.bz2 busybox-w32-03dad22f8a1b8b1410fdcccf69af1bb5cce4de7c.zip |
hush: use ash's read builtin
function old new delta
shell_builtin_read - 1000 +1000
set_local_var_from_halves - 24 +24
setvar2 - 7 +7
...
popstring 140 134 -6
ash_main 1375 1368 -7
setvar 184 174 -10
arith_set_local_var 36 - -36
builtin_read 1096 185 -911
------------------------------------------------------------------------------
(add/remove: 3/1 grow/shrink: 5/23 up/down: 1038/-1007) Total: 31 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/Kbuild | 2 | ||||
-rw-r--r-- | shell/ash.c | 14 | ||||
-rw-r--r-- | shell/builtin_read.c | 10 | ||||
-rw-r--r-- | shell/builtin_read.h | 2 | ||||
-rw-r--r-- | shell/hush.c | 59 | ||||
-rw-r--r-- | shell/hush_test/hush-read/read_REPLY.right | 5 | ||||
-rwxr-xr-x | shell/hush_test/hush-read/read_REPLY.tests | 5 | ||||
-rw-r--r-- | shell/hush_test/hush-read/read_ifs.right | 10 | ||||
-rwxr-xr-x | shell/hush_test/hush-read/read_ifs.tests | 10 | ||||
-rw-r--r-- | shell/hush_test/hush-read/read_n.right | 3 | ||||
-rwxr-xr-x | shell/hush_test/hush-read/read_n.tests | 3 | ||||
-rw-r--r-- | shell/hush_test/hush-read/read_r.right | 2 | ||||
-rwxr-xr-x | shell/hush_test/hush-read/read_r.tests | 2 | ||||
-rw-r--r-- | shell/hush_test/hush-read/read_t.right | 4 | ||||
-rwxr-xr-x | shell/hush_test/hush-read/read_t.tests | 10 | ||||
-rw-r--r-- | shell/match.h | 2 | ||||
-rw-r--r-- | shell/math.c | 19 | ||||
-rw-r--r-- | shell/math.h | 11 |
18 files changed, 124 insertions, 49 deletions
diff --git a/shell/Kbuild b/shell/Kbuild index 155ac6f0f..d8306dc96 100644 --- a/shell/Kbuild +++ b/shell/Kbuild | |||
@@ -6,7 +6,7 @@ | |||
6 | 6 | ||
7 | lib-y:= | 7 | lib-y:= |
8 | lib-$(CONFIG_ASH) += ash.o ash_ptr_hack.o shell_common.o builtin_read.o | 8 | lib-$(CONFIG_ASH) += ash.o ash_ptr_hack.o shell_common.o builtin_read.o |
9 | lib-$(CONFIG_HUSH) += hush.o match.o | 9 | lib-$(CONFIG_HUSH) += hush.o match.o shell_common.o builtin_read.o |
10 | lib-$(CONFIG_CTTYHACK) += cttyhack.o | 10 | lib-$(CONFIG_CTTYHACK) += cttyhack.o |
11 | 11 | ||
12 | lib-$(CONFIG_SH_MATH_SUPPORT) += math.o | 12 | lib-$(CONFIG_SH_MATH_SUPPORT) += math.o |
diff --git a/shell/ash.c b/shell/ash.c index c7deffd08..31dc59253 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -1884,7 +1884,7 @@ getoptsreset(const char *value) | |||
1884 | * Return of a legal variable name (a letter or underscore followed by zero or | 1884 | * Return of a legal variable name (a letter or underscore followed by zero or |
1885 | * more letters, underscores, and digits). | 1885 | * more letters, underscores, and digits). |
1886 | */ | 1886 | */ |
1887 | static char * | 1887 | static char* FAST_FUNC |
1888 | endofname(const char *name) | 1888 | endofname(const char *name) |
1889 | { | 1889 | { |
1890 | char *p; | 1890 | char *p; |
@@ -1991,7 +1991,7 @@ findvar(struct var **vpp, const char *name) | |||
1991 | /* | 1991 | /* |
1992 | * Find the value of a variable. Returns NULL if not set. | 1992 | * Find the value of a variable. Returns NULL if not set. |
1993 | */ | 1993 | */ |
1994 | static const char * | 1994 | static const char* FAST_FUNC |
1995 | lookupvar(const char *name) | 1995 | lookupvar(const char *name) |
1996 | { | 1996 | { |
1997 | struct var *v; | 1997 | struct var *v; |
@@ -2114,6 +2114,12 @@ setvar(const char *name, const char *val, int flags) | |||
2114 | INT_ON; | 2114 | INT_ON; |
2115 | } | 2115 | } |
2116 | 2116 | ||
2117 | static void FAST_FUNC | ||
2118 | setvar2(const char *name, const char *val) | ||
2119 | { | ||
2120 | setvar(name, val, 0); | ||
2121 | } | ||
2122 | |||
2117 | #if ENABLE_ASH_GETOPTS | 2123 | #if ENABLE_ASH_GETOPTS |
2118 | /* | 2124 | /* |
2119 | * Safe version of setvar, returns 1 on success 0 on failure. | 2125 | * Safe version of setvar, returns 1 on success 0 on failure. |
@@ -5304,7 +5310,7 @@ ash_arith(const char *s) | |||
5304 | int errcode = 0; | 5310 | int errcode = 0; |
5305 | 5311 | ||
5306 | math_hooks.lookupvar = lookupvar; | 5312 | math_hooks.lookupvar = lookupvar; |
5307 | math_hooks.setvar = setvar; | 5313 | math_hooks.setvar = setvar2; |
5308 | math_hooks.endofname = endofname; | 5314 | math_hooks.endofname = endofname; |
5309 | 5315 | ||
5310 | INT_OFF; | 5316 | INT_OFF; |
@@ -12526,7 +12532,7 @@ readcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
12526 | } | 12532 | } |
12527 | } | 12533 | } |
12528 | 12534 | ||
12529 | r = builtin_read(setvar, | 12535 | r = shell_builtin_read(setvar2, |
12530 | argptr, | 12536 | argptr, |
12531 | bltinlookup("IFS"), /* can be NULL */ | 12537 | bltinlookup("IFS"), /* can be NULL */ |
12532 | read_flags, | 12538 | read_flags, |
diff --git a/shell/builtin_read.c b/shell/builtin_read.c index 24cfe08fb..412bcf869 100644 --- a/shell/builtin_read.c +++ b/shell/builtin_read.c | |||
@@ -21,7 +21,7 @@ | |||
21 | #include "builtin_read.h" | 21 | #include "builtin_read.h" |
22 | 22 | ||
23 | const char* FAST_FUNC | 23 | const char* FAST_FUNC |
24 | builtin_read(void (*setvar)(const char *name, const char *val, int flags), | 24 | shell_builtin_read(void FAST_FUNC (*setvar)(const char *name, const char *val), |
25 | char **argv, | 25 | char **argv, |
26 | const char *ifs, | 26 | const char *ifs, |
27 | int read_flags, | 27 | int read_flags, |
@@ -178,7 +178,7 @@ builtin_read(void (*setvar)(const char *name, const char *val, int flags), | |||
178 | if (argv[1] != NULL && is_ifs) { | 178 | if (argv[1] != NULL && is_ifs) { |
179 | buffer[bufpos] = '\0'; | 179 | buffer[bufpos] = '\0'; |
180 | bufpos = 0; | 180 | bufpos = 0; |
181 | setvar(*argv, buffer, 0); | 181 | setvar(*argv, buffer); |
182 | argv++; | 182 | argv++; |
183 | /* can we skip one non-space ifs char? (2: yes) */ | 183 | /* can we skip one non-space ifs char? (2: yes) */ |
184 | startword = isspace(c) ? 2 : 1; | 184 | startword = isspace(c) ? 2 : 1; |
@@ -195,14 +195,14 @@ builtin_read(void (*setvar)(const char *name, const char *val, int flags), | |||
195 | continue; | 195 | continue; |
196 | buffer[bufpos + 1] = '\0'; | 196 | buffer[bufpos + 1] = '\0'; |
197 | /* Use the remainder as a value for the next variable */ | 197 | /* Use the remainder as a value for the next variable */ |
198 | setvar(*argv, buffer, 0); | 198 | setvar(*argv, buffer); |
199 | /* Set the rest to "" */ | 199 | /* Set the rest to "" */ |
200 | while (*++argv) | 200 | while (*++argv) |
201 | setvar(*argv, "", 0); | 201 | setvar(*argv, ""); |
202 | } else { | 202 | } else { |
203 | /* Note: no $IFS removal */ | 203 | /* Note: no $IFS removal */ |
204 | buffer[bufpos] = '\0'; | 204 | buffer[bufpos] = '\0'; |
205 | setvar("REPLY", buffer, 0); | 205 | setvar("REPLY", buffer); |
206 | } | 206 | } |
207 | 207 | ||
208 | ret: | 208 | ret: |
diff --git a/shell/builtin_read.h b/shell/builtin_read.h index 930d01428..bc23dc5ae 100644 --- a/shell/builtin_read.h +++ b/shell/builtin_read.h | |||
@@ -27,7 +27,7 @@ enum { | |||
27 | }; | 27 | }; |
28 | 28 | ||
29 | const char* FAST_FUNC | 29 | const char* FAST_FUNC |
30 | builtin_read(void (*setvar)(const char *name, const char *val, int flags), | 30 | shell_builtin_read(void FAST_FUNC (*setvar)(const char *name, const char *val), |
31 | char **argv, | 31 | char **argv, |
32 | const char *ifs, | 32 | const char *ifs, |
33 | int read_flags, | 33 | int read_flags, |
diff --git a/shell/hush.c b/shell/hush.c index 88a7b988a..bb0ab8408 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -84,6 +84,9 @@ | |||
84 | #if ENABLE_HUSH_CASE | 84 | #if ENABLE_HUSH_CASE |
85 | # include <fnmatch.h> | 85 | # include <fnmatch.h> |
86 | #endif | 86 | #endif |
87 | |||
88 | #include "shell_common.h" | ||
89 | #include "builtin_read.h" | ||
87 | #include "math.h" | 90 | #include "math.h" |
88 | #include "match.h" | 91 | #include "match.h" |
89 | #if ENABLE_HUSH_RANDOM_SUPPORT | 92 | #if ENABLE_HUSH_RANDOM_SUPPORT |
@@ -1307,7 +1310,7 @@ static struct variable *get_local_var(const char *name) | |||
1307 | return NULL; | 1310 | return NULL; |
1308 | } | 1311 | } |
1309 | 1312 | ||
1310 | static const char *get_local_var_value(const char *name) | 1313 | static const char* FAST_FUNC get_local_var_value(const char *name) |
1311 | { | 1314 | { |
1312 | struct variable **pp = get_ptr_to_local_var(name); | 1315 | struct variable **pp = get_ptr_to_local_var(name); |
1313 | if (pp) | 1316 | if (pp) |
@@ -1510,7 +1513,7 @@ static void unset_vars(char **strings) | |||
1510 | #if ENABLE_SH_MATH_SUPPORT | 1513 | #if ENABLE_SH_MATH_SUPPORT |
1511 | #define is_name(c) ((c) == '_' || isalpha((unsigned char)(c))) | 1514 | #define is_name(c) ((c) == '_' || isalpha((unsigned char)(c))) |
1512 | #define is_in_name(c) ((c) == '_' || isalnum((unsigned char)(c))) | 1515 | #define is_in_name(c) ((c) == '_' || isalnum((unsigned char)(c))) |
1513 | static char *endofname(const char *name) | 1516 | static char* FAST_FUNC endofname(const char *name) |
1514 | { | 1517 | { |
1515 | char *p; | 1518 | char *p; |
1516 | 1519 | ||
@@ -1524,11 +1527,10 @@ static char *endofname(const char *name) | |||
1524 | return p; | 1527 | return p; |
1525 | } | 1528 | } |
1526 | 1529 | ||
1527 | static void arith_set_local_var(const char *name, const char *val, int flags) | 1530 | static void FAST_FUNC set_local_var_from_halves(const char *name, const char *val) |
1528 | { | 1531 | { |
1529 | /* arith code doesnt malloc space, so do it for it */ | ||
1530 | char *var = xasprintf("%s=%s", name, val); | 1532 | char *var = xasprintf("%s=%s", name, val); |
1531 | set_local_var(var, flags, /*lvl:*/ 0, /*ro:*/ 0); | 1533 | set_local_var(var, /*flags:*/ 0, /*lvl:*/ 0, /*ro:*/ 0); |
1532 | } | 1534 | } |
1533 | #endif | 1535 | #endif |
1534 | 1536 | ||
@@ -2538,7 +2540,7 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg, char | |||
2538 | 2540 | ||
2539 | exp_str = expand_pseudo_dquoted(arg); | 2541 | exp_str = expand_pseudo_dquoted(arg); |
2540 | hooks.lookupvar = get_local_var_value; | 2542 | hooks.lookupvar = get_local_var_value; |
2541 | hooks.setvar = arith_set_local_var; | 2543 | hooks.setvar = set_local_var_from_halves; |
2542 | hooks.endofname = endofname; | 2544 | hooks.endofname = endofname; |
2543 | res = arith(exp_str ? exp_str : arg, &errcode, &hooks); | 2545 | res = arith(exp_str ? exp_str : arg, &errcode, &hooks); |
2544 | free(exp_str); | 2546 | free(exp_str); |
@@ -6157,7 +6159,7 @@ static struct pipe *parse_stream(char **pstring, | |||
6157 | 6159 | ||
6158 | G.ifs = get_local_var_value("IFS"); | 6160 | G.ifs = get_local_var_value("IFS"); |
6159 | if (G.ifs == NULL) | 6161 | if (G.ifs == NULL) |
6160 | G.ifs = " \t\n"; | 6162 | G.ifs = defifs; |
6161 | 6163 | ||
6162 | reset: | 6164 | reset: |
6163 | #if ENABLE_HUSH_INTERACTIVE | 6165 | #if ENABLE_HUSH_INTERACTIVE |
@@ -7727,24 +7729,37 @@ static int FAST_FUNC builtin_pwd(char **argv UNUSED_PARAM) | |||
7727 | 7729 | ||
7728 | static int FAST_FUNC builtin_read(char **argv) | 7730 | static int FAST_FUNC builtin_read(char **argv) |
7729 | { | 7731 | { |
7730 | char *string; | 7732 | const char *r; |
7731 | const char *name = "REPLY"; | 7733 | char *opt_n = NULL; |
7734 | char *opt_p = NULL; | ||
7735 | char *opt_t = NULL; | ||
7736 | char *opt_u = NULL; | ||
7737 | int read_flags; | ||
7732 | 7738 | ||
7733 | if (argv[1]) { | 7739 | /* "!": do not abort on errors. |
7734 | name = argv[1]; | 7740 | * Option string must start with "sr" to match BUILTIN_READ_xxx |
7735 | /* bash (3.2.33(1)) bug: "read 0abcd" will execute, | 7741 | */ |
7736 | * and _after_ that_ it will complain */ | 7742 | read_flags = getopt32(argv, "!srn:p:t:u:", &opt_n, &opt_p, &opt_t, &opt_u); |
7737 | if (!is_well_formed_var_name(name, '\0')) { | 7743 | if (read_flags == (uint32_t)-1) |
7738 | /* Mimic bash message */ | 7744 | return EXIT_FAILURE; |
7739 | bb_error_msg("read: '%s': not a valid identifier", name); | 7745 | argv += optind; |
7740 | return 1; | ||
7741 | } | ||
7742 | } | ||
7743 | 7746 | ||
7744 | //TODO: bash unbackslashes input, splits words and puts them in argv[i] | 7747 | r = shell_builtin_read(set_local_var_from_halves, |
7748 | argv, | ||
7749 | get_local_var_value("IFS"), /* can be NULL */ | ||
7750 | read_flags, | ||
7751 | opt_n, | ||
7752 | opt_p, | ||
7753 | opt_t, | ||
7754 | opt_u | ||
7755 | ); | ||
7756 | |||
7757 | if ((uintptr_t)r > 1) { | ||
7758 | bb_error_msg("%s", r); | ||
7759 | r = (char*)(uintptr_t)1; | ||
7760 | } | ||
7745 | 7761 | ||
7746 | string = xmalloc_reads(STDIN_FILENO, xasprintf("%s=", name), NULL); | 7762 | return (uintptr_t)r; |
7747 | return set_local_var(string, /*exp:*/ 0, /*lvl:*/ 0, /*ro:*/ 0); | ||
7748 | } | 7763 | } |
7749 | 7764 | ||
7750 | /* http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#set | 7765 | /* http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#set |
diff --git a/shell/hush_test/hush-read/read_REPLY.right b/shell/hush_test/hush-read/read_REPLY.right new file mode 100644 index 000000000..59f5d5487 --- /dev/null +++ b/shell/hush_test/hush-read/read_REPLY.right | |||
@@ -0,0 +1,5 @@ | |||
1 | test 1: | abc1 def | | ||
2 | test 2: | \abc2 d\ef | | ||
3 | test 3: |abc3 def| | ||
4 | test 4: |\abc4 d\ef| | ||
5 | Done | ||
diff --git a/shell/hush_test/hush-read/read_REPLY.tests b/shell/hush_test/hush-read/read_REPLY.tests new file mode 100755 index 000000000..ba20cae8d --- /dev/null +++ b/shell/hush_test/hush-read/read_REPLY.tests | |||
@@ -0,0 +1,5 @@ | |||
1 | echo ' \abc1 d\ef ' | ( read ; echo "test 1: |$REPLY|" ) | ||
2 | echo ' \abc2 d\ef ' | ( read -r ; echo "test 2: |$REPLY|" ) | ||
3 | echo ' \abc3 d\ef ' | ( read REPLY; echo "test 3: |$REPLY|" ) | ||
4 | echo ' \abc4 d\ef ' | ( read -r REPLY; echo "test 4: |$REPLY|" ) | ||
5 | echo Done | ||
diff --git a/shell/hush_test/hush-read/read_ifs.right b/shell/hush_test/hush-read/read_ifs.right new file mode 100644 index 000000000..b52334456 --- /dev/null +++ b/shell/hush_test/hush-read/read_ifs.right | |||
@@ -0,0 +1,10 @@ | |||
1 | test 1: .a. .b. .c. | ||
2 | test 2: .a. .b. .c. | ||
3 | test 3: .a. .. .b,c. | ||
4 | test 4: .a. .. .b,c. | ||
5 | test 5: .a. .. .c. | ||
6 | test 6: .a. .. .c. .d. | ||
7 | test 7: .a. .. .b,c,d , ,. | ||
8 | test 8: .. .a. .b. .c. | ||
9 | test 9: .a. .b. .c. .. | ||
10 | test A: .. .a. .. .b. .c. | ||
diff --git a/shell/hush_test/hush-read/read_ifs.tests b/shell/hush_test/hush-read/read_ifs.tests new file mode 100755 index 000000000..6e8311247 --- /dev/null +++ b/shell/hush_test/hush-read/read_ifs.tests | |||
@@ -0,0 +1,10 @@ | |||
1 | printf 'a\t\tb\tc\n' | ( IFS=$(printf "\t") read a b c; echo "test 1: .$a. .$b. .$c." ) | ||
2 | printf 'a\t\tb\tc\n' | ( IFS=$(printf " \t") read a b c; echo "test 2: .$a. .$b. .$c." ) | ||
3 | printf 'a,,b,c\n' | ( IFS="," read a b c; echo "test 3: .$a. .$b. .$c." ) | ||
4 | printf 'a,,b,c\n' | ( IFS=" ," read a b c; echo "test 4: .$a. .$b. .$c." ) | ||
5 | printf 'a ,, c\n' | ( IFS=" ," read a b c; echo "test 5: .$a. .$b. .$c." ) | ||
6 | printf 'a ,, c d\n' | ( IFS=" ," read a b c d; echo "test 6: .$a. .$b. .$c. .$d." ) | ||
7 | printf ' a,,b,c,d , ,\n' | ( IFS=" ," read a b c; echo "test 7: .$a. .$b. .$c." ) | ||
8 | printf '\t,\ta\t,\tb\tc' | ( IFS=$(printf " \t,") read a b c d; echo "test 8: .$a. .$b. .$c. .$d." ) | ||
9 | printf '\t\ta\t,\tb\tc' | ( IFS=$(printf " \t,") read a b c d; echo "test 9: .$a. .$b. .$c. .$d." ) | ||
10 | printf '\t,\ta\t,,\tb\tc' | ( IFS=$(printf " \t,") read a b c d e; echo "test A: .$a. .$b. .$c. .$d. .$e." ) | ||
diff --git a/shell/hush_test/hush-read/read_n.right b/shell/hush_test/hush-read/read_n.right new file mode 100644 index 000000000..1f81af0bc --- /dev/null +++ b/shell/hush_test/hush-read/read_n.right | |||
@@ -0,0 +1,3 @@ | |||
1 | test | ||
2 | tes | ||
3 | tes | ||
diff --git a/shell/hush_test/hush-read/read_n.tests b/shell/hush_test/hush-read/read_n.tests new file mode 100755 index 000000000..12423ba6e --- /dev/null +++ b/shell/hush_test/hush-read/read_n.tests | |||
@@ -0,0 +1,3 @@ | |||
1 | echo 'test' | (read reply; echo "$reply") | ||
2 | echo 'test' | (read -n 3 reply; echo "$reply") | ||
3 | echo 'test' | (read -n3 reply; echo "$reply") | ||
diff --git a/shell/hush_test/hush-read/read_r.right b/shell/hush_test/hush-read/read_r.right new file mode 100644 index 000000000..3536bf757 --- /dev/null +++ b/shell/hush_test/hush-read/read_r.right | |||
@@ -0,0 +1,2 @@ | |||
1 | testbest | ||
2 | test\ | ||
diff --git a/shell/hush_test/hush-read/read_r.tests b/shell/hush_test/hush-read/read_r.tests new file mode 100755 index 000000000..2c4cc6106 --- /dev/null +++ b/shell/hush_test/hush-read/read_r.tests | |||
@@ -0,0 +1,2 @@ | |||
1 | echo -e 'test\\\nbest' | (read reply; echo "$reply") | ||
2 | echo -e 'test\\\nbest' | (read -r reply; echo "$reply") | ||
diff --git a/shell/hush_test/hush-read/read_t.right b/shell/hush_test/hush-read/read_t.right new file mode 100644 index 000000000..04126cbe6 --- /dev/null +++ b/shell/hush_test/hush-read/read_t.right | |||
@@ -0,0 +1,4 @@ | |||
1 | >< | ||
2 | >< | ||
3 | >test< | ||
4 | >test< | ||
diff --git a/shell/hush_test/hush-read/read_t.tests b/shell/hush_test/hush-read/read_t.tests new file mode 100755 index 000000000..d65f1aeaa --- /dev/null +++ b/shell/hush_test/hush-read/read_t.tests | |||
@@ -0,0 +1,10 @@ | |||
1 | # bash 3.2 outputs: | ||
2 | |||
3 | # >< | ||
4 | { echo -n 'te'; sleep 2; echo 'st'; } | (read -t 1 reply; echo ">$reply<") | ||
5 | # >< | ||
6 | { sleep 2; echo 'test'; } | (read -t 1 reply; echo ">$reply<") | ||
7 | # >test< | ||
8 | { echo -n 'te'; sleep 1; echo 'st'; } | (read -t 2 reply; echo ">$reply<") | ||
9 | # >test< | ||
10 | { sleep 1; echo 'test'; } | (read -t 2 reply; echo ">$reply<") | ||
diff --git a/shell/match.h b/shell/match.h index 98ff8745a..c022ceb25 100644 --- a/shell/match.h +++ b/shell/match.h | |||
@@ -5,6 +5,8 @@ | |||
5 | 5 | ||
6 | PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN | 6 | PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN |
7 | 7 | ||
8 | //TODO! Why ash.c still uses internal version?! | ||
9 | |||
8 | typedef char *(*scan_t)(char *string, char *match, bool match_at_left); | 10 | typedef char *(*scan_t)(char *string, char *match, bool match_at_left); |
9 | 11 | ||
10 | char *scanleft(char *string, char *match, bool match_at_left); | 12 | char *scanleft(char *string, char *match, bool match_at_left); |
diff --git a/shell/math.c b/shell/math.c index 76159b299..91fb28f05 100644 --- a/shell/math.c +++ b/shell/math.c | |||
@@ -25,14 +25,6 @@ | |||
25 | * | 25 | * |
26 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. | 26 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. |
27 | */ | 27 | */ |
28 | #include "libbb.h" | ||
29 | #include "math.h" | ||
30 | |||
31 | #define a_e_h_t arith_eval_hooks_t | ||
32 | #define lookupvar (math_hooks->lookupvar) | ||
33 | #define setvar (math_hooks->setvar) | ||
34 | #define endofname (math_hooks->endofname) | ||
35 | |||
36 | /* Copyright (c) 2001 Aaron Lehmann <aaronl@vitelus.com> | 28 | /* Copyright (c) 2001 Aaron Lehmann <aaronl@vitelus.com> |
37 | 29 | ||
38 | Permission is hereby granted, free of charge, to any person obtaining | 30 | Permission is hereby granted, free of charge, to any person obtaining |
@@ -99,7 +91,6 @@ | |||
99 | * whitespace chars should be considered. Look below the "#include"s for a | 91 | * whitespace chars should be considered. Look below the "#include"s for a |
100 | * precompiler test. | 92 | * precompiler test. |
101 | */ | 93 | */ |
102 | |||
103 | /* | 94 | /* |
104 | * Aug 26, 2001 Manuel Novoa III | 95 | * Aug 26, 2001 Manuel Novoa III |
105 | * | 96 | * |
@@ -109,7 +100,6 @@ | |||
109 | * modified slightly to take account of my changes to the code. | 100 | * modified slightly to take account of my changes to the code. |
110 | * | 101 | * |
111 | */ | 102 | */ |
112 | |||
113 | /* | 103 | /* |
114 | * (C) 2003 Vladimir Oleynik <dzo@simtreas.ru> | 104 | * (C) 2003 Vladimir Oleynik <dzo@simtreas.ru> |
115 | * | 105 | * |
@@ -126,6 +116,13 @@ | |||
126 | * - protect $((num num)) as true zero expr (Manuel`s error) | 116 | * - protect $((num num)) as true zero expr (Manuel`s error) |
127 | * - always use special isspace(), see comment from bash ;-) | 117 | * - always use special isspace(), see comment from bash ;-) |
128 | */ | 118 | */ |
119 | #include "libbb.h" | ||
120 | #include "math.h" | ||
121 | |||
122 | #define a_e_h_t arith_eval_hooks_t | ||
123 | #define lookupvar (math_hooks->lookupvar) | ||
124 | #define setvar (math_hooks->setvar ) | ||
125 | #define endofname (math_hooks->endofname) | ||
129 | 126 | ||
130 | #define arith_isspace(arithval) \ | 127 | #define arith_isspace(arithval) \ |
131 | (arithval == ' ' || arithval == '\n' || arithval == '\t') | 128 | (arithval == ' ' || arithval == '\n' || arithval == '\t') |
@@ -420,7 +417,7 @@ arith_apply(operator op, v_n_t *numstack, v_n_t **numstackptr, a_e_h_t *math_hoo | |||
420 | } | 417 | } |
421 | /* save to shell variable */ | 418 | /* save to shell variable */ |
422 | sprintf(buf, arith_t_fmt, rez); | 419 | sprintf(buf, arith_t_fmt, rez); |
423 | setvar(numptr_m1->var, buf, 0); | 420 | setvar(numptr_m1->var, buf); |
424 | /* after saving, make previous value for v++ or v-- */ | 421 | /* after saving, make previous value for v++ or v-- */ |
425 | if (op == TOK_POST_INC) | 422 | if (op == TOK_POST_INC) |
426 | rez--; | 423 | rez--; |
diff --git a/shell/math.h b/shell/math.h index 7b7898ea0..2b0b2b89d 100644 --- a/shell/math.h +++ b/shell/math.h | |||
@@ -87,12 +87,13 @@ typedef long arith_t; | |||
87 | #define strto_arith_t strtoul | 87 | #define strto_arith_t strtoul |
88 | #endif | 88 | #endif |
89 | 89 | ||
90 | typedef const char *(*arith_var_lookup_t)(const char *name); | 90 | typedef const char* FAST_FUNC (*arith_var_lookup_t)(const char *name); |
91 | typedef void (*arith_var_set_t)(const char *name, const char *val, int flags); | 91 | typedef void FAST_FUNC (*arith_var_set_t)(const char *name, const char *val); |
92 | typedef char *(*arith_var_endofname_t)(const char *name); | 92 | typedef char* FAST_FUNC (*arith_var_endofname_t)(const char *name); |
93 | |||
93 | typedef struct arith_eval_hooks { | 94 | typedef struct arith_eval_hooks { |
94 | arith_var_lookup_t lookupvar; | 95 | arith_var_lookup_t lookupvar; |
95 | arith_var_set_t setvar; | 96 | arith_var_set_t setvar; |
96 | arith_var_endofname_t endofname; | 97 | arith_var_endofname_t endofname; |
97 | } arith_eval_hooks_t; | 98 | } arith_eval_hooks_t; |
98 | 99 | ||