aboutsummaryrefslogtreecommitdiff
path: root/shell/ash.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/ash.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/ash.c')
-rw-r--r--shell/ash.c85
1 files changed, 39 insertions, 46 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 4aaea2803..1cd205068 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -185,10 +185,6 @@ struct globals_misc {
185#define debug optlist[15] 185#define debug optlist[15]
186#endif 186#endif
187 187
188#if ENABLE_SH_MATH_SUPPORT
189 arith_eval_hooks_t math_hooks;
190#endif
191
192 /* trap handler commands */ 188 /* trap handler commands */
193 /* 189 /*
194 * Sigmode records the current value of the signal handlers for the various 190 * Sigmode records the current value of the signal handlers for the various
@@ -238,7 +234,6 @@ extern struct globals_misc *const ash_ptr_to_globals_misc;
238#define random_LCG (G_misc.random_LCG ) 234#define random_LCG (G_misc.random_LCG )
239#define backgndpid (G_misc.backgndpid ) 235#define backgndpid (G_misc.backgndpid )
240#define job_warning (G_misc.job_warning) 236#define job_warning (G_misc.job_warning)
241#define math_hooks (G_misc.math_hooks )
242#define INIT_G_misc() do { \ 237#define INIT_G_misc() do { \
243 (*(struct globals_misc**)&ash_ptr_to_globals_misc) = xzalloc(sizeof(G_misc)); \ 238 (*(struct globals_misc**)&ash_ptr_to_globals_misc) = xzalloc(sizeof(G_misc)); \
244 barrier(); \ 239 barrier(); \
@@ -1103,6 +1098,14 @@ ash_msg_and_raise_error(const char *msg, ...)
1103 va_end(ap); 1098 va_end(ap);
1104} 1099}
1105 1100
1101static void raise_error_syntax(const char *) NORETURN;
1102static void
1103raise_error_syntax(const char *msg)
1104{
1105 ash_msg_and_raise_error("syntax error: %s", msg);
1106 /* NOTREACHED */
1107}
1108
1106static void ash_msg_and_raise(int, const char *, ...) NORETURN; 1109static void ash_msg_and_raise(int, const char *, ...) NORETURN;
1107static void 1110static void
1108ash_msg_and_raise(int cond, const char *msg, ...) 1111ash_msg_and_raise(int cond, const char *msg, ...)
@@ -5241,7 +5244,32 @@ redirectsafe(union node *redir, int flags)
5241 */ 5244 */
5242 5245
5243#if ENABLE_SH_MATH_SUPPORT 5246#if ENABLE_SH_MATH_SUPPORT
5244static arith_t dash_arith(const char *); 5247static arith_t
5248ash_arith(const char *s)
5249{
5250 arith_eval_hooks_t math_hooks;
5251 arith_t result;
5252 int errcode = 0;
5253
5254 math_hooks.lookupvar = lookupvar;
5255 math_hooks.setvar = setvar;
5256 math_hooks.endofname = endofname;
5257
5258 INT_OFF;
5259 result = arith(s, &errcode, &math_hooks);
5260 if (errcode < 0) {
5261 if (errcode == -3)
5262 ash_msg_and_raise_error("exponent less than 0");
5263 if (errcode == -2)
5264 ash_msg_and_raise_error("divide by zero");
5265 if (errcode == -5)
5266 ash_msg_and_raise_error("expression recursion loop detected");
5267 raise_error_syntax(s);
5268 }
5269 INT_ON;
5270
5271 return result;
5272}
5245#endif 5273#endif
5246 5274
5247/* 5275/*
@@ -5720,7 +5748,7 @@ expari(int quotes)
5720 if (quotes) 5748 if (quotes)
5721 rmescapes(p + 2); 5749 rmescapes(p + 2);
5722 5750
5723 len = cvtnum(dash_arith(p + 2)); 5751 len = cvtnum(ash_arith(p + 2));
5724 5752
5725 if (flag != '"') 5753 if (flag != '"')
5726 recordregion(begoff, begoff + len, 0); 5754 recordregion(begoff, begoff + len, 0);
@@ -10127,14 +10155,6 @@ static struct heredoc *heredoc;
10127 */ 10155 */
10128#define NEOF ((union node *)&tokpushback) 10156#define NEOF ((union node *)&tokpushback)
10129 10157
10130static void raise_error_syntax(const char *) NORETURN;
10131static void
10132raise_error_syntax(const char *msg)
10133{
10134 ash_msg_and_raise_error("syntax error: %s", msg);
10135 /* NOTREACHED */
10136}
10137
10138/* 10158/*
10139 * Called when an unexpected token is read during the parse. The argument 10159 * Called when an unexpected token is read during the parse. The argument
10140 * is the token that is expected, or -1 if more than one type of token can 10160 * is the token that is expected, or -1 if more than one type of token can
@@ -12353,33 +12373,11 @@ timescmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
12353} 12373}
12354 12374
12355#if ENABLE_SH_MATH_SUPPORT 12375#if ENABLE_SH_MATH_SUPPORT
12356static arith_t
12357dash_arith(const char *s)
12358{
12359 arith_t result;
12360 int errcode = 0;
12361
12362 INT_OFF;
12363 result = arith(s, &errcode, &math_hooks);
12364 if (errcode < 0) {
12365 if (errcode == -3)
12366 ash_msg_and_raise_error("exponent less than 0");
12367 if (errcode == -2)
12368 ash_msg_and_raise_error("divide by zero");
12369 if (errcode == -5)
12370 ash_msg_and_raise_error("expression recursion loop detected");
12371 raise_error_syntax(s);
12372 }
12373 INT_ON;
12374
12375 return result;
12376}
12377
12378/* 12376/*
12379 * The let builtin. partial stolen from GNU Bash, the Bourne Again SHell. 12377 * The let builtin. partial stolen from GNU Bash, the Bourne Again SHell.
12380 * Copyright (C) 1987, 1989, 1991 Free Software Foundation, Inc. 12378 * Copyright (C) 1987, 1989, 1991 Free Software Foundation, Inc.
12381 * 12379 *
12382 * Copyright (C) 2003 Vladimir Oleynik <dzo@simtreas.ru> 12380 * Copyright (C) 2003 Vladimir Oleynik <dzo@simtreas.ru>
12383 */ 12381 */
12384static int 12382static int
12385letcmd(int argc UNUSED_PARAM, char **argv) 12383letcmd(int argc UNUSED_PARAM, char **argv)
@@ -12390,7 +12388,7 @@ letcmd(int argc UNUSED_PARAM, char **argv)
12390 if (!*argv) 12388 if (!*argv)
12391 ash_msg_and_raise_error("expression expected"); 12389 ash_msg_and_raise_error("expression expected");
12392 do { 12390 do {
12393 i = dash_arith(*argv); 12391 i = ash_arith(*argv);
12394 } while (*++argv); 12392 } while (*++argv);
12395 12393
12396 return !i; 12394 return !i;
@@ -13119,11 +13117,6 @@ int ash_main(int argc UNUSED_PARAM, char **argv)
13119 INIT_G_alias(); 13117 INIT_G_alias();
13120#endif 13118#endif
13121 INIT_G_cmdtable(); 13119 INIT_G_cmdtable();
13122#if ENABLE_SH_MATH_SUPPORT
13123 math_hooks.lookupvar = lookupvar;
13124 math_hooks.setvar = setvar;
13125 math_hooks.endofname = endofname;
13126#endif
13127 13120
13128#if PROFILE 13121#if PROFILE
13129 monitor(4, etext, profile_buf, sizeof(profile_buf), 50); 13122 monitor(4, etext, profile_buf, sizeof(profile_buf), 50);