From 1aa783e32d58973e88f5d77aaf3d8f667b868339 Mon Sep 17 00:00:00 2001 From: Fabian Fichter Date: Mon, 27 Sep 2021 23:15:48 +0200 Subject: [PATCH] Support spaces in variants.ini path * Allow whitespace characters in `load` command. * Support loading of multiple files separated by `:`/`;`. Closes #361. --- src/evaluate.cpp | 7 +------ src/uci.cpp | 14 +++++++++----- src/uci.h | 6 ++++++ src/ucioption.cpp | 10 +++++++++- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/evaluate.cpp b/src/evaluate.cpp index a9af47f..2b44d33 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -87,12 +87,7 @@ namespace Eval { stringstream ss(eval_file); string variant = string(Options["UCI_Variant"]); useNNUE = false; -#ifndef _WIN32 - constexpr char SepChar = ':'; -#else - constexpr char SepChar = ';'; -#endif - while (getline(ss, eval_file, SepChar)) + while (getline(ss, eval_file, UCI::SepChar)) { string basename = eval_file.substr(eval_file.find_last_of("\\/") + 1); string nnueAlias = variants.find(variant)->second->nnueAlias; diff --git a/src/uci.cpp b/src/uci.cpp index ef6a6cf..6f3564d 100644 --- a/src/uci.cpp +++ b/src/uci.cpp @@ -248,18 +248,22 @@ namespace { void load(istringstream& is) { string token; - while (is >> token) - Options["VariantPath"] = token; + std::getline(is >> std::ws, token); + std::size_t end = token.find_last_not_of(' '); + if (end != std::string::npos) + Options["VariantPath"] = token.erase(end + 1); } // check() is called when engine receives the "check" command. - // The function reads variant configuration files and validates them. + // The function reads a variant configuration file and validates it. void check(istringstream& is) { string token; - while (is >> token) - variants.parse(token); + std::getline(is >> std::ws, token); + std::size_t end = token.find_last_not_of(' '); + if (end != std::string::npos) + variants.parse(token.erase(end + 1)); } } // namespace diff --git a/src/uci.h b/src/uci.h index 133f88f..004cd69 100644 --- a/src/uci.h +++ b/src/uci.h @@ -33,6 +33,12 @@ class Position; namespace UCI { +#ifndef _WIN32 + constexpr char SepChar = ':'; +#else + constexpr char SepChar = ';'; +#endif + void init_variant(const Variant* v); class Option; diff --git a/src/ucioption.cpp b/src/ucioption.cpp index 8618bb8..b1ceb8c 100644 --- a/src/ucioption.cpp +++ b/src/ucioption.cpp @@ -66,7 +66,15 @@ void on_tb_path(const Option& o) { Tablebases::init(o); } void on_use_NNUE(const Option& ) { Eval::NNUE::init(); } void on_eval_file(const Option& ) { Eval::NNUE::init(); } -void on_variant_path(const Option& o) { variants.parse(o); Options["UCI_Variant"].set_combo(variants.get_keys()); } +void on_variant_path(const Option& o) { + std::stringstream ss((std::string)o); + std::string path; + + while (std::getline(ss, path, SepChar)) + variants.parse(path); + + Options["UCI_Variant"].set_combo(variants.get_keys()); +} void on_variant_set(const Option &o) { // Re-initialize NNUE Eval::NNUE::init(); -- 1.7.0.4