From: Steinar H. Gunderson Date: Sat, 13 Dec 2014 00:49:03 +0000 (+0100) Subject: Store the current file number (with offset) in the binary output. X-Git-Url: https://git.sesse.net/?p=pgn-extract;a=commitdiff_plain;h=ff5dcab7f4204ec4e2a764fc1d71ac7189418e48 Store the current file number (with offset) in the binary output. --- diff --git a/argsfile.c b/argsfile.c index 7bba901..62146f6 100644 --- a/argsfile.c +++ b/argsfile.c @@ -1086,6 +1086,10 @@ process_long_form_argument(const char *argument, const char *associated_value) GlobalState.end_position = atol(associated_value); return 2; } + else if(stringcompare(argument, "startfilenum") == 0) { + GlobalState.start_file_number = atoi(associated_value); + return 2; + } else if(stringcompare(argument, "version") == 0) { fprintf(GlobalState.logfile, "pgn-extract %s\n", CURRENT_VERSION); exit(0); diff --git a/grammar.c b/grammar.c index 133947e..73bad6b 100644 --- a/grammar.c +++ b/grammar.c @@ -827,6 +827,7 @@ 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 diff --git a/lex.c b/lex.c index 23d6131..36a06a6 100644 --- a/lex.c +++ b/lex.c @@ -1149,6 +1149,7 @@ open_input_file(int file_number) */ if(open_input(list_of_files.files[file_number])){ GlobalState.current_file_type = list_of_files.file_type[file_number]; + GlobalState.current_file_number = file_number + GlobalState.start_file_number; return TRUE; } else{ diff --git a/main.c b/main.c index ec4df57..eb25da5 100644 --- a/main.c +++ b/main.c @@ -107,6 +107,8 @@ StateInfo GlobalState = { "MATCH", /* position_match_comment (--markpositionmatches) */ (char *)NULL, /* current_input_file */ NORMALFILE, /* current_file_type */ + -1, /* current_file_number */ + 0, /* start_file_number */ 0, /* start_position */ LONG_MAX, /* end_position */ DEFAULT_ECO_FILE, /* eco_file (-e) */ diff --git a/output.c b/output.c index 9ba84c1..83054d4 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); + int file_num = current_game.file_number; long start_position = current_game.start_position; // Parse date and time, if it exists. Set invalid dates to year 3000. @@ -1242,6 +1243,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(&file_num, sizeof(file_num), 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 cf7be10..ed7a82d 100644 --- a/typedef.h +++ b/typedef.h @@ -146,6 +146,8 @@ typedef struct { * 0 => no error found. */ int error_ply; + /* File number this game comes from. */ + int file_number; /* File position of the first byte of the game, or -1 * if unknown. */ @@ -279,6 +281,9 @@ typedef struct { const char *current_input_file; /* Whether this is a CHECKFILE or a NORMALFILE. */ SourceFileType current_file_type; + /* Current file number. Used to disambiguate PGN file positions. */ + int current_file_number; + int start_file_number; /* Byte positions to scan to and from in the PGN file. * Starting in the middle of a game will yield unexpected * results.