]> git.sesse.net Git - pgn-extract/blobdiff - grammar.c
Support scanning only a range of the file.
[pgn-extract] / grammar.c
index ab2278381a8c3250bd0c64a4143d134aa4128ff6..133947ec0ef2a8670d412458dd3fe85f5dcdb31e 100644 (file)
--- a/grammar.c
+++ b/grammar.c
@@ -83,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.
@@ -236,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);
         }
@@ -997,6 +998,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);
@@ -1004,7 +1010,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;
     }