Track of line number correctly when input file has code with very long lines.
--- 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];