From: H.G.Muller Date: Wed, 19 Nov 2025 20:40:37 +0000 (+0100) Subject: Improve variant recognition from PGN Event tag X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=refs%2Fheads%2Fv4.9.x;p=xboard.git Improve variant recognition from PGN Event tag Before the Variant tag was invented XBoard extracted the variant name from the Event tag, and ICS still use this method. The recognition was too liberal, though, as any occurence of w or wild followed by a number would be taken as an ICS 'wild' variant. Now we check at least whether the suspected variant name is not part of a larger word: it must be preceded by a space, or be at the start of the tag's value string. This is also applied to strings that indicate FRC. --- diff --git a/backend.c b/backend.c index 36bdf2d..6432f8d 100644 --- a/backend.c +++ b/backend.c @@ -2139,6 +2139,14 @@ VariantName (VariantClass v) return variantNames[v]; } +char * +SpaceStrCaseStr(char *e, char *name) +{ + char *p = StrCaseStr(e, name); + if(!p) return NULL; + if(p == e || p[-1] == ' ') return p; + return NULL; +} /* Identify a variant from the strings the chess servers use or the PGN Variant tag names we use. */ @@ -2174,12 +2182,12 @@ StringToVariant (char *e) } if (!found) { - if ((StrCaseStr(e, "fischer") && StrCaseStr(e, "random")) - || StrCaseStr(e, "wild/fr") - || StrCaseStr(e, "frc") || StrCaseStr(e, "960")) { + if ((SpaceStrCaseStr(e, "fischer") && StrCaseStr(e, "random")) + || SpaceStrCaseStr(e, "wild/fr") + || SpaceStrCaseStr(e, "frc") || SpaceStrCaseStr(e, "960") || SpaceStrCaseStr(e, "chess960")) { v = VariantFischeRandom; - } else if ((i = 4, p = StrCaseStr(e, "wild")) || - (i = 1, p = StrCaseStr(e, "w"))) { + } else if ((i = 4, p = SpaceStrCaseStr(e, "wild")) || + (i = 1, p = SpaceStrCaseStr(e, "w"))) { p += i; while (*p && (isspace(*p) || *p == '(' || *p == '/')) p++; if (isdigit(*p)) {