diff options
Diffstat (limited to 'shell')
-rw-r--r-- | shell/Config.in | 9 | ||||
-rw-r--r-- | shell/ash.c | 34 |
2 files changed, 31 insertions, 12 deletions
diff --git a/shell/Config.in b/shell/Config.in index b064ed41b..c8f4a936c 100644 --- a/shell/Config.in +++ b/shell/Config.in | |||
@@ -67,6 +67,15 @@ config CONFIG_ASH_MATH_SUPPORT | |||
67 | help | 67 | help |
68 | Enable math support in the ash shell. | 68 | Enable math support in the ash shell. |
69 | 69 | ||
70 | config CONFIG_ASH_MATH_SUPPORT_64 | ||
71 | bool " Extend Posix math support to 64 bit" | ||
72 | default n | ||
73 | depends on CONFIG_ASH_MATH_SUPPORT | ||
74 | help | ||
75 | Enable 64-bit math support in the ash shell. This will make | ||
76 | the shell slightly larger, but will allow computation with very | ||
77 | large numbers. | ||
78 | |||
70 | config CONFIG_ASH_GETOPTS | 79 | config CONFIG_ASH_GETOPTS |
71 | bool " Enable getopt builtin to parse positional parameters" | 80 | bool " Enable getopt builtin to parse positional parameters" |
72 | default n | 81 | default n |
diff --git a/shell/ash.c b/shell/ash.c index e2205efd2..a1c4f346b 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -1446,7 +1446,13 @@ static void defun(char *, union node *); | |||
1446 | static void unsetfunc(const char *); | 1446 | static void unsetfunc(const char *); |
1447 | 1447 | ||
1448 | #ifdef CONFIG_ASH_MATH_SUPPORT | 1448 | #ifdef CONFIG_ASH_MATH_SUPPORT |
1449 | static long dash_arith(const char *); | 1449 | #ifdef CONFIG_ASH_MATH_SUPPORT_64 |
1450 | typedef int64_t arith_t; | ||
1451 | #else | ||
1452 | typedef long arith_t; | ||
1453 | #endif | ||
1454 | static arith_t dash_arith(const char *); | ||
1455 | static arith_t arith(const char *expr, int *perrcode); | ||
1450 | #endif | 1456 | #endif |
1451 | 1457 | ||
1452 | #ifdef CONFIG_ASH_RANDOM_SUPPORT | 1458 | #ifdef CONFIG_ASH_RANDOM_SUPPORT |
@@ -4531,7 +4537,7 @@ static void ifsfree(void); | |||
4531 | static void expandmeta(struct strlist *, int); | 4537 | static void expandmeta(struct strlist *, int); |
4532 | static int patmatch(char *, const char *); | 4538 | static int patmatch(char *, const char *); |
4533 | 4539 | ||
4534 | static int cvtnum(long); | 4540 | static int cvtnum(arith_t); |
4535 | static size_t esclen(const char *, const char *); | 4541 | static size_t esclen(const char *, const char *); |
4536 | static char *scanleft(char *, char *, char *, char *, int, int); | 4542 | static char *scanleft(char *, char *, char *, char *, int, int); |
4537 | static char *scanright(char *, char *, char *, char *, int, int); | 4543 | static char *scanright(char *, char *, char *, char *, int, int); |
@@ -5902,12 +5908,16 @@ casematch(union node *pattern, char *val) | |||
5902 | */ | 5908 | */ |
5903 | 5909 | ||
5904 | static int | 5910 | static int |
5905 | cvtnum(long num) | 5911 | cvtnum(arith_t num) |
5906 | { | 5912 | { |
5907 | int len; | 5913 | int len; |
5908 | 5914 | ||
5909 | expdest = makestrspace(32, expdest); | 5915 | expdest = makestrspace(32, expdest); |
5916 | #ifdef CONFIG_ASH_MATH_SUPPORT_64 | ||
5917 | len = fmtstr(expdest, 32, "%lld", (long long) num); | ||
5918 | #else | ||
5910 | len = fmtstr(expdest, 32, "%ld", num); | 5919 | len = fmtstr(expdest, 32, "%ld", num); |
5920 | #endif | ||
5911 | STADJUST(len, expdest); | 5921 | STADJUST(len, expdest); |
5912 | return len; | 5922 | return len; |
5913 | } | 5923 | } |
@@ -12488,10 +12498,10 @@ static int timescmd(int ac, char **av) | |||
12488 | } | 12498 | } |
12489 | 12499 | ||
12490 | #ifdef CONFIG_ASH_MATH_SUPPORT | 12500 | #ifdef CONFIG_ASH_MATH_SUPPORT |
12491 | static long | 12501 | static arith_t |
12492 | dash_arith(const char *s) | 12502 | dash_arith(const char *s) |
12493 | { | 12503 | { |
12494 | long result; | 12504 | arith_t result; |
12495 | int errcode = 0; | 12505 | int errcode = 0; |
12496 | 12506 | ||
12497 | INTOFF; | 12507 | INTOFF; |
@@ -12523,7 +12533,7 @@ static int | |||
12523 | letcmd(int argc, char **argv) | 12533 | letcmd(int argc, char **argv) |
12524 | { | 12534 | { |
12525 | char **ap; | 12535 | char **ap; |
12526 | long i; | 12536 | arith_t i; |
12527 | 12537 | ||
12528 | ap = argv + 1; | 12538 | ap = argv + 1; |
12529 | if(!*ap) | 12539 | if(!*ap) |
@@ -13094,8 +13104,8 @@ static inline int is_right_associativity(operator prec) | |||
13094 | 13104 | ||
13095 | 13105 | ||
13096 | typedef struct ARITCH_VAR_NUM { | 13106 | typedef struct ARITCH_VAR_NUM { |
13097 | long val; | 13107 | arith_t val; |
13098 | long contidional_second_val; | 13108 | arith_t contidional_second_val; |
13099 | char contidional_second_val_initialized; | 13109 | char contidional_second_val_initialized; |
13100 | char *var; /* if NULL then is regular number, | 13110 | char *var; /* if NULL then is regular number, |
13101 | else is variable name */ | 13111 | else is variable name */ |
@@ -13152,9 +13162,9 @@ static int arith_lookup_val(v_n_t *t) | |||
13152 | static inline int | 13162 | static inline int |
13153 | arith_apply(operator op, v_n_t *numstack, v_n_t **numstackptr) | 13163 | arith_apply(operator op, v_n_t *numstack, v_n_t **numstackptr) |
13154 | { | 13164 | { |
13155 | long numptr_val; | 13165 | int64_t numptr_val; |
13156 | v_n_t *numptr_m1; | 13166 | v_n_t *numptr_m1; |
13157 | long rez; | 13167 | int64_t rez; |
13158 | int ret_arith_lookup_val; | 13168 | int ret_arith_lookup_val; |
13159 | 13169 | ||
13160 | if (NUMPTR == numstack) goto err; /* There is no operator that can work | 13170 | if (NUMPTR == numstack) goto err; /* There is no operator that can work |
@@ -13280,7 +13290,7 @@ arith_apply(operator op, v_n_t *numstack, v_n_t **numstackptr) | |||
13280 | goto err; | 13290 | goto err; |
13281 | } | 13291 | } |
13282 | /* save to shell variable */ | 13292 | /* save to shell variable */ |
13283 | sprintf(buf, "%ld", rez); | 13293 | sprintf(buf, "%lld", (long long) rez); |
13284 | setvar(numptr_m1->var, buf, 0); | 13294 | setvar(numptr_m1->var, buf, 0); |
13285 | /* after saving, make previous value for v++ or v-- */ | 13295 | /* after saving, make previous value for v++ or v-- */ |
13286 | if(op == TOK_POST_INC) | 13296 | if(op == TOK_POST_INC) |
@@ -13343,7 +13353,7 @@ static const char op_tokens[] = { | |||
13343 | #define endexpression &op_tokens[sizeof(op_tokens)-7] | 13353 | #define endexpression &op_tokens[sizeof(op_tokens)-7] |
13344 | 13354 | ||
13345 | 13355 | ||
13346 | extern long arith (const char *expr, int *perrcode) | 13356 | static arith_t arith (const char *expr, int *perrcode) |
13347 | { | 13357 | { |
13348 | register char arithval; /* Current character under analysis */ | 13358 | register char arithval; /* Current character under analysis */ |
13349 | operator lasttok, op; | 13359 | operator lasttok, op; |