]> skyeroc.xyz Git - dgamelaunch/commitdiff
handle unterminated strings a bit better, and negative numbers
authorJoshua Kwan <joshk@triplehelix.org>
Mon, 2 Feb 2004 01:03:57 +0000 (01:03 +0000)
committerJoshua Kwan <joshk@triplehelix.org>
Mon, 2 Feb 2004 01:03:57 +0000 (01:03 +0000)
git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@212 db0b04b0-f4d1-0310-9a6d-de3e77497b0e

config.l
config.y

index 8555daecf5fd5e11243752cbca7c259b8bbf3db1..95bb71375489f699b988898d8ae0980a67efbdab 100644 (file)
--- a/config.l
+++ b/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);
 }
 
 %%
index fd31bd3f619d090daf4cab0ce1f8ebc1a167dc60..02863cd1a10329a748f784da3fa1ed340d0efe56 100644 (file)
--- a/config.y
+++ b/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);
 }