From 24340f183eef0351ac9b6cfc0aa3d9c1672893b6 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Fri, 12 Dec 2014 22:53:53 +0100 Subject: [PATCH] Store start position in the binary output. --- grammar.c | 5 +++++ lex.c | 5 +++++ lex.h | 1 + output.c | 2 ++ typedef.h | 4 ++++ 5 files changed, 17 insertions(+) diff --git a/grammar.c b/grammar.c index 85540c1..ab22783 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. @@ -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 3474a15..0c8d26f 100644 --- 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 a86c425..e0cb4dc 100644 --- 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); diff --git a/output.c b/output.c index a17d5b1..9ba84c1 100644 --- 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(×tamp, 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); } diff --git a/typedef.h b/typedef.h index 2f79308..65c93b5 100644 --- 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, -- 2.39.2