]> git.sesse.net Git - pgn-extract/commitdiff
Store start position in the binary output.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 12 Dec 2014 21:53:53 +0000 (22:53 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 12 Dec 2014 21:56:56 +0000 (22:56 +0100)
grammar.c
lex.c
lex.h
output.c
typedef.h

index 85540c17f7a065c338dc574a8cf239c56eff844f..ab2278381a8c3250bd0c64a4143d134aa4128ff6 100644 (file)
--- 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.
@@ -655,6 +658,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. */
@@ -822,6 +826,7 @@ DealWithGame(Move *move_list)
     current_game.moves_checked = FALSE;
     current_game.moves_ok = FALSE;
     current_game.error_ply = 0;
+    current_game.start_position = game_start_position;
   
     /* Determine whether or not this game is wanted, on the
      * basis of the various selection criteria available.
diff --git a/lex.c b/lex.c
index 3474a15523b27055716617a802e651f593f1bf3f..0c8d26f192148e54c1ea5ac32f54587dc29dbfbc 100644 (file)
--- a/lex.c
+++ b/lex.c
@@ -1268,3 +1268,8 @@ terminate_input(void)
     }
 }
 
+    /* Return the position in the current file. Returns -1 if it is unseekable. */
+long get_position(void)
+{
+    return ftell(yyin);
+}
diff --git a/lex.h b/lex.h
index a86c4253deba57f8bbbe7107684e877f253df1cb..e0cb4dc40062471dba964fb98a6f12ac27717695 100644 (file)
--- a/lex.h
+++ b/lex.h
@@ -87,3 +87,4 @@ char *next_input_line(FILE *fp);
 LinePair gather_tag(char *line, unsigned char *linep);
 LinePair gather_string(char *line, unsigned char *linep);
 Boolean is_character_class(unsigned char ch, TokenType character_class);
+long get_position(void);
index a17d5b1653cc54c86cc19728560130676478f222..9ba84c101cfa51570d18f4a908de6392e5a750e2 100644 (file)
--- a/output.c
+++ b/output.c
@@ -1205,6 +1205,7 @@ output_sesse_bin_game(Game current_game,FILE *outputfile,
 
     int white_elo = atoi(white_elo_tag);
     int black_elo = atoi(black_elo_tag);
+    long start_position = current_game.start_position;
 
     // Parse date and time, if it exists. Set invalid dates to year 3000.
     const char *date_tag = current_game.tags[DATE_TAG];
@@ -1241,6 +1242,7 @@ output_sesse_bin_game(Game current_game,FILE *outputfile,
         fwrite(&black_elo, sizeof(black_elo), 1, outputfile);
         fwrite(&opening, sizeof(opening), 1, outputfile);
         fwrite(&timestamp, sizeof(timestamp), 1, outputfile);
+        fwrite(&start_position, sizeof(start_position), 1, outputfile);
         putc(strlen((char *)move->move), outputfile);
         fwrite(move->move, strlen((char *)move->move), 1, outputfile);
     }
index 2f79308c7426d62d18d5729d6f80e6c29634f0d9..65c93b59a1aa26934d4c536005b507f6ff9a7653 100644 (file)
--- a/typedef.h
+++ b/typedef.h
@@ -146,6 +146,10 @@ typedef struct {
      * 0 => no error found.
      */
     int error_ply;
+    /* File position of the first byte of the game, or -1
+     * if unknown.
+     */
+    long start_position;
 } Game;
 
 /* Define a type to distinguish between CHECK files, NORMAL files,