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 typedef struct chmUnitInfo chmUnitInfo;
86 typedef struct chm_dir {
87   int nentries;
88   char **info;
89 } chm_dir;
90 
91 /* open an ITS archive */
92 #ifdef PPC_BSTR
93 /* RWE 6/12/2003 */
94 struct chmFile* chm_open(BSTR filename);
95 #else
96 struct chmFile* chm_open(const char *filename);
97 #endif
98 
99 /* close an ITS archive */
100 void chm_close(struct chmFile *h);
101 
102 /* methods for ssetting tuning parameters for particular file */
103 #define CHM_PARAM_MAX_BLOCKS_CACHED 0
104 void chm_set_param(struct chmFile *h,
105                    int paramType,
106                    int paramVal);
107 
108 /* resolve a particular object from the archive */
109 #define CHM_RESOLVE_SUCCESS (0)
110 #define CHM_RESOLVE_FAILURE (1)
111 int chm_resolve_object(struct chmFile *h,
112                        const char *objPath,
113                        struct chmUnitInfo *ui);
114 
115 /* retrieve part of an object from the archive */
116 LONGINT64 chm_retrieve_object(struct chmFile *h,
117                               struct chmUnitInfo *ui,
118                               unsigned char *buf,
119                               LONGUINT64 addr,
120                               LONGINT64 len);
121 
122 /* enumerate the objects in the .chm archive */
123 typedef int (*CHM_ENUMERATOR)(struct chmFile *h,
124                               struct chmUnitInfo *ui,
125                               void *context);
126 #define CHM_ENUMERATE_NORMAL    (1)
127 #define CHM_ENUMERATE_META      (2)
128 #define CHM_ENUMERATE_SPECIAL   (4)
129 #define CHM_ENUMERATE_FILES     (8)
130 #define CHM_ENUMERATE_DIRS      (16)
131 #define CHM_ENUMERATE_ALL       (31)
132 #define CHM_ENUMERATOR_FAILURE  (0)
133 #define CHM_ENUMERATOR_CONTINUE (1)
134 #define CHM_ENUMERATOR_SUCCESS  (2)
135 int chm_enumerate(struct chmFile *h,
136                   int what,
137                   CHM_ENUMERATOR e,
138                   void *context);
139 
140 int chm_enumerate_dir(struct chmFile *h,
141                       const char *prefix,
142                       int what,
143                       CHM_ENUMERATOR e,
144                       void *context);
145 
146 chm_dir get_names(struct chmFile *h);
147 #ifdef __cplusplus
148 }
149 #endif
150 
151 #endif /* INCLUDED_CHMLIB_H */
152