diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-11-29 02:18:13 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-11-29 02:18:13 +0100 |
commit | 2ce42e98d799de4c3389d9c4ce0a6b0d42dac7cc (patch) | |
tree | e67de3ecd71317e5862211e1c44eb615debfe4c2 | |
parent | 068d386a6c3901c24aba17676555a951c4c860a2 (diff) | |
download | busybox-w32-2ce42e98d799de4c3389d9c4ce0a6b0d42dac7cc.tar.gz busybox-w32-2ce42e98d799de4c3389d9c4ce0a6b0d42dac7cc.tar.bz2 busybox-w32-2ce42e98d799de4c3389d9c4ce0a6b0d42dac7cc.zip |
ash: more cosmetics and cleanups
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/ash.c | 83 |
1 files changed, 35 insertions, 48 deletions
diff --git a/shell/ash.c b/shell/ash.c index d716d408b..a90122149 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -446,6 +446,7 @@ out2str(const char *p) | |||
446 | /* ============ Parser structures */ | 446 | /* ============ Parser structures */ |
447 | 447 | ||
448 | /* control characters in argument strings */ | 448 | /* control characters in argument strings */ |
449 | #define CTL_FIRST CTLESC | ||
449 | #define CTLESC ((unsigned char)'\201') /* escape next character */ | 450 | #define CTLESC ((unsigned char)'\201') /* escape next character */ |
450 | #define CTLVAR ((unsigned char)'\202') /* variable defn */ | 451 | #define CTLVAR ((unsigned char)'\202') /* variable defn */ |
451 | #define CTLENDVAR ((unsigned char)'\203') | 452 | #define CTLENDVAR ((unsigned char)'\203') |
@@ -455,6 +456,7 @@ out2str(const char *p) | |||
455 | #define CTLARI ((unsigned char)'\206') /* arithmetic expression */ | 456 | #define CTLARI ((unsigned char)'\206') /* arithmetic expression */ |
456 | #define CTLENDARI ((unsigned char)'\207') | 457 | #define CTLENDARI ((unsigned char)'\207') |
457 | #define CTLQUOTEMARK ((unsigned char)'\210') | 458 | #define CTLQUOTEMARK ((unsigned char)'\210') |
459 | #define CTL_LAST CTLQUOTEMARK | ||
458 | 460 | ||
459 | /* variable substitution byte (follows CTLVAR) */ | 461 | /* variable substitution byte (follows CTLVAR) */ |
460 | #define VSTYPE 0x0f /* type of variable substitution */ | 462 | #define VSTYPE 0x0f /* type of variable substitution */ |
@@ -2602,23 +2604,12 @@ pwdcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
2602 | #define CSPCL 13 /* these terminate a word */ | 2604 | #define CSPCL 13 /* these terminate a word */ |
2603 | #define CIGN 14 /* character should be ignored */ | 2605 | #define CIGN 14 /* character should be ignored */ |
2604 | 2606 | ||
2607 | #define PEOF 256 | ||
2605 | #if ENABLE_ASH_ALIAS | 2608 | #if ENABLE_ASH_ALIAS |
2606 | # define PEOA 256 | 2609 | # define PEOA 257 |
2607 | # define PEOF 257 | ||
2608 | #else | ||
2609 | # define PEOF 256 | ||
2610 | #endif | 2610 | #endif |
2611 | 2611 | ||
2612 | /* number syntax index */ | 2612 | #define USE_SIT_FUNCTION ENABLE_ASH_OPTIMIZE_FOR_SIZE |
2613 | #define BASESYNTAX 0 /* not in quotes */ | ||
2614 | #define DQSYNTAX 1 /* in double quotes */ | ||
2615 | #define SQSYNTAX 2 /* in single quotes */ | ||
2616 | #define ARISYNTAX 3 /* in arithmetic */ | ||
2617 | #define PSSYNTAX 4 /* prompt */ | ||
2618 | |||
2619 | #if ENABLE_ASH_OPTIMIZE_FOR_SIZE | ||
2620 | # define USE_SIT_FUNCTION | ||
2621 | #endif | ||
2622 | 2613 | ||
2623 | #if ENABLE_SH_MATH_SUPPORT | 2614 | #if ENABLE_SH_MATH_SUPPORT |
2624 | # define SIT_ITEM(a,b,c,d) (a | (b << 4) | (c << 8) | (d << 12)) | 2615 | # define SIT_ITEM(a,b,c,d) (a | (b << 4) | (c << 8) | (d << 12)) |
@@ -2640,7 +2631,7 @@ static const uint16_t S_I_T[] = { | |||
2640 | SIT_ITEM(CBACK , CBACK , CCTL , CBACK ), /* 9, \ */ | 2631 | SIT_ITEM(CBACK , CBACK , CCTL , CBACK ), /* 9, \ */ |
2641 | SIT_ITEM(CBQUOTE , CBQUOTE , CWORD, CBQUOTE), /* 10, ` */ | 2632 | SIT_ITEM(CBQUOTE , CBQUOTE , CWORD, CBQUOTE), /* 10, ` */ |
2642 | SIT_ITEM(CENDVAR , CENDVAR , CWORD, CENDVAR), /* 11, } */ | 2633 | SIT_ITEM(CENDVAR , CENDVAR , CWORD, CENDVAR), /* 11, } */ |
2643 | #ifndef USE_SIT_FUNCTION | 2634 | #if !USE_SIT_FUNCTION |
2644 | SIT_ITEM(CENDFILE, CENDFILE , CENDFILE, CENDFILE),/* 12, PEOF */ | 2635 | SIT_ITEM(CENDFILE, CENDFILE , CENDFILE, CENDFILE),/* 12, PEOF */ |
2645 | SIT_ITEM(CWORD , CWORD , CWORD, CWORD ), /* 13, 0-9A-Za-z */ | 2636 | SIT_ITEM(CWORD , CWORD , CWORD, CWORD ), /* 13, 0-9A-Za-z */ |
2646 | SIT_ITEM(CCTL , CCTL , CCTL , CCTL ) /* 14, CTLESC ... */ | 2637 | SIT_ITEM(CCTL , CCTL , CCTL , CCTL ) /* 14, CTLESC ... */ |
@@ -2671,8 +2662,14 @@ enum { | |||
2671 | /* c in SIT(c, syntax) must be an *unsigned char* or PEOA or PEOF, | 2662 | /* c in SIT(c, syntax) must be an *unsigned char* or PEOA or PEOF, |
2672 | * caller must ensure proper cast on it if c is *char_ptr! | 2663 | * caller must ensure proper cast on it if c is *char_ptr! |
2673 | */ | 2664 | */ |
2665 | /* Values for syntax param */ | ||
2666 | #define BASESYNTAX 0 /* not in quotes */ | ||
2667 | #define DQSYNTAX 1 /* in double quotes */ | ||
2668 | #define SQSYNTAX 2 /* in single quotes */ | ||
2669 | #define ARISYNTAX 3 /* in arithmetic */ | ||
2670 | #define PSSYNTAX 4 /* prompt. never passed to SIT() */ | ||
2674 | 2671 | ||
2675 | #ifdef USE_SIT_FUNCTION | 2672 | #if USE_SIT_FUNCTION |
2676 | 2673 | ||
2677 | static int | 2674 | static int |
2678 | SIT(int c, int syntax) | 2675 | SIT(int c, int syntax) |
@@ -2696,24 +2693,24 @@ SIT(int c, int syntax) | |||
2696 | const char *s; | 2693 | const char *s; |
2697 | int indx; | 2694 | int indx; |
2698 | 2695 | ||
2699 | if (c == PEOF) { /* 2^8+2 */ | 2696 | if (c == PEOF) |
2700 | return CENDFILE; | 2697 | return CENDFILE; |
2701 | } | ||
2702 | # if ENABLE_ASH_ALIAS | 2698 | # if ENABLE_ASH_ALIAS |
2703 | if (c == PEOA) { /* 2^8+1 */ | 2699 | if (c == PEOA) |
2704 | indx = 0; | 2700 | indx = 0; |
2705 | } else | 2701 | else |
2706 | # endif | 2702 | # endif |
2707 | { | 2703 | { |
2708 | if ((unsigned char)c >= CTLESC | 2704 | /* Cast is purely for paranoia here, |
2709 | && (unsigned char)c <= CTLQUOTEMARK | 2705 | * just in case someone passed signed char to us */ |
2706 | if ((unsigned char)c >= CTL_FIRST | ||
2707 | && (unsigned char)c <= CTL_LAST | ||
2710 | ) { | 2708 | ) { |
2711 | return CCTL; | 2709 | return CCTL; |
2712 | } | 2710 | } |
2713 | s = strchrnul(spec_symbls, c); | 2711 | s = strchrnul(spec_symbls, c); |
2714 | if (*s == '\0') { | 2712 | if (*s == '\0') |
2715 | return CWORD; | 2713 | return CWORD; |
2716 | } | ||
2717 | indx = syntax_index_table[s - spec_symbls]; | 2714 | indx = syntax_index_table[s - spec_symbls]; |
2718 | } | 2715 | } |
2719 | return (S_I_T[indx] >> (syntax*4)) & 0xf; | 2716 | return (S_I_T[indx] >> (syntax*4)) & 0xf; |
@@ -2979,13 +2976,13 @@ static const uint8_t syntax_index_table[] = { | |||
2979 | /* 253 */ CWORD_CWORD_CWORD_CWORD, | 2976 | /* 253 */ CWORD_CWORD_CWORD_CWORD, |
2980 | /* 254 */ CWORD_CWORD_CWORD_CWORD, | 2977 | /* 254 */ CWORD_CWORD_CWORD_CWORD, |
2981 | /* 255 */ CWORD_CWORD_CWORD_CWORD, | 2978 | /* 255 */ CWORD_CWORD_CWORD_CWORD, |
2979 | /* PEOF */ CENDFILE_CENDFILE_CENDFILE_CENDFILE, | ||
2982 | # if ENABLE_ASH_ALIAS | 2980 | # if ENABLE_ASH_ALIAS |
2983 | /* PEOA */ CSPCL_CIGN_CIGN_CIGN, | 2981 | /* PEOA */ CSPCL_CIGN_CIGN_CIGN, |
2984 | # endif | 2982 | # endif |
2985 | /* PEOF */ CENDFILE_CENDFILE_CENDFILE_CENDFILE, | ||
2986 | }; | 2983 | }; |
2987 | 2984 | ||
2988 | # define SIT(c, syntax) ((S_I_T[syntax_index_table[c]] >> (syntax*4)) & 0xf) | 2985 | # define SIT(c, syntax) ((S_I_T[syntax_index_table[c]] >> ((syntax)*4)) & 0xf) |
2989 | 2986 | ||
2990 | #endif /* !USE_SIT_FUNCTION */ | 2987 | #endif /* !USE_SIT_FUNCTION */ |
2991 | 2988 | ||
@@ -9544,17 +9541,14 @@ pgetc(void) | |||
9544 | } | 9541 | } |
9545 | 9542 | ||
9546 | #if ENABLE_ASH_OPTIMIZE_FOR_SIZE | 9543 | #if ENABLE_ASH_OPTIMIZE_FOR_SIZE |
9547 | #define pgetc_fast() pgetc() | 9544 | # define pgetc_fast() pgetc() |
9548 | #else | 9545 | #else |
9549 | #define pgetc_fast() pgetc_as_macro() | 9546 | # define pgetc_fast() pgetc_as_macro() |
9550 | #endif | 9547 | #endif |
9551 | 9548 | ||
9552 | /* | ||
9553 | * Same as pgetc(), but ignores PEOA. | ||
9554 | */ | ||
9555 | #if ENABLE_ASH_ALIAS | 9549 | #if ENABLE_ASH_ALIAS |
9556 | static int | 9550 | static int |
9557 | pgetc2(void) | 9551 | pgetc_without_PEOA(void) |
9558 | { | 9552 | { |
9559 | int c; | 9553 | int c; |
9560 | do { | 9554 | do { |
@@ -9567,7 +9561,7 @@ pgetc2(void) | |||
9567 | return c; | 9561 | return c; |
9568 | } | 9562 | } |
9569 | #else | 9563 | #else |
9570 | #define pgetc2() pgetc() | 9564 | # define pgetc_without_PEOA() pgetc() |
9571 | #endif | 9565 | #endif |
9572 | 9566 | ||
9573 | /* | 9567 | /* |
@@ -9581,7 +9575,7 @@ pfgets(char *line, int len) | |||
9581 | int c; | 9575 | int c; |
9582 | 9576 | ||
9583 | while (--nleft > 0) { | 9577 | while (--nleft > 0) { |
9584 | c = pgetc2(); | 9578 | c = pgetc_without_PEOA(); |
9585 | if (c == PEOF) { | 9579 | if (c == PEOF) { |
9586 | if (p == line) | 9580 | if (p == line) |
9587 | return NULL; | 9581 | return NULL; |
@@ -10891,7 +10885,7 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs) | |||
10891 | USTPUTC(c, out); | 10885 | USTPUTC(c, out); |
10892 | break; | 10886 | break; |
10893 | case CBACK: /* backslash */ | 10887 | case CBACK: /* backslash */ |
10894 | c = pgetc2(); | 10888 | c = pgetc_without_PEOA(); |
10895 | if (c == PEOF) { | 10889 | if (c == PEOF) { |
10896 | USTPUTC(CTLESC, out); | 10890 | USTPUTC(CTLESC, out); |
10897 | USTPUTC('\\', out); | 10891 | USTPUTC('\\', out); |
@@ -11005,9 +10999,7 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs) | |||
11005 | #endif | 10999 | #endif |
11006 | goto endword; /* exit outer loop */ | 11000 | goto endword; /* exit outer loop */ |
11007 | } | 11001 | } |
11008 | #if ENABLE_ASH_ALIAS | 11002 | IF_ASH_ALIAS(if (c != PEOA)) |
11009 | if (c != PEOA) | ||
11010 | #endif | ||
11011 | USTPUTC(c, out); | 11003 | USTPUTC(c, out); |
11012 | 11004 | ||
11013 | } | 11005 | } |
@@ -11059,13 +11051,12 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs) | |||
11059 | checkend: { | 11051 | checkend: { |
11060 | if (eofmark) { | 11052 | if (eofmark) { |
11061 | #if ENABLE_ASH_ALIAS | 11053 | #if ENABLE_ASH_ALIAS |
11062 | if (c == PEOA) { | 11054 | if (c == PEOA) |
11063 | c = pgetc2(); | 11055 | c = pgetc_without_PEOA(); |
11064 | } | ||
11065 | #endif | 11056 | #endif |
11066 | if (striptabs) { | 11057 | if (striptabs) { |
11067 | while (c == '\t') { | 11058 | while (c == '\t') { |
11068 | c = pgetc2(); | 11059 | c = pgetc_without_PEOA(); |
11069 | } | 11060 | } |
11070 | } | 11061 | } |
11071 | if (c == *eofmark) { | 11062 | if (c == *eofmark) { |
@@ -11377,9 +11368,7 @@ parsebackq: { | |||
11377 | /* fall through */ | 11368 | /* fall through */ |
11378 | 11369 | ||
11379 | case PEOF: | 11370 | case PEOF: |
11380 | #if ENABLE_ASH_ALIAS | 11371 | IF_ASH_ALIAS(case PEOA:) |
11381 | case PEOA: | ||
11382 | #endif | ||
11383 | startlinno = g_parsefile->linno; | 11372 | startlinno = g_parsefile->linno; |
11384 | raise_error_syntax("EOF in backquote substitution"); | 11373 | raise_error_syntax("EOF in backquote substitution"); |
11385 | 11374 | ||
@@ -11596,9 +11585,7 @@ xxreadtoken(void) | |||
11596 | c = pgetc_fast(); | 11585 | c = pgetc_fast(); |
11597 | switch (c) { | 11586 | switch (c) { |
11598 | case ' ': case '\t': | 11587 | case ' ': case '\t': |
11599 | #if ENABLE_ASH_ALIAS | 11588 | IF_ASH_ALIAS(case PEOA:) |
11600 | case PEOA: | ||
11601 | #endif | ||
11602 | continue; | 11589 | continue; |
11603 | case '#': | 11590 | case '#': |
11604 | while ((c = pgetc()) != '\n' && c != PEOF) | 11591 | while ((c = pgetc()) != '\n' && c != PEOF) |