Track of line number correctly when input file has code with very long lines.
authormjsousa
Wed, 19 Mar 2014 12:13:43 +0000
changeset 880 599e88d12f9a
parent 879 c61b2e370181
child 881 e05d69c1ccb3
child 885 b2604fc6d25c
Track of line number correctly when input file has code with very long lines.
stage1_2/iec_flex.ll
--- a/stage1_2/iec_flex.ll	Wed Mar 19 12:05:18 2014 +0000
+++ b/stage1_2/iec_flex.ll	Wed Mar 19 12:13:43 2014 +0000
@@ -1780,7 +1780,7 @@
 /* Tracking Functions... */
 /*************************/
 
-#define MAX_LINE_LENGTH 1000
+#define MAX_LINE_LENGTH 1024
 
 tracking_t *GetNewTracking(FILE* in_file) {
   tracking_t* new_env = new tracking_t;
@@ -1821,8 +1821,12 @@
       return 0;
     }
     
-    current_tracking->lineNumber++;
     current_tracking->lineLength = strlen(current_tracking->buffer);
+    
+    /* only increment line number if the buffer was big enough to read the whole line! */
+    char last_char = current_tracking->buffer[current_tracking->lineLength - 1];
+    if (('\n' == last_char) || ('\r' == last_char))  // '\r' ---> CR, '\n'  ---> LF
+      current_tracking->lineNumber++;
   }
   
   b[0] = current_tracking->buffer[current_tracking->currentChar];