aboutsummaryrefslogtreecommitdiff
path: root/shell/math.c
diff options
context:
space:
mode:
Diffstat (limited to 'shell/math.c')
-rw-r--r--shell/math.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/shell/math.c b/shell/math.c
index 2942cdd26..049d5703b 100644
--- a/shell/math.c
+++ b/shell/math.c
@@ -668,19 +668,26 @@ evaluate_string(arith_state_t *math_state, const char *expr)
668 668
669 /* Should be an operator */ 669 /* Should be an operator */
670 670
671 /* Special case: NUM-- and NUM++ are not recognized if NUM 671 /* Special case: XYZ--, XYZ++, --XYZ, ++XYZ are recognized
672 * is a literal number, not a variable. IOW: 672 * only if XYZ is a variable name, not a number or EXPR. IOW:
673 * "a+++v" is a++ + v. 673 * "a+++v" is a++ + v.
674 * "7+++v" is 7 + ++v, not 7++ + v. 674 * "7+++v" is 7 + ++v, not 7++ + v.
675 * "--7" is - - 7, not --7.
676 * "++++a" is + + ++a, not ++ ++ a.
677 * (we still mishandle "(a)+++7", should be treated as (a) + + + 7, but we do increment a)
675 */ 678 */
676 if (lasttok == TOK_NUM && !numstackptr[-1].var /* number literal */ 679 if ((expr[0] == '+' || expr[0] == '-')
677 && (expr[0] == '+' || expr[0] == '-')
678 && (expr[1] == expr[0]) 680 && (expr[1] == expr[0])
679 ) { 681 ) {
680 //bb_error_msg("special %c%c", expr[0], expr[0]); 682 if (numstackptr == numstack || !numstackptr[-1].var) { /* not a VAR++ */
681 op = (expr[0] == '+' ? TOK_ADD : TOK_SUB); 683 char next = skip_whitespace(expr + 2)[0];
682 expr += 1; 684 if (!(isalpha(next) || next == '_')) { /* not a ++VAR */
683 goto tok_found1; 685 //bb_error_msg("special %c%c", expr[0], expr[0]);
686 op = (expr[0] == '+' ? TOK_ADD : TOK_SUB);
687 expr++;
688 goto tok_found1;
689 }
690 }
684 } 691 }
685 692
686 p = op_tokens; 693 p = op_tokens;