]> mj.ucw.cz Git - umpf.git/blobdiff - lex.c
fix many little bugs, release 0.1
[umpf.git] / lex.c
diff --git a/lex.c b/lex.c
index e16a724c4c61073773d3838dd98305230400f00c..89fb71b2a8d15f0c35df1eefa2bb9ca4d41e7051 100644 (file)
--- a/lex.c
+++ b/lex.c
@@ -97,19 +97,21 @@ xstrdup(const char* s)
 static char*
 get_string_out(int delim)
 {
-       int last = delim; 
        int i = 0;
        int c;
        char buf[BUFSIZE];
 
-       while ((c = getc(conf)) != delim || last == '\\'){
-               if (last=='\\' && c != delim)
-                       buf[i-1] = c;
-               else {          
-                       buf[i] = c;
-                       i++;
-               }
-               last = c;
+       while ((c = getc(conf)) != delim){
+               if (c == '\\') {        
+                       c = getc(conf);
+                       if (c == EOF)
+                               parse_err("Unbounded string, %c missing", delim);
+                       buf[i++] = c;
+               } else if (c == '\n' || c == EOF)
+                       parse_err("Unbounded string, %c missing", delim);
+               else            
+                       buf[i++] = c;
+
                if (i >= BUFSIZE-1)
                        parse_err("Too long string, max allowed length is %d",BUFSIZE-1);       
        }       
@@ -222,7 +224,8 @@ yylex(void)
                        if (i >= BUFSIZE-1)
                                parse_err("Too long number");   
                }
-               ungetc(c,conf);
+               if (c != EOF)
+                       ungetc(c,conf);
                buf[i] = 0;
                yylval.str = xstrdup(buf);
 
@@ -239,6 +242,8 @@ yylex(void)
                        if (i >= BUFSIZE-1)
                                parse_err("Too long identifier, max allowed length is %d",BUFSIZE-1);   
                }
+               if (!i)
+                       parse_err("Variable identifier must not be empty");
                if (c > 0)
                        ungetc(c,conf);
                buf[i] = 0;