]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
This should fix line counting issues with the lexer
authorDale Weiler <killfieldengine@gmail.com>
Sat, 28 Apr 2012 20:30:44 +0000 (16:30 -0400)
committerDale Weiler <killfieldengine@gmail.com>
Sat, 28 Apr 2012 20:30:44 +0000 (16:30 -0400)
lex.c

diff --git a/lex.c b/lex.c
index 671d7a53220305070218624dff2f14fdee7d9931..deee270b2fba35b374ff202bf92fbbd716d02298 100644 (file)
--- a/lex.c
+++ b/lex.c
@@ -77,14 +77,25 @@ static inline void lex_clear(lex_file *file) {
  * it's own internal state for this.
  */
 static int lex_inget(lex_file *file) {
+    char  get;
     file->length --;
-    if (file->last > 0)
-        return file->peek[--file->last];
-    return fgetc(file->file);
+    
+    if (file->last > 0) {
+        if ((get = file->peek[--file->last]) == '\n')
+            file->line ++;
+        return get;
+    }
+    if ((get = fgetc(file->file)) == '\n')
+        file->line++;
+        
+    return get;
 }
 static void lex_unget(int ch, lex_file *file) {
-    if (file->last < sizeof(file->peek))
+    if (file->last < sizeof(file->peek)) {
+        if (ch == '\n')
+            file->line --;
         file->peek[file->last++] = ch;
+    }
     file->length ++;
 }