Put the comparison with PEOF into a new macro is_eof(). Don't use it if the

character comes from a string.
This commit is contained in:
Stefan Farfeleder 2005-08-13 15:47:13 +00:00
parent adecfb8dfc
commit 716b138b4b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=149026
2 changed files with 8 additions and 6 deletions

View File

@ -343,9 +343,10 @@ print(char *name)
static char *macro[] = {
"#define is_digit(c)\t((is_type+SYNBASE)[c] & ISDIGIT)",
"#define is_alpha(c)\t((c) != PEOF && ((c) < CTLESC || (c) > CTLQUOTEMARK) && isalpha((unsigned char) (c)))",
"#define is_name(c)\t((c) != PEOF && ((c) < CTLESC || (c) > CTLQUOTEMARK) && ((c) == '_' || isalpha((unsigned char) (c))))",
"#define is_in_name(c)\t((c) != PEOF && ((c) < CTLESC || (c) > CTLQUOTEMARK) && ((c) == '_' || isalnum((unsigned char) (c))))",
"#define is_eof(c)\t((c) == PEOF)",
"#define is_alpha(c)\t(((c) < CTLESC || (c) > CTLQUOTEMARK) && isalpha((unsigned char) (c)))",
"#define is_name(c)\t(((c) < CTLESC || (c) > CTLQUOTEMARK) && ((c) == '_' || isalpha((unsigned char) (c))))",
"#define is_in_name(c)\t(((c) < CTLESC || (c) > CTLQUOTEMARK) && ((c) == '_' || isalnum((unsigned char) (c))))",
"#define is_special(c)\t((is_type+SYNBASE)[c] & (ISSPECL|ISDIGIT))",
NULL
};

View File

@ -1192,7 +1192,8 @@ parsesub: {
int bracketed_name = 0; /* used to handle ${[0-9]*} variables */
c = pgetc();
if (c != '(' && c != '{' && !is_name(c) && !is_special(c)) {
if (c != '(' && c != '{' && (is_eof(c) || !is_name(c)) &&
!is_special(c)) {
USTPUTC('$', out);
pungetc();
} else if (c == '(') { /* $(command) or $((arith)) */
@ -1219,11 +1220,11 @@ parsesub: {
else
subtype = 0;
}
if (is_name(c)) {
if (!is_eof(c) && is_name(c)) {
do {
STPUTC(c, out);
c = pgetc();
} while (is_in_name(c));
} while (!is_eof(c) && is_in_name(c));
} else if (is_digit(c)) {
if (bracketed_name) {
do {