handle unterminated strings a bit better, and negative numbers
git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@212 db0b04b0-f4d1-0310-9a6d-de3e77497b0e
This commit is contained in:
parent
d5c7d15202
commit
4fc6f54bec
34
config.l
34
config.l
|
@ -15,7 +15,8 @@ unsigned int line = 1, col = 0;
|
|||
|
||||
%}
|
||||
|
||||
NUMBER -?[0-9]+
|
||||
NEGNUMBER -[0-9]+
|
||||
NUMBER [^-][0-9]+
|
||||
VALUE \".*\"
|
||||
MALSTRING \"[^\"\n]*\n
|
||||
WHITE [\t ]*
|
||||
|
@ -23,27 +24,14 @@ COMMENT ^#.*
|
|||
|
||||
%%
|
||||
|
||||
{NUMBER} {
|
||||
unsigned int x;
|
||||
errno = 0;
|
||||
|
||||
if (atoi(yytext) < 0)
|
||||
{
|
||||
fprintf(stderr,"%s:%d: negative value not accepted! Fix it now!\n",
|
||||
{NEGNUMBER} {
|
||||
fprintf(stderr,"%s:%d: negative value not accepted! Fix it now!\n",
|
||||
config, line);
|
||||
graceful_exit(1);
|
||||
}
|
||||
|
||||
x = strtoul(yytext, NULL, 10);
|
||||
|
||||
if (errno == ERANGE)
|
||||
{
|
||||
fprintf(stderr, "%s:%d: %s is too big! Fix it now!\n",
|
||||
config, line, yytext);
|
||||
graceful_exit(1);
|
||||
}
|
||||
|
||||
yylval.i = x;
|
||||
graceful_exit(1);
|
||||
}
|
||||
|
||||
{NUMBER} {
|
||||
yylval.i = strtoul(yytext, NULL, 10);
|
||||
return TYPE_NUMBER;
|
||||
}
|
||||
|
||||
|
@ -54,8 +42,10 @@ COMMENT ^#.*
|
|||
}
|
||||
|
||||
{MALSTRING} {
|
||||
yytext[yyleng - 1] = '\0'; /* remove trailing newline */
|
||||
/* yytext already contains a newline, no need for one here */
|
||||
fprintf(stderr, "%s:%d:%d: unterminated string constant: %s\n", config, line, col - yyleng + 1, yytext);
|
||||
return TYPE_MALSTRING;
|
||||
}
|
||||
|
||||
{WHITE} { }
|
||||
|
@ -80,7 +70,7 @@ COMMENT ^#.*
|
|||
\n { line++; col = 0; }
|
||||
|
||||
. {
|
||||
fprintf(stderr, "%s: unrecognized token \"%s\" at line %d, column %d\n", config, yytext, line, col);
|
||||
fprintf(stderr, "%s:%d:%d unrecognized token \"%s\"\n", config, line, col, yytext);
|
||||
}
|
||||
|
||||
%%
|
||||
|
|
5
config.y
5
config.y
|
@ -26,7 +26,7 @@ static const char* lookup_token (int t);
|
|||
%token TYPE_SUSER TYPE_SGROUP TYPE_SGID TYPE_SUID TYPE_MAX
|
||||
%token TYPE_PATH_NETHACK TYPE_PATH_DGLDIR TYPE_PATH_SPOOL
|
||||
%token TYPE_PATH_BANNER TYPE_PATH_CANNED TYPE_PATH_CHROOT
|
||||
%token TYPE_PATH_PASSWD TYPE_PATH_LOCKFILE
|
||||
%token TYPE_PATH_PASSWD TYPE_PATH_LOCKFILE TYPE_MALSTRING
|
||||
%token <s> TYPE_VALUE
|
||||
%token <i> TYPE_NUMBER
|
||||
%type <kt> KeyType
|
||||
|
@ -154,6 +154,7 @@ KeyPair: KeyType '=' TYPE_VALUE {
|
|||
|
||||
free($3);
|
||||
}
|
||||
| KeyType '=' TYPE_MALSTRING {}
|
||||
| KeyType '=' TYPE_NUMBER {
|
||||
if (!myconfig)
|
||||
{
|
||||
|
@ -238,5 +239,5 @@ const char* lookup_token (int t)
|
|||
void yyerror(char const* s)
|
||||
{
|
||||
if (!silent)
|
||||
fprintf(stderr, "%s: couldn't parse \"%s\" at line %d, column %d: %s\n", config, yytext, line, col, s);
|
||||
fprintf(stderr, "%s:%d:%d: couldn't parse \"%s\": %s\n", config, line, col, yytext, s);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue