loader.tex
[cacao.git] / unzip.h
1 /* MODIFIED BY Joseph Wenninger */
2 /* unzip.h -- IO for uncompress .zip files using zlib 
3    Version 0.15 beta, Mar 19th, 1998,
4
5    Copyright (C) 1998 Gilles Vollant
6
7    This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
8      WinZip, InfoZip tools and compatible.
9    Encryption and multi volume ZipFile (span) are not supported.
10    Old compressions used by old PKZip 1.x are not supported
11
12    THIS IS AN ALPHA VERSION. AT THIS STAGE OF DEVELOPPEMENT, SOMES API OR STRUCTURE
13    CAN CHANGE IN FUTURE VERSION !!
14    I WAIT FEEDBACK at mail info@winimage.com
15    Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
16
17    Condition of use and distribution are the same than zlib :
18
19   This software is provided 'as-is', without any express or implied
20   warranty.  In no event will the authors be held liable for any damages
21   arising from the use of this software.
22
23   Permission is granted to anyone to use this software for any purpose,
24   including commercial applications, and to alter it and redistribute it
25   freely, subject to the following restrictions:
26
27   1. The origin of this software must not be misrepresented; you must not
28      claim that you wrote the original software. If you use this software
29      in a product, an acknowledgment in the product documentation would be
30      appreciated but is not required.
31   2. Altered source versions must be plainly marked as such, and must not be
32      misrepresented as being the original software.
33   3. This notice may not be removed or altered from any source distribution.
34
35
36 */
37 /* for more info about .ZIP format, see 
38       ftp://ftp.cdrom.com/pub/infozip/doc/appnote-970311-iz.zip
39    PkWare has also a specification at :
40       ftp://ftp.pkware.com/probdesc.zip */
41
42 #ifndef _unz_H
43 #define _unz_H
44
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48
49 #ifndef _ZLIB_H
50 #include "zlib.h"
51 #endif
52
53 #include "global.h"
54
55 #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
56 /* like the STRICT of WIN32, we define a pointer that cannot be converted
57     from (void*) without cast */
58 typedef struct TagunzFile__ { int unused; } unzFile__; 
59 typedef unzFile__ *unzFile;
60 #else
61 typedef voidp unzFile;
62 #endif
63
64
65 #define UNZ_OK                                  (0)
66 #define UNZ_END_OF_LIST_OF_FILE (-100)
67 #define UNZ_ERRNO               (Z_ERRNO)
68 #define UNZ_EOF                 (0)
69 #define UNZ_PARAMERROR                  (-102)
70 #define UNZ_BADZIPFILE                  (-103)
71 #define UNZ_INTERNALERROR               (-104)
72 #define UNZ_CRCERROR                    (-105)
73
74 /* tm_unz contain date/time info */
75 typedef struct tm_unz_s 
76 {
77         uInt tm_sec;            /* seconds after the minute - [0,59] */
78         uInt tm_min;            /* minutes after the hour - [0,59] */
79         uInt tm_hour;           /* hours since midnight - [0,23] */
80         uInt tm_mday;           /* day of the month - [1,31] */
81         uInt tm_mon;            /* months since January - [0,11] */
82         uInt tm_year;           /* years - [1980..2044] */
83 } tm_unz;
84
85 #ifndef z_off_t
86 #define z_off_t uLong
87 #endif
88
89 int cacao_locate(unzFile file,utf* filename); /*JOWENN*/
90
91 /* unz_global_info structure contain global data about the ZIPfile
92    These data comes from the end of central dir */
93 typedef struct unz_global_info_s
94 {
95         uLong number_entry;         /* total number of entries in
96                                        the central dir on this disk */
97         uLong size_comment;         /* size of the global comment of the zipfile */
98 } unz_global_info;
99
100
101 /* unz_file_info contain information about a file in the zipfile */
102 typedef struct unz_file_info_s
103 {
104     uLong version;              /* version made by                 2 bytes */
105     uLong version_needed;       /* version needed to extract       2 bytes */
106     uLong flag;                 /* general purpose bit flag        2 bytes */
107     uLong compression_method;   /* compression method              2 bytes */
108     uLong dosDate;              /* last mod file date in Dos fmt   4 bytes */
109     uLong crc;                  /* crc-32                          4 bytes */
110     uLong compressed_size;      /* compressed size                 4 bytes */ 
111     uLong uncompressed_size;    /* uncompressed size               4 bytes */ 
112     uLong size_filename;        /* filename length                 2 bytes */
113     uLong size_file_extra;      /* extra field length              2 bytes */
114     uLong size_file_comment;    /* file comment length             2 bytes */
115
116     uLong disk_num_start;       /* disk number start               2 bytes */
117     uLong internal_fa;          /* internal file attributes        2 bytes */
118     uLong external_fa;          /* external file attributes        4 bytes */
119
120     tm_unz tmu_date;
121 } unz_file_info;
122
123
124 /* unz_file_info_interntal contain internal info about a file in zipfile*/
125 typedef struct unz_file_info_internal_s
126 {
127     uLong offset_curfile;/* relative offset of local header 4 bytes */
128 } unz_file_info_internal;
129
130
131 /* file_in_zip_read_info_s contain internal information about a file in zipfile,
132     when reading and decompress it */
133 typedef struct
134 {
135         char  *read_buffer;         /* internal buffer for compressed data */
136         z_stream stream;            /* zLib stream structure for inflate */
137
138         uLong pos_in_zipfile;       /* position in byte on the zipfile, for fseek*/
139         uLong stream_initialised;   /* flag set if stream structure is initialised*/
140
141         uLong offset_local_extrafield;/* offset of the local extra field */
142         uInt  size_local_extrafield;/* size of the local extra field */
143         uLong pos_local_extrafield;   /* position in the local extra field in read*/
144
145         uLong crc32;                /* crc32 of all data uncompressed */
146         uLong crc32_wait;           /* crc32 we must obtain after decompress all */
147         uLong rest_read_compressed; /* number of byte to be decompressed */
148         uLong rest_read_uncompressed;/*number of byte to be obtained after decomp*/
149         FILE* file;                 /* io structore of the zipfile */
150         uLong compression_method;   /* compression method (0==store) */
151         uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
152 } file_in_zip_read_info_s;
153
154
155 /*JOWENN*/
156 typedef struct cacao_entry
157 {
158         struct cacao_entry *next;
159         utf *name;
160         uLong pos;
161 } cacao_entry_s;
162
163 /* unz_s contain internal information about the zipfile
164 */
165 typedef struct
166 {
167         FILE* file;                 /* io structore of the zipfile */
168         unz_global_info gi;       /* public global information */
169         uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
170         uLong num_file;             /* number of the current file in the zipfile*/
171         uLong pos_in_central_dir;   /* pos of the current file in the central dir*/
172         uLong current_file_ok;      /* flag about the usability of the current file*/
173         uLong central_pos;          /* position of the beginning of the central dir*/
174
175         uLong size_central_dir;     /* size of the central directory  */
176         uLong offset_central_dir;   /* offset of start of central directory with
177                                                                    respect to the starting disk number */
178
179         unz_file_info cur_file_info; /* public info about the current file in zip*/
180         unz_file_info_internal cur_file_info_internal; /* private info about it*/
181         file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current
182                                             file if we are decompressing it */
183         cacao_entry_s *cacao_dir_list;
184 } unz_s;
185
186
187 int  unzStringFileNameCompare OF ((const char* fileName1,
188                                                                                                  const char* fileName2,
189                                                                                                  int iCaseSensitivity));
190 /*
191    Compare two filename (fileName1,fileName2).
192    If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
193    If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
194                                                                 or strcasecmp)
195    If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
196         (like 1 on Unix, 2 on Windows)
197 */
198
199
200 unzFile unzOpen OF((const char *path));
201 /*
202   Open a Zip file. path contain the full pathname (by example,
203      on a Windows NT computer "c:\\zlib\\zlib111.zip" or on an Unix computer
204          "zlib/zlib111.zip".
205          If the zipfile cannot be opened (file don't exist or in not valid), the
206            return value is NULL.
207      Else, the return value is a unzFile Handle, usable with other function
208            of this unzip package.
209 */
210
211 int  unzClose OF((unzFile file));
212 /*
213   Close a ZipFile opened with unzipOpen.
214   If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
215     these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
216   return UNZ_OK if there is no problem. */
217
218 int  unzGetGlobalInfo OF((unzFile file,
219                                         unz_global_info *pglobal_info));
220 /*
221   Write info about the ZipFile in the *pglobal_info structure.
222   No preparation of the structure is needed
223   return UNZ_OK if there is no problem. */
224
225
226 int unzGetGlobalComment OF((unzFile file,
227                                                                                    char *szComment,
228                                            uLong uSizeBuf));
229 /*
230   Get the global comment string of the ZipFile, in the szComment buffer.
231   uSizeBuf is the size of the szComment buffer.
232   return the number of byte copied or an error code <0
233 */
234
235
236 /***************************************************************************/
237 /* Unzip package allow you browse the directory of the zipfile */
238
239 int  unzGoToFirstFile OF((unzFile file));
240 /*
241   Set the current file of the zipfile to the first file.
242   return UNZ_OK if there is no problem
243 */
244
245 int  unzGoToNextFile OF((unzFile file));
246 /*
247   Set the current file of the zipfile to the next file.
248   return UNZ_OK if there is no problem
249   return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
250 */
251
252 void cacao_create_directoryList(unzFile file);
253
254 int  unzLocateFile OF((unzFile file, 
255                                      const char *szFileName,
256                                      int iCaseSensitivity));
257 /*
258   Try locate the file szFileName in the zipfile.
259   For the iCaseSensitivity signification, see unzStringFileNameCompare
260
261   return value :
262   UNZ_OK if the file is found. It becomes the current file.
263   UNZ_END_OF_LIST_OF_FILE if the file is not found
264 */
265
266
267 int  unzGetCurrentFileInfo OF((unzFile file,
268                                              unz_file_info *pfile_info,
269                                              char *szFileName,
270                                              uLong fileNameBufferSize,
271                                              void *extraField,
272                                              uLong extraFieldBufferSize,
273                                              char *szComment,
274                                              uLong commentBufferSize));
275 /*
276   Get Info about the current file
277   if pfile_info!=NULL, the *pfile_info structure will contain somes info about
278             the current file
279   if szFileName!=NULL, the filemane string will be copied in szFileName
280                         (fileNameBufferSize is the size of the buffer)
281   if extraField!=NULL, the extra field information will be copied in extraField
282                         (extraFieldBufferSize is the size of the buffer).
283                         This is the Central-header version of the extra field
284   if szComment!=NULL, the comment string of the file will be copied in szComment
285                         (commentBufferSize is the size of the buffer)
286 */
287
288 /***************************************************************************/
289 /* for reading the content of the current zipfile, you can open it, read data
290    from it, and close it (you can close it before reading all the file)
291    */
292
293 int  unzOpenCurrentFile OF((unzFile file));
294 /*
295   Open for reading data the current file in the zipfile.
296   If there is no error, the return value is UNZ_OK.
297 */
298
299 int  unzCloseCurrentFile OF((unzFile file));
300 /*
301   Close the file in zip opened with unzOpenCurrentFile
302   Return UNZ_CRCERROR if all the file was read but the CRC is not good
303 */
304
305                                                                                                 
306 int  unzReadCurrentFile OF((unzFile file, 
307                                           voidp buf,
308                                           unsigned len));
309 /*
310   Read bytes from the current file (opened by unzOpenCurrentFile)
311   buf contain buffer where data must be copied
312   len the size of buf.
313
314   return the number of byte copied if somes bytes are copied
315   return 0 if the end of file was reached
316   return <0 with error code if there is an error
317     (UNZ_ERRNO for IO error, or zLib error for uncompress error)
318 */
319
320 z_off_t unztell OF((unzFile file));
321 /*
322   Give the current position in uncompressed data
323 */
324
325 int  unzeof OF((unzFile file));
326 /*
327   return 1 if the end of file was reached, 0 elsewhere 
328 */
329
330 int  unzGetLocalExtrafield OF((unzFile file,
331                                                                                          voidp buf,
332                                                                                          unsigned len));
333 /*
334   Read extra field from the current file (opened by unzOpenCurrentFile)
335   This is the local-header version of the extra field (sometimes, there is
336     more info in the local-header version than in the central-header)
337
338   if buf==NULL, it return the size of the local extra field
339
340   if buf!=NULL, len is the size of the buffer, the extra header is copied in
341         buf.
342   the return value is the number of bytes copied in buf, or (if <0) 
343         the error code
344 */
345
346
347 #ifdef __cplusplus
348 }
349 #endif
350
351 #endif /* _unz_H */