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.
This commit is contained in:
Eric Andersen 2004-06-22 08:29:45 +00:00
parent 16a4c41674
commit ed9ecf7894
3 changed files with 31 additions and 14 deletions

View File

@ -289,8 +289,6 @@ char *concat_path_file(const char *path, const char *filename);
char *concat_subpath_file(const char *path, const char *filename); char *concat_subpath_file(const char *path, const char *filename);
char *last_char_is(const char *s, int c); char *last_char_is(const char *s, int c);
extern long arith (const char *startbuf, int *errcode);
int read_package_field(const char *package_buffer, char **field_name, char **field_value); int read_package_field(const char *package_buffer, char **field_name, char **field_value);
//#warning yuk! //#warning yuk!
char *fgets_str(FILE *file, const char *terminating_string); char *fgets_str(FILE *file, const char *terminating_string);

View File

@ -67,6 +67,15 @@ config CONFIG_ASH_MATH_SUPPORT
help help
Enable math support in the ash shell. Enable math support in the ash shell.
config CONFIG_ASH_MATH_SUPPORT_64
bool " Extend Posix math support to 64 bit"
default n
depends on CONFIG_ASH_MATH_SUPPORT
help
Enable 64-bit math support in the ash shell. This will make
the shell slightly larger, but will allow computation with very
large numbers.
config CONFIG_ASH_GETOPTS config CONFIG_ASH_GETOPTS
bool " Enable getopt builtin to parse positional parameters" bool " Enable getopt builtin to parse positional parameters"
default n default n

View File

@ -1446,7 +1446,13 @@ static void defun(char *, union node *);
static void unsetfunc(const char *); static void unsetfunc(const char *);
#ifdef CONFIG_ASH_MATH_SUPPORT #ifdef CONFIG_ASH_MATH_SUPPORT
static long dash_arith(const char *); #ifdef CONFIG_ASH_MATH_SUPPORT_64
typedef int64_t arith_t;
#else
typedef long arith_t;
#endif
static arith_t dash_arith(const char *);
static arith_t arith(const char *expr, int *perrcode);
#endif #endif
#ifdef CONFIG_ASH_RANDOM_SUPPORT #ifdef CONFIG_ASH_RANDOM_SUPPORT
@ -4531,7 +4537,7 @@ static void ifsfree(void);
static void expandmeta(struct strlist *, int); static void expandmeta(struct strlist *, int);
static int patmatch(char *, const char *); static int patmatch(char *, const char *);
static int cvtnum(long); static int cvtnum(arith_t);
static size_t esclen(const char *, const char *); static size_t esclen(const char *, const char *);
static char *scanleft(char *, char *, char *, char *, int, int); static char *scanleft(char *, char *, char *, char *, int, int);
static char *scanright(char *, char *, char *, char *, int, int); static char *scanright(char *, char *, char *, char *, int, int);
@ -5902,12 +5908,16 @@ casematch(union node *pattern, char *val)
*/ */
static int static int
cvtnum(long num) cvtnum(arith_t num)
{ {
int len; int len;
expdest = makestrspace(32, expdest); expdest = makestrspace(32, expdest);
#ifdef CONFIG_ASH_MATH_SUPPORT_64
len = fmtstr(expdest, 32, "%lld", (long long) num);
#else
len = fmtstr(expdest, 32, "%ld", num); len = fmtstr(expdest, 32, "%ld", num);
#endif
STADJUST(len, expdest); STADJUST(len, expdest);
return len; return len;
} }
@ -12488,10 +12498,10 @@ static int timescmd(int ac, char **av)
} }
#ifdef CONFIG_ASH_MATH_SUPPORT #ifdef CONFIG_ASH_MATH_SUPPORT
static long static arith_t
dash_arith(const char *s) dash_arith(const char *s)
{ {
long result; arith_t result;
int errcode = 0; int errcode = 0;
INTOFF; INTOFF;
@ -12523,7 +12533,7 @@ static int
letcmd(int argc, char **argv) letcmd(int argc, char **argv)
{ {
char **ap; char **ap;
long i; arith_t i;
ap = argv + 1; ap = argv + 1;
if(!*ap) if(!*ap)
@ -13094,8 +13104,8 @@ static inline int is_right_associativity(operator prec)
typedef struct ARITCH_VAR_NUM { typedef struct ARITCH_VAR_NUM {
long val; arith_t val;
long contidional_second_val; arith_t contidional_second_val;
char contidional_second_val_initialized; char contidional_second_val_initialized;
char *var; /* if NULL then is regular number, char *var; /* if NULL then is regular number,
else is variable name */ else is variable name */
@ -13152,9 +13162,9 @@ static int arith_lookup_val(v_n_t *t)
static inline int static inline int
arith_apply(operator op, v_n_t *numstack, v_n_t **numstackptr) arith_apply(operator op, v_n_t *numstack, v_n_t **numstackptr)
{ {
long numptr_val; int64_t numptr_val;
v_n_t *numptr_m1; v_n_t *numptr_m1;
long rez; int64_t rez;
int ret_arith_lookup_val; int ret_arith_lookup_val;
if (NUMPTR == numstack) goto err; /* There is no operator that can work 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)
goto err; goto err;
} }
/* save to shell variable */ /* save to shell variable */
sprintf(buf, "%ld", rez); sprintf(buf, "%lld", (long long) rez);
setvar(numptr_m1->var, buf, 0); setvar(numptr_m1->var, buf, 0);
/* after saving, make previous value for v++ or v-- */ /* after saving, make previous value for v++ or v-- */
if(op == TOK_POST_INC) if(op == TOK_POST_INC)
@ -13343,7 +13353,7 @@ static const char op_tokens[] = {
#define endexpression &op_tokens[sizeof(op_tokens)-7] #define endexpression &op_tokens[sizeof(op_tokens)-7]
extern long arith (const char *expr, int *perrcode) static arith_t arith (const char *expr, int *perrcode)
{ {
register char arithval; /* Current character under analysis */ register char arithval; /* Current character under analysis */
operator lasttok, op; operator lasttok, op;