aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2009-04-02 20:17:49 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2009-04-02 20:17:49 +0000
commitb7aaae9052025426b669a0edeec1da5997fea8be (patch)
tree062eff7de09b9307a57260c47571888ed3f598b7
parent7a79afa3cab4d35f6c042a1038554948ebe9b2e1 (diff)
downloadbusybox-w32-b7aaae9052025426b669a0edeec1da5997fea8be.tar.gz
busybox-w32-b7aaae9052025426b669a0edeec1da5997fea8be.tar.bz2
busybox-w32-b7aaae9052025426b669a0edeec1da5997fea8be.zip
hush: rename ->o_quote to ->o_escape
hush_test/hush-arith/*: new tests for arithmetic evaluation
-rw-r--r--shell/hush.c56
-rw-r--r--shell/hush_test/hush-arith/arith.right138
-rwxr-xr-xshell/hush_test/hush-arith/arith.tests302
-rwxr-xr-xshell/hush_test/hush-arith/arith1.sub40
-rwxr-xr-xshell/hush_test/hush-arith/arith2.sub57
5 files changed, 565 insertions, 28 deletions
diff --git a/shell/hush.c b/shell/hush.c
index b46a1fd76..f0d372625 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -392,9 +392,9 @@ typedef struct o_string {
392 char *data; 392 char *data;
393 int length; /* position where data is appended */ 393 int length; /* position where data is appended */
394 int maxlen; 394 int maxlen;
395 /* Misnomer! it's not "quoting", it's "protection against globbing"! 395 /* Protect newly added chars against globbing
396 * (by prepending \ to *, ?, [ and to \ too) */ 396 * (by prepending \ to *, ?, [, \) */
397 smallint o_quote; 397 smallint o_escape;
398 smallint o_glob; 398 smallint o_glob;
399 smallint nonnull; 399 smallint nonnull;
400 smallint has_empty_slot; 400 smallint has_empty_slot;
@@ -1440,7 +1440,7 @@ static void o_addqchr(o_string *o, int ch)
1440static void o_addQchr(o_string *o, int ch) 1440static void o_addQchr(o_string *o, int ch)
1441{ 1441{
1442 int sz = 1; 1442 int sz = 1;
1443 if (o->o_quote && strchr("*?[\\", ch)) { 1443 if (o->o_escape && strchr("*?[\\", ch)) {
1444 sz++; 1444 sz++;
1445 o->data[o->length] = '\\'; 1445 o->data[o->length] = '\\';
1446 o->length++; 1446 o->length++;
@@ -1453,7 +1453,7 @@ static void o_addQchr(o_string *o, int ch)
1453 1453
1454static void o_addQstr(o_string *o, const char *str, int len) 1454static void o_addQstr(o_string *o, const char *str, int len)
1455{ 1455{
1456 if (!o->o_quote) { 1456 if (!o->o_escape) {
1457 o_addstr(o, str, len); 1457 o_addstr(o, str, len);
1458 return; 1458 return;
1459 } 1459 }
@@ -1668,7 +1668,7 @@ static int expand_on_ifs(o_string *output, int n, const char *str)
1668 while (1) { 1668 while (1) {
1669 int word_len = strcspn(str, G.ifs); 1669 int word_len = strcspn(str, G.ifs);
1670 if (word_len) { 1670 if (word_len) {
1671 if (output->o_quote || !output->o_glob) 1671 if (output->o_escape || !output->o_glob)
1672 o_addQstr(output, str, word_len); 1672 o_addQstr(output, str, word_len);
1673 else /* protect backslashes against globbing up :) */ 1673 else /* protect backslashes against globbing up :) */
1674 o_addstr_duplicate_backslash(output, str, word_len); 1674 o_addstr_duplicate_backslash(output, str, word_len);
@@ -1751,9 +1751,9 @@ static int expand_vars_to_list(o_string *output, int n, char *arg, char or_mask)
1751 break; 1751 break;
1752 ored_ch |= first_ch; /* do it for "$@" _now_, when we know it's not empty */ 1752 ored_ch |= first_ch; /* do it for "$@" _now_, when we know it's not empty */
1753 if (!(first_ch & 0x80)) { /* unquoted $* or $@ */ 1753 if (!(first_ch & 0x80)) { /* unquoted $* or $@ */
1754 smallint sv = output->o_quote; 1754 smallint sv = output->o_escape;
1755 /* unquoted var's contents should be globbed, so don't quote */ 1755 /* unquoted var's contents should be globbed, so don't escape */
1756 output->o_quote = 0; 1756 output->o_escape = 0;
1757 while (G.global_argv[i]) { 1757 while (G.global_argv[i]) {
1758 n = expand_on_ifs(output, n, G.global_argv[i]); 1758 n = expand_on_ifs(output, n, G.global_argv[i]);
1759 debug_printf_expand("expand_vars_to_list: argv %d (last %d)\n", i, G.global_argc - 1); 1759 debug_printf_expand("expand_vars_to_list: argv %d (last %d)\n", i, G.global_argc - 1);
@@ -1766,7 +1766,7 @@ static int expand_vars_to_list(o_string *output, int n, char *arg, char or_mask)
1766 debug_print_list("expand_vars_to_list[3]", output, n); 1766 debug_print_list("expand_vars_to_list[3]", output, n);
1767 } 1767 }
1768 } 1768 }
1769 output->o_quote = sv; 1769 output->o_escape = sv;
1770 } else 1770 } else
1771 /* If or_mask is nonzero, we handle assignment 'a=....$@.....' 1771 /* If or_mask is nonzero, we handle assignment 'a=....$@.....'
1772 * and in this case should treat it like '$*' - see 'else...' below */ 1772 * and in this case should treat it like '$*' - see 'else...' below */
@@ -1945,17 +1945,17 @@ static int expand_vars_to_list(o_string *output, int n, char *arg, char or_mask)
1945 store_val: 1945 store_val:
1946#endif 1946#endif
1947 if (!(first_ch & 0x80)) { /* unquoted $VAR */ 1947 if (!(first_ch & 0x80)) { /* unquoted $VAR */
1948 debug_printf_expand("unquoted '%s', output->o_quote:%d\n", val, output->o_quote); 1948 debug_printf_expand("unquoted '%s', output->o_escape:%d\n", val, output->o_escape);
1949 if (val) { 1949 if (val) {
1950 /* unquoted var's contents should be globbed, so don't quote */ 1950 /* unquoted var's contents should be globbed, so don't escape */
1951 smallint sv = output->o_quote; 1951 smallint sv = output->o_escape;
1952 output->o_quote = 0; 1952 output->o_escape = 0;
1953 n = expand_on_ifs(output, n, val); 1953 n = expand_on_ifs(output, n, val);
1954 val = NULL; 1954 val = NULL;
1955 output->o_quote = sv; 1955 output->o_escape = sv;
1956 } 1956 }
1957 } else { /* quoted $VAR, val will be appended below */ 1957 } else { /* quoted $VAR, val will be appended below */
1958 debug_printf_expand("quoted '%s', output->o_quote:%d\n", val, output->o_quote); 1958 debug_printf_expand("quoted '%s', output->o_escape:%d\n", val, output->o_escape);
1959 } 1959 }
1960 } /* default: */ 1960 } /* default: */
1961 } /* switch (char after <SPECIAL_VAR_SYMBOL>) */ 1961 } /* switch (char after <SPECIAL_VAR_SYMBOL>) */
@@ -1999,7 +1999,7 @@ static char **expand_variables(char **argv, int or_mask)
1999 o_string output = NULL_O_STRING; 1999 o_string output = NULL_O_STRING;
2000 2000
2001 if (or_mask & 0x100) { 2001 if (or_mask & 0x100) {
2002 output.o_quote = 1; /* protect against globbing for "$var" */ 2002 output.o_escape = 1; /* protect against globbing for "$var" */
2003 /* (unquoted $var will temporarily switch it off) */ 2003 /* (unquoted $var will temporarily switch it off) */
2004 output.o_glob = 1; 2004 output.o_glob = 1;
2005 } 2005 }
@@ -3979,7 +3979,7 @@ static int handle_dollar(o_string *dest, struct in_str *input)
3979{ 3979{
3980 int expansion; 3980 int expansion;
3981 int ch = i_peek(input); /* first character after the $ */ 3981 int ch = i_peek(input); /* first character after the $ */
3982 unsigned char quote_mask = dest->o_quote ? 0x80 : 0; 3982 unsigned char quote_mask = dest->o_escape ? 0x80 : 0;
3983 3983
3984 debug_printf_parse("handle_dollar entered: ch='%c'\n", ch); 3984 debug_printf_parse("handle_dollar entered: ch='%c'\n", ch);
3985 if (isalpha(ch)) { 3985 if (isalpha(ch)) {
@@ -4143,7 +4143,7 @@ static int parse_stream_dquoted(o_string *dest, struct in_str *input, int dquote
4143 if (ch == dquote_end) { /* may be only '"' or EOF */ 4143 if (ch == dquote_end) { /* may be only '"' or EOF */
4144 dest->nonnull = 1; 4144 dest->nonnull = 1;
4145 if (dest->o_assignment == NOT_ASSIGNMENT) 4145 if (dest->o_assignment == NOT_ASSIGNMENT)
4146 dest->o_quote ^= 1; 4146 dest->o_escape ^= 1;
4147 debug_printf_parse("parse_stream_dquoted return 0\n"); 4147 debug_printf_parse("parse_stream_dquoted return 0\n");
4148 return 0; 4148 return 0;
4149 } 4149 }
@@ -4157,8 +4157,8 @@ static int parse_stream_dquoted(o_string *dest, struct in_str *input, int dquote
4157 if (ch != '\n') { 4157 if (ch != '\n') {
4158 next = i_peek(input); 4158 next = i_peek(input);
4159 } 4159 }
4160 debug_printf_parse(": ch=%c (%d) m=%d quote=%d\n", 4160 debug_printf_parse(": ch=%c (%d) m=%d escape=%d\n",
4161 ch, ch, m, dest->o_quote); 4161 ch, ch, m, dest->o_escape);
4162 /* Basically, checking every CHAR_SPECIAL char except '"' */ 4162 /* Basically, checking every CHAR_SPECIAL char except '"' */
4163 if (ch == '\\') { 4163 if (ch == '\\') {
4164 if (next == EOF) { 4164 if (next == EOF) {
@@ -4225,13 +4225,13 @@ static int parse_stream(o_string *dest, struct parse_context *ctx,
4225 int is_in_dquote; 4225 int is_in_dquote;
4226 int next; 4226 int next;
4227 4227
4228 /* Only double-quote state is handled in the state variable dest->o_quote. 4228 /* Double-quote state is handled in the state variable is_in_dquote.
4229 * A single-quote triggers a bypass of the main loop until its mate is 4229 * A single-quote triggers a bypass of the main loop until its mate is
4230 * found. When recursing, quote state is passed in via dest->o_quote. */ 4230 * found. When recursing, quote state is passed in via dest->o_escape. */
4231 4231
4232 debug_printf_parse("parse_stream entered, end_trigger='%s' dest->o_assignment:%d\n", end_trigger, dest->o_assignment); 4232 debug_printf_parse("parse_stream entered, end_trigger='%s' dest->o_assignment:%d\n", end_trigger, dest->o_assignment);
4233 4233
4234 is_in_dquote = dest->o_quote; 4234 is_in_dquote = dest->o_escape;
4235 while (1) { 4235 while (1) {
4236 if (is_in_dquote) { 4236 if (is_in_dquote) {
4237 if (parse_stream_dquoted(dest, input, '"')) 4237 if (parse_stream_dquoted(dest, input, '"'))
@@ -4248,8 +4248,8 @@ static int parse_stream(o_string *dest, struct parse_context *ctx,
4248 next = i_peek(input); 4248 next = i_peek(input);
4249 } 4249 }
4250 } 4250 }
4251 debug_printf_parse(": ch=%c (%d) m=%d quote=%d\n", 4251 debug_printf_parse(": ch=%c (%d) m=%d escape=%d\n",
4252 ch, ch, m, dest->o_quote); 4252 ch, ch, m, dest->o_escape);
4253 if (m == CHAR_ORDINARY) { 4253 if (m == CHAR_ORDINARY) {
4254 o_addQchr(dest, ch); 4254 o_addQchr(dest, ch);
4255 if ((dest->o_assignment == MAYBE_ASSIGNMENT 4255 if ((dest->o_assignment == MAYBE_ASSIGNMENT
@@ -4365,7 +4365,7 @@ static int parse_stream(o_string *dest, struct parse_context *ctx,
4365 dest->nonnull = 1; 4365 dest->nonnull = 1;
4366 is_in_dquote ^= 1; /* invert */ 4366 is_in_dquote ^= 1; /* invert */
4367 if (dest->o_assignment == NOT_ASSIGNMENT) 4367 if (dest->o_assignment == NOT_ASSIGNMENT)
4368 dest->o_quote ^= 1; 4368 dest->o_escape ^= 1;
4369 break; 4369 break;
4370#if ENABLE_HUSH_TICK 4370#if ENABLE_HUSH_TICK
4371 case '`': { 4371 case '`': {
@@ -4594,7 +4594,7 @@ static int parse_and_run_stream(struct in_str *inp, int parse_flag)
4594 } 4594 }
4595#endif 4595#endif
4596 /*temp.nonnull = 0; - o_free does it below */ 4596 /*temp.nonnull = 0; - o_free does it below */
4597 /*temp.o_quote = 0; - o_free does it below */ 4597 /*temp.o_escape = 0; - o_free does it below */
4598 free_pipe_list(ctx.list_head, /* indent: */ 0); 4598 free_pipe_list(ctx.list_head, /* indent: */ 0);
4599 /* Discard all unprocessed line input, force prompt on */ 4599 /* Discard all unprocessed line input, force prompt on */
4600 inp->p = NULL; 4600 inp->p = NULL;
diff --git a/shell/hush_test/hush-arith/arith.right b/shell/hush_test/hush-arith/arith.right
new file mode 100644
index 000000000..a35fe893f
--- /dev/null
+++ b/shell/hush_test/hush-arith/arith.right
@@ -0,0 +1,138 @@
1Format: 'expected actual'
2163 163
34 4
416 16
58 8
62 2
74 4
82 2
92 2
101 1
110 0
120 0
130 0
141 1
151 1
162 2
17-3 -3
18-2 -2
191 1
200 0
212 2
22131072 131072
2329 29
2433 33
2549 49
261 1
271 1
280 0
290 0
301 1
311 1
321 1
332 2
343 3
351 1
3658 58
372 2
3860 60
391 1
40256 256
4116 16
4262 62
434 4
4429 29
455 5
46-4 -4
474 4
481 1
4932 32
5032 32
511 1
521 1
5332 32
5420 20
5530 30
5620 20
5730 30
58hush: arith: syntax error
596 6
606,5,3 6,5,3
61263 263
62255 255
6340 40
64hush: arith: syntax error
65hush: arith: divide by zero
66hush: can't exec 'let': No such file or directory
67hush: arith: syntax error
68hush: can't exec 'let': No such file or directory
69abc
70def
71ghi
72hush: arith: syntax error
7316 16
74hush: arith: syntax error
75hush: arith: syntax error
76hush: arith: syntax error
779 9
78hush: arith: syntax error
79hush: arith: syntax error
809 9
819 9
829 9
837 7
847
854 4
8632767 32767
8732768 32768
88131072 131072
892147483647 2147483647
901 1
914 4
924 4
935 5
945 5
954 4
963 3
973 3
984 4
994 4
100hush: arith: syntax error
101hush: arith: syntax error
102hush: arith: syntax error
103hush: arith: syntax error
104hush: arith: syntax error
1054 4
1067 7
107-7 -7
108hush: arith: syntax error
109hush: arith: syntax error
110hush: arith: syntax error
111hush: arith: syntax error
1126 6
1133 3
1147 7
1154 4
1160 0
1173 3
1187 7
1192 2
120-2 -2
1211 1
122hush: arith: syntax error
123hush: arith: syntax error
124hush: arith: syntax error
125hush: arith: syntax error
126hush: arith: syntax error
1275 5
1281 1
1294 4
1300 0
131hush: arith: syntax error
132hush: arith: syntax error
1338 12
134hush: arith: syntax error
13542
13642
13742
138hush: can't exec 'a[b[c]d]=e': No such file or directory
diff --git a/shell/hush_test/hush-arith/arith.tests b/shell/hush_test/hush-arith/arith.tests
new file mode 100755
index 000000000..57e66e888
--- /dev/null
+++ b/shell/hush_test/hush-arith/arith.tests
@@ -0,0 +1,302 @@
1#ash# set +o posix
2#ash# declare -i iv jv
3
4echo "Format: 'expected actual'"
5
6iv=$(( 3 + 5 * 32 ))
7echo 163 $iv
8#ash# iv=iv+3
9#ash# echo 166 $iv
10iv=2
11jv=iv
12
13: $((jv *= 2)) ##hush## let "jv *= 2"
14echo 4 $jv
15jv=$(( $jv << 2 ))
16echo 16 $jv
17
18: $((jv=$jv / 2)) ##hush## let jv="$jv / 2"
19echo 8 $jv
20#ash# jv="jv >> 2"
21: $((jv=jv >> 2)) ##hush## let jv="jv >> 2"
22echo 2 $jv
23
24iv=$((iv+ $jv))
25echo 4 $iv
26echo 2 $((iv -= jv))
27echo 2 $iv
28echo 1 $(( iv == jv ))
29echo 0 $(( iv != $jv ))
30echo 0 $(( iv < jv ))
31echo 0 $(( $iv > $jv ))
32echo 1 $(( iv <= $jv ))
33echo 1 $(( $iv >= jv ))
34
35echo 2 $jv
36echo -3 $(( ~$jv ))
37echo -2 $(( ~1 ))
38echo 1 $(( ! 0 ))
39
40echo 0 $(( jv % 2 ))
41echo 2 $(( $iv % 4 ))
42
43echo 131072 $(( iv <<= 16 ))
44echo 29 $(( iv %= 33 ))
45
46echo 33 $(( 33 & 55 ))
47echo 49 $(( 33 | 17 ))
48
49echo 1 $(( iv && $jv ))
50echo 1 $(( $iv || jv ))
51
52echo 0 $(( iv && 0 ))
53echo 0 $(( iv & 0 ))
54echo 1 $(( iv && 1 ))
55echo 1 $(( iv & 1 ))
56
57echo 1 $(( $jv || 0 ))
58echo 2 $(( jv | 0 ))
59echo 3 $(( jv | 1 ))
60echo 1 $(( $jv || 1 ))
61
62: $((iv *= jv)) ##hush## let 'iv *= jv'
63echo 58 $iv
64echo 2 $jv
65: $((jv += $iv)) ##hush## let "jv += $iv"
66echo 60 $jv
67
68echo 1 $(( jv /= iv ))
69echo 256 $(( jv <<= 8 ))
70echo 16 $(( jv >>= 4 ))
71
72echo 62 $(( iv |= 4 ))
73echo 4 $(( iv &= 4 ))
74
75echo 29 $(( iv += (jv + 9)))
76echo 5 $(( (iv + 4) % 7 ))
77
78# unary plus, minus
79echo -4 $(( +4 - 8 ))
80echo 4 $(( -4 + 8 ))
81
82# conditional expressions
83echo 1 $(( 4<5 ? 1 : 32))
84echo 32 $(( 4>5 ? 1 : 32))
85echo 32 $(( 4>(2+3) ? 1 : 32))
86echo 1 $(( 4<(2+3) ? 1 : 32))
87echo 1 $(( (2+2)<(2+3) ? 1 : 32))
88echo 32 $(( (2+2)>(2+3) ? 1 : 32))
89
90# check that the unevaluated part of the ternary operator does not do
91# evaluation or assignment
92x=i+=2
93y=j+=2
94#ash# declare -i i=1 j=1
95 i=1
96 j=1
97echo 20 $((1 ? 20 : (x+=2)))
98#ash# echo $i,$x # ash mishandles this
99echo 30 $((0 ? (y+=2) : 30))
100#ash# echo $j,$y # ash mishandles this
101
102x=i+=2
103y=j+=2
104#ash# declare -i i=1 j=1
105 i=1
106 j=1
107echo 20 $((1 ? 20 : (x+=2)))
108#ash# echo $i,$x # ash mishandles this
109echo 30 $((0 ? (y+=2) : 30))
110#ash# echo $i,$y # ash mishandles this
111
112# check precedence of assignment vs. conditional operator
113# should be an error
114#ash# declare -i x=2
115 x=2
116#ashnote# bash reports error but continues, ash aborts - using subshell to 'emulate' bash:
117( y=$((1 ? 20 : x+=2)) )
118
119# check precedence of assignment vs. conditional operator
120#ash# declare -i x=2
121 x=2
122# ash says "line NNN: syntax error: 0 ? x+=2 : 20"
123#ash# echo 20 $((0 ? x+=2 : 20))
124
125# associativity of assignment-operator operator
126#ash# declare -i i=1 j=2 k=3
127i=1
128j=2
129k=3
130echo 6 $((i += j += k))
131echo 6,5,3 $i,$j,$k
132
133# octal, hex
134echo 263 $(( 0x100 | 007 ))
135echo 255 $(( 0xff ))
136#ash# echo 255 $(( 16#ff ))
137#ash# echo 127 $(( 16#FF/2 ))
138#ash# echo 36 $(( 8#44 ))
139
140echo 40 $(( 8 ^ 32 ))
141
142#ash# # other bases
143#ash# echo 10 $(( 16#a ))
144#ash# echo 10 $(( 32#a ))
145#ash# echo 10 $(( 56#a ))
146#ash# echo 10 $(( 64#a ))
147#ash#
148#ash# echo 10 $(( 16#A ))
149#ash# echo 10 $(( 32#A ))
150#ash# echo 36 $(( 56#A ))
151#ash# echo 36 $(( 64#A ))
152#ash#
153#ash# echo 62 $(( 64#@ ))
154#ash# echo 63 $(( 64#_ ))
155
156#ash# # weird bases (error)
157#ash# echo $(( 3425#56 ))
158
159#ash# # missing number after base
160#ash# echo 0 $(( 2# ))
161
162# these should generate errors
163( echo $(( 7 = 43 )) )
164#ash# echo $(( 2#44 ))
165( echo $(( 44 / 0 )) )
166( let 'jv += $iv' )
167( echo $(( jv += \$iv )) )
168( let 'rv = 7 + (43 * 6' )
169
170#ash# # more errors
171#ash# declare -i i
172#ash# i=0#4
173#ash# i=2#110#11
174
175((echo abc; echo def;); echo ghi)
176
177#ash# if (((4+4) + (4 + 7))); then
178#ash# echo ok
179#ash# fi
180
181#ash# (()) # make sure the null expression works OK
182
183#ash# a=(0 2 4 6)
184#ash# echo 6 $(( a[1] + a[2] ))
185#ash# echo 1 $(( (a[1] + a[2]) == a[3] ))
186#ash# (( (a[1] + a[2]) == a[3] )) ; echo 0 $?
187
188# test pushing and popping the expression stack
189unset A
190A="4 + "
191( echo A $(( ( 4 + A ) + 4 )) )
192A="3 + 5"
193echo 16 $(( ( 4 + A ) + 4 ))
194
195# badly-formed conditional expressions
196( echo $(( 4 ? : $A )) )
197( echo $(( 1 ? 20 )) )
198( echo $(( 4 ? 20 : )) )
199
200# precedence and short-circuit evaluation
201B=9
202echo 9 $B
203
204# error
205( echo $(( 0 && B=42 )); echo 9 $B )
206
207# error
208( echo $(( 1 || B=88 )); echo 9 $B )
209
210# ash mistakenly evaluates B=... below
211#ash# echo 0 $(( 0 && (B=42) ))
212echo 9 $B
213#ash# echo 0 $(( (${$} - $$) && (B=42) ))
214echo 9 $B
215#ash# echo 1 $(( 1 || (B=88) ))
216echo 9 $B
217
218
219# until command with (( )) command
220x=7
221
222echo 7 $x
223#ash# until (( x == 4 ))
224 until test "$x" = 4
225do
226 echo $x
227 x=4
228done
229
230echo 4 $x
231
232# exponentiation
233echo 32767 $(( 2**15 - 1))
234echo 32768 $(( 2**(16-1)))
235echo 131072 $(( 2**16*2 ))
236echo 2147483647 $(( 2**31-1))
237echo 1 $(( 2**0 ))
238
239# {pre,post}-{inc,dec}rement and associated errors
240
241x=4
242
243echo 4 $x
244echo 4 $(( x++ ))
245echo 5 $x
246echo 5 $(( x-- ))
247echo 4 $x
248
249echo 3 $(( --x ))
250echo 3 $x
251
252echo 4 $(( ++x ))
253echo 4 $x
254
255# bash 3.2 apparently thinks that ++7 is 7
256#ash# echo 7 $(( ++7 ))
257( echo $(( 7-- )) )
258
259( echo $(( --x=7 )) )
260( echo $(( ++x=7 )) )
261
262( echo $(( x++=7 )) )
263( echo $(( x--=7 )) )
264
265echo 4 $x
266
267echo 7 $(( +7 ))
268echo -7 $(( -7 ))
269
270# bash 3.2 apparently thinks that ++7 is 7
271#ash# echo $(( ++7 ))
272#ash# echo $(( --7 ))
273
274${THIS_SH} ./arith1.sub
275${THIS_SH} ./arith2.sub
276
277x=4
278y=7
279
280#ash# (( x=8 , y=12 ))
281 x=8
282 y=12
283echo $x $y
284
285#ash# # should be an error
286#ash# (( x=9 y=41 ))
287
288# These are errors
289unset b
290( echo $((a b)) )
291#ash# ((a b))
292
293n=42
294printf "%d\n" $n
295printf "%i\n" $n
296#ash# echo $(( 8#$(printf "%o\n" $n) ))
297printf "%u\n" $n
298#ash# echo $(( 16#$(printf "%x\n" $n) ))
299#ash# echo $(( 16#$(printf "%X\n" $n) ))
300
301# causes longjmp botches through bash-2.05b
302a[b[c]d]=e
diff --git a/shell/hush_test/hush-arith/arith1.sub b/shell/hush_test/hush-arith/arith1.sub
new file mode 100755
index 000000000..80aa99922
--- /dev/null
+++ b/shell/hush_test/hush-arith/arith1.sub
@@ -0,0 +1,40 @@
1# test of redone post-increment and post-decrement code
2( echo $(( 4-- )) )
3( echo $(( 4++ )) )
4( echo $(( 4 -- )) )
5( echo $(( 4 ++ )) )
6
7#ash# (( array[0]++ ))
8#ash# echo ${array}
9
10#ash# (( array[0] ++ ))
11#ash# echo ${array}
12
13#ash# (( a++ ))
14#ash# echo $a
15#ash# (( a ++ ))
16#ash# echo $a
17 a=2
18
19echo 6 $(( a ++ + 4 ))
20echo 3 $a
21
22echo 7 $(( a+++4 ))
23echo 4 $a
24
25echo 0 $(( a---4 ))
26echo 3 $a
27
28echo 7 $(( a -- + 4 ))
29echo 2 $a
30
31echo -2 $(( a -- - 4 ))
32echo 1 $a
33
34#ash# (( ++ + 7 ))
35
36#ash# (( ++ ))
37( echo $(( +++7 )) )
38# bash 3.2 apparently thinks that ++ +7 is 7
39#ash# echo $(( ++ + 7 ))
40#ash# (( -- ))
diff --git a/shell/hush_test/hush-arith/arith2.sub b/shell/hush_test/hush-arith/arith2.sub
new file mode 100755
index 000000000..f7e3c9235
--- /dev/null
+++ b/shell/hush_test/hush-arith/arith2.sub
@@ -0,0 +1,57 @@
1# bash 3.2 apparently thinks that ++7 is 7 etc
2( echo $(( --7 )) )
3( echo $(( ++7 )) )
4( echo $(( -- 7 )) )
5( echo $(( ++ 7 )) )
6
7#ash# ((++array[0] ))
8#ash# echo 1 $array
9#ash# (( ++ array[0] ))
10#ash# echo 2 $array
11
12#ash# (( ++a ))
13#ash# echo 1 $a
14#ash# (( ++ a ))
15#ash# echo 2 $a
16
17#ash# (( --a ))
18#ash# echo 1 $a
19#ash# (( -- a ))
20#ash# echo 0 $a
21 a=0
22
23echo 5 $(( 4 + ++a ))
24echo 1 $a
25
26# ash doesn't handle it right...
27#ash# echo 6 $(( 4+++a ))
28#ash# echo 2 $a
29 a=2
30
31# ash doesn't handle it right...
32#ash# echo 3 $(( 4---a ))
33#ash# echo 1 $a
34 a=1
35
36echo 4 $(( 4 - -- a ))
37echo 0 $a
38
39#ash# (( -- ))
40# bash 3.2 apparently thinks that ---7 is -7
41#ash# echo $(( ---7 ))
42( echo $(( -- - 7 )) )
43
44#ash# (( ++ ))
45# bash 3.2: 7
46#ash# echo 7 $(( ++7 ))
47( echo $(( ++ + 7 )) )
48
49# bash 3.2: -7
50#ash# echo -7 $(( ++-7 ))
51# bash 3.2: -7
52#ash# echo -7 $(( ++ - 7 ))
53
54# bash 3.2: 7
55#ash# echo 7 $(( +--7 ))
56# bash 3.2: 7
57#ash# echo 7 $(( -- + 7 ))