Skip to content

Commit

Permalink
support additional keyword files used for syntax help on vb3
Browse files Browse the repository at this point in the history
  • Loading branch information
cracyc committed Jan 8, 2020
1 parent a101e16 commit 729fac5
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 101 deletions.
16 changes: 10 additions & 6 deletions user/winhelp.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ BOOL WINAPI wine_WinHelp32A(HWND hWnd, LPCSTR lpHelpFile, UINT wCommand, ULONG_P
}
}
*success_exec = TRUE;
MULTIKEYHELPA multikey32;
MULTIKEYHELPA *multikey32 = NULL;
HELPWININFOA info32;
switch (wCommand)
{
Expand All @@ -274,11 +274,13 @@ BOOL WINAPI wine_WinHelp32A(HWND hWnd, LPCSTR lpHelpFile, UINT wCommand, ULONG_P
//this conversion is not tested.
MESSAGE("HELP_MULTIKEY\n");
LPMULTIKEYHELP16 multikey16 = (LPMULTIKEYHELP16)dwData;
multikey32.mkKeylist = multikey16->mkKeylist;
multikey32.mkSize = multikey16->mkSize - (sizeof(MULTIKEYHELPA) - sizeof(MULTIKEYHELP16));
memcpy(&multikey32.szKeyphrase, multikey16->szKeyphrase, sizeof(MULTIKEYHELP16) - offsetof(MULTIKEYHELP16, szKeyphrase));
dwData = &multikey32;
dsize = ((LPMULTIKEYHELPA)dwData)->mkSize;
size = multikey16->mkSize + (sizeof(MULTIKEYHELPA) - sizeof(MULTIKEYHELP16));
multikey32 = HeapAlloc(GetProcessHeap(), 0, size);
multikey32->mkKeylist = multikey16->mkKeylist;
multikey32->mkSize = size;
memcpy(&multikey32->szKeyphrase, multikey16->szKeyphrase, multikey16->mkSize - offsetof(MULTIKEYHELP16, szKeyphrase));
dwData = multikey32;
dsize = size;
}
break;
case HELP_SETWINPOS:
Expand Down Expand Up @@ -360,6 +362,8 @@ BOOL WINAPI wine_WinHelp32A(HWND hWnd, LPCSTR lpHelpFile, UINT wCommand, ULONG_P
ret = SendMessageA(hDest, WM_COPYDATA, (WPARAM)hWnd, (LPARAM)&cds);
RestoreThunkLock(mutex_count);
HeapFree(GetProcessHeap(), 0, lpwh);
if (multikey32)
HeapFree(GetProcessHeap(), 0, multikey32);
return ret;
}

71 changes: 44 additions & 27 deletions winhlp32/hlpfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -2336,47 +2336,63 @@ static BOOL HLPFILE_GetContext(HLPFILE *hlpfile)
*
* HLPFILE_GetTreeData
*/
static BOOL HLPFILE_GetTreeData(HLPFILE *hlpfile, BYTE **addr, char *tree, char *data)
HLPFILE_XW *HLPFILE_GetTreeData(HLPFILE *hlpfile, char keyfile)
{
BYTE *cbuf, *cend;
unsigned clen;
char tree[] = "|xWBTREE";
char data[] = "|xWDATA";
HLPFILE_XW *xw = NULL;

keyfile = toupper(keyfile);

for (int i = 0; i < 5; i++)
{
if (hlpfile->xw[i].id == keyfile)
return &hlpfile->xw[i];
if (!hlpfile->xw[i].id)
{
xw = &hlpfile->xw[i];
break;
}
}
if (!xw)
return NULL;
tree[1] = keyfile;
data[1] = keyfile;

if (!HLPFILE_FindSubFile(hlpfile, tree, &cbuf, &cend)) return FALSE;
clen = cend - cbuf;
addr[TREE] = HeapAlloc(GetProcessHeap(), 0, clen);
if (!addr[TREE]) return FALSE;
memcpy(addr[TREE], cbuf, clen);
xw->tree = HeapAlloc(GetProcessHeap(), 0, clen);
if (!xw->tree) return FALSE;
memcpy(xw->tree, cbuf, clen);

if (!HLPFILE_FindSubFile(hlpfile, data, &cbuf, &cend))
{
WINE_ERR("corrupted help file: %s present but %s absent\n", tree, data);
HeapFree(GetProcessHeap(), 0, addr[TREE]);
addr[TREE] = NULL;
return FALSE;
HeapFree(GetProcessHeap(), 0, xw->tree);
return NULL;
}
clen = cend - cbuf;
addr[DATA] = HeapAlloc(GetProcessHeap(), 0, clen);
if (!addr[DATA])
xw->data = HeapAlloc(GetProcessHeap(), 0, clen);
if (!xw->data)
{
HeapFree(GetProcessHeap(), 0, addr[DATA]);
HeapFree(GetProcessHeap(), 0, addr[TREE]);
addr[TREE] = NULL;
return FALSE;
HeapFree(GetProcessHeap(), 0, xw->data);
HeapFree(GetProcessHeap(), 0, xw->tree);
return NULL;
}
memcpy(addr[DATA], cbuf, clen);
memcpy(xw->data, cbuf, clen);
xw->id = keyfile;

return TRUE;
return xw;
}
/***********************************************************************
*
* HLPFILE_GetKeywords
*/
static BOOL HLPFILE_GetKeywords (HLPFILE *hlpfile)
static BOOL HLPFILE_GetKeywords(HLPFILE *hlpfile)
{
BOOL ret;
ret = HLPFILE_GetTreeData(hlpfile, hlpfile->kw, "|KWBTREE", "|KWDATA");
HLPFILE_GetTreeData(hlpfile, hlpfile->aw, "|AWBTREE", "|AWDATA");
return ret;
return HLPFILE_GetTreeData(hlpfile, 'K') ? TRUE : FALSE;
}


Expand Down Expand Up @@ -2523,17 +2539,18 @@ void HLPFILE_FreeHlpFile(HLPFILE* hlpfile)
HeapFree(GetProcessHeap(), 0, hlpfile->phrases_buffer);
HeapFree(GetProcessHeap(), 0, hlpfile->topic_map);
HeapFree(GetProcessHeap(), 0, hlpfile->help_on_file);
HeapFree(GetProcessHeap(), 0, hlpfile->kw[TREE]);
HeapFree(GetProcessHeap(), 0, hlpfile->kw[DATA]);
for (int i = 0; i < 5; i++)
{
if (hlpfile->xw[i].id)
{
HeapFree(GetProcessHeap(), 0, hlpfile->xw[i].tree);
HeapFree(GetProcessHeap(), 0, hlpfile->xw[i].data);
}
}
if (hlpfile->TOMap)
HeapFree(GetProcessHeap(), 0, hlpfile->TOMap);
if (hlpfile->ttlbtree)
HeapFree(GetProcessHeap(), 0, hlpfile->ttlbtree);
if (hlpfile->aw[TREE])
{
HeapFree(GetProcessHeap(), 0, hlpfile->aw[TREE]);
HeapFree(GetProcessHeap(), 0, hlpfile->aw[DATA]);
}
HeapFree(GetProcessHeap(), 0, hlpfile);
}

Expand Down
14 changes: 7 additions & 7 deletions winhlp32/hlpfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@ typedef struct
COLORREF color;
} HLPFILE_FONT;

enum
typedef struct
{
TREE,
DATA
};
char id;
BYTE *tree;
BYTE *data;
} HLPFILE_XW;

typedef struct tagHlpFileFile
{
Expand All @@ -116,8 +117,7 @@ typedef struct tagHlpFileFile
HLPFILE_PAGE* last_page;
HLPFILE_MACRO* first_macro;
BYTE* Context;
BYTE* kw[2];
BYTE* aw[2];
HLPFILE_XW xw[5];
unsigned wMapLen;
HLPFILE_MAP* Map;
unsigned wTOMapLen;
Expand Down Expand Up @@ -194,7 +194,7 @@ HLPFILE_PAGE* HLPFILE_PageByMap(HLPFILE* hlpfile, LONG lMap, ULONG* relative);
HLPFILE_PAGE* HLPFILE_PageByOffset(HLPFILE* hlpfile, LONG offset, ULONG* relative);
LONG HLPFILE_Hash(LPCSTR lpszContext);
void HLPFILE_FreeHlpFile(HLPFILE*);

HLPFILE_XW *HLPFILE_GetTreeData(HLPFILE *hlpfile, char keyfile);
void HLPFILE_BPTreeEnum(BYTE*, HLPFILE_BPTreeCallback cb, void *cookie);

struct RtfData {
Expand Down
47 changes: 2 additions & 45 deletions winhlp32/macro.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,49 +74,6 @@ static WINHELP_BUTTON** MACRO_LookupButton(WINHELP_WINDOW* win, LPCSTR na
return b;
}

static void MACRO_SearchKey(BYTE **tree, LPCSTR keywords, LONG type, LPCSTR topic, LPCSTR window)
{
DWORD ids[20], t;
int idn = 0;
char *key;
HLPFILE_PAGE *page = MACRO_CurrentWindow()->page;
if ((type > 1) || !tree[TREE]) return;
key = strtok(keywords, ";");
while (key)
{
key = HLPFILE_BPTreeSearch(tree[TREE], key, comp_xWBTreeKey);
if (key)
{
int count = *(SHORT *)(key + strlen(key) + 1);
int offset = *(ULONG *)(key + strlen(key) + 3);
for (int i = 0; i < count; i++)
{
DWORD ref = *(DWORD *)(tree[DATA] + offset + 9 + (4 * i));
if (ref == page->offset) continue;
ids[idn++] = ref;
if (idn == 20) break;
}
if (idn == 20) break;
}
key = strtok(NULL, ";");
}
if (!idn) return;
if ((type != 1) || (idn > 1))
{
struct index_data idx;
idx.hlpfile = page->file;
idx.jump = FALSE;
idx.offset = (ULONG)ids;
idx.count = idn;
t = DialogBoxParamA(NULL, MAKEINTRESOURCE(IDD_TOPIC), MACRO_CurrentWindow()->hMainWnd, WINHELP_TopicDlgProc, &idx);
if (t == 0xFFFFFFFF) return;
}
else
t = ids[0];
HLPFILE_WINDOWINFO* win = window ? WINHELP_GetWindowInfo(page->file, window) : MACRO_CurrentWindow()->info;
WINHELP_OpenHelpWindow(HLPFILE_PageByOffset, page->file, t, win, SW_NORMAL);
}

static BOOL MACRO_Load(struct MacroDesc *macro)
{
void *fn = NULL;
Expand Down Expand Up @@ -299,7 +256,7 @@ static void CALLBACK MACRO_AddAccelerator(LONG u1, LONG u2, LPCSTR str)
static void CALLBACK MACRO_ALink(LPCSTR keywords, LONG type, LPCSTR topic, LPCSTR window)
{
WINE_TRACE("(%s, %u, %s, %s)\n", debugstr_a(keywords), type, debugstr_a(topic), debugstr_a(window));
MACRO_SearchKey(MACRO_CurrentWindow()->page->file->aw, keywords, type, topic, window);
WINHELP_SearchKey('A', keywords, type, topic, window, MACRO_CurrentWindow(), MACRO_CurrentWindow()->page->file);
}

void CALLBACK MACRO_Annotate(void)
Expand Down Expand Up @@ -775,7 +732,7 @@ static void CALLBACK MACRO_JumpKeyword(LPCSTR lpszPath, LPCSTR lpszWindow, LPCST
static void CALLBACK MACRO_KLink(LPCSTR keywords, LONG type, LPCSTR topic, LPCSTR window)
{
WINE_TRACE("(%s, %u, %s, %s)\n", debugstr_a(keywords), type, debugstr_a(topic), debugstr_a(window));
MACRO_SearchKey(MACRO_CurrentWindow()->page->file->kw, keywords, type, topic, window);
WINHELP_SearchKey('K', keywords, type, topic, window, MACRO_CurrentWindow(), MACRO_CurrentWindow()->page->file);
}

static void CALLBACK MACRO_Menu(void)
Expand Down
Loading

0 comments on commit 729fac5

Please sign in to comment.