]> git.sesse.net Git - pgn-extract/blobdiff - lex.c
Support scanning only a range of the file.
[pgn-extract] / lex.c
diff --git a/lex.c b/lex.c
index 0c8d26f192148e54c1ea5ac32f54587dc29dbfbc..23d61316d428c39c54d4b88e9fcb73c54b2b277d 100644 (file)
--- a/lex.c
+++ b/lex.c
@@ -23,6 +23,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <limits.h>
 #include <ctype.h>
 #if defined(__BORLANDC__) || defined(_MSC_VER)
 #include <io.h>
@@ -1101,6 +1102,37 @@ open_input(const char *infile)
     return yyin != NULL;
 }
 
+Boolean
+seek_to_begin(void)
+{
+    if(GlobalState.start_position <= 0) {
+        return TRUE;
+    }
+    if(fseek(yyin, GlobalState.start_position, SEEK_SET) != 0) {
+        fprintf(GlobalState.logfile,"Cannot seek to position %ld in %s\n",
+                GlobalState.start_position,
+                GlobalState.current_input_file);
+        return FALSE;
+    }
+    return TRUE;
+}
+
+Boolean
+at_end_of_input(void)
+{
+    long pos;
+    if(GlobalState.end_position >= LONG_MAX) {
+        return FALSE;
+    }
+    pos = ftell(yyin); 
+    if(pos == -1) {
+        fprintf(GlobalState.logfile,"Cannot find position in %s\n",
+                GlobalState.current_input_file); 
+        return TRUE;
+    }
+    return pos >= GlobalState.end_position;
+}
+
         /* Simple interface to open_input for the ECO file. */
 Boolean
 open_eco_file(const char *eco_file)