X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=lex.c;h=23d61316d428c39c54d4b88e9fcb73c54b2b277d;hb=be3167c9e0220a4ee3e8b5c5f813fb2627d1ce55;hp=2b1b60fea25bc850c00d88b9355173be0b678a10;hpb=4e0c88b473dffdefb830e6806c3692aab6b4fa0c;p=pgn-extract diff --git a/lex.c b/lex.c index 2b1b60f..23d6131 100644 --- a/lex.c +++ b/lex.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #if defined(__BORLANDC__) || defined(_MSC_VER) #include @@ -332,7 +333,7 @@ gather_string(char *line, unsigned char *linep) if(!GlobalState.skipping_current_game) { fprintf(GlobalState.logfile,"Missing closing quote in %s\n",line); } - if(len != 1){ + if(len > 1){ /* Move back to the null. */ linep--; str[len-1] = '\0'; @@ -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) @@ -1268,3 +1300,8 @@ terminate_input(void) } } + /* Return the position in the current file. Returns -1 if it is unseekable. */ +long get_position(void) +{ + return ftell(yyin); +}