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, unsigned);
76 static BOOL
HLPFILE_SkipParagraph(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
, ref
, index
* 0x8000L
+ offs
)) return FALSE
;
352 if (!HLPFILE_SkipParagraph(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 ref
, 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
;
436 page
->reference
= ref
;
438 page
->browse_bwd
= GET_UINT(buf
, 0x19);
439 page
->browse_fwd
= GET_UINT(buf
, 0x1D);
441 WINE_TRACE("Added page[%d]: title='%s' %08x << %08x >> %08x\n",
442 page
->wNumber
, page
->lpszTitle
,
443 page
->browse_bwd
, page
->offset
, page
->browse_fwd
);
445 memset(&attributes
, 0, sizeof(attributes
));
447 /* now load macros */
448 ptr
= page
->lpszTitle
+ strlen(page
->lpszTitle
) + 1;
449 while (ptr
< page
->lpszTitle
+ titlesize
)
451 unsigned len
= strlen(ptr
);
454 WINE_TRACE("macro: %s\n", ptr
);
455 macro
= HeapAlloc(GetProcessHeap(), 0, sizeof(HLPFILE_MACRO
) + len
+ 1);
456 macro
->lpszMacro
= macro_str
= (char*)(macro
+ 1);
457 memcpy(macro_str
, ptr
, len
+ 1);
458 /* FIXME: shall we really link macro in reverse order ??
459 * may produce strange results when played at page opening
461 macro
->next
= page
->first_macro
;
462 page
->first_macro
= macro
;
469 static long fetch_long(BYTE
** ptr
)
475 ret
= (*(unsigned long*)(*ptr
) - 0x80000000L
) / 2;
480 ret
= (*(unsigned short*)(*ptr
) - 0x8000) / 2;
487 static unsigned long fetch_ulong(BYTE
** ptr
)
493 ret
= *(unsigned long*)(*ptr
) / 2;
498 ret
= *(unsigned short*)(*ptr
) / 2;
504 static short fetch_short(BYTE
** ptr
)
510 ret
= (*(unsigned short*)(*ptr
) - 0x8000) / 2;
515 ret
= (*(unsigned char*)(*ptr
) - 0x80) / 2;
521 static unsigned short fetch_ushort(BYTE
** ptr
)
527 ret
= *(unsigned short*)(*ptr
) / 2;
532 ret
= *(unsigned char*)(*ptr
) / 2;
538 /***********************************************************************
540 * HLPFILE_SkipParagraph
542 static BOOL
HLPFILE_SkipParagraph(HLPFILE
*hlpfile
, BYTE
*buf
, BYTE
*end
, unsigned* len
)
546 if (!hlpfile
->first_page
) {WINE_WARN("no page\n"); return FALSE
;};
547 if (buf
+ 0x19 > end
) {WINE_WARN("header too small\n"); return FALSE
;};
550 if (buf
[0x14] == 0x20 || buf
[0x14] == 0x23)
553 *len
= fetch_ushort(&tmp
);
555 else *len
= end
-buf
-15;
560 /******************************************************************
561 * HLPFILE_DecompressGfx
563 * Decompress the data part of a bitmap or a metafile
565 static BYTE
* HLPFILE_DecompressGfx(BYTE
* src
, unsigned csz
, unsigned sz
, BYTE packing
)
572 WINE_TRACE("Unpacking (%d) from %u bytes to %u bytes\n", packing
, csz
, sz
);
576 case 0: /* uncompressed */
578 WINE_WARN("Bogus gfx sizes (uncompressed): %u / %u\n", sz
, csz
);
582 tmp
= dst
= HeapAlloc(GetProcessHeap(), 0, sz
);
583 if (!dst
) return NULL
;
584 HLPFILE_UncompressRLE(src
, src
+ csz
, &tmp
, sz
);
586 WINE_WARN("Bogus gfx sizes (RunLen): %lu/%u\n", (SIZE_T
)(tmp
- dst
), sz
);
589 sz77
= HLPFILE_UncompressedLZ77_Size(src
, src
+ csz
);
590 dst
= HeapAlloc(GetProcessHeap(), 0, sz77
);
591 if (!dst
) return NULL
;
592 HLPFILE_UncompressLZ77(src
, src
+ csz
, dst
);
594 WINE_WARN("Bogus gfx sizes (LZ77): %u / %u\n", sz77
, sz
);
596 case 3: /* LZ77 then RLE */
597 sz77
= HLPFILE_UncompressedLZ77_Size(src
, src
+ csz
);
598 tmp
= HeapAlloc(GetProcessHeap(), 0, sz77
);
599 if (!tmp
) return FALSE
;
600 HLPFILE_UncompressLZ77(src
, src
+ csz
, tmp
);
601 dst
= tmp2
= HeapAlloc(GetProcessHeap(), 0, sz
);
604 HeapFree(GetProcessHeap(), 0, tmp
);
607 HLPFILE_UncompressRLE(tmp
, tmp
+ sz77
, &tmp2
, sz
);
608 if (tmp2
- dst
!= sz
)
609 WINE_WARN("Bogus gfx sizes (LZ77+RunLen): %lu / %u\n", (SIZE_T
)(tmp2
- dst
), sz
);
610 HeapFree(GetProcessHeap(), 0, tmp
);
613 WINE_FIXME("Unsupported packing %u\n", packing
);
619 /******************************************************************
624 static BOOL
HLPFILE_LoadBitmap(BYTE
* beg
, BYTE type
, BYTE pack
,
625 HLPFILE_PARAGRAPH
* paragraph
)
630 unsigned long off
, csz
;
633 bi
= HeapAlloc(GetProcessHeap(), 0, sizeof(*bi
));
634 if (!bi
) return FALSE
;
636 ptr
= beg
+ 2; /* for type and pack */
638 bi
->bmiHeader
.biSize
= sizeof(bi
->bmiHeader
);
639 bi
->bmiHeader
.biXPelsPerMeter
= fetch_ulong(&ptr
);
640 bi
->bmiHeader
.biYPelsPerMeter
= fetch_ulong(&ptr
);
641 bi
->bmiHeader
.biPlanes
= fetch_ushort(&ptr
);
642 bi
->bmiHeader
.biBitCount
= fetch_ushort(&ptr
);
643 bi
->bmiHeader
.biWidth
= fetch_ulong(&ptr
);
644 bi
->bmiHeader
.biHeight
= fetch_ulong(&ptr
);
645 bi
->bmiHeader
.biClrUsed
= fetch_ulong(&ptr
);
646 bi
->bmiHeader
.biClrImportant
= fetch_ulong(&ptr
);
647 bi
->bmiHeader
.biCompression
= BI_RGB
;
648 if (bi
->bmiHeader
.biBitCount
> 32) WINE_FIXME("Unknown bit count %u\n", bi
->bmiHeader
.biBitCount
);
649 if (bi
->bmiHeader
.biPlanes
!= 1) WINE_FIXME("Unsupported planes %u\n", bi
->bmiHeader
.biPlanes
);
650 bi
->bmiHeader
.biSizeImage
= (((bi
->bmiHeader
.biWidth
* bi
->bmiHeader
.biBitCount
+ 31) & ~31) / 8) * bi
->bmiHeader
.biHeight
;
651 WINE_TRACE("planes=%d bc=%d size=(%d,%d)\n",
652 bi
->bmiHeader
.biPlanes
, bi
->bmiHeader
.biBitCount
,
653 bi
->bmiHeader
.biWidth
, bi
->bmiHeader
.biHeight
);
655 csz
= fetch_ulong(&ptr
);
656 fetch_ulong(&ptr
); /* hotspot size */
658 off
= GET_UINT(ptr
, 0); ptr
+= 4;
659 /* GET_UINT(ptr, 0); hotspot offset */ ptr
+= 4;
661 /* now read palette info */
664 unsigned nc
= bi
->bmiHeader
.biClrUsed
;
667 /* not quite right, especially for bitfields type of compression */
668 if (!nc
&& bi
->bmiHeader
.biBitCount
<= 8)
669 nc
= 1 << bi
->bmiHeader
.biBitCount
;
671 bi
= HeapReAlloc(GetProcessHeap(), 0, bi
, sizeof(*bi
) + nc
* sizeof(RGBQUAD
));
672 if (!bi
) return FALSE
;
673 for (i
= 0; i
< nc
; i
++)
675 bi
->bmiColors
[i
].rgbBlue
= ptr
[0];
676 bi
->bmiColors
[i
].rgbGreen
= ptr
[1];
677 bi
->bmiColors
[i
].rgbRed
= ptr
[2];
678 bi
->bmiColors
[i
].rgbReserved
= 0;
682 pict_beg
= HLPFILE_DecompressGfx(beg
+ off
, csz
, bi
->bmiHeader
.biSizeImage
, pack
);
684 paragraph
->u
.gfx
.u
.bmp
.hBitmap
= CreateDIBitmap(hdc
= GetDC(0), &bi
->bmiHeader
,
688 if (!paragraph
->u
.gfx
.u
.bmp
.hBitmap
)
689 WINE_ERR("Couldn't create bitmap\n");
691 HeapFree(GetProcessHeap(), 0, bi
);
692 if (pict_beg
!= beg
+ off
) HeapFree(GetProcessHeap(), 0, pict_beg
);
697 /******************************************************************
698 * HLPFILE_LoadMetaFile
702 static BOOL
HLPFILE_LoadMetaFile(BYTE
* beg
, BYTE pack
, HLPFILE_PARAGRAPH
* paragraph
)
705 unsigned long size
, csize
;
706 unsigned long off
, hsoff
;
708 LPMETAFILEPICT lpmfp
;
710 WINE_TRACE("Loading metafile\n");
712 ptr
= beg
+ 2; /* for type and pack */
714 lpmfp
= ¶graph
->u
.gfx
.u
.mfp
;
715 lpmfp
->mm
= fetch_ushort(&ptr
); /* mapping mode */
717 lpmfp
->xExt
= GET_USHORT(ptr
, 0);
718 lpmfp
->yExt
= GET_USHORT(ptr
, 2);
721 size
= fetch_ulong(&ptr
); /* decompressed size */
722 csize
= fetch_ulong(&ptr
); /* compressed size */
723 fetch_ulong(&ptr
); /* hotspot size */
724 off
= GET_UINT(ptr
, 0);
725 hsoff
= GET_UINT(ptr
, 4);
728 WINE_TRACE("sz=%lu csz=%lu (%d,%d) offs=%lu/%lu,%lu\n",
729 size
, csize
, lpmfp
->xExt
, lpmfp
->yExt
, off
, (SIZE_T
)(ptr
- beg
), hsoff
);
731 bits
= HLPFILE_DecompressGfx(beg
+ off
, csize
, size
, pack
);
732 if (!bits
) return FALSE
;
734 paragraph
->cookie
= para_metafile
;
736 lpmfp
->hMF
= SetMetaFileBitsEx(size
, bits
);
739 WINE_FIXME("Couldn't load metafile\n");
741 if (bits
!= beg
+ off
) HeapFree(GetProcessHeap(), 0, bits
);
746 /******************************************************************
747 * HLPFILE_LoadGfxByAddr
751 static BOOL
HLPFILE_LoadGfxByAddr(HLPFILE
*hlpfile
, BYTE
* ref
,
753 HLPFILE_PARAGRAPH
* paragraph
)
757 numpict
= GET_USHORT(ref
, 2);
758 WINE_TRACE("Got picture magic=%04x #=%d\n",
759 GET_USHORT(ref
, 0), numpict
);
761 for (i
= 0; i
< numpict
; i
++)
767 WINE_TRACE("Offset[%d] = %x\n", i
, GET_UINT(ref
, (1 + i
) * 4));
768 beg
= ptr
= ref
+ GET_UINT(ref
, (1 + i
) * 4);
775 case 5: /* device dependent bmp */
776 case 6: /* device independent bmp */
777 HLPFILE_LoadBitmap(beg
, type
, pack
, paragraph
);
780 HLPFILE_LoadMetaFile(beg
, pack
, paragraph
);
782 default: WINE_FIXME("Unknown type %u\n", type
); return FALSE
;
785 /* FIXME: hotspots */
787 /* FIXME: implement support for multiple picture format */
788 if (numpict
!= 1) WINE_FIXME("Supporting only one bitmap format per logical bitmap (for now). Using first format\n");
794 /******************************************************************
795 * HLPFILE_LoadGfxByIndex
799 static BOOL
HLPFILE_LoadGfxByIndex(HLPFILE
*hlpfile
, unsigned index
,
800 HLPFILE_PARAGRAPH
* paragraph
)
806 WINE_TRACE("Loading picture #%d\n", index
);
808 if (index
< hlpfile
->numBmps
&& hlpfile
->bmps
[index
] != NULL
)
810 paragraph
->u
.gfx
.u
.bmp
.hBitmap
= hlpfile
->bmps
[index
];
814 sprintf(tmp
, "|bm%u", index
);
816 if (!HLPFILE_FindSubFile(hlpfile
, tmp
, &ref
, &end
)) {WINE_WARN("no sub file\n"); return FALSE
;}
820 ret
= HLPFILE_LoadGfxByAddr(hlpfile
, ref
, end
- ref
, paragraph
);
823 if (ret
&& paragraph
->cookie
== para_bitmap
)
825 if (index
>= hlpfile
->numBmps
)
827 hlpfile
->numBmps
= index
+ 1;
829 hlpfile
->bmps
= HeapReAlloc(GetProcessHeap(), 0, hlpfile
->bmps
,
830 hlpfile
->numBmps
* sizeof(hlpfile
->bmps
[0]));
832 hlpfile
->bmps
= HeapAlloc(GetProcessHeap(), 0,
833 hlpfile
->numBmps
* sizeof(hlpfile
->bmps
[0]));
836 hlpfile
->bmps
[index
] = paragraph
->u
.gfx
.u
.bmp
.hBitmap
;
841 /******************************************************************
846 static HLPFILE_LINK
* HLPFILE_AllocLink(int cookie
, const char* str
, LONG hash
,
847 BOOL clrChange
, unsigned wnd
)
852 /* FIXME: should build a string table for the attributes.link.lpszPath
853 * they are reallocated for each link
855 link
= HeapAlloc(GetProcessHeap(), 0, sizeof(HLPFILE_LINK
) + strlen(str
) + 1);
856 if (!link
) return NULL
;
858 link
->cookie
= cookie
;
859 link
->lpszString
= link_str
= (char*)link
+ sizeof(HLPFILE_LINK
);
860 strcpy(link_str
, str
);
862 link
->bClrChange
= clrChange
? 1 : 0;
866 WINE_TRACE("Link[%d] to %s@%08x:%d\n",
867 link
->cookie
, link
->lpszString
,
868 link
->lHash
, link
->window
);
872 /***********************************************************************
874 * HLPFILE_BrowseParagraph
876 static BOOL
HLPFILE_BrowseParagraph(HLPFILE_PAGE
* page
, BYTE
*buf
, BYTE
* end
)
878 HLPFILE_PARAGRAPH
*paragraph
, **paragraphptr
;
880 BYTE
*format
, *format_end
;
881 char *text
, *text_base
, *text_end
;
882 long size
, blocksize
, datalen
;
884 unsigned nc
, ncol
= 1;
885 BOOL in_table
= FALSE
;
887 for (paragraphptr
= &page
->first_paragraph
; *paragraphptr
;
888 paragraphptr
= &(*paragraphptr
)->next
) /* Nothing */;
890 if (buf
+ 0x19 > end
) {WINE_WARN("header too small\n"); return FALSE
;};
892 blocksize
= GET_UINT(buf
, 0);
893 size
= GET_UINT(buf
, 0x4);
894 datalen
= GET_UINT(buf
, 0x10);
895 text
= text_base
= HeapAlloc(GetProcessHeap(), 0, size
);
896 if (!text
) return FALSE
;
897 if (size
> blocksize
- datalen
)
899 /* need to decompress */
900 if (page
->file
->hasPhrases
)
901 HLPFILE_Uncompress2(page
->file
, buf
+ datalen
, end
, (BYTE
*)text
, (BYTE
*)text
+ size
);
902 else if (page
->file
->hasPhrases40
)
903 HLPFILE_Uncompress3(page
->file
, text
, text
+ size
, buf
+ datalen
, end
);
906 WINE_FIXME("Text size is too long, splitting\n");
907 size
= blocksize
- datalen
;
908 memcpy(text
, buf
+ datalen
, size
);
912 memcpy(text
, buf
+ datalen
, size
);
914 text_end
= text
+ size
;
917 format_end
= buf
+ GET_UINT(buf
, 0x10);
919 if (buf
[0x14] == 0x20 || buf
[0x14] == 0x23)
922 fetch_ushort(&format
);
925 if (buf
[0x14] == 0x23)
932 WINE_TRACE("#cols %u\n", ncol
);
934 if (type
== 0 || type
== 2)
939 for (nc
= 0; nc
< ncol
; /**/)
941 WINE_TRACE("looking for format at offset %lu in column %d\n", (SIZE_T
)(format
- (buf
+ 0x15)), nc
);
944 nc
= GET_SHORT(format
, 0);
950 bits
= GET_USHORT(format
, 0); format
+= 2;
951 if (bits
& 0x0001) fetch_long(&format
);
952 if (bits
& 0x0002) fetch_short(&format
);
953 if (bits
& 0x0004) fetch_short(&format
);
954 if (bits
& 0x0008) fetch_short(&format
);
955 if (bits
& 0x0010) fetch_short(&format
);
956 if (bits
& 0x0020) fetch_short(&format
);
957 if (bits
& 0x0040) fetch_short(&format
);
958 if (bits
& 0x0100) format
+= 3;
961 int ntab
= fetch_short(&format
);
966 ts
= fetch_ushort(&format
);
967 if (ts
& 0x4000) fetch_ushort(&format
);
970 /* 0x0400, 0x0800 and 0x1000 don't need space */
971 if ((bits
& 0xE080) != 0)
972 WINE_FIXME("Unsupported bits %04x, potential trouble ahead\n", bits
);
974 while (text
< text_end
&& format
< format_end
)
976 WINE_TRACE("Got text: %s (%p/%p - %p/%p)\n", wine_dbgstr_a(text
), text
, text_end
, format
, format_end
);
977 textsize
= strlen(text
) + 1;
980 paragraph
= HeapAlloc(GetProcessHeap(), 0,
981 sizeof(HLPFILE_PARAGRAPH
) + textsize
);
982 if (!paragraph
) return FALSE
;
983 *paragraphptr
= paragraph
;
984 paragraphptr
= ¶graph
->next
;
986 paragraph
->next
= NULL
;
987 paragraph
->link
= attributes
.link
;
988 if (paragraph
->link
) paragraph
->link
->wRefCount
++;
989 paragraph
->cookie
= para_normal_text
;
990 paragraph
->u
.text
.wFont
= attributes
.wFont
;
991 paragraph
->u
.text
.wVSpace
= attributes
.wVSpace
;
992 paragraph
->u
.text
.wHSpace
= attributes
.wHSpace
;
993 paragraph
->u
.text
.wIndent
= attributes
.wIndent
;
994 paragraph
->u
.text
.lpszText
= (char*)paragraph
+ sizeof(HLPFILE_PARAGRAPH
);
995 strcpy(paragraph
->u
.text
.lpszText
, text
);
997 attributes
.wVSpace
= 0;
998 attributes
.wHSpace
= 0;
1000 /* else: null text, keep on storing attributes */
1003 if (*format
== 0xff)
1009 WINE_TRACE("format=%02x\n", *format
);
1013 WINE_FIXME("NIY20\n");
1018 WINE_FIXME("NIY21\n");
1023 attributes
.wFont
= GET_USHORT(format
, 1);
1024 WINE_TRACE("Changing font to %d\n", attributes
.wFont
);
1029 attributes
.wVSpace
++;
1034 attributes
.wVSpace
++;
1035 attributes
.wIndent
= 0;
1040 attributes
.wIndent
++;
1054 BYTE pos
= (*format
- 0x86);
1055 BYTE type
= format
[1];
1059 size
= fetch_long(&format
);
1061 paragraph
= HeapAlloc(GetProcessHeap(), 0,
1062 sizeof(HLPFILE_PARAGRAPH
) + textsize
);
1063 if (!paragraph
) return FALSE
;
1064 *paragraphptr
= paragraph
;
1065 paragraphptr
= ¶graph
->next
;
1067 paragraph
->next
= NULL
;
1068 paragraph
->link
= attributes
.link
;
1069 if (paragraph
->link
) paragraph
->link
->wRefCount
++;
1070 paragraph
->cookie
= para_bitmap
;
1071 paragraph
->u
.gfx
.pos
= pos
;
1075 fetch_ushort(&format
); /* hot spot */
1078 switch (GET_SHORT(format
, 0))
1081 HLPFILE_LoadGfxByIndex(page
->file
, GET_SHORT(format
, 2),
1085 WINE_FIXME("does it work ??? %x<%lu>#%u\n",
1086 GET_SHORT(format
, 0),
1087 size
, GET_SHORT(format
, 2));
1088 HLPFILE_LoadGfxByAddr(page
->file
, format
+ 2, size
- 4,
1092 WINE_FIXME("??? %u\n", GET_SHORT(format
, 0));
1097 WINE_FIXME("Got an embedded element %s\n", format
+ 6);
1100 WINE_FIXME("Got a type %d picture\n", type
);
1103 if (attributes
.wVSpace
) paragraph
->u
.gfx
.pos
|= 0x8000;
1110 HLPFILE_FreeLink(attributes
.link
);
1111 attributes
.link
= NULL
;
1117 WINE_FIXME("NIY non-break space/hyphen\n");
1129 WINE_TRACE("macro => %s\n", format
+ 3);
1130 HLPFILE_FreeLink(attributes
.link
);
1131 attributes
.link
= HLPFILE_AllocLink(hlp_link_macro
, (const char*)format
+ 3,
1132 0, !(*format
& 4), -1);
1133 format
+= 3 + GET_USHORT(format
, 1);
1138 WINE_WARN("jump topic 1 => %u\n", GET_UINT(format
, 1));
1139 HLPFILE_FreeLink(attributes
.link
);
1140 attributes
.link
= HLPFILE_AllocLink((*format
& 1) ? hlp_link_link
: hlp_link_popup
,
1141 page
->file
->lpszPath
,
1142 GET_UINT(format
, 1)-16,
1153 HLPFILE_FreeLink(attributes
.link
);
1154 attributes
.link
= HLPFILE_AllocLink((*format
& 1) ? hlp_link_link
: hlp_link_popup
,
1155 page
->file
->lpszPath
,
1156 GET_UINT(format
, 1),
1157 !(*format
& 4), -1);
1166 char* ptr
= (char*) format
+ 8;
1167 BYTE type
= format
[3];
1176 ptr
= page
->file
->lpszPath
;
1179 for (wnd
= page
->file
->numWindows
- 1; wnd
>= 0; wnd
--)
1181 if (!strcmp(ptr
, page
->file
->windows
[wnd
].name
)) break;
1184 WINE_WARN("Couldn't find window info for %s\n", ptr
);
1185 ptr
+= strlen(ptr
) + 1;
1190 WINE_WARN("Unknown link type %d\n", type
);
1193 HLPFILE_FreeLink(attributes
.link
);
1194 attributes
.link
= HLPFILE_AllocLink((*format
& 4) ? hlp_link_link
: hlp_link_popup
,
1195 ptr
, GET_UINT(format
, 4),
1196 !(*format
& 1), wnd
);
1198 format
+= 3 + GET_USHORT(format
, 1);
1202 WINE_WARN("format %02x\n", *format
);
1207 HeapFree(GetProcessHeap(), 0, text_base
);
1211 /******************************************************************
1212 * HLPFILE_BrowsePage
1215 BOOL
HLPFILE_BrowsePage(HLPFILE_PAGE
* page
)
1217 HLPFILE
*hlpfile
= page
->file
;
1219 DWORD ref
= page
->reference
;
1220 unsigned index
, old_index
= -1, offset
, count
= 0;
1224 if (hlpfile
->version
<= 16)
1226 index
= (ref
- 0x0C) / hlpfile
->dsize
;
1227 offset
= (ref
- 0x0C) % hlpfile
->dsize
;
1231 index
= (ref
- 0x0C) >> 14;
1232 offset
= (ref
- 0x0C) & 0x3FFF;
1235 if (hlpfile
->version
<= 16 && index
!= old_index
&& index
!= 0)
1237 /* we jumped to the next block, adjust pointers */
1242 if (index
>= hlpfile
->topic_maplen
) {WINE_WARN("maplen\n"); break;}
1243 buf
= hlpfile
->topic_map
[index
] + offset
;
1244 if (buf
+ 0x15 >= hlpfile
->topic_end
) {WINE_WARN("extra\n"); break;}
1245 end
= min(buf
+ GET_UINT(buf
, 0), hlpfile
->topic_end
);
1246 if (index
!= old_index
) {old_index
= index
;}
1251 if (count
++) goto done
;
1256 if (!HLPFILE_BrowseParagraph(page
, buf
, end
)) return FALSE
;
1259 WINE_ERR("buf[0x14] = %x\n", buf
[0x14]);
1261 if (hlpfile
->version
<= 16)
1263 ref
+= GET_UINT(buf
, 0xc);
1264 if (GET_UINT(buf
, 0xc) == 0)
1268 ref
= GET_UINT(buf
, 0xc);
1269 } while (ref
!= 0xffffffff);
1274 /******************************************************************
1279 static BOOL
HLPFILE_ReadFont(HLPFILE
* hlpfile
)
1282 unsigned i
, len
, idx
;
1283 unsigned face_num
, dscr_num
, face_offset
, dscr_offset
;
1286 if (!HLPFILE_FindSubFile(hlpfile
, "|FONT", &ref
, &end
))
1288 WINE_WARN("no subfile FONT\n");
1289 hlpfile
->numFonts
= 0;
1290 hlpfile
->fonts
= NULL
;
1296 face_num
= GET_USHORT(ref
, 0);
1297 dscr_num
= GET_USHORT(ref
, 2);
1298 face_offset
= GET_USHORT(ref
, 4);
1299 dscr_offset
= GET_USHORT(ref
, 6);
1301 WINE_TRACE("Got NumFacenames=%u@%u NumDesc=%u@%u\n",
1302 face_num
, face_offset
, dscr_num
, dscr_offset
);
1304 hlpfile
->numFonts
= dscr_num
;
1305 hlpfile
->fonts
= HeapAlloc(GetProcessHeap(), 0, sizeof(HLPFILE_FONT
) * dscr_num
);
1307 len
= (dscr_offset
- face_offset
) / face_num
;
1308 /* EPP for (i = face_offset; i < dscr_offset; i += len) */
1309 /* EPP WINE_FIXME("[%d]: %*s\n", i / len, len, ref + i); */
1310 for (i
= 0; i
< dscr_num
; i
++)
1312 flag
= ref
[dscr_offset
+ i
* 11 + 0];
1313 family
= ref
[dscr_offset
+ i
* 11 + 2];
1315 hlpfile
->fonts
[i
].LogFont
.lfHeight
= -ref
[dscr_offset
+ i
* 11 + 1] / 2 - 3;
1316 hlpfile
->fonts
[i
].LogFont
.lfWidth
= 0;
1317 hlpfile
->fonts
[i
].LogFont
.lfEscapement
= 0;
1318 hlpfile
->fonts
[i
].LogFont
.lfOrientation
= 0;
1319 hlpfile
->fonts
[i
].LogFont
.lfWeight
= (flag
& 1) ? 700 : 400;
1320 hlpfile
->fonts
[i
].LogFont
.lfItalic
= (flag
& 2) ? TRUE
: FALSE
;
1321 hlpfile
->fonts
[i
].LogFont
.lfUnderline
= (flag
& 4) ? TRUE
: FALSE
;
1322 hlpfile
->fonts
[i
].LogFont
.lfStrikeOut
= (flag
& 8) ? TRUE
: FALSE
;
1323 hlpfile
->fonts
[i
].LogFont
.lfCharSet
= DEFAULT_CHARSET
;
1324 hlpfile
->fonts
[i
].LogFont
.lfOutPrecision
= OUT_DEFAULT_PRECIS
;
1325 hlpfile
->fonts
[i
].LogFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
1326 hlpfile
->fonts
[i
].LogFont
.lfQuality
= DEFAULT_QUALITY
;
1327 hlpfile
->fonts
[i
].LogFont
.lfPitchAndFamily
= DEFAULT_PITCH
;
1331 case 0x01: hlpfile
->fonts
[i
].LogFont
.lfPitchAndFamily
|= FF_MODERN
; break;
1332 case 0x02: hlpfile
->fonts
[i
].LogFont
.lfPitchAndFamily
|= FF_ROMAN
; break;
1333 case 0x03: hlpfile
->fonts
[i
].LogFont
.lfPitchAndFamily
|= FF_SWISS
; break;
1334 case 0x04: hlpfile
->fonts
[i
].LogFont
.lfPitchAndFamily
|= FF_SCRIPT
; break;
1335 case 0x05: hlpfile
->fonts
[i
].LogFont
.lfPitchAndFamily
|= FF_DECORATIVE
; break;
1336 default: WINE_FIXME("Unknown family %u\n", family
);
1338 idx
= GET_USHORT(ref
, dscr_offset
+ i
* 11 + 3);
1342 memcpy(hlpfile
->fonts
[i
].LogFont
.lfFaceName
, ref
+ face_offset
+ idx
* len
, min(len
, LF_FACESIZE
- 1));
1343 hlpfile
->fonts
[i
].LogFont
.lfFaceName
[min(len
, LF_FACESIZE
- 1)] = '\0';
1347 WINE_FIXME("Too high face ref (%u/%u)\n", idx
, face_num
);
1348 strcpy(hlpfile
->fonts
[i
].LogFont
.lfFaceName
, "Helv");
1350 hlpfile
->fonts
[i
].hFont
= 0;
1351 hlpfile
->fonts
[i
].color
= RGB(ref
[dscr_offset
+ i
* 11 + 5],
1352 ref
[dscr_offset
+ i
* 11 + 6],
1353 ref
[dscr_offset
+ i
* 11 + 7]);
1354 #define X(b,s) ((flag & (1 << b)) ? "-"s: "")
1355 WINE_TRACE("Font[%d]: flags=%02x%s%s%s%s%s%s pSize=%u family=%u face=%s[%u] color=%08x\n",
1361 X(4, "dblUnderline"),
1363 ref
[dscr_offset
+ i
* 11 + 1],
1365 hlpfile
->fonts
[i
].LogFont
.lfFaceName
, idx
,
1366 GET_UINT(ref
, dscr_offset
+ i
* 11 + 5) & 0x00FFFFFF);
1371 /***********************************************************************
1373 * HLPFILE_ReadFileToBuffer
1375 static BOOL
HLPFILE_ReadFileToBuffer(HLPFILE
* hlpfile
, HFILE hFile
)
1377 BYTE header
[16], dummy
[1];
1379 if (_hread(hFile
, header
, 16) != 16) {WINE_WARN("header\n"); return FALSE
;};
1382 if (GET_UINT(header
, 0) != 0x00035F3F)
1383 {WINE_WARN("wrong header\n"); return FALSE
;};
1385 hlpfile
->file_buffer_size
= GET_UINT(header
, 12);
1386 hlpfile
->file_buffer
= HeapAlloc(GetProcessHeap(), 0, hlpfile
->file_buffer_size
+ 1);
1387 if (!hlpfile
->file_buffer
) return FALSE
;
1389 memcpy(hlpfile
->file_buffer
, header
, 16);
1390 if (_hread(hFile
, hlpfile
->file_buffer
+ 16, hlpfile
->file_buffer_size
- 16) !=hlpfile
->file_buffer_size
- 16)
1391 {WINE_WARN("filesize1\n"); return FALSE
;};
1393 if (_hread(hFile
, dummy
, 1) != 0) WINE_WARN("filesize2\n");
1395 hlpfile
->file_buffer
[hlpfile
->file_buffer_size
] = '\0'; /* FIXME: was '0', sounds backwards to me */
1400 /**************************************************************************
1403 * HLPFILE_BPTreeCompare function for HLPFILE directory.
1406 static int comp_FindSubFile(void *p
, const void *key
,
1407 int leaf
, void** next
)
1409 *next
= (char *)p
+strlen(p
)+(leaf
?5:3);
1410 WINE_TRACE("Comparing '%s' with '%s'\n", (char *)p
, (char *)key
);
1411 return strcmp(p
, key
);
1414 /***********************************************************************
1416 * HLPFILE_FindSubFile
1418 static BOOL
HLPFILE_FindSubFile(HLPFILE
* hlpfile
, LPCSTR name
, BYTE
**subbuf
, BYTE
**subend
)
1422 WINE_TRACE("looking for file '%s'\n", name
);
1423 ptr
= HLPFILE_BPTreeSearch(hlpfile
->file_buffer
+ GET_UINT(hlpfile
->file_buffer
, 4),
1424 name
, comp_FindSubFile
);
1425 if (!ptr
) return FALSE
;
1426 *subbuf
= hlpfile
->file_buffer
+ GET_UINT(ptr
, strlen(name
)+1);
1427 if (*subbuf
>= hlpfile
->file_buffer
+ hlpfile
->file_buffer_size
)
1429 WINE_ERR("internal file %s does not fit\n", name
);
1432 *subend
= *subbuf
+ GET_UINT(*subbuf
, 0);
1433 if (*subend
> hlpfile
->file_buffer
+ hlpfile
->file_buffer_size
)
1435 WINE_ERR("internal file %s does not fit\n", name
);
1438 if (GET_UINT(*subbuf
, 0) < GET_UINT(*subbuf
, 4) + 9)
1440 WINE_ERR("invalid size provided for internal file %s\n", name
);
1446 /***********************************************************************
1448 * HLPFILE_SystemCommands
1450 static BOOL
HLPFILE_SystemCommands(HLPFILE
* hlpfile
)
1452 BYTE
*buf
, *ptr
, *end
;
1453 HLPFILE_MACRO
*macro
, **m
;
1455 unsigned short magic
, minor
, major
, flags
;
1457 hlpfile
->lpszTitle
= NULL
;
1459 if (!HLPFILE_FindSubFile(hlpfile
, "|SYSTEM", &buf
, &end
)) return FALSE
;
1461 magic
= GET_USHORT(buf
+ 9, 0);
1462 minor
= GET_USHORT(buf
+ 9, 2);
1463 major
= GET_USHORT(buf
+ 9, 4);
1464 /* gen date on 4 bytes */
1465 flags
= GET_USHORT(buf
+ 9, 10);
1466 WINE_TRACE("Got system header: magic=%04x version=%d.%d flags=%04x\n",
1467 magic
, major
, minor
, flags
);
1468 if (magic
!= 0x036C || major
!= 1)
1469 {WINE_WARN("Wrong system header\n"); return FALSE
;}
1472 hlpfile
->tbsize
= 0x800;
1473 hlpfile
->compressed
= 0;
1475 else if (flags
== 0)
1477 hlpfile
->tbsize
= 0x1000;
1478 hlpfile
->compressed
= 0;
1480 else if (flags
== 4)
1482 hlpfile
->tbsize
= 0x1000;
1483 hlpfile
->compressed
= 1;
1487 hlpfile
->tbsize
= 0x800;
1488 hlpfile
->compressed
= 1;
1491 if (hlpfile
->compressed
)
1492 hlpfile
->dsize
= 0x4000;
1494 hlpfile
->dsize
= hlpfile
->tbsize
- 0x0C;
1496 hlpfile
->version
= minor
;
1497 hlpfile
->flags
= flags
;
1499 for (ptr
= buf
+ 0x15; ptr
+ 4 <= end
; ptr
+= GET_USHORT(ptr
, 2) + 4)
1501 char *str
= (char*) ptr
+ 4;
1502 switch (GET_USHORT(ptr
, 0))
1505 if (hlpfile
->lpszTitle
) {WINE_WARN("title\n"); break;}
1506 hlpfile
->lpszTitle
= HeapAlloc(GetProcessHeap(), 0, strlen(str
) + 1);
1507 if (!hlpfile
->lpszTitle
) return FALSE
;
1508 lstrcpy(hlpfile
->lpszTitle
, str
);
1509 WINE_TRACE("Title: %s\n", hlpfile
->lpszTitle
);
1513 if (hlpfile
->lpszCopyright
) {WINE_WARN("copyright\n"); break;}
1514 hlpfile
->lpszCopyright
= HeapAlloc(GetProcessHeap(), 0, strlen(str
) + 1);
1515 if (!hlpfile
->lpszCopyright
) return FALSE
;
1516 lstrcpy(hlpfile
->lpszCopyright
, str
);
1517 WINE_TRACE("Copyright: %s\n", hlpfile
->lpszCopyright
);
1521 if (GET_USHORT(ptr
, 2) != 4) {WINE_WARN("system3\n");break;}
1522 hlpfile
->contents_start
= GET_UINT(ptr
, 4);
1523 WINE_TRACE("Setting contents start at %08lx\n", hlpfile
->contents_start
);
1527 macro
= HeapAlloc(GetProcessHeap(), 0, sizeof(HLPFILE_MACRO
) + lstrlen(str
) + 1);
1529 p
= (char*)macro
+ sizeof(HLPFILE_MACRO
);
1531 macro
->lpszMacro
= p
;
1533 for (m
= &hlpfile
->first_macro
; *m
; m
= &(*m
)->next
);
1538 if (GET_USHORT(ptr
, 2) != 90) {WINE_WARN("system6\n");break;}
1540 if (hlpfile
->windows
)
1541 hlpfile
->windows
= HeapReAlloc(GetProcessHeap(), 0, hlpfile
->windows
,
1542 sizeof(HLPFILE_WINDOWINFO
) * ++hlpfile
->numWindows
);
1544 hlpfile
->windows
= HeapAlloc(GetProcessHeap(), 0,
1545 sizeof(HLPFILE_WINDOWINFO
) * ++hlpfile
->numWindows
);
1547 if (hlpfile
->windows
)
1549 unsigned flags
= GET_USHORT(ptr
, 4);
1550 HLPFILE_WINDOWINFO
* wi
= &hlpfile
->windows
[hlpfile
->numWindows
- 1];
1552 if (flags
& 0x0001) strcpy(wi
->type
, &str
[2]);
1553 else wi
->type
[0] = '\0';
1554 if (flags
& 0x0002) strcpy(wi
->name
, &str
[12]);
1555 else wi
->name
[0] = '\0';
1556 if (flags
& 0x0004) strcpy(wi
->caption
, &str
[21]);
1557 else lstrcpynA(wi
->caption
, hlpfile
->lpszTitle
, sizeof(wi
->caption
));
1558 wi
->origin
.x
= (flags
& 0x0008) ? GET_USHORT(ptr
, 76) : CW_USEDEFAULT
;
1559 wi
->origin
.y
= (flags
& 0x0010) ? GET_USHORT(ptr
, 78) : CW_USEDEFAULT
;
1560 wi
->size
.cx
= (flags
& 0x0020) ? GET_USHORT(ptr
, 80) : CW_USEDEFAULT
;
1561 wi
->size
.cy
= (flags
& 0x0040) ? GET_USHORT(ptr
, 82) : CW_USEDEFAULT
;
1562 wi
->style
= (flags
& 0x0080) ? GET_USHORT(ptr
, 84) : SW_SHOW
;
1563 wi
->win_style
= WS_OVERLAPPEDWINDOW
;
1564 wi
->sr_color
= (flags
& 0x0100) ? GET_UINT(ptr
, 86) : 0xFFFFFF;
1565 wi
->nsr_color
= (flags
& 0x0200) ? GET_UINT(ptr
, 90) : 0xFFFFFF;
1566 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",
1567 flags
& 0x0001 ? 'T' : 't',
1568 flags
& 0x0002 ? 'N' : 'n',
1569 flags
& 0x0004 ? 'C' : 'c',
1570 flags
& 0x0008 ? 'X' : 'x',
1571 flags
& 0x0010 ? 'Y' : 'y',
1572 flags
& 0x0020 ? 'W' : 'w',
1573 flags
& 0x0040 ? 'H' : 'h',
1574 flags
& 0x0080 ? 'S' : 's',
1575 wi
->type
, wi
->name
, wi
->caption
, wi
->origin
.x
, wi
->origin
.y
,
1576 wi
->size
.cx
, wi
->size
.cy
);
1580 WINE_WARN("Citation: '%s'\n", ptr
+ 4);
1583 WINE_WARN("Unsupported SystemRecord[%d]\n", GET_USHORT(ptr
, 0));
1586 if (!hlpfile
->lpszTitle
)
1587 hlpfile
->lpszTitle
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, 1);
1591 /***********************************************************************
1593 * HLPFILE_UncompressedLZ77_Size
1595 static INT
HLPFILE_UncompressedLZ77_Size(BYTE
*ptr
, BYTE
*end
)
1602 for (i
= 0; i
< 8 && ptr
< end
; i
++, mask
>>= 1)
1606 int code
= GET_USHORT(ptr
, 0);
1607 int len
= 3 + (code
>> 12);
1611 else newsize
++, ptr
++;
1618 /***********************************************************************
1620 * HLPFILE_UncompressLZ77
1622 static BYTE
*HLPFILE_UncompressLZ77(BYTE
*ptr
, BYTE
*end
, BYTE
*newptr
)
1629 for (i
= 0; i
< 8 && ptr
< end
; i
++, mask
>>= 1)
1633 int code
= GET_USHORT(ptr
, 0);
1634 int len
= 3 + (code
>> 12);
1635 int offset
= code
& 0xfff;
1637 * We must copy byte-by-byte here. We cannot use memcpy nor
1638 * memmove here. Just example:
1639 * a[]={1,2,3,4,5,6,7,8,9,10}
1643 * {1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 11, 12}
1645 for (; len
>0; len
--, newptr
++) *newptr
= *(newptr
-offset
-1);
1648 else *newptr
++ = *ptr
++;
1655 /***********************************************************************
1657 * HLPFILE_UncompressLZ77_Phrases
1659 static BOOL
HLPFILE_UncompressLZ77_Phrases(HLPFILE
* hlpfile
)
1661 UINT i
, num
, dec_size
, head_size
;
1664 if (!HLPFILE_FindSubFile(hlpfile
, "|Phrases", &buf
, &end
)) return FALSE
;
1666 if (hlpfile
->version
<= 16)
1671 num
= hlpfile
->num_phrases
= GET_USHORT(buf
, 9);
1672 if (buf
+ 2 * num
+ 0x13 >= end
) {WINE_WARN("1a\n"); return FALSE
;};
1674 if (hlpfile
->version
<= 16)
1675 dec_size
= end
- buf
- 15 - 2 * num
;
1677 dec_size
= HLPFILE_UncompressedLZ77_Size(buf
+ 0x13 + 2 * num
, end
);
1679 hlpfile
->phrases_offsets
= HeapAlloc(GetProcessHeap(), 0, sizeof(unsigned) * (num
+ 1));
1680 hlpfile
->phrases_buffer
= HeapAlloc(GetProcessHeap(), 0, dec_size
);
1681 if (!hlpfile
->phrases_offsets
|| !hlpfile
->phrases_buffer
)
1683 HeapFree(GetProcessHeap(), 0, hlpfile
->phrases_offsets
);
1684 HeapFree(GetProcessHeap(), 0, hlpfile
->phrases_buffer
);
1688 for (i
= 0; i
<= num
; i
++)
1689 hlpfile
->phrases_offsets
[i
] = GET_USHORT(buf
, 0x11 + 2 * i
) - 2 * num
- 2;
1691 if (hlpfile
->version
<= 16)
1692 memcpy(hlpfile
->phrases_buffer
, buf
+ 15 + 2*num
, dec_size
);
1694 HLPFILE_UncompressLZ77(buf
+ 0x13 + 2 * num
, end
, (BYTE
*)hlpfile
->phrases_buffer
);
1696 hlpfile
->hasPhrases
= TRUE
;
1700 /***********************************************************************
1702 * HLPFILE_Uncompress_Phrases40
1704 static BOOL
HLPFILE_Uncompress_Phrases40(HLPFILE
* hlpfile
)
1707 INT dec_size
, cpr_size
;
1708 BYTE
*buf_idx
, *end_idx
;
1709 BYTE
*buf_phs
, *end_phs
;
1710 long* ptr
, mask
= 0;
1712 unsigned short bc
, n
;
1714 if (!HLPFILE_FindSubFile(hlpfile
, "|PhrIndex", &buf_idx
, &end_idx
) ||
1715 !HLPFILE_FindSubFile(hlpfile
, "|PhrImage", &buf_phs
, &end_phs
)) return FALSE
;
1717 ptr
= (long*)(buf_idx
+ 9 + 28);
1718 bc
= GET_USHORT(buf_idx
, 9 + 24) & 0x0F;
1719 num
= hlpfile
->num_phrases
= GET_USHORT(buf_idx
, 9 + 4);
1721 WINE_TRACE("Index: Magic=%08x #entries=%u CpsdSize=%u PhrImgSize=%u\n"
1722 "\tPhrImgCprsdSize=%u 0=%u bc=%x ukn=%x\n",
1723 GET_UINT(buf_idx
, 9 + 0),
1724 GET_UINT(buf_idx
, 9 + 4),
1725 GET_UINT(buf_idx
, 9 + 8),
1726 GET_UINT(buf_idx
, 9 + 12),
1727 GET_UINT(buf_idx
, 9 + 16),
1728 GET_UINT(buf_idx
, 9 + 20),
1729 GET_USHORT(buf_idx
, 9 + 24),
1730 GET_USHORT(buf_idx
, 9 + 26));
1732 dec_size
= GET_UINT(buf_idx
, 9 + 12);
1733 cpr_size
= GET_UINT(buf_idx
, 9 + 16);
1735 if (dec_size
!= cpr_size
&&
1736 dec_size
!= HLPFILE_UncompressedLZ77_Size(buf_phs
+ 9, end_phs
))
1738 WINE_WARN("size mismatch %u %u\n",
1739 dec_size
, HLPFILE_UncompressedLZ77_Size(buf_phs
+ 9, end_phs
));
1740 dec_size
= max(dec_size
, HLPFILE_UncompressedLZ77_Size(buf_phs
+ 9, end_phs
));
1743 hlpfile
->phrases_offsets
= HeapAlloc(GetProcessHeap(), 0, sizeof(unsigned) * (num
+ 1));
1744 hlpfile
->phrases_buffer
= HeapAlloc(GetProcessHeap(), 0, dec_size
);
1745 if (!hlpfile
->phrases_offsets
|| !hlpfile
->phrases_buffer
)
1747 HeapFree(GetProcessHeap(), 0, hlpfile
->phrases_offsets
);
1748 HeapFree(GetProcessHeap(), 0, hlpfile
->phrases_buffer
);
1752 #define getbit() (ptr += (mask < 0), mask = mask*2 + (mask<=0), (*ptr & mask) != 0)
1754 hlpfile
->phrases_offsets
[0] = 0;
1755 for (i
= 0; i
< num
; i
++)
1757 for (n
= 1; getbit(); n
+= 1 << bc
);
1759 if (bc
> 1 && getbit()) n
+= 2;
1760 if (bc
> 2 && getbit()) n
+= 4;
1761 if (bc
> 3 && getbit()) n
+= 8;
1762 if (bc
> 4 && getbit()) n
+= 16;
1763 hlpfile
->phrases_offsets
[i
+ 1] = hlpfile
->phrases_offsets
[i
] + n
;
1767 if (dec_size
== cpr_size
)
1768 memcpy(hlpfile
->phrases_buffer
, buf_phs
+ 9, dec_size
);
1770 HLPFILE_UncompressLZ77(buf_phs
+ 9, end_phs
, (BYTE
*)hlpfile
->phrases_buffer
);
1772 hlpfile
->hasPhrases40
= TRUE
;
1776 /***********************************************************************
1778 * HLPFILE_Uncompress_Topic
1780 static BOOL
HLPFILE_Uncompress_Topic(HLPFILE
* hlpfile
)
1782 BYTE
*buf
, *ptr
, *end
, *newptr
;
1783 unsigned int i
, newsize
= 0;
1784 unsigned int topic_size
;
1786 if (!HLPFILE_FindSubFile(hlpfile
, "|TOPIC", &buf
, &end
))
1787 {WINE_WARN("topic0\n"); return FALSE
;}
1789 buf
+= 9; /* Skip file header */
1790 topic_size
= end
- buf
;
1791 if (hlpfile
->compressed
)
1793 hlpfile
->topic_maplen
= (topic_size
- 1) / hlpfile
->tbsize
+ 1;
1795 for (i
= 0; i
< hlpfile
->topic_maplen
; i
++)
1797 ptr
= buf
+ i
* hlpfile
->tbsize
;
1799 /* I don't know why, it's necessary for printman.hlp */
1800 if (ptr
+ 0x44 > end
) ptr
= end
- 0x44;
1802 newsize
+= HLPFILE_UncompressedLZ77_Size(ptr
+ 0xc, min(end
, ptr
+ hlpfile
->tbsize
));
1805 hlpfile
->topic_map
= HeapAlloc(GetProcessHeap(), 0,
1806 hlpfile
->topic_maplen
* sizeof(hlpfile
->topic_map
[0]) + newsize
);
1807 if (!hlpfile
->topic_map
) return FALSE
;
1808 newptr
= (BYTE
*)(hlpfile
->topic_map
+ hlpfile
->topic_maplen
);
1809 hlpfile
->topic_end
= newptr
+ newsize
;
1811 for (i
= 0; i
< hlpfile
->topic_maplen
; i
++)
1813 ptr
= buf
+ i
* hlpfile
->tbsize
;
1814 if (ptr
+ 0x44 > end
) ptr
= end
- 0x44;
1816 hlpfile
->topic_map
[i
] = newptr
;
1817 newptr
= HLPFILE_UncompressLZ77(ptr
+ 0xc, min(end
, ptr
+ hlpfile
->tbsize
), newptr
);
1822 /* basically, we need to copy the TopicBlockSize byte pages
1823 * (removing the first 0x0C) in one single area in memory
1825 hlpfile
->topic_maplen
= (topic_size
- 1) / hlpfile
->tbsize
+ 1;
1826 hlpfile
->topic_map
= HeapAlloc(GetProcessHeap(), 0,
1827 hlpfile
->topic_maplen
* (sizeof(hlpfile
->topic_map
[0]) + hlpfile
->dsize
));
1828 if (!hlpfile
->topic_map
) return FALSE
;
1829 newptr
= (BYTE
*)(hlpfile
->topic_map
+ hlpfile
->topic_maplen
);
1830 hlpfile
->topic_end
= newptr
+ topic_size
;
1832 for (i
= 0; i
< hlpfile
->topic_maplen
; i
++)
1834 hlpfile
->topic_map
[i
] = newptr
+ i
* hlpfile
->dsize
;
1835 memcpy(hlpfile
->topic_map
[i
], buf
+ i
* hlpfile
->tbsize
+ 0x0C, hlpfile
->dsize
);
1841 /***********************************************************************
1843 * HLPFILE_Uncompress2
1846 static void HLPFILE_Uncompress2(HLPFILE
* hlpfile
, const BYTE
*ptr
, const BYTE
*end
, BYTE
*newptr
, const BYTE
*newend
)
1848 BYTE
*phptr
, *phend
;
1852 while (ptr
< end
&& newptr
< newend
)
1854 if (!*ptr
|| *ptr
>= 0x10)
1858 code
= 0x100 * ptr
[0] + ptr
[1];
1859 index
= (code
- 0x100) / 2;
1861 phptr
= (BYTE
*)hlpfile
->phrases_buffer
+ hlpfile
->phrases_offsets
[index
];
1862 phend
= (BYTE
*)hlpfile
->phrases_buffer
+ hlpfile
->phrases_offsets
[index
+ 1];
1864 if (newptr
+ (phend
- phptr
) > newend
)
1866 WINE_FIXME("buffer overflow %p > %p for %lu bytes\n",
1867 newptr
, newend
, (SIZE_T
)(phend
- phptr
));
1870 memcpy(newptr
, phptr
, phend
- phptr
);
1871 newptr
+= phend
- phptr
;
1872 if (code
& 1) *newptr
++ = ' ';
1877 if (newptr
> newend
) WINE_FIXME("buffer overflow %p > %p\n", newptr
, newend
);
1880 /******************************************************************
1881 * HLPFILE_Uncompress3
1885 static BOOL
HLPFILE_Uncompress3(HLPFILE
* hlpfile
, char* dst
, const char* dst_end
,
1886 const BYTE
* src
, const BYTE
* src_end
)
1888 unsigned int idx
, len
;
1890 for (; src
< src_end
; src
++)
1892 if ((*src
& 1) == 0)
1895 if (idx
> hlpfile
->num_phrases
)
1897 WINE_ERR("index in phrases %d/%d\n", idx
, hlpfile
->num_phrases
);
1902 len
= hlpfile
->phrases_offsets
[idx
+ 1] - hlpfile
->phrases_offsets
[idx
];
1903 if (dst
+ len
<= dst_end
)
1904 memcpy(dst
, &hlpfile
->phrases_buffer
[hlpfile
->phrases_offsets
[idx
]], len
);
1907 else if ((*src
& 0x03) == 0x01)
1909 idx
= (*src
+ 1) * 64;
1911 if (idx
> hlpfile
->num_phrases
)
1913 WINE_ERR("index in phrases %d/%d\n", idx
, hlpfile
->num_phrases
);
1918 len
= hlpfile
->phrases_offsets
[idx
+ 1] - hlpfile
->phrases_offsets
[idx
];
1919 if (dst
+ len
<= dst_end
)
1920 memcpy(dst
, &hlpfile
->phrases_buffer
[hlpfile
->phrases_offsets
[idx
]], len
);
1923 else if ((*src
& 0x07) == 0x03)
1925 len
= (*src
/ 8) + 1;
1926 if (dst
+ len
<= dst_end
)
1927 memcpy(dst
, src
+ 1, len
);
1932 len
= (*src
/ 16) + 1;
1933 if (dst
+ len
<= dst_end
)
1934 memset(dst
, ((*src
& 0x0F) == 0x07) ? ' ' : 0, len
);
1939 if (dst
> dst_end
) WINE_ERR("buffer overflow (%p > %p)\n", dst
, dst_end
);
1943 /******************************************************************
1944 * HLPFILE_UncompressRLE
1948 static void HLPFILE_UncompressRLE(const BYTE
* src
, const BYTE
* end
, BYTE
** dst
, unsigned dstsz
)
1951 BYTE
* sdst
= *dst
+ dstsz
;
1959 if ((*dst
) + ch
<= sdst
)
1960 memcpy(*dst
, src
, ch
);
1965 if ((*dst
) + ch
<= sdst
)
1966 memset(*dst
, (char)*src
, ch
);
1972 WINE_WARN("Buffer X-flow: d(%lu) instead of d(%u)\n",
1973 (SIZE_T
)(*dst
- (sdst
- dstsz
)), dstsz
);
1976 /**************************************************************************
1977 * HLPFILE_BPTreeSearch
1979 * Searches for an element in B+ tree
1982 * buf [I] pointer to the embedded file structured as a B+ tree
1983 * key [I] pointer to data to find
1984 * comp [I] compare function
1987 * Pointer to block identified by key, or NULL if failure.
1990 void* HLPFILE_BPTreeSearch(BYTE
* buf
, const void* key
,
1991 HLPFILE_BPTreeCompare comp
)
1997 BYTE
*pages
, *ptr
, *newptr
;
2001 magic
= GET_USHORT(buf
, 9);
2002 if (magic
!= 0x293B)
2004 WINE_ERR("Invalid magic in B+ tree: 0x%x\n", magic
);
2007 page_size
= GET_USHORT(buf
, 9+4);
2008 cur_page
= GET_USHORT(buf
, 9+26);
2009 level
= GET_USHORT(buf
, 9+32);
2010 pages
= buf
+ 9 + 38;
2013 ptr
= pages
+ cur_page
*page_size
;
2014 entries
= GET_SHORT(ptr
, 2);
2016 for (i
= 0; i
< entries
; i
++)
2018 if (comp(ptr
, key
, 0, (void **)&newptr
) > 0) break;
2021 cur_page
= GET_USHORT(ptr
-2, 0);
2023 ptr
= pages
+ cur_page
*page_size
;
2024 entries
= GET_SHORT(ptr
, 2);
2026 for (i
= 0; i
< entries
; i
++)
2028 ret
= comp(ptr
, key
, 1, (void **)&newptr
);
2029 if (ret
== 0) return ptr
;
2030 if (ret
> 0) return NULL
;
2036 /**************************************************************************
2037 * HLPFILE_BPTreeEnum
2039 * Enumerates elements in B+ tree.
2042 * buf [I] pointer to the embedded file structured as a B+ tree
2043 * cb [I] compare function
2044 * cookie [IO] cookie for cb function
2046 void HLPFILE_BPTreeEnum(BYTE
* buf
, HLPFILE_BPTreeCallback cb
, void* cookie
)
2052 BYTE
*pages
, *ptr
, *newptr
;
2055 magic
= GET_USHORT(buf
, 9);
2056 if (magic
!= 0x293B)
2058 WINE_ERR("Invalid magic in B+ tree: 0x%x\n", magic
);
2061 page_size
= GET_USHORT(buf
, 9+4);
2062 cur_page
= GET_USHORT(buf
, 9+26);
2063 level
= GET_USHORT(buf
, 9+32);
2064 pages
= buf
+ 9 + 38;
2067 ptr
= pages
+ cur_page
*page_size
;
2068 cur_page
= GET_USHORT(ptr
, 4);
2070 while (cur_page
!= 0xFFFF)
2072 ptr
= pages
+ cur_page
*page_size
;
2073 entries
= GET_SHORT(ptr
, 2);
2075 for (i
= 0; i
< entries
; i
++)
2077 cb(ptr
, (void **)&newptr
, cookie
);
2080 cur_page
= GET_USHORT(pages
+cur_page
*page_size
, 6);
2085 /***********************************************************************
2087 * HLPFILE_GetContext
2089 static BOOL
HLPFILE_GetContext(HLPFILE
*hlpfile
)
2094 if (!HLPFILE_FindSubFile(hlpfile
, "|CONTEXT", &cbuf
, &cend
))
2095 {WINE_WARN("context0\n"); return FALSE
;}
2098 hlpfile
->Context
= HeapAlloc(GetProcessHeap(), 0, clen
);
2099 if (!hlpfile
->Context
) return FALSE
;
2100 memcpy(hlpfile
->Context
, cbuf
, clen
);
2105 /***********************************************************************
2107 * HLPFILE_GetKeywords
2109 static BOOL
HLPFILE_GetKeywords(HLPFILE
*hlpfile
)
2114 if (!HLPFILE_FindSubFile(hlpfile
, "|KWBTREE", &cbuf
, &cend
)) return FALSE
;
2116 hlpfile
->kwbtree
= HeapAlloc(GetProcessHeap(), 0, clen
);
2117 if (!hlpfile
->kwbtree
) return FALSE
;
2118 memcpy(hlpfile
->kwbtree
, cbuf
, clen
);
2120 if (!HLPFILE_FindSubFile(hlpfile
, "|KWDATA", &cbuf
, &cend
))
2122 WINE_ERR("corrupted help file: kwbtree present but kwdata absent\n");
2123 HeapFree(GetProcessHeap(), 0, hlpfile
->kwbtree
);
2127 hlpfile
->kwdata
= HeapAlloc(GetProcessHeap(), 0, clen
);
2128 if (!hlpfile
->kwdata
)
2130 HeapFree(GetProcessHeap(), 0, hlpfile
->kwdata
);
2133 memcpy(hlpfile
->kwdata
, cbuf
, clen
);
2138 /***********************************************************************
2142 static BOOL
HLPFILE_GetMap(HLPFILE
*hlpfile
)
2145 unsigned entries
, i
;
2147 if (!HLPFILE_FindSubFile(hlpfile
, "|CTXOMAP", &cbuf
, &cend
))
2148 {WINE_WARN("no map section\n"); return FALSE
;}
2150 entries
= GET_USHORT(cbuf
, 9);
2151 hlpfile
->Map
= HeapAlloc(GetProcessHeap(), 0, entries
* sizeof(HLPFILE_MAP
));
2152 if (!hlpfile
->Map
) return FALSE
;
2153 hlpfile
->wMapLen
= entries
;
2154 for (i
= 0; i
< entries
; i
++)
2156 hlpfile
->Map
[i
].lMap
= GET_UINT(cbuf
+11,i
*8);
2157 hlpfile
->Map
[i
].offset
= GET_UINT(cbuf
+11,i
*8+4);
2162 /******************************************************************
2163 * HLPFILE_DeleteLink
2167 void HLPFILE_FreeLink(HLPFILE_LINK
* link
)
2169 if (link
&& !--link
->wRefCount
)
2170 HeapFree(GetProcessHeap(), 0, link
);
2173 /***********************************************************************
2175 * HLPFILE_DeleteParagraph
2177 static void HLPFILE_DeleteParagraph(HLPFILE_PARAGRAPH
* paragraph
)
2179 HLPFILE_PARAGRAPH
* next
;
2183 next
= paragraph
->next
;
2185 if (paragraph
->cookie
== para_metafile
)
2186 DeleteMetaFile(paragraph
->u
.gfx
.u
.mfp
.hMF
);
2188 HLPFILE_FreeLink(paragraph
->link
);
2190 HeapFree(GetProcessHeap(), 0, paragraph
);
2195 /***********************************************************************
2199 static void HLPFILE_DeleteMacro(HLPFILE_MACRO
* macro
)
2201 HLPFILE_MACRO
* next
;
2206 HeapFree(GetProcessHeap(), 0, macro
);
2211 /***********************************************************************
2215 static void HLPFILE_DeletePage(HLPFILE_PAGE
* page
)
2222 HLPFILE_DeleteParagraph(page
->first_paragraph
);
2223 HLPFILE_DeleteMacro(page
->first_macro
);
2224 HeapFree(GetProcessHeap(), 0, page
);
2229 /***********************************************************************
2231 * HLPFILE_FreeHlpFile
2233 void HLPFILE_FreeHlpFile(HLPFILE
* hlpfile
)
2237 if (!hlpfile
|| --hlpfile
->wRefCount
> 0) return;
2239 if (hlpfile
->next
) hlpfile
->next
->prev
= hlpfile
->prev
;
2240 if (hlpfile
->prev
) hlpfile
->prev
->next
= hlpfile
->next
;
2241 else first_hlpfile
= hlpfile
->next
;
2243 if (hlpfile
->numFonts
)
2245 for (i
= 0; i
< hlpfile
->numFonts
; i
++)
2247 DeleteObject(hlpfile
->fonts
[i
].hFont
);
2249 HeapFree(GetProcessHeap(), 0, hlpfile
->fonts
);
2252 if (hlpfile
->numBmps
)
2254 for (i
= 0; i
< hlpfile
->numBmps
; i
++)
2256 DeleteObject(hlpfile
->bmps
[i
]);
2258 HeapFree(GetProcessHeap(), 0, hlpfile
->bmps
);
2261 HLPFILE_DeletePage(hlpfile
->first_page
);
2262 HLPFILE_DeleteMacro(hlpfile
->first_macro
);
2264 if (hlpfile
->numWindows
) HeapFree(GetProcessHeap(), 0, hlpfile
->windows
);
2265 HeapFree(GetProcessHeap(), 0, hlpfile
->Context
);
2266 HeapFree(GetProcessHeap(), 0, hlpfile
->Map
);
2267 HeapFree(GetProcessHeap(), 0, hlpfile
->lpszTitle
);
2268 HeapFree(GetProcessHeap(), 0, hlpfile
->lpszCopyright
);
2269 HeapFree(GetProcessHeap(), 0, hlpfile
->file_buffer
);
2270 HeapFree(GetProcessHeap(), 0, hlpfile
->phrases_offsets
);
2271 HeapFree(GetProcessHeap(), 0, hlpfile
->phrases_buffer
);
2272 HeapFree(GetProcessHeap(), 0, hlpfile
->topic_map
);
2273 HeapFree(GetProcessHeap(), 0, hlpfile
);