OSDN Git Service

Fix bugs of simultaneous connection.
[ffftp/ffftp.git] / contrib / putty / WINDOWS / WINHELP.C
1 /*\r
2  * winhelp.c: centralised functions to launch Windows help files,\r
3  * and to decide whether to use .HLP or .CHM help in any given\r
4  * situation.\r
5  */\r
6 \r
7 #include <stdio.h>\r
8 #include <stdlib.h>\r
9 #include <string.h>\r
10 #include <assert.h>\r
11 \r
12 #include "putty.h"\r
13 \r
14 #ifndef NO_HTMLHELP\r
15 #include <htmlhelp.h>\r
16 #endif /* NO_HTMLHELP */\r
17 \r
18 static int requested_help;\r
19 static char *help_path;\r
20 static int help_has_contents;\r
21 #ifndef NO_HTMLHELP\r
22 DECL_WINDOWS_FUNCTION(static, HWND, HtmlHelpA, (HWND, LPCSTR, UINT, DWORD));\r
23 static char *chm_path;\r
24 #endif /* NO_HTMLHELP */\r
25 \r
26 void init_help(void)\r
27 {\r
28     char b[2048], *p, *q, *r;\r
29     FILE *fp;\r
30 \r
31     GetModuleFileName(NULL, b, sizeof(b) - 1);\r
32     r = b;\r
33     p = strrchr(b, '\\');\r
34     if (p && p >= r) r = p+1;\r
35     q = strrchr(b, ':');\r
36     if (q && q >= r) r = q+1;\r
37     strcpy(r, PUTTY_HELP_FILE);\r
38     if ( (fp = fopen(b, "r")) != NULL) {\r
39         help_path = dupstr(b);\r
40         fclose(fp);\r
41     } else\r
42         help_path = NULL;\r
43     strcpy(r, PUTTY_HELP_CONTENTS);\r
44     if ( (fp = fopen(b, "r")) != NULL) {\r
45         help_has_contents = TRUE;\r
46         fclose(fp);\r
47     } else\r
48         help_has_contents = FALSE;\r
49 \r
50 #ifndef NO_HTMLHELP\r
51     strcpy(r, PUTTY_CHM_FILE);\r
52     if ( (fp = fopen(b, "r")) != NULL) {\r
53         chm_path = dupstr(b);\r
54         fclose(fp);\r
55     } else\r
56         chm_path = NULL;\r
57     if (chm_path) {\r
58         HINSTANCE dllHH = load_system32_dll("hhctrl.ocx");\r
59         GET_WINDOWS_FUNCTION(dllHH, HtmlHelpA);\r
60         if (!p_HtmlHelpA) {\r
61             chm_path = NULL;\r
62             if (dllHH)\r
63                 FreeLibrary(dllHH);\r
64         }\r
65     }\r
66 #endif /* NO_HTMLHELP */\r
67 }\r
68 \r
69 void shutdown_help(void)\r
70 {\r
71     /* Nothing to do currently.\r
72      * (If we were running HTML Help single-threaded, this is where we'd\r
73      * call HH_UNINITIALIZE.) */\r
74 }\r
75 \r
76 int has_help(void)\r
77 {\r
78     /*\r
79      * FIXME: it would be nice here to disregard help_path on\r
80      * platforms that didn't have WINHLP32. But that's probably\r
81      * unrealistic, since even Vista will have it if the user\r
82      * specifically downloads it.\r
83      */\r
84     return (help_path\r
85 #ifndef NO_HTMLHELP\r
86             || chm_path\r
87 #endif /* NO_HTMLHELP */\r
88            );\r
89 }\r
90 \r
91 void launch_help(HWND hwnd, const char *topic)\r
92 {\r
93     if (topic) {\r
94         int colonpos = strcspn(topic, ":");\r
95 \r
96 #ifndef NO_HTMLHELP\r
97         if (chm_path) {\r
98             char *fname;\r
99             assert(topic[colonpos] != '\0');\r
100             fname = dupprintf("%s::/%s.html>main", chm_path,\r
101                               topic + colonpos + 1);\r
102             p_HtmlHelpA(hwnd, fname, HH_DISPLAY_TOPIC, 0);\r
103             sfree(fname);\r
104         } else\r
105 #endif /* NO_HTMLHELP */\r
106         if (help_path) {\r
107             char *cmd = dupprintf("JI(`',`%.*s')", colonpos, topic);\r
108             WinHelp(hwnd, help_path, HELP_COMMAND, (DWORD)cmd);\r
109             sfree(cmd);\r
110         }\r
111     } else {\r
112 #ifndef NO_HTMLHELP\r
113         if (chm_path) {\r
114             p_HtmlHelpA(hwnd, chm_path, HH_DISPLAY_TOPIC, 0);\r
115         } else\r
116 #endif /* NO_HTMLHELP */\r
117         if (help_path) {\r
118             WinHelp(hwnd, help_path,\r
119                     help_has_contents ? HELP_FINDER : HELP_CONTENTS, 0);\r
120         }\r
121     }\r
122     requested_help = TRUE;\r
123 }\r
124 \r
125 void quit_help(HWND hwnd)\r
126 {\r
127     if (requested_help) {\r
128 #ifndef NO_HTMLHELP\r
129         if (chm_path) {\r
130             p_HtmlHelpA(NULL, NULL, HH_CLOSE_ALL, 0);\r
131         } else\r
132 #endif /* NO_HTMLHELP */\r
133         if (help_path) {\r
134             WinHelp(hwnd, help_path, HELP_QUIT, 0);\r
135         }\r
136         requested_help = FALSE;\r
137     }\r
138 }\r