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
27 //#include <winbase.h>
30 #include <wine/debug.h>
34 WINE_DEFAULT_DEBUG_CHANNEL(winhelp
);
36 static inline unsigned short GET_USHORT(const BYTE
* buffer
, unsigned i
)
38 return (BYTE
)buffer
[i
] + 0x100 * (BYTE
)buffer
[i
+ 1];
41 static inline short GET_SHORT(const BYTE
* buffer
, unsigned i
)
43 return (BYTE
)buffer
[i
] + 0x100 * (signed char)buffer
[i
+1];
46 static inline unsigned GET_UINT(const BYTE
* buffer
, unsigned i
)
48 return GET_USHORT(buffer
, i
) + 0x10000 * GET_USHORT(buffer
, i
+ 2);
51 static HLPFILE
*first_hlpfile
= 0;
54 /**************************************************************************
55 * HLPFILE_BPTreeSearch
57 * Searches for an element in B+ tree
60 * buf [I] pointer to the embedded file structured as a B+ tree
61 * key [I] pointer to data to find
62 * comp [I] compare function
65 * Pointer to block identified by key, or NULL if failure.
68 static void* HLPFILE_BPTreeSearch(BYTE
* buf
, const void* key
,
69 HLPFILE_BPTreeCompare comp
)
75 BYTE
*pages
, *ptr
, *newptr
;
79 magic
= GET_USHORT(buf
, 9);
82 WINE_ERR("Invalid magic in B+ tree: 0x%x\n", magic
);
85 page_size
= GET_USHORT(buf
, 9+4);
86 cur_page
= GET_USHORT(buf
, 9+26);
87 level
= GET_USHORT(buf
, 9+32);
91 ptr
= pages
+ cur_page
*page_size
;
92 entries
= GET_SHORT(ptr
, 2);
94 for (i
= 0; i
< entries
; i
++)
96 if (comp(ptr
, key
, 0, (void **)&newptr
) > 0) break;
99 cur_page
= GET_USHORT(ptr
-2, 0);
101 ptr
= pages
+ cur_page
*page_size
;
102 entries
= GET_SHORT(ptr
, 2);
104 for (i
= 0; i
< entries
; i
++)
106 ret
= comp(ptr
, key
, 1, (void **)&newptr
);
107 if (ret
== 0) return ptr
;
108 if (ret
> 0) return NULL
;
114 /**************************************************************************
117 * Enumerates elements in B+ tree.
120 * buf [I] pointer to the embedded file structured as a B+ tree
121 * cb [I] compare function
122 * cookie [IO] cookie for cb function
124 void HLPFILE_BPTreeEnum(BYTE
* buf
, HLPFILE_BPTreeCallback cb
, void* cookie
)
130 BYTE
*pages
, *ptr
, *newptr
;
133 magic
= GET_USHORT(buf
, 9);
136 WINE_ERR("Invalid magic in B+ tree: 0x%x\n", magic
);
139 page_size
= GET_USHORT(buf
, 9+4);
140 cur_page
= GET_USHORT(buf
, 9+26);
141 level
= GET_USHORT(buf
, 9+32);
142 pages
= buf
+ 9 + 38;
145 ptr
= pages
+ cur_page
*page_size
;
146 cur_page
= GET_USHORT(ptr
, 4);
148 while (cur_page
!= 0xFFFF)
150 ptr
= pages
+ cur_page
*page_size
;
151 entries
= GET_SHORT(ptr
, 2);
153 for (i
= 0; i
< entries
; i
++)
155 cb(ptr
, (void **)&newptr
, cookie
);
158 cur_page
= GET_USHORT(pages
+cur_page
*page_size
, 6);
163 /***********************************************************************
165 * HLPFILE_UncompressedLZ77_Size
167 static INT
HLPFILE_UncompressedLZ77_Size(const BYTE
*ptr
, const BYTE
*end
)
174 for (i
= 0; i
< 8 && ptr
< end
; i
++, mask
>>= 1)
178 int code
= GET_USHORT(ptr
, 0);
179 int len
= 3 + (code
>> 12);
183 else newsize
++, ptr
++;
190 /***********************************************************************
192 * HLPFILE_UncompressLZ77
194 static BYTE
*HLPFILE_UncompressLZ77(const BYTE
*ptr
, const BYTE
*end
, BYTE
*newptr
)
201 for (i
= 0; i
< 8 && ptr
< end
; i
++, mask
>>= 1)
205 int code
= GET_USHORT(ptr
, 0);
206 int len
= 3 + (code
>> 12);
207 int offset
= code
& 0xfff;
209 * We must copy byte-by-byte here. We cannot use memcpy nor
210 * memmove here. Just example:
211 * a[]={1,2,3,4,5,6,7,8,9,10}
215 * {1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 11, 12}
217 for (; len
>0; len
--, newptr
++) *newptr
= *(newptr
-offset
-1);
220 else *newptr
++ = *ptr
++;
227 /***********************************************************************
229 * HLPFILE_Uncompress2
232 static void HLPFILE_Uncompress2(HLPFILE
* hlpfile
, const BYTE
*ptr
, const BYTE
*end
, BYTE
*newptr
, const BYTE
*newend
)
238 while (ptr
< end
&& newptr
< newend
)
240 if (!*ptr
|| *ptr
>= 0x10)
244 code
= 0x100 * ptr
[0] + ptr
[1];
245 index
= (code
- 0x100) / 2;
247 phptr
= (BYTE
*)hlpfile
->phrases_buffer
+ hlpfile
->phrases_offsets
[index
];
248 phend
= (BYTE
*)hlpfile
->phrases_buffer
+ hlpfile
->phrases_offsets
[index
+ 1];
250 if (newptr
+ (phend
- phptr
) > newend
)
252 WINE_FIXME("buffer overflow %p > %p for %lu bytes\n",
253 newptr
, newend
, (SIZE_T
)(phend
- phptr
));
256 memcpy(newptr
, phptr
, phend
- phptr
);
257 newptr
+= phend
- phptr
;
258 if (code
& 1) *newptr
++ = ' ';
263 if (newptr
> newend
) WINE_FIXME("buffer overflow %p > %p\n", newptr
, newend
);
266 /******************************************************************
267 * HLPFILE_Uncompress3
271 static BOOL
HLPFILE_Uncompress3(HLPFILE
* hlpfile
, char* dst
, const char* dst_end
,
272 const BYTE
* src
, const BYTE
* src_end
)
274 unsigned int idx
, len
;
276 for (; src
< src_end
; src
++)
281 if (idx
> hlpfile
->num_phrases
)
283 WINE_ERR("index in phrases %d/%d\n", idx
, hlpfile
->num_phrases
);
288 len
= hlpfile
->phrases_offsets
[idx
+ 1] - hlpfile
->phrases_offsets
[idx
];
289 if (dst
+ len
<= dst_end
)
290 memcpy(dst
, &hlpfile
->phrases_buffer
[hlpfile
->phrases_offsets
[idx
]], len
);
293 else if ((*src
& 0x03) == 0x01)
295 idx
= (*src
+ 1) * 64;
297 if (idx
> hlpfile
->num_phrases
)
299 WINE_ERR("index in phrases %d/%d\n", idx
, hlpfile
->num_phrases
);
304 len
= hlpfile
->phrases_offsets
[idx
+ 1] - hlpfile
->phrases_offsets
[idx
];
305 if (dst
+ len
<= dst_end
)
306 memcpy(dst
, &hlpfile
->phrases_buffer
[hlpfile
->phrases_offsets
[idx
]], len
);
309 else if ((*src
& 0x07) == 0x03)
311 len
= (*src
/ 8) + 1;
312 if (dst
+ len
<= dst_end
)
313 memcpy(dst
, src
+ 1, len
);
318 len
= (*src
/ 16) + 1;
319 if (dst
+ len
<= dst_end
)
320 memset(dst
, ((*src
& 0x0F) == 0x07) ? ' ' : 0, len
);
325 if (dst
> dst_end
) WINE_ERR("buffer overflow (%p > %p)\n", dst
, dst_end
);
329 /******************************************************************
330 * HLPFILE_UncompressRLE
334 static void HLPFILE_UncompressRLE(const BYTE
* src
, const BYTE
* end
, BYTE
* dst
, unsigned dstsz
)
337 BYTE
* sdst
= dst
+ dstsz
;
345 if (dst
+ ch
<= sdst
)
346 memcpy(dst
, src
, ch
);
351 if (dst
+ ch
<= sdst
)
352 memset(dst
, (char)*src
, ch
);
358 WINE_WARN("Buffer X-flow: d(%lu) instead of d(%u)\n",
359 (SIZE_T
)(dst
- (sdst
- dstsz
)), dstsz
);
363 /******************************************************************
364 * HLPFILE_PageByOffset
368 HLPFILE_PAGE
*HLPFILE_PageByOffset(HLPFILE
* hlpfile
, LONG offset
, ULONG
* relative
)
373 if (!hlpfile
) return 0;
375 WINE_TRACE("<%s>[%x]\n", hlpfile
->lpszPath
, offset
);
377 if (offset
== 0xFFFFFFFF) return NULL
;
380 for (found
= NULL
, page
= hlpfile
->first_page
; page
; page
= page
->next
)
382 if (page
->offset
<= offset
&& (!found
|| found
->offset
< page
->offset
))
384 *relative
= offset
- page
->offset
;
389 WINE_ERR("Page of offset %u not found in file %s\n",
390 offset
, hlpfile
->lpszPath
);
394 /***********************************************************************
398 static HLPFILE_PAGE
* HLPFILE_Contents(HLPFILE
*hlpfile
, ULONG
* relative
)
400 HLPFILE_PAGE
* page
= NULL
;
402 if (!hlpfile
) return NULL
;
404 page
= HLPFILE_PageByOffset(hlpfile
, hlpfile
->contents_start
, relative
);
407 page
= hlpfile
->first_page
;
413 /**************************************************************************
416 * HLPFILE_BPTreeCompare function for '|CONTEXT' B+ tree file
419 static int comp_PageByHash(void *p
, const void *key
,
420 int leaf
, void** next
)
422 LONG lKey
= (LONG_PTR
)key
;
423 LONG lTest
= (INT
)GET_UINT(p
, 0);
425 *next
= (char *)p
+(leaf
?8:6);
426 WINE_TRACE("Comparing '%d' with '%d'\n", lKey
, lTest
);
427 if (lTest
< lKey
) return -1;
428 if (lTest
> lKey
) return 1;
432 /***********************************************************************
436 HLPFILE_PAGE
*HLPFILE_PageByHash(HLPFILE
* hlpfile
, LONG lHash
, ULONG
* relative
)
440 if (!hlpfile
) return NULL
;
441 if (!lHash
) return HLPFILE_Contents(hlpfile
, relative
);
443 WINE_TRACE("<%s>[%x]\n", hlpfile
->lpszPath
, lHash
);
445 /* For win 3.0 files hash values are really page numbers */
446 if (hlpfile
->version
<= 16)
448 if (lHash
>= hlpfile
->wTOMapLen
) return NULL
;
449 return HLPFILE_PageByOffset(hlpfile
, hlpfile
->TOMap
[lHash
], relative
);
452 ptr
= HLPFILE_BPTreeSearch(hlpfile
->Context
, LongToPtr(lHash
), comp_PageByHash
);
455 WINE_ERR("Page of hash %x not found in file %s\n", lHash
, hlpfile
->lpszPath
);
459 return HLPFILE_PageByOffset(hlpfile
, GET_UINT(ptr
, 4), relative
);
462 /***********************************************************************
466 HLPFILE_PAGE
*HLPFILE_PageByMap(HLPFILE
* hlpfile
, LONG lMap
, ULONG
* relative
)
470 if (!hlpfile
) return 0;
472 WINE_TRACE("<%s>[%x]\n", hlpfile
->lpszPath
, lMap
);
474 for (i
= 0; i
< hlpfile
->wMapLen
; i
++)
476 if (hlpfile
->Map
[i
].lMap
== lMap
)
477 return HLPFILE_PageByOffset(hlpfile
, hlpfile
->Map
[i
].offset
, relative
);
480 WINE_ERR("Page of Map %x not found in file %s\n", lMap
, hlpfile
->lpszPath
);
484 /**************************************************************************
487 * HLPFILE_BPTreeCompare function for HLPFILE directory.
490 static int comp_FindSubFile(void *p
, const void *key
,
491 int leaf
, void** next
)
493 *next
= (char *)p
+strlen(p
)+(leaf
?5:3);
494 WINE_TRACE("Comparing '%s' with '%s'\n", (char *)p
, (const char *)key
);
495 return strcmp(p
, key
);
498 /***********************************************************************
500 * HLPFILE_FindSubFile
502 static BOOL
HLPFILE_FindSubFile(HLPFILE
* hlpfile
, LPCSTR name
, BYTE
**subbuf
, BYTE
**subend
)
506 WINE_TRACE("looking for file '%s'\n", name
);
507 ptr
= HLPFILE_BPTreeSearch(hlpfile
->file_buffer
+ GET_UINT(hlpfile
->file_buffer
, 4),
508 name
, comp_FindSubFile
);
509 if (!ptr
) return FALSE
;
510 *subbuf
= hlpfile
->file_buffer
+ GET_UINT(ptr
, strlen(name
)+1);
511 if (*subbuf
>= hlpfile
->file_buffer
+ hlpfile
->file_buffer_size
)
513 WINE_ERR("internal file %s does not fit\n", name
);
516 *subend
= *subbuf
+ GET_UINT(*subbuf
, 0);
517 if (*subend
> hlpfile
->file_buffer
+ hlpfile
->file_buffer_size
)
519 WINE_ERR("internal file %s does not fit\n", name
);
522 if (GET_UINT(*subbuf
, 0) < GET_UINT(*subbuf
, 4) + 9)
524 WINE_ERR("invalid size provided for internal file %s\n", name
);
530 /***********************************************************************
534 LONG
HLPFILE_Hash(LPCSTR lpszContext
)
539 while ((c
= *lpszContext
++))
542 if (c
>= 'A' && c
<= 'Z') x
= c
- 'A' + 17;
543 if (c
>= 'a' && c
<= 'z') x
= c
- 'a' + 17;
544 if (c
>= '1' && c
<= '9') x
= c
- '0';
545 if (c
== '0') x
= 10;
546 if (c
== '.') x
= 12;
547 if (c
== '_') x
= 13;
548 if (x
) lHash
= lHash
* 43 + x
;
553 static LONG
fetch_long(const BYTE
** ptr
)
559 ret
= (*(const ULONG
*)(*ptr
) - 0x80000000) / 2;
564 ret
= (*(const USHORT
*)(*ptr
) - 0x8000) / 2;
571 static ULONG
fetch_ulong(const BYTE
** ptr
)
577 ret
= *(const ULONG
*)(*ptr
) / 2;
582 ret
= *(const USHORT
*)(*ptr
) / 2;
588 static short fetch_short(const BYTE
** ptr
)
594 ret
= (*(const unsigned short*)(*ptr
) - 0x8000) / 2;
599 ret
= (*(const unsigned char*)(*ptr
) - 0x80) / 2;
605 static unsigned short fetch_ushort(const BYTE
** ptr
)
611 ret
= *(const unsigned short*)(*ptr
) / 2;
616 ret
= *(const unsigned char*)(*ptr
) / 2;
622 /******************************************************************
623 * HLPFILE_DecompressGfx
625 * Decompress the data part of a bitmap or a metafile
627 static const BYTE
* HLPFILE_DecompressGfx(const BYTE
* src
, unsigned csz
, unsigned sz
, BYTE packing
,
634 WINE_TRACE("Unpacking (%d) from %u bytes to %u bytes\n", packing
, csz
, sz
);
638 case 0: /* uncompressed */
640 WINE_WARN("Bogus gfx sizes (uncompressed): %u / %u\n", sz
, csz
);
645 dst
= *alloc
= HeapAlloc(GetProcessHeap(), 0, sz
);
646 if (!dst
) return NULL
;
647 HLPFILE_UncompressRLE(src
, src
+ csz
, *alloc
, sz
);
650 sz77
= HLPFILE_UncompressedLZ77_Size(src
, src
+ csz
);
651 dst
= *alloc
= HeapAlloc(GetProcessHeap(), 0, sz77
);
652 if (!dst
) return NULL
;
653 HLPFILE_UncompressLZ77(src
, src
+ csz
, *alloc
);
655 WINE_WARN("Bogus gfx sizes (LZ77): %u / %u\n", sz77
, sz
);
657 case 3: /* LZ77 then RLE */
658 sz77
= HLPFILE_UncompressedLZ77_Size(src
, src
+ csz
);
659 tmp
= HeapAlloc(GetProcessHeap(), 0, sz77
);
660 if (!tmp
) return FALSE
;
661 HLPFILE_UncompressLZ77(src
, src
+ csz
, tmp
);
662 dst
= *alloc
= HeapAlloc(GetProcessHeap(), 0, sz
);
665 HeapFree(GetProcessHeap(), 0, tmp
);
668 HLPFILE_UncompressRLE(tmp
, tmp
+ sz77
, *alloc
, sz
);
669 HeapFree(GetProcessHeap(), 0, tmp
);
672 WINE_FIXME("Unsupported packing %u\n", packing
);
678 static BOOL
HLPFILE_RtfAddRawString(struct RtfData
* rd
, const char* str
, size_t sz
)
680 if (rd
->ptr
+ sz
>= rd
->data
+ rd
->allocated
)
682 char* new = HeapReAlloc(GetProcessHeap(), 0, rd
->data
, rd
->allocated
*= 2);
683 if (!new) return FALSE
;
684 rd
->ptr
= new + (rd
->ptr
- rd
->data
);
687 memcpy(rd
->ptr
, str
, sz
);
693 static BOOL
HLPFILE_RtfAddControl(struct RtfData
* rd
, const char* str
)
695 if (*str
== '\\' || *str
== '{') rd
->in_text
= FALSE
;
696 else if (*str
== '}') rd
->in_text
= TRUE
;
697 return HLPFILE_RtfAddRawString(rd
, str
, strlen(str
));
700 static BOOL
HLPFILE_RtfAddText(struct RtfData
* rd
, const char* str
)
709 if (!HLPFILE_RtfAddRawString(rd
, " ", 1)) return FALSE
;
712 for (last
= p
= str
; *p
; p
++)
714 if (*p
& 0x80) /* escape non-ASCII chars */
717 rlen
= sprintf(xx
, "\\'%x", *(const BYTE
*)p
);
722 case '{': rlen
= 2; replace
= "\\{"; break;
723 case '}': rlen
= 2; replace
= "\\}"; break;
724 case '\\': rlen
= 2; replace
= "\\\\"; break;
727 if ((p
!= last
&& !HLPFILE_RtfAddRawString(rd
, last
, p
- last
)) ||
728 !HLPFILE_RtfAddRawString(rd
, replace
, rlen
)) return FALSE
;
731 return HLPFILE_RtfAddRawString(rd
, last
, p
- last
);
734 /******************************************************************
738 static BOOL
HLPFILE_RtfAddHexBytes(struct RtfData
* rd
, const void* _ptr
, unsigned sz
)
742 const BYTE
* ptr
= _ptr
;
743 static const char* _2hex
= "0123456789abcdef";
747 if (!HLPFILE_RtfAddRawString(rd
, " ", 1)) return FALSE
;
750 for (; sz
; sz
-= step
)
753 for (i
= 0; i
< step
; i
++)
755 tmp
[2 * i
+ 0] = _2hex
[*ptr
>> 4];
756 tmp
[2 * i
+ 1] = _2hex
[*ptr
++ & 0xF];
758 if (!HLPFILE_RtfAddRawString(rd
, tmp
, 2 * step
)) return FALSE
;
763 static HLPFILE_LINK
* HLPFILE_AllocLink(struct RtfData
* rd
, int cookie
,
764 const char* str
, unsigned len
, LONG hash
,
765 unsigned clrChange
, unsigned bHotSpot
, unsigned wnd
);
767 /******************************************************************
768 * HLPFILE_AddHotSpotLinks
771 static void HLPFILE_AddHotSpotLinks(struct RtfData
* rd
, HLPFILE
* file
,
772 const BYTE
* start
, ULONG hs_size
, ULONG hs_offset
)
778 if (hs_size
== 0 || hs_offset
== 0) return;
782 hs_num
= GET_USHORT(start
, 1);
783 hs_macro
= GET_UINT(start
, 3);
785 str
= (const char*)start
+ 7 + 15 * hs_num
+ hs_macro
;
786 /* FIXME: should use hs_size to prevent out of bounds reads */
787 for (i
= 0; i
< hs_num
; i
++)
789 HLPFILE_HOTSPOTLINK
* hslink
;
791 WINE_TRACE("%02x-%02x%02x {%s,%s}\n",
792 start
[7 + 15 * i
+ 0], start
[7 + 15 * i
+ 1], start
[7 + 15 * i
+ 2],
793 str
, str
+ strlen(str
) + 1);
794 /* str points to two null terminated strings:
795 * hotspot name, then link name
797 str
+= strlen(str
) + 1; /* skip hotspot name */
800 switch (start
[7 + 15 * i
+ 0])
801 /* The next two chars always look like 0x04 0x00 ???
802 * What are they for ?
806 hslink
= (HLPFILE_HOTSPOTLINK
*)
807 HLPFILE_AllocLink(rd
, hlp_link_macro
, str
, -1, 0, 0, 1, -1);
812 hslink
= (HLPFILE_HOTSPOTLINK
*)
813 HLPFILE_AllocLink(rd
, (start
[7 + 15 * i
+ 0] & 1) ? hlp_link_link
: hlp_link_popup
,
814 file
->lpszPath
, -1, HLPFILE_Hash(str
),
821 const char* win
= strchr(str
, '>');
827 for (wnd
= file
->numWindows
- 1; wnd
>= 0; wnd
--)
829 if (!strcmp(win
+ 1, file
->windows
[wnd
].name
)) break;
832 WINE_WARN("Couldn't find window info for %s\n", win
);
833 if ((tgt
= HeapAlloc(GetProcessHeap(), 0, win
- str
+ 1)))
835 memcpy(tgt
, str
, win
- str
);
836 tgt
[win
- str
] = '\0';
839 hslink
= (HLPFILE_HOTSPOTLINK
*)
840 HLPFILE_AllocLink(rd
, (start
[7 + 15 * i
+ 0] & 1) ? hlp_link_link
: hlp_link_popup
,
841 file
->lpszPath
, -1, HLPFILE_Hash(tgt
? tgt
: str
), 0, 1, wnd
);
842 HeapFree(GetProcessHeap(), 0, tgt
);
846 WINE_FIXME("unknown hotsport target 0x%x\n", start
[7 + 15 * i
+ 0]);
850 hslink
->x
= GET_USHORT(start
, 7 + 15 * i
+ 3);
851 hslink
->y
= GET_USHORT(start
, 7 + 15 * i
+ 5);
852 hslink
->width
= GET_USHORT(start
, 7 + 15 * i
+ 7);
853 hslink
->height
= GET_USHORT(start
, 7 + 15 * i
+ 9);
854 /* target = GET_UINT(start, 7 + 15 * i + 11); */
856 str
+= strlen(str
) + 1;
860 /******************************************************************
861 * HLPFILE_RtfAddTransparentBitmap
863 * We'll transform a transparent bitmap into an metafile that
864 * we then transform into RTF
866 static BOOL
HLPFILE_RtfAddTransparentBitmap(struct RtfData
* rd
, const BITMAPINFO
* bi
,
867 const void* pict
, unsigned nc
)
869 HDC hdc
, hdcMask
, hdcMem
, hdcEMF
;
870 HBITMAP hbm
, hbmMask
, hbmOldMask
, hbmOldMem
;
876 hbm
= CreateDIBitmap(hdc
= GetDC(0), &bi
->bmiHeader
,
877 CBM_INIT
, pict
, bi
, DIB_RGB_COLORS
);
879 hdcMem
= CreateCompatibleDC(hdc
);
880 hbmOldMem
= SelectObject(hdcMem
, hbm
);
882 /* create the mask bitmap from the main bitmap */
883 hdcMask
= CreateCompatibleDC(hdc
);
884 hbmMask
= CreateBitmap(bi
->bmiHeader
.biWidth
, bi
->bmiHeader
.biHeight
, 1, 1, NULL
);
885 hbmOldMask
= SelectObject(hdcMask
, hbmMask
);
887 RGB(bi
->bmiColors
[nc
- 1].rgbRed
,
888 bi
->bmiColors
[nc
- 1].rgbGreen
,
889 bi
->bmiColors
[nc
- 1].rgbBlue
));
890 BitBlt(hdcMask
, 0, 0, bi
->bmiHeader
.biWidth
, bi
->bmiHeader
.biHeight
, hdcMem
, 0, 0, SRCCOPY
);
892 /* sets to RGB(0,0,0) the transparent bits in main bitmap */
893 SetBkColor(hdcMem
, RGB(0,0,0));
894 SetTextColor(hdcMem
, RGB(255,255,255));
895 BitBlt(hdcMem
, 0, 0, bi
->bmiHeader
.biWidth
, bi
->bmiHeader
.biHeight
, hdcMask
, 0, 0, SRCAND
);
897 SelectObject(hdcMask
, hbmOldMask
);
900 SelectObject(hdcMem
, hbmOldMem
);
903 /* we create the bitmap on the fly */
904 hdcEMF
= CreateEnhMetaFileW(NULL
, NULL
, NULL
, NULL
);
905 hdcMem
= CreateCompatibleDC(hdcEMF
);
907 /* sets to RGB(0,0,0) the transparent bits in final bitmap */
908 hbmOldMem
= SelectObject(hdcMem
, hbmMask
);
909 SetBkColor(hdcEMF
, RGB(255, 255, 255));
910 SetTextColor(hdcEMF
, RGB(0, 0, 0));
911 BitBlt(hdcEMF
, 0, 0, bi
->bmiHeader
.biWidth
, bi
->bmiHeader
.biHeight
, hdcMem
, 0, 0, SRCAND
);
913 /* and copy the remaining bits of main bitmap */
914 SelectObject(hdcMem
, hbm
);
915 BitBlt(hdcEMF
, 0, 0, bi
->bmiHeader
.biWidth
, bi
->bmiHeader
.biHeight
, hdcMem
, 0, 0, SRCPAINT
);
916 SelectObject(hdcMem
, hbmOldMem
);
921 DeleteObject(hbmMask
);
924 hEMF
= CloseEnhMetaFile(hdcEMF
);
926 /* generate rtf stream */
927 sz
= GetEnhMetaFileBits(hEMF
, 0, NULL
);
928 if (sz
&& (data
= HeapAlloc(GetProcessHeap(), 0, sz
)))
930 if (sz
== GetEnhMetaFileBits(hEMF
, sz
, data
))
932 ret
= HLPFILE_RtfAddControl(rd
, "{\\pict\\emfblip") &&
933 HLPFILE_RtfAddHexBytes(rd
, data
, sz
) &&
934 HLPFILE_RtfAddControl(rd
, "}");
936 HeapFree(GetProcessHeap(), 0, data
);
938 DeleteEnhMetaFile(hEMF
);
943 /******************************************************************
944 * HLPFILE_RtfAddBitmap
947 static BOOL
HLPFILE_RtfAddBitmap(struct RtfData
* rd
, HLPFILE
* file
, const BYTE
* beg
, BYTE type
, BYTE pack
)
950 const BYTE
* pict_beg
;
955 BOOL clrImportant
= FALSE
;
958 unsigned hs_size
, hs_offset
;
960 bi
= HeapAlloc(GetProcessHeap(), 0, sizeof(*bi
));
961 if (!bi
) return FALSE
;
963 ptr
= beg
+ 2; /* for type and pack */
965 bi
->bmiHeader
.biSize
= sizeof(bi
->bmiHeader
);
966 bi
->bmiHeader
.biXPelsPerMeter
= fetch_ulong(&ptr
);
967 bi
->bmiHeader
.biYPelsPerMeter
= fetch_ulong(&ptr
);
968 bi
->bmiHeader
.biPlanes
= fetch_ushort(&ptr
);
969 bi
->bmiHeader
.biBitCount
= fetch_ushort(&ptr
);
970 bi
->bmiHeader
.biWidth
= fetch_ulong(&ptr
);
971 bi
->bmiHeader
.biHeight
= fetch_ulong(&ptr
);
972 bi
->bmiHeader
.biClrUsed
= fetch_ulong(&ptr
);
973 clrImportant
= fetch_ulong(&ptr
);
974 bi
->bmiHeader
.biClrImportant
= (clrImportant
> 1) ? clrImportant
: 0;
975 bi
->bmiHeader
.biCompression
= BI_RGB
;
976 if (bi
->bmiHeader
.biBitCount
> 32) WINE_FIXME("Unknown bit count %u\n", bi
->bmiHeader
.biBitCount
);
977 if (bi
->bmiHeader
.biPlanes
!= 1) WINE_FIXME("Unsupported planes %u\n", bi
->bmiHeader
.biPlanes
);
978 bi
->bmiHeader
.biSizeImage
= (((bi
->bmiHeader
.biWidth
* bi
->bmiHeader
.biBitCount
+ 31) & ~31) / 8) * bi
->bmiHeader
.biHeight
;
979 WINE_TRACE("planes=%d bc=%d size=(%d,%d)\n",
980 bi
->bmiHeader
.biPlanes
, bi
->bmiHeader
.biBitCount
,
981 bi
->bmiHeader
.biWidth
, bi
->bmiHeader
.biHeight
);
983 csz
= fetch_ulong(&ptr
);
984 hs_size
= fetch_ulong(&ptr
);
986 off
= GET_UINT(ptr
, 0); ptr
+= 4;
987 hs_offset
= GET_UINT(ptr
, 0); ptr
+= 4;
988 HLPFILE_AddHotSpotLinks(rd
, file
, beg
, hs_size
, hs_offset
);
990 /* now read palette info */
995 nc
= bi
->bmiHeader
.biClrUsed
;
996 /* not quite right, especially for bitfields type of compression */
997 if (!nc
&& bi
->bmiHeader
.biBitCount
<= 8)
998 nc
= 1 << bi
->bmiHeader
.biBitCount
;
1000 bi
= HeapReAlloc(GetProcessHeap(), 0, bi
, sizeof(*bi
) + nc
* sizeof(RGBQUAD
));
1001 if (!bi
) return FALSE
;
1002 for (i
= 0; i
< nc
; i
++)
1004 bi
->bmiColors
[i
].rgbBlue
= ptr
[0];
1005 bi
->bmiColors
[i
].rgbGreen
= ptr
[1];
1006 bi
->bmiColors
[i
].rgbRed
= ptr
[2];
1007 bi
->bmiColors
[i
].rgbReserved
= 0;
1011 pict_beg
= HLPFILE_DecompressGfx(beg
+ off
, csz
, bi
->bmiHeader
.biSizeImage
, pack
, &alloc
);
1013 if (clrImportant
== 1 && nc
> 0)
1015 ret
= HLPFILE_RtfAddTransparentBitmap(rd
, bi
, pict_beg
, nc
);
1018 if (!HLPFILE_RtfAddControl(rd
, "{\\pict")) goto done
;
1021 sprintf(tmp
, "\\dibitmap0\\picw%d\\pich%d",
1022 bi
->bmiHeader
.biWidth
, bi
->bmiHeader
.biHeight
);
1023 if (!HLPFILE_RtfAddControl(rd
, tmp
)) goto done
;
1024 if (!HLPFILE_RtfAddHexBytes(rd
, bi
, sizeof(*bi
) + nc
* sizeof(RGBQUAD
))) goto done
;
1028 sprintf(tmp
, "\\wbitmap0\\wbmbitspixel%d\\wbmplanes%d\\picw%d\\pich%d",
1029 bi
->bmiHeader
.biBitCount
, bi
->bmiHeader
.biPlanes
,
1030 bi
->bmiHeader
.biWidth
, bi
->bmiHeader
.biHeight
);
1031 if (!HLPFILE_RtfAddControl(rd
, tmp
)) goto done
;
1033 if (!HLPFILE_RtfAddHexBytes(rd
, pict_beg
, bi
->bmiHeader
.biSizeImage
)) goto done
;
1034 if (!HLPFILE_RtfAddControl(rd
, "}")) goto done
;
1038 HeapFree(GetProcessHeap(), 0, bi
);
1039 HeapFree(GetProcessHeap(), 0, alloc
);
1044 /******************************************************************
1045 * HLPFILE_RtfAddMetaFile
1048 static BOOL
HLPFILE_RtfAddMetaFile(struct RtfData
* rd
, HLPFILE
* file
, const BYTE
* beg
, BYTE pack
)
1050 ULONG size
, csize
, off
, hs_offset
, hs_size
;
1058 WINE_TRACE("Loading metafile\n");
1060 ptr
= beg
+ 2; /* for type and pack */
1062 mm
= fetch_ushort(&ptr
); /* mapping mode */
1063 sprintf(tmp
, "{\\pict\\wmetafile%d\\picw%d\\pich%d",
1064 mm
, GET_USHORT(ptr
, 0), GET_USHORT(ptr
, 2));
1065 if (!HLPFILE_RtfAddControl(rd
, tmp
)) return FALSE
;
1068 size
= fetch_ulong(&ptr
); /* decompressed size */
1069 csize
= fetch_ulong(&ptr
); /* compressed size */
1070 hs_size
= fetch_ulong(&ptr
); /* hotspot size */
1071 off
= GET_UINT(ptr
, 0);
1072 hs_offset
= GET_UINT(ptr
, 4);
1075 HLPFILE_AddHotSpotLinks(rd
, file
, beg
, hs_size
, hs_offset
);
1077 WINE_TRACE("sz=%u csz=%u offs=%u/%u,%u/%u\n",
1078 size
, csize
, off
, (ULONG
)(ptr
- beg
), hs_size
, hs_offset
);
1080 bits
= HLPFILE_DecompressGfx(beg
+ off
, csize
, size
, pack
, &alloc
);
1081 if (!bits
) return FALSE
;
1083 ret
= HLPFILE_RtfAddHexBytes(rd
, bits
, size
) &&
1084 HLPFILE_RtfAddControl(rd
, "}");
1086 HeapFree(GetProcessHeap(), 0, alloc
);
1091 /******************************************************************
1092 * HLPFILE_RtfAddGfxByAddr
1095 static BOOL
HLPFILE_RtfAddGfxByAddr(struct RtfData
* rd
, HLPFILE
*hlpfile
,
1096 const BYTE
* ref
, ULONG size
)
1098 unsigned i
, numpict
;
1100 numpict
= GET_USHORT(ref
, 2);
1101 WINE_TRACE("Got picture magic=%04x #=%d\n", GET_USHORT(ref
, 0), numpict
);
1103 for (i
= 0; i
< numpict
; i
++)
1109 WINE_TRACE("Offset[%d] = %x\n", i
, GET_UINT(ref
, (1 + i
) * 4));
1110 beg
= ptr
= ref
+ GET_UINT(ref
, (1 + i
) * 4);
1117 case 5: /* device dependent bmp */
1118 case 6: /* device independent bmp */
1119 HLPFILE_RtfAddBitmap(rd
, hlpfile
, beg
, type
, pack
);
1122 HLPFILE_RtfAddMetaFile(rd
, hlpfile
, beg
, pack
);
1124 default: WINE_FIXME("Unknown type %u\n", type
); return FALSE
;
1127 /* FIXME: hotspots */
1129 /* FIXME: implement support for multiple picture format */
1130 if (numpict
!= 1) WINE_FIXME("Supporting only one bitmap format per logical bitmap (for now). Using first format\n");
1136 /******************************************************************
1137 * HLPFILE_RtfAddGfxByIndex
1141 static BOOL
HLPFILE_RtfAddGfxByIndex(struct RtfData
* rd
, HLPFILE
*hlpfile
,
1147 WINE_TRACE("Loading picture #%d\n", index
);
1149 sprintf(tmp
, "|bm%u", index
);
1151 if (!HLPFILE_FindSubFile(hlpfile
, tmp
, &ref
, &end
)) {WINE_WARN("no sub file\n"); return FALSE
;}
1154 return HLPFILE_RtfAddGfxByAddr(rd
, hlpfile
, ref
, end
- ref
);
1157 /******************************************************************
1162 static HLPFILE_LINK
* HLPFILE_AllocLink(struct RtfData
* rd
, int cookie
,
1163 const char* str
, unsigned len
, LONG hash
,
1164 unsigned clrChange
, unsigned bHotSpot
, unsigned wnd
)
1168 unsigned asz
= bHotSpot
? sizeof(HLPFILE_HOTSPOTLINK
) : sizeof(HLPFILE_LINK
);
1170 /* FIXME: should build a string table for the attributes.link.lpszPath
1171 * they are reallocated for each link
1173 if (len
== -1) len
= strlen(str
);
1174 link
= HeapAlloc(GetProcessHeap(), 0, asz
+ len
+ 1);
1175 if (!link
) return NULL
;
1177 link
->cookie
= cookie
;
1178 link
->string
= link_str
= (char*)link
+ asz
;
1179 memcpy(link_str
, str
, len
);
1180 link_str
[len
] = '\0';
1182 link
->bClrChange
= clrChange
? 1 : 0;
1183 link
->bHotSpot
= bHotSpot
;
1185 link
->next
= rd
->first_link
;
1186 rd
->first_link
= link
;
1187 link
->cpMin
= rd
->char_pos
;
1188 rd
->force_color
= clrChange
;
1189 if (rd
->current_link
) WINE_FIXME("Pending link\n");
1191 link
->cpMax
= rd
->char_pos
;
1193 rd
->current_link
= link
;
1195 WINE_TRACE("Link[%d] to %s@%08x:%d\n",
1196 link
->cookie
, link
->string
, link
->hash
, link
->window
);
1200 static unsigned HLPFILE_HalfPointsToTwips(unsigned pts
)
1202 static unsigned logPxY
;
1205 HDC hdc
= GetDC(NULL
);
1206 logPxY
= GetDeviceCaps(hdc
, LOGPIXELSY
);
1207 ReleaseDC(NULL
, hdc
);
1209 return MulDiv(pts
, 72 * 10, logPxY
);
1212 /***********************************************************************
1214 * HLPFILE_BrowseParagraph
1216 static BOOL
HLPFILE_BrowseParagraph(HLPFILE_PAGE
* page
, struct RtfData
* rd
,
1217 BYTE
*buf
, BYTE
* end
, unsigned* parlen
)
1220 const BYTE
*format
, *format_end
;
1221 char *text
, *text_base
, *text_end
;
1222 LONG size
, blocksize
, datalen
;
1223 unsigned short bits
;
1224 unsigned nc
, ncol
= 1;
1226 BOOL in_table
= FALSE
;
1230 if (buf
+ 0x19 > end
) {WINE_WARN("header too small\n"); return FALSE
;};
1233 blocksize
= GET_UINT(buf
, 0);
1234 size
= GET_UINT(buf
, 0x4);
1235 datalen
= GET_UINT(buf
, 0x10);
1236 text
= text_base
= HeapAlloc(GetProcessHeap(), 0, size
);
1237 if (!text
) return FALSE
;
1238 if (size
> blocksize
- datalen
)
1240 /* need to decompress */
1241 if (page
->file
->hasPhrases
)
1242 HLPFILE_Uncompress2(page
->file
, buf
+ datalen
, end
, (BYTE
*)text
, (BYTE
*)text
+ size
);
1243 else if (page
->file
->hasPhrases40
)
1244 HLPFILE_Uncompress3(page
->file
, text
, text
+ size
, buf
+ datalen
, end
);
1247 WINE_FIXME("Text size is too long, splitting\n");
1248 size
= blocksize
- datalen
;
1249 memcpy(text
, buf
+ datalen
, size
);
1253 memcpy(text
, buf
+ datalen
, size
);
1255 text_end
= text
+ size
;
1257 format
= buf
+ 0x15;
1258 format_end
= buf
+ GET_UINT(buf
, 0x10);
1260 if (buf
[0x14] == 0x20 || buf
[0x14] == 0x23)
1262 fetch_long(&format
);
1263 *parlen
= fetch_ushort(&format
);
1266 if (buf
[0x14] == 0x23)
1273 if (!HLPFILE_RtfAddControl(rd
, "\\trowd")) goto done
;
1275 if (type
== 0 || type
== 2)
1277 table_width
= GET_SHORT(format
, 0);
1281 table_width
= 32767;
1282 WINE_TRACE("New table: cols=%d type=%x width=%d\n",
1283 ncol
, type
, table_width
);
1287 sprintf(tmp
, "\\trgaph%d\\trleft%d",
1288 HLPFILE_HalfPointsToTwips(MulDiv(GET_SHORT(format
, 6), table_width
, 32767)),
1289 HLPFILE_HalfPointsToTwips(MulDiv(GET_SHORT(format
, 0), table_width
, 32767)));
1290 if (!HLPFILE_RtfAddControl(rd
, tmp
)) goto done
;
1291 pos
= HLPFILE_HalfPointsToTwips(MulDiv(GET_SHORT(format
, 6) / 2, table_width
, 32767));
1292 for (nc
= 0; nc
< ncol
; nc
++)
1294 WINE_TRACE("column(%d/%d) gap=%d width=%d\n",
1295 nc
, ncol
, GET_SHORT(format
, nc
*4),
1296 GET_SHORT(format
, nc
*4+2));
1297 pos
+= GET_SHORT(format
, nc
* 4) + GET_SHORT(format
, nc
* 4 + 2);
1298 sprintf(tmp
, "\\cellx%d",
1299 HLPFILE_HalfPointsToTwips(MulDiv(pos
, table_width
, 32767)));
1300 if (!HLPFILE_RtfAddControl(rd
, tmp
)) goto done
;
1305 WINE_TRACE("column(0/%d) gap=%d width=%d\n",
1306 ncol
, GET_SHORT(format
, 0), GET_SHORT(format
, 2));
1307 sprintf(tmp
, "\\trleft%d\\cellx%d ",
1308 HLPFILE_HalfPointsToTwips(MulDiv(GET_SHORT(format
, 0), table_width
, 32767)),
1309 HLPFILE_HalfPointsToTwips(MulDiv(GET_SHORT(format
, 0) + GET_SHORT(format
, 2),
1310 table_width
, 32767)));
1311 if (!HLPFILE_RtfAddControl(rd
, tmp
)) goto done
;
1316 for (nc
= 0; nc
< ncol
; /**/)
1318 WINE_TRACE("looking for format at offset %lu in column %d\n", (SIZE_T
)(format
- (buf
+ 0x15)), nc
);
1319 if (!HLPFILE_RtfAddControl(rd
, "\\pard")) goto done
;
1322 nc
= GET_SHORT(format
, 0);
1323 if (nc
== -1) break;
1325 if (!HLPFILE_RtfAddControl(rd
, "\\intbl")) goto done
;
1328 if (buf
[0x14] == 0x01)
1332 bits
= GET_USHORT(format
, 0); format
+= 2;
1333 if (bits
& 0x0001) fetch_long(&format
);
1336 sprintf(tmp
, "\\sb%d", HLPFILE_HalfPointsToTwips(fetch_short(&format
)));
1337 if (!HLPFILE_RtfAddControl(rd
, tmp
)) goto done
;
1341 sprintf(tmp
, "\\sa%d", HLPFILE_HalfPointsToTwips(fetch_short(&format
)));
1342 if (!HLPFILE_RtfAddControl(rd
, tmp
)) goto done
;
1346 sprintf(tmp
, "\\sl%d", HLPFILE_HalfPointsToTwips(fetch_short(&format
)));
1347 if (!HLPFILE_RtfAddControl(rd
, tmp
)) goto done
;
1351 sprintf(tmp
, "\\li%d", HLPFILE_HalfPointsToTwips(fetch_short(&format
)));
1352 if (!HLPFILE_RtfAddControl(rd
, tmp
)) goto done
;
1356 sprintf(tmp
, "\\ri%d", HLPFILE_HalfPointsToTwips(fetch_short(&format
)));
1357 if (!HLPFILE_RtfAddControl(rd
, tmp
)) goto done
;
1361 sprintf(tmp
, "\\fi%d", HLPFILE_HalfPointsToTwips(fetch_short(&format
)));
1362 if (!HLPFILE_RtfAddControl(rd
, tmp
)) goto done
;
1366 BYTE brdr
= *format
++;
1369 if ((brdr
& 0x01) && !HLPFILE_RtfAddControl(rd
, "\\box")) goto done
;
1370 if ((brdr
& 0x02) && !HLPFILE_RtfAddControl(rd
, "\\brdrt")) goto done
;
1371 if ((brdr
& 0x04) && !HLPFILE_RtfAddControl(rd
, "\\brdrl")) goto done
;
1372 if ((brdr
& 0x08) && !HLPFILE_RtfAddControl(rd
, "\\brdrb")) goto done
;
1373 if ((brdr
& 0x10) && !HLPFILE_RtfAddControl(rd
, "\\brdrr")) goto done
;
1374 if ((brdr
& 0x20) && !HLPFILE_RtfAddControl(rd
, "\\brdrth")) goto done
;
1375 if (!(brdr
& 0x20) && !HLPFILE_RtfAddControl(rd
, "\\brdrs")) goto done
;
1376 if ((brdr
& 0x40) && !HLPFILE_RtfAddControl(rd
, "\\brdrdb")) goto done
;
1379 w
= GET_SHORT(format
, 0); format
+= 2;
1382 sprintf(tmp
, "\\brdrw%d", HLPFILE_HalfPointsToTwips(w
));
1383 if (!HLPFILE_RtfAddControl(rd
, tmp
)) goto done
;
1388 int i
, ntab
= fetch_short(&format
);
1392 for (i
= 0; i
< ntab
; i
++)
1394 tab
= fetch_ushort(&format
);
1395 ts
= (tab
& 0x4000) ? fetch_ushort(&format
) : 0 /* left */;
1398 default: WINE_FIXME("Unknown tab style %x\n", ts
);
1400 case 0: kind
= ""; break;
1401 case 1: kind
= "\\tqr"; break;
1402 case 2: kind
= "\\tqc"; break;
1404 /* FIXME: do kind */
1405 sprintf(tmp
, "%s\\tx%d",
1406 kind
, HLPFILE_HalfPointsToTwips(tab
& 0x3FFF));
1407 if (!HLPFILE_RtfAddControl(rd
, tmp
)) goto done
;
1410 switch (bits
& 0xc00)
1412 default: WINE_FIXME("Unsupported alignment 0xC00\n"); break;
1413 case 0: if (!HLPFILE_RtfAddControl(rd
, "\\ql")) goto done
; break;
1414 case 0x400: if (!HLPFILE_RtfAddControl(rd
, "\\qr")) goto done
; break;
1415 case 0x800: if (!HLPFILE_RtfAddControl(rd
, "\\qc")) goto done
; break;
1418 /* 0x1000 doesn't need space */
1419 if ((bits
& 0x1000) && !HLPFILE_RtfAddControl(rd
, "\\keep")) goto done
;
1420 if ((bits
& 0xE080) != 0)
1421 WINE_FIXME("Unsupported bits %04x, potential trouble ahead\n", bits
);
1423 while (text
< text_end
&& format
< format_end
)
1425 WINE_TRACE("Got text: %s (%p/%p - %p/%p)\n", wine_dbgstr_a(text
), text
, text_end
, format
, format_end
);
1426 textsize
= strlen(text
);
1429 if (rd
->force_color
)
1431 if ((rd
->current_link
->cookie
== hlp_link_popup
) ?
1432 !HLPFILE_RtfAddControl(rd
, "{\\uld\\cf1") :
1433 !HLPFILE_RtfAddControl(rd
, "{\\ul\\cf1")) goto done
;
1435 if (!HLPFILE_RtfAddText(rd
, text
)) goto done
;
1436 if (rd
->force_color
&& !HLPFILE_RtfAddControl(rd
, "}")) goto done
;
1437 rd
->char_pos
+= textsize
;
1439 /* else: null text, keep on storing attributes */
1440 text
+= textsize
+ 1;
1442 if (*format
== 0xff)
1448 WINE_TRACE("format=%02x\n", *format
);
1452 WINE_FIXME("NIY20\n");
1457 WINE_FIXME("NIY21\n");
1463 unsigned font
= GET_USHORT(format
, 1);
1466 WINE_TRACE("Changing font to %d\n", font
);
1468 /* Font size in hlpfile is given in the same units as
1469 rtf control word \fs uses (half-points). */
1470 switch (rd
->font_scale
)
1472 case 0: fs
= page
->file
->fonts
[font
].LogFont
.lfHeight
- 4; break;
1474 case 1: fs
= page
->file
->fonts
[font
].LogFont
.lfHeight
; break;
1475 case 2: fs
= page
->file
->fonts
[font
].LogFont
.lfHeight
+ 4; break;
1477 /* FIXME: missing at least colors, also bold attribute looses information */
1479 sprintf(tmp
, "\\f%d\\cf%d\\fs%d%s%s%s%s",
1481 page
->file
->fonts
[font
].LogFont
.lfWeight
> 400 ? "\\b" : "\\b0",
1482 page
->file
->fonts
[font
].LogFont
.lfItalic
? "\\i" : "\\i0",
1483 page
->file
->fonts
[font
].LogFont
.lfUnderline
? "\\ul" : "\\ul0",
1484 page
->file
->fonts
[font
].LogFont
.lfStrikeOut
? "\\strike" : "\\strike0");
1485 if (!HLPFILE_RtfAddControl(rd
, tmp
)) goto done
;
1490 if (!HLPFILE_RtfAddControl(rd
, "\\line")) goto done
;
1498 if (format
[1] != 0xFF)
1500 if (!HLPFILE_RtfAddControl(rd
, "\\par\\intbl")) goto done
;
1504 if (!HLPFILE_RtfAddControl(rd
, "\\cell\\pard\\intbl")) goto done
;
1507 else if (!HLPFILE_RtfAddControl(rd
, "\\par")) goto done
;
1513 if (!HLPFILE_RtfAddControl(rd
, "\\tab")) goto done
;
1528 BYTE type
= format
[1];
1530 /* FIXME: we don't use 'BYTE pos = (*format - 0x86);' for the image position */
1532 size
= fetch_long(&format
);
1537 fetch_ushort(&format
); /* hot spot */
1540 switch (GET_SHORT(format
, 0))
1543 HLPFILE_RtfAddGfxByIndex(rd
, page
->file
, GET_SHORT(format
, 2));
1547 WINE_FIXME("does it work ??? %x<%u>#%u\n",
1548 GET_SHORT(format
, 0),
1549 size
, GET_SHORT(format
, 2));
1550 HLPFILE_RtfAddGfxByAddr(rd
, page
->file
, format
+ 2, size
- 4);
1554 WINE_FIXME("??? %u\n", GET_SHORT(format
, 0));
1559 WINE_FIXME("Got an embedded element %s\n", format
+ 6);
1562 WINE_FIXME("Got a type %d picture\n", type
);
1571 if (!rd
->current_link
)
1572 WINE_FIXME("No existing link\n");
1573 rd
->current_link
->cpMax
= rd
->char_pos
;
1574 rd
->current_link
= NULL
;
1575 rd
->force_color
= FALSE
;
1579 if (!HLPFILE_RtfAddControl(rd
, "\\~")) goto done
;
1585 if (!HLPFILE_RtfAddControl(rd
, "\\_")) goto done
;
1586 /* FIXME: it could be that hyphen is also in input stream !! */
1599 WINE_TRACE("macro => %s\n", format
+ 3);
1600 HLPFILE_AllocLink(rd
, hlp_link_macro
, (const char*)format
+ 3,
1601 GET_USHORT(format
, 1), 0, !(*format
& 4), 0, -1);
1602 format
+= 3 + GET_USHORT(format
, 1);
1607 WINE_WARN("jump topic 1 => %u\n", GET_UINT(format
, 1));
1608 HLPFILE_AllocLink(rd
, (*format
& 1) ? hlp_link_link
: hlp_link_popup
,
1609 page
->file
->lpszPath
, -1, GET_UINT(format
, 1), 1, 0, -1);
1619 HLPFILE_AllocLink(rd
, (*format
& 1) ? hlp_link_link
: hlp_link_popup
,
1620 page
->file
->lpszPath
, -1, GET_UINT(format
, 1),
1621 !(*format
& 4), 0, -1);
1630 const char* ptr
= (const char*) format
+ 8;
1631 BYTE type
= format
[3];
1640 ptr
= page
->file
->lpszPath
;
1643 for (wnd
= page
->file
->numWindows
- 1; wnd
>= 0; wnd
--)
1645 if (!strcmp(ptr
, page
->file
->windows
[wnd
].name
)) break;
1648 WINE_WARN("Couldn't find window info for %s\n", ptr
);
1649 ptr
+= strlen(ptr
) + 1;
1654 WINE_WARN("Unknown link type %d\n", type
);
1657 HLPFILE_AllocLink(rd
, (*format
& 1) ? hlp_link_link
: hlp_link_popup
,
1658 ptr
, -1, GET_UINT(format
, 4), !(*format
& 4), 0, wnd
);
1660 format
+= 3 + GET_USHORT(format
, 1);
1664 WINE_WARN("format %02x\n", *format
);
1671 if (!HLPFILE_RtfAddControl(rd
, "\\row\\par\\pard\\plain")) goto done
;
1677 HeapFree(GetProcessHeap(), 0, text_base
);
1681 /******************************************************************
1682 * HLPFILE_BrowsePage
1685 BOOL
HLPFILE_BrowsePage(HLPFILE_PAGE
* page
, struct RtfData
* rd
,
1686 unsigned font_scale
, unsigned relative
)
1688 HLPFILE
*hlpfile
= page
->file
;
1690 DWORD ref
= page
->reference
;
1691 unsigned index
, old_index
= -1, offset
, count
= 0, offs
= 0;
1692 unsigned cpg
, parlen
;
1694 const char* ck
= NULL
;
1697 rd
->data
= rd
->ptr
= HeapAlloc(GetProcessHeap(), 0, rd
->allocated
= 32768);
1699 rd
->first_link
= rd
->current_link
= NULL
;
1700 rd
->force_color
= FALSE
;
1701 rd
->font_scale
= font_scale
;
1702 rd
->relative
= relative
;
1703 rd
->char_pos_rel
= 0;
1705 switch (hlpfile
->charset
)
1707 case DEFAULT_CHARSET
:
1708 case ANSI_CHARSET
: cpg
= 1252; break;
1709 case SHIFTJIS_CHARSET
: cpg
= 932; break;
1710 case HANGEUL_CHARSET
: cpg
= 949; break;
1711 case GB2312_CHARSET
: cpg
= 936; break;
1712 case CHINESEBIG5_CHARSET
: cpg
= 950; break;
1713 case GREEK_CHARSET
: cpg
= 1253; break;
1714 case TURKISH_CHARSET
: cpg
= 1254; break;
1715 case HEBREW_CHARSET
: cpg
= 1255; break;
1716 case ARABIC_CHARSET
: cpg
= 1256; break;
1717 case BALTIC_CHARSET
: cpg
= 1257; break;
1718 case VIETNAMESE_CHARSET
: cpg
= 1258; break;
1719 case RUSSIAN_CHARSET
: cpg
= 1251; break;
1720 case EE_CHARSET
: cpg
= 1250; break;
1721 case THAI_CHARSET
: cpg
= 874; break;
1722 case JOHAB_CHARSET
: cpg
= 1361; break;
1723 case MAC_CHARSET
: ck
= "mac"; break;
1725 WINE_FIXME("Unsupported charset %u\n", hlpfile
->charset
);
1730 sprintf(tmp
, "{\\rtf1\\%s\\deff0", ck
);
1731 if (!HLPFILE_RtfAddControl(rd
, tmp
)) return FALSE
;
1735 sprintf(tmp
, "{\\rtf1\\ansi\\ansicpg%d\\deff0", cpg
);
1736 if (!HLPFILE_RtfAddControl(rd
, tmp
)) return FALSE
;
1739 /* generate font table */
1740 if (!HLPFILE_RtfAddControl(rd
, "{\\fonttbl")) return FALSE
;
1741 for (index
= 0; index
< hlpfile
->numFonts
; index
++)
1744 switch (hlpfile
->fonts
[index
].LogFont
.lfPitchAndFamily
& 0xF0)
1746 case FF_MODERN
: family
= "modern"; break;
1747 case FF_ROMAN
: family
= "roman"; break;
1748 case FF_SWISS
: family
= "swiss"; break;
1749 case FF_SCRIPT
: family
= "script"; break;
1750 case FF_DECORATIVE
: family
= "decor"; break;
1751 default: family
= "nil"; break;
1753 sprintf(tmp
, "{\\f%d\\f%s\\fprq%d\\fcharset%d %s;}",
1755 hlpfile
->fonts
[index
].LogFont
.lfPitchAndFamily
& 0x0F,
1756 hlpfile
->fonts
[index
].LogFont
.lfCharSet
,
1757 hlpfile
->fonts
[index
].LogFont
.lfFaceName
);
1758 if (!HLPFILE_RtfAddControl(rd
, tmp
)) return FALSE
;
1760 if (!HLPFILE_RtfAddControl(rd
, "}")) return FALSE
;
1761 /* generate color table */
1762 if (!HLPFILE_RtfAddControl(rd
, "{\\colortbl ;\\red0\\green128\\blue0;")) return FALSE
;
1763 for (index
= 0; index
< hlpfile
->numFonts
; index
++)
1765 sprintf(tmp
, "\\red%d\\green%d\\blue%d;",
1766 GetRValue(hlpfile
->fonts
[index
].color
),
1767 GetGValue(hlpfile
->fonts
[index
].color
),
1768 GetBValue(hlpfile
->fonts
[index
].color
));
1769 if (!HLPFILE_RtfAddControl(rd
, tmp
)) return FALSE
;
1771 if (!HLPFILE_RtfAddControl(rd
, "}")) return FALSE
;
1775 if (hlpfile
->version
<= 16)
1777 index
= (ref
- 0x0C) / hlpfile
->dsize
;
1778 offset
= (ref
- 0x0C) % hlpfile
->dsize
;
1782 index
= (ref
- 0x0C) >> 14;
1783 offset
= (ref
- 0x0C) & 0x3FFF;
1786 if (hlpfile
->version
<= 16 && index
!= old_index
&& old_index
!= -1)
1788 /* we jumped to the next block, adjust pointers */
1793 if (index
>= hlpfile
->topic_maplen
) {WINE_WARN("maplen\n"); break;}
1794 buf
= hlpfile
->topic_map
[index
] + offset
;
1795 if (buf
+ 0x15 >= hlpfile
->topic_end
) {WINE_WARN("extra\n"); break;}
1796 end
= min(buf
+ GET_UINT(buf
, 0), hlpfile
->topic_end
);
1797 if (index
!= old_index
) {offs
= 0; old_index
= index
;}
1802 if (count
++) goto done
;
1807 if (!HLPFILE_BrowseParagraph(page
, rd
, buf
, end
, &parlen
)) return FALSE
;
1808 if (relative
> index
* 0x8000 + offs
)
1809 rd
->char_pos_rel
= rd
->char_pos
;
1813 WINE_ERR("buf[0x14] = %x\n", buf
[0x14]);
1815 if (hlpfile
->version
<= 16)
1817 ref
+= GET_UINT(buf
, 0xc);
1818 if (GET_UINT(buf
, 0xc) == 0)
1822 ref
= GET_UINT(buf
, 0xc);
1823 } while (ref
!= 0xffffffff);
1825 page
->first_link
= rd
->first_link
;
1826 return HLPFILE_RtfAddControl(rd
, "}");
1829 /******************************************************************
1834 static BOOL
HLPFILE_ReadFont(HLPFILE
* hlpfile
)
1837 unsigned i
, len
, idx
;
1838 unsigned face_num
, dscr_num
, face_offset
, dscr_offset
;
1841 if (!HLPFILE_FindSubFile(hlpfile
, "|FONT", &ref
, &end
))
1843 WINE_WARN("no subfile FONT\n");
1844 hlpfile
->numFonts
= 0;
1845 hlpfile
->fonts
= NULL
;
1851 face_num
= GET_USHORT(ref
, 0);
1852 dscr_num
= GET_USHORT(ref
, 2);
1853 face_offset
= GET_USHORT(ref
, 4);
1854 dscr_offset
= GET_USHORT(ref
, 6);
1856 WINE_TRACE("Got NumFacenames=%u@%u NumDesc=%u@%u\n",
1857 face_num
, face_offset
, dscr_num
, dscr_offset
);
1859 hlpfile
->numFonts
= dscr_num
;
1860 hlpfile
->fonts
= HeapAlloc(GetProcessHeap(), 0, sizeof(HLPFILE_FONT
) * dscr_num
);
1862 len
= (dscr_offset
- face_offset
) / face_num
;
1863 /* EPP for (i = face_offset; i < dscr_offset; i += len) */
1864 /* EPP WINE_FIXME("[%d]: %*s\n", i / len, len, ref + i); */
1865 for (i
= 0; i
< dscr_num
; i
++)
1867 flag
= ref
[dscr_offset
+ i
* 11 + 0];
1868 family
= ref
[dscr_offset
+ i
* 11 + 2];
1870 hlpfile
->fonts
[i
].LogFont
.lfHeight
= ref
[dscr_offset
+ i
* 11 + 1];
1871 hlpfile
->fonts
[i
].LogFont
.lfWidth
= 0;
1872 hlpfile
->fonts
[i
].LogFont
.lfEscapement
= 0;
1873 hlpfile
->fonts
[i
].LogFont
.lfOrientation
= 0;
1874 hlpfile
->fonts
[i
].LogFont
.lfWeight
= (flag
& 1) ? 700 : 400;
1875 hlpfile
->fonts
[i
].LogFont
.lfItalic
= (flag
& 2) != 0;
1876 hlpfile
->fonts
[i
].LogFont
.lfUnderline
= (flag
& 4) != 0;
1877 hlpfile
->fonts
[i
].LogFont
.lfStrikeOut
= (flag
& 8) != 0;
1878 hlpfile
->fonts
[i
].LogFont
.lfCharSet
= hlpfile
->charset
;
1879 hlpfile
->fonts
[i
].LogFont
.lfOutPrecision
= OUT_DEFAULT_PRECIS
;
1880 hlpfile
->fonts
[i
].LogFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
1881 hlpfile
->fonts
[i
].LogFont
.lfQuality
= DEFAULT_QUALITY
;
1882 hlpfile
->fonts
[i
].LogFont
.lfPitchAndFamily
= DEFAULT_PITCH
;
1886 case 0x01: hlpfile
->fonts
[i
].LogFont
.lfPitchAndFamily
|= FF_MODERN
; break;
1887 case 0x02: hlpfile
->fonts
[i
].LogFont
.lfPitchAndFamily
|= FF_ROMAN
; break;
1888 case 0x03: hlpfile
->fonts
[i
].LogFont
.lfPitchAndFamily
|= FF_SWISS
; break;
1889 case 0x04: hlpfile
->fonts
[i
].LogFont
.lfPitchAndFamily
|= FF_SCRIPT
; break;
1890 case 0x05: hlpfile
->fonts
[i
].LogFont
.lfPitchAndFamily
|= FF_DECORATIVE
; break;
1891 default: WINE_FIXME("Unknown family %u\n", family
);
1893 idx
= GET_USHORT(ref
, dscr_offset
+ i
* 11 + 3);
1897 memcpy(hlpfile
->fonts
[i
].LogFont
.lfFaceName
, ref
+ face_offset
+ idx
* len
, min(len
, LF_FACESIZE
- 1));
1898 hlpfile
->fonts
[i
].LogFont
.lfFaceName
[min(len
, LF_FACESIZE
- 1)] = '\0';
1902 WINE_FIXME("Too high face ref (%u/%u)\n", idx
, face_num
);
1903 strcpy(hlpfile
->fonts
[i
].LogFont
.lfFaceName
, "Helv");
1905 hlpfile
->fonts
[i
].hFont
= 0;
1906 hlpfile
->fonts
[i
].color
= RGB(ref
[dscr_offset
+ i
* 11 + 5],
1907 ref
[dscr_offset
+ i
* 11 + 6],
1908 ref
[dscr_offset
+ i
* 11 + 7]);
1909 #define X(b,s) ((flag & (1 << b)) ? "-"s: "")
1910 WINE_TRACE("Font[%d]: flags=%02x%s%s%s%s%s%s pSize=%u family=%u face=%s[%u] color=%08x\n",
1916 X(4, "dblUnderline"),
1918 ref
[dscr_offset
+ i
* 11 + 1],
1920 hlpfile
->fonts
[i
].LogFont
.lfFaceName
, idx
,
1921 GET_UINT(ref
, dscr_offset
+ i
* 11 + 5) & 0x00FFFFFF);
1926 /***********************************************************************
1928 * HLPFILE_ReadFileToBuffer
1930 static BOOL
HLPFILE_ReadFileToBuffer(HLPFILE
* hlpfile
, HFILE hFile
)
1932 BYTE header
[16], dummy
[1];
1934 if (_hread(hFile
, header
, 16) != 16) {WINE_WARN("header\n"); return FALSE
;};
1937 if (GET_UINT(header
, 0) != 0x00035F3F)
1938 {WINE_WARN("wrong header\n"); return FALSE
;};
1940 hlpfile
->file_buffer_size
= GET_UINT(header
, 12);
1941 hlpfile
->file_buffer
= HeapAlloc(GetProcessHeap(), 0, hlpfile
->file_buffer_size
+ 1);
1942 if (!hlpfile
->file_buffer
) return FALSE
;
1944 memcpy(hlpfile
->file_buffer
, header
, 16);
1945 if (_hread(hFile
, hlpfile
->file_buffer
+ 16, hlpfile
->file_buffer_size
- 16) !=hlpfile
->file_buffer_size
- 16)
1946 {WINE_WARN("filesize1\n"); return FALSE
;};
1948 if (_hread(hFile
, dummy
, 1) != 0) WINE_WARN("filesize2\n");
1950 hlpfile
->file_buffer
[hlpfile
->file_buffer_size
] = '\0'; /* FIXME: was '0', sounds backwards to me */
1955 /***********************************************************************
1957 * HLPFILE_SystemCommands
1959 static BOOL
HLPFILE_SystemCommands(HLPFILE
* hlpfile
)
1961 BYTE
*buf
, *ptr
, *end
;
1962 HLPFILE_MACRO
*macro
, **m
;
1964 unsigned short magic
, minor
, major
, flags
;
1966 hlpfile
->lpszTitle
= NULL
;
1968 if (!HLPFILE_FindSubFile(hlpfile
, "|SYSTEM", &buf
, &end
)) return FALSE
;
1970 magic
= GET_USHORT(buf
+ 9, 0);
1971 minor
= GET_USHORT(buf
+ 9, 2);
1972 major
= GET_USHORT(buf
+ 9, 4);
1973 /* gen date on 4 bytes */
1974 flags
= GET_USHORT(buf
+ 9, 10);
1975 WINE_TRACE("Got system header: magic=%04x version=%d.%d flags=%04x\n",
1976 magic
, major
, minor
, flags
);
1977 if (magic
!= 0x036C || major
!= 1)
1978 {WINE_WARN("Wrong system header\n"); return FALSE
;}
1981 hlpfile
->tbsize
= 0x800;
1982 hlpfile
->compressed
= 0;
1984 else if (flags
== 0)
1986 hlpfile
->tbsize
= 0x1000;
1987 hlpfile
->compressed
= 0;
1989 else if (flags
== 4)
1991 hlpfile
->tbsize
= 0x1000;
1992 hlpfile
->compressed
= 1;
1996 hlpfile
->tbsize
= 0x800;
1997 hlpfile
->compressed
= 1;
2000 if (hlpfile
->compressed
)
2001 hlpfile
->dsize
= 0x4000;
2003 hlpfile
->dsize
= hlpfile
->tbsize
- 0x0C;
2005 hlpfile
->version
= minor
;
2006 hlpfile
->flags
= flags
;
2007 hlpfile
->charset
= DEFAULT_CHARSET
;
2009 if (hlpfile
->version
<= 16)
2011 char *str
= (char*)buf
+ 0x15;
2013 hlpfile
->lpszTitle
= HeapAlloc(GetProcessHeap(), 0, strlen(str
) + 1);
2014 if (!hlpfile
->lpszTitle
) return FALSE
;
2015 strcpy(hlpfile
->lpszTitle
, str
);
2016 WINE_TRACE("Title: %s\n", hlpfile
->lpszTitle
);
2017 /* Nothing more to parse */
2020 for (ptr
= buf
+ 0x15; ptr
+ 4 <= end
; ptr
+= GET_USHORT(ptr
, 2) + 4)
2022 char *str
= (char*) ptr
+ 4;
2023 switch (GET_USHORT(ptr
, 0))
2026 if (hlpfile
->lpszTitle
) {WINE_WARN("title\n"); break;}
2027 hlpfile
->lpszTitle
= HeapAlloc(GetProcessHeap(), 0, strlen(str
) + 1);
2028 if (!hlpfile
->lpszTitle
) return FALSE
;
2029 strcpy(hlpfile
->lpszTitle
, str
);
2030 WINE_TRACE("Title: %s\n", hlpfile
->lpszTitle
);
2034 if (hlpfile
->lpszCopyright
) {WINE_WARN("copyright\n"); break;}
2035 hlpfile
->lpszCopyright
= HeapAlloc(GetProcessHeap(), 0, strlen(str
) + 1);
2036 if (!hlpfile
->lpszCopyright
) return FALSE
;
2037 strcpy(hlpfile
->lpszCopyright
, str
);
2038 WINE_TRACE("Copyright: %s\n", hlpfile
->lpszCopyright
);
2042 if (GET_USHORT(ptr
, 2) != 4) {WINE_WARN("system3\n");break;}
2043 hlpfile
->contents_start
= GET_UINT(ptr
, 4);
2044 WINE_TRACE("Setting contents start at %08lx\n", hlpfile
->contents_start
);
2048 macro
= HeapAlloc(GetProcessHeap(), 0, sizeof(HLPFILE_MACRO
) + strlen(str
) + 1);
2050 p
= (char*)macro
+ sizeof(HLPFILE_MACRO
);
2052 macro
->lpszMacro
= p
;
2054 for (m
= &hlpfile
->first_macro
; *m
; m
= &(*m
)->next
);
2059 if (GET_USHORT(ptr
, 4 + 4) != 1)
2060 WINE_FIXME("More than one icon, picking up first\n");
2061 /* 0x16 is sizeof(CURSORICONDIR), see user32/user_private.h */
2062 hlpfile
->hIcon
= CreateIconFromResourceEx(ptr
+ 4 + 0x16,
2063 GET_USHORT(ptr
, 2) - 0x16, TRUE
,
2068 if (GET_USHORT(ptr
, 2) != 90) {WINE_WARN("system6\n");break;}
2070 if (hlpfile
->windows
)
2071 hlpfile
->windows
= HeapReAlloc(GetProcessHeap(), 0, hlpfile
->windows
,
2072 sizeof(HLPFILE_WINDOWINFO
) * ++hlpfile
->numWindows
);
2074 hlpfile
->windows
= HeapAlloc(GetProcessHeap(), 0,
2075 sizeof(HLPFILE_WINDOWINFO
) * ++hlpfile
->numWindows
);
2077 if (hlpfile
->windows
)
2079 HLPFILE_WINDOWINFO
* wi
= &hlpfile
->windows
[hlpfile
->numWindows
- 1];
2081 flags
= GET_USHORT(ptr
, 4);
2082 if (flags
& 0x0001) strcpy(wi
->type
, &str
[2]);
2083 else wi
->type
[0] = '\0';
2084 if (flags
& 0x0002) strcpy(wi
->name
, &str
[12]);
2085 else wi
->name
[0] = '\0';
2086 if (flags
& 0x0004) strcpy(wi
->caption
, &str
[21]);
2087 else lstrcpynA(wi
->caption
, hlpfile
->lpszTitle
, sizeof(wi
->caption
));
2088 wi
->origin
.x
= (flags
& 0x0008) ? GET_USHORT(ptr
, 76) : CW_USEDEFAULT
;
2089 wi
->origin
.y
= (flags
& 0x0010) ? GET_USHORT(ptr
, 78) : CW_USEDEFAULT
;
2090 wi
->size
.cx
= (flags
& 0x0020) ? GET_USHORT(ptr
, 80) : CW_USEDEFAULT
;
2091 wi
->size
.cy
= (flags
& 0x0040) ? GET_USHORT(ptr
, 82) : CW_USEDEFAULT
;
2092 wi
->style
= (flags
& 0x0080) ? GET_USHORT(ptr
, 84) : SW_SHOW
;
2093 wi
->win_style
= WS_OVERLAPPEDWINDOW
;
2094 wi
->sr_color
= (flags
& 0x0100) ? GET_UINT(ptr
, 86) : 0xFFFFFF;
2095 wi
->nsr_color
= (flags
& 0x0200) ? GET_UINT(ptr
, 90) : 0xFFFFFF;
2096 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",
2097 flags
& 0x0001 ? 'T' : 't',
2098 flags
& 0x0002 ? 'N' : 'n',
2099 flags
& 0x0004 ? 'C' : 'c',
2100 flags
& 0x0008 ? 'X' : 'x',
2101 flags
& 0x0010 ? 'Y' : 'y',
2102 flags
& 0x0020 ? 'W' : 'w',
2103 flags
& 0x0040 ? 'H' : 'h',
2104 flags
& 0x0080 ? 'S' : 's',
2105 wi
->type
, wi
->name
, wi
->caption
, wi
->origin
.x
, wi
->origin
.y
,
2106 wi
->size
.cx
, wi
->size
.cy
);
2110 WINE_WARN("Citation: '%s'\n", ptr
+ 4);
2113 hlpfile
->charset
= ptr
[4];
2114 WINE_TRACE("Charset: %d\n", hlpfile
->charset
);
2117 WINE_WARN("Unsupported SystemRecord[%d]\n", GET_USHORT(ptr
, 0));
2120 if (!hlpfile
->lpszTitle
)
2121 hlpfile
->lpszTitle
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, 1);
2125 /***********************************************************************
2127 * HLPFILE_GetContext
2129 static BOOL
HLPFILE_GetContext(HLPFILE
*hlpfile
)
2134 if (!HLPFILE_FindSubFile(hlpfile
, "|CONTEXT", &cbuf
, &cend
))
2135 {WINE_WARN("context0\n"); return FALSE
;}
2138 hlpfile
->Context
= HeapAlloc(GetProcessHeap(), 0, clen
);
2139 if (!hlpfile
->Context
) return FALSE
;
2140 memcpy(hlpfile
->Context
, cbuf
, clen
);
2145 /***********************************************************************
2147 * HLPFILE_GetKeywords
2149 static BOOL
HLPFILE_GetKeywords(HLPFILE
*hlpfile
)
2154 if (!HLPFILE_FindSubFile(hlpfile
, "|KWBTREE", &cbuf
, &cend
)) return FALSE
;
2156 hlpfile
->kwbtree
= HeapAlloc(GetProcessHeap(), 0, clen
);
2157 if (!hlpfile
->kwbtree
) return FALSE
;
2158 memcpy(hlpfile
->kwbtree
, cbuf
, clen
);
2160 if (!HLPFILE_FindSubFile(hlpfile
, "|KWDATA", &cbuf
, &cend
))
2162 WINE_ERR("corrupted help file: kwbtree present but kwdata absent\n");
2163 HeapFree(GetProcessHeap(), 0, hlpfile
->kwbtree
);
2167 hlpfile
->kwdata
= HeapAlloc(GetProcessHeap(), 0, clen
);
2168 if (!hlpfile
->kwdata
)
2170 HeapFree(GetProcessHeap(), 0, hlpfile
->kwdata
);
2173 memcpy(hlpfile
->kwdata
, cbuf
, clen
);
2178 /***********************************************************************
2182 static BOOL
HLPFILE_GetMap(HLPFILE
*hlpfile
)
2185 unsigned entries
, i
;
2187 if (!HLPFILE_FindSubFile(hlpfile
, "|CTXOMAP", &cbuf
, &cend
))
2188 {WINE_WARN("no map section\n"); return FALSE
;}
2190 entries
= GET_USHORT(cbuf
, 9);
2191 hlpfile
->Map
= HeapAlloc(GetProcessHeap(), 0, entries
* sizeof(HLPFILE_MAP
));
2192 if (!hlpfile
->Map
) return FALSE
;
2193 hlpfile
->wMapLen
= entries
;
2194 for (i
= 0; i
< entries
; i
++)
2196 hlpfile
->Map
[i
].lMap
= GET_UINT(cbuf
+11,i
*8);
2197 hlpfile
->Map
[i
].offset
= GET_UINT(cbuf
+11,i
*8+4);
2202 /***********************************************************************
2206 static BOOL
HLPFILE_GetTOMap(HLPFILE
*hlpfile
)
2211 if (!HLPFILE_FindSubFile(hlpfile
, "|TOMAP", &cbuf
, &cend
))
2212 {WINE_WARN("no tomap section\n"); return FALSE
;}
2214 clen
= cend
- cbuf
- 9;
2215 hlpfile
->TOMap
= HeapAlloc(GetProcessHeap(), 0, clen
);
2216 if (!hlpfile
->TOMap
) return FALSE
;
2217 memcpy(hlpfile
->TOMap
, cbuf
+9, clen
);
2218 hlpfile
->wTOMapLen
= clen
/4;
2222 /***********************************************************************
2226 static void HLPFILE_DeleteMacro(HLPFILE_MACRO
* macro
)
2228 HLPFILE_MACRO
* next
;
2233 HeapFree(GetProcessHeap(), 0, macro
);
2238 /***********************************************************************
2242 static void HLPFILE_DeletePage(HLPFILE_PAGE
* page
)
2249 HLPFILE_DeleteMacro(page
->first_macro
);
2250 HeapFree(GetProcessHeap(), 0, page
);
2255 /***********************************************************************
2257 * HLPFILE_FreeHlpFile
2259 void HLPFILE_FreeHlpFile(HLPFILE
* hlpfile
)
2263 if (!hlpfile
|| --hlpfile
->wRefCount
> 0) return;
2265 if (hlpfile
->next
) hlpfile
->next
->prev
= hlpfile
->prev
;
2266 if (hlpfile
->prev
) hlpfile
->prev
->next
= hlpfile
->next
;
2267 else first_hlpfile
= hlpfile
->next
;
2269 if (hlpfile
->numFonts
)
2271 for (i
= 0; i
< hlpfile
->numFonts
; i
++)
2273 DeleteObject(hlpfile
->fonts
[i
].hFont
);
2275 HeapFree(GetProcessHeap(), 0, hlpfile
->fonts
);
2278 if (hlpfile
->numBmps
)
2280 for (i
= 0; i
< hlpfile
->numBmps
; i
++)
2282 DeleteObject(hlpfile
->bmps
[i
]);
2284 HeapFree(GetProcessHeap(), 0, hlpfile
->bmps
);
2287 HLPFILE_DeletePage(hlpfile
->first_page
);
2288 HLPFILE_DeleteMacro(hlpfile
->first_macro
);
2290 DestroyIcon(hlpfile
->hIcon
);
2291 if (hlpfile
->numWindows
) HeapFree(GetProcessHeap(), 0, hlpfile
->windows
);
2292 HeapFree(GetProcessHeap(), 0, hlpfile
->Context
);
2293 HeapFree(GetProcessHeap(), 0, hlpfile
->Map
);
2294 HeapFree(GetProcessHeap(), 0, hlpfile
->lpszTitle
);
2295 HeapFree(GetProcessHeap(), 0, hlpfile
->lpszCopyright
);
2296 HeapFree(GetProcessHeap(), 0, hlpfile
->file_buffer
);
2297 HeapFree(GetProcessHeap(), 0, hlpfile
->phrases_offsets
);
2298 HeapFree(GetProcessHeap(), 0, hlpfile
->phrases_buffer
);
2299 HeapFree(GetProcessHeap(), 0, hlpfile
->topic_map
);
2300 HeapFree(GetProcessHeap(), 0, hlpfile
->help_on_file
);
2301 HeapFree(GetProcessHeap(), 0, hlpfile
);
2304 /***********************************************************************
2306 * HLPFILE_UncompressLZ77_Phrases
2308 static BOOL
HLPFILE_UncompressLZ77_Phrases(HLPFILE
* hlpfile
)
2310 UINT i
, num
, dec_size
, head_size
;
2313 if (!HLPFILE_FindSubFile(hlpfile
, "|Phrases", &buf
, &end
)) return FALSE
;
2315 if (hlpfile
->version
<= 16)
2320 num
= hlpfile
->num_phrases
= GET_USHORT(buf
, 9);
2321 if (buf
+ 2 * num
+ 0x13 >= end
) {WINE_WARN("1a\n"); return FALSE
;};
2323 if (hlpfile
->version
<= 16)
2324 dec_size
= end
- buf
- 15 - 2 * num
;
2326 dec_size
= HLPFILE_UncompressedLZ77_Size(buf
+ 0x13 + 2 * num
, end
);
2328 hlpfile
->phrases_offsets
= HeapAlloc(GetProcessHeap(), 0, sizeof(unsigned) * (num
+ 1));
2329 hlpfile
->phrases_buffer
= HeapAlloc(GetProcessHeap(), 0, dec_size
);
2330 if (!hlpfile
->phrases_offsets
|| !hlpfile
->phrases_buffer
)
2332 HeapFree(GetProcessHeap(), 0, hlpfile
->phrases_offsets
);
2333 HeapFree(GetProcessHeap(), 0, hlpfile
->phrases_buffer
);
2337 for (i
= 0; i
<= num
; i
++)
2338 hlpfile
->phrases_offsets
[i
] = GET_USHORT(buf
, head_size
+ 2 * i
) - 2 * num
- 2;
2340 if (hlpfile
->version
<= 16)
2341 memcpy(hlpfile
->phrases_buffer
, buf
+ 15 + 2*num
, dec_size
);
2343 HLPFILE_UncompressLZ77(buf
+ 0x13 + 2 * num
, end
, (BYTE
*)hlpfile
->phrases_buffer
);
2345 hlpfile
->hasPhrases
= TRUE
;
2349 /***********************************************************************
2351 * HLPFILE_Uncompress_Phrases40
2353 static BOOL
HLPFILE_Uncompress_Phrases40(HLPFILE
* hlpfile
)
2356 INT dec_size
, cpr_size
;
2357 BYTE
*buf_idx
, *end_idx
;
2358 BYTE
*buf_phs
, *end_phs
;
2359 ULONG
* ptr
, mask
= 0;
2361 unsigned short bc
, n
;
2363 if (!HLPFILE_FindSubFile(hlpfile
, "|PhrIndex", &buf_idx
, &end_idx
) ||
2364 !HLPFILE_FindSubFile(hlpfile
, "|PhrImage", &buf_phs
, &end_phs
)) return FALSE
;
2366 ptr
= (ULONG
*)(buf_idx
+ 9 + 28);
2367 bc
= GET_USHORT(buf_idx
, 9 + 24) & 0x0F;
2368 num
= hlpfile
->num_phrases
= GET_USHORT(buf_idx
, 9 + 4);
2370 WINE_TRACE("Index: Magic=%08x #entries=%u CpsdSize=%u PhrImgSize=%u\n"
2371 "\tPhrImgCprsdSize=%u 0=%u bc=%x ukn=%x\n",
2372 GET_UINT(buf_idx
, 9 + 0),
2373 GET_UINT(buf_idx
, 9 + 4),
2374 GET_UINT(buf_idx
, 9 + 8),
2375 GET_UINT(buf_idx
, 9 + 12),
2376 GET_UINT(buf_idx
, 9 + 16),
2377 GET_UINT(buf_idx
, 9 + 20),
2378 GET_USHORT(buf_idx
, 9 + 24),
2379 GET_USHORT(buf_idx
, 9 + 26));
2381 dec_size
= GET_UINT(buf_idx
, 9 + 12);
2382 cpr_size
= GET_UINT(buf_idx
, 9 + 16);
2384 if (dec_size
!= cpr_size
&&
2385 dec_size
!= HLPFILE_UncompressedLZ77_Size(buf_phs
+ 9, end_phs
))
2387 WINE_WARN("size mismatch %u %u\n",
2388 dec_size
, HLPFILE_UncompressedLZ77_Size(buf_phs
+ 9, end_phs
));
2389 dec_size
= max(dec_size
, HLPFILE_UncompressedLZ77_Size(buf_phs
+ 9, end_phs
));
2392 hlpfile
->phrases_offsets
= HeapAlloc(GetProcessHeap(), 0, sizeof(unsigned) * (num
+ 1));
2393 hlpfile
->phrases_buffer
= HeapAlloc(GetProcessHeap(), 0, dec_size
);
2394 if (!hlpfile
->phrases_offsets
|| !hlpfile
->phrases_buffer
)
2396 HeapFree(GetProcessHeap(), 0, hlpfile
->phrases_offsets
);
2397 HeapFree(GetProcessHeap(), 0, hlpfile
->phrases_buffer
);
2401 #define getbit() ((mask <<= 1) ? (*ptr & mask) != 0: (*++ptr & (mask=1)) != 0)
2403 hlpfile
->phrases_offsets
[0] = 0;
2404 ptr
--; /* as we'll first increment ptr because mask is 0 on first getbit() call */
2405 for (i
= 0; i
< num
; i
++)
2407 for (n
= 1; getbit(); n
+= 1 << bc
);
2409 if (bc
> 1 && getbit()) n
+= 2;
2410 if (bc
> 2 && getbit()) n
+= 4;
2411 if (bc
> 3 && getbit()) n
+= 8;
2412 if (bc
> 4 && getbit()) n
+= 16;
2413 hlpfile
->phrases_offsets
[i
+ 1] = hlpfile
->phrases_offsets
[i
] + n
;
2417 if (dec_size
== cpr_size
)
2418 memcpy(hlpfile
->phrases_buffer
, buf_phs
+ 9, dec_size
);
2420 HLPFILE_UncompressLZ77(buf_phs
+ 9, end_phs
, (BYTE
*)hlpfile
->phrases_buffer
);
2422 hlpfile
->hasPhrases40
= TRUE
;
2426 /***********************************************************************
2428 * HLPFILE_Uncompress_Topic
2430 static BOOL
HLPFILE_Uncompress_Topic(HLPFILE
* hlpfile
)
2432 BYTE
*buf
, *ptr
, *end
, *newptr
;
2433 unsigned int i
, newsize
= 0;
2434 unsigned int topic_size
;
2436 if (!HLPFILE_FindSubFile(hlpfile
, "|TOPIC", &buf
, &end
))
2437 {WINE_WARN("topic0\n"); return FALSE
;}
2439 buf
+= 9; /* Skip file header */
2440 topic_size
= end
- buf
;
2441 if (hlpfile
->compressed
)
2443 hlpfile
->topic_maplen
= (topic_size
- 1) / hlpfile
->tbsize
+ 1;
2445 for (i
= 0; i
< hlpfile
->topic_maplen
; i
++)
2447 ptr
= buf
+ i
* hlpfile
->tbsize
;
2449 /* I don't know why, it's necessary for printman.hlp */
2450 if (ptr
+ 0x44 > end
) ptr
= end
- 0x44;
2452 newsize
+= HLPFILE_UncompressedLZ77_Size(ptr
+ 0xc, min(end
, ptr
+ hlpfile
->tbsize
));
2455 hlpfile
->topic_map
= HeapAlloc(GetProcessHeap(), 0,
2456 hlpfile
->topic_maplen
* sizeof(hlpfile
->topic_map
[0]) + newsize
);
2457 if (!hlpfile
->topic_map
) return FALSE
;
2458 newptr
= (BYTE
*)(hlpfile
->topic_map
+ hlpfile
->topic_maplen
);
2459 hlpfile
->topic_end
= newptr
+ newsize
;
2461 for (i
= 0; i
< hlpfile
->topic_maplen
; i
++)
2463 ptr
= buf
+ i
* hlpfile
->tbsize
;
2464 if (ptr
+ 0x44 > end
) ptr
= end
- 0x44;
2466 hlpfile
->topic_map
[i
] = newptr
;
2467 newptr
= HLPFILE_UncompressLZ77(ptr
+ 0xc, min(end
, ptr
+ hlpfile
->tbsize
), newptr
);
2472 /* basically, we need to copy the TopicBlockSize byte pages
2473 * (removing the first 0x0C) in one single area in memory
2475 hlpfile
->topic_maplen
= (topic_size
- 1) / hlpfile
->tbsize
+ 1;
2476 hlpfile
->topic_map
= HeapAlloc(GetProcessHeap(), 0,
2477 hlpfile
->topic_maplen
* (sizeof(hlpfile
->topic_map
[0]) + hlpfile
->dsize
));
2478 if (!hlpfile
->topic_map
) return FALSE
;
2479 newptr
= (BYTE
*)(hlpfile
->topic_map
+ hlpfile
->topic_maplen
);
2480 hlpfile
->topic_end
= newptr
+ topic_size
;
2482 for (i
= 0; i
< hlpfile
->topic_maplen
; i
++)
2484 hlpfile
->topic_map
[i
] = newptr
+ i
* hlpfile
->dsize
;
2485 memcpy(hlpfile
->topic_map
[i
], buf
+ i
* hlpfile
->tbsize
+ 0x0C, hlpfile
->dsize
);
2491 /***********************************************************************
2495 static BOOL
HLPFILE_AddPage(HLPFILE
*hlpfile
, const BYTE
*buf
, const BYTE
*end
, unsigned ref
, unsigned offset
)
2499 UINT titlesize
, blocksize
, datalen
;
2501 HLPFILE_MACRO
*macro
;
2503 blocksize
= GET_UINT(buf
, 0);
2504 datalen
= GET_UINT(buf
, 0x10);
2505 title
= buf
+ datalen
;
2506 if (title
> end
) {WINE_WARN("page2\n"); return FALSE
;};
2508 titlesize
= GET_UINT(buf
, 4);
2509 page
= HeapAlloc(GetProcessHeap(), 0, sizeof(HLPFILE_PAGE
) + titlesize
+ 1);
2510 if (!page
) return FALSE
;
2511 page
->lpszTitle
= (char*)page
+ sizeof(HLPFILE_PAGE
);
2513 if (titlesize
> blocksize
- datalen
)
2515 /* need to decompress */
2516 if (hlpfile
->hasPhrases
)
2517 HLPFILE_Uncompress2(hlpfile
, title
, end
, (BYTE
*)page
->lpszTitle
, (BYTE
*)page
->lpszTitle
+ titlesize
);
2518 else if (hlpfile
->hasPhrases40
)
2519 HLPFILE_Uncompress3(hlpfile
, page
->lpszTitle
, page
->lpszTitle
+ titlesize
, title
, end
);
2522 WINE_FIXME("Text size is too long, splitting\n");
2523 titlesize
= blocksize
- datalen
;
2524 memcpy(page
->lpszTitle
, title
, titlesize
);
2528 memcpy(page
->lpszTitle
, title
, titlesize
);
2530 page
->lpszTitle
[titlesize
] = '\0';
2532 if (hlpfile
->first_page
)
2534 hlpfile
->last_page
->next
= page
;
2535 page
->prev
= hlpfile
->last_page
;
2536 hlpfile
->last_page
= page
;
2540 hlpfile
->first_page
= page
;
2541 hlpfile
->last_page
= page
;
2545 page
->file
= hlpfile
;
2547 page
->first_macro
= NULL
;
2548 page
->first_link
= NULL
;
2549 page
->wNumber
= GET_UINT(buf
, 0x21);
2550 page
->offset
= offset
;
2551 page
->reference
= ref
;
2553 page
->browse_bwd
= GET_UINT(buf
, 0x19);
2554 page
->browse_fwd
= GET_UINT(buf
, 0x1D);
2556 if (hlpfile
->version
<= 16)
2558 if (page
->browse_bwd
== 0xFFFF || page
->browse_bwd
== 0xFFFFFFFF)
2559 page
->browse_bwd
= 0xFFFFFFFF;
2561 page
->browse_bwd
= hlpfile
->TOMap
[page
->browse_bwd
];
2563 if (page
->browse_fwd
== 0xFFFF || page
->browse_fwd
== 0xFFFFFFFF)
2564 page
->browse_fwd
= 0xFFFFFFFF;
2566 page
->browse_fwd
= hlpfile
->TOMap
[page
->browse_fwd
];
2569 WINE_TRACE("Added page[%d]: title='%s' %08x << %08x >> %08x\n",
2570 page
->wNumber
, page
->lpszTitle
,
2571 page
->browse_bwd
, page
->offset
, page
->browse_fwd
);
2573 /* now load macros */
2574 ptr
= page
->lpszTitle
+ strlen(page
->lpszTitle
) + 1;
2575 while (ptr
< page
->lpszTitle
+ titlesize
)
2577 unsigned len
= strlen(ptr
);
2580 WINE_TRACE("macro: %s\n", ptr
);
2581 macro
= HeapAlloc(GetProcessHeap(), 0, sizeof(HLPFILE_MACRO
) + len
+ 1);
2582 macro
->lpszMacro
= macro_str
= (char*)(macro
+ 1);
2583 memcpy(macro_str
, ptr
, len
+ 1);
2584 /* FIXME: shall we really link macro in reverse order ??
2585 * may produce strange results when played at page opening
2587 macro
->next
= page
->first_macro
;
2588 page
->first_macro
= macro
;
2595 /***********************************************************************
2597 * HLPFILE_SkipParagraph
2599 static BOOL
HLPFILE_SkipParagraph(HLPFILE
*hlpfile
, const BYTE
*buf
, const BYTE
*end
, unsigned* len
)
2603 if (!hlpfile
->first_page
) {WINE_WARN("no page\n"); return FALSE
;};
2604 if (buf
+ 0x19 > end
) {WINE_WARN("header too small\n"); return FALSE
;};
2607 if (buf
[0x14] == 0x20 || buf
[0x14] == 0x23)
2610 *len
= fetch_ushort(&tmp
);
2612 else *len
= end
-buf
-15;
2617 /***********************************************************************
2619 * HLPFILE_DoReadHlpFile
2621 static BOOL
HLPFILE_DoReadHlpFile(HLPFILE
*hlpfile
, LPCSTR lpszPath
)
2628 unsigned index
, old_index
, offset
, len
, offs
, topicoffset
;
2630 hFile
= OpenFile(lpszPath
, &ofs
, OF_READ
);
2631 if (hFile
== HFILE_ERROR
) return FALSE
;
2633 ret
= HLPFILE_ReadFileToBuffer(hlpfile
, hFile
);
2635 if (!ret
) return FALSE
;
2637 if (!HLPFILE_SystemCommands(hlpfile
)) return FALSE
;
2639 if (hlpfile
->version
<= 16 && !HLPFILE_GetTOMap(hlpfile
)) return FALSE
;
2641 /* load phrases support */
2642 if (!HLPFILE_UncompressLZ77_Phrases(hlpfile
))
2643 HLPFILE_Uncompress_Phrases40(hlpfile
);
2645 if (!HLPFILE_Uncompress_Topic(hlpfile
)) return FALSE
;
2646 if (!HLPFILE_ReadFont(hlpfile
)) return FALSE
;
2654 if (hlpfile
->version
<= 16)
2656 index
= (ref
- 0x0C) / hlpfile
->dsize
;
2657 offset
= (ref
- 0x0C) % hlpfile
->dsize
;
2661 index
= (ref
- 0x0C) >> 14;
2662 offset
= (ref
- 0x0C) & 0x3FFF;
2665 if (hlpfile
->version
<= 16 && index
!= old_index
&& old_index
!= -1)
2667 /* we jumped to the next block, adjust pointers */
2672 WINE_TRACE("ref=%08x => [%u/%u]\n", ref
, index
, offset
);
2674 if (index
>= hlpfile
->topic_maplen
) {WINE_WARN("maplen\n"); break;}
2675 buf
= hlpfile
->topic_map
[index
] + offset
;
2676 if (buf
+ 0x15 >= hlpfile
->topic_end
) {WINE_WARN("extra\n"); break;}
2677 end
= min(buf
+ GET_UINT(buf
, 0), hlpfile
->topic_end
);
2678 if (index
!= old_index
) {offs
= 0; old_index
= index
;}
2683 if (hlpfile
->version
<= 16)
2684 topicoffset
= ref
+ index
* 12;
2686 topicoffset
= index
* 0x8000 + offs
;
2687 if (!HLPFILE_AddPage(hlpfile
, buf
, end
, ref
, topicoffset
)) return FALSE
;
2693 if (!HLPFILE_SkipParagraph(hlpfile
, buf
, end
, &len
)) return FALSE
;
2698 WINE_ERR("buf[0x14] = %x\n", buf
[0x14]);
2701 if (hlpfile
->version
<= 16)
2703 ref
+= GET_UINT(buf
, 0xc);
2704 if (GET_UINT(buf
, 0xc) == 0)
2708 ref
= GET_UINT(buf
, 0xc);
2709 } while (ref
!= 0xffffffff);
2711 HLPFILE_GetKeywords(hlpfile
);
2712 HLPFILE_GetMap(hlpfile
);
2713 if (hlpfile
->version
<= 16) return TRUE
;
2714 return HLPFILE_GetContext(hlpfile
);
2717 /***********************************************************************
2719 * HLPFILE_ReadHlpFile
2721 HLPFILE
*HLPFILE_ReadHlpFile(LPCSTR lpszPath
)
2725 for (hlpfile
= first_hlpfile
; hlpfile
; hlpfile
= hlpfile
->next
)
2727 if (!strcmp(lpszPath
, hlpfile
->lpszPath
))
2729 hlpfile
->wRefCount
++;
2734 hlpfile
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2735 sizeof(HLPFILE
) + strlen(lpszPath
) + 1);
2736 if (!hlpfile
) return 0;
2738 hlpfile
->lpszPath
= (char*)hlpfile
+ sizeof(HLPFILE
);
2739 hlpfile
->contents_start
= 0xFFFFFFFF;
2740 hlpfile
->next
= first_hlpfile
;
2741 hlpfile
->wRefCount
= 1;
2743 strcpy(hlpfile
->lpszPath
, lpszPath
);
2745 first_hlpfile
= hlpfile
;
2746 if (hlpfile
->next
) hlpfile
->next
->prev
= hlpfile
;
2748 if (!HLPFILE_DoReadHlpFile(hlpfile
, lpszPath
))
2750 HLPFILE_FreeHlpFile(hlpfile
);