Rev 12 | Rev 33 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 12 | Rev 32 | ||
|---|---|---|---|
| Line 37... | Line 37... | ||
| 37 | hChessEngineStdoutRd = NULL; |
37 | hChessEngineStdoutRd = NULL; |
| 38 | hChessEngineStdoutWr = NULL; |
38 | hChessEngineStdoutWr = NULL; |
| 39 | player->wants_hint = false; |
39 | player->wants_hint = false; |
| 40 | 40 | ||
| 41 | // build the chess engine module path and pathname |
41 | // build the chess engine module path and pathname |
| 42 | swprintf_s (chessenginemodule_path, WCHAR_SIZEOF (chessenginemodule_path), L"%s/engine", |
42 | swprintf_s (chessenginemodule_path, WCHAR_SIZEOF (chessenginemodule_path), L"%s/engine/%s", app_path, options.engine.program); |
| 43 | swprintf_s (chessenginemodule_pathname, WCHAR_SIZEOF (chessenginemodule_pathname), L"%s/engine/%s", app_path, options.engine.cmdline); |
43 | swprintf_s (chessenginemodule_pathname, WCHAR_SIZEOF (chessenginemodule_pathname), L"%s/engine/%s/%s", app_path, options.engine.program, options.engine.cmdline); |
| 44 | 44 | ||
| 45 | // prepare the pipes' security attributes |
45 | // prepare the pipes' security attributes |
| 46 | saAttr.nLength = sizeof (SECURITY_ATTRIBUTES); |
46 | saAttr.nLength = sizeof (SECURITY_ATTRIBUTES); |
| 47 | saAttr.bInheritHandle = true; // set the bInheritHandle flag so pipe handles are inherited |
47 | saAttr.bInheritHandle = true; // set the bInheritHandle flag so pipe handles are inherited |
| 48 | saAttr.lpSecurityDescriptor = NULL; |
48 | saAttr.lpSecurityDescriptor = NULL; |
| Line 83... | Line 83... | ||
| 83 | } |
83 | } |
| 84 | 84 | ||
| 85 | // eventually initialize the debug log file |
85 | // eventually initialize the debug log file |
| 86 | Debug_Init (L"Chess engine output.txt"); |
86 | Debug_Init (L"Chess engine output.txt"); |
| 87 | 87 | ||
| 88 | // |
88 | // build the init file full qualified path name and try to open it |
| - | 89 | swprintf_s (chessengineinitfile_pathname, WCHAR_SIZEOF (chessengineinitfile_pathname), L"%s/engines/%s/init.txt", app_path, options.engine.program); |
|
| 89 |
|
90 | _wfopen_s (&fp, chessengineinitfile_pathname, L"r"); |
| - | 91 | ||
| - | 92 | // could the init file be opened ? |
|
| - | 93 | if (fp != NULL) |
|
| 90 | { |
94 | { |
| 91 | // build the init file full qualified path name (either relative or absolute) |
- | |
| 92 | if (wcschr (options.engine.init_file, L':') != NULL) |
- | |
| 93 | wcscpy_s (chessengineinitfile_pathname, WCHAR_SIZEOF (chessengineinitfile_pathname), options.engine.init_file); // absolute path |
- | |
| 94 | else |
- | |
| 95 | swprintf_s (chessengineinitfile_pathname, WCHAR_SIZEOF (chessengineinitfile_pathname), L"%s/engine/%s", app_path, options.engine.init_file); // relative path |
- | |
| 96 | - | ||
| 97 | // now try to open the file |
- | |
| 98 | _wfopen_s (&fp, chessengineinitfile_pathname, L"r"); |
- | |
| 99 | - | ||
| 100 | // on error, give up |
- | |
| 101 | if (fp == NULL) |
- | |
| 102 | { |
- | |
| 103 | messagebox.hWndParent = hMainWnd; |
- | |
| 104 | wcscpy_s (messagebox.title, WCHAR_SIZEOF (messagebox.title), LOCALIZE (L"ImportantMessage")); |
- | |
| 105 | wcscpy_s (messagebox.text, WCHAR_SIZEOF (messagebox.text), LOCALIZE (L"Error_UnableToOpenChessEngineInitFile")); |
- | |
| 106 | messagebox.flags = MB_ICONWARNING | MB_OK; |
- | |
| 107 | DialogBox_Message (&messagebox); // display a modeless error message box |
- | |
| 108 | - | ||
| 109 | PlayerEngine_Shutdown (player); // on error, shutdown the engine |
- | |
| 110 | return (false); |
- | |
| 111 | } |
- | |
| 112 | - | ||
| 113 | Debug_Log (L"===Found initialization file, parsing...===\n"); |
95 | Debug_Log (L"===Found initialization file, parsing...===\n"); |
| 114 | 96 | ||
| 115 | // SMP HACK -- is our engine Crafty ? if so, set the max CPUs to use to core max - 1 |
97 | // SMP HACK -- is our engine Crafty ? if so, set the max CPUs to use to core max - 1 |
| 116 | // (the computer will look like hung if all CPU is taken) |
98 | // (the computer will look like hung if all CPU is taken) |
| 117 | if (wcsistr (options.engine.name, L"Crafty") != NULL) |
99 | if (wcsistr (options.engine.name, L"Crafty") != NULL) |
| 118 | { |
100 | { |
| 119 | GetSystemInfo (&sysinfo); // get the number of cores and build the corresponding engine initialization order |
101 | GetSystemInfo (&sysinfo); // get the number of cores and build the corresponding engine initialization order |
| 120 | swprintf_s (widechar_buffer, WCHAR_SIZEOF (widechar_buffer), L"mt %d\n", max (sysinfo.dwNumberOfProcessors - |
102 | swprintf_s (widechar_buffer, WCHAR_SIZEOF (widechar_buffer), L"mt %d\n", max (1, sysinfo.dwNumberOfProcessors - 1)); |
| 121 | - | ||
| 122 | // new command line found, append it to the send buffer |
- | |
| 123 | Player_SendBuffer_Add (player, 1000, widechar_buffer); |
103 | Player_SendBuffer_Add (player, 1000, widechar_buffer); |
| 124 | } |
104 | } |
| 125 | 105 | ||
| 126 | // read line per line |
106 | // read line per line |
| 127 | while (fgetws (widechar_buffer, WCHAR_SIZEOF (widechar_buffer), fp) != NULL) |
107 | while (fgetws (widechar_buffer, WCHAR_SIZEOF (widechar_buffer), fp) != NULL) |