53d6b163b3ef7ec7af19c0f74e8eaf4248390552
[xboard.git] / winboard / wsettings.c
1 /*\r
2  * Engine-settings dialog. The complexity come from an attempt to present the engine-defined options\r
3  * in a nicey formatted layout. To this end we first run a back-end pre-formatter, which will distribute\r
4  * the controls over two columns (the minimum required, as some are double width). It also takes care of\r
5  * grouping options that start with the same word (mainly for "Polyglot ..." options). It assigns relative\r
6  * suitability to break points between lines, and in the end decides if and where to break up the list\r
7  * for display in multiple (2*N) columns.\r
8  * The thus obtained list representing the topology of the layout is then passed to a front-end routine\r
9  * that generates the actual dialog box from it.\r
10  */\r
11 \r
12 #include "config.h"\r
13 \r
14 #include <windows.h>\r
15 #include <Windowsx.h>\r
16 #include <stdio.h>\r
17 #include <string.h>\r
18 #include "common.h"\r
19 #include "frontend.h"\r
20 #include "backend.h"\r
21 #include "winboard.h"\r
22 #include "backendz.h"\r
23 \r
24 #define _(s) T_(s)\r
25 #define N_(s) s\r
26 \r
27 int layoutList[2*MAX_OPTIONS];\r
28 int checkList[2*MAX_OPTIONS];\r
29 int comboList[2*MAX_OPTIONS];\r
30 int buttonList[2*MAX_OPTIONS];\r
31 int boxList[2*MAX_OPTIONS];\r
32 int groupNameList[2*MAX_OPTIONS];\r
33 int breaks[MAX_OPTIONS];\r
34 int checks, combos, buttons, layout, groups;\r
35 char title[MSG_SIZ];\r
36 char *engineName, *engineDir, *engineChoice, *engineLine, *nickName, *params;\r
37 Boolean isUCI, hasBook, storeVariant, v1, addToList, useNick, isUCCI;\r
38 extern Option installOptions[], matchOptions[];\r
39 char *engineList[MAXENGINES] = {""}, *engineMnemonic[MAXENGINES] = {""};\r
40 void (*okFunc)();\r
41 ChessProgramState *activeCps;\r
42 Option *activeList;\r
43 int InstallOK P((void));\r
44 typedef int ButtonCallback(HWND h);\r
45 ButtonCallback *comboCallback;\r
46 \r
47 void\r
48 PrintOpt(int i, int right, Option *optionList)\r
49 {\r
50     if(i<0) {\r
51         if(!right) fprintf(debugFP, "%30s", "");\r
52     } else {\r
53         Option opt = optionList[i];\r
54         switch(opt.type) {\r
55             case Slider:\r
56             case Spin:\r
57                 fprintf(debugFP, "%20.20s [    +/-]", opt.name);\r
58                 break;\r
59             case TextBox:\r
60             case FileName:\r
61             case PathName:\r
62                 fprintf(debugFP, "%20.20s [______________________________________]", opt.name);\r
63                 break;\r
64             case Label:\r
65                 fprintf(debugFP, "%41.41s", opt.name);\r
66                 break;\r
67             case CheckBox:\r
68                 fprintf(debugFP, "[x] %-26.25s", opt.name);\r
69                 break;\r
70             case ComboBox:\r
71                 fprintf(debugFP, "%20.20s [ COMBO ]", opt.name);\r
72                 break;\r
73             case Button:\r
74             case SaveButton:\r
75             case ResetButton:\r
76                 fprintf(debugFP, "[ %26.26s ]", opt.name);\r
77             case Message:\r
78             default:\r
79                 break;\r
80         }\r
81     }\r
82     fprintf(debugFP, right ? "\n" : " ");\r
83 }\r
84 \r
85 void\r
86 CreateOptionDialogTest(int *list, int nr, Option *optionList)\r
87 {\r
88     int line;\r
89 \r
90     for(line = 0; line < nr; line+=2) {\r
91         PrintOpt(list[line+1], 0, optionList);\r
92         PrintOpt(list[line], 1, optionList);\r
93     }\r
94 }\r
95 \r
96 void\r
97 LayoutOptions(int firstOption, int endOption, char *groupName, Option *optionList)\r
98 {\r
99     int i, b = strlen(groupName), stop, prefix, right, nextOption, firstButton = buttons;\r
100     Control lastType, nextType;\r
101 \r
102     nextOption = firstOption;\r
103     while(nextOption < endOption) {\r
104         checks = combos = 0; stop = 0;\r
105         lastType = Button; // kludge to make sure leading Spin will not be prefixed\r
106         // first separate out buttons for later treatment, and collect consecutive checks and combos\r
107         while(nextOption < endOption && !stop) {\r
108             switch(nextType = optionList[nextOption].type) {\r
109                 case CheckBox: checkList[checks++] = nextOption; lastType = CheckBox; break;\r
110                 case ComboBox: comboList[combos++] = nextOption; lastType = ComboBox; break;\r
111                 case ResetButton:\r
112                 case SaveButton:\r
113                 case Button:  buttonList[buttons++] = nextOption; lastType = Button; break;\r
114                 case TextBox:\r
115                 case ListBox:\r
116                 case FileName:\r
117                 case PathName:\r
118                 case Slider:\r
119                 case Label:\r
120                 case Spin: stop++;\r
121                 default:\r
122                 case Message: ; // cannot happen\r
123             }\r
124             nextOption++;\r
125         }\r
126         // We now must be at the end, or looking at a spin or textbox (in nextType)\r
127         if(!stop)\r
128             nextType = Button; // kudge to flush remaining checks and combos undistorted\r
129         // Take a new line if a spin follows combos or checks, or when we encounter a textbox\r
130         if((combos+checks || nextType == TextBox || nextType == ListBox || nextType == FileName || nextType == PathName || nextType == Label) && layout&1) {\r
131             layoutList[layout++] = -1;\r
132         }\r
133         // The last check or combo before a spin will be put on the same line as that spin (prefix)\r
134         // and will thus not be grouped with other checks and combos\r
135         prefix = -1;\r
136         if(nextType == Spin && lastType != Button) {\r
137             if(lastType == CheckBox) prefix = checkList[--checks]; else\r
138             if(lastType == ComboBox) prefix = comboList[--combos];\r
139         }\r
140         // if a combo is followed by a textbox, it must stay at the end of the combo/checks list to appear\r
141         // immediately above the textbox, so treat it as check. (A check would automatically be and remain there.)\r
142         if((nextType == TextBox || nextType == ListBox || nextType == FileName || nextType == PathName) && lastType == ComboBox)\r
143             checkList[checks++] = comboList[--combos];\r
144         // Now append the checks behind the (remaining) combos to treat them as one group\r
145         for(i=0; i< checks; i++)\r
146             comboList[combos++] = checkList[i];\r
147         // emit the consecutive checks and combos in two columns\r
148         right = combos/2; // rounded down if odd!\r
149         for(i=0; i<right; i++) {\r
150             breaks[layout/2] = 2;\r
151             layoutList[layout++] = comboList[i];\r
152             layoutList[layout++] = comboList[i + right];\r
153         }\r
154         // An odd check or combo (which could belong to following textBox) will be put in the left column\r
155         // If there was an even number of checks and combos the last one will automatically be in that position\r
156         if(combos&1) {\r
157             layoutList[layout++] = -1;\r
158             layoutList[layout++] = comboList[2*right];\r
159         }\r
160         if(nextType == ListBox) {\r
161             // A listBox will be left-adjusted, and cause rearrangement of the elements before it to the right column\r
162             breaks[layout/2] = lastType == Button ? 0 : 100;\r
163             layoutList[layout++] = -1;\r
164             layoutList[layout++] = nextOption - 1;\r
165             for(i=optionList[nextOption-1].min; i>0; i--) { // extra high text edit\r
166                 breaks[layout/2] = -1;\r
167                 layoutList[layout++] = -1;\r
168                 layoutList[layout++] = -1;\r
169             }\r
170         } else \r
171         if(nextType == TextBox || nextType == FileName || nextType == PathName || nextType == Label) {\r
172             // A textBox is double width, so must be left-adjusted, and the right column remains empty\r
173             breaks[layout/2] = lastType == Button ? 0 : 100;\r
174             layoutList[layout++] = -1;\r
175             layoutList[layout++] = nextOption - 1;\r
176             if(optionList[nextOption-1].min) { // extra high text edit: goes right of existing listbox\r
177                 layout -= 2; // remove\r
178                 layoutList[layout-2*optionList[nextOption-1].min-2] = nextOption - 1;\r
179             }\r
180         } else if(nextType == Spin) {\r
181             // A spin will go in the next available position (right to left!). If it had to be prefixed with\r
182             // a check or combo, this next position must be to the right, and the prefix goes left to it.\r
183             layoutList[layout++] = nextOption - 1;\r
184             if(prefix >= 0) layoutList[layout++] = prefix;\r
185         }\r
186     }\r
187     // take a new line if needed\r
188     if(layout&1) layoutList[layout++] = -1;\r
189     // emit the buttons belonging in this group; loose buttons are saved for last, to appear at bottom of dialog\r
190     if(b) {\r
191         while(buttons > firstButton)\r
192             layoutList[layout++] = buttonList[--buttons];\r
193         if(layout&1) layoutList[layout++] = -1;\r
194     }\r
195 }\r
196 \r
197 char *\r
198 EndMatch(char *s1, char *s2)\r
199 {\r
200         char *p, *q;\r
201         p = s1; while(*p) p++;\r
202         q = s2; while(*q) q++;\r
203         while(p > s1 && q > s2 && *p == *q) { p--; q--; }\r
204         if(p[1] == 0) return NULL;\r
205         return p+1;\r
206 }\r
207 \r
208 void\r
209 DesignOptionDialog(int nrOpt, Option *optionList)\r
210 {\r
211     int k=0, n=0;\r
212     char buf[MSG_SIZ];\r
213 \r
214     layout = 0;\r
215     buttons = groups = 0;\r
216     while(k < nrOpt) { // k steps through 'solitary' options\r
217         // look if we hit a group of options having names that start with the same word\r
218         int groupSize = 1, groupNameLength = 50;\r
219         sscanf(optionList[k].name, "%s", buf); // get first word of option name\r
220         while(k + groupSize < nrOpt &&\r
221               strstr(optionList[k+groupSize].name, buf) == optionList[k+groupSize].name) {\r
222                 int j;\r
223                 for(j=0; j<groupNameLength; j++) // determine common initial part of option names\r
224                     if( optionList[k].name[j] != optionList[k+groupSize].name[j]) break;\r
225                 groupNameLength = j;\r
226                 groupSize++;\r
227 \r
228         }\r
229         if(groupSize > 3) {\r
230                 // We found a group to terminates the current section\r
231                 LayoutOptions(n, k, "", optionList); // flush all solitary options appearing before the group\r
232                 groupNameList[groups] = groupNameLength;\r
233                 boxList[groups++] = layout; // group start in even entries\r
234                 LayoutOptions(k, k+groupSize, buf, optionList); // flush the group\r
235                 boxList[groups++] = layout; // group end in odd entries\r
236                 k = n = k + groupSize;\r
237         } else k += groupSize; // small groups are grouped with the solitary options\r
238     }\r
239     if(n != k) LayoutOptions(n, k, "", optionList); // flush remaining solitary options\r
240     // decide if and where we break into two column pairs\r
241 \r
242     // Emit buttons and add OK and cancel\r
243 //    for(k=0; k<buttons; k++) layoutList[layout++] = buttonList[k];\r
244  \r
245    // Create the dialog window\r
246     if(appData.debugMode) CreateOptionDialogTest(layoutList, layout, optionList);\r
247 //    CreateOptionDialog(layoutList, layout, optionList);\r
248     if(!activeCps) okFunc = optionList[nrOpt].target;\r
249 }\r
250 \r
251 #include <windows.h>\r
252 \r
253 extern HINSTANCE hInst;\r
254 \r
255 typedef struct {\r
256     DLGITEMTEMPLATE item;\r
257     WORD code;\r
258     WORD controlType;\r
259     wchar_t d1, data;\r
260     WORD creationData;\r
261 } Item;\r
262 \r
263 struct {\r
264     DLGTEMPLATE header;\r
265     WORD menu;\r
266     WORD winClass;\r
267     wchar_t title[20];\r
268     WORD pointSize;\r
269     wchar_t fontName[14];\r
270     Item control[MAX_OPTIONS];\r
271 } template = {\r
272     { DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU | DS_SETFONT, 0, 0, 0, 0, 295, 300 },\r
273     0x0000, 0x0000, L"Engine #1 Settings ", 8, L"MS Sans Serif"\r
274 };\r
275 \r
276 char *\r
277 AddCR(char *s)\r
278 {\r
279     char *p=s, *q;\r
280     int n=0;\r
281     while(p = strchr(p, '\n')) p++, n++; // count linefeeds\r
282     p = q = malloc(strlen(s) + n + 1);\r
283     while(*p++ = *s++) if(p[-1] == '\n') p[-1] = '\r', *p++ = '\n';\r
284     return q;\r
285 }\r
286 \r
287 void\r
288 SetOptionValues(HWND hDlg, ChessProgramState *cps, Option *optionList)\r
289 // Put all current option values in controls, and write option names next to them\r
290 {\r
291     HANDLE hwndCombo;\r
292     int i, k;\r
293     char **choices, *name;\r
294 \r
295     for(i=0; i<layout+buttons; i++) {\r
296         int j=layoutList[i];\r
297         if(j == -2) SetDlgItemText( hDlg, 2000+2*i, ". . ." );\r
298         if(j<0) continue;\r
299         name = cps ? optionList[j].name : _(optionList[j].name);\r
300         if(strstr(name, "Polyglot ") == name) name += 9;\r
301         SetDlgItemText( hDlg, 2000+2*i, name );\r
302 //if(appData.debugMode) fprintf(debugFP, "# %s = %d\n",optionList[j].name, optionList[j].value );\r
303         switch(optionList[j].type) {\r
304             case Spin:\r
305                 SetDlgItemInt( hDlg, 2001+2*i, cps ? optionList[j].value : *(int*)optionList[j].target, TRUE );\r
306                 break;\r
307             case TextBox:\r
308             case FileName:\r
309             case PathName:\r
310                 name = AddCR(cps ? optionList[j].textValue : *(char**)optionList[j].target); // stupid CR...\r
311                 SetDlgItemText( hDlg, 2001+2*i, name);\r
312                 free(name);\r
313                 break;\r
314             case CheckBox:\r
315                 CheckDlgButton( hDlg, 2000+2*i, (cps ? optionList[j].value : *(Boolean*)optionList[j].target) != 0);\r
316                 break;\r
317             case ComboBox:\r
318                 choices = (char**) optionList[j].textValue;\r
319                 hwndCombo = GetDlgItem(hDlg, 2001+2*i);\r
320                 SendMessage(hwndCombo, CB_RESETCONTENT, 0, 0);\r
321                 for(k=0; k<optionList[j].max; k++) {\r
322                     SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM) choices[k]);\r
323                 }\r
324                 SendMessage(hwndCombo, CB_SELECTSTRING, (WPARAM) -1, (LPARAM) choices[optionList[j].value]);\r
325                 break;\r
326             case ListBox:\r
327                 choices = (char**) optionList[j].choice;\r
328                 hwndCombo = GetDlgItem(hDlg, 2001+2*i);\r
329                 SendMessage(hwndCombo, LB_RESETCONTENT, 0, 0);\r
330                 for(k=0; k<optionList[j].max; k++) {\r
331                     SendMessage(hwndCombo, LB_ADDSTRING, 0, (LPARAM) choices[k]);\r
332                 }\r
333                 break;\r
334             case Button:\r
335             case SaveButton:\r
336             default:\r
337                 break;\r
338         }\r
339     }\r
340     SetDlgItemText( hDlg, IDOK, _("OK") );\r
341     SetDlgItemText( hDlg, IDCANCEL, _("Cancel") );\r
342     title[0] &= ~32; // capitalize\r
343     SetWindowText( hDlg, title);\r
344     for(i=0; i<groups; i+=2) {\r
345         int id, p; char buf[MSG_SIZ];\r
346         id = k = boxList[i];\r
347         if(layoutList[k] < 0) k++;\r
348         if(layoutList[k] < 0) continue;\r
349         for(p=0; p<groupNameList[i]; p++) buf[p] = optionList[layoutList[k]].name[p];\r
350         buf[p] = 0;\r
351         SetDlgItemText( hDlg, 2000+2*(id+MAX_OPTIONS), buf );\r
352     }\r
353 }\r
354 \r
355 \r
356 int\r
357 GetOptionValues(HWND hDlg, ChessProgramState *cps, Option *optionList)\r
358 // read out all controls, and if value is altered, remember it and send it to the engine\r
359 {\r
360     HANDLE hwndCombo;\r
361     int i, k, new=0, changed=0, len;\r
362     char **choices, newText[MSG_SIZ], buf[MSG_SIZ], *text;\r
363     BOOL success;\r
364 \r
365     for(i=0; i<layout; i++) {\r
366         int j=layoutList[i];\r
367         if(j<0) continue;\r
368         switch(optionList[j].type) {\r
369             case Spin:\r
370                 new = GetDlgItemInt( hDlg, 2001+2*i, &success, TRUE );\r
371                 if(!success) break;\r
372                 if(new < optionList[j].min) new = optionList[j].min;\r
373                 if(new > optionList[j].max) new = optionList[j].max;\r
374                 if(!cps) { *(int*)optionList[j].target = new; break; }\r
375                 changed = 2*(optionList[j].value != new);\r
376                 optionList[j].value = new;\r
377                 break;\r
378             case TextBox:\r
379             case FileName:\r
380             case PathName:\r
381                 if(cps) len = MSG_SIZ - strlen(optionList[j].name) - 9, text = newText;\r
382                 else    len = GetWindowTextLength(GetDlgItem(hDlg, 2001+2*i)) + 1, text = (char*) malloc(len);\r
383                 success = GetDlgItemText( hDlg, 2001+2*i, text, len );\r
384                 if(!success) text[0] = NULLCHAR; // empty string can be valid input\r
385                 if(!cps) {\r
386                     char *p;\r
387                     p = (optionList[j].type != FileName ? strdup(text) : InterpretFileName(text, homeDir)); // all files relative to homeDir!\r
388                     FREE(*(char**)optionList[j].target); *(char**)optionList[j].target = p;\r
389                     free(text); text = p;\r
390                     while(*p++ = *text++) if(p[-1] == '\r') p--; // crush CR\r
391                     break;\r
392                 }\r
393                 changed = strcmp(optionList[j].textValue, newText) != 0;\r
394                 safeStrCpy(optionList[j].textValue, newText, MSG_SIZ - (optionList[j].textValue - optionList[j].name) );\r
395                 break;\r
396             case CheckBox:\r
397                 new = IsDlgButtonChecked( hDlg, 2000+2*i );\r
398                 if(!cps) { *(Boolean*)optionList[j].target = new; break; }\r
399                 changed = 2*(optionList[j].value != new);\r
400                 optionList[j].value = new;\r
401                 break;\r
402             case ComboBox:\r
403                 choices = (char**) optionList[j].textValue;\r
404                 hwndCombo = GetDlgItem(hDlg, 2001+2*i);\r
405                 success = GetDlgItemText( hDlg, 2001+2*i, newText, MSG_SIZ );\r
406                 if(!success) break;\r
407                 new = -1;\r
408                 for(k=0; k<optionList[j].max; k++) {\r
409                     if(choices[k] && !strcmp(choices[k], newText)) new = k;\r
410                 }\r
411                 if(!cps && new > 0) {\r
412                     if(*(char**)optionList[j].target) free(*(char**)optionList[j].target);\r
413                     *(char**)optionList[j].target = strdup(optionList[j].choice[new]);\r
414                     break;\r
415                 }\r
416                 changed = new >= 0 && (optionList[j].value != new);\r
417                 if(changed) optionList[j].value = new;\r
418                 break;\r
419             case ListBox:\r
420                 if(optionList[j].textValue)\r
421                     *(int*) optionList[j].textValue = SendDlgItemMessage(hDlg, 2001+2*i, LB_GETCURSEL, 0, 0);\r
422             case Button:\r
423             default:\r
424                 break; // are treated instantly, so they have been sent already\r
425         }\r
426         if(changed == 2)\r
427           snprintf(buf, MSG_SIZ, "option %s=%d\n", optionList[j].name, new); else\r
428         if(changed == 1)\r
429           snprintf(buf, MSG_SIZ, "option %s=%s\n", optionList[j].name, newText);\r
430         if(changed) SendToProgram(buf, cps);\r
431     }\r
432     if(!cps && okFunc) return ((ButtonCallback*) okFunc)(0);\r
433     return 1;\r
434 }\r
435 \r
436 char *defaultExt[] = { NULL, "pgn", "fen", "exe", "trn", "bin", "log", "ini" };\r
437 \r
438 LRESULT CALLBACK SettingsProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
439 {\r
440     char buf[MSG_SIZ];\r
441     int i, j, ext;\r
442 \r
443     switch( message )\r
444     {\r
445     case WM_INITDIALOG:\r
446 \r
447 //        CenterWindow(hDlg, GetWindow(hDlg, GW_OWNER));\r
448         SetOptionValues(hDlg, activeCps, activeList);\r
449 \r
450         SetFocus(GetDlgItem(hDlg, IDCANCEL));\r
451 \r
452         break;\r
453 \r
454     case WM_COMMAND:\r
455         switch( LOWORD(wParam) ) {\r
456         case IDOK:\r
457             if(!GetOptionValues(hDlg, activeCps, activeList)) return FALSE;\r
458             EndDialog( hDlg, 0 );\r
459             comboCallback = NULL; activeCps = NULL;\r
460             return TRUE;\r
461 \r
462         case IDCANCEL:\r
463             EndDialog( hDlg, 1 );\r
464             comboCallback = NULL; activeCps = NULL;\r
465             return TRUE;\r
466 \r
467         default:\r
468             // program-defined push buttons\r
469             i = LOWORD(wParam);\r
470             if( i>=2000 &&  i < 2000+2*(layout+buttons)) {\r
471                 j = layoutList[(i - 2000)/2];\r
472                 if(j == -2) {\r
473                           char filter[] =\r
474                                 "All files\0*.*\0Game files\0*.pgn;*.gam\0Position files\0*.fen;*.epd;*.pos\0"\r
475                                 "EXE files\0*.exe\0Tournament files (*.trn)\0*.trn\0"\r
476                                 "BIN Files\0*.bin\0LOG Files\0*.log\0INI Files\0*.ini\0\0";\r
477                           OPENFILENAME ofn;\r
478 \r
479                           safeStrCpy( buf, "" , sizeof( buf)/sizeof( buf[0]) );\r
480 \r
481                           ZeroMemory( &ofn, sizeof(ofn) );\r
482 \r
483                           ofn.lStructSize = sizeof(ofn);\r
484                           ofn.hwndOwner = hDlg;\r
485                           ofn.hInstance = hInst;\r
486                           ofn.lpstrFilter = filter;\r
487                           ofn.nFilterIndex      = 1L + (ext = activeCps ? 0 : activeList[layoutList[(i-2000)/2+1]].max & 31);\r
488                           ofn.lpstrDefExt       = defaultExt[ext];\r
489                           ofn.lpstrFile = buf;\r
490                           ofn.nMaxFile = sizeof(buf);\r
491                           ofn.lpstrTitle = _("Choose File");\r
492                           ofn.Flags = OFN_FILEMUSTEXIST | OFN_LONGNAMES | OFN_HIDEREADONLY;\r
493 \r
494                           if( activeList[layoutList[(i-2000)/2+1]].max & 32 ?\r
495                                                        GetOpenFileName( &ofn ) :\r
496                                                        GetSaveFileName( &ofn ) ) {\r
497                               SetDlgItemText( hDlg, i+3, buf );\r
498                           }\r
499                 } else\r
500                 if(j == -3) {\r
501                     if( BrowseForFolder( _("Choose Folder:"), buf ) ) {\r
502                         SetDlgItemText( hDlg, i+3, buf );\r
503                     }\r
504                 }\r
505                 if(j < 0) break;\r
506                 if(comboCallback && activeList[j].type == ComboBox && HIWORD(wParam) == CBN_SELCHANGE) {\r
507                     if(j > 5) break; // Yegh! Must solve problem with more than one combobox in dialog\r
508                     (*comboCallback)(hDlg);\r
509                     break;\r
510                 } else\r
511                 if(activeList[j].type == ListBox && HIWORD(wParam) == /*LBN_SELCHANGE*/ LBN_DBLCLK) {\r
512                     ((ButtonCallback *) activeList[j].target)(hDlg);\r
513                     break;\r
514                 } else\r
515                 if( activeList[j].type  == SaveButton)\r
516                      GetOptionValues(hDlg, activeCps, activeList);\r
517                 else if( activeList[j].type  != Button) break;\r
518                 else if( !activeCps ) { (*(ButtonCallback*) activeList[j].target)(hDlg); break; }\r
519                 snprintf(buf, MSG_SIZ, "option %s\n", activeList[j].name);\r
520                 SendToProgram(buf, activeCps);\r
521             }\r
522             break;\r
523         }\r
524 \r
525         break;\r
526     }\r
527 \r
528     return FALSE;\r
529 }\r
530 \r
531 void AddControl(int x, int y, int w, int h, int type, int style, int n)\r
532 {\r
533     int i;\r
534 \r
535     i = template.header.cdit++;\r
536     template.control[i].item.style = style;\r
537     template.control[i].item.dwExtendedStyle = 0;\r
538     template.control[i].item.x = x;\r
539     template.control[i].item.y = y;\r
540     template.control[i].item.cx = w;\r
541     template.control[i].item.cy = h;\r
542     template.control[i].item.id = 2000 + n;\r
543     template.control[i].code = 0xFFFF;\r
544     template.control[i].controlType = type;\r
545     template.control[i].d1 = ' ';\r
546     template.control[i].data = 0;\r
547     template.control[i].creationData = 0;\r
548 }\r
549 \r
550 void AddOption(int x, int y, Control type, int i)\r
551 {\r
552     int extra;\r
553 \r
554     switch(type) {\r
555         case Slider:\r
556         case Spin:\r
557             AddControl(x, y+1, 95, 9, 0x0082, SS_ENDELLIPSIS | WS_VISIBLE | WS_CHILD, i);\r
558             AddControl(x+95, y, 50, 11, 0x0081, ES_AUTOHSCROLL | ES_NUMBER | WS_BORDER | WS_VISIBLE | WS_CHILD | WS_TABSTOP, i+1);\r
559             break;\r
560         case TextBox:\r
561             extra = 13*activeList[layoutList[i/2]].min; // when extra high, left-align and put description text above it\r
562             AddControl(x+(extra?50:0), y+1, 95, 9, 0x0082, SS_ENDELLIPSIS | WS_VISIBLE | WS_CHILD, i);\r
563             AddControl(x+(extra?50:95), y+(extra?13:0), extra?105:200, 11+(extra?extra-13:0), 0x0081, ES_AUTOHSCROLL | WS_BORDER | WS_VISIBLE |\r
564                                         WS_CHILD | WS_TABSTOP | (extra ? ES_MULTILINE | ES_WANTRETURN | WS_VSCROLL :0), i+1);\r
565             break;\r
566         case ListBox:\r
567             AddControl(x, y+1, 95, 9, 0x0082, SS_ENDELLIPSIS | WS_VISIBLE | WS_CHILD, i);\r
568             extra = 13*activeList[layoutList[i/2]].min;\r
569             AddControl(x, y+13, 105, 11+extra-13, 0x0083, LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_HSCROLL | WS_BORDER | LBS_NOTIFY |\r
570                                                                  WS_VISIBLE | WS_CHILD | WS_TABSTOP, i+1);\r
571             break;\r
572         case Label:\r
573             extra = activeList[layoutList[i/2]].value;\r
574             AddControl(x+extra, y+1, 290-extra, 9, 0x0082, SS_ENDELLIPSIS | WS_VISIBLE | WS_CHILD | WS_TABSTOP, i);\r
575             break;\r
576         case FileName:\r
577         case PathName:\r
578             AddControl(x, y+1, 95, 9, 0x0082, SS_ENDELLIPSIS | WS_VISIBLE | WS_CHILD, i);\r
579             AddControl(x+95, y, 180, 11, 0x0081, ES_AUTOHSCROLL | WS_BORDER | WS_VISIBLE | WS_CHILD | WS_TABSTOP, i+1);\r
580             AddControl(x+275, y, 20, 12, 0x0080, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | WS_TABSTOP, i-2);\r
581             layoutList[i/2-1] = -2 - (type == PathName);\r
582             break;\r
583         case CheckBox:\r
584             AddControl(x, y, 145, 11, 0x0080, BS_AUTOCHECKBOX | WS_VISIBLE | WS_CHILD | WS_TABSTOP, i);\r
585             break;\r
586         case ComboBox:\r
587             AddControl(x, y+1, 95, 9, 0x0082, SS_ENDELLIPSIS | WS_VISIBLE | WS_CHILD, i);\r
588             AddControl(x+95, y-1, !activeCps && x<10 ? 120 : 50, 500, 0x0085,\r
589                         CBS_AUTOHSCROLL | CBS_DROPDOWN | WS_VISIBLE | WS_CHILD | WS_TABSTOP | WS_VSCROLL, i+1);\r
590             break;\r
591         case Button:\r
592         case ResetButton:\r
593         case SaveButton:\r
594             AddControl(x-2, y, 65, 13, 0x0080, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | WS_TABSTOP, i);\r
595         case Message:\r
596         default:\r
597             break;\r
598     }\r
599 \r
600 }\r
601 \r
602 void\r
603 CreateDialogTemplate(int *layoutList, int nr, Option *optionList)\r
604 {\r
605     int i, ii, j, x=1, y=0, maxY=0, buttonRows, breakPoint = 1000, k=0;\r
606 \r
607     template.header.cdit = 0;\r
608     template.header.cx = 307;\r
609     buttonRows = (buttons + 1 + 3)/4; // 4 per row, rounded up\r
610     if(nr > 50) {\r
611         breakPoint = (nr+2*buttonRows+1)/2 & ~1;\r
612         template.header.cx = 625;\r
613     }\r
614 \r
615     for(ii=0; ii<nr; ii++) {\r
616         i = ii^1; if(i == nr) i = ii; // if two on one line, swap order of treatment, to get good (left to right) tabbing order.\r
617         if(k < groups && ii == boxList[k]) {\r
618             y += 10;\r
619             AddControl(x+2, y+13*(i>>1)-2, 301, 13*(boxList[k+1]-boxList[k]>>1)+8,\r
620                                                 0x0082, WS_VISIBLE | WS_CHILD | SS_BLACKFRAME, 2400);\r
621             AddControl(x+60, y+13*(i>>1)-6, 10*groupNameList[k]/3, 10,\r
622                                                 0x0082, SS_ENDELLIPSIS | WS_VISIBLE | WS_CHILD, 2*(ii+MAX_OPTIONS));\r
623         }\r
624         j = layoutList[i];\r
625         if(j >= 0) {\r
626             AddOption(x+155-150*(i&1), y+13*(i>>1)+5, optionList[j].type, 2*i);\r
627             // listboxes have the special power to adjust the width of the column they are in\r
628             if(optionList[j].type == ListBox) x -= optionList[j].value, template.header.cx -= optionList[j].value;\r
629         }\r
630         if(k < groups && ii+1 == boxList[k+1]) {\r
631             k += 2; y += 4;\r
632         }\r
633         if(ii+1 >= breakPoint && breaks[ii+1>>1] >= 0) { x += 318; maxY = y+13*(ii+1>>1)+5; y = -13*(ii+1>>1); breakPoint = 1000; }\r
634     }\r
635     // add butons at the bottom of dialog window\r
636     y += 13*(nr>>1)+5;\r
637 \r
638     for(i=0; i<buttons; i++) {\r
639         AddControl(x+70*(i%4)+5, y+18*(i/4), 65, 15, 0x0080, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | WS_TABSTOP, 2*(nr+i));\r
640         layoutList[nr+i] = buttonList[i];\r
641     }\r
642     AddControl(x+225, y+18*(buttonRows-1), 30, 15, 0x0080, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | WS_TABSTOP, IDOK-2000);\r
643     AddControl(x+260, y+18*(buttonRows-1), 40, 15, 0x0080, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | WS_TABSTOP, IDCANCEL-2000);\r
644     y += 18*buttonRows; if(y < maxY) y = maxY;\r
645     template.title[8] = optionList == first.option ? '1' :  '2';\r
646     template.header.cy = y+2;\r
647     template.header.style &= ~WS_VSCROLL;\r
648 }\r
649 \r
650 void\r
651 EngineOptionsPopup(HWND hwnd, ChessProgramState *cps)\r
652 {\r
653     FARPROC lpProc = MakeProcInstance( (FARPROC) SettingsProc, hInst );\r
654 \r
655     activeCps = cps; activeList = cps->option;\r
656     snprintf(title, MSG_SIZ, _("%s Engine Settings (%s)"), T_(cps->which), cps->tidy);\r
657     DesignOptionDialog(cps->nrOptions, cps->option);\r
658     CreateDialogTemplate(layoutList, layout, cps->option);\r
659 \r
660 \r
661     DialogBoxIndirect( hInst, &template.header, hwnd, (DLGPROC)lpProc );\r
662 \r
663     FreeProcInstance(lpProc);\r
664 \r
665     return;\r
666 }\r
667 \r
668 int EnterGroup P((HWND hDlg));\r
669 \r
670 static int engineNr, selected;\r
671 \r
672 int InstallOK()\r
673 {\r
674     if(selected >= 0) { ASSIGN(engineLine, engineList[selected]); }\r
675     if(engineLine[0] == '#') { DisplayError(_("Select single engine from the group"), 0); return 0; }\r
676     if(isUCCI) isUCI = 2;\r
677     if(!engineNr) Load(&first, 0); else Load(&second, 1);\r
678     return 1;\r
679 }\r
680 \r
681 Option installOptions[] = {\r
682 //  {   0,  0,    0, NULL, (void*) &engineLine, (char*) engineMnemonic, engineList, ComboBox, N_("Select engine from list:") },\r
683   { 195, 14,    0, NULL, (void*) &EnterGroup, (char*) &selected, engineMnemonic, ListBox, N_("Select engine from list:") },\r
684   {   0,  0,    0, NULL, NULL, NULL, NULL, Label, N_("or specify one below:") },\r
685   {   0,  0,    0, NULL, (void*) &nickName, NULL, NULL, TextBox, N_("Nickname (optional):") },\r
686   {   0,  0,    0, NULL, (void*) &useNick, NULL, NULL, CheckBox, N_("Use nickname in PGN tag") },\r
687   {   0,  0, 32+3, NULL, (void*) &engineName, NULL, NULL, FileName, N_("Engine (*.exe):") },\r
688   {   0,  0,    0, NULL, (void*) &params, NULL, NULL, TextBox, N_("command-line parameters:") },\r
689   {   0,  0,    0, NULL, (void*) &wbOptions, NULL, NULL, TextBox, N_("Special WinBoard options:") },\r
690   {   0,  0,    0, NULL, (void*) &engineDir, NULL, NULL, PathName, N_("directory:") },\r
691   {  95,  0,    0, NULL, NULL, NULL, NULL, Label, N_("(Directory will be derived from engine path when left empty)") },\r
692   {   0,  0,    0, NULL, (void*) &addToList, NULL, NULL, CheckBox, N_("Add this engine to the list") },\r
693   {   0,  0,    0, NULL, (void*) &hasBook, NULL, NULL, CheckBox, N_("Must not use GUI book") },\r
694   {   0,  0,    0, NULL, (void*) &storeVariant, NULL, NULL, CheckBox, N_("Force current variant with this engine") },\r
695   {   0,  0,    0, NULL, (void*) &isUCI, NULL, NULL, CheckBox, N_("UCI") },\r
696   {   0,  0,    0, NULL, (void*) &v1, NULL, NULL, CheckBox, N_("WB protocol v1 (skip waiting for features)") },\r
697   {   0,  0,    0, NULL, (void*) &isUCCI, NULL, NULL, CheckBox, N_("UCCI / USI (uses specified /uxiAdapter)") },\r
698   {   0,  1,    0, NULL, (void*) &InstallOK, "", NULL, EndMark , "" }\r
699 };\r
700 \r
701 void\r
702 GenericPopup(HWND hwnd, Option *optionList)\r
703 {\r
704     FARPROC lpProc = MakeProcInstance( (FARPROC) SettingsProc, hInst );\r
705     int n=0;\r
706 \r
707     while(optionList[n].type != EndMark) n++;\r
708     activeCps = NULL; activeList = optionList;\r
709     DesignOptionDialog(n, optionList);\r
710     CreateDialogTemplate(layoutList, layout, optionList);\r
711 \r
712     DialogBoxIndirect( hInst, &template.header, hwnd, (DLGPROC)lpProc );\r
713 \r
714     FreeProcInstance(lpProc);\r
715 \r
716     return;\r
717 }\r
718 \r
719 int\r
720 EnterGroup(HWND hDlg)\r
721 {\r
722     char buf[MSG_SIZ];\r
723     HANDLE hwndCombo = GetDlgItem(hDlg, 2001+2*1);\r
724     int i = SendDlgItemMessage(hDlg, 2001+2*1, LB_GETCURSEL, 0, 0);\r
725     if(i == 0) buf[0] = NULLCHAR; // back to top level\r
726     else if(engineList[i][0] == '#') safeStrCpy(buf, engineList[i], MSG_SIZ); // group header, open group\r
727     else {\r
728         ASSIGN(engineLine, engineList[i]);\r
729         if(isUCCI) isUCI = 2;\r
730         if(!engineNr) Load(&first, 0); else Load(&second, 1);\r
731         EndDialog( hDlg, 0 );\r
732         return 0; // normal line, select engine\r
733     }\r
734     installOptions[0].max = NamesToList(firstChessProgramNames, engineList, engineMnemonic, buf); // replace list by only the group contents\r
735     SendMessage(hwndCombo, LB_RESETCONTENT, 0, 0);\r
736     SendMessage(hwndCombo, LB_ADDSTRING, 0, (LPARAM) buf);\r
737     for(i=1; i<installOptions[0].max; i++) {\r
738             SendMessage(hwndCombo, LB_ADDSTRING, 0, (LPARAM) engineMnemonic[i]);\r
739     }\r
740 //    SendMessage(hwndCombo, CB_SELECTSTRING, (WPARAM) 0, (LPARAM) buf);\r
741     return 0;\r
742 }\r
743 \r
744 void LoadEnginePopUp(HWND hwnd, int nr)\r
745 {\r
746     isUCI = isUCCI = storeVariant = v1 = useNick = FALSE; addToList = hasBook = TRUE; // defaults\r
747     engineNr = nr;\r
748     if(engineDir)    free(engineDir);    engineDir = strdup("");\r
749     if(params)       free(params);       params = strdup("");\r
750     if(nickName)     free(nickName);     nickName = strdup("");\r
751     if(engineLine)   free(engineLine);   engineLine = strdup("");\r
752     if(engineName)   free(engineName);   engineName = strdup("");\r
753     ASSIGN(wbOptions, "");\r
754     installOptions[0].max = NamesToList(firstChessProgramNames, engineList, engineMnemonic, ""); // only top level\r
755     snprintf(title, MSG_SIZ, _("Load %s Engine"), nr ? _("second") : _("first"));\r
756 \r
757     GenericPopup(hwnd, installOptions);\r
758 }\r
759 \r
760 Boolean autoinc, twice, swiss;\r
761 char *tfName;\r
762 \r
763 int MatchOK()\r
764 {\r
765     if(autoinc) appData.loadGameIndex = appData.loadPositionIndex = -(twice + 1); else\r
766     if(!appData.loadGameFile[0]) appData.loadGameIndex = -2*twice; // kludge to pass value of "twice" for use in GUI book\r
767     if(swiss) { appData.defaultMatchGames = 1; appData.tourneyType = -1; }\r
768     if(CreateTourney(tfName) && !matchMode) { // CreateTourney reloads original settings if file already existed\r
769         MatchEvent(2);\r
770         return 1; // close dialog\r
771     }\r
772     return matchMode || !appData.participants[0]; // if we failed to create and are not in playing, forbid popdown if there are participants\r
773 }\r
774 \r
775 void PseudoOK(HWND hDlg)\r
776 {\r
777     void (*saveOK)();\r
778     saveOK = okFunc; okFunc = 0;\r
779     GetOptionValues(hDlg, activeCps, activeList);\r
780     EndDialog( hDlg, 0 );\r
781     comboCallback = NULL; activeCps = NULL;\r
782 \r
783     if(autoinc) appData.loadGameIndex = appData.loadPositionIndex = -(twice + 1); else\r
784     if(!appData.loadGameFile[0]) appData.loadGameIndex = -2*twice; // kludge to pass value of "twice" for use in GUI book\r
785     if(swiss) { appData.defaultMatchGames = 1; appData.tourneyType = -1; }\r
786 }\r
787 \r
788 char *GetParticipants(HWND hDlg)\r
789 {\r
790     int len = GetWindowTextLength(GetDlgItem(hDlg, 2001+2*0)) + 1;\r
791     char *participants,*p, *q;\r
792     if(len < 4) return NULL; // box is empty (enough)\r
793     participants = (char*) malloc(len);\r
794     GetDlgItemText(hDlg, 2001+2*0, participants, len );\r
795     p = q = participants;\r
796     while(*p++ = *q++) if(p[-1] == '\r') p--;\r
797     return participants;\r
798 }\r
799 \r
800 void ReplaceParticipant(HWND hDlg)\r
801 {\r
802     char *participants = GetParticipants(hDlg);\r
803     Substitute(participants, TRUE);\r
804 }\r
805         \r
806 void UpgradeParticipant(HWND hDlg)\r
807 {\r
808     char *participants = GetParticipants(hDlg);\r
809     Substitute(participants, FALSE);\r
810 }\r
811 \r
812 void Inspect(HWND hDlg)\r
813 {\r
814     FILE *f;\r
815     char name[MSG_SIZ];\r
816     GetDlgItemText(hDlg, 2001+2*33, name, MSG_SIZ );\r
817     if(name[0] && (f = fopen(name, "r")) ) {\r
818         char *saveSaveFile;\r
819         saveSaveFile = appData.saveGameFile; appData.saveGameFile = NULL; // this is a persistent option, protect from change\r
820         ParseArgsFromFile(f);\r
821         autoinc = ((appData.loadPositionFile[0] ? appData.loadGameIndex : appData.loadPositionIndex) < 0);\r
822         twice = ((appData.loadPositionFile[0] ? appData.loadGameIndex : appData.loadPositionIndex) == -2);\r
823         swiss = appData.tourneyType < 0;\r
824         SetOptionValues(hDlg, NULL, activeList);\r
825         FREE(appData.saveGameFile); appData.saveGameFile = saveSaveFile;\r
826     } else DisplayError(_("First you must specify an existing tourney file to clone"), 0);\r
827 }\r
828 \r
829 void TimeControlOptionsPopup P((HWND hDlg));\r
830 void UciOptionsPopup P((HWND hDlg));\r
831 int AddToTourney P((HWND hDlg));\r
832 \r
833 Option tourneyOptions[] = {\r
834   { 80,  15,        0, NULL, (void*) &AddToTourney, NULL, engineMnemonic, ListBox, N_("Select Engine:") },\r
835   { 0xD, 15,        0, NULL, (void*) &appData.participants, "", NULL, TextBox, N_("Tourney participants:") },\r
836   { 0,  0,          4, NULL, (void*) &tfName, "", NULL, FileName, N_("Tournament file:") },\r
837   { 30, 0,          0, NULL, NULL, NULL, NULL, Label, N_("If you specify an existing file, the rest of this dialog will be ignored.") },\r
838   { 30, 0,          0, NULL, NULL, NULL, NULL, Label, N_("Otherwise, the file will be created, with the settings you specify below:") },\r
839   { 0,  0,          0, NULL, (void*) &swiss, "", NULL, CheckBox, N_("Use Swiss pairing engine (cycles = rounds)") },\r
840   { 0,  0,         10, NULL, (void*) &appData.tourneyType, "", NULL, Spin, N_("Tourney type (0=RR, 1=gauntlet):") },\r
841   { 0,  0,          0, NULL, (void*) &appData.cycleSync, "", NULL, CheckBox, N_("Sync after cycle") },\r
842   { 0,  1, 1000000000, NULL, (void*) &appData.tourneyCycles, "", NULL, Spin, N_("Number of tourney cycles:") },\r
843   { 0,  0,          0, NULL, (void*) &appData.roundSync, "", NULL, CheckBox, N_("Sync after round") },\r
844   { 0,  1, 1000000000, NULL, (void*) &appData.defaultMatchGames, "", NULL, Spin, N_("Games per Match / Pairing:") },\r
845   { 0,  0,          1, NULL, (void*) &appData.saveGameFile, "", NULL, FileName, N_("File for saving tourney games:") },\r
846   { 0,  0,       32+1, NULL, (void*) &appData.loadGameFile, "", NULL, FileName, N_("Game File with Opening Lines:") },\r
847   { 0, -2, 1000000000, NULL, (void*) &appData.loadGameIndex, "", NULL, Spin, N_("Game Number:") },\r
848   { 0,  0,       32+2, NULL, (void*) &appData.loadPositionFile, "", NULL, FileName, N_("File with Start Positions:") },\r
849   { 0, -2, 1000000000, NULL, (void*) &appData.loadPositionIndex, "", NULL, Spin, N_("Position Number:") },\r
850   { 0,  0,          0, NULL, (void*) &autoinc, "", NULL, CheckBox, N_("Step through lines/positions in file") },\r
851   { 0,  0, 1000000000, NULL, (void*) &appData.rewindIndex, "", NULL, Spin, N_("Rewind after (0 = never):") },\r
852   { 0,  0,          0, NULL, (void*) &twice, "", NULL, CheckBox, N_("Use each line/position twice") },\r
853   { 0,  0,          0, NULL, (void*) &appData.defNoBook, "", NULL, CheckBox, N_("Make all use GUI book by default") },\r
854   { 0,  0, 1000000000, NULL, (void*) &appData.matchPause, "", NULL, Spin, N_("Pause between Games (ms):") },\r
855   { 0,  0,          0, NULL, (void*) &ReplaceParticipant, "", NULL, Button, N_("Replace Engine") },\r
856   { 0,  0,          0, NULL, (void*) &UpgradeParticipant, "", NULL, Button, N_("Upgrade Engine") },\r
857   { 0,  0,          0, NULL, (void*) &TimeControlOptionsPopup, "", NULL, Button, N_("Time Control...") },\r
858   { 0,  0,          0, NULL, (void*) &UciOptionsPopup, "", NULL, Button, N_("Common Engine...") },\r
859   { 0,  0,          0, NULL, (void*) &Inspect, "", NULL, Button, N_("Clone Tourney") },\r
860   { 0,  0,          0, NULL, (void*) &PseudoOK, "", NULL, Button, N_("Continue Later") },\r
861   { 0, 0, 0, NULL, (void*) &MatchOK, "", NULL, EndMark , "" }\r
862 };\r
863 \r
864 int AddToTourney(HWND hDlg)\r
865 {\r
866   char buf[MSG_SIZ];\r
867   HANDLE hwndCombo = GetDlgItem(hDlg, 2001+2*1);\r
868   int i = SendDlgItemMessage(hDlg, 2001+2*1, LB_GETCURSEL, 0, 0);\r
869   if(i<0) return 0;\r
870   if(i == 0) buf[0] = NULLCHAR; // back to top level\r
871   else if(engineList[i][0] == '#') safeStrCpy(buf, engineList[i], MSG_SIZ); // group header, open group\r
872   else { // normal line, select engine\r
873     snprintf(buf, MSG_SIZ, "%s\r\n", engineMnemonic[i]);\r
874     SendMessage( GetDlgItem(hDlg, 2001+2*0), EM_SETSEL, 99999, 99999 );\r
875     SendMessage( GetDlgItem(hDlg, 2001+2*0), EM_REPLACESEL, (WPARAM) FALSE, (LPARAM) buf );\r
876     return 0;\r
877   }\r
878   tourneyOptions[0].max = NamesToList(firstChessProgramNames, engineList, engineMnemonic, buf); // replace list by only the group contents\r
879   SendMessage(hwndCombo, LB_RESETCONTENT, 0, 0);\r
880   SendMessage(hwndCombo, LB_ADDSTRING, 0, (LPARAM) buf);\r
881   for(i=1; i<tourneyOptions[0].max; i++) {\r
882     SendMessage(hwndCombo, LB_ADDSTRING, 0, (LPARAM) engineMnemonic[i]);\r
883   }\r
884 //  SendMessage(hwndCombo, CB_SELECTSTRING, (WPARAM) 0, (LPARAM) buf);\r
885   return 0;\r
886 }\r
887 \r
888 void TourneyPopup(HWND hwnd)\r
889 {\r
890     int n = NamesToList(firstChessProgramNames, engineList, engineMnemonic, "");\r
891     autoinc = appData.loadGameIndex < 0 || appData.loadPositionIndex < 0;\r
892     twice = FALSE; swiss = appData.tourneyType < 0;\r
893     tourneyOptions[0].max = n;\r
894     snprintf(title, MSG_SIZ, _("Tournament and Match Options"));\r
895     ASSIGN(tfName, appData.tourneyFile[0] ? appData.tourneyFile : MakeName(appData.defName));\r
896 \r
897     GenericPopup(hwnd, tourneyOptions);\r
898 }\r