Increase max nr of engines to 2000
[xboard.git] / xoptions.c
index 58c9a3b..8b9b644 100644 (file)
@@ -83,6 +83,7 @@ extern char *getenv();
 // [HGM] the following code for makng menu popups was cloned from the FileNamePopUp routines
 
 static Widget previous = NULL;
+extern Pixel timerBackgroundPixel;
 
 void
 SetFocus (Widget w, XtPointer data, XEvent *event, Boolean *b)
@@ -130,7 +131,7 @@ SetWidgetText (Option *opt, char *buf, int n)
     Arg arg;
     XtSetArg(arg, XtNstring, buf);
     XtSetValues(opt->handle, &arg, 1);
-    SetFocus(opt->handle, shells[n], NULL, False);
+    if(n >= 0) SetFocus(opt->handle, shells[n], NULL, False);
 }
 
 void
@@ -253,6 +254,7 @@ int MakeColors P((void));
 void CreateGCs P((int redo));
 void CreateAnyPieces P((void));
 int GenericReadout P((int selected));
+void GenericUpdate P((int selected));
 Widget shells[10];
 Widget marked[10];
 Boolean shellUp[10];
@@ -309,7 +311,7 @@ char *engineName, *engineDir, *engineChoice, *engineLine, *nickName, *params, *t
 Boolean isUCI, hasBook, storeVariant, v1, addToList, useNick;
 extern Option installOptions[], matchOptions[];
 char *engineNr[] = { N_("First Engine"), N_("Second Engine"), NULL };
-char *engineList[100] = {" "}, *engineMnemonic[100] = {""};
+char *engineList[MAXENGINES] = {" "}, *engineMnemonic[MAXENGINES] = {""};
 
 int
 AppendText (Option *opt, char *s)
@@ -362,6 +364,21 @@ UpgradeParticipant ()
     Substitute(strdup(engineName), False);
 }
 
+void
+CloneTourney ()
+{
+    FILE *f;
+    char *name;
+    GetWidgetText(currentOption, &name);
+    if(name && name[0] && (f = fopen(name, "r")) ) {
+       char *saveSaveFile;
+       saveSaveFile = appData.saveGameFile; appData.saveGameFile = NULL; // this is a persistent option, protect from change
+       ParseArgsFromFile(f);
+       engineName = appData.participants; GenericUpdate(-1);
+       FREE(appData.saveGameFile); appData.saveGameFile = saveSaveFile;
+    } else DisplayError(_("First you must specify an existing tourney file to clone"), 0);
+}
+
 Option matchOptions[] = {
 { 0,  0,          0, NULL, (void*) &tfName, ".trn", NULL, FileName, N_("Tournament file:") },
 { 0,  0,          0, NULL, (void*) &appData.roundSync, "", NULL, CheckBox, N_("Sync after round    (for concurrent playing of a single") },
@@ -382,6 +399,7 @@ Option matchOptions[] = {
 { 0,  0,          0, NULL, (void*) &appData.defNoBook, "", NULL, CheckBox, N_("Disable own engine books by default") },
 { 0,  0,          0, NULL, (void*) &ReplaceParticipant, NULL, NULL, Button, N_("Replace Engine") },
 { 0,  1,          0, NULL, (void*) &UpgradeParticipant, NULL, NULL, Button, N_("Upgrade Engine") },
+{ 0,  1,          0, NULL, (void*) &CloneTourney, NULL, NULL, Button, N_("Clone Tourney") },
 { 0, 1, 0, NULL, (void*) &MatchOK, "", NULL, EndMark , "" }
 };
 
@@ -710,7 +728,7 @@ SetColor (char *colorName, Option *box)
            } else {
                buttonColor = *(Pixel *) vTo.addr;
            }
-       } else buttonColor = (Pixel) 0;
+       } else buttonColor = timerBackgroundPixel;
        XtSetArg(args[0], XtNbackground, buttonColor);;
        XtSetValues(box->handle, args, 1);
 }
@@ -826,6 +844,50 @@ Option boardOptions[] = {
 { 0, 0, 0, NULL, (void*) &BoardOptionsOK, "", NULL, EndMark , "" }
 };
 
+void
+GenericUpdate (int selected)
+{
+    int i, j;
+    char buf[MSG_SIZ];
+    float x;
+       for(i=0; ; i++) {
+           if(selected >= 0) { if(i < selected) continue; else if(i > selected) break; }
+           switch(currentOption[i].type) {
+               case TextBox:
+               case FileName:
+               case PathName:
+                   SetWidgetText(&currentOption[i],  *(char**) currentOption[i].target, -1);
+                   break;
+               case Spin:
+                   sprintf(buf, "%d", *(int*) currentOption[i].target);
+                   SetWidgetText(&currentOption[i], buf, -1);
+                   break;
+               case Fractional:
+                   sprintf(buf, "%4.2f", *(float*) currentOption[i].target);
+                   SetWidgetText(&currentOption[i], buf, -1);
+                   break;
+               case CheckBox:
+                   SetWidgetState(&currentOption[i],  *(Boolean*) currentOption[i].target);
+                   break;
+               case ComboBox:
+                   for(j=0; currentOption[i].choice[j]; j++)
+                       if(*(char**)currentOption[i].target && !strcmp(*(char**)currentOption[i].target, currentOption[i].choice[j])) break;
+                   values[i] = currentOption[i].value = j + (currentOption[i].choice[j] == NULL);
+                   // TODO: actually display this
+                   break;
+               case EndMark:
+                   return;
+           default:
+               printf("GenericUpdate: unexpected case in switch.\n");
+               case Button:
+               case SaveButton:
+               case Label:
+               case Break:
+             break;
+           }
+       }
+}
+
 int
 GenericReadout (int selected)
 {