/* ============ Parser structures */
/* control characters in argument strings */
+#define CTL_FIRST CTLESC
#define CTLESC ((unsigned char)'\201') /* escape next character */
#define CTLVAR ((unsigned char)'\202') /* variable defn */
#define CTLENDVAR ((unsigned char)'\203')
#define CTLARI ((unsigned char)'\206') /* arithmetic expression */
#define CTLENDARI ((unsigned char)'\207')
#define CTLQUOTEMARK ((unsigned char)'\210')
+#define CTL_LAST CTLQUOTEMARK
/* variable substitution byte (follows CTLVAR) */
#define VSTYPE 0x0f /* type of variable substitution */
#define CSPCL 13 /* these terminate a word */
#define CIGN 14 /* character should be ignored */
+#define PEOF 256
#if ENABLE_ASH_ALIAS
-# define PEOA 256
-# define PEOF 257
-#else
-# define PEOF 256
+# define PEOA 257
#endif
-/* number syntax index */
-#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
+#define USE_SIT_FUNCTION ENABLE_ASH_OPTIMIZE_FOR_SIZE
#if ENABLE_SH_MATH_SUPPORT
# define SIT_ITEM(a,b,c,d) (a | (b << 4) | (c << 8) | (d << 12))
SIT_ITEM(CBACK , CBACK , CCTL , CBACK ), /* 9, \ */
SIT_ITEM(CBQUOTE , CBQUOTE , CWORD, CBQUOTE), /* 10, ` */
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(CWORD , CWORD , CWORD, CWORD ), /* 13, 0-9A-Za-z */
SIT_ITEM(CCTL , CCTL , CCTL , CCTL ) /* 14, CTLESC ... */
/* 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!
*/
+/* 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
SIT(int c, int syntax)
const char *s;
int indx;
- if (c == PEOF) { /* 2^8+2 */
+ if (c == PEOF)
return CENDFILE;
- }
# if ENABLE_ASH_ALIAS
- if (c == PEOA) { /* 2^8+1 */
+ if (c == PEOA)
indx = 0;
- } else
+ else
# endif
{
- if ((unsigned char)c >= CTLESC
- && (unsigned char)c <= CTLQUOTEMARK
+ /* Cast is purely for paranoia here,
+ * just in case someone passed signed char to us */
+ if ((unsigned char)c >= CTL_FIRST
+ && (unsigned char)c <= CTL_LAST
) {
return CCTL;
}
s = strchrnul(spec_symbls, c);
- if (*s == '\0') {
+ if (*s == '\0')
return CWORD;
- }
indx = syntax_index_table[s - spec_symbls];
}
return (S_I_T[indx] >> (syntax*4)) & 0xf;
/* 253 */ CWORD_CWORD_CWORD_CWORD,
/* 254 */ CWORD_CWORD_CWORD_CWORD,
/* 255 */ CWORD_CWORD_CWORD_CWORD,
+ /* PEOF */ CENDFILE_CENDFILE_CENDFILE_CENDFILE,
# if ENABLE_ASH_ALIAS
/* PEOA */ CSPCL_CIGN_CIGN_CIGN,
# 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 */
}
#if ENABLE_ASH_OPTIMIZE_FOR_SIZE
-#define pgetc_fast() pgetc()
+# define pgetc_fast() pgetc()
#else
-#define pgetc_fast() pgetc_as_macro()
+# define pgetc_fast() pgetc_as_macro()
#endif
-/*
- * Same as pgetc(), but ignores PEOA.
- */
#if ENABLE_ASH_ALIAS
static int
-pgetc2(void)
+pgetc_without_PEOA(void)
{
int c;
do {
return c;
}
#else
-#define pgetc2() pgetc()
+# define pgetc_without_PEOA() pgetc()
#endif
/*
int c;
while (--nleft > 0) {
- c = pgetc2();
+ c = pgetc_without_PEOA();
if (c == PEOF) {
if (p == line)
return NULL;
USTPUTC(c, out);
break;
case CBACK: /* backslash */
- c = pgetc2();
+ c = pgetc_without_PEOA();
if (c == PEOF) {
USTPUTC(CTLESC, out);
USTPUTC('\\', out);
#endif
goto endword; /* exit outer loop */
}
-#if ENABLE_ASH_ALIAS
- if (c != PEOA)
-#endif
+ IF_ASH_ALIAS(if (c != PEOA))
USTPUTC(c, out);
}
checkend: {
if (eofmark) {
#if ENABLE_ASH_ALIAS
- if (c == PEOA) {
- c = pgetc2();
- }
+ if (c == PEOA)
+ c = pgetc_without_PEOA();
#endif
if (striptabs) {
while (c == '\t') {
- c = pgetc2();
+ c = pgetc_without_PEOA();
}
}
if (c == *eofmark) {
/* fall through */
case PEOF:
-#if ENABLE_ASH_ALIAS
- case PEOA:
-#endif
+ IF_ASH_ALIAS(case PEOA:)
startlinno = g_parsefile->linno;
raise_error_syntax("EOF in backquote substitution");
c = pgetc_fast();
switch (c) {
case ' ': case '\t':
-#if ENABLE_ASH_ALIAS
- case PEOA:
-#endif
+ IF_ASH_ALIAS(case PEOA:)
continue;
case '#':
while ((c = pgetc()) != '\n' && c != PEOF)