aboutsummaryrefslogtreecommitdiff
path: root/shell/hush.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2009-04-02 13:46:27 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2009-04-02 13:46:27 +0000
commitb29eb6ed255ad87f49b70220d254810063c7ebf3 (patch)
tree8b4ece864a7f9e1161abe59bf887c4fd81d473bb /shell/hush.c
parent0dfe1d26a9000da4925f64c07a96b3e09ba175b1 (diff)
downloadbusybox-w32-b29eb6ed255ad87f49b70220d254810063c7ebf3.tar.gz
busybox-w32-b29eb6ed255ad87f49b70220d254810063c7ebf3.tar.bz2
busybox-w32-b29eb6ed255ad87f49b70220d254810063c7ebf3.zip
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 e93e5a9a0..3725191d8 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -454,9 +454,6 @@ struct globals {
454#if ENABLE_FEATURE_EDITING 454#if ENABLE_FEATURE_EDITING
455 line_input_t *line_input_state; 455 line_input_t *line_input_state;
456#endif 456#endif
457#if ENABLE_SH_MATH_SUPPORT
458 arith_eval_hooks_t hooks;
459#endif
460 pid_t root_pid; 457 pid_t root_pid;
461 pid_t last_bg_pid; 458 pid_t last_bg_pid;
462#if ENABLE_HUSH_JOB 459#if ENABLE_HUSH_JOB
@@ -1189,12 +1186,12 @@ static char *endofname(const char *name)
1189static void arith_set_local_var(const char *name, const char *val, int flags) 1186static void arith_set_local_var(const char *name, const char *val, int flags)
1190{ 1187{
1191 /* arith code doesnt malloc space, so do it for it */ 1188 /* arith code doesnt malloc space, so do it for it */
1192 char *var = xmalloc(strlen(name) + 1 + strlen(val) + 1); 1189 char *var = xasprintf("%s=%s", name, val);
1193 sprintf(var, "%s=%s", name, val);
1194 set_local_var(var, flags); 1190 set_local_var(var, flags);
1195} 1191}
1196#endif 1192#endif
1197 1193
1194
1198/* 1195/*
1199 * in_str support 1196 * in_str support
1200 */ 1197 */
@@ -1807,20 +1804,26 @@ static int expand_vars_to_list(o_string *output, int n, char *arg, char or_mask)
1807#endif 1804#endif
1808#if ENABLE_SH_MATH_SUPPORT 1805#if ENABLE_SH_MATH_SUPPORT
1809 case '+': { /* <SPECIAL_VAR_SYMBOL>(cmd<SPECIAL_VAR_SYMBOL> */ 1806 case '+': { /* <SPECIAL_VAR_SYMBOL>(cmd<SPECIAL_VAR_SYMBOL> */
1807 arith_eval_hooks_t hooks;
1810 arith_t res; 1808 arith_t res;
1811 char buf[30]; 1809 char buf[30];
1812 int errcode; 1810 int errcode;
1811
1813 *p = '\0'; 1812 *p = '\0';
1814 ++arg; 1813 ++arg;
1815 debug_printf_subst("ARITH '%s' first_ch %x\n", arg, first_ch); 1814 debug_printf_subst("ARITH '%s' first_ch %x\n", arg, first_ch);
1816 res = arith(arg, &errcode, &G.hooks); 1815 hooks.lookupvar = lookup_param;
1817 if (errcode < 0) 1816 hooks.setvar = arith_set_local_var;
1817 hooks.endofname = endofname;
1818 res = arith(arg, &errcode, &hooks);
1819 if (errcode < 0) {
1818 switch (errcode) { 1820 switch (errcode) {
1819 case -3: maybe_die("arith", "exponent less than 0"); break; 1821 case -3: maybe_die("arith", "exponent less than 0"); break;
1820 case -2: maybe_die("arith", "divide by zero"); break; 1822 case -2: maybe_die("arith", "divide by zero"); break;
1821 case -5: maybe_die("arith", "expression recursion loop detected"); break; 1823 case -5: maybe_die("arith", "expression recursion loop detected"); break;
1822 default: maybe_die("arith", "syntax error"); 1824 default: maybe_die("arith", "syntax error"); break;
1823 } 1825 }
1826 }
1824 sprintf(buf, arith_t_fmt, res); 1827 sprintf(buf, arith_t_fmt, res);
1825 o_addstrauto(output, buf); 1828 o_addstrauto(output, buf);
1826 debug_printf_subst("ARITH RES '"arith_t_fmt"'\n", res); 1829 debug_printf_subst("ARITH RES '"arith_t_fmt"'\n", res);
@@ -4601,11 +4604,6 @@ int hush_main(int argc, char **argv)
4601#if ENABLE_FEATURE_EDITING 4604#if ENABLE_FEATURE_EDITING
4602 G.line_input_state = new_line_input_t(FOR_SHELL); 4605 G.line_input_state = new_line_input_t(FOR_SHELL);
4603#endif 4606#endif
4604#if ENABLE_SH_MATH_SUPPORT
4605 G.hooks.lookupvar = lookup_param;
4606 G.hooks.setvar = arith_set_local_var;
4607 G.hooks.endofname = endofname;
4608#endif
4609 /* XXX what should these be while sourcing /etc/profile? */ 4607 /* XXX what should these be while sourcing /etc/profile? */
4610 G.global_argc = argc; 4608 G.global_argc = argc;
4611 G.global_argv = argv; 4609 G.global_argv = argv;