1 | /* $Id: chm_lib.h,v 1.10 2002/10/09 01:16:33 jedwin Exp $ */ |
2 | /*************************************************************************** |
3 | * chm_lib.h - CHM archive manipulation routines * |
4 | * ------------------- * |
5 | * * |
6 | * author: Jed Wing <jedwin@ugcs.caltech.edu> * |
7 | * version: 0.3 * |
8 | * notes: These routines are meant for the manipulation of microsoft * |
9 | * .chm (compiled html help) files, but may likely be used * |
10 | * for the manipulation of any ITSS archive, if ever ITSS * |
11 | * archives are used for any other purpose. * |
12 | * * |
13 | * Note also that the section names are statically handled. * |
14 | * To be entirely correct, the section names should be read * |
15 | * from the section names meta-file, and then the various * |
16 | * content sections and the "transforms" to apply to the data * |
17 | * they contain should be inferred from the section name and * |
18 | * the meta-files referenced using that name; however, all of * |
19 | * the files I've been able to get my hands on appear to have * |
20 | * only two sections: Uncompressed and MSCompressed. * |
21 | * Additionally, the ITSS.DLL file included with Windows does * |
22 | * not appear to handle any different transforms than the * |
23 | * simple LZX-transform. Furthermore, the list of transforms * |
24 | * to apply is broken, in that only half the required space * |
25 | * is allocated for the list. (It appears as though the * |
26 | * space is allocated for ASCII strings, but the strings are * |
27 | * written as unicode. As a result, only the first half of * |
28 | * the string appears.) So this is probably not too big of * |
29 | * a deal, at least until CHM v4 (MS .lit files), which also * |
30 | * incorporate encryption, of some description. * |
31 | ***************************************************************************/ |
32 | |
33 | /*************************************************************************** |
34 | * * |
35 | * This program is free software; you can redistribute it and/or modify * |
36 | * it under the terms of the GNU Lesser General Public License as * |
37 | * published by the Free Software Foundation; either version 2.1 of the * |
38 | * License, or (at your option) any later version. * |
39 | * * |
40 | ***************************************************************************/ |
41 | |
42 | #ifndef INCLUDED_CHMLIB_H |
43 | #define INCLUDED_CHMLIB_H |
44 | |
45 | #ifdef __cplusplus |
46 | extern "C" { |
47 | #endif |
48 | |
49 | /* RWE 6/12/1002 */ |
50 | #ifdef PPC_BSTR |
51 | #include <wtypes.h> |
52 | #endif |
53 | |
54 | #ifdef WIN32 |
55 | #ifdef __MINGW32__ |
56 | #define __int64 long long |
57 | #endif |
58 | typedef unsigned __int64 LONGUINT64; |
59 | typedef __int64 LONGINT64; |
60 | #else |
61 | typedef unsigned long long LONGUINT64; |
62 | typedef long long LONGINT64; |
63 | #endif |
64 | |
65 | /* the two available spaces in a CHM file */ |
66 | /* N.B.: The format supports arbitrarily many spaces, but only */ |
67 | /* two appear to be used at present. */ |
68 | #define CHM_UNCOMPRESSED (0) |
69 | #define CHM_COMPRESSED (1) |
70 | |
71 | /* structure representing an ITS (CHM) file stream */ |
72 | struct chmFile; |
73 | |
74 | /* structure representing an element from an ITS file stream */ |
75 | #define CHM_MAX_PATHLEN (512) |
76 | struct chmUnitInfo |
77 | { |
78 | LONGUINT64 start; |
79 | LONGUINT64 length; |
80 | int space; |
81 | int flags; |
82 | char path[CHM_MAX_PATHLEN+1]; |
83 | }; |
84 | |
85 | /* open an ITS archive */ |
86 | #ifdef PPC_BSTR |
87 | /* RWE 6/12/2003 */ |
88 | struct chmFile* chm_open(BSTR filename); |
89 | #else |
90 | struct chmFile* chm_open(const char *filename); |
91 | #endif |
92 | |
93 | /* close an ITS archive */ |
94 | void chm_close(struct chmFile *h); |
95 | |
96 | /* methods for ssetting tuning parameters for particular file */ |
97 | #define CHM_PARAM_MAX_BLOCKS_CACHED 0 |
98 | void chm_set_param(struct chmFile *h, |
99 | int paramType, |
100 | int paramVal); |
101 | |
102 | /* resolve a particular object from the archive */ |
103 | #define CHM_RESOLVE_SUCCESS (0) |
104 | #define CHM_RESOLVE_FAILURE (1) |
105 | int chm_resolve_object(struct chmFile *h, |
106 | const char *objPath, |
107 | struct chmUnitInfo *ui); |
108 | |
109 | /* retrieve part of an object from the archive */ |
110 | LONGINT64 chm_retrieve_object(struct chmFile *h, |
111 | struct chmUnitInfo *ui, |
112 | unsigned char *buf, |
113 | LONGUINT64 addr, |
114 | LONGINT64 len); |
115 | |
116 | /* enumerate the objects in the .chm archive */ |
117 | typedef int (*CHM_ENUMERATOR)(struct chmFile *h, |
118 | struct chmUnitInfo *ui, |
119 | void *context); |
120 | #define CHM_ENUMERATE_NORMAL (1) |
121 | #define CHM_ENUMERATE_META (2) |
122 | #define CHM_ENUMERATE_SPECIAL (4) |
123 | #define CHM_ENUMERATE_FILES (8) |
124 | #define CHM_ENUMERATE_DIRS (16) |
125 | #define CHM_ENUMERATE_ALL (31) |
126 | #define CHM_ENUMERATOR_FAILURE (0) |
127 | #define CHM_ENUMERATOR_CONTINUE (1) |
128 | #define CHM_ENUMERATOR_SUCCESS (2) |
129 | int chm_enumerate(struct chmFile *h, |
130 | int what, |
131 | CHM_ENUMERATOR e, |
132 | void *context); |
133 | |
134 | int chm_enumerate_dir(struct chmFile *h, |
135 | const char *prefix, |
136 | int what, |
137 | CHM_ENUMERATOR e, |
138 | void *context); |
139 | |
140 | #ifdef __cplusplus |
141 | } |
142 | #endif |
143 | |
144 | #endif /* INCLUDED_CHMLIB_H */ |
145 | |