Fix variant-name recognition
authorH.G.Muller <hgm@hgm-xboard.(none)>
Tue, 21 Oct 2014 20:07:09 +0000 (22:07 +0200)
committerH.G.Muller <hgm@hgm-xboard.(none)>
Tue, 21 Oct 2014 20:07:09 +0000 (22:07 +0200)
StringToVariant did recognize whether the name to recognize had suffuxes
compared to the tabulated name, but not if it had prefixes. So 'shoshogi'
would be recognized as 'shogi'.

backend.c

index bab4386..4cc497f 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -2108,14 +2108,14 @@ StringToVariant (char *e)
     int wnum = -1;
     VariantClass v = VariantNormal;
     int i, found = FALSE;
-    char buf[MSG_SIZ];
+    char buf[MSG_SIZ], c;
     int len;
 
     if (!e) return v;
 
     /* [HGM] skip over optional board-size prefixes */
-    if( sscanf(e, "%dx%d_", &i, &i) == 2 ||
-        sscanf(e, "%dx%d+%d_", &i, &i, &i) == 3 ) {
+    if( sscanf(e, "%dx%d_%c", &i, &i, &c) == 3 ||
+        sscanf(e, "%dx%d+%d_%c", &i, &i, &i, &c) == 4 ) {
         while( *e++ != '_');
     }
 
@@ -2125,7 +2125,7 @@ StringToVariant (char *e)
     } else
     for (i=0; i<sizeof(variantNames)/sizeof(char*); i++) {
       if (p = StrCaseStr(e, variantNames[i])) {
-       if(p && i >= VariantShogi && isalpha(p[strlen(variantNames[i])])) continue;
+       if(p && i >= VariantShogi && (p != e || isalpha(p[strlen(variantNames[i])]))) continue;
        v = (VariantClass) i;
        found = TRUE;
        break;