summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko2023-06-17 10:40:29 +0200
committerDenys Vlasenko2023-06-17 10:40:29 +0200
commit6221832bc15d9037360e3bdc9405df08ed801cc1 (patch)
tree1bed0a30a665f8c57f588888720b908d76dcaf14
parentd6f98f214b3bd242f7404b68a4f9d777114fffa3 (diff)
downloadbusybox-6221832bc15d9037360e3bdc9405df08ed801cc1.zip
busybox-6221832bc15d9037360e3bdc9405df08ed801cc1.tar.gz
shell/math.h: update comments, rearrange struct members for smaller code
function old new delta arith_apply 1000 998 -2 evaluate_string 1414 1406 -8 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-10) Total: -10 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/math.c2
-rw-r--r--shell/math.h26
2 files changed, 5 insertions, 23 deletions
diff --git a/shell/math.c b/shell/math.c
index 56f866b..6196a6a 100644
--- a/shell/math.c
+++ b/shell/math.c
@@ -926,9 +926,9 @@ dbg(" numstack:%d val:%lld '%s'", (int)(numstackptr - numstack), numstackptr[
arith_t FAST_FUNC
arith(arith_state_t *math_state, const char *expr)
{
+ math_state->evaluation_disabled = 0;
math_state->errmsg = NULL;
math_state->list_of_recursed_names = NULL;
- math_state->evaluation_disabled = 0;
return evaluate_string(math_state, expr);
}
diff --git a/shell/math.h b/shell/math.h
index 452ddad..9812184 100644
--- a/shell/math.h
+++ b/shell/math.h
@@ -6,7 +6,6 @@
*
* See math.c for internal documentation.
*/
-
/* The math library has just one function:
*
* arith_t arith(arith_state_t *state, const char *expr);
@@ -22,7 +21,6 @@
* "1 + 2 + 3"
* you would obviously get back 6.
*/
-
/* To add support to a shell, you need to implement three functions:
*
* lookupvar() - look up and return the value of a variable
@@ -36,28 +34,12 @@
* setvar() - set a variable to some value
*
* If the arithmetic expansion does something like:
- * $(( i = 1))
+ * $((i = 1))
* then the math code will make a call like so:
- * setvar("i", "1", 0);
+ * setvar("i", "1");
* The storage for the first two parameters are not allocated, so your
* shell implementation will most likely need to strdup() them to save.
- *
- * endofname() - return the end of a variable name from input
- *
- * The arithmetic code does not know about variable naming conventions.
- * So when it is given an experession, it knows something is not numeric,
- * but it is up to the shell to dictate what is a valid identifiers.
- * So when it encounters something like:
- * $(( some_var + 123 ))
- * It will make a call like so:
- * end = endofname("some_var + 123");
- * So the shell needs to scan the input string and return a pointer to the
- * first non-identifier string. In this case, it should return the input
- * pointer with an offset pointing to the first space. The typical
- * implementation will return the offset of first char that does not match
- * the regex (in C locale): ^[a-zA-Z_][a-zA-Z_0-9]*
*/
-
#ifndef SHELL_MATH_H
#define SHELL_MATH_H 1
@@ -75,11 +57,11 @@ typedef const char* FAST_FUNC (*arith_var_lookup_t)(const char *name);
typedef void FAST_FUNC (*arith_var_set_t)(const char *name, const char *val);
typedef struct arith_state_t {
+ uint64_t evaluation_disabled;
const char *errmsg;
+ void *list_of_recursed_names;
arith_var_lookup_t lookupvar;
arith_var_set_t setvar;
- uint64_t evaluation_disabled;
- void *list_of_recursed_names;
} arith_state_t;
arith_t FAST_FUNC arith(arith_state_t *state, const char *expr);