ash: more cosmetics and cleanups

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2009-11-29 02:18:13 +01:00
parent 068d386a6c
commit 2ce42e98d7

View File

@ -446,6 +446,7 @@ out2str(const char *p)
/* ============ Parser structures */ /* ============ Parser structures */
/* control characters in argument strings */ /* control characters in argument strings */
#define CTL_FIRST CTLESC
#define CTLESC ((unsigned char)'\201') /* escape next character */ #define CTLESC ((unsigned char)'\201') /* escape next character */
#define CTLVAR ((unsigned char)'\202') /* variable defn */ #define CTLVAR ((unsigned char)'\202') /* variable defn */
#define CTLENDVAR ((unsigned char)'\203') #define CTLENDVAR ((unsigned char)'\203')
@ -455,6 +456,7 @@ out2str(const char *p)
#define CTLARI ((unsigned char)'\206') /* arithmetic expression */ #define CTLARI ((unsigned char)'\206') /* arithmetic expression */
#define CTLENDARI ((unsigned char)'\207') #define CTLENDARI ((unsigned char)'\207')
#define CTLQUOTEMARK ((unsigned char)'\210') #define CTLQUOTEMARK ((unsigned char)'\210')
#define CTL_LAST CTLQUOTEMARK
/* variable substitution byte (follows CTLVAR) */ /* variable substitution byte (follows CTLVAR) */
#define VSTYPE 0x0f /* type of variable substitution */ #define VSTYPE 0x0f /* type of variable substitution */
@ -2602,23 +2604,12 @@ pwdcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
#define CSPCL 13 /* these terminate a word */ #define CSPCL 13 /* these terminate a word */
#define CIGN 14 /* character should be ignored */ #define CIGN 14 /* character should be ignored */
#if ENABLE_ASH_ALIAS
# define PEOA 256
# define PEOF 257
#else
#define PEOF 256 #define PEOF 256
#if ENABLE_ASH_ALIAS
# define PEOA 257
#endif #endif
/* number syntax index */ #define USE_SIT_FUNCTION ENABLE_ASH_OPTIMIZE_FOR_SIZE
#define BASESYNTAX 0 /* not in quotes */
#define DQSYNTAX 1 /* in double quotes */
#define SQSYNTAX 2 /* in single quotes */
#define ARISYNTAX 3 /* in arithmetic */
#define PSSYNTAX 4 /* prompt */
#if ENABLE_ASH_OPTIMIZE_FOR_SIZE
# define USE_SIT_FUNCTION
#endif
#if ENABLE_SH_MATH_SUPPORT #if ENABLE_SH_MATH_SUPPORT
# define SIT_ITEM(a,b,c,d) (a | (b << 4) | (c << 8) | (d << 12)) # 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[] = {
SIT_ITEM(CBACK , CBACK , CCTL , CBACK ), /* 9, \ */ SIT_ITEM(CBACK , CBACK , CCTL , CBACK ), /* 9, \ */
SIT_ITEM(CBQUOTE , CBQUOTE , CWORD, CBQUOTE), /* 10, ` */ SIT_ITEM(CBQUOTE , CBQUOTE , CWORD, CBQUOTE), /* 10, ` */
SIT_ITEM(CENDVAR , CENDVAR , CWORD, CENDVAR), /* 11, } */ SIT_ITEM(CENDVAR , CENDVAR , CWORD, CENDVAR), /* 11, } */
#ifndef USE_SIT_FUNCTION #if !USE_SIT_FUNCTION
SIT_ITEM(CENDFILE, CENDFILE , CENDFILE, CENDFILE),/* 12, PEOF */ SIT_ITEM(CENDFILE, CENDFILE , CENDFILE, CENDFILE),/* 12, PEOF */
SIT_ITEM(CWORD , CWORD , CWORD, CWORD ), /* 13, 0-9A-Za-z */ SIT_ITEM(CWORD , CWORD , CWORD, CWORD ), /* 13, 0-9A-Za-z */
SIT_ITEM(CCTL , CCTL , CCTL , CCTL ) /* 14, CTLESC ... */ SIT_ITEM(CCTL , CCTL , CCTL , CCTL ) /* 14, CTLESC ... */
@ -2671,8 +2662,14 @@ enum {
/* c in SIT(c, syntax) must be an *unsigned char* or PEOA or PEOF, /* c in SIT(c, syntax) must be an *unsigned char* or PEOA or PEOF,
* caller must ensure proper cast on it if c is *char_ptr! * caller must ensure proper cast on it if c is *char_ptr!
*/ */
/* Values for syntax param */
#define BASESYNTAX 0 /* not in quotes */
#define DQSYNTAX 1 /* in double quotes */
#define SQSYNTAX 2 /* in single quotes */
#define ARISYNTAX 3 /* in arithmetic */
#define PSSYNTAX 4 /* prompt. never passed to SIT() */
#ifdef USE_SIT_FUNCTION #if USE_SIT_FUNCTION
static int static int
SIT(int c, int syntax) SIT(int c, int syntax)
@ -2696,24 +2693,24 @@ SIT(int c, int syntax)
const char *s; const char *s;
int indx; int indx;
if (c == PEOF) { /* 2^8+2 */ if (c == PEOF)
return CENDFILE; return CENDFILE;
}
# if ENABLE_ASH_ALIAS # if ENABLE_ASH_ALIAS
if (c == PEOA) { /* 2^8+1 */ if (c == PEOA)
indx = 0; indx = 0;
} else else
# endif # endif
{ {
if ((unsigned char)c >= CTLESC /* Cast is purely for paranoia here,
&& (unsigned char)c <= CTLQUOTEMARK * just in case someone passed signed char to us */
if ((unsigned char)c >= CTL_FIRST
&& (unsigned char)c <= CTL_LAST
) { ) {
return CCTL; return CCTL;
} }
s = strchrnul(spec_symbls, c); s = strchrnul(spec_symbls, c);
if (*s == '\0') { if (*s == '\0')
return CWORD; return CWORD;
}
indx = syntax_index_table[s - spec_symbls]; indx = syntax_index_table[s - spec_symbls];
} }
return (S_I_T[indx] >> (syntax*4)) & 0xf; return (S_I_T[indx] >> (syntax*4)) & 0xf;
@ -2979,13 +2976,13 @@ static const uint8_t syntax_index_table[] = {
/* 253 */ CWORD_CWORD_CWORD_CWORD, /* 253 */ CWORD_CWORD_CWORD_CWORD,
/* 254 */ CWORD_CWORD_CWORD_CWORD, /* 254 */ CWORD_CWORD_CWORD_CWORD,
/* 255 */ CWORD_CWORD_CWORD_CWORD, /* 255 */ CWORD_CWORD_CWORD_CWORD,
/* PEOF */ CENDFILE_CENDFILE_CENDFILE_CENDFILE,
# if ENABLE_ASH_ALIAS # if ENABLE_ASH_ALIAS
/* PEOA */ CSPCL_CIGN_CIGN_CIGN, /* PEOA */ CSPCL_CIGN_CIGN_CIGN,
# endif # endif
/* PEOF */ CENDFILE_CENDFILE_CENDFILE_CENDFILE,
}; };
# define SIT(c, syntax) ((S_I_T[syntax_index_table[c]] >> (syntax*4)) & 0xf) # define SIT(c, syntax) ((S_I_T[syntax_index_table[c]] >> ((syntax)*4)) & 0xf)
#endif /* !USE_SIT_FUNCTION */ #endif /* !USE_SIT_FUNCTION */
@ -9549,12 +9546,9 @@ pgetc(void)
# define pgetc_fast() pgetc_as_macro() # define pgetc_fast() pgetc_as_macro()
#endif #endif
/*
* Same as pgetc(), but ignores PEOA.
*/
#if ENABLE_ASH_ALIAS #if ENABLE_ASH_ALIAS
static int static int
pgetc2(void) pgetc_without_PEOA(void)
{ {
int c; int c;
do { do {
@ -9567,7 +9561,7 @@ pgetc2(void)
return c; return c;
} }
#else #else
#define pgetc2() pgetc() # define pgetc_without_PEOA() pgetc()
#endif #endif
/* /*
@ -9581,7 +9575,7 @@ pfgets(char *line, int len)
int c; int c;
while (--nleft > 0) { while (--nleft > 0) {
c = pgetc2(); c = pgetc_without_PEOA();
if (c == PEOF) { if (c == PEOF) {
if (p == line) if (p == line)
return NULL; return NULL;
@ -10891,7 +10885,7 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs)
USTPUTC(c, out); USTPUTC(c, out);
break; break;
case CBACK: /* backslash */ case CBACK: /* backslash */
c = pgetc2(); c = pgetc_without_PEOA();
if (c == PEOF) { if (c == PEOF) {
USTPUTC(CTLESC, out); USTPUTC(CTLESC, out);
USTPUTC('\\', out); USTPUTC('\\', out);
@ -11005,9 +10999,7 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs)
#endif #endif
goto endword; /* exit outer loop */ goto endword; /* exit outer loop */
} }
#if ENABLE_ASH_ALIAS IF_ASH_ALIAS(if (c != PEOA))
if (c != PEOA)
#endif
USTPUTC(c, out); USTPUTC(c, out);
} }
@ -11059,13 +11051,12 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs)
checkend: { checkend: {
if (eofmark) { if (eofmark) {
#if ENABLE_ASH_ALIAS #if ENABLE_ASH_ALIAS
if (c == PEOA) { if (c == PEOA)
c = pgetc2(); c = pgetc_without_PEOA();
}
#endif #endif
if (striptabs) { if (striptabs) {
while (c == '\t') { while (c == '\t') {
c = pgetc2(); c = pgetc_without_PEOA();
} }
} }
if (c == *eofmark) { if (c == *eofmark) {
@ -11377,9 +11368,7 @@ parsebackq: {
/* fall through */ /* fall through */
case PEOF: case PEOF:
#if ENABLE_ASH_ALIAS IF_ASH_ALIAS(case PEOA:)
case PEOA:
#endif
startlinno = g_parsefile->linno; startlinno = g_parsefile->linno;
raise_error_syntax("EOF in backquote substitution"); raise_error_syntax("EOF in backquote substitution");
@ -11596,9 +11585,7 @@ xxreadtoken(void)
c = pgetc_fast(); c = pgetc_fast();
switch (c) { switch (c) {
case ' ': case '\t': case ' ': case '\t':
#if ENABLE_ASH_ALIAS IF_ASH_ALIAS(case PEOA:)
case PEOA:
#endif
continue; continue;
case '#': case '#':
while ((c = pgetc()) != '\n' && c != PEOF) while ((c = pgetc()) != '\n' && c != PEOF)