aboutsummaryrefslogtreecommitdiff
path: root/shell/math.h
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2023-07-13 08:06:26 +0100
committerRon Yorston <rmy@pobox.com>2023-07-13 08:06:26 +0100
commitbd978d0256fd3a67de1a7dd54f1a37f9435be363 (patch)
treecb869384a533ac0d95fe787d75be6c050e1e7c1a /shell/math.h
parentb2901ce8efa050da00e0f3a73f3be9bf9402deea (diff)
parentd70256a5c719439cc6fab6a4571c1bb46178e4c7 (diff)
downloadbusybox-w32-bd978d0256fd3a67de1a7dd54f1a37f9435be363.tar.gz
busybox-w32-bd978d0256fd3a67de1a7dd54f1a37f9435be363.tar.bz2
busybox-w32-bd978d0256fd3a67de1a7dd54f1a37f9435be363.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'shell/math.h')
-rw-r--r--shell/math.h27
1 files changed, 4 insertions, 23 deletions
diff --git a/shell/math.h b/shell/math.h
index a3fe51b6b..aeb3b93c3 100644
--- a/shell/math.h
+++ b/shell/math.h
@@ -6,7 +6,6 @@
6 * 6 *
7 * See math.c for internal documentation. 7 * See math.c for internal documentation.
8 */ 8 */
9
10/* The math library has just one function: 9/* The math library has just one function:
11 * 10 *
12 * arith_t arith(arith_state_t *state, const char *expr); 11 * arith_t arith(arith_state_t *state, const char *expr);
@@ -22,7 +21,6 @@
22 * "1 + 2 + 3" 21 * "1 + 2 + 3"
23 * you would obviously get back 6. 22 * you would obviously get back 6.
24 */ 23 */
25
26/* To add support to a shell, you need to implement three functions: 24/* To add support to a shell, you need to implement three functions:
27 * 25 *
28 * lookupvar() - look up and return the value of a variable 26 * lookupvar() - look up and return the value of a variable
@@ -36,28 +34,12 @@
36 * setvar() - set a variable to some value 34 * setvar() - set a variable to some value
37 * 35 *
38 * If the arithmetic expansion does something like: 36 * If the arithmetic expansion does something like:
39 * $(( i = 1)) 37 * $((i = 1))
40 * then the math code will make a call like so: 38 * then the math code will make a call like so:
41 * setvar("i", "1", 0); 39 * setvar("i", "1");
42 * The storage for the first two parameters are not allocated, so your 40 * The storage for the first two parameters are not allocated, so your
43 * shell implementation will most likely need to strdup() them to save. 41 * shell implementation will most likely need to strdup() them to save.
44 *
45 * endofname() - return the end of a variable name from input
46 *
47 * The arithmetic code does not know about variable naming conventions.
48 * So when it is given an experession, it knows something is not numeric,
49 * but it is up to the shell to dictate what is a valid identifiers.
50 * So when it encounters something like:
51 * $(( some_var + 123 ))
52 * It will make a call like so:
53 * end = endofname("some_var + 123");
54 * So the shell needs to scan the input string and return a pointer to the
55 * first non-identifier string. In this case, it should return the input
56 * pointer with an offset pointing to the first space. The typical
57 * implementation will return the offset of first char that does not match
58 * the regex (in C locale): ^[a-zA-Z_][a-zA-Z_0-9]*
59 */ 42 */
60
61#ifndef SHELL_MATH_H 43#ifndef SHELL_MATH_H
62#define SHELL_MATH_H 1 44#define SHELL_MATH_H 1
63 45
@@ -73,14 +55,13 @@ typedef long arith_t;
73 55
74typedef const char* FAST_FUNC (*arith_var_lookup_t)(const char *name); 56typedef const char* FAST_FUNC (*arith_var_lookup_t)(const char *name);
75typedef void FAST_FUNC (*arith_var_set_t)(const char *name, const char *val); 57typedef void FAST_FUNC (*arith_var_set_t)(const char *name, const char *val);
76//typedef const char* FAST_FUNC (*arith_var_endofname_t)(const char *name);
77 58
78typedef struct arith_state_t { 59typedef struct arith_state_t {
60 unsigned evaluation_disabled;
79 const char *errmsg; 61 const char *errmsg;
62 void *list_of_recursed_names;
80 arith_var_lookup_t lookupvar; 63 arith_var_lookup_t lookupvar;
81 arith_var_set_t setvar; 64 arith_var_set_t setvar;
82// arith_var_endofname_t endofname;
83 void *list_of_recursed_names;
84} arith_state_t; 65} arith_state_t;
85 66
86arith_t FAST_FUNC arith(arith_state_t *state, const char *expr); 67arith_t FAST_FUNC arith(arith_state_t *state, const char *expr);