aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2004-06-22 08:29:45 +0000
committerandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2004-06-22 08:29:45 +0000
commit5d3b12c60ee497d5203d067e424864c992069401 (patch)
tree1f7b66f71f04cf66fab5fc0a385adb34d5d5b97b /shell
parent3152f0fa8f49f1c122e204f654f6a072dca48f4c (diff)
downloadbusybox-w32-5d3b12c60ee497d5203d067e424864c992069401.tar.gz
busybox-w32-5d3b12c60ee497d5203d067e424864c992069401.tar.bz2
busybox-w32-5d3b12c60ee497d5203d067e424864c992069401.zip
Patch from Bastian Blank:
The updated patch adds a config option to explicitely enable 64 bit arithmetic. Also it removes the arith prototype from libbb.h as it is not used outside of ash. Bastian this patch has been slightly modified by Erik for cleanliness. git-svn-id: svn://busybox.net/trunk/busybox@8910 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'shell')
-rw-r--r--shell/Config.in9
-rw-r--r--shell/ash.c34
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
70config 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
70config CONFIG_ASH_GETOPTS 79config 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 *);
1446static void unsetfunc(const char *); 1446static void unsetfunc(const char *);
1447 1447
1448#ifdef CONFIG_ASH_MATH_SUPPORT 1448#ifdef CONFIG_ASH_MATH_SUPPORT
1449static long dash_arith(const char *); 1449#ifdef CONFIG_ASH_MATH_SUPPORT_64
1450typedef int64_t arith_t;
1451#else
1452typedef long arith_t;
1453#endif
1454static arith_t dash_arith(const char *);
1455static 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);
4531static void expandmeta(struct strlist *, int); 4537static void expandmeta(struct strlist *, int);
4532static int patmatch(char *, const char *); 4538static int patmatch(char *, const char *);
4533 4539
4534static int cvtnum(long); 4540static int cvtnum(arith_t);
4535static size_t esclen(const char *, const char *); 4541static size_t esclen(const char *, const char *);
4536static char *scanleft(char *, char *, char *, char *, int, int); 4542static char *scanleft(char *, char *, char *, char *, int, int);
4537static char *scanright(char *, char *, char *, char *, int, int); 4543static char *scanright(char *, char *, char *, char *, int, int);
@@ -5902,12 +5908,16 @@ casematch(union node *pattern, char *val)
5902 */ 5908 */
5903 5909
5904static int 5910static int
5905cvtnum(long num) 5911cvtnum(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
12491static long 12501static arith_t
12492dash_arith(const char *s) 12502dash_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
12523letcmd(int argc, char **argv) 12533letcmd(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
13096typedef struct ARITCH_VAR_NUM { 13106typedef 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)
13152static inline int 13162static inline int
13153arith_apply(operator op, v_n_t *numstack, v_n_t **numstackptr) 13163arith_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
13346extern long arith (const char *expr, int *perrcode) 13356static 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;