o Add support for escaped characters in the WORD macro

o Modify fill() to squash escape chars
This commit is contained in:
Todd C. Miller
1999-10-10 18:38:40 +00:00
parent deb02f9b36
commit f963da3164
2 changed files with 932 additions and 853 deletions

1762
lex.yy.c

File diff suppressed because it is too large Load Diff

View File

@@ -93,7 +93,7 @@ extern void yyerror __P((char *));
OCTET (1?[0-9]{1,2})|(2[0-4][0-9])|(25[0-5]) OCTET (1?[0-9]{1,2})|(2[0-4][0-9])|(25[0-5])
DOTTEDQUAD {OCTET}(\.{OCTET}){3} DOTTEDQUAD {OCTET}(\.{OCTET}){3}
HOSTNAME [[:alnum:]_-]+ HOSTNAME [[:alnum:]_-]+
WORD [^@!=:,\(\) \t\n\\]+ WORD ([^@!=:,\(\) \t\n\\]|\\[^\n])+
%e 4000 %e 4000
%p 6000 %p 6000
@@ -114,14 +114,13 @@ WORD [^@!=:,\(\) \t\n\\]+
LEXTRACE("\n\t"); LEXTRACE("\n\t");
} /* throw away EOL after \ */ } /* throw away EOL after \ */
<GOTCMND>\\[@:\,=\\ \t] { <GOTCMND>\\[:\,=\\ \t] {
LEXTRACE("QUOTEDCHAR "); LEXTRACE("QUOTEDCHAR ");
fill_args(yytext + 1, 1, sawspace); fill_args(yytext + 1, 1, sawspace);
sawspace = FALSE; sawspace = FALSE;
} }
<GOTDEFS>\"[^\"]+\" { <GOTDEFS>\"([^\"]|\\\")+\" {
/* XXX - should allow " to be quoted */
LEXTRACE("WORD(1) "); LEXTRACE("WORD(1) ");
fill(yytext + 1, yyleng - 2); fill(yytext + 1, yyleng - 2);
return(WORD); return(WORD);
@@ -262,8 +261,7 @@ PASSWD[[:blank:]]*: {
} }
} }
<GOTDEFS>[^ \t\n,=!]+ { <GOTDEFS>{WORD} {
/* XXX - should allow [!=,] to be quoted */
LEXTRACE("WORD(3) "); LEXTRACE("WORD(3) ");
fill(yytext, yyleng); fill(yytext, yyleng);
return(WORD); return(WORD);
@@ -337,13 +335,20 @@ fill(s, len)
char *s; char *s;
int len; int len;
{ {
int i, j;
yylval.string = (char *) malloc(len + 1); yylval.string = (char *) malloc(len + 1);
if (yylval.string == NULL) if (yylval.string == NULL)
yyerror("unable to allocate memory"); yyerror("unable to allocate memory");
/* copy the string and NULL-terminate it */ /* Copy the string and collapse any escaped characters. */
(void) strncpy(yylval.string, s, len); for (i = 0, j = 0; i < len; i++, j++) {
yylval.string[len] = '\0'; if (s[i] == '\\' && i != len - 1)
yylval.string[j] = s[++i];
else
yylval.string[j] = s[i];
}
yylval.string[j] = '\0';
} }
static void static void