summaryrefslogtreecommitdiff
path: root/shell/hush.c
diff options
context:
space:
mode:
authorDenis Vlasenko2009-04-02 13:46:27 +0000
committerDenis Vlasenko2009-04-02 13:46:27 +0000
commitb29eb6ed255ad87f49b70220d254810063c7ebf3 (patch)
tree8b4ece864a7f9e1161abe59bf887c4fd81d473bb /shell/hush.c
parent0dfe1d26a9000da4925f64c07a96b3e09ba175b1 (diff)
downloadbusybox-b29eb6ed255ad87f49b70220d254810063c7ebf3.zip
busybox-b29eb6ed255ad87f49b70220d254810063c7ebf3.tar.gz
shells: do not need to have math state global
function old new delta ash_arith - 143 +143 expand_variables 2102 2124 +22 popstring 134 140 +6 parse_command 1460 1463 +3 trapcmd 236 238 +2 changepath 197 196 -1 raise_interrupt 86 83 -3 hush_main 1012 991 -21 ash_main 1388 1364 -24 arith_set_local_var 73 34 -39 dash_arith 117 - -117 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 4/5 up/down: 176/-205) Total: -29 bytes
Diffstat (limited to 'shell/hush.c')
-rw-r--r--shell/hush.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/shell/hush.c b/shell/hush.c
index e93e5a9..3725191 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -454,9 +454,6 @@ struct globals {
#if ENABLE_FEATURE_EDITING
line_input_t *line_input_state;
#endif
-#if ENABLE_SH_MATH_SUPPORT
- arith_eval_hooks_t hooks;
-#endif
pid_t root_pid;
pid_t last_bg_pid;
#if ENABLE_HUSH_JOB
@@ -1189,12 +1186,12 @@ static char *endofname(const char *name)
static void arith_set_local_var(const char *name, const char *val, int flags)
{
/* arith code doesnt malloc space, so do it for it */
- char *var = xmalloc(strlen(name) + 1 + strlen(val) + 1);
- sprintf(var, "%s=%s", name, val);
+ char *var = xasprintf("%s=%s", name, val);
set_local_var(var, flags);
}
#endif
+
/*
* in_str support
*/
@@ -1807,20 +1804,26 @@ static int expand_vars_to_list(o_string *output, int n, char *arg, char or_mask)
#endif
#if ENABLE_SH_MATH_SUPPORT
case '+': { /* <SPECIAL_VAR_SYMBOL>(cmd<SPECIAL_VAR_SYMBOL> */
+ arith_eval_hooks_t hooks;
arith_t res;
char buf[30];
int errcode;
+
*p = '\0';
++arg;
debug_printf_subst("ARITH '%s' first_ch %x\n", arg, first_ch);
- res = arith(arg, &errcode, &G.hooks);
- if (errcode < 0)
+ hooks.lookupvar = lookup_param;
+ hooks.setvar = arith_set_local_var;
+ hooks.endofname = endofname;
+ res = arith(arg, &errcode, &hooks);
+ if (errcode < 0) {
switch (errcode) {
case -3: maybe_die("arith", "exponent less than 0"); break;
case -2: maybe_die("arith", "divide by zero"); break;
case -5: maybe_die("arith", "expression recursion loop detected"); break;
- default: maybe_die("arith", "syntax error");
+ default: maybe_die("arith", "syntax error"); break;
}
+ }
sprintf(buf, arith_t_fmt, res);
o_addstrauto(output, buf);
debug_printf_subst("ARITH RES '"arith_t_fmt"'\n", res);
@@ -4601,11 +4604,6 @@ int hush_main(int argc, char **argv)
#if ENABLE_FEATURE_EDITING
G.line_input_state = new_line_input_t(FOR_SHELL);
#endif
-#if ENABLE_SH_MATH_SUPPORT
- G.hooks.lookupvar = lookup_param;
- G.hooks.setvar = arith_set_local_var;
- G.hooks.endofname = endofname;
-#endif
/* XXX what should these be while sourcing /etc/profile? */
G.global_argc = argc;
G.global_argv = argv;