doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Unzip.h
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 
29 #ifndef __UNZIP_H__
30 #define __UNZIP_H__
31 
32 
33 #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
34 /* like the STRICT of WIN32, we define a pointer that cannot be converted
35  from (void*) without cast */
36 typedef struct TagunzFile__ { int unused; } unzFile__;
37 typedef unzFile__ *unzFile;
38 #else
39 typedef void* unzFile;
40 #endif
41 
42 /* tm_unz contain date/time info */
43 typedef struct tm_unz_s
44 {
45  unsigned int tm_sec; /* seconds after the minute - [0,59] */
46  unsigned int tm_min; /* minutes after the hour - [0,59] */
47  unsigned int tm_hour; /* hours since midnight - [0,23] */
48  unsigned int tm_mday; /* day of the month - [1,31] */
49  unsigned int tm_mon; /* months since January - [0,11] */
50  unsigned int tm_year; /* years - [1980..2044] */
51 } tm_unz;
52 
53 /* unz_global_info structure contain global data about the ZIPfile
54  These data comes from the end of central dir */
55 typedef struct unz_global_info_s
56 {
57  unsigned long number_entry; /* total number of entries in the central dir on this disk */
58  unsigned long size_comment; /* size of the global comment of the zipfile */
60 
61 
62 /* unz_file_info contain information about a file in the zipfile */
63 typedef struct unz_file_info_s
64 {
65  unsigned long version; /* version made by 2 unsigned chars */
66  unsigned long version_needed; /* version needed to extract 2 unsigned chars */
67  unsigned long flag; /* general purpose bit flag 2 unsigned chars */
68  unsigned long compression_method; /* compression method 2 unsigned chars */
69  unsigned long dosDate; /* last mod file date in Dos fmt 4 unsigned chars */
70  unsigned long crc; /* crc-32 4 unsigned chars */
71  unsigned long compressed_size; /* compressed size 4 unsigned chars */
72  unsigned long uncompressed_size; /* uncompressed size 4 unsigned chars */
73  unsigned long size_filename; /* filename length 2 unsigned chars */
74  unsigned long size_file_extra; /* extra field length 2 unsigned chars */
75  unsigned long size_file_comment; /* file comment length 2 unsigned chars */
76 
77  unsigned long disk_num_start; /* disk number start 2 unsigned chars */
78  unsigned long internal_fa; /* internal file attributes 2 unsigned chars */
79  unsigned long external_fa; /* external file attributes 4 unsigned chars */
80 
83 
84 /* unz_file_info_interntal contain internal info about a file in zipfile*/
86 {
87  unsigned long offset_curfile;/* relative offset of static header 4 unsigned chars */
89 
90 typedef void* (*alloc_func) (void* opaque, unsigned int items, unsigned int size);
91 typedef void (*free_func) (void* opaque, void* address);
92 
93 struct internal_state;
94 
95 typedef struct z_stream_s {
96  unsigned char *next_in; /* next input unsigned char */
97  unsigned int avail_in; /* number of unsigned chars available at next_in */
98  unsigned long total_in; /* total nb of input unsigned chars read so */
99 
100  unsigned char *next_out; /* next output unsigned char should be put there */
101  unsigned int avail_out; /* remaining free space at next_out */
102  unsigned long total_out; /* total nb of unsigned chars output so */
103 
104  char *msg; /* last error message, NULL if no error */
105  struct internal_state *state; /* not visible by applications */
106 
107  alloc_func zalloc; /* used to allocate the internal state */
108  free_func zfree; /* used to free the internal state */
109  unsigned char* opaque; /* private data object passed to zalloc and zfree */
110 
111  int data_type; /* best guess about the data type: ascii or binary */
112  unsigned long adler; /* adler32 value of the uncompressed data */
113  unsigned long reserved; /* reserved for future use */
114 } z_stream;
115 
117 
118 
119 /* file_in_zip_read_info_s contain internal information about a file in zipfile,
120  when reading and decompress it */
121 typedef struct
122 {
123  char *read_buffer; /* internal buffer for compressed data */
124  z_stream stream; /* zLib stream structure for inflate */
125 
126  unsigned long pos_in_zipfile; /* position in unsigned char on the zipfile, for fseek*/
127  unsigned long stream_initialised; /* flag set if stream structure is initialised*/
128 
129  unsigned long offset_local_extrafield;/* offset of the static extra field */
130  unsigned int size_local_extrafield;/* size of the static extra field */
131  unsigned long pos_local_extrafield; /* position in the static extra field in read*/
132 
133  unsigned long crc32; /* crc32 of all data uncompressed */
134  unsigned long crc32_wait; /* crc32 we must obtain after decompress all */
135  unsigned long rest_read_compressed; /* number of unsigned char to be decompressed */
136  unsigned long rest_read_uncompressed;/*number of unsigned char to be obtained after decomp*/
137  FILE* file; /* io structore of the zipfile */
138  unsigned long compression_method; /* compression method (0==store) */
139  unsigned long byte_before_the_zipfile;/* unsigned char before the zipfile, (>0 for sfx)*/
141 
142 
143 /* unz_s contain internal information about the zipfile
144 */
145 typedef struct
146 {
147  FILE* file; /* io structore of the zipfile */
148  unz_global_info gi; /* public global information */
149  unsigned long byte_before_the_zipfile;/* unsigned char before the zipfile, (>0 for sfx)*/
150  unsigned long num_file; /* number of the current file in the zipfile*/
151  unsigned long pos_in_central_dir; /* pos of the current file in the central dir*/
152  unsigned long current_file_ok; /* flag about the usability of the current file*/
153  unsigned long central_pos; /* position of the beginning of the central dir*/
154 
155  unsigned long size_central_dir; /* size of the central directory */
156  unsigned long offset_central_dir; /* offset of start of central directory with
157  respect to the starting disk number */
158 
159  unz_file_info cur_file_info; /* public info about the current file in zip*/
160  unz_file_info_internal cur_file_info_internal; /* private info about it*/
161  file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current
162  file if we are decompressing it */
163 } unz_s;
164 
165 #define UNZ_OK (0)
166 #define UNZ_END_OF_LIST_OF_FILE (-100)
167 #define UNZ_ERRNO (Z_ERRNO)
168 #define UNZ_EOF (0)
169 #define UNZ_PARAMERROR (-102)
170 #define UNZ_BADZIPFILE (-103)
171 #define UNZ_INTERNALERROR (-104)
172 #define UNZ_CRCERROR (-105)
173 
174 #define UNZ_CASESENSITIVE 1
175 #define UNZ_NOTCASESENSITIVE 2
176 #define UNZ_OSDEFAULTCASE 0
177 
178 extern int unzStringFileNameCompare (const char* fileName1, const char* fileName2, int iCaseSensitivity);
179 
180 /*
181  Compare two filename (fileName1,fileName2).
182  If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
183  If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
184  or strcasecmp)
185  If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
186  (like 1 on Unix, 2 on Windows)
187 */
188 
189 extern unzFile unzOpen (const char *path);
190 extern unzFile unzReOpen (const char* path, unzFile file);
191 
192 /*
193  Open a Zip file. path contain the full pathname (by example,
194  on a Windows NT computer "c:\\zlib\\zlib111.zip" or on an Unix computer
195  "zlib/zlib111.zip".
196  If the zipfile cannot be opened (file don't exist or in not valid), the
197  return value is NULL.
198  Else, the return value is a unzFile Handle, usable with other function
199  of this unzip package.
200 */
201 
202 extern int unzClose (unzFile file);
203 
204 /*
205  Close a ZipFile opened with unzipOpen.
206  If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
207  these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
208  return UNZ_OK if there is no problem. */
209 
210 extern int unzGetGlobalInfo (unzFile file, unz_global_info *pglobal_info);
211 
212 /*
213  Write info about the ZipFile in the *pglobal_info structure.
214  No preparation of the structure is needed
215  return UNZ_OK if there is no problem. */
216 
217 
218 extern int unzGetGlobalComment (unzFile file, char *szComment, unsigned long uSizeBuf);
219 
220 /*
221  Get the global comment string of the ZipFile, in the szComment buffer.
222  uSizeBuf is the size of the szComment buffer.
223  return the number of unsigned char copied or an error code <0
224 */
225 
226 
227 /***************************************************************************/
228 /* Unzip package allow you browse the directory of the zipfile */
229 
230 extern int unzGoToFirstFile (unzFile file);
231 
232 /*
233  Set the current file of the zipfile to the first file.
234  return UNZ_OK if there is no problem
235 */
236 
237 extern int unzGoToNextFile (unzFile file);
238 
239 /*
240  Set the current file of the zipfile to the next file.
241  return UNZ_OK if there is no problem
242  return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
243 */
244 
245 extern int unzGetCurrentFileInfoPosition (unzFile file, unsigned long *pos );
246 
247 /*
248  Get the position of the info of the current file in the zip.
249  return UNZ_OK if there is no problem
250 */
251 
252 extern int unzSetCurrentFileInfoPosition (unzFile file, unsigned long pos );
253 
254 /*
255  Set the position of the info of the current file in the zip.
256  return UNZ_OK if there is no problem
257 */
258 
259 extern int unzLocateFile (unzFile file, const char *szFileName, int iCaseSensitivity);
260 
261 /*
262  Try locate the file szFileName in the zipfile.
263  For the iCaseSensitivity signification, see unzStringFileNameCompare
264 
265  return value :
266  UNZ_OK if the file is found. It becomes the current file.
267  UNZ_END_OF_LIST_OF_FILE if the file is not found
268 */
269 
270 
271 extern int unzGetCurrentFileInfo (unzFile file, unz_file_info *pfile_info, char *szFileName, unsigned long fileNameBufferSize, void *extraField, unsigned long extraFieldBufferSize, char *szComment, unsigned long commentBufferSize);
272 
273 /*
274  Get Info about the current file
275  if pfile_info!=NULL, the *pfile_info structure will contain somes info about
276  the current file
277  if szFileName!=NULL, the filemane string will be copied in szFileName
278  (fileNameBufferSize is the size of the buffer)
279  if extraField!=NULL, the extra field information will be copied in extraField
280  (extraFieldBufferSize is the size of the buffer).
281  This is the Central-header version of the extra field
282  if szComment!=NULL, the comment string of the file will be copied in szComment
283  (commentBufferSize is the size of the buffer)
284 */
285 
286 /***************************************************************************/
287 /* for reading the content of the current zipfile, you can open it, read data
288  from it, and close it (you can close it before reading all the file)
289  */
290 
291 extern int unzOpenCurrentFile (unzFile file);
292 
293 /*
294  Open for reading data the current file in the zipfile.
295  If there is no error, the return value is UNZ_OK.
296 */
297 
298 extern int unzCloseCurrentFile (unzFile file);
299 
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 extern int unzReadCurrentFile (unzFile file, void* buf, unsigned len);
307 
308 /*
309  Read unsigned chars from the current file (opened by unzOpenCurrentFile)
310  buf contain buffer where data must be copied
311  len the size of buf.
312 
313  return the number of unsigned char copied if somes unsigned chars are copied
314  return 0 if the end of file was reached
315  return <0 with error code if there is an error
316  (UNZ_ERRNO for IO error, or zLib error for uncompress error)
317 */
318 
319 extern long unztell(unzFile file);
320 
321 /*
322  Give the current position in uncompressed data
323 */
324 
325 extern int unzeof (unzFile file);
326 
327 /*
328  return 1 if the end of file was reached, 0 elsewhere
329 */
330 
331 extern int unzGetLocalExtrafield (unzFile file, void* buf, unsigned len);
332 
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 unsigned chars copied in buf, or (if <0)
343  the error code
344 */
345 
346 #endif /* __UNZIP_H__ */
struct unz_global_info_s unz_global_info
unsigned long offset_local_extrafield
Definition: Unzip.h:129
unsigned int avail_in
Definition: Unzip.h:97
unsigned int tm_mday
Definition: Unzip.h:48
unsigned long size_file_extra
Definition: Unzip.h:74
unsigned long size_comment
Definition: Unzip.h:58
int unzReadCurrentFile(unzFile file, void *buf, unsigned len)
Definition: Unzip.cpp:1952
struct unz_file_info_s unz_file_info
unsigned long compression_method
Definition: Unzip.h:138
int unzGoToNextFile(unzFile file)
Definition: Unzip.cpp:1648
unsigned long offset_curfile
Definition: Unzip.h:87
void(* free_func)(void *opaque, void *address)
Definition: Unzip.h:91
unzFile unzReOpen(const char *path, unzFile file)
Definition: Unzip.cpp:1282
unsigned int tm_year
Definition: Unzip.h:50
int unzOpenCurrentFile(unzFile file)
Definition: Unzip.cpp:1852
tm_unz tmu_date
Definition: Unzip.h:81
unsigned long offset_central_dir
Definition: Unzip.h:156
struct unz_file_info_internal_s unz_file_info_internal
unsigned long crc
Definition: Unzip.h:70
unsigned long flag
Definition: Unzip.h:67
unsigned char * next_out
Definition: Unzip.h:100
unsigned long rest_read_uncompressed
Definition: Unzip.h:136
struct z_stream_s z_stream
unsigned long byte_before_the_zipfile
Definition: Unzip.h:139
unsigned int tm_sec
Definition: Unzip.h:45
char * msg
Definition: Unzip.h:104
unsigned long pos_local_extrafield
Definition: Unzip.h:131
unsigned char * opaque
Definition: Unzip.h:109
GLenum GLsizei len
Definition: glext.h:3472
unsigned long stream_initialised
Definition: Unzip.h:127
unsigned long crc32_wait
Definition: Unzip.h:134
free_func zfree
Definition: Unzip.h:108
int unzGetLocalExtrafield(unzFile file, void *buf, unsigned len)
Definition: Unzip.cpp:2128
unzFile unzOpen(const char *path)
Definition: Unzip.cpp:1309
int unzGetGlobalInfo(unzFile file, unz_global_info *pglobal_info)
Definition: Unzip.cpp:1424
unsigned int tm_hour
Definition: Unzip.h:47
unsigned long version
Definition: Unzip.h:65
unsigned long total_out
Definition: Unzip.h:102
int unzCloseCurrentFile(unzFile file)
Definition: Unzip.cpp:2172
unsigned int avail_out
Definition: Unzip.h:101
file_in_zip_read_info_s * pfile_in_zip_read
Definition: Unzip.h:161
unsigned long version_needed
Definition: Unzip.h:66
int data_type
Definition: Unzip.h:111
unsigned long uncompressed_size
Definition: Unzip.h:72
int unzClose(unzFile file)
Definition: Unzip.cpp:1404
unsigned long rest_read_compressed
Definition: Unzip.h:135
int unzGetCurrentFileInfo(unzFile file, unz_file_info *pfile_info, char *szFileName, unsigned long fileNameBufferSize, void *extraField, unsigned long extraFieldBufferSize, char *szComment, unsigned long commentBufferSize)
Definition: Unzip.cpp:1612
unsigned long compression_method
Definition: Unzip.h:68
unsigned long pos_in_central_dir
Definition: Unzip.h:151
unsigned long central_pos
Definition: Unzip.h:153
void * unzFile
Definition: Unzip.h:39
unz_file_info cur_file_info
Definition: Unzip.h:159
unsigned char * next_in
Definition: Unzip.h:96
const char * path
Definition: sws.c:117
alloc_func zalloc
Definition: Unzip.h:107
Definition: Unzip.h:43
unsigned int size_local_extrafield
Definition: Unzip.h:130
unsigned long disk_num_start
Definition: Unzip.h:77
unsigned long total_in
Definition: Unzip.h:98
int unzSetCurrentFileInfoPosition(unzFile file, unsigned long pos)
Definition: Unzip.cpp:1691
int unzGoToFirstFile(unzFile file)
Definition: Unzip.cpp:1627
unsigned long internal_fa
Definition: Unzip.h:78
unsigned long dosDate
Definition: Unzip.h:69
unsigned long crc32
Definition: Unzip.h:133
unsigned int tm_min
Definition: Unzip.h:46
unsigned long pos_in_zipfile
Definition: Unzip.h:126
unsigned int tm_mon
Definition: Unzip.h:49
unsigned long current_file_ok
Definition: Unzip.h:152
int unzeof(unzFile file)
Definition: Unzip.cpp:2096
unsigned long number_entry
Definition: Unzip.h:57
unsigned long byte_before_the_zipfile
Definition: Unzip.h:149
int unzGetCurrentFileInfoPosition(unzFile file, unsigned long *pos)
Definition: Unzip.cpp:1675
GLsizeiptr size
Definition: glext.h:3112
int unzStringFileNameCompare(const char *fileName1, const char *fileName2, int iCaseSensitivity)
Definition: Unzip.cpp:1210
GLuint address
Definition: glext.h:5165
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
unsigned long compressed_size
Definition: Unzip.h:71
Definition: Unzip.h:145
unsigned long external_fa
Definition: Unzip.h:79
void *(* alloc_func)(void *opaque, unsigned int items, unsigned int size)
Definition: Unzip.h:90
struct internal_state * state
Definition: Unzip.h:105
unsigned long num_file
Definition: Unzip.h:150
unz_file_info_internal cur_file_info_internal
Definition: Unzip.h:160
unsigned long size_file_comment
Definition: Unzip.h:75
long unztell(unzFile file)
Definition: Unzip.cpp:2077
int unzGetGlobalComment(unzFile file, char *szComment, unsigned long uSizeBuf)
Definition: Unzip.cpp:2213
unsigned long reserved
Definition: Unzip.h:113
unsigned long adler
Definition: Unzip.h:112
unsigned long size_central_dir
Definition: Unzip.h:155
unz_global_info gi
Definition: Unzip.h:148
int unzLocateFile(unzFile file, const char *szFileName, int iCaseSensitivity)
Definition: Unzip.cpp:1716
struct tm_unz_s tm_unz
FILE * file
Definition: Unzip.h:147
unsigned long size_filename
Definition: Unzip.h:73
z_stream * z_streamp
Definition: Unzip.h:116