aboutsummaryrefslogtreecommitdiff
path: root/shell/math.h
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2010-09-16 11:50:46 +0200
committerDenys Vlasenko <dvlasenk@redhat.com>2010-09-16 11:50:46 +0200
commitbed7c81ea24e9e9ba2a897e233de2abefe611e8b (patch)
treeb18a4559e60300fecd7275c0088f8942441072a2 /shell/math.h
parent063847d6bd23e184c409f37645ba90fa4d039ada (diff)
downloadbusybox-w32-bed7c81ea24e9e9ba2a897e233de2abefe611e8b.tar.gz
busybox-w32-bed7c81ea24e9e9ba2a897e233de2abefe611e8b.tar.bz2
busybox-w32-bed7c81ea24e9e9ba2a897e233de2abefe611e8b.zip
shell/math: deconvolute and explain ?: handling. Give better error message
function old new delta arith_apply 1271 1283 +12 Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'shell/math.h')
-rw-r--r--shell/math.h20
1 files changed, 4 insertions, 16 deletions
diff --git a/shell/math.h b/shell/math.h
index 2dcab130d..2d305eb12 100644
--- a/shell/math.h
+++ b/shell/math.h
@@ -9,19 +9,13 @@
9 9
10/* The math library has just one function: 10/* The math library has just one function:
11 * 11 *
12 * arith_t arith(arith_state_t *states, const char *expr); 12 * arith_t arith(arith_state_t *state, const char *expr);
13 * 13 *
14 * The expr argument is the math string to parse. All normal expansions must 14 * The expr argument is the math string to parse. All normal expansions must
15 * be done already. i.e. no dollar symbols should be present. 15 * be done already. i.e. no dollar symbols should be present.
16 * 16 *
17 * The state argument is a pointer to a struct of hooks for your shell (see below), 17 * The state argument is a pointer to a struct of hooks for your shell (see below),
18 * and a semi-detailed error code. Currently, those values are (for 18 * and an error message string (NULL if no error).
19 * compatibility, you should assume all negative values are errors):
20 * 0 - no errors (yay!)
21 * -1 - unspecified problem
22 * -2 - divide by zero
23 * -3 - exponent less than 0
24 * -5 - expression recursion loop detected
25 * 19 *
26 * The function returns the answer to the expression. So if you called it 20 * The function returns the answer to the expression. So if you called it
27 * with the expression: 21 * with the expression:
@@ -64,12 +58,6 @@
64 * the regex (in C locale): ^[a-zA-Z_][a-zA-Z_0-9]* 58 * the regex (in C locale): ^[a-zA-Z_][a-zA-Z_0-9]*
65 */ 59 */
66 60
67/* To make your life easier when dealing with optional 64bit math support,
68 * rather than assume that the type is "signed long" and you can always
69 * use "%ld" to scan/print the value, use the arith_t helper defines. See
70 * below for the exact things that are available.
71 */
72
73#ifndef SHELL_MATH_H 61#ifndef SHELL_MATH_H
74#define SHELL_MATH_H 1 62#define SHELL_MATH_H 1
75 63
@@ -77,11 +65,11 @@ PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
77 65
78#if ENABLE_SH_MATH_SUPPORT_64 66#if ENABLE_SH_MATH_SUPPORT_64
79typedef long long arith_t; 67typedef long long arith_t;
80#define arith_t_fmt "%lld" 68#define ARITH_FMT "%lld"
81#define strto_arith_t strtoull 69#define strto_arith_t strtoull
82#else 70#else
83typedef long arith_t; 71typedef long arith_t;
84#define arith_t_fmt "%ld" 72#define ARITH_FMT "%ld"
85#define strto_arith_t strtoul 73#define strto_arith_t strtoul
86#endif 74#endif
87 75