4 * Copyright 1996 Ulrich Schmid
5 * 2002, 2008 Eric Pouech
6 * 2007 Kirill K. Smirnov
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(winhelp
);
37 static inline unsigned short GET_USHORT(const BYTE
* buffer
, unsigned i
)
39 return (BYTE
)buffer
[i
] + 0x100 * (BYTE
)buffer
[i
+ 1];
42 static inline short GET_SHORT(const BYTE
* buffer
, unsigned i
)
44 return (BYTE
)buffer
[i
] + 0x100 * (signed char)buffer
[i
+1];
47 static inline unsigned GET_UINT(const BYTE
* buffer
, unsigned i
)
49 return GET_USHORT(buffer
, i
) + 0x10000 * GET_USHORT(buffer
, i
+ 2);
52 static HLPFILE
*first_hlpfile
= 0;
63 static BOOL
HLPFILE_DoReadHlpFile(HLPFILE
*, LPCSTR
);
64 static BOOL
HLPFILE_ReadFileToBuffer(HLPFILE
*, HFILE
);
65 static BOOL
HLPFILE_FindSubFile(HLPFILE
*, LPCSTR
, BYTE
**, BYTE
**);
66 static BOOL
HLPFILE_SystemCommands(HLPFILE
*);
67 static INT
HLPFILE_UncompressedLZ77_Size(BYTE
*ptr
, BYTE
*end
);
68 static BYTE
* HLPFILE_UncompressLZ77(BYTE
*ptr
, BYTE
*end
, BYTE
*newptr
);
69 static BOOL
HLPFILE_UncompressLZ77_Phrases(HLPFILE
*);
70 static BOOL
HLPFILE_Uncompress_Phrases40(HLPFILE
*);
71 static BOOL
HLPFILE_Uncompress_Topic(HLPFILE
*);
72 static BOOL
HLPFILE_GetContext(HLPFILE
*);
73 static BOOL
HLPFILE_GetKeywords(HLPFILE
*);
74 static BOOL
HLPFILE_GetMap(HLPFILE
*);
75 static BOOL
HLPFILE_AddPage(HLPFILE
*, BYTE
*, BYTE
*, unsigned);
76 static BOOL
HLPFILE_AddParagraph(HLPFILE
*, BYTE
*, BYTE
*, unsigned*);
77 static void HLPFILE_Uncompress2(HLPFILE
*, const BYTE
*, const BYTE
*, BYTE
*, const BYTE
*);
78 static BOOL
HLPFILE_Uncompress3(HLPFILE
*, char*, const char*, const BYTE
*, const BYTE
*);
79 static void HLPFILE_UncompressRLE(const BYTE
* src
, const BYTE
* end
, BYTE
** dst
, unsigned dstsz
);
80 static BOOL
HLPFILE_ReadFont(HLPFILE
* hlpfile
);
82 /***********************************************************************
84 * HLPFILE_PageByNumber
86 static HLPFILE_PAGE
*HLPFILE_PageByNumber(HLPFILE
* hlpfile
, UINT wNum
)
91 WINE_TRACE("<%s>[%u]\n", hlpfile
->lpszPath
, wNum
);
93 for (page
= hlpfile
->first_page
; page
&& temp
; page
= page
->next
) temp
--;
95 WINE_ERR("Page of number %u not found in file %s\n", wNum
, hlpfile
->lpszPath
);
100 * this finds the page containing the offset. The offset can either
101 * refer to the top of the page (offset == page->offset), or
102 * to some paragraph inside the page...
103 * As of today, we only return the page... we should also return
104 * a paragraph, and then, while opening a new page, compute the
105 * y-offset of the paragraph to be shown and scroll the window
108 /******************************************************************
109 * HLPFILE_PageByOffset
113 HLPFILE_PAGE
*HLPFILE_PageByOffset(HLPFILE
* hlpfile
, LONG offset
)
118 if (!hlpfile
) return 0;
120 WINE_TRACE("<%s>[%x]\n", hlpfile
->lpszPath
, offset
);
122 if (offset
== 0xFFFFFFFF) return NULL
;
125 for (found
= NULL
, page
= hlpfile
->first_page
; page
; page
= page
->next
)
127 if (page
->offset
<= offset
&& (!found
|| found
->offset
< page
->offset
))
131 WINE_ERR("Page of offset %u not found in file %s\n",
132 offset
, hlpfile
->lpszPath
);
136 /**************************************************************************
139 * HLPFILE_BPTreeCompare function for '|CONTEXT' B+ tree file
142 static int comp_PageByHash(void *p
, const void *key
,
143 int leaf
, void** next
)
145 LONG lKey
= (LONG_PTR
)key
;
146 LONG lTest
= (INT
)GET_UINT(p
, 0);
148 *next
= (char *)p
+(leaf
?8:6);
149 WINE_TRACE("Comparing '%d' with '%d'\n", lKey
, lTest
);
150 if (lTest
< lKey
) return -1;
151 if (lTest
> lKey
) return 1;
155 /***********************************************************************
157 * HLPFILE_HlpFilePageByHash
159 HLPFILE_PAGE
*HLPFILE_PageByHash(HLPFILE
* hlpfile
, LONG lHash
)
163 if (!hlpfile
) return 0;
165 WINE_TRACE("<%s>[%x]\n", hlpfile
->lpszPath
, lHash
);
167 /* For win 3.0 files hash values are really page numbers */
168 if (hlpfile
->version
<= 16)
169 return HLPFILE_PageByNumber(hlpfile
, lHash
);
171 ptr
= HLPFILE_BPTreeSearch(hlpfile
->Context
, LongToPtr(lHash
), comp_PageByHash
);
174 WINE_ERR("Page of hash %x not found in file %s\n", lHash
, hlpfile
->lpszPath
);
178 return HLPFILE_PageByOffset(hlpfile
, GET_UINT(ptr
, 4));
181 /***********************************************************************
185 HLPFILE_PAGE
*HLPFILE_PageByMap(HLPFILE
* hlpfile
, LONG lMap
)
189 if (!hlpfile
) return 0;
191 WINE_TRACE("<%s>[%x]\n", hlpfile
->lpszPath
, lMap
);
193 for (i
= 0; i
< hlpfile
->wMapLen
; i
++)
195 if (hlpfile
->Map
[i
].lMap
== lMap
)
196 return HLPFILE_PageByOffset(hlpfile
, hlpfile
->Map
[i
].offset
);
199 WINE_ERR("Page of Map %x not found in file %s\n", lMap
, hlpfile
->lpszPath
);
203 /***********************************************************************
207 HLPFILE_PAGE
* HLPFILE_Contents(HLPFILE
*hlpfile
)
209 HLPFILE_PAGE
* page
= NULL
;
211 if (!hlpfile
) return NULL
;
213 page
= HLPFILE_PageByOffset(hlpfile
, hlpfile
->contents_start
);
214 if (!page
) page
= hlpfile
->first_page
;
218 /***********************************************************************
222 LONG
HLPFILE_Hash(LPCSTR lpszContext
)
227 while ((c
= *lpszContext
++))
230 if (c
>= 'A' && c
<= 'Z') x
= c
- 'A' + 17;
231 if (c
>= 'a' && c
<= 'z') x
= c
- 'a' + 17;
232 if (c
>= '1' && c
<= '9') x
= c
- '0';
233 if (c
== '0') x
= 10;
234 if (c
== '.') x
= 12;
235 if (c
== '_') x
= 13;
236 if (x
) lHash
= lHash
* 43 + x
;
241 /***********************************************************************
243 * HLPFILE_ReadHlpFile
245 HLPFILE
*HLPFILE_ReadHlpFile(LPCSTR lpszPath
)
249 for (hlpfile
= first_hlpfile
; hlpfile
; hlpfile
= hlpfile
->next
)
251 if (!strcmp(lpszPath
, hlpfile
->lpszPath
))
253 hlpfile
->wRefCount
++;
258 hlpfile
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
259 sizeof(HLPFILE
) + lstrlen(lpszPath
) + 1);
260 if (!hlpfile
) return 0;
262 hlpfile
->lpszPath
= (char*)hlpfile
+ sizeof(HLPFILE
);
263 hlpfile
->contents_start
= 0xFFFFFFFF;
264 hlpfile
->next
= first_hlpfile
;
265 hlpfile
->wRefCount
= 1;
267 strcpy(hlpfile
->lpszPath
, lpszPath
);
269 first_hlpfile
= hlpfile
;
270 if (hlpfile
->next
) hlpfile
->next
->prev
= hlpfile
;
272 if (!HLPFILE_DoReadHlpFile(hlpfile
, lpszPath
))
274 HLPFILE_FreeHlpFile(hlpfile
);
281 /***********************************************************************
283 * HLPFILE_DoReadHlpFile
285 static BOOL
HLPFILE_DoReadHlpFile(HLPFILE
*hlpfile
, LPCSTR lpszPath
)
292 unsigned index
, old_index
, offset
, len
, offs
;
294 hFile
= OpenFile(lpszPath
, &ofs
, OF_READ
);
295 if (hFile
== HFILE_ERROR
) return FALSE
;
297 ret
= HLPFILE_ReadFileToBuffer(hlpfile
, hFile
);
299 if (!ret
) return FALSE
;
301 if (!HLPFILE_SystemCommands(hlpfile
)) return FALSE
;
303 /* load phrases support */
304 if (!HLPFILE_UncompressLZ77_Phrases(hlpfile
))
305 HLPFILE_Uncompress_Phrases40(hlpfile
);
307 if (!HLPFILE_Uncompress_Topic(hlpfile
)) return FALSE
;
308 if (!HLPFILE_ReadFont(hlpfile
)) return FALSE
;
310 buf
= hlpfile
->topic_map
[0];
317 if (hlpfile
->version
<= 16)
319 index
= (ref
- 0x0C) / hlpfile
->dsize
;
320 offset
= (ref
- 0x0C) % hlpfile
->dsize
;
324 index
= (ref
- 0x0C) >> 14;
325 offset
= (ref
- 0x0C) & 0x3FFF;
328 if (hlpfile
->version
<= 16 && index
!= old_index
&& index
!= 0)
330 /* we jumped to the next block, adjust pointers */
335 WINE_TRACE("ref=%08x => [%u/%u]\n", ref
, index
, offset
);
337 if (index
>= hlpfile
->topic_maplen
) {WINE_WARN("maplen\n"); break;}
338 buf
= hlpfile
->topic_map
[index
] + offset
;
339 if (buf
+ 0x15 >= hlpfile
->topic_end
) {WINE_WARN("extra\n"); break;}
340 end
= min(buf
+ GET_UINT(buf
, 0), hlpfile
->topic_end
);
341 if (index
!= old_index
) {offs
= 0; old_index
= index
;}
346 if (!HLPFILE_AddPage(hlpfile
, buf
, end
, index
* 0x8000L
+ offs
)) return FALSE
;
352 if (!HLPFILE_AddParagraph(hlpfile
, buf
, end
, &len
)) return FALSE
;
357 WINE_ERR("buf[0x14] = %x\n", buf
[0x14]);
360 if (hlpfile
->version
<= 16)
362 ref
+= GET_UINT(buf
, 0xc);
363 if (GET_UINT(buf
, 0xc) == 0)
367 ref
= GET_UINT(buf
, 0xc);
368 } while (ref
!= 0xffffffff);
370 HLPFILE_GetKeywords(hlpfile
);
371 HLPFILE_GetMap(hlpfile
);
372 if (hlpfile
->version
<= 16) return TRUE
;
373 return HLPFILE_GetContext(hlpfile
);
376 /***********************************************************************
380 static BOOL
HLPFILE_AddPage(HLPFILE
*hlpfile
, BYTE
*buf
, BYTE
*end
, unsigned offset
)
384 UINT titlesize
, blocksize
, datalen
;
388 blocksize
= GET_UINT(buf
, 0);
389 datalen
= GET_UINT(buf
, 0x10);
390 title
= buf
+ datalen
;
391 if (title
> end
) {WINE_WARN("page2\n"); return FALSE
;};
393 titlesize
= GET_UINT(buf
, 4);
394 page
= HeapAlloc(GetProcessHeap(), 0, sizeof(HLPFILE_PAGE
) + titlesize
+ 1);
395 if (!page
) return FALSE
;
396 page
->lpszTitle
= (char*)page
+ sizeof(HLPFILE_PAGE
);
398 if (titlesize
> blocksize
- datalen
)
400 /* need to decompress */
401 if (hlpfile
->hasPhrases
)
402 HLPFILE_Uncompress2(hlpfile
, title
, end
, (BYTE
*)page
->lpszTitle
, (BYTE
*)page
->lpszTitle
+ titlesize
);
403 else if (hlpfile
->hasPhrases40
)
404 HLPFILE_Uncompress3(hlpfile
, page
->lpszTitle
, page
->lpszTitle
+ titlesize
, title
, end
);
407 WINE_FIXME("Text size is too long, splitting\n");
408 titlesize
= blocksize
- datalen
;
409 memcpy(page
->lpszTitle
, title
, titlesize
);
413 memcpy(page
->lpszTitle
, title
, titlesize
);
415 page
->lpszTitle
[titlesize
] = '\0';
417 if (hlpfile
->first_page
)
419 hlpfile
->last_page
->next
= page
;
420 page
->prev
= hlpfile
->last_page
;
421 hlpfile
->last_page
= page
;
425 hlpfile
->first_page
= page
;
426 hlpfile
->last_page
= page
;
430 page
->file
= hlpfile
;
432 page
->first_paragraph
= NULL
;
433 page
->first_macro
= NULL
;
434 page
->wNumber
= GET_UINT(buf
, 0x21);
435 page
->offset
= offset
;
437 page
->browse_bwd
= GET_UINT(buf
, 0x19);
438 page
->browse_fwd
= GET_UINT(buf
, 0x1D);
440 WINE_TRACE("Added page[%d]: title='%s' %08x << %08x >> %08x\n",
441 page
->wNumber
, page
->lpszTitle
,
442 page
->browse_bwd
, page
->offset
, page
->browse_fwd
);
444 memset(&attributes
, 0, sizeof(attributes
));
446 /* now load macros */
447 ptr
= page
->lpszTitle
+ strlen(page
->lpszTitle
) + 1;
448 while (ptr
< page
->lpszTitle
+ titlesize
)
450 unsigned len
= strlen(ptr
);
453 WINE_TRACE("macro: %s\n", ptr
);
454 macro
= HeapAlloc(GetProcessHeap(), 0, sizeof(HLPFILE_MACRO
) + len
+ 1);
455 macro
->lpszMacro
= macro_str
= (char*)(macro
+ 1);
456 memcpy(macro_str
, ptr
, len
+ 1);
457 /* FIXME: shall we really link macro in reverse order ??
458 * may produce strange results when played at page opening
460 macro
->next
= page
->first_macro
;
461 page
->first_macro
= macro
;
468 static long fetch_long(BYTE
** ptr
)
474 ret
= (*(unsigned long*)(*ptr
) - 0x80000000L
) / 2;
479 ret
= (*(unsigned short*)(*ptr
) - 0x8000) / 2;
486 static unsigned long fetch_ulong(BYTE
** ptr
)
492 ret
= *(unsigned long*)(*ptr
) / 2;
497 ret
= *(unsigned short*)(*ptr
) / 2;
503 static short fetch_short(BYTE
** ptr
)
509 ret
= (*(unsigned short*)(*ptr
) - 0x8000) / 2;
514 ret
= (*(unsigned char*)(*ptr
) - 0x80) / 2;
520 static unsigned short fetch_ushort(BYTE
** ptr
)
526 ret
= *(unsigned short*)(*ptr
) / 2;
531 ret
= *(unsigned char*)(*ptr
) / 2;
537 /******************************************************************
538 * HLPFILE_DecompressGfx
540 * Decompress the data part of a bitmap or a metafile
542 static BYTE
* HLPFILE_DecompressGfx(BYTE
* src
, unsigned csz
, unsigned sz
, BYTE packing
)
549 WINE_TRACE("Unpacking (%d) from %u bytes to %u bytes\n", packing
, csz
, sz
);
553 case 0: /* uncompressed */
555 WINE_WARN("Bogus gfx sizes (uncompressed): %u / %u\n", sz
, csz
);
559 tmp
= dst
= HeapAlloc(GetProcessHeap(), 0, sz
);
560 if (!dst
) return NULL
;
561 HLPFILE_UncompressRLE(src
, src
+ csz
, &tmp
, sz
);
563 WINE_WARN("Bogus gfx sizes (RunLen): %lu/%u\n", (SIZE_T
)(tmp
- dst
), sz
);
566 sz77
= HLPFILE_UncompressedLZ77_Size(src
, src
+ csz
);
567 dst
= HeapAlloc(GetProcessHeap(), 0, sz77
);
568 if (!dst
) return NULL
;
569 HLPFILE_UncompressLZ77(src
, src
+ csz
, dst
);
571 WINE_WARN("Bogus gfx sizes (LZ77): %u / %u\n", sz77
, sz
);
573 case 3: /* LZ77 then RLE */
574 sz77
= HLPFILE_UncompressedLZ77_Size(src
, src
+ csz
);
575 tmp
= HeapAlloc(GetProcessHeap(), 0, sz77
);
576 if (!tmp
) return FALSE
;
577 HLPFILE_UncompressLZ77(src
, src
+ csz
, tmp
);
578 dst
= tmp2
= HeapAlloc(GetProcessHeap(), 0, sz
);
581 HeapFree(GetProcessHeap(), 0, tmp
);
584 HLPFILE_UncompressRLE(tmp
, tmp
+ sz77
, &tmp2
, sz
);
585 if (tmp2
- dst
!= sz
)
586 WINE_WARN("Bogus gfx sizes (LZ77+RunLen): %lu / %u\n", (SIZE_T
)(tmp2
- dst
), sz
);
587 HeapFree(GetProcessHeap(), 0, tmp
);
590 WINE_FIXME("Unsupported packing %u\n", packing
);
596 /******************************************************************
601 static BOOL
HLPFILE_LoadBitmap(BYTE
* beg
, BYTE type
, BYTE pack
,
602 HLPFILE_PARAGRAPH
* paragraph
)
607 unsigned long off
, csz
;
610 bi
= HeapAlloc(GetProcessHeap(), 0, sizeof(*bi
));
611 if (!bi
) return FALSE
;
613 ptr
= beg
+ 2; /* for type and pack */
615 bi
->bmiHeader
.biSize
= sizeof(bi
->bmiHeader
);
616 bi
->bmiHeader
.biXPelsPerMeter
= fetch_ulong(&ptr
);
617 bi
->bmiHeader
.biYPelsPerMeter
= fetch_ulong(&ptr
);
618 bi
->bmiHeader
.biPlanes
= fetch_ushort(&ptr
);
619 bi
->bmiHeader
.biBitCount
= fetch_ushort(&ptr
);
620 bi
->bmiHeader
.biWidth
= fetch_ulong(&ptr
);
621 bi
->bmiHeader
.biHeight
= fetch_ulong(&ptr
);
622 bi
->bmiHeader
.biClrUsed
= fetch_ulong(&ptr
);
623 bi
->bmiHeader
.biClrImportant
= fetch_ulong(&ptr
);
624 bi
->bmiHeader
.biCompression
= BI_RGB
;
625 if (bi
->bmiHeader
.biBitCount
> 32) WINE_FIXME("Unknown bit count %u\n", bi
->bmiHeader
.biBitCount
);
626 if (bi
->bmiHeader
.biPlanes
!= 1) WINE_FIXME("Unsupported planes %u\n", bi
->bmiHeader
.biPlanes
);
627 bi
->bmiHeader
.biSizeImage
= (((bi
->bmiHeader
.biWidth
* bi
->bmiHeader
.biBitCount
+ 31) & ~31) / 8) * bi
->bmiHeader
.biHeight
;
628 WINE_TRACE("planes=%d bc=%d size=(%d,%d)\n",
629 bi
->bmiHeader
.biPlanes
, bi
->bmiHeader
.biBitCount
,
630 bi
->bmiHeader
.biWidth
, bi
->bmiHeader
.biHeight
);
632 csz
= fetch_ulong(&ptr
);
633 fetch_ulong(&ptr
); /* hotspot size */
635 off
= GET_UINT(ptr
, 0); ptr
+= 4;
636 /* GET_UINT(ptr, 0); hotspot offset */ ptr
+= 4;
638 /* now read palette info */
641 unsigned nc
= bi
->bmiHeader
.biClrUsed
;
644 /* not quite right, especially for bitfields type of compression */
645 if (!nc
&& bi
->bmiHeader
.biBitCount
<= 8)
646 nc
= 1 << bi
->bmiHeader
.biBitCount
;
648 bi
= HeapReAlloc(GetProcessHeap(), 0, bi
, sizeof(*bi
) + nc
* sizeof(RGBQUAD
));
649 if (!bi
) return FALSE
;
650 for (i
= 0; i
< nc
; i
++)
652 bi
->bmiColors
[i
].rgbBlue
= ptr
[0];
653 bi
->bmiColors
[i
].rgbGreen
= ptr
[1];
654 bi
->bmiColors
[i
].rgbRed
= ptr
[2];
655 bi
->bmiColors
[i
].rgbReserved
= 0;
659 pict_beg
= HLPFILE_DecompressGfx(beg
+ off
, csz
, bi
->bmiHeader
.biSizeImage
, pack
);
661 paragraph
->u
.gfx
.u
.bmp
.hBitmap
= CreateDIBitmap(hdc
= GetDC(0), &bi
->bmiHeader
,
665 if (!paragraph
->u
.gfx
.u
.bmp
.hBitmap
)
666 WINE_ERR("Couldn't create bitmap\n");
668 HeapFree(GetProcessHeap(), 0, bi
);
669 if (pict_beg
!= beg
+ off
) HeapFree(GetProcessHeap(), 0, pict_beg
);
674 /******************************************************************
675 * HLPFILE_LoadMetaFile
679 static BOOL
HLPFILE_LoadMetaFile(BYTE
* beg
, BYTE pack
, HLPFILE_PARAGRAPH
* paragraph
)
682 unsigned long size
, csize
;
683 unsigned long off
, hsoff
;
685 LPMETAFILEPICT lpmfp
;
687 WINE_TRACE("Loading metafile\n");
689 ptr
= beg
+ 2; /* for type and pack */
691 lpmfp
= ¶graph
->u
.gfx
.u
.mfp
;
692 lpmfp
->mm
= fetch_ushort(&ptr
); /* mapping mode */
694 lpmfp
->xExt
= GET_USHORT(ptr
, 0);
695 lpmfp
->yExt
= GET_USHORT(ptr
, 2);
698 size
= fetch_ulong(&ptr
); /* decompressed size */
699 csize
= fetch_ulong(&ptr
); /* compressed size */
700 fetch_ulong(&ptr
); /* hotspot size */
701 off
= GET_UINT(ptr
, 0);
702 hsoff
= GET_UINT(ptr
, 4);
705 WINE_TRACE("sz=%lu csz=%lu (%d,%d) offs=%lu/%lu,%lu\n",
706 size
, csize
, lpmfp
->xExt
, lpmfp
->yExt
, off
, (SIZE_T
)(ptr
- beg
), hsoff
);
708 bits
= HLPFILE_DecompressGfx(beg
+ off
, csize
, size
, pack
);
709 if (!bits
) return FALSE
;
711 paragraph
->cookie
= para_metafile
;
713 lpmfp
->hMF
= SetMetaFileBitsEx(size
, bits
);
716 WINE_FIXME("Couldn't load metafile\n");
718 if (bits
!= beg
+ off
) HeapFree(GetProcessHeap(), 0, bits
);
723 /******************************************************************
724 * HLPFILE_LoadGfxByAddr
728 static BOOL
HLPFILE_LoadGfxByAddr(HLPFILE
*hlpfile
, BYTE
* ref
,
730 HLPFILE_PARAGRAPH
* paragraph
)
734 numpict
= GET_USHORT(ref
, 2);
735 WINE_TRACE("Got picture magic=%04x #=%d\n",
736 GET_USHORT(ref
, 0), numpict
);
738 for (i
= 0; i
< numpict
; i
++)
744 WINE_TRACE("Offset[%d] = %x\n", i
, GET_UINT(ref
, (1 + i
) * 4));
745 beg
= ptr
= ref
+ GET_UINT(ref
, (1 + i
) * 4);
752 case 5: /* device dependent bmp */
753 case 6: /* device independent bmp */
754 HLPFILE_LoadBitmap(beg
, type
, pack
, paragraph
);
757 HLPFILE_LoadMetaFile(beg
, pack
, paragraph
);
759 default: WINE_FIXME("Unknown type %u\n", type
); return FALSE
;
762 /* FIXME: hotspots */
764 /* FIXME: implement support for multiple picture format */
765 if (numpict
!= 1) WINE_FIXME("Supporting only one bitmap format per logical bitmap (for now). Using first format\n");
771 /******************************************************************
772 * HLPFILE_LoadGfxByIndex
776 static BOOL
HLPFILE_LoadGfxByIndex(HLPFILE
*hlpfile
, unsigned index
,
777 HLPFILE_PARAGRAPH
* paragraph
)
783 WINE_TRACE("Loading picture #%d\n", index
);
785 if (index
< hlpfile
->numBmps
&& hlpfile
->bmps
[index
] != NULL
)
787 paragraph
->u
.gfx
.u
.bmp
.hBitmap
= hlpfile
->bmps
[index
];
791 sprintf(tmp
, "|bm%u", index
);
793 if (!HLPFILE_FindSubFile(hlpfile
, tmp
, &ref
, &end
)) {WINE_WARN("no sub file\n"); return FALSE
;}
797 ret
= HLPFILE_LoadGfxByAddr(hlpfile
, ref
, end
- ref
, paragraph
);
800 if (ret
&& paragraph
->cookie
== para_bitmap
)
802 if (index
>= hlpfile
->numBmps
)
804 hlpfile
->numBmps
= index
+ 1;
806 hlpfile
->bmps
= HeapReAlloc(GetProcessHeap(), 0, hlpfile
->bmps
,
807 hlpfile
->numBmps
* sizeof(hlpfile
->bmps
[0]));
809 hlpfile
->bmps
= HeapAlloc(GetProcessHeap(), 0,
810 hlpfile
->numBmps
* sizeof(hlpfile
->bmps
[0]));
813 hlpfile
->bmps
[index
] = paragraph
->u
.gfx
.u
.bmp
.hBitmap
;
818 /******************************************************************
823 static HLPFILE_LINK
* HLPFILE_AllocLink(int cookie
, const char* str
, LONG hash
,
824 BOOL clrChange
, unsigned wnd
)
829 /* FIXME: should build a string table for the attributes.link.lpszPath
830 * they are reallocated for each link
832 link
= HeapAlloc(GetProcessHeap(), 0, sizeof(HLPFILE_LINK
) + strlen(str
) + 1);
833 if (!link
) return NULL
;
835 link
->cookie
= cookie
;
836 link
->lpszString
= link_str
= (char*)link
+ sizeof(HLPFILE_LINK
);
837 strcpy(link_str
, str
);
839 link
->bClrChange
= clrChange
? 1 : 0;
843 WINE_TRACE("Link[%d] to %s@%08x:%d\n",
844 link
->cookie
, link
->lpszString
,
845 link
->lHash
, link
->window
);
849 /***********************************************************************
851 * HLPFILE_AddParagraph
853 static BOOL
HLPFILE_AddParagraph(HLPFILE
*hlpfile
, BYTE
*buf
, BYTE
*end
, unsigned* len
)
856 HLPFILE_PARAGRAPH
*paragraph
, **paragraphptr
;
858 BYTE
*format
, *format_end
;
859 char *text
, *text_base
, *text_end
;
860 long size
, blocksize
, datalen
;
862 unsigned nc
, ncol
= 1;
864 if (!hlpfile
->last_page
) {WINE_WARN("no page\n"); return FALSE
;};
865 page
= hlpfile
->last_page
;
866 for (paragraphptr
= &page
->first_paragraph
; *paragraphptr
;
867 paragraphptr
= &(*paragraphptr
)->next
) /* Nothing */;
869 if (buf
+ 0x19 > end
) {WINE_WARN("header too small\n"); return FALSE
;};
871 blocksize
= GET_UINT(buf
, 0);
872 size
= GET_UINT(buf
, 0x4);
873 datalen
= GET_UINT(buf
, 0x10);
874 text
= text_base
= HeapAlloc(GetProcessHeap(), 0, size
);
875 if (!text
) return FALSE
;
876 if (size
> blocksize
- datalen
)
878 /* need to decompress */
879 if (hlpfile
->hasPhrases
)
880 HLPFILE_Uncompress2(hlpfile
, buf
+ datalen
, end
, (BYTE
*)text
, (BYTE
*)text
+ size
);
881 else if (hlpfile
->hasPhrases40
)
882 HLPFILE_Uncompress3(hlpfile
, text
, text
+ size
, buf
+ datalen
, end
);
885 WINE_FIXME("Text size is too long, splitting\n");
886 size
= blocksize
- datalen
;
887 memcpy(text
, buf
+ datalen
, size
);
891 memcpy(text
, buf
+ datalen
, size
);
893 text_end
= text
+ size
;
896 format_end
= buf
+ GET_UINT(buf
, 0x10);
898 if (buf
[0x14] == 0x20 || buf
[0x14] == 0x23)
901 *len
= fetch_ushort(&format
);
903 else *len
= end
-buf
-15;
905 if (buf
[0x14] == 0x23)
911 WINE_TRACE("#cols %u\n", ncol
);
913 if (type
== 0 || type
== 2)
918 for (nc
= 0; nc
< ncol
; nc
++)
920 WINE_TRACE("looking for format at offset %lu for column %d\n", (SIZE_T
)(format
- (buf
+ 0x15)), nc
);
921 if (buf
[0x14] == 0x23)
923 if (buf
[0x14] == 0x01)
927 bits
= GET_USHORT(format
, 0); format
+= 2;
928 if (bits
& 0x0001) fetch_long(&format
);
929 if (bits
& 0x0002) fetch_short(&format
);
930 if (bits
& 0x0004) fetch_short(&format
);
931 if (bits
& 0x0008) fetch_short(&format
);
932 if (bits
& 0x0010) fetch_short(&format
);
933 if (bits
& 0x0020) fetch_short(&format
);
934 if (bits
& 0x0040) fetch_short(&format
);
935 if (bits
& 0x0100) format
+= 3;
938 int ntab
= fetch_short(&format
);
943 ts
= fetch_ushort(&format
);
944 if (ts
& 0x4000) fetch_ushort(&format
);
947 /* 0x0400, 0x0800 and 0x1000 don't need space */
948 if ((bits
& 0xE080) != 0)
949 WINE_FIXME("Unsupported bits %04x, potential trouble ahead\n", bits
);
951 while (text
< text_end
&& format
< format_end
)
953 WINE_TRACE("Got text: %s (%p/%p - %p/%p)\n", wine_dbgstr_a(text
), text
, text_end
, format
, format_end
);
954 textsize
= strlen(text
) + 1;
957 paragraph
= HeapAlloc(GetProcessHeap(), 0,
958 sizeof(HLPFILE_PARAGRAPH
) + textsize
);
959 if (!paragraph
) return FALSE
;
960 *paragraphptr
= paragraph
;
961 paragraphptr
= ¶graph
->next
;
963 paragraph
->next
= NULL
;
964 paragraph
->link
= attributes
.link
;
965 if (paragraph
->link
) paragraph
->link
->wRefCount
++;
966 paragraph
->cookie
= para_normal_text
;
967 paragraph
->u
.text
.wFont
= attributes
.wFont
;
968 paragraph
->u
.text
.wVSpace
= attributes
.wVSpace
;
969 paragraph
->u
.text
.wHSpace
= attributes
.wHSpace
;
970 paragraph
->u
.text
.wIndent
= attributes
.wIndent
;
971 paragraph
->u
.text
.lpszText
= (char*)paragraph
+ sizeof(HLPFILE_PARAGRAPH
);
972 strcpy(paragraph
->u
.text
.lpszText
, text
);
974 attributes
.wVSpace
= 0;
975 attributes
.wHSpace
= 0;
977 /* else: null text, keep on storing attributes */
986 WINE_TRACE("format=%02x\n", *format
);
990 WINE_FIXME("NIY20\n");
995 WINE_FIXME("NIY21\n");
1000 attributes
.wFont
= GET_USHORT(format
, 1);
1001 WINE_TRACE("Changing font to %d\n", attributes
.wFont
);
1006 attributes
.wVSpace
++;
1011 attributes
.wVSpace
++;
1012 attributes
.wIndent
= 0;
1017 attributes
.wIndent
++;
1031 BYTE pos
= (*format
- 0x86);
1032 BYTE type
= format
[1];
1036 size
= fetch_long(&format
);
1038 paragraph
= HeapAlloc(GetProcessHeap(), 0,
1039 sizeof(HLPFILE_PARAGRAPH
) + textsize
);
1040 if (!paragraph
) return FALSE
;
1041 *paragraphptr
= paragraph
;
1042 paragraphptr
= ¶graph
->next
;
1044 paragraph
->next
= NULL
;
1045 paragraph
->link
= attributes
.link
;
1046 if (paragraph
->link
) paragraph
->link
->wRefCount
++;
1047 paragraph
->cookie
= para_bitmap
;
1048 paragraph
->u
.gfx
.pos
= pos
;
1052 fetch_ushort(&format
); /* hot spot */
1055 switch (GET_SHORT(format
, 0))
1058 HLPFILE_LoadGfxByIndex(hlpfile
, GET_SHORT(format
, 2),
1062 WINE_FIXME("does it work ??? %x<%lu>#%u\n",
1063 GET_SHORT(format
, 0),
1064 size
, GET_SHORT(format
, 2));
1065 HLPFILE_LoadGfxByAddr(hlpfile
, format
+ 2, size
- 4,
1069 WINE_FIXME("??? %u\n", GET_SHORT(format
, 0));
1074 WINE_FIXME("Got an embedded element %s\n", format
+ 6);
1077 WINE_FIXME("Got a type %d picture\n", type
);
1080 if (attributes
.wVSpace
) paragraph
->u
.gfx
.pos
|= 0x8000;
1087 HLPFILE_FreeLink(attributes
.link
);
1088 attributes
.link
= NULL
;
1094 WINE_FIXME("NIY non-break space/hyphen\n");
1106 WINE_TRACE("macro => %s\n", format
+ 3);
1107 HLPFILE_FreeLink(attributes
.link
);
1108 attributes
.link
= HLPFILE_AllocLink(hlp_link_macro
, (const char*)format
+ 3,
1109 0, !(*format
& 4), -1);
1110 format
+= 3 + GET_USHORT(format
, 1);
1115 WINE_WARN("jump topic 1 => %u\n", GET_UINT(format
, 1));
1116 HLPFILE_FreeLink(attributes
.link
);
1117 attributes
.link
= HLPFILE_AllocLink((*format
& 1) ? hlp_link_link
: hlp_link_popup
,
1119 GET_UINT(format
, 1)-16,
1130 HLPFILE_FreeLink(attributes
.link
);
1131 attributes
.link
= HLPFILE_AllocLink((*format
& 1) ? hlp_link_link
: hlp_link_popup
,
1133 GET_UINT(format
, 1),
1134 !(*format
& 4), -1);
1143 char* ptr
= (char*) format
+ 8;
1144 BYTE type
= format
[3];
1148 if (type
== 1) wnd
= *ptr
++;
1149 if (type
== 4 || type
== 6)
1152 ptr
+= strlen(ptr
) + 1;
1155 str
= hlpfile
->lpszPath
;
1158 for (wnd
= hlpfile
->numWindows
- 1; wnd
>= 0; wnd
--)
1160 if (!strcmp(ptr
, hlpfile
->windows
[wnd
].name
)) break;
1163 WINE_WARN("Couldn't find window info for %s\n", ptr
);
1165 HLPFILE_FreeLink(attributes
.link
);
1166 attributes
.link
= HLPFILE_AllocLink((*format
& 4) ? hlp_link_link
: hlp_link_popup
,
1167 str
, GET_UINT(format
, 4),
1168 !(*format
& 1), wnd
);
1170 format
+= 3 + GET_USHORT(format
, 1);
1174 WINE_WARN("format %02x\n", *format
);
1179 HeapFree(GetProcessHeap(), 0, text_base
);
1183 /******************************************************************
1188 static BOOL
HLPFILE_ReadFont(HLPFILE
* hlpfile
)
1191 unsigned i
, len
, idx
;
1192 unsigned face_num
, dscr_num
, face_offset
, dscr_offset
;
1195 if (!HLPFILE_FindSubFile(hlpfile
, "|FONT", &ref
, &end
))
1197 WINE_WARN("no subfile FONT\n");
1198 hlpfile
->numFonts
= 0;
1199 hlpfile
->fonts
= NULL
;
1205 face_num
= GET_USHORT(ref
, 0);
1206 dscr_num
= GET_USHORT(ref
, 2);
1207 face_offset
= GET_USHORT(ref
, 4);
1208 dscr_offset
= GET_USHORT(ref
, 6);
1210 WINE_TRACE("Got NumFacenames=%u@%u NumDesc=%u@%u\n",
1211 face_num
, face_offset
, dscr_num
, dscr_offset
);
1213 hlpfile
->numFonts
= dscr_num
;
1214 hlpfile
->fonts
= HeapAlloc(GetProcessHeap(), 0, sizeof(HLPFILE_FONT
) * dscr_num
);
1216 len
= (dscr_offset
- face_offset
) / face_num
;
1217 /* EPP for (i = face_offset; i < dscr_offset; i += len) */
1218 /* EPP WINE_FIXME("[%d]: %*s\n", i / len, len, ref + i); */
1219 for (i
= 0; i
< dscr_num
; i
++)
1221 flag
= ref
[dscr_offset
+ i
* 11 + 0];
1222 family
= ref
[dscr_offset
+ i
* 11 + 2];
1224 hlpfile
->fonts
[i
].LogFont
.lfHeight
= -ref
[dscr_offset
+ i
* 11 + 1] / 2 - 3;
1225 hlpfile
->fonts
[i
].LogFont
.lfWidth
= 0;
1226 hlpfile
->fonts
[i
].LogFont
.lfEscapement
= 0;
1227 hlpfile
->fonts
[i
].LogFont
.lfOrientation
= 0;
1228 hlpfile
->fonts
[i
].LogFont
.lfWeight
= (flag
& 1) ? 700 : 400;
1229 hlpfile
->fonts
[i
].LogFont
.lfItalic
= (flag
& 2) ? TRUE
: FALSE
;
1230 hlpfile
->fonts
[i
].LogFont
.lfUnderline
= (flag
& 4) ? TRUE
: FALSE
;
1231 hlpfile
->fonts
[i
].LogFont
.lfStrikeOut
= (flag
& 8) ? TRUE
: FALSE
;
1232 hlpfile
->fonts
[i
].LogFont
.lfCharSet
= DEFAULT_CHARSET
;
1233 hlpfile
->fonts
[i
].LogFont
.lfOutPrecision
= OUT_DEFAULT_PRECIS
;
1234 hlpfile
->fonts
[i
].LogFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
1235 hlpfile
->fonts
[i
].LogFont
.lfQuality
= DEFAULT_QUALITY
;
1236 hlpfile
->fonts
[i
].LogFont
.lfPitchAndFamily
= DEFAULT_PITCH
;
1240 case 0x01: hlpfile
->fonts
[i
].LogFont
.lfPitchAndFamily
|= FF_MODERN
; break;
1241 case 0x02: hlpfile
->fonts
[i
].LogFont
.lfPitchAndFamily
|= FF_ROMAN
; break;
1242 case 0x03: hlpfile
->fonts
[i
].LogFont
.lfPitchAndFamily
|= FF_SWISS
; break;
1243 case 0x04: hlpfile
->fonts
[i
].LogFont
.lfPitchAndFamily
|= FF_SCRIPT
; break;
1244 case 0x05: hlpfile
->fonts
[i
].LogFont
.lfPitchAndFamily
|= FF_DECORATIVE
; break;
1245 default: WINE_FIXME("Unknown family %u\n", family
);
1247 idx
= GET_USHORT(ref
, dscr_offset
+ i
* 11 + 3);
1251 memcpy(hlpfile
->fonts
[i
].LogFont
.lfFaceName
, ref
+ face_offset
+ idx
* len
, min(len
, LF_FACESIZE
- 1));
1252 hlpfile
->fonts
[i
].LogFont
.lfFaceName
[min(len
, LF_FACESIZE
- 1)] = '\0';
1256 WINE_FIXME("Too high face ref (%u/%u)\n", idx
, face_num
);
1257 strcpy(hlpfile
->fonts
[i
].LogFont
.lfFaceName
, "Helv");
1259 hlpfile
->fonts
[i
].hFont
= 0;
1260 hlpfile
->fonts
[i
].color
= RGB(ref
[dscr_offset
+ i
* 11 + 5],
1261 ref
[dscr_offset
+ i
* 11 + 6],
1262 ref
[dscr_offset
+ i
* 11 + 7]);
1263 #define X(b,s) ((flag & (1 << b)) ? "-"s: "")
1264 WINE_TRACE("Font[%d]: flags=%02x%s%s%s%s%s%s pSize=%u family=%u face=%s[%u] color=%08x\n",
1270 X(4, "dblUnderline"),
1272 ref
[dscr_offset
+ i
* 11 + 1],
1274 hlpfile
->fonts
[i
].LogFont
.lfFaceName
, idx
,
1275 GET_UINT(ref
, dscr_offset
+ i
* 11 + 5) & 0x00FFFFFF);
1280 /***********************************************************************
1282 * HLPFILE_ReadFileToBuffer
1284 static BOOL
HLPFILE_ReadFileToBuffer(HLPFILE
* hlpfile
, HFILE hFile
)
1286 BYTE header
[16], dummy
[1];
1288 if (_hread(hFile
, header
, 16) != 16) {WINE_WARN("header\n"); return FALSE
;};
1291 if (GET_UINT(header
, 0) != 0x00035F3F)
1292 {WINE_WARN("wrong header\n"); return FALSE
;};
1294 hlpfile
->file_buffer_size
= GET_UINT(header
, 12);
1295 hlpfile
->file_buffer
= HeapAlloc(GetProcessHeap(), 0, hlpfile
->file_buffer_size
+ 1);
1296 if (!hlpfile
->file_buffer
) return FALSE
;
1298 memcpy(hlpfile
->file_buffer
, header
, 16);
1299 if (_hread(hFile
, hlpfile
->file_buffer
+ 16, hlpfile
->file_buffer_size
- 16) !=hlpfile
->file_buffer_size
- 16)
1300 {WINE_WARN("filesize1\n"); return FALSE
;};
1302 if (_hread(hFile
, dummy
, 1) != 0) WINE_WARN("filesize2\n");
1304 hlpfile
->file_buffer
[hlpfile
->file_buffer_size
] = '\0'; /* FIXME: was '0', sounds ackward to me */
1309 /**************************************************************************
1312 * HLPFILE_BPTreeCompare function for HLPFILE directory.
1315 static int comp_FindSubFile(void *p
, const void *key
,
1316 int leaf
, void** next
)
1318 *next
= (char *)p
+strlen(p
)+(leaf
?5:3);
1319 WINE_TRACE("Comparing '%s' with '%s'\n", (char *)p
, (char *)key
);
1320 return strcmp(p
, key
);
1323 /***********************************************************************
1325 * HLPFILE_FindSubFile
1327 static BOOL
HLPFILE_FindSubFile(HLPFILE
* hlpfile
, LPCSTR name
, BYTE
**subbuf
, BYTE
**subend
)
1331 WINE_TRACE("looking for file '%s'\n", name
);
1332 ptr
= HLPFILE_BPTreeSearch(hlpfile
->file_buffer
+ GET_UINT(hlpfile
->file_buffer
, 4),
1333 name
, comp_FindSubFile
);
1334 if (!ptr
) return FALSE
;
1335 *subbuf
= hlpfile
->file_buffer
+ GET_UINT(ptr
, strlen(name
)+1);
1336 if (*subbuf
>= hlpfile
->file_buffer
+ hlpfile
->file_buffer_size
)
1338 WINE_ERR("internal file %s does not fit\n", name
);
1341 *subend
= *subbuf
+ GET_UINT(*subbuf
, 0);
1342 if (*subend
> hlpfile
->file_buffer
+ hlpfile
->file_buffer_size
)
1344 WINE_ERR("internal file %s does not fit\n", name
);
1347 if (GET_UINT(*subbuf
, 0) < GET_UINT(*subbuf
, 4) + 9)
1349 WINE_ERR("invalid size provided for internal file %s\n", name
);
1355 /***********************************************************************
1357 * HLPFILE_SystemCommands
1359 static BOOL
HLPFILE_SystemCommands(HLPFILE
* hlpfile
)
1361 BYTE
*buf
, *ptr
, *end
;
1362 HLPFILE_MACRO
*macro
, **m
;
1364 unsigned short magic
, minor
, major
, flags
;
1366 hlpfile
->lpszTitle
= NULL
;
1368 if (!HLPFILE_FindSubFile(hlpfile
, "|SYSTEM", &buf
, &end
)) return FALSE
;
1370 magic
= GET_USHORT(buf
+ 9, 0);
1371 minor
= GET_USHORT(buf
+ 9, 2);
1372 major
= GET_USHORT(buf
+ 9, 4);
1373 /* gen date on 4 bytes */
1374 flags
= GET_USHORT(buf
+ 9, 10);
1375 WINE_TRACE("Got system header: magic=%04x version=%d.%d flags=%04x\n",
1376 magic
, major
, minor
, flags
);
1377 if (magic
!= 0x036C || major
!= 1)
1378 {WINE_WARN("Wrong system header\n"); return FALSE
;}
1381 hlpfile
->tbsize
= 0x800;
1382 hlpfile
->compressed
= 0;
1384 else if (flags
== 0)
1386 hlpfile
->tbsize
= 0x1000;
1387 hlpfile
->compressed
= 0;
1389 else if (flags
== 4)
1391 hlpfile
->tbsize
= 0x1000;
1392 hlpfile
->compressed
= 1;
1396 hlpfile
->tbsize
= 0x800;
1397 hlpfile
->compressed
= 1;
1400 if (hlpfile
->compressed
)
1401 hlpfile
->dsize
= 0x4000;
1403 hlpfile
->dsize
= hlpfile
->tbsize
- 0x0C;
1405 hlpfile
->version
= minor
;
1406 hlpfile
->flags
= flags
;
1408 for (ptr
= buf
+ 0x15; ptr
+ 4 <= end
; ptr
+= GET_USHORT(ptr
, 2) + 4)
1410 char *str
= (char*) ptr
+ 4;
1411 switch (GET_USHORT(ptr
, 0))
1414 if (hlpfile
->lpszTitle
) {WINE_WARN("title\n"); break;}
1415 hlpfile
->lpszTitle
= HeapAlloc(GetProcessHeap(), 0, strlen(str
) + 1);
1416 if (!hlpfile
->lpszTitle
) return FALSE
;
1417 lstrcpy(hlpfile
->lpszTitle
, str
);
1418 WINE_TRACE("Title: %s\n", hlpfile
->lpszTitle
);
1422 if (hlpfile
->lpszCopyright
) {WINE_WARN("copyright\n"); break;}
1423 hlpfile
->lpszCopyright
= HeapAlloc(GetProcessHeap(), 0, strlen(str
) + 1);
1424 if (!hlpfile
->lpszCopyright
) return FALSE
;
1425 lstrcpy(hlpfile
->lpszCopyright
, str
);
1426 WINE_TRACE("Copyright: %s\n", hlpfile
->lpszCopyright
);
1430 if (GET_USHORT(ptr
, 2) != 4) {WINE_WARN("system3\n");break;}
1431 hlpfile
->contents_start
= GET_UINT(ptr
, 4);
1432 WINE_TRACE("Setting contents start at %08lx\n", hlpfile
->contents_start
);
1436 macro
= HeapAlloc(GetProcessHeap(), 0, sizeof(HLPFILE_MACRO
) + lstrlen(str
) + 1);
1438 p
= (char*)macro
+ sizeof(HLPFILE_MACRO
);
1440 macro
->lpszMacro
= p
;
1442 for (m
= &hlpfile
->first_macro
; *m
; m
= &(*m
)->next
);
1447 if (GET_USHORT(ptr
, 2) != 90) {WINE_WARN("system6\n");break;}
1449 if (hlpfile
->windows
)
1450 hlpfile
->windows
= HeapReAlloc(GetProcessHeap(), 0, hlpfile
->windows
,
1451 sizeof(HLPFILE_WINDOWINFO
) * ++hlpfile
->numWindows
);
1453 hlpfile
->windows
= HeapAlloc(GetProcessHeap(), 0,
1454 sizeof(HLPFILE_WINDOWINFO
) * ++hlpfile
->numWindows
);
1456 if (hlpfile
->windows
)
1458 unsigned flags
= GET_USHORT(ptr
, 4);
1459 HLPFILE_WINDOWINFO
* wi
= &hlpfile
->windows
[hlpfile
->numWindows
- 1];
1461 if (flags
& 0x0001) strcpy(wi
->type
, &str
[2]);
1462 else wi
->type
[0] = '\0';
1463 if (flags
& 0x0002) strcpy(wi
->name
, &str
[12]);
1464 else wi
->name
[0] = '\0';
1465 if (flags
& 0x0004) strcpy(wi
->caption
, &str
[23]);
1466 else lstrcpynA(wi
->caption
, hlpfile
->lpszTitle
, sizeof(wi
->caption
));
1467 wi
->origin
.x
= (flags
& 0x0008) ? GET_USHORT(ptr
, 76) : CW_USEDEFAULT
;
1468 wi
->origin
.y
= (flags
& 0x0010) ? GET_USHORT(ptr
, 78) : CW_USEDEFAULT
;
1469 wi
->size
.cx
= (flags
& 0x0020) ? GET_USHORT(ptr
, 80) : CW_USEDEFAULT
;
1470 wi
->size
.cy
= (flags
& 0x0040) ? GET_USHORT(ptr
, 82) : CW_USEDEFAULT
;
1471 wi
->style
= (flags
& 0x0080) ? GET_USHORT(ptr
, 84) : SW_SHOW
;
1472 wi
->win_style
= WS_OVERLAPPEDWINDOW
;
1473 wi
->sr_color
= (flags
& 0x0100) ? GET_UINT(ptr
, 86) : 0xFFFFFF;
1474 wi
->nsr_color
= (flags
& 0x0200) ? GET_UINT(ptr
, 90) : 0xFFFFFF;
1475 WINE_TRACE("System-Window: flags=%c%c%c%c%c%c%c%c type=%s name=%s caption=%s (%d,%d)x(%d,%d)\n",
1476 flags
& 0x0001 ? 'T' : 't',
1477 flags
& 0x0002 ? 'N' : 'n',
1478 flags
& 0x0004 ? 'C' : 'c',
1479 flags
& 0x0008 ? 'X' : 'x',
1480 flags
& 0x0010 ? 'Y' : 'y',
1481 flags
& 0x0020 ? 'W' : 'w',
1482 flags
& 0x0040 ? 'H' : 'h',
1483 flags
& 0x0080 ? 'S' : 's',
1484 wi
->type
, wi
->name
, wi
->caption
, wi
->origin
.x
, wi
->origin
.y
,
1485 wi
->size
.cx
, wi
->size
.cy
);
1489 WINE_WARN("Unsupported SystemRecord[%d]\n", GET_USHORT(ptr
, 0));
1492 if (!hlpfile
->lpszTitle
)
1493 hlpfile
->lpszTitle
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, 1);
1497 /***********************************************************************
1499 * HLPFILE_UncompressedLZ77_Size
1501 static INT
HLPFILE_UncompressedLZ77_Size(BYTE
*ptr
, BYTE
*end
)
1508 for (i
= 0; i
< 8 && ptr
< end
; i
++, mask
>>= 1)
1512 int code
= GET_USHORT(ptr
, 0);
1513 int len
= 3 + (code
>> 12);
1517 else newsize
++, ptr
++;
1524 /***********************************************************************
1526 * HLPFILE_UncompressLZ77
1528 static BYTE
*HLPFILE_UncompressLZ77(BYTE
*ptr
, BYTE
*end
, BYTE
*newptr
)
1535 for (i
= 0; i
< 8 && ptr
< end
; i
++, mask
>>= 1)
1539 int code
= GET_USHORT(ptr
, 0);
1540 int len
= 3 + (code
>> 12);
1541 int offset
= code
& 0xfff;
1543 * We must copy byte-by-byte here. We cannot use memcpy nor
1544 * memmove here. Just example:
1545 * a[]={1,2,3,4,5,6,7,8,9,10}
1549 * {1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 11, 12}
1551 for (; len
>0; len
--, newptr
++) *newptr
= *(newptr
-offset
-1);
1554 else *newptr
++ = *ptr
++;
1561 /***********************************************************************
1563 * HLPFILE_UncompressLZ77_Phrases
1565 static BOOL
HLPFILE_UncompressLZ77_Phrases(HLPFILE
* hlpfile
)
1567 UINT i
, num
, dec_size
, head_size
;
1570 if (!HLPFILE_FindSubFile(hlpfile
, "|Phrases", &buf
, &end
)) return FALSE
;
1572 if (hlpfile
->version
<= 16)
1577 num
= hlpfile
->num_phrases
= GET_USHORT(buf
, 9);
1578 if (buf
+ 2 * num
+ 0x13 >= end
) {WINE_WARN("1a\n"); return FALSE
;};
1580 if (hlpfile
->version
<= 16)
1581 dec_size
= end
- buf
- 15 - 2 * num
;
1583 dec_size
= HLPFILE_UncompressedLZ77_Size(buf
+ 0x13 + 2 * num
, end
);
1585 hlpfile
->phrases_offsets
= HeapAlloc(GetProcessHeap(), 0, sizeof(unsigned) * (num
+ 1));
1586 hlpfile
->phrases_buffer
= HeapAlloc(GetProcessHeap(), 0, dec_size
);
1587 if (!hlpfile
->phrases_offsets
|| !hlpfile
->phrases_buffer
)
1589 HeapFree(GetProcessHeap(), 0, hlpfile
->phrases_offsets
);
1590 HeapFree(GetProcessHeap(), 0, hlpfile
->phrases_buffer
);
1594 for (i
= 0; i
<= num
; i
++)
1595 hlpfile
->phrases_offsets
[i
] = GET_USHORT(buf
, 0x11 + 2 * i
) - 2 * num
- 2;
1597 if (hlpfile
->version
<= 16)
1598 memcpy(hlpfile
->phrases_buffer
, buf
+ 15 + 2*num
, dec_size
);
1600 HLPFILE_UncompressLZ77(buf
+ 0x13 + 2 * num
, end
, (BYTE
*)hlpfile
->phrases_buffer
);
1602 hlpfile
->hasPhrases
= TRUE
;
1606 /***********************************************************************
1608 * HLPFILE_Uncompress_Phrases40
1610 static BOOL
HLPFILE_Uncompress_Phrases40(HLPFILE
* hlpfile
)
1613 INT dec_size
, cpr_size
;
1614 BYTE
*buf_idx
, *end_idx
;
1615 BYTE
*buf_phs
, *end_phs
;
1616 long* ptr
, mask
= 0;
1618 unsigned short bc
, n
;
1620 if (!HLPFILE_FindSubFile(hlpfile
, "|PhrIndex", &buf_idx
, &end_idx
) ||
1621 !HLPFILE_FindSubFile(hlpfile
, "|PhrImage", &buf_phs
, &end_phs
)) return FALSE
;
1623 ptr
= (long*)(buf_idx
+ 9 + 28);
1624 bc
= GET_USHORT(buf_idx
, 9 + 24) & 0x0F;
1625 num
= hlpfile
->num_phrases
= GET_USHORT(buf_idx
, 9 + 4);
1627 WINE_TRACE("Index: Magic=%08x #entries=%u CpsdSize=%u PhrImgSize=%u\n"
1628 "\tPhrImgCprsdSize=%u 0=%u bc=%x ukn=%x\n",
1629 GET_UINT(buf_idx
, 9 + 0),
1630 GET_UINT(buf_idx
, 9 + 4),
1631 GET_UINT(buf_idx
, 9 + 8),
1632 GET_UINT(buf_idx
, 9 + 12),
1633 GET_UINT(buf_idx
, 9 + 16),
1634 GET_UINT(buf_idx
, 9 + 20),
1635 GET_USHORT(buf_idx
, 9 + 24),
1636 GET_USHORT(buf_idx
, 9 + 26));
1638 dec_size
= GET_UINT(buf_idx
, 9 + 12);
1639 cpr_size
= GET_UINT(buf_idx
, 9 + 16);
1641 if (dec_size
!= cpr_size
&&
1642 dec_size
!= HLPFILE_UncompressedLZ77_Size(buf_phs
+ 9, end_phs
))
1644 WINE_WARN("size mismatch %u %u\n",
1645 dec_size
, HLPFILE_UncompressedLZ77_Size(buf_phs
+ 9, end_phs
));
1646 dec_size
= max(dec_size
, HLPFILE_UncompressedLZ77_Size(buf_phs
+ 9, end_phs
));
1649 hlpfile
->phrases_offsets
= HeapAlloc(GetProcessHeap(), 0, sizeof(unsigned) * (num
+ 1));
1650 hlpfile
->phrases_buffer
= HeapAlloc(GetProcessHeap(), 0, dec_size
);
1651 if (!hlpfile
->phrases_offsets
|| !hlpfile
->phrases_buffer
)
1653 HeapFree(GetProcessHeap(), 0, hlpfile
->phrases_offsets
);
1654 HeapFree(GetProcessHeap(), 0, hlpfile
->phrases_buffer
);
1658 #define getbit() (ptr += (mask < 0), mask = mask*2 + (mask<=0), (*ptr & mask) != 0)
1660 hlpfile
->phrases_offsets
[0] = 0;
1661 for (i
= 0; i
< num
; i
++)
1663 for (n
= 1; getbit(); n
+= 1 << bc
);
1665 if (bc
> 1 && getbit()) n
+= 2;
1666 if (bc
> 2 && getbit()) n
+= 4;
1667 if (bc
> 3 && getbit()) n
+= 8;
1668 if (bc
> 4 && getbit()) n
+= 16;
1669 hlpfile
->phrases_offsets
[i
+ 1] = hlpfile
->phrases_offsets
[i
] + n
;
1673 if (dec_size
== cpr_size
)
1674 memcpy(hlpfile
->phrases_buffer
, buf_phs
+ 9, dec_size
);
1676 HLPFILE_UncompressLZ77(buf_phs
+ 9, end_phs
, (BYTE
*)hlpfile
->phrases_buffer
);
1678 hlpfile
->hasPhrases40
= TRUE
;
1682 /***********************************************************************
1684 * HLPFILE_Uncompress_Topic
1686 static BOOL
HLPFILE_Uncompress_Topic(HLPFILE
* hlpfile
)
1688 BYTE
*buf
, *ptr
, *end
, *newptr
;
1689 unsigned int i
, newsize
= 0;
1690 unsigned int topic_size
;
1692 if (!HLPFILE_FindSubFile(hlpfile
, "|TOPIC", &buf
, &end
))
1693 {WINE_WARN("topic0\n"); return FALSE
;}
1695 buf
+= 9; /* Skip file header */
1696 topic_size
= end
- buf
;
1697 if (hlpfile
->compressed
)
1699 hlpfile
->topic_maplen
= (topic_size
- 1) / hlpfile
->tbsize
+ 1;
1701 for (i
= 0; i
< hlpfile
->topic_maplen
; i
++)
1703 ptr
= buf
+ i
* hlpfile
->tbsize
;
1705 /* I don't know why, it's necessary for printman.hlp */
1706 if (ptr
+ 0x44 > end
) ptr
= end
- 0x44;
1708 newsize
+= HLPFILE_UncompressedLZ77_Size(ptr
+ 0xc, min(end
, ptr
+ hlpfile
->tbsize
));
1711 hlpfile
->topic_map
= HeapAlloc(GetProcessHeap(), 0,
1712 hlpfile
->topic_maplen
* sizeof(hlpfile
->topic_map
[0]) + newsize
);
1713 if (!hlpfile
->topic_map
) return FALSE
;
1714 newptr
= (BYTE
*)(hlpfile
->topic_map
+ hlpfile
->topic_maplen
);
1715 hlpfile
->topic_end
= newptr
+ newsize
;
1717 for (i
= 0; i
< hlpfile
->topic_maplen
; i
++)
1719 ptr
= buf
+ i
* hlpfile
->tbsize
;
1720 if (ptr
+ 0x44 > end
) ptr
= end
- 0x44;
1722 hlpfile
->topic_map
[i
] = newptr
;
1723 newptr
= HLPFILE_UncompressLZ77(ptr
+ 0xc, min(end
, ptr
+ hlpfile
->tbsize
), newptr
);
1728 /* basically, we need to copy the TopicBlockSize byte pages
1729 * (removing the first 0x0C) in one single area in memory
1731 hlpfile
->topic_maplen
= (topic_size
- 1) / hlpfile
->tbsize
+ 1;
1732 hlpfile
->topic_map
= HeapAlloc(GetProcessHeap(), 0,
1733 hlpfile
->topic_maplen
* (sizeof(hlpfile
->topic_map
[0]) + hlpfile
->dsize
));
1734 if (!hlpfile
->topic_map
) return FALSE
;
1735 newptr
= (BYTE
*)(hlpfile
->topic_map
+ hlpfile
->topic_maplen
);
1736 hlpfile
->topic_end
= newptr
+ topic_size
;
1738 for (i
= 0; i
< hlpfile
->topic_maplen
; i
++)
1740 hlpfile
->topic_map
[i
] = newptr
+ i
* hlpfile
->dsize
;
1741 memcpy(hlpfile
->topic_map
[i
], buf
+ i
* hlpfile
->tbsize
+ 0x0C, hlpfile
->dsize
);
1747 /***********************************************************************
1749 * HLPFILE_Uncompress2
1752 static void HLPFILE_Uncompress2(HLPFILE
* hlpfile
, const BYTE
*ptr
, const BYTE
*end
, BYTE
*newptr
, const BYTE
*newend
)
1754 BYTE
*phptr
, *phend
;
1758 while (ptr
< end
&& newptr
< newend
)
1760 if (!*ptr
|| *ptr
>= 0x10)
1764 code
= 0x100 * ptr
[0] + ptr
[1];
1765 index
= (code
- 0x100) / 2;
1767 phptr
= (BYTE
*)hlpfile
->phrases_buffer
+ hlpfile
->phrases_offsets
[index
];
1768 phend
= (BYTE
*)hlpfile
->phrases_buffer
+ hlpfile
->phrases_offsets
[index
+ 1];
1770 if (newptr
+ (phend
- phptr
) > newend
)
1772 WINE_FIXME("buffer overflow %p > %p for %lu bytes\n",
1773 newptr
, newend
, (SIZE_T
)(phend
- phptr
));
1776 memcpy(newptr
, phptr
, phend
- phptr
);
1777 newptr
+= phend
- phptr
;
1778 if (code
& 1) *newptr
++ = ' ';
1783 if (newptr
> newend
) WINE_FIXME("buffer overflow %p > %p\n", newptr
, newend
);
1786 /******************************************************************
1787 * HLPFILE_Uncompress3
1791 static BOOL
HLPFILE_Uncompress3(HLPFILE
* hlpfile
, char* dst
, const char* dst_end
,
1792 const BYTE
* src
, const BYTE
* src_end
)
1794 unsigned int idx
, len
;
1796 for (; src
< src_end
; src
++)
1798 if ((*src
& 1) == 0)
1801 if (idx
> hlpfile
->num_phrases
)
1803 WINE_ERR("index in phrases %d/%d\n", idx
, hlpfile
->num_phrases
);
1808 len
= hlpfile
->phrases_offsets
[idx
+ 1] - hlpfile
->phrases_offsets
[idx
];
1809 if (dst
+ len
<= dst_end
)
1810 memcpy(dst
, &hlpfile
->phrases_buffer
[hlpfile
->phrases_offsets
[idx
]], len
);
1813 else if ((*src
& 0x03) == 0x01)
1815 idx
= (*src
+ 1) * 64;
1817 if (idx
> hlpfile
->num_phrases
)
1819 WINE_ERR("index in phrases %d/%d\n", idx
, hlpfile
->num_phrases
);
1824 len
= hlpfile
->phrases_offsets
[idx
+ 1] - hlpfile
->phrases_offsets
[idx
];
1825 if (dst
+ len
<= dst_end
)
1826 memcpy(dst
, &hlpfile
->phrases_buffer
[hlpfile
->phrases_offsets
[idx
]], len
);
1829 else if ((*src
& 0x07) == 0x03)
1831 len
= (*src
/ 8) + 1;
1832 if (dst
+ len
<= dst_end
)
1833 memcpy(dst
, src
+ 1, len
);
1838 len
= (*src
/ 16) + 1;
1839 if (dst
+ len
<= dst_end
)
1840 memset(dst
, ((*src
& 0x0F) == 0x07) ? ' ' : 0, len
);
1845 if (dst
> dst_end
) WINE_ERR("buffer overflow (%p > %p)\n", dst
, dst_end
);
1849 /******************************************************************
1850 * HLPFILE_UncompressRLE
1854 static void HLPFILE_UncompressRLE(const BYTE
* src
, const BYTE
* end
, BYTE
** dst
, unsigned dstsz
)
1857 BYTE
* sdst
= *dst
+ dstsz
;
1865 if ((*dst
) + ch
<= sdst
)
1866 memcpy(*dst
, src
, ch
);
1871 if ((*dst
) + ch
<= sdst
)
1872 memset(*dst
, (char)*src
, ch
);
1878 WINE_WARN("Buffer X-flow: d(%lu) instead of d(%u)\n",
1879 (SIZE_T
)(*dst
- (sdst
- dstsz
)), dstsz
);
1882 /**************************************************************************
1883 * HLPFILE_BPTreeSearch
1885 * Searches for an element in B+ tree
1888 * buf [I] pointer to the embedded file structured as a B+ tree
1889 * key [I] pointer to data to find
1890 * comp [I] compare function
1893 * Pointer to block identified by key, or NULL if failure.
1896 void* HLPFILE_BPTreeSearch(BYTE
* buf
, const void* key
,
1897 HLPFILE_BPTreeCompare comp
)
1903 BYTE
*pages
, *ptr
, *newptr
;
1907 magic
= GET_USHORT(buf
, 9);
1908 if (magic
!= 0x293B)
1910 WINE_ERR("Invalid magic in B+ tree: 0x%x\n", magic
);
1913 page_size
= GET_USHORT(buf
, 9+4);
1914 cur_page
= GET_USHORT(buf
, 9+26);
1915 level
= GET_USHORT(buf
, 9+32);
1916 pages
= buf
+ 9 + 38;
1919 ptr
= pages
+ cur_page
*page_size
;
1920 entries
= GET_SHORT(ptr
, 2);
1922 for (i
= 0; i
< entries
; i
++)
1924 if (comp(ptr
, key
, 0, (void **)&newptr
) > 0) break;
1927 cur_page
= GET_USHORT(ptr
-2, 0);
1929 ptr
= pages
+ cur_page
*page_size
;
1930 entries
= GET_SHORT(ptr
, 2);
1932 for (i
= 0; i
< entries
; i
++)
1934 ret
= comp(ptr
, key
, 1, (void **)&newptr
);
1935 if (ret
== 0) return ptr
;
1936 if (ret
> 0) return NULL
;
1942 /**************************************************************************
1943 * HLPFILE_BPTreeEnum
1945 * Enumerates elements in B+ tree.
1948 * buf [I] pointer to the embedded file structured as a B+ tree
1949 * cb [I] compare function
1950 * cookie [IO] cookie for cb function
1952 void HLPFILE_BPTreeEnum(BYTE
* buf
, HLPFILE_BPTreeCallback cb
, void* cookie
)
1958 BYTE
*pages
, *ptr
, *newptr
;
1961 magic
= GET_USHORT(buf
, 9);
1962 if (magic
!= 0x293B)
1964 WINE_ERR("Invalid magic in B+ tree: 0x%x\n", magic
);
1967 page_size
= GET_USHORT(buf
, 9+4);
1968 cur_page
= GET_USHORT(buf
, 9+26);
1969 level
= GET_USHORT(buf
, 9+32);
1970 pages
= buf
+ 9 + 38;
1973 ptr
= pages
+ cur_page
*page_size
;
1974 cur_page
= GET_USHORT(ptr
, 4);
1976 while (cur_page
!= 0xFFFF)
1978 ptr
= pages
+ cur_page
*page_size
;
1979 entries
= GET_SHORT(ptr
, 2);
1981 for (i
= 0; i
< entries
; i
++)
1983 cb(ptr
, (void **)&newptr
, cookie
);
1986 cur_page
= GET_USHORT(pages
+cur_page
*page_size
, 6);
1991 /***********************************************************************
1993 * HLPFILE_GetContext
1995 static BOOL
HLPFILE_GetContext(HLPFILE
*hlpfile
)
2000 if (!HLPFILE_FindSubFile(hlpfile
, "|CONTEXT", &cbuf
, &cend
))
2001 {WINE_WARN("context0\n"); return FALSE
;}
2004 hlpfile
->Context
= HeapAlloc(GetProcessHeap(), 0, clen
);
2005 if (!hlpfile
->Context
) return FALSE
;
2006 memcpy(hlpfile
->Context
, cbuf
, clen
);
2011 /***********************************************************************
2013 * HLPFILE_GetKeywords
2015 static BOOL
HLPFILE_GetKeywords(HLPFILE
*hlpfile
)
2020 if (!HLPFILE_FindSubFile(hlpfile
, "|KWBTREE", &cbuf
, &cend
)) return FALSE
;
2022 hlpfile
->kwbtree
= HeapAlloc(GetProcessHeap(), 0, clen
);
2023 if (!hlpfile
->kwbtree
) return FALSE
;
2024 memcpy(hlpfile
->kwbtree
, cbuf
, clen
);
2026 if (!HLPFILE_FindSubFile(hlpfile
, "|KWDATA", &cbuf
, &cend
))
2028 WINE_ERR("corrupted help file: kwbtree present but kwdata absent\n");
2029 HeapFree(GetProcessHeap(), 0, hlpfile
->kwbtree
);
2033 hlpfile
->kwdata
= HeapAlloc(GetProcessHeap(), 0, clen
);
2034 if (!hlpfile
->kwdata
)
2036 HeapFree(GetProcessHeap(), 0, hlpfile
->kwdata
);
2039 memcpy(hlpfile
->kwdata
, cbuf
, clen
);
2044 /***********************************************************************
2048 static BOOL
HLPFILE_GetMap(HLPFILE
*hlpfile
)
2051 unsigned entries
, i
;
2053 if (!HLPFILE_FindSubFile(hlpfile
, "|CTXOMAP", &cbuf
, &cend
))
2054 {WINE_WARN("no map section\n"); return FALSE
;}
2056 entries
= GET_USHORT(cbuf
, 9);
2057 hlpfile
->Map
= HeapAlloc(GetProcessHeap(), 0, entries
* sizeof(HLPFILE_MAP
));
2058 if (!hlpfile
->Map
) return FALSE
;
2059 hlpfile
->wMapLen
= entries
;
2060 for (i
= 0; i
< entries
; i
++)
2062 hlpfile
->Map
[i
].lMap
= GET_UINT(cbuf
+11,i
*8);
2063 hlpfile
->Map
[i
].offset
= GET_UINT(cbuf
+11,i
*8+4);
2068 /******************************************************************
2069 * HLPFILE_DeleteLink
2073 void HLPFILE_FreeLink(HLPFILE_LINK
* link
)
2075 if (link
&& !--link
->wRefCount
)
2076 HeapFree(GetProcessHeap(), 0, link
);
2079 /***********************************************************************
2081 * HLPFILE_DeleteParagraph
2083 static void HLPFILE_DeleteParagraph(HLPFILE_PARAGRAPH
* paragraph
)
2085 HLPFILE_PARAGRAPH
* next
;
2089 next
= paragraph
->next
;
2091 if (paragraph
->cookie
== para_metafile
)
2092 DeleteMetaFile(paragraph
->u
.gfx
.u
.mfp
.hMF
);
2094 HLPFILE_FreeLink(paragraph
->link
);
2096 HeapFree(GetProcessHeap(), 0, paragraph
);
2101 /***********************************************************************
2105 static void HLPFILE_DeleteMacro(HLPFILE_MACRO
* macro
)
2107 HLPFILE_MACRO
* next
;
2112 HeapFree(GetProcessHeap(), 0, macro
);
2117 /***********************************************************************
2121 static void HLPFILE_DeletePage(HLPFILE_PAGE
* page
)
2128 HLPFILE_DeleteParagraph(page
->first_paragraph
);
2129 HLPFILE_DeleteMacro(page
->first_macro
);
2130 HeapFree(GetProcessHeap(), 0, page
);
2135 /***********************************************************************
2137 * HLPFILE_FreeHlpFile
2139 void HLPFILE_FreeHlpFile(HLPFILE
* hlpfile
)
2143 if (!hlpfile
|| --hlpfile
->wRefCount
> 0) return;
2145 if (hlpfile
->next
) hlpfile
->next
->prev
= hlpfile
->prev
;
2146 if (hlpfile
->prev
) hlpfile
->prev
->next
= hlpfile
->next
;
2147 else first_hlpfile
= hlpfile
->next
;
2149 if (hlpfile
->numFonts
)
2151 for (i
= 0; i
< hlpfile
->numFonts
; i
++)
2153 DeleteObject(hlpfile
->fonts
[i
].hFont
);
2155 HeapFree(GetProcessHeap(), 0, hlpfile
->fonts
);
2158 if (hlpfile
->numBmps
)
2160 for (i
= 0; i
< hlpfile
->numBmps
; i
++)
2162 DeleteObject(hlpfile
->bmps
[i
]);
2164 HeapFree(GetProcessHeap(), 0, hlpfile
->bmps
);
2167 HLPFILE_DeletePage(hlpfile
->first_page
);
2168 HLPFILE_DeleteMacro(hlpfile
->first_macro
);
2170 if (hlpfile
->numWindows
) HeapFree(GetProcessHeap(), 0, hlpfile
->windows
);
2171 HeapFree(GetProcessHeap(), 0, hlpfile
->Context
);
2172 HeapFree(GetProcessHeap(), 0, hlpfile
->Map
);
2173 HeapFree(GetProcessHeap(), 0, hlpfile
->lpszTitle
);
2174 HeapFree(GetProcessHeap(), 0, hlpfile
->lpszCopyright
);
2175 HeapFree(GetProcessHeap(), 0, hlpfile
->file_buffer
);
2176 HeapFree(GetProcessHeap(), 0, hlpfile
->phrases_offsets
);
2177 HeapFree(GetProcessHeap(), 0, hlpfile
->phrases_buffer
);
2178 HeapFree(GetProcessHeap(), 0, hlpfile
->topic_map
);
2179 HeapFree(GetProcessHeap(), 0, hlpfile
);