X-Git-Url: https://git.sesse.net/?p=pgn-extract;a=blobdiff_plain;f=grammar.c;h=73bad6b563dd58cc4ca09b8649c89ba9ccf01884;hp=0d708de6735b41872aaf85974868b271327c01be;hb=HEAD;hpb=4e0c88b473dffdefb830e6806c3692aab6b4fa0c diff --git a/grammar.c b/grammar.c index 0d708de..73bad6b 100644 --- a/grammar.c +++ b/grammar.c @@ -48,6 +48,9 @@ static TokenType current_symbol = NO_TOKEN; */ static unsigned RAV_level = 0; +/* At what file position the current game started. */ +static long game_start_position = -1; + /* Retain details of the header of a game. * This comprises the Tags and any comment prefixing the * moves of the game. @@ -80,7 +83,7 @@ static void check_result(char **Tags,const char *terminating_result); static void free_comment_list(CommentList *comment_list); static void DealWithEcoLine(Move *move_list); static void DealWithGame(Move *move_list); -static Boolean finished_processing(void); +static Boolean finished_processing(SourceFileType file_type); /* Initialise the game header structure to contain * space for the default number of tags. @@ -233,17 +236,18 @@ select_output_file(StateInfo *GameState,const char *eco) * Conditions for finishing processing, other than all the input * having been processed. */ -static Boolean finished_processing(void) +static Boolean finished_processing(SourceFileType file_type) { - return (GlobalState.matching_game_number > 0 && - GlobalState.num_games_matched == GlobalState.matching_game_number); + return ((file_type != ECOFILE && at_end_of_input()) || + (GlobalState.matching_game_number > 0 && + GlobalState.num_games_matched == GlobalState.matching_game_number)); } static void ParseOptGameList(SourceFileType file_type) { Move *move_list = NULL; - while(ParseGame(&move_list) && !finished_processing()){ + while(ParseGame(&move_list) && !finished_processing(file_type)){ if(file_type == NORMALFILE){ DealWithGame(move_list); } @@ -267,6 +271,10 @@ ParseOptGameList(SourceFileType file_type) move_list = NULL; setup_for_new_game(); } + if(file_type == ECOFILE && GlobalState.dump_eco) { + dumpEcoTable(); + exit(0); + } } /* Parse a game and return a pointer to any valid list of moves @@ -651,6 +659,7 @@ setup_for_new_game(void) { restart_lex_for_new_game(); RAV_level = 0; + game_start_position = get_position(); } /* Discard any data held in the GameHeader.Tags structure. */ @@ -734,6 +743,9 @@ free_move_list(Move *move_list) if(next->epd != NULL){ (void) free((void *)next->epd); } + if(next->bpfen != NULL){ + (void) free((void *)next->bpfen); + } if(next->terminating_result != NULL){ (void) free((void *)next->terminating_result); } @@ -815,6 +827,8 @@ DealWithGame(Move *move_list) current_game.moves_checked = FALSE; current_game.moves_ok = FALSE; current_game.error_ply = 0; + current_game.file_number = GlobalState.current_file_number; + current_game.start_position = game_start_position; /* Determine whether or not this game is wanted, on the * basis of the various selection criteria available. @@ -985,6 +999,11 @@ DealWithEcoLine(Move *move_list) int yyparse(SourceFileType file_type) { + if(file_type != ECOFILE) { + if(!seek_to_begin()) { + return 1; + } + } setup_for_new_game(); current_symbol = skip_to_next_game(NO_TOKEN); ParseOptGameList(file_type); @@ -992,7 +1011,7 @@ yyparse(SourceFileType file_type) /* Ok -- EOF. */ return 0; } - else if(finished_processing()) { + else if(finished_processing(file_type)) { /* Ok -- done all we need to. */ return 0; }