]> de.git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - lex.c
I got parsing to work finally.
[xonotic/gmqcc.git] / lex.c
diff --git a/lex.c b/lex.c
index 669d13d7afd89201c20d7dd47ae6e666d6d6a5cd..556f485536934d6a860ddc40197bb5aa6327cb0f 100644 (file)
--- a/lex.c
+++ b/lex.c
@@ -48,7 +48,7 @@ struct lex_file *lex_open(FILE *fp) {
        lex->size   = lex->length; /* copy, this is never changed */
        fseek(lex->file, 0, SEEK_SET);
        lex->last = 0;
-       lex->line = 1;
+       lex->line = 0;
        
        memset(lex->peek, 0, sizeof(lex->peek));
        return lex;
@@ -139,15 +139,20 @@ static int lex_digraph(struct lex_file *file, int first) {
 
 static int lex_getch(struct lex_file *file) {
        int ch = lex_inget(file);
-       
+
+       static int str = 0;
        switch (ch) {
                case '?' :
                        return lex_trigraph(file);
                case '<' :
                case ':' :
                case '%' :
-                       return lex_digraph (file, ch);
-               case '\n': file->line ++;
+               case '"' : str = !str; if (str) { file->line ++; }
+                       return lex_digraph(file, ch);
+                       
+               case '\n':
+                       if (!str)
+                               file->line++;
        }
                
        return ch;
@@ -277,7 +282,14 @@ int lex_token(struct lex_file *file) {
        /* valid identifier */
        if (ch > 0 && (ch == '_' || isalpha(ch))) {
                lex_clear(file);
-               while (ch > 0 && ch != ' ' && ch != '(' && ch != '\n' && ch != ';') {
+               
+               /*
+                * Yes this is dirty, but there is no other _sane_ easy
+                * way to do it, this is what I call defensive programming
+                * if something breaks, add more defense :-)
+                */
+               while (ch >   0   && ch != ' ' && ch != '(' &&
+                      ch != '\n' && ch != ';' && ch != ')') {
                        lex_addch(ch, file);
                        ch = lex_getsource(file);
                }