Improve variant recognition for enabling buttons (XB)
authorH.G.Muller <hgm@hgm-xboard.(none)>
Sun, 7 Feb 2016 21:48:34 +0000 (22:48 +0100)
committerH.G.Muller <hgm@hgm-xboard.(none)>
Sun, 7 Feb 2016 21:48:34 +0000 (22:48 +0100)
Buttons for variants were enabled when the name of the variant they
selected was a sub-string of waht the engine could play, so that
Grand Chess (variant grand) would be enabled by Fairy-Max' grande-acedrex.
Now we test if the matched sub-string of the engine's variants feature
is immediately followed by a comma (or at the end).

gtk/xoptions.c
xaw/xoptions.c

index 3df99a7..5880751 100644 (file)
@@ -1457,10 +1457,12 @@ if(appData.debugMode) printf("n=%d, h=%d, w=%d\n",n,height,width);
             /* set button color on new variant dialog */
             if(option[i].textValue) {
                 static char *b = "Bold";
             /* set button color on new variant dialog */
             if(option[i].textValue) {
                 static char *b = "Bold";
+                char *v, *p = NULL, n = option[i].value;
+                if(n >= 0) v = VariantName(n), p = strstr(first.variants, v);
                 gdk_color_parse( option[i].textValue, &color );
                 gtk_widget_modify_bg ( GTK_WIDGET(button), GTK_STATE_NORMAL, &color );
                 gtk_widget_set_sensitive(button, option[i].value >= 0 && (appData.noChessProgram
                 gdk_color_parse( option[i].textValue, &color );
                 gtk_widget_modify_bg ( GTK_WIDGET(button), GTK_STATE_NORMAL, &color );
                 gtk_widget_set_sensitive(button, option[i].value >= 0 && (appData.noChessProgram
-                                        || strstr(first.variants, VariantName(option[i].value))));
+                                        || p && (!*v || strlen(p) == strlen(v) || p[strlen(v)] == ',')));
                 if(engineVariant[100] ? !strcmp(engineVariant+100, option[i].name) : 
                    gameInfo.variant ? option[i].value == gameInfo.variant : !strcmp(option[i].name, "Normal"))
                     SetWidgetFont(gtk_bin_get_child(GTK_BIN(button)), &b);
                 if(engineVariant[100] ? !strcmp(engineVariant+100, option[i].name) : 
                    gameInfo.variant ? option[i].value == gameInfo.variant : !strcmp(option[i].name, "Normal"))
                     SetWidgetFont(gtk_bin_get_child(GTK_BIN(button)), &b);
index 1809743..153ca43 100644 (file)
@@ -1136,8 +1136,10 @@ GenericPopUp (Option *option, char *title, DialogClass dlgNr, DialogClass parent
                                   option[i].max /* w */, shrink ? textHeight : 0 /* h */, option[i].min & 0xE | chain /* chain */);
            XtSetArg(args[j], XtNlabel, _(option[i].name));  j++;
            if(option[i].textValue && *option[i].textValue == '#') { // special for buttons of New Variant dialog
                                   option[i].max /* w */, shrink ? textHeight : 0 /* h */, option[i].min & 0xE | chain /* chain */);
            XtSetArg(args[j], XtNlabel, _(option[i].name));  j++;
            if(option[i].textValue && *option[i].textValue == '#') { // special for buttons of New Variant dialog
+               char *p, *v, n = option[i].value;
+               if(n) v = VariantName(n), p = strstr(first.variants, v);
                XtSetArg(args[j], XtNsensitive, option[i].value >= 0 && (appData.noChessProgram
                XtSetArg(args[j], XtNsensitive, option[i].value >= 0 && (appData.noChessProgram
-                                        || strstr(first.variants, VariantName(option[i].value)))); j++;
+                                        || p && (!*v || strlen(p) == strlen(v) || p[strlen(v)] == ','))); j++;
                XtSetArg(args[j], XtNborderWidth, (gameInfo.variant == option[i].value)+1); j++;
            }
            option[i].handle = (void*)
                XtSetArg(args[j], XtNborderWidth, (gameInfo.variant == option[i].value)+1); j++;
            }
            option[i].handle = (void*)