Fix multi-leg promotions
[xboard.git] / winboard / help.c
1 /*\r
2  * help.h\r
3  *\r
4  * Copyright 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Free Software Foundation, Inc.\r
5  * ------------------------------------------------------------------------\r
6  *\r
7  * GNU XBoard is free software: you can redistribute it and/or modify\r
8  * it under the terms of the GNU General Public License as published by\r
9  * the Free Software Foundation, either version 3 of the License, or (at\r
10  * your option) any later version.\r
11  *\r
12  * GNU XBoard is distributed in the hope that it will be useful, but\r
13  * WITHOUT ANY WARRANTY; without even the implied warranty of\r
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
15  * General Public License for more details.\r
16  *\r
17  * You should have received a copy of the GNU General Public License\r
18  * along with this program. If not, see http://www.gnu.org/licenses/.  *\r
19  *\r
20  *------------------------------------------------------------------------\r
21  ** See the file ChangeLog for a revision history.  */\r
22 \r
23 /* Windows html help function to avoid having to link with the htmlhlp.lib  */\r
24 \r
25 #include <windows.h>\r
26 #include <stdio.h>\r
27 #include "config.h"
28 #include "help.h"
29 \r
30 FILE *debugFP;\r
31 \r
32 HWND WINAPI\r
33 HtmlHelp( HWND hwnd, LPCSTR helpFile, UINT action, DWORD_PTR data )\r
34 {\r
35         PROCESS_INFORMATION helpProcInfo;\r
36         STARTUPINFO siStartInfo;\r
37         char buf[100];\r
38         static int status = 0;\r
39         FILE *f;\r
40 \r
41         if(status < 0) return NULL;\r
42 \r
43         if(!status) {\r
44                 f = fopen(helpFile, "r");\r
45                 if(f == NULL) {\r
46                         status = -1;\r
47                         return NULL;\r
48                 }\r
49                 status = 1;\r
50                 fclose(f);\r
51         }\r
52 \r
53         siStartInfo.cb = sizeof(STARTUPINFO);\r
54         siStartInfo.lpReserved = NULL;\r
55         siStartInfo.lpDesktop = NULL;\r
56         siStartInfo.lpTitle = NULL;\r
57         siStartInfo.dwFlags = STARTF_USESTDHANDLES;\r
58         siStartInfo.cbReserved2 = 0;\r
59         siStartInfo.lpReserved2 = NULL;\r
60         siStartInfo.hStdInput = NULL;\r
61         siStartInfo.hStdOutput = NULL;\r
62         siStartInfo.hStdError = debugFP;\r
63 \r
64         snprintf(buf, sizeof(buf)/sizeof(buf[0]),"Hh.exe %s", helpFile);\r
65 \r
66         // ignore the other parameters; just start the viewer with the help file\r
67         if(  CreateProcess(NULL,\r
68                            buf,            /* command line */\r
69                            NULL,           /* process security attributes */\r
70                            NULL,           /* primary thread security attrs */\r
71                            FALSE,          /* handles are inherited */\r
72                            DETACHED_PROCESS|CREATE_NEW_PROCESS_GROUP,\r
73                            NULL,           /* use parent's environment */\r
74                            NULL,\r
75                            &siStartInfo,   /* STARTUPINFO pointer */\r
76                            &helpProcInfo)  /* receives PROCESS_INFORMATION */\r
77                 ) return hwnd; else return NULL;\r
78 }\r
79 \r
80 //HWND WINAPI\r
81 int\r
82 MyHelp(HWND hwnd, LPSTR helpFile, UINT action, DWORD_PTR data)\r
83 {\r
84         static int status = 0;\r
85         FILE *f;\r
86 \r
87         if(status < 0) return 0;\r
88 \r
89         if(!status) {\r
90                 f = fopen(helpFile, "r");\r
91                 if(f == NULL) {\r
92                         status = -1;\r
93                         return 0;\r
94                 }\r
95                 status = 1;\r
96                 fclose(f);\r
97         }\r
98         return WinHelp(hwnd, helpFile, action, data);\r
99 }\r