]> git.sesse.net Git - pgn-extract/commitdiff
Add code to dump out the ECO names by hash.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 11 Dec 2014 00:13:04 +0000 (01:13 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 12 Dec 2014 21:56:56 +0000 (22:56 +0100)
argsfile.c
eco.c
eco.h
grammar.c
main.c
output.c
typedef.h

index 82be49ef3749b174b5e62870459b7a50d270c38a..e2caa076645d738b20e8c7158f29d051e7822dd3 100644 (file)
@@ -176,6 +176,7 @@ usage_and_exit(void)
       "--append - see -a",
       "--checkfile - see -c",
       "--checkmate - see -M",
+      "--dumpeco - dump a list of all ECO hashes with names, then quit",
       "--duplicates - see -d",
       "--evaluation - include a position evaluation after each move",
       "--fencomments - include a FEN string after each move",
@@ -908,6 +909,10 @@ process_long_form_argument(const char *argument, const char *associated_value)
         process_argument(MATCH_CHECKMATE_ARGUMENT, "");
         return 1;
     }
+    else if(stringcompare(argument, "dumpeco") == 0) {
+        GlobalState.dump_eco = TRUE;
+        return 1;
+    }
     else if(stringcompare(argument, "duplicates") == 0) {
         process_argument(DUPLICATES_FILE_ARGUMENT, associated_value);
         return 2;
diff --git a/eco.c b/eco.c
index 6a0d9201a3e33b7f43b68fc94a2d7723bcdf1669..3d5bbca3361897fc963a72f38f60111da0e037d4 100644 (file)
--- a/eco.c
+++ b/eco.c
@@ -53,23 +53,24 @@ static unsigned maximum_half_moves = ECO_HALF_MOVE_LIMIT;
 #define ECO_TABLE_SIZE 4096
 static EcoLog **EcoTable;
 
-#if INCLUDE_UNUSED_FUNCTIONS
-static void
+void
 dumpEcoTable(void)
 {   unsigned ix;
     for(ix = 0; ix < ECO_TABLE_SIZE; ix++){
         if(EcoTable[ix] != NULL){
             EcoLog *entry = NULL;
             for(entry = EcoTable[ix]; entry != NULL; entry = entry->next){
-                fprintf(stderr,"%s %lu %lu ",entry->ECO_tag,
-                                entry->required_hash_value,
-                                entry->cumulative_hash_value);
+                printf("%u\t", (unsigned int)(entry->cumulative_hash_value));
+                printf("%s\t", entry->ECO_tag ? entry->ECO_tag : "");
+                printf("%s\t", entry->Opening_tag ? entry->Opening_tag : "");
+                printf("%s\t", entry->Variation_tag ? entry->Variation_tag : "");
+                printf("%s\n", entry->Sub_Variation_tag ? entry->Sub_Variation_tag : "");
             }
-            fprintf(stderr,"\n");
         }
     }
 }
 
+#if INCLUDE_UNUSED_FUNCTIONS
         /* Return at how many points this match works.
          *        required_hash_value
          *            cumulative_hash_value
diff --git a/eco.h b/eco.h
index 54afb0b06494224fc791d6d0ec0979a6d73d5700..218e0170c9cf23760784a8840eda65424cc616f5 100644 (file)
--- a/eco.h
+++ b/eco.h
@@ -38,6 +38,7 @@ typedef struct EcoLog {
     struct EcoLog *next;
 } EcoLog;
 
+void dumpEcoTable(void);
 EcoLog *eco_matches(HashCode current_hash_value, HashCode cumulative_hash_value,
                     unsigned half_moves_played);
 Boolean add_ECO(Game game_details);
index 1d792a4a645f68a0897a1f5289826dcb2584a6dc..85540c17f7a065c338dc574a8cf239c56eff844f 100644 (file)
--- a/grammar.c
+++ b/grammar.c
@@ -267,6 +267,10 @@ ParseOptGameList(SourceFileType file_type)
         move_list = NULL;
         setup_for_new_game();
     }
+    if(file_type == ECOFILE && GlobalState.dump_eco) {
+        dumpEcoTable();
+        exit(0);
+    }
 }
 
         /* Parse a game and return a pointer to any valid list of moves
diff --git a/main.c b/main.c
index 5439f117db42d4a9b42ee2ffe18267da3fa6d573..218793a0f7005bf5d352faa0ed85c7d80b4fb058 100644 (file)
--- a/main.c
+++ b/main.c
@@ -102,6 +102,7 @@ StateInfo GlobalState = {
     FALSE,                /* add_position_match_comments (--markmatches) */
     FALSE,                /* output_total_plycount (--totalplycount) */
     FALSE,                /* add_hashcode_tag (--addhashcode) */
+    FALSE,                /* dump-eco (--dumpeco) */
     "MATCH",             /* position_match_comment (--markpositionmatches) */
     (char *)NULL,         /* current_input_file */
     NORMALFILE,           /* current_file_type */
index 297cf8b37b3e107e6922cf1256b296c51e390893..8a95f2a2540fb4a53dc2a1583a0819c20d9aa5e7 100644 (file)
--- a/output.c
+++ b/output.c
@@ -1206,7 +1206,7 @@ output_sesse_bin_game(Game current_game,FILE *outputfile,
     int black_elo = atoi(black_elo_tag);
 
     for (move = current_game.moves; move != NULL; move = move->next) {
-        unsigned int opening = move->eco ? move->eco->cumulative_hash_value : 0;
+        unsigned int opening = move->eco ? move->eco->cumulative_hash_value : 0;  // Truncate to 32 bits.
 
         // key
         putc(move->bpfen_len + strlen((char *)move->move), outputfile);
index df0d81dfd18ad60314e54995b403dcff0f8b17e2..2f79308c7426d62d18d5729d6f80e6c29634f0d9 100644 (file)
--- a/typedef.h
+++ b/typedef.h
@@ -267,6 +267,8 @@ typedef struct {
     Boolean output_total_plycount;
     /* Whether to add a HashCode tag. */
     Boolean add_hashcode_tag;
+    /* Whether to dump ECO data to stdout after loading.*/
+    Boolean dump_eco;
     /* The comment to use for position matches, if required. */
     const char *position_match_comment;
     /* Current input file name. */