Remove spaces from USI option names
authorFabian Fichter <ianfab@users.noreply.github.com>
Thu, 14 Jan 2021 19:35:59 +0000 (20:35 +0100)
committerFabian Fichter <ianfab@users.noreply.github.com>
Thu, 14 Jan 2021 19:35:59 +0000 (20:35 +0100)
USI does not allow spaces in option names:
http://hgm.nubati.net/usi.html

Some GUIs seem to rely on that and do not display options containing
spaces, so spaces in option names are now replaced by underscores.

Closes #237.

src/uci.cpp
src/ucioption.cpp

index 6580e4d..2b0c6a4 100644 (file)
@@ -112,7 +112,9 @@ namespace {
 
     if (Options.count(name))
         Options[name] = value;
-    else if (Options["Protocol"] == "ucci" && (std::replace(name.begin(), name.end(), '_', ' '), Options.count(name)))
+    // UCI dialects do not allow spaces
+    else if (   (Options["Protocol"] == "ucci" || Options["Protocol"] == "usi")
+             && (std::replace(name.begin(), name.end(), '_', ' '), Options.count(name)))
         Options[name] = value;
     else
         sync_cout << "No such option: " << name << sync_endl;
index 21473cc..4a7820a 100644 (file)
@@ -232,11 +232,13 @@ std::ostream& operator<<(std::ostream& os, const OptionsMap& om) {
           if (it.second.idx == idx)
           {
               const Option& o = it.second;
-              if (Options["Protocol"] == "ucci")
+              // UCI dialects do not allow spaces
+              if (Options["Protocol"] == "ucci" || Options["Protocol"] == "usi")
               {
                   string name = it.first;
                   std::replace(name.begin(), name.end(), ' ', '_');
-                  os << "\noption " <<  name << " type " << o.type;
+                  // UCCI skips "name"
+                  os << "\noption " << (Options["Protocol"] == "ucci" ? "" : "name ") << name << " type " << o.type;
               }
               else
                   os << "\noption name " << it.first << " type " << o.type;