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