X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=lex.c;h=36a06a638ed7d1f946688a6c5a045dcc8e73db14;hb=HEAD;hp=3474a15523b27055716617a802e651f593f1bf3f;hpb=ac09fe874e77b559d7b6de36d913a8cb064c9210;p=pgn-extract diff --git a/lex.c b/lex.c index 3474a15..36a06a6 100644 --- a/lex.c +++ b/lex.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #if defined(__BORLANDC__) || defined(_MSC_VER) #include @@ -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) @@ -1117,6 +1149,7 @@ open_input_file(int file_number) */ if(open_input(list_of_files.files[file_number])){ GlobalState.current_file_type = list_of_files.file_type[file_number]; + GlobalState.current_file_number = file_number + GlobalState.start_file_number; return TRUE; } else{ @@ -1268,3 +1301,8 @@ terminate_input(void) } } + /* Return the position in the current file. Returns -1 if it is unseekable. */ +long get_position(void) +{ + return ftell(yyin); +}