math support in busybox shells

Denys Vlasenko vda.linux at googlemail.com
Thu Apr 2 03:36:25 UTC 2009


On Wednesday 01 April 2009 17:10, Mike Frysinger wrote:
> the ash code, while frightening, doesnt pollute its math code.  whoever did 
> the merge kept it nice and clean :).
> 
> so this patch moves the arith() func (and few related stuff) out of ash.c and 
> into math.c.  that's the bulk of it, so you can ignore the large chunk against 
> ash.c/math.c.
> 
> other things:
>  - rename ASH_MATH to SH_MATH in Config.in and such
>  - add arith_set_hooks() func to top of math.c
>  - simplify the 64bit #if mess in math.h
>  - constify the lookupvar() func in ash
>  - add a set wrapper to hush since the math code (1) doesnt alloc the variable 
> storage and (2) uses two strings rather than one with "var=val"
>  - implement $((...)) detection/parsing in hush
> -mike

+static arith_var_lookup_t lookupvar;
+static arith_var_set_t setvar;
+static arith_var_endofname_t endofname;

Apart from these statics, it looks ok.

Can you create

struct arith_eval_state {
	arith_var_lookup_t lookupvar;
	arith_var_set_t setvar;
	arith_var_endofname_t endofname;
};

and pass a pointer to it into arith() calls?

Line editing does something like that.
--
vda


More information about the busybox mailing list