From 2941984be26cee5bbb0757ed20172035ed06d2f4 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Thu, 11 Dec 2014 01:13:04 +0100 Subject: [PATCH] Add code to dump out the ECO names by hash. --- argsfile.c | 5 +++++ eco.c | 13 +++++++------ eco.h | 1 + grammar.c | 4 ++++ main.c | 1 + output.c | 2 +- typedef.h | 2 ++ 7 files changed, 21 insertions(+), 7 deletions(-) diff --git a/argsfile.c b/argsfile.c index 82be49e..e2caa07 100644 --- a/argsfile.c +++ b/argsfile.c @@ -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 6a0d920..3d5bbca 100644 --- 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 54afb0b..218e017 100644 --- 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); diff --git a/grammar.c b/grammar.c index 1d792a4..85540c1 100644 --- 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 5439f11..218793a 100644 --- 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 */ diff --git a/output.c b/output.c index 297cf8b..8a95f2a 100644 --- 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); diff --git a/typedef.h b/typedef.h index df0d81d..2f79308 100644 --- 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. */ -- 2.39.2