Make DoSleep front-end wrapper for msec sleep
[xboard.git] / winboard / wsettings.c
index 11de72b..3ceaf34 100644 (file)
@@ -486,6 +486,7 @@ LRESULT CALLBACK SettingsProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPa
                if( activeList[j].type  == SaveButton)\r
                     GetOptionValues(hDlg, activeCps, activeList);\r
                else if( activeList[j].type  != Button) break;\r
+               else if( !activeCps ) { (*(ButtonCallback*) activeList[j].target)(hDlg); break; }\r
                snprintf(buf, MSG_SIZ, "option %s\n", activeList[j].name);\r
                SendToProgram(buf, activeCps);\r
            }\r
@@ -693,10 +694,58 @@ char *tfName;
 int MatchOK()\r
 {\r
     if(autoinc) appData.loadGameIndex = appData.loadPositionIndex = -(twice + 1);\r
+    if(!appData.loadGameFile[0]) appData.loadGameIndex = -2*twice; // kludge to pass value of "twice" for use in GUI book\r
     if(swiss) { appData.defaultMatchGames = 1; appData.tourneyType = -1; }\r
-    if(CreateTourney(tfName)) MatchEvent(2); else return !appData.participants[0];\r
-    return 1;\r
+    if(CreateTourney(tfName) && !matchMode) { // CreateTourney reloads original settings if file already existed\r
+       MatchEvent(2);\r
+       return 1; // close dialog\r
+    }\r
+    return matchMode || !appData.participants[0]; // if we failed to create and are not in playing, forbid popdown if there are participants\r
+}\r
+\r
+char *GetParticipants(HWND hDlg)\r
+{\r
+    int len = GetWindowTextLength(GetDlgItem(hDlg, 2001+2*9)) + 1;\r
+    char *participants,*p, *q;\r
+    if(len < 4) return NULL; // box is empty (enough)\r
+    participants = (char*) malloc(len);\r
+    GetDlgItemText(hDlg, 2001+2*9, participants, len );\r
+    p = q = participants;\r
+    while(*p++ = *q++) if(p[-1] == '\r') p--;\r
+    return participants;\r
+}\r
+\r
+void ReplaceParticipant(HWND hDlg)\r
+{\r
+    char *participants = GetParticipants(hDlg);\r
+    Substitute(participants, TRUE);\r
 }\r
+       \r
+void UpgradeParticipant(HWND hDlg)\r
+{\r
+    char *participants = GetParticipants(hDlg);\r
+    Substitute(participants, FALSE);\r
+}\r
+\r
+void Inspect(HWND hDlg)\r
+{\r
+    FILE *f;\r
+    char name[MSG_SIZ];\r
+    GetDlgItemText(hDlg, 2001+2*1, name, MSG_SIZ );\r
+    if(name && name[0] && (f = fopen(name, "r")) ) {\r
+       char *saveSaveFile;\r
+       saveSaveFile = appData.saveGameFile; appData.saveGameFile = NULL; // this is a persistent option, protect from change\r
+       ParseArgsFromFile(f);\r
+       autoinc = ((appData.loadPositionFile[0] ? appData.loadGameIndex : appData.loadPositionIndex) < 0);\r
+       twice = ((appData.loadPositionFile[0] ? appData.loadGameIndex : appData.loadPositionIndex) == -2);\r
+       swiss = appData.tourneyType < 0;\r
+       SetOptionValues(hDlg, NULL, activeList);\r
+       FREE(appData.saveGameFile); appData.saveGameFile = saveSaveFile;\r
+    }\r
+}\r
+\r
+void TimeControlOptionsPopup P((HWND hDlg));\r
+void UciOptionsPopup P((HWND hDlg));\r
 \r
 Option tourneyOptions[] = {\r
   { 0,  0,          4, NULL, (void*) &tfName, "", NULL, FileName, N_("Tournament file:") },\r
@@ -719,6 +768,11 @@ Option tourneyOptions[] = {
   { 0,  0, 1000000000, NULL, (void*) &appData.rewindIndex, "", NULL, Spin, N_("Rewind after (0 = never):") },\r
   { 0,  0,          0, NULL, (void*) &twice, "", NULL, CheckBox, N_("Use each line/position twice") },\r
   { 0,  0, 1000000000, NULL, (void*) &appData.matchPause, "", NULL, Spin, N_("Pause between Games (ms):") },\r
+  { 0,  0,          0, NULL, (void*) &ReplaceParticipant, "", NULL, Button, N_("Replace Engine") },\r
+  { 0,  0,          0, NULL, (void*) &UpgradeParticipant, "", NULL, Button, N_("Upgrade Engine") },\r
+  { 0,  0,          0, NULL, (void*) &TimeControlOptionsPopup, "", NULL, Button, N_("Time Control...") },\r
+  { 0,  0,          0, NULL, (void*) &UciOptionsPopup, "", NULL, Button, N_("Common Engine...") },\r
+  { 0,  0,          0, NULL, (void*) &Inspect, "", NULL, Button, N_("Inspect TourneyFile") },\r
   { 0, 0, 0, NULL, (void*) &MatchOK, "", NULL, EndMark , "" }\r
 };\r
 \r
@@ -741,7 +795,7 @@ void TourneyPopup(HWND hwnd)
     NamesToList(firstChessProgramNames, engineList, engineMnemonic);\r
     comboCallback = &AddToTourney;\r
     autoinc = appData.loadGameIndex < 0 || appData.loadPositionIndex < 0;\r
-    twice = TRUE; swiss = appData.tourneyType < 0;\r
+    twice = FALSE; swiss = appData.tourneyType < 0;\r
     while(engineList[n]) n++; tourneyOptions[3].max = n-1;\r
     snprintf(title, MSG_SIZ, _("Tournament and Match Options"));\r
     ASSIGN(tfName, appData.tourneyFile[0] ? appData.tourneyFile : MakeName(appData.defName));\r