]> git.sesse.net Git - pgn-extract/commitdiff
Store the current file number (with offset) in the binary output.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 13 Dec 2014 00:49:03 +0000 (01:49 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 13 Dec 2014 00:49:03 +0000 (01:49 +0100)
argsfile.c
grammar.c
lex.c
main.c
output.c
typedef.h

index 7bba9011b6da589af20e3c20285ce8c53646486f..62146f69707006fbf1f2c5b5ad9914d94d5cf23c 100644 (file)
@@ -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);
index 133947ec0ef2a8670d412458dd3fe85f5dcdb31e..73bad6b563dd58cc4ca09b8649c89ba9ccf01884 100644 (file)
--- 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 23d61316d428c39c54d4b88e9fcb73c54b2b277d..36a06a638ed7d1f946688a6c5a045dcc8e73db14 100644 (file)
--- 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 ec4df57cdf0e356223ab6ab49746762a21d87fc9..eb25da5abcc7d48eda11d48125c676d025ee78cb 100644 (file)
--- 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) */
index 9ba84c101cfa51570d18f4a908de6392e5a750e2..83054d418b27e4afb1ff182d6a1f23000fc70182 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);
+    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(&timestamp, 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);
index cf7be10005b34e242eee55463a6c315d63af1aae..ed7a82d47302524ba8cec3bb375d53be5de20cf3 100644 (file)
--- 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.