aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-02-23 21:10:23 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-02-23 21:10:23 +0000
commit2de3d9fbeef02d19305a4a18c758a4e5f65260d4 (patch)
treed67f98a23d9da88e9fdf38fcecf05f254cee98f9
parenta89150733a39d25a916c28e76f530845a56342bb (diff)
downloadbusybox-w32-2de3d9fbeef02d19305a4a18c758a4e5f65260d4.tar.gz
busybox-w32-2de3d9fbeef02d19305a4a18c758a4e5f65260d4.tar.bz2
busybox-w32-2de3d9fbeef02d19305a4a18c758a4e5f65260d4.zip
ash: cleanup part 2.5
-rw-r--r--shell/ash.c317
1 files changed, 159 insertions, 158 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 869ed12fd..c96517c3a 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -66,6 +66,15 @@
66#endif 66#endif
67 67
68 68
69/* ============ Misc helpers */
70
71#define xbarrier() do { __asm__ __volatile__ ("": : :"memory"); } while (0)
72
73/* C99 say: "char" declaration may be signed or unsigned default */
74#define signed_char2int(sc) ((int)((signed char)sc))
75
76
77
69/* ============ Shell options */ 78/* ============ Shell options */
70 79
71static const char *const optletters_optnames[] = { 80static const char *const optletters_optnames[] = {
@@ -192,13 +201,11 @@ static volatile sig_atomic_t pendingsigs;
192 * much more efficient and portable. (But hacking the kernel is so much 201 * much more efficient and portable. (But hacking the kernel is so much
193 * more fun than worrying about efficiency and portability. :-)) 202 * more fun than worrying about efficiency and portability. :-))
194 */ 203 */
195#define xbarrier() ({ __asm__ __volatile__ ("": : :"memory"); })
196#define INT_OFF \ 204#define INT_OFF \
197 ({ \ 205 do { \
198 suppressint++; \ 206 suppressint++; \
199 xbarrier(); \ 207 xbarrier(); \
200 0; \ 208 } while (0)
201 })
202 209
203/* 210/*
204 * Called to raise an exception. Since C doesn't include exceptions, we 211 * Called to raise an exception. Since C doesn't include exceptions, we
@@ -263,38 +270,37 @@ force_int_on(void)
263#define FORCE_INT_ON force_int_on() 270#define FORCE_INT_ON force_int_on()
264#else 271#else
265#define INT_ON \ 272#define INT_ON \
266 ({ \ 273 do { \
267 xbarrier(); \ 274 xbarrier(); \
268 if (--suppressint == 0 && intpending) raise_interrupt(); \ 275 if (--suppressint == 0 && intpending) \
269 0; \ 276 raise_interrupt(); \
270 }) 277 } while (0)
271#define FORCE_INT_ON \ 278#define FORCE_INT_ON \
272 ({ \ 279 do { \
273 xbarrier(); \ 280 xbarrier(); \
274 suppressint = 0; \ 281 suppressint = 0; \
275 if (intpending) raise_interrupt(); \ 282 if (intpending) \
276 0; \ 283 raise_interrupt(); \
277 }) 284 } while (0)
278#endif /* ASH_OPTIMIZE_FOR_SIZE */ 285#endif /* ASH_OPTIMIZE_FOR_SIZE */
279 286
280#define SAVE_INT(v) ((v) = suppressint) 287#define SAVE_INT(v) ((v) = suppressint)
281 288
282#define RESTORE_INT(v) \ 289#define RESTORE_INT(v) \
283 ({ \ 290 do { \
284 xbarrier(); \ 291 xbarrier(); \
285 suppressint = (v); \ 292 suppressint = (v); \
286 if (suppressint == 0 && intpending) raise_interrupt(); \ 293 if (suppressint == 0 && intpending) \
287 0; \ 294 raise_interrupt(); \
288 }) 295 } while (0)
289 296
290#define EXSIGON \ 297#define EXSIGON \
291 ({ \ 298 do { \
292 exsig++; \ 299 exsig++; \
293 xbarrier(); \ 300 xbarrier(); \
294 if (pendingsigs) \ 301 if (pendingsigs) \
295 raise_exception(EXSIG); \ 302 raise_exception(EXSIG); \
296 0; \ 303 } while (0)
297 })
298/* EXSIG is turned off by evalbltin(). */ 304/* EXSIG is turned off by evalbltin(). */
299 305
300/* 306/*
@@ -406,7 +412,7 @@ out2str(const char *p)
406} 412}
407 413
408 414
409/* ============ Parsing structures */ 415/* ============ Parser structures */
410 416
411/* control characters in argument strings */ 417/* control characters in argument strings */
412#define CTLESC '\201' /* escape next character */ 418#define CTLESC '\201' /* escape next character */
@@ -436,6 +442,8 @@ out2str(const char *p)
436#define VSTRIMLEFTMAX 0x9 /* ${var##pattern} */ 442#define VSTRIMLEFTMAX 0x9 /* ${var##pattern} */
437#define VSLENGTH 0xa /* ${#var} */ 443#define VSLENGTH 0xa /* ${#var} */
438 444
445static const char dolatstr[] = { CTLVAR, VSNORMAL|VSQUOTE, '@', '=', '\0' };
446
439#define NCMD 0 447#define NCMD 0
440#define NPIPE 1 448#define NPIPE 1
441#define NREDIR 2 449#define NREDIR 2
@@ -1361,21 +1369,25 @@ _STPUTC(int c, char *p)
1361 return p; 1369 return p;
1362} 1370}
1363 1371
1364#define STARTSTACKSTR(p) ((p) = stackblock()) 1372#define STARTSTACKSTR(p) ((p) = stackblock())
1365#define STPUTC(c, p) ((p) = _STPUTC((c), (p))) 1373#define STPUTC(c, p) ((p) = _STPUTC((c), (p)))
1366#define CHECKSTRSPACE(n, p) \ 1374#define CHECKSTRSPACE(n, p) \
1367 ({ \ 1375 do { \
1368 char *q = (p); \ 1376 char *q = (p); \
1369 size_t l = (n); \ 1377 size_t l = (n); \
1370 size_t m = sstrend - q; \ 1378 size_t m = sstrend - q; \
1371 if (l > m) \ 1379 if (l > m) \
1372 (p) = makestrspace(l, q); \ 1380 (p) = makestrspace(l, q); \
1373 0; \ 1381 } while (0)
1374 })
1375#define USTPUTC(c, p) (*p++ = (c)) 1382#define USTPUTC(c, p) (*p++ = (c))
1376#define STACKSTRNUL(p) ((p) == sstrend ? (p = growstackstr(), *p = '\0') : (*p = '\0')) 1383#define STACKSTRNUL(p) \
1384 do { \
1385 if ((p) == sstrend) \
1386 p = growstackstr(); \
1387 *p = '\0'; \
1388 } while (0)
1377#define STUNPUTC(p) (--p) 1389#define STUNPUTC(p) (--p)
1378#define STTOPC(p) p[-1] 1390#define STTOPC(p) (p[-1])
1379#define STADJUST(amount, p) (p += (amount)) 1391#define STADJUST(amount, p) (p += (amount))
1380 1392
1381#define grabstackstr(p) stalloc((char *)(p) - (char *)stackblock()) 1393#define grabstackstr(p) stalloc((char *)(p) - (char *)stackblock())
@@ -1519,6 +1531,29 @@ nextopt(const char *optstring)
1519} 1531}
1520 1532
1521 1533
1534/* ============ Math support definitions */
1535
1536#if ENABLE_ASH_MATH_SUPPORT_64
1537typedef int64_t arith_t;
1538#define arith_t_type long long
1539#else
1540typedef long arith_t;
1541#define arith_t_type long
1542#endif
1543
1544#if ENABLE_ASH_MATH_SUPPORT
1545static arith_t dash_arith(const char *);
1546static arith_t arith(const char *expr, int *perrcode);
1547#endif
1548
1549#if ENABLE_ASH_RANDOM_SUPPORT
1550static unsigned long rseed;
1551#ifndef DYNAMIC_VAR
1552#define DYNAMIC_VAR
1553#endif
1554#endif
1555
1556
1522/* ============ Shell variables */ 1557/* ============ Shell variables */
1523 1558
1524/* flags */ 1559/* flags */
@@ -1532,9 +1567,9 @@ nextopt(const char *optstring)
1532#define VNOSET 0x80 /* do not set variable - just readonly test */ 1567#define VNOSET 0x80 /* do not set variable - just readonly test */
1533#define VNOSAVE 0x100 /* when text is on the heap before setvareq */ 1568#define VNOSAVE 0x100 /* when text is on the heap before setvareq */
1534#ifdef DYNAMIC_VAR 1569#ifdef DYNAMIC_VAR
1535# define VDYNAMIC 0x200 /* dynamic variable */ 1570# define VDYNAMIC 0x200 /* dynamic variable */
1536# else 1571#else
1537# define VDYNAMIC 0 1572# define VDYNAMIC 0
1538#endif 1573#endif
1539 1574
1540static const char defpathvar[] = "PATH=/usr/local/bin:/usr/bin:/sbin:/bin"; 1575static const char defpathvar[] = "PATH=/usr/local/bin:/usr/bin:/sbin:/bin";
@@ -2401,12 +2436,6 @@ pwdcmd(int argc, char **argv)
2401#define IBUFSIZ (BUFSIZ + 1) 2436#define IBUFSIZ (BUFSIZ + 1)
2402#define basebuf bb_common_bufsiz1 /* buffer for top level input file */ 2437#define basebuf bb_common_bufsiz1 /* buffer for top level input file */
2403 2438
2404
2405/* shell.h */
2406
2407static const char spcstr[] = " ";
2408static const char dolatstr[] = { CTLVAR, VSNORMAL|VSQUOTE, '@', '=', '\0' };
2409
2410/* Syntax classes */ 2439/* Syntax classes */
2411#define CWORD 0 /* character is nothing special */ 2440#define CWORD 0 /* character is nothing special */
2412#define CNL 1 /* newline character */ 2441#define CNL 1 /* newline character */
@@ -2435,77 +2464,72 @@ static const char dolatstr[] = { CTLVAR, VSNORMAL|VSQUOTE, '@', '=', '\0' };
2435#define PEOA_OR_PEOF PEOF 2464#define PEOA_OR_PEOF PEOF
2436#endif 2465#endif
2437 2466
2438/* C99 say: "char" declaration may be signed or unsigned default */
2439#define SC2INT(chr2may_be_negative_int) (int)((signed char)chr2may_be_negative_int)
2440
2441/* 2467/*
2442 * is_special(c) evaluates to 1 for c in "!#$*-0123456789?@"; 0 otherwise 2468 * is_special(c) evaluates to 1 for c in "!#$*-0123456789?@"; 0 otherwise
2443 * (assuming ascii char codes, as the original implementation did) 2469 * (assuming ascii char codes, as the original implementation did)
2444 */ 2470 */
2445#define is_special(c) \ 2471#define is_special(c) \
2446 ( (((unsigned int)c) - 33 < 32) \ 2472 ((((unsigned int)c) - 33 < 32) \
2447 && ((0xc1ff920dUL >> (((unsigned int)c) - 33)) & 1)) 2473 && ((0xc1ff920dUL >> (((unsigned int)c) - 33)) & 1))
2474
2475/* number syntax index */
2476#define BASESYNTAX 0 /* not in quotes */
2477#define DQSYNTAX 1 /* in double quotes */
2478#define SQSYNTAX 2 /* in single quotes */
2479#define ARISYNTAX 3 /* in arithmetic */
2448 2480
2449#if ENABLE_ASH_OPTIMIZE_FOR_SIZE 2481#if ENABLE_ASH_OPTIMIZE_FOR_SIZE
2450#define USE_SIT_FUNCTION 2482#define USE_SIT_FUNCTION
2451#endif 2483#endif
2452 2484
2453/* number syntax index */
2454#define BASESYNTAX 0 /* not in quotes */
2455#define DQSYNTAX 1 /* in double quotes */
2456#define SQSYNTAX 2 /* in single quotes */
2457#define ARISYNTAX 3 /* in arithmetic */
2458
2459#if ENABLE_ASH_MATH_SUPPORT 2485#if ENABLE_ASH_MATH_SUPPORT
2460static const char S_I_T[][4] = { 2486static const char S_I_T[][4] = {
2461#if ENABLE_ASH_ALIAS 2487#if ENABLE_ASH_ALIAS
2462 {CSPCL, CIGN, CIGN, CIGN}, /* 0, PEOA */ 2488 { CSPCL, CIGN, CIGN, CIGN }, /* 0, PEOA */
2463#endif 2489#endif
2464 {CSPCL, CWORD, CWORD, CWORD}, /* 1, ' ' */ 2490 { CSPCL, CWORD, CWORD, CWORD }, /* 1, ' ' */
2465 {CNL, CNL, CNL, CNL}, /* 2, \n */ 2491 { CNL, CNL, CNL, CNL }, /* 2, \n */
2466 {CWORD, CCTL, CCTL, CWORD}, /* 3, !*-/:=?[]~ */ 2492 { CWORD, CCTL, CCTL, CWORD }, /* 3, !*-/:=?[]~ */
2467 {CDQUOTE, CENDQUOTE, CWORD, CWORD}, /* 4, '"' */ 2493 { CDQUOTE, CENDQUOTE, CWORD, CWORD }, /* 4, '"' */
2468 {CVAR, CVAR, CWORD, CVAR}, /* 5, $ */ 2494 { CVAR, CVAR, CWORD, CVAR }, /* 5, $ */
2469 {CSQUOTE, CWORD, CENDQUOTE, CWORD}, /* 6, "'" */ 2495 { CSQUOTE, CWORD, CENDQUOTE, CWORD }, /* 6, "'" */
2470 {CSPCL, CWORD, CWORD, CLP}, /* 7, ( */ 2496 { CSPCL, CWORD, CWORD, CLP }, /* 7, ( */
2471 {CSPCL, CWORD, CWORD, CRP}, /* 8, ) */ 2497 { CSPCL, CWORD, CWORD, CRP }, /* 8, ) */
2472 {CBACK, CBACK, CCTL, CBACK}, /* 9, \ */ 2498 { CBACK, CBACK, CCTL, CBACK }, /* 9, \ */
2473 {CBQUOTE, CBQUOTE, CWORD, CBQUOTE}, /* 10, ` */ 2499 { CBQUOTE, CBQUOTE, CWORD, CBQUOTE }, /* 10, ` */
2474 {CENDVAR, CENDVAR, CWORD, CENDVAR}, /* 11, } */ 2500 { CENDVAR, CENDVAR, CWORD, CENDVAR }, /* 11, } */
2475#ifndef USE_SIT_FUNCTION 2501#ifndef USE_SIT_FUNCTION
2476 {CENDFILE, CENDFILE, CENDFILE, CENDFILE}, /* 12, PEOF */ 2502 { CENDFILE, CENDFILE, CENDFILE, CENDFILE }, /* 12, PEOF */
2477 {CWORD, CWORD, CWORD, CWORD}, /* 13, 0-9A-Za-z */ 2503 { CWORD, CWORD, CWORD, CWORD }, /* 13, 0-9A-Za-z */
2478 {CCTL, CCTL, CCTL, CCTL} /* 14, CTLESC ... */ 2504 { CCTL, CCTL, CCTL, CCTL } /* 14, CTLESC ... */
2479#endif 2505#endif
2480}; 2506};
2481#else 2507#else
2482static const char S_I_T[][3] = { 2508static const char S_I_T[][3] = {
2483#if ENABLE_ASH_ALIAS 2509#if ENABLE_ASH_ALIAS
2484 {CSPCL, CIGN, CIGN}, /* 0, PEOA */ 2510 { CSPCL, CIGN, CIGN }, /* 0, PEOA */
2485#endif 2511#endif
2486 {CSPCL, CWORD, CWORD}, /* 1, ' ' */ 2512 { CSPCL, CWORD, CWORD }, /* 1, ' ' */
2487 {CNL, CNL, CNL}, /* 2, \n */ 2513 { CNL, CNL, CNL }, /* 2, \n */
2488 {CWORD, CCTL, CCTL}, /* 3, !*-/:=?[]~ */ 2514 { CWORD, CCTL, CCTL }, /* 3, !*-/:=?[]~ */
2489 {CDQUOTE, CENDQUOTE, CWORD}, /* 4, '"' */ 2515 { CDQUOTE, CENDQUOTE, CWORD }, /* 4, '"' */
2490 {CVAR, CVAR, CWORD}, /* 5, $ */ 2516 { CVAR, CVAR, CWORD }, /* 5, $ */
2491 {CSQUOTE, CWORD, CENDQUOTE}, /* 6, "'" */ 2517 { CSQUOTE, CWORD, CENDQUOTE }, /* 6, "'" */
2492 {CSPCL, CWORD, CWORD}, /* 7, ( */ 2518 { CSPCL, CWORD, CWORD }, /* 7, ( */
2493 {CSPCL, CWORD, CWORD}, /* 8, ) */ 2519 { CSPCL, CWORD, CWORD }, /* 8, ) */
2494 {CBACK, CBACK, CCTL}, /* 9, \ */ 2520 { CBACK, CBACK, CCTL }, /* 9, \ */
2495 {CBQUOTE, CBQUOTE, CWORD}, /* 10, ` */ 2521 { CBQUOTE, CBQUOTE, CWORD }, /* 10, ` */
2496 {CENDVAR, CENDVAR, CWORD}, /* 11, } */ 2522 { CENDVAR, CENDVAR, CWORD }, /* 11, } */
2497#ifndef USE_SIT_FUNCTION 2523#ifndef USE_SIT_FUNCTION
2498 {CENDFILE, CENDFILE, CENDFILE}, /* 12, PEOF */ 2524 { CENDFILE, CENDFILE, CENDFILE }, /* 12, PEOF */
2499 {CWORD, CWORD, CWORD}, /* 13, 0-9A-Za-z */ 2525 { CWORD, CWORD, CWORD }, /* 13, 0-9A-Za-z */
2500 {CCTL, CCTL, CCTL} /* 14, CTLESC ... */ 2526 { CCTL, CCTL, CCTL } /* 14, CTLESC ... */
2501#endif 2527#endif
2502}; 2528};
2503#endif /* ASH_MATH_SUPPORT */ 2529#endif /* ASH_MATH_SUPPORT */
2504 2530
2505#ifdef USE_SIT_FUNCTION 2531#ifdef USE_SIT_FUNCTION
2506 2532
2507#define U_C(c) ((unsigned char)(c))
2508
2509static int 2533static int
2510SIT(int c, int syntax) 2534SIT(int c, int syntax)
2511{ 2535{
@@ -2535,9 +2559,13 @@ SIT(int c, int syntax)
2535 indx = 0; 2559 indx = 0;
2536 else 2560 else
2537#endif 2561#endif
2538 if (U_C(c) >= U_C(CTLESC) && U_C(c) <= U_C(CTLQUOTEMARK)) 2562#define U_C(c) ((unsigned char)(c))
2563
2564 if ((unsigned char)c >= (unsigned char)(CTLESC)
2565 && (unsigned char)c <= (unsigned char)(CTLQUOTEMARK)
2566 ) {
2539 return CCTL; 2567 return CCTL;
2540 else { 2568 } else {
2541 s = strchr(spec_symbls, c); 2569 s = strchr(spec_symbls, c);
2542 if (s == NULL || *s == '\0') 2570 if (s == NULL || *s == '\0')
2543 return CWORD; 2571 return CWORD;
@@ -2546,41 +2574,39 @@ SIT(int c, int syntax)
2546 return S_I_T[indx][syntax]; 2574 return S_I_T[indx][syntax];
2547} 2575}
2548 2576
2549#else /* USE_SIT_FUNCTION */ 2577#else /* !USE_SIT_FUNCTION */
2550
2551#define SIT(c, syntax) S_I_T[(int)syntax_index_table[((int)c)+SYNBASE]][syntax]
2552 2578
2553#if ENABLE_ASH_ALIAS 2579#if ENABLE_ASH_ALIAS
2554#define CSPCL_CIGN_CIGN_CIGN 0 2580#define CSPCL_CIGN_CIGN_CIGN 0
2555#define CSPCL_CWORD_CWORD_CWORD 1 2581#define CSPCL_CWORD_CWORD_CWORD 1
2556#define CNL_CNL_CNL_CNL 2 2582#define CNL_CNL_CNL_CNL 2
2557#define CWORD_CCTL_CCTL_CWORD 3 2583#define CWORD_CCTL_CCTL_CWORD 3
2558#define CDQUOTE_CENDQUOTE_CWORD_CWORD 4 2584#define CDQUOTE_CENDQUOTE_CWORD_CWORD 4
2559#define CVAR_CVAR_CWORD_CVAR 5 2585#define CVAR_CVAR_CWORD_CVAR 5
2560#define CSQUOTE_CWORD_CENDQUOTE_CWORD 6 2586#define CSQUOTE_CWORD_CENDQUOTE_CWORD 6
2561#define CSPCL_CWORD_CWORD_CLP 7 2587#define CSPCL_CWORD_CWORD_CLP 7
2562#define CSPCL_CWORD_CWORD_CRP 8 2588#define CSPCL_CWORD_CWORD_CRP 8
2563#define CBACK_CBACK_CCTL_CBACK 9 2589#define CBACK_CBACK_CCTL_CBACK 9
2564#define CBQUOTE_CBQUOTE_CWORD_CBQUOTE 10 2590#define CBQUOTE_CBQUOTE_CWORD_CBQUOTE 10
2565#define CENDVAR_CENDVAR_CWORD_CENDVAR 11 2591#define CENDVAR_CENDVAR_CWORD_CENDVAR 11
2566#define CENDFILE_CENDFILE_CENDFILE_CENDFILE 12 2592#define CENDFILE_CENDFILE_CENDFILE_CENDFILE 12
2567#define CWORD_CWORD_CWORD_CWORD 13 2593#define CWORD_CWORD_CWORD_CWORD 13
2568#define CCTL_CCTL_CCTL_CCTL 14 2594#define CCTL_CCTL_CCTL_CCTL 14
2569#else 2595#else
2570#define CSPCL_CWORD_CWORD_CWORD 0 2596#define CSPCL_CWORD_CWORD_CWORD 0
2571#define CNL_CNL_CNL_CNL 1 2597#define CNL_CNL_CNL_CNL 1
2572#define CWORD_CCTL_CCTL_CWORD 2 2598#define CWORD_CCTL_CCTL_CWORD 2
2573#define CDQUOTE_CENDQUOTE_CWORD_CWORD 3 2599#define CDQUOTE_CENDQUOTE_CWORD_CWORD 3
2574#define CVAR_CVAR_CWORD_CVAR 4 2600#define CVAR_CVAR_CWORD_CVAR 4
2575#define CSQUOTE_CWORD_CENDQUOTE_CWORD 5 2601#define CSQUOTE_CWORD_CENDQUOTE_CWORD 5
2576#define CSPCL_CWORD_CWORD_CLP 6 2602#define CSPCL_CWORD_CWORD_CLP 6
2577#define CSPCL_CWORD_CWORD_CRP 7 2603#define CSPCL_CWORD_CWORD_CRP 7
2578#define CBACK_CBACK_CCTL_CBACK 8 2604#define CBACK_CBACK_CCTL_CBACK 8
2579#define CBQUOTE_CBQUOTE_CWORD_CBQUOTE 9 2605#define CBQUOTE_CBQUOTE_CWORD_CBQUOTE 9
2580#define CENDVAR_CENDVAR_CWORD_CENDVAR 10 2606#define CENDVAR_CENDVAR_CWORD_CENDVAR 10
2581#define CENDFILE_CENDFILE_CENDFILE_CENDFILE 11 2607#define CENDFILE_CENDFILE_CENDFILE_CENDFILE 11
2582#define CWORD_CWORD_CWORD_CWORD 12 2608#define CWORD_CWORD_CWORD_CWORD 12
2583#define CCTL_CCTL_CCTL_CCTL 13 2609#define CCTL_CCTL_CCTL_CCTL 13
2584#endif 2610#endif
2585 2611
2586static const char syntax_index_table[258] = { 2612static const char syntax_index_table[258] = {
@@ -2847,30 +2873,9 @@ static const char syntax_index_table[258] = {
2847 /* 257 127 */ CWORD_CWORD_CWORD_CWORD, 2873 /* 257 127 */ CWORD_CWORD_CWORD_CWORD,
2848}; 2874};
2849 2875
2850#endif /* USE_SIT_FUNCTION */ 2876#define SIT(c, syntax) (S_I_T[(int)syntax_index_table[((int)c)+SYNBASE]][syntax])
2851
2852
2853/* exec.h */
2854
2855#if ENABLE_ASH_MATH_SUPPORT_64
2856typedef int64_t arith_t;
2857#define arith_t_type long long
2858#else
2859typedef long arith_t;
2860#define arith_t_type long
2861#endif
2862
2863#if ENABLE_ASH_MATH_SUPPORT
2864static arith_t dash_arith(const char *);
2865static arith_t arith(const char *expr, int *perrcode);
2866#endif
2867 2877
2868#if ENABLE_ASH_RANDOM_SUPPORT 2878#endif /* USE_SIT_FUNCTION */
2869static unsigned long rseed;
2870# ifndef DYNAMIC_VAR
2871# define DYNAMIC_VAR
2872# endif
2873#endif
2874 2879
2875 2880
2876/* main.h */ 2881/* main.h */
@@ -4244,10 +4249,10 @@ cmdlist(union node *np, int sep)
4244{ 4249{
4245 for (; np; np = np->narg.next) { 4250 for (; np; np = np->narg.next) {
4246 if (!sep) 4251 if (!sep)
4247 cmdputs(spcstr); 4252 cmdputs(" ");
4248 cmdtxt(np); 4253 cmdtxt(np);
4249 if (sep && np->narg.next) 4254 if (sep && np->narg.next)
4250 cmdputs(spcstr); 4255 cmdputs(" ");
4251 } 4256 }
4252} 4257}
4253 4258
@@ -4810,7 +4815,7 @@ memtodest(const char *p, size_t len, int syntax, int quotes)
4810 q = makestrspace(len * 2, q); 4815 q = makestrspace(len * 2, q);
4811 4816
4812 while (len--) { 4817 while (len--) {
4813 int c = SC2INT(*p++); 4818 int c = signed_char2int(*p++);
4814 if (!c) 4819 if (!c)
4815 continue; 4820 continue;
4816 if (quotes && (SIT(c, syntax) == CCTL || SIT(c, syntax) == CBACK)) 4821 if (quotes && (SIT(c, syntax) == CCTL || SIT(c, syntax) == CBACK))
@@ -5477,7 +5482,7 @@ varvalue(char *name, int varflags, int flags)
5477 goto param; 5482 goto param;
5478 /* fall through */ 5483 /* fall through */
5479 case '*': 5484 case '*':
5480 sep = ifsset() ? SC2INT(ifsval()[0]) : ' '; 5485 sep = ifsset() ? signed_char2int(ifsval()[0]) : ' ';
5481 if (quotes && (SIT(sep, syntax) == CCTL || SIT(sep, syntax) == CBACK)) 5486 if (quotes && (SIT(sep, syntax) == CCTL || SIT(sep, syntax) == CBACK))
5482 sepq = 1; 5487 sepq = 1;
5483 param: 5488 param:
@@ -8510,7 +8515,7 @@ preadbuffer(void)
8510#endif 8515#endif
8511 popstring(); 8516 popstring();
8512 if (--parsenleft >= 0) 8517 if (--parsenleft >= 0)
8513 return SC2INT(*parsenextc++); 8518 return signed_char2int(*parsenextc++);
8514 } 8519 }
8515 if (parsenleft == EOF_NLEFT || parsefile->buf == NULL) 8520 if (parsenleft == EOF_NLEFT || parsefile->buf == NULL)
8516 return PEOF; 8521 return PEOF;
@@ -8563,25 +8568,20 @@ preadbuffer(void)
8563 8568
8564 *q = savec; 8569 *q = savec;
8565 8570
8566 return SC2INT(*parsenextc++); 8571 return signed_char2int(*parsenextc++);
8567} 8572}
8568 8573
8569#define pgetc_as_macro() (--parsenleft >= 0? SC2INT(*parsenextc++) : preadbuffer()) 8574#define pgetc_as_macro() (--parsenleft >= 0? signed_char2int(*parsenextc++) : preadbuffer())
8570
8571#if ENABLE_ASH_OPTIMIZE_FOR_SIZE
8572#define pgetc_macro() pgetc()
8573static int 8575static int
8574pgetc(void) 8576pgetc(void)
8575{ 8577{
8576 return pgetc_as_macro(); 8578 return pgetc_as_macro();
8577} 8579}
8580
8581#if ENABLE_ASH_OPTIMIZE_FOR_SIZE
8582#define pgetc_macro() pgetc()
8578#else 8583#else
8579#define pgetc_macro() pgetc_as_macro() 8584#define pgetc_macro() pgetc_as_macro()
8580static int
8581pgetc(void)
8582{
8583 return pgetc_macro();
8584}
8585#endif 8585#endif
8586 8586
8587/* 8587/*
@@ -8810,6 +8810,7 @@ setinputstring(char *string)
8810 * 8810 *
8811 * Routines to check for mail. 8811 * Routines to check for mail.
8812 */ 8812 */
8813
8813#if ENABLE_ASH_MAIL 8814#if ENABLE_ASH_MAIL
8814 8815
8815#define MAXMBOXES 10 8816#define MAXMBOXES 10
@@ -8870,6 +8871,7 @@ changemail(const char *val)
8870{ 8871{
8871 mail_var_path_changed++; 8872 mail_var_path_changed++;
8872} 8873}
8874
8873#endif /* ASH_MAIL */ 8875#endif /* ASH_MAIL */
8874 8876
8875 8877
@@ -9133,7 +9135,7 @@ showvars(const char *sep_prefix, int on, int off)
9133 ep = listvars(on, off, &epend); 9135 ep = listvars(on, off, &epend);
9134 qsort(ep, epend - ep, sizeof(char *), vpcmp); 9136 qsort(ep, epend - ep, sizeof(char *), vpcmp);
9135 9137
9136 sep = *sep_prefix ? spcstr : sep_prefix; 9138 sep = *sep_prefix ? " " : sep_prefix;
9137 9139
9138 for (; ep < epend; ep++) { 9140 for (; ep < epend; ep++) {
9139 const char *p; 9141 const char *p;
@@ -10991,9 +10993,8 @@ readcmdfile(char *name)
10991} 10993}
10992 10994
10993 10995
10994/* ============ redir.c */ 10996/* ============ redir.c
10995 10997 *
10996/*
10997 * Code for dealing with input/output redirection. 10998 * Code for dealing with input/output redirection.
10998 */ 10999 */
10999 11000