1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-10 01:48:00 +00:00

Sort out line-endings on new file.

[originally from svn r7001]
This commit is contained in:
Jacob Nevins 2006-12-17 17:46:12 +00:00
parent 1dac1bc911
commit d660f65ac1

View File

@ -1,123 +1,123 @@
/* /*
* winhelp.c: centralised functions to launch Windows help files, * winhelp.c: centralised functions to launch Windows help files,
* and to decide whether to use .HLP or .CHM help in any given * and to decide whether to use .HLP or .CHM help in any given
* situation. * situation.
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include "putty.h" #include "putty.h"
#include <htmlhelp.h> #include <htmlhelp.h>
typedef HWND (CALLBACK *htmlhelp_t)(HWND, LPCSTR, UINT, DWORD); typedef HWND (CALLBACK *htmlhelp_t)(HWND, LPCSTR, UINT, DWORD);
static char *help_path, *chm_path; static char *help_path, *chm_path;
static int help_has_contents; static int help_has_contents;
static int requested_help; static int requested_help;
static DWORD html_help_cookie; static DWORD html_help_cookie;
static htmlhelp_t htmlhelp; static htmlhelp_t htmlhelp;
void init_help(void) void init_help(void)
{ {
char b[2048], *p, *q, *r; char b[2048], *p, *q, *r;
FILE *fp; FILE *fp;
GetModuleFileName(NULL, b, sizeof(b) - 1); GetModuleFileName(NULL, b, sizeof(b) - 1);
r = b; r = b;
p = strrchr(b, '\\'); p = strrchr(b, '\\');
if (p && p >= r) r = p+1; if (p && p >= r) r = p+1;
q = strrchr(b, ':'); q = strrchr(b, ':');
if (q && q >= r) r = q+1; if (q && q >= r) r = q+1;
strcpy(r, PUTTY_HELP_FILE); strcpy(r, PUTTY_HELP_FILE);
if ( (fp = fopen(b, "r")) != NULL) { if ( (fp = fopen(b, "r")) != NULL) {
help_path = dupstr(b); help_path = dupstr(b);
fclose(fp); fclose(fp);
} else } else
help_path = NULL; help_path = NULL;
strcpy(r, PUTTY_HELP_CONTENTS); strcpy(r, PUTTY_HELP_CONTENTS);
if ( (fp = fopen(b, "r")) != NULL) { if ( (fp = fopen(b, "r")) != NULL) {
help_has_contents = TRUE; help_has_contents = TRUE;
fclose(fp); fclose(fp);
} else } else
help_has_contents = FALSE; help_has_contents = FALSE;
strcpy(r, PUTTY_CHM_FILE); strcpy(r, PUTTY_CHM_FILE);
if ( (fp = fopen(b, "r")) != NULL) { if ( (fp = fopen(b, "r")) != NULL) {
chm_path = dupstr(b); chm_path = dupstr(b);
fclose(fp); fclose(fp);
} else } else
chm_path = NULL; chm_path = NULL;
if (chm_path) { if (chm_path) {
HINSTANCE dllHH = LoadLibrary("hhctrl.ocx"); HINSTANCE dllHH = LoadLibrary("hhctrl.ocx");
if (dllHH) { if (dllHH) {
htmlhelp = (htmlhelp_t)GetProcAddress(dllHH, "HtmlHelpA"); htmlhelp = (htmlhelp_t)GetProcAddress(dllHH, "HtmlHelpA");
if (!htmlhelp) if (!htmlhelp)
FreeLibrary(dllHH); FreeLibrary(dllHH);
} }
if (htmlhelp) if (htmlhelp)
htmlhelp(NULL, NULL, HH_INITIALIZE, (DWORD)&html_help_cookie); htmlhelp(NULL, NULL, HH_INITIALIZE, (DWORD)&html_help_cookie);
else else
chm_path = NULL; chm_path = NULL;
} }
} }
void shutdown_help(void) void shutdown_help(void)
{ {
if (chm_path) if (chm_path)
htmlhelp(NULL, NULL, HH_UNINITIALIZE, html_help_cookie); htmlhelp(NULL, NULL, HH_UNINITIALIZE, html_help_cookie);
} }
int has_help(void) int has_help(void)
{ {
/* /*
* FIXME: it would be nice here to disregard help_path on * FIXME: it would be nice here to disregard help_path on
* platforms that didn't have WINHLP32. But that's probably * platforms that didn't have WINHLP32. But that's probably
* unrealistic, since even Vista will have it if the user * unrealistic, since even Vista will have it if the user
* specifically downloads it. * specifically downloads it.
*/ */
return (help_path || chm_path); return (help_path || chm_path);
} }
void launch_help(HWND hwnd, const char *topic) void launch_help(HWND hwnd, const char *topic)
{ {
if (topic) { if (topic) {
int colonpos = strcspn(topic, ":"); int colonpos = strcspn(topic, ":");
if (chm_path) { if (chm_path) {
char *fname; char *fname;
assert(topic[colonpos] != '\0'); assert(topic[colonpos] != '\0');
fname = dupprintf("%s::/%s.html>main", chm_path, fname = dupprintf("%s::/%s.html>main", chm_path,
topic + colonpos + 1); topic + colonpos + 1);
htmlhelp(hwnd, fname, HH_DISPLAY_TOPIC, 0); htmlhelp(hwnd, fname, HH_DISPLAY_TOPIC, 0);
sfree(fname); sfree(fname);
} else if (help_path) { } else if (help_path) {
char *cmd = dupprintf("JI(`',`%.*s')", colonpos, topic); char *cmd = dupprintf("JI(`',`%.*s')", colonpos, topic);
WinHelp(hwnd, help_path, HELP_COMMAND, (DWORD)cmd); WinHelp(hwnd, help_path, HELP_COMMAND, (DWORD)cmd);
sfree(cmd); sfree(cmd);
} }
} else { } else {
if (chm_path) { if (chm_path) {
htmlhelp(hwnd, chm_path, HH_DISPLAY_TOPIC, 0); htmlhelp(hwnd, chm_path, HH_DISPLAY_TOPIC, 0);
} else if (help_path) { } else if (help_path) {
WinHelp(hwnd, help_path, WinHelp(hwnd, help_path,
help_has_contents ? HELP_FINDER : HELP_CONTENTS, 0); help_has_contents ? HELP_FINDER : HELP_CONTENTS, 0);
} }
} }
requested_help = TRUE; requested_help = TRUE;
} }
void quit_help(HWND hwnd) void quit_help(HWND hwnd)
{ {
if (requested_help) { if (requested_help) {
if (chm_path) { if (chm_path) {
htmlhelp(NULL, NULL, HH_CLOSE_ALL, 0); htmlhelp(NULL, NULL, HH_CLOSE_ALL, 0);
} else if (help_path) { } else if (help_path) {
WinHelp(hwnd, help_path, HELP_QUIT, 0); WinHelp(hwnd, help_path, HELP_QUIT, 0);
} }
requested_help = FALSE; requested_help = FALSE;
} }
} }