2 WARNING: DO NOT UNCRUSTIFY
3 It will still compile after an uncrustify, but it will be *broken*
4 See https://github.com/TTimo/GtkRadiant/issues/33
8 Copyright (C) 1999-2007 id Software, Inc. and contributors.
9 For a list of contributors, see the accompanying CONTRIBUTORS file.
11 This file is part of GtkRadiant.
13 GtkRadiant is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 GtkRadiant is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with GtkRadiant; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 /*****************************************************************************
31 * desc: IO on .zip files using portions of zlib
34 *****************************************************************************/
41 // TTimo added for safe_malloc wrapping
44 /* unzip.h -- IO for uncompress .zip files using zlib
45 Version 0.15 beta, Mar 19th, 1998,
47 Copyright (C) 1998 Gilles Vollant
49 This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
50 WinZip, InfoZip tools and compatible.
51 Encryption and multi volume ZipFile (span) are not supported.
52 Old compressions used by old PKZip 1.x are not supported
54 THIS IS AN ALPHA VERSION. AT THIS STAGE OF DEVELOPPEMENT, SOMES API OR STRUCTURE
55 CAN CHANGE IN FUTURE VERSION !!
56 I WAIT FEEDBACK at mail info@winimage.com
57 Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
59 Condition of use and distribution are the same than zlib :
61 This software is provided 'as-is', without any express or implied
62 warranty. In no event will the authors be held liable for any damages
63 arising from the use of this software.
65 Permission is granted to anyone to use this software for any purpose,
66 including commercial applications, and to alter it and redistribute it
67 freely, subject to the following restrictions:
69 1. The origin of this software must not be misrepresented; you must not
70 claim that you wrote the original software. If you use this software
71 in a product, an acknowledgment in the product documentation would be
72 appreciated but is not required.
73 2. Altered source versions must be plainly marked as such, and must not be
74 misrepresented as being the original software.
75 3. This notice may not be removed or altered from any source distribution.
80 // private stuff to not include cmdlib.h
82 ============================================================================
86 ============================================================================
90 #define __BIG_ENDIAN__
95 short __LittleShort (short l)
105 short __BigShort (short l)
111 int __LittleLong (int l)
120 return ((int)b1<<24) + ((int)b2<<16) + ((int)b3<<8) + b4;
123 int __BigLong (int l)
129 float __LittleFloat (float l)
131 union {byte b[4]; float f;} in, out;
142 float __BigFloat (float l)
151 short __BigShort (short l)
161 short __LittleShort (short l)
167 int __BigLong (int l)
176 return ((int)b1<<24) + ((int)b2<<16) + ((int)b3<<8) + b4;
179 int __LittleLong (int l)
184 float __BigFloat (float l)
186 union {byte b[4]; float f;} in, out;
197 float __LittleFloat (float l)
209 #define zmemcpy memcpy
210 #define zmemcmp memcmp
211 #define zmemzero(dest, len) memset(dest, 0, len)
213 /* Diagnostic functions */
216 # define Assert(cond,msg) assert(cond);
217 //{if(!(cond)) Sys_Error(msg);}
218 # define Trace(x) {if (z_verbose>=0) Sys_Error x ;}
219 # define Tracev(x) {if (z_verbose>0) Sys_Error x ;}
220 # define Tracevv(x) {if (z_verbose>1) Sys_Error x ;}
221 # define Tracec(c,x) {if (z_verbose>0 && (c)) Sys_Error x ;}
222 # define Tracecv(c,x) {if (z_verbose>1 && (c)) Sys_Error x ;}
224 # define Assert(cond,msg)
229 # define Tracecv(c,x)
233 typedef uLong (*check_func) OF((uLong check, const Byte *buf, uInt len));
234 static voidp zcalloc OF((voidp opaque, unsigned items, unsigned size));
235 static void zcfree OF((voidp opaque, voidp ptr));
237 #define ZALLOC(strm, items, size) \
238 (*((strm)->zalloc))((strm)->opaque, (items), (size))
239 #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidp)(addr))
240 #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
244 # define DEF_WBITS MAX_WBITS
246 /* default windowBits for decompression. MAX_WBITS is for compression only */
247 #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
250 #if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES) && \
251 !defined(CASESENSITIVITYDEFAULT_NO)
252 #define CASESENSITIVITYDEFAULT_NO
257 #define UNZ_BUFSIZE (65536)
260 #ifndef UNZ_MAXFILENAMEINZIP
261 #define UNZ_MAXFILENAMEINZIP (256)
265 # define ALLOC(size) (safe_malloc(size))
268 # define TRYFREE(p) {if (p) free(p);}
271 #define SIZECENTRALDIRITEM (0x2e)
272 #define SIZEZIPLOCALHEADER (0x1e)
274 /* ===========================================================================
275 Read a byte from a gz_stream; update next_in and avail_in. Return EOF
277 IN assertion: the stream s has been sucessfully opened for reading.
281 static int unzlocal_getByte(FILE *fin,int *pi)
284 int err = fread(&c, 1, 1, fin);
300 /* ===========================================================================
301 Reads a long in LSB order from the given gz_stream. Sets
303 static int unzlocal_getShort (FILE* fin, uLong *pX)
307 if ( fread( &v, sizeof( v ), 1, fin ) != 1 ) {
311 *pX = __LittleShort( v);
319 err = unzlocal_getByte(fin,&i);
323 err = unzlocal_getByte(fin,&i);
334 static int unzlocal_getLong (FILE *fin, uLong *pX)
338 if ( fread( &v, sizeof( v ), 1, fin ) != 1 ) {
342 *pX = __LittleLong( v);
350 err = unzlocal_getByte(fin,&i);
354 err = unzlocal_getByte(fin,&i);
358 err = unzlocal_getByte(fin,&i);
362 err = unzlocal_getByte(fin,&i);
374 /* My own strcmpi / strcasecmp */
375 static int strcmpcasenosensitive_internal (const char* fileName1,const char* fileName2)
379 char c1=*(fileName1++);
380 char c2=*(fileName2++);
381 if ((c1>='a') && (c1<='z'))
383 if ((c2>='a') && (c2<='z'))
386 return ((c2=='\0') ? 0 : -1);
397 #ifdef CASESENSITIVITYDEFAULT_NO
398 #define CASESENSITIVITYDEFAULTVALUE 2
400 #define CASESENSITIVITYDEFAULTVALUE 1
403 #ifndef STRCMPCASENOSENTIVEFUNCTION
404 #define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal
408 Compare two filename (fileName1,fileName2).
409 If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
410 If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
412 If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
413 (like 1 on Unix, 2 on Windows)
416 extern int unzStringFileNameCompare (const char* fileName1,const char* fileName2,int iCaseSensitivity)
418 if (iCaseSensitivity==0)
419 iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;
421 if (iCaseSensitivity==1)
422 return strcmp(fileName1,fileName2);
424 return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2);
427 #define BUFREADCOMMENT (0x400)
430 Locate the Central directory of a zipfile (at the end, just before
433 static uLong unzlocal_SearchCentralDir(FILE *fin)
438 uLong uMaxBack=0xffff; /* maximum size of global comment */
441 if (fseek(fin,0,SEEK_END) != 0)
445 uSizeFile = ftell( fin );
447 if (uMaxBack>uSizeFile)
448 uMaxBack = uSizeFile;
450 buf = (unsigned char*)safe_malloc(BUFREADCOMMENT+4);
455 while (uBackRead<uMaxBack)
457 uLong uReadSize,uReadPos ;
459 if (uBackRead+BUFREADCOMMENT>uMaxBack)
460 uBackRead = uMaxBack;
462 uBackRead+=BUFREADCOMMENT;
463 uReadPos = uSizeFile-uBackRead ;
465 uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
466 (BUFREADCOMMENT+4) : (uSizeFile-uReadPos);
467 if (fseek(fin,uReadPos,SEEK_SET)!=0)
470 if (fread(buf,(uInt)uReadSize,1,fin)!=1)
473 for (i=(int)uReadSize-3; (i--)>0;)
474 if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
475 ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
477 uPosFound = uReadPos+i;
488 extern unzFile unzReOpen (const char* path, unzFile file)
493 fin=fopen(path,"rb");
497 s=(unz_s*)safe_malloc(sizeof(unz_s));
498 memcpy(s, (unz_s*)file, sizeof(unz_s));
505 Open a Zip file. path contain the full pathname (by example,
506 on a Windows NT computer "c:\\test\\zlib109.zip" or on an Unix computer
508 If the zipfile cannot be opened (file don't exist or in not valid), the
509 return value is NULL.
510 Else, the return value is a unzFile Handle, usable with other function
511 of this unzip package.
513 extern unzFile unzOpen (const char* path)
517 uLong central_pos,uL;
520 uLong number_disk; /* number of the current dist, used for
521 spaning ZIP, unsupported, always 0*/
522 uLong number_disk_with_CD; /* number the the disk with central dir, used
523 for spaning ZIP, unsupported, always 0*/
524 uLong number_entry_CD; /* total number of entries in
526 (same than number_entry on nospan) */
530 fin=fopen(path,"rb");
534 central_pos = unzlocal_SearchCentralDir(fin);
538 if (fseek(fin,central_pos,SEEK_SET)!=0)
541 /* the signature, already checked */
542 if (unzlocal_getLong(fin,&uL)!=UNZ_OK)
545 /* number of this disk */
546 if (unzlocal_getShort(fin,&number_disk)!=UNZ_OK)
549 /* number of the disk with the start of the central directory */
550 if (unzlocal_getShort(fin,&number_disk_with_CD)!=UNZ_OK)
553 /* total number of entries in the central dir on this disk */
554 if (unzlocal_getShort(fin,&us.gi.number_entry)!=UNZ_OK)
557 /* total number of entries in the central dir */
558 if (unzlocal_getShort(fin,&number_entry_CD)!=UNZ_OK)
561 if ((number_entry_CD!=us.gi.number_entry) ||
562 (number_disk_with_CD!=0) ||
566 /* size of the central directory */
567 if (unzlocal_getLong(fin,&us.size_central_dir)!=UNZ_OK)
570 /* offset of start of central directory with respect to the
571 starting disk number */
572 if (unzlocal_getLong(fin,&us.offset_central_dir)!=UNZ_OK)
575 /* zipfile comment length */
576 if (unzlocal_getShort(fin,&us.gi.size_comment)!=UNZ_OK)
579 if ((central_pos<us.offset_central_dir+us.size_central_dir) &&
590 us.byte_before_the_zipfile = central_pos -
591 (us.offset_central_dir+us.size_central_dir);
592 us.central_pos = central_pos;
593 us.pfile_in_zip_read = NULL;
596 s=(unz_s*)safe_malloc(sizeof(unz_s));
598 // unzGoToFirstFile((unzFile)s);
604 Close a ZipFile opened with unzipOpen.
605 If there is files inside the .Zip opened with unzipOpenCurrentFile (see later),
606 these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
607 return UNZ_OK if there is no problem. */
608 extern int unzClose (unzFile file)
612 return UNZ_PARAMERROR;
615 if (s->pfile_in_zip_read!=NULL)
616 unzCloseCurrentFile(file);
625 Write info about the ZipFile in the *pglobal_info structure.
626 No preparation of the structure is needed
627 return UNZ_OK if there is no problem. */
628 extern int unzGetGlobalInfo (unzFile file,unz_global_info *pglobal_info)
632 return UNZ_PARAMERROR;
640 Translate date/time from Dos format to tm_unz (readable more easilty)
642 static void unzlocal_DosDateToTmuDate (uLong ulDosDate, tm_unz* ptm)
645 uDate = (uLong)(ulDosDate>>16);
646 ptm->tm_mday = (uInt)(uDate&0x1f) ;
647 ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ;
648 ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ;
650 ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800);
651 ptm->tm_min = (uInt) ((ulDosDate&0x7E0)/0x20) ;
652 ptm->tm_sec = (uInt) (2*(ulDosDate&0x1f)) ;
656 Get Info about the current file in the zipfile, with internal only info
658 static int unzlocal_GetCurrentFileInfoInternal (unzFile file,
659 unz_file_info *pfile_info,
660 unz_file_info_internal
661 *pfile_info_internal,
663 uLong fileNameBufferSize,
665 uLong extraFieldBufferSize,
667 uLong commentBufferSize)
670 unz_file_info file_info;
671 unz_file_info_internal file_info_internal;
677 return UNZ_PARAMERROR;
679 if (fseek(s->file,s->pos_in_central_dir+s->byte_before_the_zipfile,SEEK_SET)!=0)
683 /* we check the magic */
685 if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK)
687 else if (uMagic!=0x02014b50)
691 if (unzlocal_getShort(s->file,&file_info.version) != UNZ_OK)
694 if (unzlocal_getShort(s->file,&file_info.version_needed) != UNZ_OK)
697 if (unzlocal_getShort(s->file,&file_info.flag) != UNZ_OK)
700 if (unzlocal_getShort(s->file,&file_info.compression_method) != UNZ_OK)
703 if (unzlocal_getLong(s->file,&file_info.dosDate) != UNZ_OK)
706 unzlocal_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date);
708 if (unzlocal_getLong(s->file,&file_info.crc) != UNZ_OK)
711 if (unzlocal_getLong(s->file,&file_info.compressed_size) != UNZ_OK)
714 if (unzlocal_getLong(s->file,&file_info.uncompressed_size) != UNZ_OK)
717 if (unzlocal_getShort(s->file,&file_info.size_filename) != UNZ_OK)
720 if (unzlocal_getShort(s->file,&file_info.size_file_extra) != UNZ_OK)
723 if (unzlocal_getShort(s->file,&file_info.size_file_comment) != UNZ_OK)
726 if (unzlocal_getShort(s->file,&file_info.disk_num_start) != UNZ_OK)
729 if (unzlocal_getShort(s->file,&file_info.internal_fa) != UNZ_OK)
732 if (unzlocal_getLong(s->file,&file_info.external_fa) != UNZ_OK)
735 if (unzlocal_getLong(s->file,&file_info_internal.offset_curfile) != UNZ_OK)
738 lSeek+=file_info.size_filename;
739 if ((err==UNZ_OK) && (szFileName!=NULL))
742 if (file_info.size_filename<fileNameBufferSize)
744 *(szFileName+file_info.size_filename)='\0';
745 uSizeRead = file_info.size_filename;
748 uSizeRead = fileNameBufferSize;
750 if ((file_info.size_filename>0) && (fileNameBufferSize>0))
751 if (fread(szFileName,(uInt)uSizeRead,1,s->file)!=1)
757 if ((err==UNZ_OK) && (extraField!=NULL))
760 if (file_info.size_file_extra<extraFieldBufferSize)
761 uSizeRead = file_info.size_file_extra;
763 uSizeRead = extraFieldBufferSize;
766 if (fseek(s->file,lSeek,SEEK_CUR)==0)
771 if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
772 if (fread(extraField,(uInt)uSizeRead,1,s->file)!=1)
774 lSeek += file_info.size_file_extra - uSizeRead;
777 lSeek+=file_info.size_file_extra;
780 if ((err==UNZ_OK) && (szComment!=NULL))
783 if (file_info.size_file_comment<commentBufferSize)
785 *(szComment+file_info.size_file_comment)='\0';
786 uSizeRead = file_info.size_file_comment;
789 uSizeRead = commentBufferSize;
792 if (fseek(s->file,lSeek,SEEK_CUR)==0)
797 if ((file_info.size_file_comment>0) && (commentBufferSize>0))
798 if (fread(szComment,(uInt)uSizeRead,1,s->file)!=1)
800 lSeek+=file_info.size_file_comment - uSizeRead;
803 lSeek+=file_info.size_file_comment;
805 if ((err==UNZ_OK) && (pfile_info!=NULL))
806 *pfile_info=file_info;
808 if ((err==UNZ_OK) && (pfile_info_internal!=NULL))
809 *pfile_info_internal=file_info_internal;
817 Write info about the ZipFile in the *pglobal_info structure.
818 No preparation of the structure is needed
819 return UNZ_OK if there is no problem.
821 extern int unzGetCurrentFileInfo ( unzFile file, unz_file_info *pfile_info,
822 char *szFileName, uLong fileNameBufferSize,
823 void *extraField, uLong extraFieldBufferSize,
824 char *szComment, uLong commentBufferSize)
826 return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL,
827 szFileName,fileNameBufferSize,
828 extraField,extraFieldBufferSize,
829 szComment,commentBufferSize);
833 Set the current file of the zipfile to the first file.
834 return UNZ_OK if there is no problem
836 extern int unzGoToFirstFile (unzFile file)
841 return UNZ_PARAMERROR;
843 s->pos_in_central_dir=s->offset_central_dir;
845 err=unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
846 &s->cur_file_info_internal,
847 NULL,0,NULL,0,NULL,0);
848 s->current_file_ok = (err == UNZ_OK);
854 Set the current file of the zipfile to the next file.
855 return UNZ_OK if there is no problem
856 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
858 extern int unzGoToNextFile (unzFile file)
864 return UNZ_PARAMERROR;
866 if (!s->current_file_ok)
867 return UNZ_END_OF_LIST_OF_FILE;
868 if (s->num_file+1==s->gi.number_entry)
869 return UNZ_END_OF_LIST_OF_FILE;
871 s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename +
872 s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ;
874 err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
875 &s->cur_file_info_internal,
876 NULL,0,NULL,0,NULL,0);
877 s->current_file_ok = (err == UNZ_OK);
883 Try locate the file szFileName in the zipfile.
884 For the iCaseSensitivity signification, see unzipStringFileNameCompare
887 UNZ_OK if the file is found. It becomes the current file.
888 UNZ_END_OF_LIST_OF_FILE if the file is not found
890 extern int unzLocateFile (unzFile file, const char *szFileName, int iCaseSensitivity)
897 uLong pos_in_central_dirSaved;
901 return UNZ_PARAMERROR;
903 if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP)
904 return UNZ_PARAMERROR;
907 if (!s->current_file_ok)
908 return UNZ_END_OF_LIST_OF_FILE;
910 num_fileSaved = s->num_file;
911 pos_in_central_dirSaved = s->pos_in_central_dir;
913 err = unzGoToFirstFile(file);
915 while (err == UNZ_OK)
917 char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
918 unzGetCurrentFileInfo(file,NULL,
919 szCurrentFileName,sizeof(szCurrentFileName)-1,
921 if (unzStringFileNameCompare(szCurrentFileName,
922 szFileName,iCaseSensitivity)==0)
924 err = unzGoToNextFile(file);
927 s->num_file = num_fileSaved ;
928 s->pos_in_central_dir = pos_in_central_dirSaved ;
934 Read the static header of the current zipfile
935 Check the coherency of the static header and info in the end of central
936 directory about this file
937 store in *piSizeVar the size of extra info in static header
938 (filename and size of extra field data)
940 static int unzlocal_CheckCurrentFileCoherencyHeader (unz_s* s, uInt* piSizeVar,
941 uLong *poffset_local_extrafield,
942 uInt *psize_local_extrafield)
944 uLong uMagic,uData,uFlags;
946 uLong size_extra_field;
950 *poffset_local_extrafield = 0;
951 *psize_local_extrafield = 0;
953 if (fseek(s->file,s->cur_file_info_internal.offset_curfile +
954 s->byte_before_the_zipfile,SEEK_SET)!=0)
959 if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK)
961 else if (uMagic!=0x04034b50)
965 if (unzlocal_getShort(s->file,&uData) != UNZ_OK)
968 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion))
971 if (unzlocal_getShort(s->file,&uFlags) != UNZ_OK)
974 if (unzlocal_getShort(s->file,&uData) != UNZ_OK)
976 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method))
979 if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) &&
980 (s->cur_file_info.compression_method!=Z_DEFLATED))
983 if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* date/time */
986 if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* crc */
988 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) &&
992 if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* size compr */
994 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) &&
998 if (unzlocal_getLong(s->file,&uData) != UNZ_OK) /* size uncompr */
1000 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) &&
1005 if (unzlocal_getShort(s->file,&size_filename) != UNZ_OK)
1007 else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename))
1010 *piSizeVar += (uInt)size_filename;
1012 if (unzlocal_getShort(s->file,&size_extra_field) != UNZ_OK)
1014 *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile +
1015 SIZEZIPLOCALHEADER + size_filename;
1016 *psize_local_extrafield = (uInt)size_extra_field;
1018 *piSizeVar += (uInt)size_extra_field;
1024 Open for reading data the current file in the zipfile.
1025 If there is no error and the file is opened, the return value is UNZ_OK.
1027 extern int unzOpenCurrentFile (unzFile file)
1033 file_in_zip_read_info_s* pfile_in_zip_read_info;
1034 uLong offset_local_extrafield; /* offset of the static extra field */
1035 uInt size_local_extrafield; /* size of the static extra field */
1038 return UNZ_PARAMERROR;
1040 if (!s->current_file_ok)
1041 return UNZ_PARAMERROR;
1043 if (s->pfile_in_zip_read != NULL)
1044 unzCloseCurrentFile(file);
1046 if (unzlocal_CheckCurrentFileCoherencyHeader(s,&iSizeVar,
1047 &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK)
1048 return UNZ_BADZIPFILE;
1050 pfile_in_zip_read_info = (file_in_zip_read_info_s*)
1051 safe_malloc(sizeof(file_in_zip_read_info_s));
1052 if (pfile_in_zip_read_info==NULL)
1053 return UNZ_INTERNALERROR;
1055 pfile_in_zip_read_info->read_buffer=(char*)safe_malloc(UNZ_BUFSIZE);
1056 pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield;
1057 pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield;
1058 pfile_in_zip_read_info->pos_local_extrafield=0;
1060 if (pfile_in_zip_read_info->read_buffer==NULL)
1062 free(pfile_in_zip_read_info);
1063 return UNZ_INTERNALERROR;
1066 pfile_in_zip_read_info->stream_initialised=0;
1068 if ((s->cur_file_info.compression_method!=0) &&
1069 (s->cur_file_info.compression_method!=Z_DEFLATED))
1071 Store = s->cur_file_info.compression_method==0;
1073 pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc;
1074 pfile_in_zip_read_info->crc32=0;
1075 pfile_in_zip_read_info->compression_method =
1076 s->cur_file_info.compression_method;
1077 pfile_in_zip_read_info->file=s->file;
1078 pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile;
1080 pfile_in_zip_read_info->stream.total_out = 0;
1084 pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
1085 pfile_in_zip_read_info->stream.zfree = (free_func)0;
1086 pfile_in_zip_read_info->stream.opaque = (voidp)0;
1088 err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
1090 pfile_in_zip_read_info->stream_initialised=1;
1091 /* windowBits is passed < 0 to tell that there is no zlib header.
1092 * Note that in this case inflate *requires* an extra "dummy" byte
1093 * after the compressed stream in order to complete decompression and
1094 * return Z_STREAM_END.
1095 * In unzip, i don't wait absolutely Z_STREAM_END because I known the
1096 * size of both compressed and uncompressed data
1099 pfile_in_zip_read_info->rest_read_compressed =
1100 s->cur_file_info.compressed_size ;
1101 pfile_in_zip_read_info->rest_read_uncompressed =
1102 s->cur_file_info.uncompressed_size ;
1105 pfile_in_zip_read_info->pos_in_zipfile =
1106 s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER +
1109 pfile_in_zip_read_info->stream.avail_in = (uInt)0;
1112 s->pfile_in_zip_read = pfile_in_zip_read_info;
1118 Read bytes from the current file.
1119 buf contain buffer where data must be copied
1120 len the size of buf.
1122 return the number of byte copied if somes bytes are copied
1123 return 0 if the end of file was reached
1124 return <0 with error code if there is an error
1125 (UNZ_ERRNO for IO error, or zLib error for uncompress error)
1127 extern int unzReadCurrentFile (unzFile file, void *buf, unsigned len)
1132 file_in_zip_read_info_s* pfile_in_zip_read_info;
1134 return UNZ_PARAMERROR;
1136 pfile_in_zip_read_info=s->pfile_in_zip_read;
1138 if (pfile_in_zip_read_info==NULL)
1139 return UNZ_PARAMERROR;
1142 if ((pfile_in_zip_read_info->read_buffer == NULL))
1143 return UNZ_END_OF_LIST_OF_FILE;
1147 pfile_in_zip_read_info->stream.next_out = (Byte*)buf;
1149 pfile_in_zip_read_info->stream.avail_out = (uInt)len;
1151 if (len>pfile_in_zip_read_info->rest_read_uncompressed)
1152 pfile_in_zip_read_info->stream.avail_out =
1153 (uInt)pfile_in_zip_read_info->rest_read_uncompressed;
1155 while (pfile_in_zip_read_info->stream.avail_out>0)
1157 if ((pfile_in_zip_read_info->stream.avail_in==0) &&
1158 (pfile_in_zip_read_info->rest_read_compressed>0))
1160 uInt uReadThis = UNZ_BUFSIZE;
1161 if (pfile_in_zip_read_info->rest_read_compressed<uReadThis)
1162 uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed;
1165 if (s->cur_file_info.compressed_size == pfile_in_zip_read_info->rest_read_compressed)
1166 if (fseek(pfile_in_zip_read_info->file,
1167 pfile_in_zip_read_info->pos_in_zipfile +
1168 pfile_in_zip_read_info->byte_before_the_zipfile,SEEK_SET)!=0)
1170 if (fread(pfile_in_zip_read_info->read_buffer,uReadThis,1,
1171 pfile_in_zip_read_info->file)!=1)
1173 pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
1175 pfile_in_zip_read_info->rest_read_compressed-=uReadThis;
1177 pfile_in_zip_read_info->stream.next_in =
1178 (Byte*)pfile_in_zip_read_info->read_buffer;
1179 pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;
1182 if (pfile_in_zip_read_info->compression_method==0)
1185 if (pfile_in_zip_read_info->stream.avail_out <
1186 pfile_in_zip_read_info->stream.avail_in)
1187 uDoCopy = pfile_in_zip_read_info->stream.avail_out ;
1189 uDoCopy = pfile_in_zip_read_info->stream.avail_in ;
1191 for (i=0;i<uDoCopy;i++)
1192 *(pfile_in_zip_read_info->stream.next_out+i) =
1193 *(pfile_in_zip_read_info->stream.next_in+i);
1195 pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,
1196 pfile_in_zip_read_info->stream.next_out,
1198 pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy;
1199 pfile_in_zip_read_info->stream.avail_in -= uDoCopy;
1200 pfile_in_zip_read_info->stream.avail_out -= uDoCopy;
1201 pfile_in_zip_read_info->stream.next_out += uDoCopy;
1202 pfile_in_zip_read_info->stream.next_in += uDoCopy;
1203 pfile_in_zip_read_info->stream.total_out += uDoCopy;
1208 uLong uTotalOutBefore,uTotalOutAfter;
1209 const Byte *bufBefore;
1211 int flush=Z_SYNC_FLUSH;
1213 uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;
1214 bufBefore = pfile_in_zip_read_info->stream.next_out;
1217 if ((pfile_in_zip_read_info->rest_read_uncompressed ==
1218 pfile_in_zip_read_info->stream.avail_out) &&
1219 (pfile_in_zip_read_info->rest_read_compressed == 0))
1222 err=inflate(&pfile_in_zip_read_info->stream,flush);
1224 uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
1225 uOutThis = uTotalOutAfter-uTotalOutBefore;
1227 pfile_in_zip_read_info->crc32 =
1228 crc32(pfile_in_zip_read_info->crc32,bufBefore,
1231 pfile_in_zip_read_info->rest_read_uncompressed -=
1234 iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
1236 if (err==Z_STREAM_END)
1237 return (iRead==0) ? UNZ_EOF : iRead;
1250 Give the current position in uncompressed data
1252 extern long unztell (unzFile file)
1255 file_in_zip_read_info_s* pfile_in_zip_read_info;
1257 return UNZ_PARAMERROR;
1259 pfile_in_zip_read_info=s->pfile_in_zip_read;
1261 if (pfile_in_zip_read_info==NULL)
1262 return UNZ_PARAMERROR;
1264 return (long)pfile_in_zip_read_info->stream.total_out;
1269 return 1 if the end of file was reached, 0 elsewhere
1271 extern int unzeof (unzFile file)
1274 file_in_zip_read_info_s* pfile_in_zip_read_info;
1276 return UNZ_PARAMERROR;
1278 pfile_in_zip_read_info=s->pfile_in_zip_read;
1280 if (pfile_in_zip_read_info==NULL)
1281 return UNZ_PARAMERROR;
1283 if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
1292 Read extra field from the current file (opened by unzOpenCurrentFile)
1293 This is the static-header version of the extra field (sometimes, there is
1294 more info in the static-header version than in the central-header)
1296 if buf==NULL, it return the size of the static extra field that can be read
1298 if buf!=NULL, len is the size of the buffer, the extra header is copied in
1300 the return value is the number of bytes copied in buf, or (if <0)
1303 extern int unzGetLocalExtrafield (unzFile file,void *buf,unsigned len)
1306 file_in_zip_read_info_s* pfile_in_zip_read_info;
1311 return UNZ_PARAMERROR;
1313 pfile_in_zip_read_info=s->pfile_in_zip_read;
1315 if (pfile_in_zip_read_info==NULL)
1316 return UNZ_PARAMERROR;
1318 size_to_read = (pfile_in_zip_read_info->size_local_extrafield -
1319 pfile_in_zip_read_info->pos_local_extrafield);
1322 return (int)size_to_read;
1324 if (len>size_to_read)
1325 read_now = (uInt)size_to_read;
1327 read_now = (uInt)len ;
1332 if (fseek(pfile_in_zip_read_info->file,
1333 pfile_in_zip_read_info->offset_local_extrafield +
1334 pfile_in_zip_read_info->pos_local_extrafield,SEEK_SET)!=0)
1337 if (fread(buf,(uInt)size_to_read,1,pfile_in_zip_read_info->file)!=1)
1340 return (int)read_now;
1344 Close the file in zip opened with unzipOpenCurrentFile
1345 Return UNZ_CRCERROR if all the file was read but the CRC is not good
1347 extern int unzCloseCurrentFile (unzFile file)
1352 file_in_zip_read_info_s* pfile_in_zip_read_info;
1354 return UNZ_PARAMERROR;
1356 pfile_in_zip_read_info=s->pfile_in_zip_read;
1358 if (pfile_in_zip_read_info==NULL)
1359 return UNZ_PARAMERROR;
1362 if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
1364 if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait)
1369 free(pfile_in_zip_read_info->read_buffer);
1370 pfile_in_zip_read_info->read_buffer = NULL;
1371 if (pfile_in_zip_read_info->stream_initialised)
1372 inflateEnd(&pfile_in_zip_read_info->stream);
1374 pfile_in_zip_read_info->stream_initialised = 0;
1375 free(pfile_in_zip_read_info);
1377 s->pfile_in_zip_read=NULL;
1384 Get the global comment string of the ZipFile, in the szComment buffer.
1385 uSizeBuf is the size of the szComment buffer.
1386 return the number of byte copied or an error code <0
1388 extern int unzGetGlobalComment (unzFile file, char *szComment, uLong uSizeBuf)
1393 return UNZ_PARAMERROR;
1396 uReadThis = uSizeBuf;
1397 if (uReadThis>s->gi.size_comment)
1398 uReadThis = s->gi.size_comment;
1400 if (fseek(s->file,s->central_pos+22,SEEK_SET)!=0)
1406 if (fread(szComment,(uInt)uReadThis,1,s->file)!=1)
1410 if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment))
1411 *(szComment+s->gi.size_comment)='\0';
1412 return (int)uReadThis;
1415 /* crc32.c -- compute the CRC-32 of a data stream
1416 * Copyright (C) 1995-1998 Mark Adler
1417 * For conditions of distribution and use, see copyright notice in zlib.h
1421 #ifdef DYNAMIC_CRC_TABLE
1423 static int crc_table_empty = 1;
1424 static uLong crc_table[256];
1425 static void make_crc_table OF((void));
1428 Generate a table for a byte-wise 32-bit CRC calculation on the polynomial:
1429 x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
1431 Polynomials over GF(2) are represented in binary, one bit per coefficient,
1432 with the lowest powers in the most significant bit. Then adding polynomials
1433 is just exclusive-or, and multiplying a polynomial by x is a right shift by
1434 one. If we call the above polynomial p, and represent a byte as the
1435 polynomial q, also with the lowest power in the most significant bit (so the
1436 byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
1437 where a mod b means the remainder after dividing a by b.
1439 This calculation is done using the shift-register method of multiplying and
1440 taking the remainder. The register is initialized to zero, and for each
1441 incoming bit, x^32 is added mod p to the register if the bit is a one (where
1442 x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
1443 x (which is shifting right by one and adding x^32 mod p if the bit shifted
1444 out is a one). We start with the highest power (least significant bit) of
1445 q and repeat for all eight bits of q.
1447 The table is simply the CRC of all possible eight bit values. This is all
1448 the information needed to generate CRC's on data a byte at a time for all
1449 combinations of CRC register values and incoming bytes.
1451 static void make_crc_table()
1455 uLong poly; /* polynomial exclusive-or pattern */
1456 /* terms of polynomial defining this crc (except x^32): */
1457 static const Byte p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
1459 /* make exclusive-or pattern from polynomial (0xedb88320L) */
1461 for (n = 0; n < sizeof(p)/sizeof(Byte); n++)
1462 poly |= 1L << (31 - p[n]);
1464 for (n = 0; n < 256; n++)
1467 for (k = 0; k < 8; k++)
1468 c = c & 1 ? poly ^ (c >> 1) : c >> 1;
1471 crc_table_empty = 0;
1474 /* ========================================================================
1475 * Table of CRC-32's of all single-byte values (made by make_crc_table)
1477 static const uLong crc_table[256] = {
1478 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
1479 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
1480 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
1481 0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
1482 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
1483 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
1484 0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
1485 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
1486 0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
1487 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
1488 0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
1489 0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
1490 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
1491 0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
1492 0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
1493 0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
1494 0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
1495 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
1496 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
1497 0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
1498 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
1499 0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
1500 0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
1501 0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
1502 0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
1503 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
1504 0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
1505 0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
1506 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
1507 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
1508 0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
1509 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
1510 0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
1511 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
1512 0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
1513 0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
1514 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
1515 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
1516 0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
1517 0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
1518 0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
1519 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
1520 0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
1521 0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
1522 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
1523 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
1524 0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
1525 0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
1526 0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
1527 0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
1528 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
1534 /* ========================================================================= */
1535 #define DO1(buf) crc = crc_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8);
1536 #define DO2(buf) DO1(buf); DO1(buf);
1537 #define DO4(buf) DO2(buf); DO2(buf);
1538 #define DO8(buf) DO4(buf); DO4(buf);
1540 /* infblock.h -- header to use infblock.c
1541 * Copyright (C) 1995-1998 Mark Adler
1542 * For conditions of distribution and use, see copyright notice in zlib.h
1545 /* WARNING: this file should *not* be used by applications. It is
1546 part of the implementation of the compression library and is
1547 subject to change. Applications should only use zlib.h.
1550 struct inflate_blocks_state;
1551 typedef struct inflate_blocks_state inflate_blocks_statef;
1553 extern inflate_blocks_statef * inflate_blocks_new OF((
1555 check_func c, /* check function */
1556 uInt w)); /* window size */
1558 extern int inflate_blocks OF((
1559 inflate_blocks_statef *,
1561 int)); /* initial return code */
1563 extern void inflate_blocks_reset OF((
1564 inflate_blocks_statef *,
1566 uLong *)); /* check value on output */
1568 extern int inflate_blocks_free OF((
1569 inflate_blocks_statef *,
1572 extern void inflate_set_dictionary OF((
1573 inflate_blocks_statef *s,
1574 const Byte *d, /* dictionary */
1575 uInt n)); /* dictionary length */
1577 extern int inflate_blocks_sync_point OF((
1578 inflate_blocks_statef *s));
1580 /* simplify the use of the inflate_huft type with some defines */
1581 #define exop word.what.Exop
1582 #define bits word.what.Bits
1584 /* Table for deflate from PKZIP's appnote.txt. */
1585 static const uInt border[] = { /* Order of the bit length code lengths */
1586 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
1588 /* inftrees.h -- header to use inftrees.c
1589 * Copyright (C) 1995-1998 Mark Adler
1590 * For conditions of distribution and use, see copyright notice in zlib.h
1593 /* WARNING: this file should *not* be used by applications. It is
1594 part of the implementation of the compression library and is
1595 subject to change. Applications should only use zlib.h.
1598 /* Huffman code lookup table entry--this entry is four bytes for machines
1599 that have 16-bit pointers (e.g. PC's in the small or medium model). */
1601 typedef struct inflate_huft_s inflate_huft;
1603 struct inflate_huft_s {
1606 Byte Exop; /* number of extra bits or operation */
1607 Byte Bits; /* number of bits in this code or subcode */
1609 uInt pad; /* pad structure to a power of 2 (4 bytes for */
1610 } word; /* 16-bit, 8 bytes for 32-bit int's) */
1611 uInt base; /* literal, length base, distance base,
1615 /* Maximum size of dynamic tree. The maximum found in a long but non-
1616 exhaustive search was 1004 huft structures (850 for length/literals
1617 and 154 for distances, the latter actually the result of an
1618 exhaustive search). The actual maximum is not known, but the
1619 value below is more than safe. */
1622 extern int inflate_trees_bits OF((
1623 uInt *, /* 19 code lengths */
1624 uInt *, /* bits tree desired/actual depth */
1625 inflate_huft * *, /* bits tree result */
1626 inflate_huft *, /* space for trees */
1627 z_streamp)); /* for messages */
1629 extern int inflate_trees_dynamic OF((
1630 uInt, /* number of literal/length codes */
1631 uInt, /* number of distance codes */
1632 uInt *, /* that many (total) code lengths */
1633 uInt *, /* literal desired/actual bit depth */
1634 uInt *, /* distance desired/actual bit depth */
1635 inflate_huft * *, /* literal/length tree result */
1636 inflate_huft * *, /* distance tree result */
1637 inflate_huft *, /* space for trees */
1638 z_streamp)); /* for messages */
1640 extern int inflate_trees_fixed OF((
1641 uInt *, /* literal desired/actual bit depth */
1642 uInt *, /* distance desired/actual bit depth */
1643 inflate_huft * *, /* literal/length tree result */
1644 inflate_huft * *, /* distance tree result */
1645 z_streamp)); /* for memory allocation */
1648 /* infcodes.h -- header to use infcodes.c
1649 * Copyright (C) 1995-1998 Mark Adler
1650 * For conditions of distribution and use, see copyright notice in zlib.h
1653 /* WARNING: this file should *not* be used by applications. It is
1654 part of the implementation of the compression library and is
1655 subject to change. Applications should only use zlib.h.
1658 struct inflate_codes_state;
1659 typedef struct inflate_codes_state inflate_codes_statef;
1661 extern inflate_codes_statef *inflate_codes_new OF((
1663 inflate_huft *, inflate_huft *,
1666 extern int inflate_codes OF((
1667 inflate_blocks_statef *,
1671 extern void inflate_codes_free OF((
1672 inflate_codes_statef *,
1675 /* infutil.h -- types and macros common to blocks and codes
1676 * Copyright (C) 1995-1998 Mark Adler
1677 * For conditions of distribution and use, see copyright notice in zlib.h
1680 /* WARNING: this file should *not* be used by applications. It is
1681 part of the implementation of the compression library and is
1682 subject to change. Applications should only use zlib.h.
1689 TYPE, /* get type bits (3, including end bit) */
1690 LENS, /* get lengths for stored */
1691 STORED, /* processing stored block */
1692 TABLE, /* get table lengths */
1693 BTREE, /* get bit lengths tree for a dynamic block */
1694 DTREE, /* get length, distance trees for a dynamic block */
1695 CODES, /* processing fixed or dynamic block */
1696 DRY, /* output remaining window bytes */
1697 DONE, /* finished last block, done */
1698 BAD} /* got a data error--stuck here */
1701 /* inflate blocks semi-private state */
1702 struct inflate_blocks_state {
1705 inflate_block_mode mode; /* current inflate_block mode */
1707 /* mode dependent information */
1709 uInt left; /* if STORED, bytes left to copy */
1711 uInt table; /* table lengths (14 bits) */
1712 uInt index; /* index into blens (or border) */
1713 uInt *blens; /* bit lengths of codes */
1714 uInt bb; /* bit length tree depth */
1715 inflate_huft *tb; /* bit length decoding tree */
1716 } trees; /* if DTREE, decoding info for trees */
1718 inflate_codes_statef
1720 } decode; /* if CODES, current state */
1721 } sub; /* submode */
1722 uInt last; /* true if this block is the last block */
1724 /* mode independent information */
1725 uInt bitk; /* bits in bit buffer */
1726 uLong bitb; /* bit buffer */
1727 inflate_huft *hufts; /* single safe_malloc for tree space */
1728 Byte *window; /* sliding window */
1729 Byte *end; /* one byte after sliding window */
1730 Byte *read; /* window read pointer */
1731 Byte *write; /* window write pointer */
1732 check_func checkfn; /* check function */
1733 uLong check; /* check on output */
1738 /* defines for inflate input/output */
1739 /* update pointers and return */
1740 #define UPDBITS {s->bitb=b;s->bitk=k;}
1741 #define UPDIN {z->avail_in=n;z->total_in+=p-z->next_in;z->next_in=p;}
1742 #define UPDOUT {s->write=q;}
1743 #define UPDATE {UPDBITS UPDIN UPDOUT}
1744 #define LEAVE {UPDATE return inflate_flush(s,z,r);}
1745 /* get bytes and bits */
1746 #define LOADIN {p=z->next_in;n=z->avail_in;b=s->bitb;k=s->bitk;}
1747 #define NEEDBYTE {if(n)r=Z_OK;else LEAVE}
1748 #define NEXTBYTE (n--,*p++)
1749 #define NEEDBITS(j) {while(k<(j)){NEEDBYTE;b|=((uLong)NEXTBYTE)<<k;k+=8;}}
1750 #define DUMPBITS(j) {b>>=(j);k-=(j);}
1752 #define WAVAIL (uInt)(q<s->read?s->read-q-1:s->end-q)
1753 #define LOADOUT {q=s->write;m=(uInt)WAVAIL;}
1754 #define WRAP {if(q==s->end&&s->read!=s->window){q=s->window;m=(uInt)WAVAIL;}}
1755 #define FLUSH {UPDOUT r=inflate_flush(s,z,r); LOADOUT}
1756 #define NEEDOUT {if(m==0){WRAP if(m==0){FLUSH WRAP if(m==0) LEAVE}}r=Z_OK;}
1757 #define OUTBYTE(a) {*q++=(Byte)(a);m--;}
1758 /* load static pointers */
1759 #define LOAD {LOADIN LOADOUT}
1761 /* masks for lower bits (size given to avoid silly warnings with Visual C++) */
1762 extern uInt inflate_mask[17];
1764 /* copy as much as possible from the sliding window to the output area */
1765 extern int inflate_flush OF((
1766 inflate_blocks_statef *,
1774 Notes beyond the 1.93a appnote.txt:
1776 1. Distance pointers never point before the beginning of the output
1778 2. Distance pointers can point back across blocks, up to 32k away.
1779 3. There is an implied maximum of 7 bits for the bit length table and
1780 15 bits for the actual data.
1781 4. If only one code exists, then it is encoded using one bit. (Zero
1782 would be more efficient, but perhaps a little confusing.) If two
1783 codes exist, they are coded using one bit each (0 and 1).
1784 5. There is no way of sending zero distance codes--a dummy must be
1785 sent if there are none. (History: a pre 2.0 version of PKZIP would
1786 store blocks with no distance codes, but this was discovered to be
1787 too harsh a criterion.) Valid only for 1.93a. 2.04c does allow
1788 zero distance codes, which is sent as one code of zero bits in
1790 6. There are up to 286 literal/length codes. Code 256 represents the
1791 end-of-block. Note however that the static length tree defines
1792 288 codes just to fill out the Huffman codes. Codes 286 and 287
1793 cannot be used though, since there is no length base or extra bits
1794 defined for them. Similarily, there are up to 30 distance codes.
1795 However, static trees define 32 codes (all 5 bits) to fill out the
1796 Huffman codes, but the last two had better not show up in the data.
1797 7. Unzip can check dynamic Huffman blocks for complete code sets.
1798 The exception is that a single code would not be complete (see #4).
1799 8. The five bits following the block type is really the number of
1800 literal codes sent minus 257.
1801 9. Length codes 8,16,16 are interpreted as 13 length codes of 8 bits
1802 (1+6+6). Therefore, to output three times the length, you output
1803 three codes (1+1+1), whereas to output four times the same length,
1804 you only need two codes (1+3). Hmm.
1805 10. In the tree reconstruction algorithm, Code = Code + Increment
1806 only if BitLength(i) is not zero. (Pretty obvious.)
1807 11. Correction: 4 Bits: # of Bit Length codes - 4 (4 - 19)
1808 12. Note: length code 284 can represent 227-258, but length code 285
1809 really is 258. The last length deserves its own, short code
1810 since it gets used a lot in very redundant files. The length
1811 258 is special since 258 - 3 (the min match length) is 255.
1812 13. The literal/length and distance code bit lengths are read as a
1813 single stream of lengths. It is possible (and advantageous) for
1814 a repeat code (16, 17, or 18) to go across the boundary between
1815 the two sets of lengths.
1818 /* And'ing with mask[n] masks the lower n bits */
1819 uInt inflate_mask[17] = {
1821 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
1822 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
1826 If you use the zlib library in a product, an acknowledgment is welcome
1827 in the documentation of your product. If for some reason you cannot
1828 include such an acknowledgment, I would appreciate that you keep this
1829 copyright string in the executable of your product.
1832 /* simplify the use of the inflate_huft type with some defines */
1833 #define exop word.what.Exop
1834 #define bits word.what.Bits
1837 static int huft_build OF((
1838 uInt *, /* code lengths in bits */
1839 uInt, /* number of codes */
1840 uInt, /* number of "simple" codes */
1841 const uInt *, /* list of base values for non-simple codes */
1842 const uInt *, /* list of extra bits for non-simple codes */
1843 inflate_huft **, /* result: starting table */
1844 uInt *, /* maximum lookup bits (returns actual) */
1845 inflate_huft *, /* space for trees */
1846 uInt *, /* hufts used in space */
1847 uInt * )); /* space for values */
1849 /* Tables for deflate from PKZIP's appnote.txt. */
1850 static const uInt cplens[31] = { /* Copy lengths for literal codes 257..285 */
1851 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
1852 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
1853 /* see note #13 above about 258 */
1854 static const uInt cplext[31] = { /* Extra bits for literal codes 257..285 */
1855 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
1856 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112}; /* 112==invalid */
1857 static const uInt cpdist[30] = { /* Copy offsets for distance codes 0..29 */
1858 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
1859 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
1860 8193, 12289, 16385, 24577};
1861 static const uInt cpdext[30] = { /* Extra bits for distance codes */
1862 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
1863 7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
1867 Huffman code decoding is performed using a multi-level table lookup.
1868 The fastest way to decode is to simply build a lookup table whose
1869 size is determined by the longest code. However, the time it takes
1870 to build this table can also be a factor if the data being decoded
1871 is not very long. The most common codes are necessarily the
1872 shortest codes, so those codes dominate the decoding time, and hence
1873 the speed. The idea is you can have a shorter table that decodes the
1874 shorter, more probable codes, and then point to subsidiary tables for
1875 the longer codes. The time it costs to decode the longer codes is
1876 then traded against the time it takes to make longer tables.
1878 This results of this trade are in the variables lbits and dbits
1879 below. lbits is the number of bits the first level table for literal/
1880 length codes can decode in one step, and dbits is the same thing for
1881 the distance codes. Subsequent tables are also less than or equal to
1882 those sizes. These values may be adjusted either when all of the
1883 codes are shorter than that, in which case the longest code length in
1884 bits is used, or when the shortest code is *longer* than the requested
1885 table size, in which case the length of the shortest code in bits is
1888 There are two different values for the two tables, since they code a
1889 different number of possibilities each. The literal/length table
1890 codes 286 possible values, or in a flat code, a little over eight
1891 bits. The distance table codes 30 possible values, or a little less
1892 than five bits, flat. The optimum values for speed end up being
1893 about one bit more than those, so lbits is 8+1 and dbits is 5+1.
1894 The optimum values may differ though from machine to machine, and
1895 possibly even between compilers. Your mileage may vary.
1899 /* If BMAX needs to be larger than 16, then h and x[] should be uLong. */
1900 #define BMAX 15 /* maximum bit length of any code */
1902 static int huft_build(uInt *b, uInt n, uInt s, const uInt *d, const uInt *e, inflate_huft ** t, uInt *m, inflate_huft *hp, uInt *hn, uInt *v)
1903 //uInt *b; /* code lengths in bits (all assumed <= BMAX) */
1904 //uInt n; /* number of codes (assumed <= 288) */
1905 //uInt s; /* number of simple-valued codes (0..s-1) */
1906 //const uInt *d; /* list of base values for non-simple codes */
1907 //const uInt *e; /* list of extra bits for non-simple codes */
1908 //inflate_huft ** t; /* result: starting table */
1909 //uInt *m; /* maximum lookup bits, returns actual */
1910 //inflate_huft *hp; /* space for trees */
1911 //uInt *hn; /* hufts used in space */
1912 //uInt *v; /* working area: values in order of bit length */
1913 /* Given a list of code lengths and a maximum table size, make a set of
1914 tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR
1915 if the given code set is incomplete (the tables are still built in this
1916 case), Z_DATA_ERROR if the input is invalid (an over-subscribed set of
1917 lengths), or Z_MEM_ERROR if not enough memory. */
1920 uInt a; /* counter for codes of length k */
1921 uInt c[BMAX+1]; /* bit length count table */
1922 uInt f; /* i repeats in table every f entries */
1923 int g; /* maximum code length */
1924 int h; /* table level */
1925 register uInt i; /* counter, current code */
1926 register uInt j; /* counter */
1927 register int k; /* number of bits in current code */
1928 int l; /* bits per table (returned in m) */
1929 uInt mask; /* (1 << w) - 1, to avoid cc -O bug on HP */
1930 register uInt *p; /* pointer into c[], b[], or v[] */
1931 inflate_huft *q; /* points to current table */
1932 struct inflate_huft_s r; /* table entry for structure assignment */
1933 inflate_huft *u[BMAX]; /* table stack */
1934 register int w; /* bits before this table == (l * h) */
1935 uInt x[BMAX+1]; /* bit offsets, then code stack */
1936 uInt *xp; /* pointer into x */
1937 int y; /* number of dummy codes added */
1938 uInt z; /* number of entries in current table */
1941 /* Generate counts for each bit length */
1943 #define C0 *p++ = 0;
1944 #define C2 C0 C0 C0 C0
1945 #define C4 C2 C2 C2 C2
1946 C4 /* clear c[]--assume BMAX+1 is 16 */
1949 c[*p++]++; /* assume all entries <= BMAX */
1951 if (c[0] == n) /* null input--all zero length codes */
1953 *t = (inflate_huft *)Z_NULL;
1959 /* Find minimum and maximum length, bound *m by those */
1961 for (j = 1; j <= BMAX; j++)
1964 k = j; /* minimum code length */
1967 for (i = BMAX; i; i--)
1970 g = i; /* maximum code length */
1976 /* Adjust last length count to fill out codes, if needed */
1977 for (y = 1 << j; j < i; j++, y <<= 1)
1978 if ((y -= c[j]) < 0)
1979 return Z_DATA_ERROR;
1980 if ((y -= c[i]) < 0)
1981 return Z_DATA_ERROR;
1985 /* Generate starting offsets into the value table for each length */
1987 p = c + 1; xp = x + 2;
1988 while (--i) { /* note that i == g from above */
1989 *xp++ = (j += *p++);
1993 /* Make a table of values in order of bit lengths */
1996 if ((j = *p++) != 0)
1999 n = x[g]; /* set n to length of v */
2002 /* Generate the Huffman codes and for each, make the table entries */
2003 x[0] = i = 0; /* first Huffman code is zero */
2004 p = v; /* grab values in bit order */
2005 h = -1; /* no tables yet--level -1 */
2006 w = -l; /* bits decoded == (l * h) */
2007 u[0] = (inflate_huft *)Z_NULL; /* just to keep compilers happy */
2008 q = (inflate_huft *)Z_NULL; /* ditto */
2011 /* go through the bit lengths (k already is bits in shortest code) */
2017 /* here i is the Huffman code of length k bits for value *p */
2018 /* make tables up to required level */
2022 w += l; /* previous table always l bits */
2024 /* compute minimum size table less than or equal to l bits */
2026 z = z > (uInt)l ? (uInt)l : z; /* table size upper limit */
2027 if ((f = 1 << (j = k - w)) > a + 1) /* try a k-w bit table */
2028 { /* too few codes for k-w bit table */
2029 f -= a + 1; /* deduct codes from patterns left */
2032 while (++j < z) /* try smaller tables up to z bits */
2034 if ((f <<= 1) <= *++xp)
2035 break; /* enough codes to use up j bits */
2036 f -= *xp; /* else deduct codes from patterns */
2039 z = 1 << j; /* table entries for j-bit table */
2041 /* allocate new table */
2042 if (*hn + z > MANY) /* (note: doesn't matter for fixed) */
2043 return Z_MEM_ERROR; /* not enough memory */
2044 u[h] = q = hp + *hn;
2047 /* connect to last table, if there is one */
2050 x[h] = i; /* save pattern for backing up */
2051 r.bits = (Byte)l; /* bits to dump before this table */
2052 r.exop = (Byte)j; /* bits in this table */
2054 r.base = (uInt)(q - u[h-1] - j); /* offset to this table */
2055 u[h-1][j] = r; /* connect to last table */
2058 *t = q; /* first table is returned result */
2061 /* set up table entry in r */
2062 r.bits = (Byte)(k - w);
2064 r.exop = 128 + 64; /* out of values--invalid code */
2067 r.exop = (Byte)(*p < 256 ? 0 : 32 + 64); /* 256 is end-of-block */
2068 r.base = *p++; /* simple code is just the value */
2072 r.exop = (Byte)(e[*p - s] + 16 + 64);/* non-simple--look up in lists */
2073 r.base = d[*p++ - s];
2076 /* fill code-like entries with r */
2078 for (j = i >> w; j < z; j += f)
2081 /* backwards increment the k-bit code i */
2082 for (j = 1 << (k - 1); i & j; j >>= 1)
2086 /* backup over finished tables */
2087 mask = (1 << w) - 1; /* needed on HP, cc -O bug */
2088 while ((i & mask) != x[h])
2090 h--; /* don't need to update q */
2092 mask = (1 << w) - 1;
2098 /* Return Z_BUF_ERROR if we were given an incomplete table */
2099 return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
2103 /* inffixed.h -- table for decoding fixed codes
2104 * Generated automatically by the maketree.c program
2107 /* WARNING: this file should *not* be used by applications. It is
2108 part of the implementation of the compression library and is
2109 subject to change. Applications should only use zlib.h.
2112 static uInt fixed_bl = 9;
2113 static uInt fixed_bd = 5;
2114 static inflate_huft fixed_tl[] = {
2115 {{{96,7}},256}, {{{0,8}},80}, {{{0,8}},16}, {{{84,8}},115},
2116 {{{82,7}},31}, {{{0,8}},112}, {{{0,8}},48}, {{{0,9}},192},
2117 {{{80,7}},10}, {{{0,8}},96}, {{{0,8}},32}, {{{0,9}},160},
2118 {{{0,8}},0}, {{{0,8}},128}, {{{0,8}},64}, {{{0,9}},224},
2119 {{{80,7}},6}, {{{0,8}},88}, {{{0,8}},24}, {{{0,9}},144},
2120 {{{83,7}},59}, {{{0,8}},120}, {{{0,8}},56}, {{{0,9}},208},
2121 {{{81,7}},17}, {{{0,8}},104}, {{{0,8}},40}, {{{0,9}},176},
2122 {{{0,8}},8}, {{{0,8}},136}, {{{0,8}},72}, {{{0,9}},240},
2123 {{{80,7}},4}, {{{0,8}},84}, {{{0,8}},20}, {{{85,8}},227},
2124 {{{83,7}},43}, {{{0,8}},116}, {{{0,8}},52}, {{{0,9}},200},
2125 {{{81,7}},13}, {{{0,8}},100}, {{{0,8}},36}, {{{0,9}},168},
2126 {{{0,8}},4}, {{{0,8}},132}, {{{0,8}},68}, {{{0,9}},232},
2127 {{{80,7}},8}, {{{0,8}},92}, {{{0,8}},28}, {{{0,9}},152},
2128 {{{84,7}},83}, {{{0,8}},124}, {{{0,8}},60}, {{{0,9}},216},
2129 {{{82,7}},23}, {{{0,8}},108}, {{{0,8}},44}, {{{0,9}},184},
2130 {{{0,8}},12}, {{{0,8}},140}, {{{0,8}},76}, {{{0,9}},248},
2131 {{{80,7}},3}, {{{0,8}},82}, {{{0,8}},18}, {{{85,8}},163},
2132 {{{83,7}},35}, {{{0,8}},114}, {{{0,8}},50}, {{{0,9}},196},
2133 {{{81,7}},11}, {{{0,8}},98}, {{{0,8}},34}, {{{0,9}},164},
2134 {{{0,8}},2}, {{{0,8}},130}, {{{0,8}},66}, {{{0,9}},228},
2135 {{{80,7}},7}, {{{0,8}},90}, {{{0,8}},26}, {{{0,9}},148},
2136 {{{84,7}},67}, {{{0,8}},122}, {{{0,8}},58}, {{{0,9}},212},
2137 {{{82,7}},19}, {{{0,8}},106}, {{{0,8}},42}, {{{0,9}},180},
2138 {{{0,8}},10}, {{{0,8}},138}, {{{0,8}},74}, {{{0,9}},244},
2139 {{{80,7}},5}, {{{0,8}},86}, {{{0,8}},22}, {{{192,8}},0},
2140 {{{83,7}},51}, {{{0,8}},118}, {{{0,8}},54}, {{{0,9}},204},
2141 {{{81,7}},15}, {{{0,8}},102}, {{{0,8}},38}, {{{0,9}},172},
2142 {{{0,8}},6}, {{{0,8}},134}, {{{0,8}},70}, {{{0,9}},236},
2143 {{{80,7}},9}, {{{0,8}},94}, {{{0,8}},30}, {{{0,9}},156},
2144 {{{84,7}},99}, {{{0,8}},126}, {{{0,8}},62}, {{{0,9}},220},
2145 {{{82,7}},27}, {{{0,8}},110}, {{{0,8}},46}, {{{0,9}},188},
2146 {{{0,8}},14}, {{{0,8}},142}, {{{0,8}},78}, {{{0,9}},252},
2147 {{{96,7}},256}, {{{0,8}},81}, {{{0,8}},17}, {{{85,8}},131},
2148 {{{82,7}},31}, {{{0,8}},113}, {{{0,8}},49}, {{{0,9}},194},
2149 {{{80,7}},10}, {{{0,8}},97}, {{{0,8}},33}, {{{0,9}},162},
2150 {{{0,8}},1}, {{{0,8}},129}, {{{0,8}},65}, {{{0,9}},226},
2151 {{{80,7}},6}, {{{0,8}},89}, {{{0,8}},25}, {{{0,9}},146},
2152 {{{83,7}},59}, {{{0,8}},121}, {{{0,8}},57}, {{{0,9}},210},
2153 {{{81,7}},17}, {{{0,8}},105}, {{{0,8}},41}, {{{0,9}},178},
2154 {{{0,8}},9}, {{{0,8}},137}, {{{0,8}},73}, {{{0,9}},242},
2155 {{{80,7}},4}, {{{0,8}},85}, {{{0,8}},21}, {{{80,8}},258},
2156 {{{83,7}},43}, {{{0,8}},117}, {{{0,8}},53}, {{{0,9}},202},
2157 {{{81,7}},13}, {{{0,8}},101}, {{{0,8}},37}, {{{0,9}},170},
2158 {{{0,8}},5}, {{{0,8}},133}, {{{0,8}},69}, {{{0,9}},234},
2159 {{{80,7}},8}, {{{0,8}},93}, {{{0,8}},29}, {{{0,9}},154},
2160 {{{84,7}},83}, {{{0,8}},125}, {{{0,8}},61}, {{{0,9}},218},
2161 {{{82,7}},23}, {{{0,8}},109}, {{{0,8}},45}, {{{0,9}},186},
2162 {{{0,8}},13}, {{{0,8}},141}, {{{0,8}},77}, {{{0,9}},250},
2163 {{{80,7}},3}, {{{0,8}},83}, {{{0,8}},19}, {{{85,8}},195},
2164 {{{83,7}},35}, {{{0,8}},115}, {{{0,8}},51}, {{{0,9}},198},
2165 {{{81,7}},11}, {{{0,8}},99}, {{{0,8}},35}, {{{0,9}},166},
2166 {{{0,8}},3}, {{{0,8}},131}, {{{0,8}},67}, {{{0,9}},230},
2167 {{{80,7}},7}, {{{0,8}},91}, {{{0,8}},27}, {{{0,9}},150},
2168 {{{84,7}},67}, {{{0,8}},123}, {{{0,8}},59}, {{{0,9}},214},
2169 {{{82,7}},19}, {{{0,8}},107}, {{{0,8}},43}, {{{0,9}},182},
2170 {{{0,8}},11}, {{{0,8}},139}, {{{0,8}},75}, {{{0,9}},246},
2171 {{{80,7}},5}, {{{0,8}},87}, {{{0,8}},23}, {{{192,8}},0},
2172 {{{83,7}},51}, {{{0,8}},119}, {{{0,8}},55}, {{{0,9}},206},
2173 {{{81,7}},15}, {{{0,8}},103}, {{{0,8}},39}, {{{0,9}},174},
2174 {{{0,8}},7}, {{{0,8}},135}, {{{0,8}},71}, {{{0,9}},238},
2175 {{{80,7}},9}, {{{0,8}},95}, {{{0,8}},31}, {{{0,9}},158},
2176 {{{84,7}},99}, {{{0,8}},127}, {{{0,8}},63}, {{{0,9}},222},
2177 {{{82,7}},27}, {{{0,8}},111}, {{{0,8}},47}, {{{0,9}},190},
2178 {{{0,8}},15}, {{{0,8}},143}, {{{0,8}},79}, {{{0,9}},254},
2179 {{{96,7}},256}, {{{0,8}},80}, {{{0,8}},16}, {{{84,8}},115},
2180 {{{82,7}},31}, {{{0,8}},112}, {{{0,8}},48}, {{{0,9}},193},
2181 {{{80,7}},10}, {{{0,8}},96}, {{{0,8}},32}, {{{0,9}},161},
2182 {{{0,8}},0}, {{{0,8}},128}, {{{0,8}},64}, {{{0,9}},225},
2183 {{{80,7}},6}, {{{0,8}},88}, {{{0,8}},24}, {{{0,9}},145},
2184 {{{83,7}},59}, {{{0,8}},120}, {{{0,8}},56}, {{{0,9}},209},
2185 {{{81,7}},17}, {{{0,8}},104}, {{{0,8}},40}, {{{0,9}},177},
2186 {{{0,8}},8}, {{{0,8}},136}, {{{0,8}},72}, {{{0,9}},241},
2187 {{{80,7}},4}, {{{0,8}},84}, {{{0,8}},20}, {{{85,8}},227},
2188 {{{83,7}},43}, {{{0,8}},116}, {{{0,8}},52}, {{{0,9}},201},
2189 {{{81,7}},13}, {{{0,8}},100}, {{{0,8}},36}, {{{0,9}},169},
2190 {{{0,8}},4}, {{{0,8}},132}, {{{0,8}},68}, {{{0,9}},233},
2191 {{{80,7}},8}, {{{0,8}},92}, {{{0,8}},28}, {{{0,9}},153},
2192 {{{84,7}},83}, {{{0,8}},124}, {{{0,8}},60}, {{{0,9}},217},
2193 {{{82,7}},23}, {{{0,8}},108}, {{{0,8}},44}, {{{0,9}},185},
2194 {{{0,8}},12}, {{{0,8}},140}, {{{0,8}},76}, {{{0,9}},249},
2195 {{{80,7}},3}, {{{0,8}},82}, {{{0,8}},18}, {{{85,8}},163},
2196 {{{83,7}},35}, {{{0,8}},114}, {{{0,8}},50}, {{{0,9}},197},
2197 {{{81,7}},11}, {{{0,8}},98}, {{{0,8}},34}, {{{0,9}},165},
2198 {{{0,8}},2}, {{{0,8}},130}, {{{0,8}},66}, {{{0,9}},229},
2199 {{{80,7}},7}, {{{0,8}},90}, {{{0,8}},26}, {{{0,9}},149},
2200 {{{84,7}},67}, {{{0,8}},122}, {{{0,8}},58}, {{{0,9}},213},
2201 {{{82,7}},19}, {{{0,8}},106}, {{{0,8}},42}, {{{0,9}},181},
2202 {{{0,8}},10}, {{{0,8}},138}, {{{0,8}},74}, {{{0,9}},245},
2203 {{{80,7}},5}, {{{0,8}},86}, {{{0,8}},22}, {{{192,8}},0},
2204 {{{83,7}},51}, {{{0,8}},118}, {{{0,8}},54}, {{{0,9}},205},
2205 {{{81,7}},15}, {{{0,8}},102}, {{{0,8}},38}, {{{0,9}},173},
2206 {{{0,8}},6}, {{{0,8}},134}, {{{0,8}},70}, {{{0,9}},237},
2207 {{{80,7}},9}, {{{0,8}},94}, {{{0,8}},30}, {{{0,9}},157},
2208 {{{84,7}},99}, {{{0,8}},126}, {{{0,8}},62}, {{{0,9}},221},
2209 {{{82,7}},27}, {{{0,8}},110}, {{{0,8}},46}, {{{0,9}},189},
2210 {{{0,8}},14}, {{{0,8}},142}, {{{0,8}},78}, {{{0,9}},253},
2211 {{{96,7}},256}, {{{0,8}},81}, {{{0,8}},17}, {{{85,8}},131},
2212 {{{82,7}},31}, {{{0,8}},113}, {{{0,8}},49}, {{{0,9}},195},
2213 {{{80,7}},10}, {{{0,8}},97}, {{{0,8}},33}, {{{0,9}},163},
2214 {{{0,8}},1}, {{{0,8}},129}, {{{0,8}},65}, {{{0,9}},227},
2215 {{{80,7}},6}, {{{0,8}},89}, {{{0,8}},25}, {{{0,9}},147},
2216 {{{83,7}},59}, {{{0,8}},121}, {{{0,8}},57}, {{{0,9}},211},
2217 {{{81,7}},17}, {{{0,8}},105}, {{{0,8}},41}, {{{0,9}},179},
2218 {{{0,8}},9}, {{{0,8}},137}, {{{0,8}},73}, {{{0,9}},243},
2219 {{{80,7}},4}, {{{0,8}},85}, {{{0,8}},21}, {{{80,8}},258},
2220 {{{83,7}},43}, {{{0,8}},117}, {{{0,8}},53}, {{{0,9}},203},
2221 {{{81,7}},13}, {{{0,8}},101}, {{{0,8}},37}, {{{0,9}},171},
2222 {{{0,8}},5}, {{{0,8}},133}, {{{0,8}},69}, {{{0,9}},235},
2223 {{{80,7}},8}, {{{0,8}},93}, {{{0,8}},29}, {{{0,9}},155},
2224 {{{84,7}},83}, {{{0,8}},125}, {{{0,8}},61}, {{{0,9}},219},
2225 {{{82,7}},23}, {{{0,8}},109}, {{{0,8}},45}, {{{0,9}},187},
2226 {{{0,8}},13}, {{{0,8}},141}, {{{0,8}},77}, {{{0,9}},251},
2227 {{{80,7}},3}, {{{0,8}},83}, {{{0,8}},19}, {{{85,8}},195},
2228 {{{83,7}},35}, {{{0,8}},115}, {{{0,8}},51}, {{{0,9}},199},
2229 {{{81,7}},11}, {{{0,8}},99}, {{{0,8}},35}, {{{0,9}},167},
2230 {{{0,8}},3}, {{{0,8}},131}, {{{0,8}},67}, {{{0,9}},231},
2231 {{{80,7}},7}, {{{0,8}},91}, {{{0,8}},27}, {{{0,9}},151},
2232 {{{84,7}},67}, {{{0,8}},123}, {{{0,8}},59}, {{{0,9}},215},
2233 {{{82,7}},19}, {{{0,8}},107}, {{{0,8}},43}, {{{0,9}},183},
2234 {{{0,8}},11}, {{{0,8}},139}, {{{0,8}},75}, {{{0,9}},247},
2235 {{{80,7}},5}, {{{0,8}},87}, {{{0,8}},23}, {{{192,8}},0},
2236 {{{83,7}},51}, {{{0,8}},119}, {{{0,8}},55}, {{{0,9}},207},
2237 {{{81,7}},15}, {{{0,8}},103}, {{{0,8}},39}, {{{0,9}},175},
2238 {{{0,8}},7}, {{{0,8}},135}, {{{0,8}},71}, {{{0,9}},239},
2239 {{{80,7}},9}, {{{0,8}},95}, {{{0,8}},31}, {{{0,9}},159},
2240 {{{84,7}},99}, {{{0,8}},127}, {{{0,8}},63}, {{{0,9}},223},
2241 {{{82,7}},27}, {{{0,8}},111}, {{{0,8}},47}, {{{0,9}},191},
2242 {{{0,8}},15}, {{{0,8}},143}, {{{0,8}},79}, {{{0,9}},255}
2244 static inflate_huft fixed_td[] = {
2245 {{{80,5}},1}, {{{87,5}},257}, {{{83,5}},17}, {{{91,5}},4097},
2246 {{{81,5}},5}, {{{89,5}},1025}, {{{85,5}},65}, {{{93,5}},16385},
2247 {{{80,5}},3}, {{{88,5}},513}, {{{84,5}},33}, {{{92,5}},8193},
2248 {{{82,5}},9}, {{{90,5}},2049}, {{{86,5}},129}, {{{192,5}},24577},
2249 {{{80,5}},2}, {{{87,5}},385}, {{{83,5}},25}, {{{91,5}},6145},
2250 {{{81,5}},7}, {{{89,5}},1537}, {{{85,5}},97}, {{{93,5}},24577},
2251 {{{80,5}},4}, {{{88,5}},769}, {{{84,5}},49}, {{{92,5}},12289},
2252 {{{82,5}},13}, {{{90,5}},3073}, {{{86,5}},193}, {{{192,5}},24577}
2255 /* infcodes.c -- process literals and length/distance pairs
2256 * Copyright (C) 1995-1998 Mark Adler
2257 * For conditions of distribution and use, see copyright notice in zlib.h
2260 /* simplify the use of the inflate_huft type with some defines */
2261 #define exop word.what.Exop
2262 #define bits word.what.Bits
2264 typedef enum { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
2265 START, /* x: set up for LEN */
2266 LEN, /* i: get length/literal/eob next */
2267 LENEXT, /* i: getting length extra (have base) */
2268 DIST, /* i: get distance next */
2269 DISTEXT, /* i: getting distance extra */
2270 COPY, /* o: copying bytes in window, waiting for space */
2271 LIT, /* o: got literal, waiting for output space */
2272 WASH, /* o: got eob, possibly still output waiting */
2273 END, /* x: got eob and all data flushed */
2274 BADCODE} /* x: got error */
2277 /* inflate codes private state */
2278 struct inflate_codes_state {
2281 inflate_codes_mode mode; /* current inflate_codes mode */
2283 /* mode dependent information */
2287 inflate_huft *tree; /* pointer into tree */
2288 uInt need; /* bits needed */
2289 } code; /* if LEN or DIST, where in tree */
2290 uInt lit; /* if LIT, literal */
2292 uInt get; /* bits to get for extra */
2293 uInt dist; /* distance back to copy from */
2294 } copy; /* if EXT or COPY, where and how much */
2295 } sub; /* submode */
2297 /* mode independent information */
2298 Byte lbits; /* ltree bits decoded per branch */
2299 Byte dbits; /* dtree bits decoder per branch */
2300 inflate_huft *ltree; /* literal/length/eob tree */
2301 inflate_huft *dtree; /* distance tree */
2305 /* infblock.h -- header to use infblock.c
2306 * Copyright (C) 1995-1998 Mark Adler
2307 * For conditions of distribution and use, see copyright notice in zlib.h
2310 /* WARNING: this file should *not* be used by applications. It is
2311 part of the implementation of the compression library and is
2312 subject to change. Applications should only use zlib.h.
2315 extern inflate_blocks_statef * inflate_blocks_new OF((
2317 check_func c, /* check function */
2318 uInt w)); /* window size */
2320 extern int inflate_blocks OF((
2321 inflate_blocks_statef *,
2323 int)); /* initial return code */
2325 extern void inflate_blocks_reset OF((
2326 inflate_blocks_statef *,
2328 uLong *)); /* check value on output */
2330 extern int inflate_blocks_free OF((
2331 inflate_blocks_statef *,
2334 extern void inflate_set_dictionary OF((
2335 inflate_blocks_statef *s,
2336 const Byte *d, /* dictionary */
2337 uInt n)); /* dictionary length */
2339 extern int inflate_blocks_sync_point OF((
2340 inflate_blocks_statef *s));
2343 imMETHOD, /* waiting for method byte */
2344 imFLAG, /* waiting for flag byte */
2345 imDICT4, /* four dictionary check bytes to go */
2346 imDICT3, /* three dictionary check bytes to go */
2347 imDICT2, /* two dictionary check bytes to go */
2348 imDICT1, /* one dictionary check byte to go */
2349 imDICT0, /* waiting for inflateSetDictionary */
2350 imBLOCKS, /* decompressing blocks */
2351 imCHECK4, /* four check bytes to go */
2352 imCHECK3, /* three check bytes to go */
2353 imCHECK2, /* two check bytes to go */
2354 imCHECK1, /* one check byte to go */
2355 imDONE, /* finished check, done */
2356 imBAD} /* got an error--stay here */
2359 /* inflate private state */
2360 struct internal_state {
2363 inflate_mode mode; /* current inflate mode */
2365 /* mode dependent information */
2367 uInt method; /* if FLAGS, method byte */
2369 uLong was; /* computed check value */
2370 uLong need; /* stream check value */
2371 } check; /* if CHECK, check values to compare */
2372 uInt marker; /* if BAD, inflateSync's marker bytes count */
2373 } sub; /* submode */
2375 /* mode independent information */
2376 int nowrap; /* flag for no wrapper */
2377 uInt wbits; /* log2(window size) (8..15, defaults to 15) */
2378 inflate_blocks_statef
2379 *blocks; /* current inflate_blocks state */