├── README.md └── Source ├── Cipher ├── cCipher.inc ├── cCipher.pas ├── cCipherAES.pas ├── cCipherDES.pas ├── cCipherRC2.pas ├── cCipherRC4.pas ├── cCipherRSA.pas ├── cCipherRandom.pas └── cCipherUtils.pas ├── DNS ├── cDNS.inc ├── cDNSServer.pas └── cDNSUtils.pas ├── HTTP ├── cHTTP.inc ├── cHTTPClient.pas ├── cHTTPServer.pas ├── cHTTPTests.pas └── cHTTPUtils.pas ├── Sockets ├── cSocket.pas ├── cSocketLib.pas ├── cUnixSock.pas └── cWinSock.pas ├── TCP ├── cTCP.inc ├── cTCPBuffer.pas ├── cTCPClient.pas ├── cTCPConnection.pas ├── cTCPServer.pas └── cTCPTests.pas ├── Utils ├── cBits32.pas ├── cDataStructs.pas ├── cDateTime.pas ├── cDecimal.pas ├── cDynArrays.pas ├── cFileUtils.pas ├── cHash.pas ├── cHugeInt.pas ├── cInteger.pas ├── cJSON.pas ├── cRandom.pas ├── cStreams.pas ├── cStrings.pas ├── cUnicodeCodecs.pas ├── cUnicodeReader.pas ├── cUtils.pas └── cVariant.pas ├── ZLib ├── cZLib.pas ├── paszlib │ ├── Adler.pas │ ├── Crc.pas │ ├── InfBlock.pas │ ├── InfCodes.pas │ ├── InfFast.pas │ ├── InfTrees.pas │ ├── README.txt │ ├── ZUtil.pas │ ├── dzlib.pas │ ├── dzlib.txt │ ├── example.pas │ ├── gZlib.pas │ ├── gzIO.pas │ ├── infutil.pas │ ├── minigzip.pas │ ├── minizip │ │ ├── MiniUnz.pas │ │ ├── MiniZip.pas │ │ ├── UnZip.pas │ │ ├── Zip.pas │ │ └── ZipUtil.pas │ ├── trees.pas │ ├── zCompres.pas │ ├── zDeflate.pas │ ├── zInflate.pas │ ├── zUnCompr.pas │ └── zconf.inc ├── zlib123 │ ├── Compile.bat │ ├── adler32.c │ ├── adler32.obj │ ├── compress.c │ ├── compress.obj │ ├── crc32.c │ ├── crc32.h │ ├── crc32.obj │ ├── deflate.c │ ├── deflate.h │ ├── deflate.obj │ ├── example.c │ ├── gzio.c │ ├── gzio.obj │ ├── infback.c │ ├── infback.obj │ ├── inffast.c │ ├── inffast.h │ ├── inffast.obj │ ├── inffixed.h │ ├── inflate.c │ ├── inflate.h │ ├── inflate.obj │ ├── inftrees.c │ ├── inftrees.h │ ├── inftrees.obj │ ├── minigzip.c │ ├── trees.c │ ├── trees.h │ ├── trees.obj │ ├── uncompr.c │ ├── uncompr.obj │ ├── zconf.h │ ├── zconf.in.h │ ├── zlib.h │ ├── zutil.c │ ├── zutil.h │ └── zutil.obj └── zlib127 │ ├── ZLibEx.inc │ ├── ZLibEx.pas │ ├── ZLibExApi.pas │ ├── ZLibExGZ.pas │ ├── readme.txt │ ├── win32 │ ├── adler32.obj │ ├── compress.obj │ ├── crc32.obj │ ├── deflate.obj │ ├── infback.obj │ ├── inffast.obj │ ├── inflate.obj │ ├── inftrees.obj │ └── trees.obj │ ├── win64 │ ├── adler32.obj │ ├── compress.obj │ ├── crc32.obj │ ├── deflate.obj │ ├── infback.obj │ ├── inffast.obj │ ├── inflate.obj │ ├── inftrees.obj │ └── trees.obj │ └── zlib │ ├── adler32.c │ ├── compress.c │ ├── crc32.c │ ├── crc32.h │ ├── deflate.c │ ├── deflate.h │ ├── infback.c │ ├── inffast.c │ ├── inffast.h │ ├── inffixed.h │ ├── inflate.c │ ├── inflate.h │ ├── inftrees.c │ ├── inftrees.h │ ├── trees.c │ ├── trees.h │ ├── zconf.h │ ├── zlib.h │ ├── zutil.c │ └── zutil.h └── cFundamentals.inc /README.md: -------------------------------------------------------------------------------- 1 | # Fundamentals 4 Library 2 | 3 | See here for Fundamentals 5: https://github.com/fundamentalslib/fundamentals5 4 | 5 | A code library for use with FreePascal/Delphi. 6 | 7 | Includes: 8 | 9 | * String, DateTime and dynamic array routines 10 | * Unicode routines 11 | * Hash (e.g. SHA256, SHA512, SHA1, SHA256, MD5) 12 | * Integer (e.g. Word128, Word256, Int128, Int256) 13 | * Huge Word, Huge Integer 14 | * Decimal (Decimal32, Decimal64, Decimal128, HugeDecimal and signed decimals) 15 | * JSON 16 | * Random number generators 17 | * Cipher (e.g. AES, DES, RC2, RC4, RSA) 18 | * Socket library (cross platform - Windows and Linux) 19 | * TCP Client 20 | * TCP Server 21 | * HTTP Client 22 | * HTTP Server 23 | -------------------------------------------------------------------------------- /Source/Cipher/cCipher.inc: -------------------------------------------------------------------------------- 1 | {******************************************************************************} 2 | { } 3 | { Library: Fundamentals 4.00 } 4 | { File name: cCipher.inc } 5 | { Description: Cipher library defines } 6 | { } 7 | {******************************************************************************} 8 | 9 | {.DEFINE DEBUG} 10 | {.DEFINE SELFTEST} 11 | 12 | {$INCLUDE ..\cFundamentals.inc} 13 | 14 | {$IFDEF DEBUG} 15 | {$IFDEF SELFTEST} 16 | {$DEFINE CIPHER_SELFTEST} 17 | {$ENDIF} 18 | {$IFDEF PROFILE} 19 | {$DEFINE CIPHER_PROFILE} 20 | {$ENDIF} 21 | {$ENDIF} 22 | 23 | -------------------------------------------------------------------------------- /Source/Cipher/cCipherRC4.pas: -------------------------------------------------------------------------------- 1 | {******************************************************************************} 2 | { } 3 | { Library: Fundamentals 4.00 } 4 | { File name: cCipherRC4.pas } 5 | { File version: 4.06 } 6 | { Description: RC4 cipher routines } 7 | { } 8 | { Copyright: Copyright (c) 2007-2013, David J Butler } 9 | { All rights reserved. } 10 | { This file is licensed under the BSD License. } 11 | { See http://www.opensource.org/licenses/bsd-license.php } 12 | { Redistribution and use in source and binary forms, with } 13 | { or without modification, are permitted provided that } 14 | { the following conditions are met: } 15 | { Redistributions of source code must retain the above } 16 | { copyright notice, this list of conditions and the } 17 | { following disclaimer. } 18 | { THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND } 19 | { CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED } 20 | { WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED } 21 | { WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A } 22 | { PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL } 23 | { THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, } 24 | { INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR } 25 | { CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, } 26 | { PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF } 27 | { USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) } 28 | { HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER } 29 | { IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING } 30 | { NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE } 31 | { USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE } 32 | { POSSIBILITY OF SUCH DAMAGE. } 33 | { } 34 | { Home page: http://fundementals.sourceforge.net } 35 | { Forum: http://sourceforge.net/forum/forum.php?forum_id=2117 } 36 | { E-mail: fundamentalslib at gmail.com } 37 | { Source: https://github.com/fundamentalslib } 38 | { } 39 | { References: } 40 | { } 41 | { * www.mozilla.org/projects/security/pki/nss/ } 42 | { draft-kaukonen-cipher-arcfour-03.txt } 43 | { } 44 | { Revision history: } 45 | { } 46 | { 2007/01/05 4.01 Initial version. } 47 | { } 48 | {******************************************************************************} 49 | 50 | {$INCLUDE cCipher.inc} 51 | 52 | unit cCipherRC4; 53 | 54 | interface 55 | 56 | 57 | 58 | { } 59 | { RC4 } 60 | { Also known as Arcfour. } 61 | { } 62 | type 63 | TRC4SBox = array[Byte] of Byte; 64 | TRC4Context = packed record 65 | S : TRC4SBox; 66 | SI : Byte; 67 | SJ : Byte; 68 | end; 69 | PRC4Context = ^TRC4Context; 70 | 71 | procedure RC4Init(const Key; const KeySize: Integer; var Context: TRC4Context); 72 | procedure RC4Buffer(var Context: TRC4Context; var Buffer; const BufferSize: Integer); 73 | 74 | 75 | 76 | implementation 77 | 78 | uses 79 | { Cipher } 80 | cCipherUtils; 81 | 82 | 83 | 84 | { } 85 | { Utilities } 86 | { } 87 | 88 | {$IFDEF DELPHI5} 89 | type 90 | PByte = ^Byte; 91 | {$ENDIF} 92 | 93 | 94 | 95 | { } 96 | { RC4 } 97 | { } 98 | procedure RC4Init(const Key; const KeySize: Integer; var Context: TRC4Context); 99 | type 100 | TRC4KeyBuffer = array[Byte] of Byte; 101 | PRC4KeyBuffer = ^TRC4KeyBuffer; 102 | var I, J, T : Byte; 103 | K : PRC4KeyBuffer; 104 | begin 105 | // Validate parameters 106 | if KeySize > 256 then 107 | raise ECipher.Create(CipherError_InvalidKeySize, 'Maximum RC4 key length is 256'); 108 | if KeySize < 1 then 109 | raise ECipher.Create(CipherError_InvalidKeySize, 'Minimum RC4 key length is 1'); 110 | // Prepare RC4 context 111 | with Context do 112 | begin 113 | for I := 0 to 255 do 114 | S[I] := I; 115 | K := @Key; 116 | J := 0; 117 | for I := 0 to 255 do 118 | begin 119 | J := Byte(J + S[I] + K^[I mod KeySize]); 120 | T := S[I]; 121 | S[I] := S[J]; 122 | S[J] := T; 123 | end; 124 | SI := 0; 125 | SJ := 0; 126 | end; 127 | end; 128 | 129 | procedure RC4Buffer(var Context: TRC4Context; var Buffer; const BufferSize: Integer); 130 | var T : Byte; 131 | F : Integer; 132 | P : PByte; 133 | begin 134 | P := @Buffer; 135 | with Context do 136 | for F := 0 to BufferSize - 1 do 137 | begin 138 | SI := Byte(SI + 1); 139 | SJ := Byte(SJ + S[SI]); 140 | T := S[SI]; 141 | S[SI] := S[SJ]; 142 | S[SJ] := T; 143 | T := Byte(S[SI] + S[SJ]); 144 | T := S[T]; 145 | P^ := P^ xor T; 146 | Inc(P); 147 | end; 148 | end; 149 | 150 | 151 | 152 | end. 153 | -------------------------------------------------------------------------------- /Source/Cipher/cCipherRSA.pas: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/Cipher/cCipherRSA.pas -------------------------------------------------------------------------------- /Source/Cipher/cCipherRandom.pas: -------------------------------------------------------------------------------- 1 | {******************************************************************************} 2 | { } 3 | { Library: Fundamentals 4.00 } 4 | { File name: cCipherRandom.pas } 5 | { File version: 4.03 } 6 | { Description: Cipher random } 7 | { } 8 | { Copyright: Copyright (c) 2010-2015, David J Butler } 9 | { All rights reserved. } 10 | { This file is licensed under the BSD License. } 11 | { See http://www.opensource.org/licenses/bsd-license.php } 12 | { Redistribution and use in source and binary forms, with } 13 | { or without modification, are permitted provided that } 14 | { the following conditions are met: } 15 | { Redistributions of source code must retain the above } 16 | { copyright notice, this list of conditions and the } 17 | { following disclaimer. } 18 | { THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND } 19 | { CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED } 20 | { WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED } 21 | { WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A } 22 | { PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL } 23 | { THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, } 24 | { INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR } 25 | { CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, } 26 | { PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF } 27 | { USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) } 28 | { HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER } 29 | { IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING } 30 | { NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE } 31 | { USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE } 32 | { POSSIBILITY OF SUCH DAMAGE. } 33 | { } 34 | { Home page: http://fundementals.sourceforge.net } 35 | { Forum: http://sourceforge.net/forum/forum.php?forum_id=2117 } 36 | { E-mail: fundamentalslib at gmail.com } 37 | { Source: https://github.com/fundamentalslib } 38 | { } 39 | { Revision history: } 40 | { } 41 | { 2010/12/17 4.01 Initial version } 42 | { 2013/09/25 4.02 UnicodeString version } 43 | { 2015/05/05 4.03 Multiple PRNGs and PRSS and SHA512 hash in random block } 44 | { generator. } 45 | { } 46 | {******************************************************************************} 47 | 48 | {$INCLUDE cCipher.inc} 49 | 50 | unit cCipherRandom; 51 | 52 | interface 53 | 54 | uses 55 | { Fundamentals } 56 | cUtils; 57 | 58 | 59 | 60 | procedure SecureRandomBuf(var Buf; const Size: Integer); 61 | 62 | function SecureRandomStrA(const Size: Integer): RawByteString; 63 | 64 | function SecureRandomHexStr(const Digits: Integer; const UpperCase: Boolean = True): String; 65 | function SecureRandomHexStrA(const Digits: Integer; const UpperCase: Boolean = True): RawByteString; 66 | function SecureRandomHexStrU(const Digits: Integer; const UpperCase: Boolean = True): UnicodeString; 67 | 68 | function SecureRandomLongWord: LongWord; 69 | 70 | 71 | 72 | implementation 73 | 74 | uses 75 | { Fundamentals } 76 | cRandom, 77 | cHash; 78 | 79 | 80 | 81 | const 82 | SecureRandomBlockBits = 128; 83 | SecureRandomBlockSize = SecureRandomBlockBits div 8; // 16 bytes 84 | 85 | type 86 | TSecureRandomBlock = array[0..SecureRandomBlockSize - 1] of Byte; 87 | PSecureRandomBlock = ^TSecureRandomBlock; 88 | 89 | // produces a block of SecureRandomBlockSize bytes of secure random material 90 | procedure SecureRandomBlockGenerator(var Block: TSecureRandomBlock); 91 | const 92 | RandomSeedDataLen = 512 div 32; 93 | var I : Integer; 94 | R512 : array[0..RandomSeedDataLen - 1] of LongWord; 95 | H512 : T512BitDigest; 96 | H256 : T256BitDigest; 97 | H128 : T128BitDigest; 98 | begin 99 | try 100 | // initialise 512 bits with multiple Pseudo Random Numbers Generators (PRNG) 101 | // and Pseudo Random System State (PRSS) 102 | for I := 0 to RandomSeedDataLen - 1 do 103 | R512[I] := RandomUniform32; 104 | R512[0] := R512[0] xor RandomSeed32; 105 | for I := 0 to RandomSeedDataLen - 1 do 106 | R512[I] := R512[I] xor urnRandom32; 107 | // hash 512 bits using SHA512 108 | H512 := CalcSHA512(R512, SizeOf(R512)); 109 | // hash 512 bits using SHA256 110 | H256 := CalcSHA256(H512, SizeOf(T512BitDigest)); 111 | // hash 256 bits using MD5 112 | H128 := CalcMD5(H256, SizeOf(T256BitDigest)); 113 | // result is 128 bits of random data 114 | Assert(SizeOf(H128) >= SecureRandomBlockSize); 115 | Move(H128, Block, SecureRandomBlockSize); 116 | finally 117 | SecureClear(H128, SizeOf(T128BitDigest)); 118 | SecureClear(H256, SizeOf(T256BitDigest)); 119 | SecureClear(H512, SizeOf(T512BitDigest)); 120 | SecureClear(R512, SizeOf(R512)); 121 | end; 122 | end; 123 | 124 | procedure SecureRandomBuf(var Buf; const Size: Integer); 125 | var P : PSecureRandomBlock; 126 | L : Integer; 127 | B : TSecureRandomBlock; 128 | begin 129 | P := @Buf; 130 | L := Size; 131 | while L >= SecureRandomBlockSize do 132 | begin 133 | SecureRandomBlockGenerator(P^); 134 | Inc(P); 135 | Dec(L, SecureRandomBlockSize); 136 | end; 137 | if L > 0 then 138 | begin 139 | SecureRandomBlockGenerator(B); 140 | Move(B, P^, L); 141 | SecureClear(B, SecureRandomBlockSize); 142 | end; 143 | end; 144 | 145 | function SecureRandomStrA(const Size: Integer): RawByteString; 146 | begin 147 | SetLength(Result, Size); 148 | if Size <= 0 then 149 | exit; 150 | SecureRandomBuf(Result[1], Size); 151 | end; 152 | 153 | function SecureRandomHexStr(const Digits: Integer; const UpperCase: Boolean = True): String; 154 | var B : TSecureRandomBlock; 155 | S, T : String; 156 | L, N : Integer; 157 | P : PLongWord; 158 | Q : PChar; 159 | begin 160 | if Digits <= 0 then 161 | begin 162 | Result := ''; 163 | exit; 164 | end; 165 | SetLength(S, Digits); 166 | Q := PChar(S); 167 | L := Digits; 168 | while L >= 8 do 169 | begin 170 | SecureRandomBlockGenerator(B); 171 | P := @B; 172 | N := SecureRandomBlockSize div 4; 173 | while (L >= 8) and (N > 0) do 174 | begin 175 | T := LongWordToHex(P^, 8, UpperCase); 176 | Move(PChar(T)^, Q^, 8 * SizeOf(Char)); 177 | SecureClearStr(T); 178 | Inc(Q, 8); 179 | Dec(N); 180 | Inc(P); 181 | Dec(L, 8); 182 | end; 183 | end; 184 | if L > 0 then 185 | begin 186 | SecureRandomBlockGenerator(B); 187 | P := @B; 188 | T := LongWordToHex(P^, L, UpperCase); 189 | Move(PChar(T)^, Q^, L * SizeOf(Char)); 190 | SecureClearStr(T); 191 | end; 192 | SecureClear(B, SecureRandomBlockSize); 193 | Result := S; 194 | end; 195 | 196 | function SecureRandomHexStrA(const Digits: Integer; const UpperCase: Boolean): RawByteString; 197 | var B : TSecureRandomBlock; 198 | S, T : RawByteString; 199 | L, N : Integer; 200 | P : PLongWord; 201 | Q : PAnsiChar; 202 | begin 203 | if Digits <= 0 then 204 | begin 205 | Result := ''; 206 | exit; 207 | end; 208 | SetLength(S, Digits); 209 | Q := PAnsiChar(S); 210 | L := Digits; 211 | while L >= 8 do 212 | begin 213 | SecureRandomBlockGenerator(B); 214 | P := @B; 215 | N := SecureRandomBlockSize div 4; 216 | while (L >= 8) and (N > 0) do 217 | begin 218 | T := LongWordToHexA(P^, 8, UpperCase); 219 | Move(PAnsiChar(T)^, Q^, 8); 220 | SecureClearStrA(T); 221 | Inc(Q, 8); 222 | Dec(N); 223 | Inc(P); 224 | Dec(L, 8); 225 | end; 226 | end; 227 | if L > 0 then 228 | begin 229 | SecureRandomBlockGenerator(B); 230 | P := @B; 231 | T := LongWordToHexA(P^, L, UpperCase); 232 | Move(PAnsiChar(T)^, Q^, L); 233 | SecureClearStrA(T); 234 | end; 235 | SecureClear(B, SecureRandomBlockSize); 236 | Result := S; 237 | end; 238 | 239 | function SecureRandomHexStrU(const Digits: Integer; const UpperCase: Boolean): UnicodeString; 240 | var B : TSecureRandomBlock; 241 | S, T : UnicodeString; 242 | L, N : Integer; 243 | P : PLongWord; 244 | Q : PWideChar; 245 | begin 246 | if Digits <= 0 then 247 | begin 248 | Result := ''; 249 | exit; 250 | end; 251 | SetLength(S, Digits); 252 | Q := PWideChar(S); 253 | L := Digits; 254 | while L >= 8 do 255 | begin 256 | SecureRandomBlockGenerator(B); 257 | P := @B; 258 | N := SecureRandomBlockSize div 4; 259 | while (L >= 8) and (N > 0) do 260 | begin 261 | T := LongWordToHexU(P^, 8, UpperCase); 262 | Move(PWideChar(T)^, Q^, 8 * SizeOf(WideChar)); 263 | SecureClear(T[1], 8 * SizeOf(WideChar)); 264 | Inc(Q, 8); 265 | Dec(N); 266 | Inc(P); 267 | Dec(L, 8); 268 | end; 269 | end; 270 | if L > 0 then 271 | begin 272 | SecureRandomBlockGenerator(B); 273 | P := @B; 274 | T := LongWordToHexU(P^, L, UpperCase); 275 | Move(PWideChar(T)^, Q^, L * SizeOf(WideChar)); 276 | SecureClear(T[1], 8 * SizeOf(WideChar)); 277 | end; 278 | SecureClear(B, SecureRandomBlockSize); 279 | Result := S; 280 | end; 281 | 282 | function SecureRandomLongWord: LongWord; 283 | var L : LongWord; 284 | begin 285 | SecureRandomBuf(L, SizeOf(LongWord)); 286 | Result := L; 287 | SecureClear(L, SizeOf(LongWord)); 288 | end; 289 | 290 | 291 | 292 | end. 293 | 294 | -------------------------------------------------------------------------------- /Source/Cipher/cCipherUtils.pas: -------------------------------------------------------------------------------- 1 | {******************************************************************************} 2 | { } 3 | { Library: Fundamentals 4.00 } 4 | { File name: cCipherUtils.pas } 5 | { File version: 4.01 } 6 | { Description: Cipher library } 7 | { } 8 | { Copyright: Copyright (c) 2007-2013, David J Butler } 9 | { All rights reserved. } 10 | { This file is licensed under the BSD License. } 11 | { See http://www.opensource.org/licenses/bsd-license.php } 12 | { Redistribution and use in source and binary forms, with } 13 | { or without modification, are permitted provided that } 14 | { the following conditions are met: } 15 | { Redistributions of source code must retain the above } 16 | { copyright notice, this list of conditions and the } 17 | { following disclaimer. } 18 | { THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND } 19 | { CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED } 20 | { WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED } 21 | { WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A } 22 | { PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL } 23 | { THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, } 24 | { INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR } 25 | { CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, } 26 | { PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF } 27 | { USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) } 28 | { HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER } 29 | { IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING } 30 | { NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE } 31 | { USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE } 32 | { POSSIBILITY OF SUCH DAMAGE. } 33 | { } 34 | { Home page: http://fundementals.sourceforge.net } 35 | { Forum: http://sourceforge.net/forum/forum.php?forum_id=2117 } 36 | { E-mail: fundamentalslib at gmail.com } 37 | { Source: https://github.com/fundamentalslib } 38 | { } 39 | { Revision history: } 40 | { } 41 | { 2007/01/05 4.01 Initial version } 42 | { } 43 | {******************************************************************************} 44 | 45 | {$INCLUDE cCipher.inc} 46 | 47 | unit cCipherUtils; 48 | 49 | interface 50 | 51 | uses 52 | { System } 53 | SysUtils; 54 | 55 | 56 | 57 | { } 58 | { RawByteString } 59 | { } 60 | {$IFNDEF SupportRawByteString} 61 | type 62 | RawByteString = AnsiString; 63 | PRawByteString = ^RawByteString; 64 | {$ENDIF} 65 | 66 | 67 | 68 | { } 69 | { Cipher errors } 70 | { } 71 | const 72 | CipherError_InvalidCipher = 1; 73 | CipherError_InvalidKeySize = 2; 74 | CipherError_InvalidKeyBits = 3; 75 | CipherError_InvalidCipherMode = 4; 76 | CipherError_InvalidBufferSize = 5; 77 | CipherError_InvalidBuffer = 6; 78 | CipherError_InvalidData = 7; 79 | 80 | type 81 | ECipher = class(Exception) 82 | protected 83 | FErrorCode : Integer; 84 | public 85 | constructor Create(const ErrorCode: Integer; const Msg: String); 86 | property ErrorCode: Integer read FErrorCode; 87 | end; 88 | 89 | 90 | 91 | { } 92 | { Secure clear helper function } 93 | { } 94 | procedure SecureClear(var Buffer; const BufferSize: Integer); 95 | procedure SecureClearStr(var S: RawByteString); 96 | 97 | 98 | 99 | implementation 100 | 101 | 102 | 103 | { } 104 | { Cipher errors } 105 | { } 106 | constructor ECipher.Create(const ErrorCode: Integer; const Msg: String); 107 | begin 108 | FErrorCode := ErrorCode; 109 | inherited Create(Msg); 110 | end; 111 | 112 | 113 | 114 | { } 115 | { Secure clear helper function } 116 | { Securely clears a piece of memory before it is released to help prevent } 117 | { sensitive information from being exposed. } 118 | { } 119 | procedure SecureClear(var Buffer; const BufferSize: Integer); 120 | begin 121 | if BufferSize <= 0 then 122 | exit; 123 | FillChar(Buffer, BufferSize, $00); 124 | end; 125 | 126 | procedure SecureClearStr(var S: RawByteString); 127 | var L : Integer; 128 | begin 129 | L := Length(S); 130 | if L = 0 then 131 | exit; 132 | SecureClear(S[1], L); 133 | S := ''; 134 | end; 135 | 136 | 137 | 138 | end. 139 | 140 | -------------------------------------------------------------------------------- /Source/DNS/cDNS.inc: -------------------------------------------------------------------------------- 1 | {$INCLUDE ..\cFundamentals.inc} 2 | 3 | {$IFDEF DEBUG} 4 | {$DEFINE DNS_DEBUG} 5 | {$ENDIF} 6 | 7 | {$IFDEF DEBUG} 8 | {$IFDEF SELFTEST} 9 | {$DEFINE DNS_SELFTEST} 10 | {$ENDIF} 11 | {$ENDIF} 12 | 13 | -------------------------------------------------------------------------------- /Source/HTTP/cHTTP.inc: -------------------------------------------------------------------------------- 1 | {$INCLUDE ..\TCP\cTCP.inc} 2 | 3 | {$IFDEF DEBUG} 4 | {$DEFINE HTTP_DEBUG} 5 | {$ENDIF} 6 | 7 | {$IFDEF DEBUG} 8 | {$IFDEF SELFTEST} 9 | {$DEFINE HTTP_SELFTEST} 10 | {$ENDIF} 11 | {$ENDIF} 12 | 13 | {.DEFINE HTTP_TLS} 14 | 15 | {.DEFINE HTTPCLIENT_CUSTOM} 16 | {.DEFINE HTTPSERVER_CUSTOM} 17 | 18 | {$IFNDEF TCPCLIENT_TLS} 19 | {$UNDEF HTTP_TLS} 20 | {$ENDIF} 21 | 22 | {$IFNDEF TCPSERVER_TLS} 23 | {$UNDEF HTTP_TLS} 24 | {$ENDIF} 25 | 26 | -------------------------------------------------------------------------------- /Source/HTTP/cHTTPUtils.pas: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/HTTP/cHTTPUtils.pas -------------------------------------------------------------------------------- /Source/Sockets/cUnixSock.pas: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/Sockets/cUnixSock.pas -------------------------------------------------------------------------------- /Source/TCP/cTCP.inc: -------------------------------------------------------------------------------- 1 | {******************************************************************************} 2 | { } 3 | { Library: Fundamentals 4.00 } 4 | { File name: cTCP.inc } 5 | { Description: TCP library conditional defines. } 6 | { } 7 | {******************************************************************************} 8 | 9 | {$INCLUDE ..\cFundamentals.inc} 10 | 11 | {$IFDEF DEBUG} 12 | {$DEFINE TCP_DEBUG} 13 | {$DEFINE TCP_DEBUG_DATA} 14 | {$DEFINE TCP_DEBUG_TLS} 15 | {$DEFINE TCP_DEBUG_SOCKET} 16 | {$DEFINE TCP_DEBUG_CONNECTION} 17 | {$DEFINE TCP_DEBUG_THREAD} 18 | {$ENDIF} 19 | 20 | {.DEFINE TCPCLIENT_SOCKS} 21 | 22 | {.DEFINE TCPCLIENT_TLS} 23 | {.DEFINE TCPSERVER_TLS} 24 | 25 | {$IFDEF DELPHI5_DOWN} 26 | {$UNDEF TCPCLIENT_TLS} 27 | {$UNDEF TCPSERVER_TLS} 28 | {$ENDIF} 29 | 30 | -------------------------------------------------------------------------------- /Source/Utils/cHugeInt.pas: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/Utils/cHugeInt.pas -------------------------------------------------------------------------------- /Source/Utils/cInteger.pas: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/Utils/cInteger.pas -------------------------------------------------------------------------------- /Source/Utils/cUnicodeCodecs.pas: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/Utils/cUnicodeCodecs.pas -------------------------------------------------------------------------------- /Source/ZLib/paszlib/Adler.pas: -------------------------------------------------------------------------------- 1 | Unit Adler; 2 | 3 | { 4 | adler32.c -- compute the Adler-32 checksum of a data stream 5 | Copyright (C) 1995-1998 Mark Adler 6 | 7 | Pascal tranlastion 8 | Copyright (C) 1998 by Jacques Nomssi Nzali 9 | For conditions of distribution and use, see copyright notice in readme.txt 10 | 11 | Modifiied 02/2003 by Sergey A. Galin for Delphi 6+ and Kylix compatibility. 12 | See README in directory above for more information. 13 | } 14 | 15 | interface 16 | 17 | {$I zconf.inc} 18 | 19 | uses 20 | ZUtil; 21 | 22 | function adler32(adler : uLong; buf : pBytef; len : uInt) : uLong; 23 | 24 | { Update a running Adler-32 checksum with the bytes buf[0..len-1] and 25 | return the updated checksum. If buf is NIL, this function returns 26 | the required initial value for the checksum. 27 | An Adler-32 checksum is almost as reliable as a CRC32 but can be computed 28 | much faster. Usage example: 29 | 30 | var 31 | adler : uLong; 32 | begin 33 | adler := adler32(0, Z_NULL, 0); 34 | 35 | while (read_buffer(buffer, length) <> EOF) do 36 | adler := adler32(adler, buffer, length); 37 | 38 | if (adler <> original_adler) then 39 | error(); 40 | end; 41 | } 42 | 43 | implementation 44 | 45 | const 46 | BASE = uLong(65521); { largest prime smaller than 65536 } 47 | {NMAX = 5552; original code with unsigned 32 bit integer } 48 | { NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 } 49 | NMAX = 3854; { code with signed 32 bit integer } 50 | { NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^31-1 } 51 | { The penalty is the time loss in the extra MOD-calls. } 52 | 53 | 54 | { ========================================================================= } 55 | 56 | function adler32(adler : uLong; buf : pBytef; len : uInt) : uLong; 57 | var 58 | s1, s2 : uLong; 59 | k : int; 60 | begin 61 | s1 := adler and $ffff; 62 | s2 := (adler shr 16) and $ffff; 63 | 64 | if not Assigned(buf) then 65 | begin 66 | adler32 := uLong(1); 67 | exit; 68 | end; 69 | 70 | while (len > 0) do 71 | begin 72 | if len < NMAX then 73 | k := len 74 | else 75 | k := NMAX; 76 | Dec(len, k); 77 | { 78 | while (k >= 16) do 79 | begin 80 | DO16(buf); 81 | Inc(buf, 16); 82 | Dec(k, 16); 83 | end; 84 | if (k <> 0) then 85 | repeat 86 | Inc(s1, buf^); 87 | Inc(puf); 88 | Inc(s2, s1); 89 | Dec(k); 90 | until (k = 0); 91 | } 92 | while (k > 0) do 93 | begin 94 | Inc(s1, buf^); 95 | Inc(s2, s1); 96 | Inc(buf); 97 | Dec(k); 98 | end; 99 | s1 := s1 mod BASE; 100 | s2 := s2 mod BASE; 101 | end; 102 | adler32 := (s2 shl 16) or s1; 103 | end; 104 | 105 | { 106 | #define DO1(buf,i) 107 | begin 108 | Inc(s1, buf[i]); 109 | Inc(s2, s1); 110 | end; 111 | #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); 112 | #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); 113 | #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); 114 | #define DO16(buf) DO8(buf,0); DO8(buf,8); 115 | } 116 | end. 117 | 118 | -------------------------------------------------------------------------------- /Source/ZLib/paszlib/Crc.pas: -------------------------------------------------------------------------------- 1 | Unit Crc; 2 | { 3 | crc32.c -- compute the CRC-32 of a data stream 4 | Copyright (C) 1995-1998 Mark Adler 5 | 6 | Pascal tranlastion 7 | Copyright (C) 1998 by Jacques Nomssi Nzali 8 | For conditions of distribution and use, see copyright notice in readme.txt 9 | 10 | Modifiied 02/2003 by Sergey A. Galin for Delphi 6+ and Kylix compatibility. 11 | See README in directory above for more information. 12 | } 13 | 14 | interface 15 | 16 | {$I zconf.inc} 17 | 18 | uses 19 | ZUtil, gZlib; 20 | 21 | 22 | function crc32(crc : uLong; buf : pBytef; len : uInt) : uLong; 23 | 24 | { Update a running crc with the bytes buf[0..len-1] and return the updated 25 | crc. If buf is NULL, this function returns the required initial value 26 | for the crc. Pre- and post-conditioning (one's complement) is performed 27 | within this function so it shouldn't be done by the application. 28 | Usage example: 29 | 30 | var 31 | crc : uLong; 32 | begin 33 | crc := crc32(0, Z_NULL, 0); 34 | 35 | while (read_buffer(buffer, length) <> EOF) do 36 | crc := crc32(crc, buffer, length); 37 | 38 | if (crc <> original_crc) then error(); 39 | end; 40 | 41 | } 42 | 43 | function get_crc_table : puLong; { can be used by asm versions of crc32() } 44 | 45 | 46 | implementation 47 | 48 | {$IFDEF DYNAMIC_CRC_TABLE} 49 | 50 | {local} 51 | const 52 | crc_table_empty : boolean = TRUE; 53 | {local} 54 | var 55 | crc_table : array[0..256-1] of uLongf; 56 | 57 | 58 | { 59 | Generate a table for a byte-wise 32-bit CRC calculation on the polynomial: 60 | 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. 61 | 62 | Polynomials over GF(2) are represented in binary, one bit per coefficient, 63 | with the lowest powers in the most significant bit. Then adding polynomials 64 | is just exclusive-or, and multiplying a polynomial by x is a right shift by 65 | one. If we call the above polynomial p, and represent a byte as the 66 | polynomial q, also with the lowest power in the most significant bit (so the 67 | byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p, 68 | where a mod b means the remainder after dividing a by b. 69 | 70 | This calculation is done using the shift-register method of multiplying and 71 | taking the remainder. The register is initialized to zero, and for each 72 | incoming bit, x^32 is added mod p to the register if the bit is a one (where 73 | x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by 74 | x (which is shifting right by one and adding x^32 mod p if the bit shifted 75 | out is a one). We start with the highest power (least significant bit) of 76 | q and repeat for all eight bits of q. 77 | 78 | The table is simply the CRC of all possible eight bit values. This is all 79 | the information needed to generate CRC's on data a byte at a time for all 80 | combinations of CRC register values and incoming bytes. 81 | } 82 | {local} 83 | procedure make_crc_table; 84 | var 85 | c : uLong; 86 | n,k : int; 87 | poly : uLong; { polynomial exclusive-or pattern } 88 | 89 | const 90 | { terms of polynomial defining this crc (except x^32): } 91 | p: array [0..13] of Byte = (0,1,2,4,5,7,8,10,11,12,16,22,23,26); 92 | 93 | begin 94 | { make exclusive-or pattern from polynomial ($EDB88320) } 95 | poly := Long(0); 96 | for n := 0 to (sizeof(p) div sizeof(Byte))-1 do 97 | poly := poly or (Long(1) shl (31 - p[n])); 98 | 99 | for n := 0 to 255 do 100 | begin 101 | c := uLong(n); 102 | for k := 0 to 7 do 103 | begin 104 | if (c and 1) <> 0 then 105 | c := poly xor (c shr 1) 106 | else 107 | c := (c shr 1); 108 | end; 109 | crc_table[n] := c; 110 | end; 111 | crc_table_empty := FALSE; 112 | end; 113 | 114 | {$ELSE} 115 | 116 | { ======================================================================== 117 | Table of CRC-32's of all single-byte values (made by make_crc_table) } 118 | 119 | {local} 120 | const 121 | crc_table : array[0..255] of uLongf = ( 122 | $00000000, $77073096, $ee0e612c, $990951ba, $076dc419, 123 | $706af48f, $e963a535, $9e6495a3, $0edb8832, $79dcb8a4, 124 | $e0d5e91e, $97d2d988, $09b64c2b, $7eb17cbd, $e7b82d07, 125 | $90bf1d91, $1db71064, $6ab020f2, $f3b97148, $84be41de, 126 | $1adad47d, $6ddde4eb, $f4d4b551, $83d385c7, $136c9856, 127 | $646ba8c0, $fd62f97a, $8a65c9ec, $14015c4f, $63066cd9, 128 | $fa0f3d63, $8d080df5, $3b6e20c8, $4c69105e, $d56041e4, 129 | $a2677172, $3c03e4d1, $4b04d447, $d20d85fd, $a50ab56b, 130 | $35b5a8fa, $42b2986c, $dbbbc9d6, $acbcf940, $32d86ce3, 131 | $45df5c75, $dcd60dcf, $abd13d59, $26d930ac, $51de003a, 132 | $c8d75180, $bfd06116, $21b4f4b5, $56b3c423, $cfba9599, 133 | $b8bda50f, $2802b89e, $5f058808, $c60cd9b2, $b10be924, 134 | $2f6f7c87, $58684c11, $c1611dab, $b6662d3d, $76dc4190, 135 | $01db7106, $98d220bc, $efd5102a, $71b18589, $06b6b51f, 136 | $9fbfe4a5, $e8b8d433, $7807c9a2, $0f00f934, $9609a88e, 137 | $e10e9818, $7f6a0dbb, $086d3d2d, $91646c97, $e6635c01, 138 | $6b6b51f4, $1c6c6162, $856530d8, $f262004e, $6c0695ed, 139 | $1b01a57b, $8208f4c1, $f50fc457, $65b0d9c6, $12b7e950, 140 | $8bbeb8ea, $fcb9887c, $62dd1ddf, $15da2d49, $8cd37cf3, 141 | $fbd44c65, $4db26158, $3ab551ce, $a3bc0074, $d4bb30e2, 142 | $4adfa541, $3dd895d7, $a4d1c46d, $d3d6f4fb, $4369e96a, 143 | $346ed9fc, $ad678846, $da60b8d0, $44042d73, $33031de5, 144 | $aa0a4c5f, $dd0d7cc9, $5005713c, $270241aa, $be0b1010, 145 | $c90c2086, $5768b525, $206f85b3, $b966d409, $ce61e49f, 146 | $5edef90e, $29d9c998, $b0d09822, $c7d7a8b4, $59b33d17, 147 | $2eb40d81, $b7bd5c3b, $c0ba6cad, $edb88320, $9abfb3b6, 148 | $03b6e20c, $74b1d29a, $ead54739, $9dd277af, $04db2615, 149 | $73dc1683, $e3630b12, $94643b84, $0d6d6a3e, $7a6a5aa8, 150 | $e40ecf0b, $9309ff9d, $0a00ae27, $7d079eb1, $f00f9344, 151 | $8708a3d2, $1e01f268, $6906c2fe, $f762575d, $806567cb, 152 | $196c3671, $6e6b06e7, $fed41b76, $89d32be0, $10da7a5a, 153 | $67dd4acc, $f9b9df6f, $8ebeeff9, $17b7be43, $60b08ed5, 154 | $d6d6a3e8, $a1d1937e, $38d8c2c4, $4fdff252, $d1bb67f1, 155 | $a6bc5767, $3fb506dd, $48b2364b, $d80d2bda, $af0a1b4c, 156 | $36034af6, $41047a60, $df60efc3, $a867df55, $316e8eef, 157 | $4669be79, $cb61b38c, $bc66831a, $256fd2a0, $5268e236, 158 | $cc0c7795, $bb0b4703, $220216b9, $5505262f, $c5ba3bbe, 159 | $b2bd0b28, $2bb45a92, $5cb36a04, $c2d7ffa7, $b5d0cf31, 160 | $2cd99e8b, $5bdeae1d, $9b64c2b0, $ec63f226, $756aa39c, 161 | $026d930a, $9c0906a9, $eb0e363f, $72076785, $05005713, 162 | $95bf4a82, $e2b87a14, $7bb12bae, $0cb61b38, $92d28e9b, 163 | $e5d5be0d, $7cdcefb7, $0bdbdf21, $86d3d2d4, $f1d4e242, 164 | $68ddb3f8, $1fda836e, $81be16cd, $f6b9265b, $6fb077e1, 165 | $18b74777, $88085ae6, $ff0f6a70, $66063bca, $11010b5c, 166 | $8f659eff, $f862ae69, $616bffd3, $166ccf45, $a00ae278, 167 | $d70dd2ee, $4e048354, $3903b3c2, $a7672661, $d06016f7, 168 | $4969474d, $3e6e77db, $aed16a4a, $d9d65adc, $40df0b66, 169 | $37d83bf0, $a9bcae53, $debb9ec5, $47b2cf7f, $30b5ffe9, 170 | $bdbdf21c, $cabac28a, $53b39330, $24b4a3a6, $bad03605, 171 | $cdd70693, $54de5729, $23d967bf, $b3667a2e, $c4614ab8, 172 | $5d681b02, $2a6f2b94, $b40bbe37, $c30c8ea1, $5a05df1b, 173 | $2d02ef8d); 174 | 175 | {$ENDIF} 176 | 177 | { ========================================================================= 178 | This function can be used by asm versions of crc32() } 179 | 180 | function get_crc_table : {const} puLong; 181 | begin 182 | {$ifdef DYNAMIC_CRC_TABLE} 183 | if (crc_table_empty) then 184 | make_crc_table; 185 | {$endif} 186 | get_crc_table := {const} puLong(@crc_table); 187 | end; 188 | 189 | { ========================================================================= } 190 | 191 | function crc32 (crc : uLong; buf : pBytef; len : uInt): uLong; 192 | begin 193 | if (buf = Z_NULL) then 194 | crc32 := Long(0) 195 | else 196 | begin 197 | 198 | {$IFDEF DYNAMIC_CRC_TABLE} 199 | if crc_table_empty then 200 | make_crc_table; 201 | {$ENDIF} 202 | 203 | crc := crc xor uLong($ffffffff); 204 | while (len >= 8) do 205 | begin 206 | {DO8(buf)} 207 | crc := crc_table[(int(crc) xor buf^) and $ff] xor (crc shr 8); 208 | inc(buf); 209 | crc := crc_table[(int(crc) xor buf^) and $ff] xor (crc shr 8); 210 | inc(buf); 211 | crc := crc_table[(int(crc) xor buf^) and $ff] xor (crc shr 8); 212 | inc(buf); 213 | crc := crc_table[(int(crc) xor buf^) and $ff] xor (crc shr 8); 214 | inc(buf); 215 | crc := crc_table[(int(crc) xor buf^) and $ff] xor (crc shr 8); 216 | inc(buf); 217 | crc := crc_table[(int(crc) xor buf^) and $ff] xor (crc shr 8); 218 | inc(buf); 219 | crc := crc_table[(int(crc) xor buf^) and $ff] xor (crc shr 8); 220 | inc(buf); 221 | crc := crc_table[(int(crc) xor buf^) and $ff] xor (crc shr 8); 222 | inc(buf); 223 | 224 | Dec(len, 8); 225 | end; 226 | if (len <> 0) then 227 | repeat 228 | {DO1(buf)} 229 | crc := crc_table[(int(crc) xor buf^) and $ff] xor (crc shr 8); 230 | inc(buf); 231 | 232 | Dec(len); 233 | until (len = 0); 234 | crc32 := crc xor uLong($ffffffff); 235 | end; 236 | end; 237 | 238 | 239 | end. -------------------------------------------------------------------------------- /Source/ZLib/paszlib/InfFast.pas: -------------------------------------------------------------------------------- 1 | Unit InfFast; 2 | 3 | { 4 | inffast.h and 5 | inffast.c -- process literals and length/distance pairs fast 6 | Copyright (C) 1995-1998 Mark Adler 7 | 8 | Pascal tranlastion 9 | Copyright (C) 1998 by Jacques Nomssi Nzali 10 | For conditions of distribution and use, see copyright notice in readme.txt 11 | 12 | Modifiied 02/2003 by Sergey A. Galin for Delphi 6+ and Kylix compatibility. 13 | See README in directory above for more information. 14 | } 15 | 16 | 17 | interface 18 | 19 | {$I zconf.inc} 20 | 21 | {.DEFINE INFFAST_DEBUG} 22 | 23 | uses zutil, gzlib; 24 | 25 | function inflate_fast( bl : uInt; 26 | bd : uInt; 27 | tl : pInflate_huft; 28 | td : pInflate_huft; 29 | var s : inflate_blocks_state; 30 | var z : z_stream) : int; 31 | 32 | 33 | implementation 34 | 35 | uses 36 | infutil; 37 | 38 | 39 | { Called with number of bytes left to write in window at least 258 40 | (the maximum string length) and number of input bytes available 41 | at least ten. The ten bytes are six bytes for the longest length/ 42 | distance pair plus four bytes for overloading the bit buffer. } 43 | 44 | function inflate_fast( bl : uInt; 45 | bd : uInt; 46 | tl : pInflate_huft; 47 | td : pInflate_huft; 48 | var s : inflate_blocks_state; 49 | var z : z_stream) : int; 50 | 51 | var 52 | t : pInflate_huft; { temporary pointer } 53 | e : uInt; { extra bits or operation } 54 | b : uLong; { bit buffer } 55 | k : uInt; { bits in bit buffer } 56 | p : pBytef; { input data pointer } 57 | n : uInt; { bytes available there } 58 | q : pBytef; { output window write pointer } 59 | m : uInt; { bytes to end of window or read pointer } 60 | ml : uInt; { mask for literal/length tree } 61 | md : uInt; { mask for distance tree } 62 | c : uInt; { bytes to copy } 63 | d : uInt; { distance back to copy from } 64 | r : pBytef; { copy source pointer } 65 | begin 66 | { load input, output, bit values (macro LOAD) } 67 | p := z.next_in; 68 | n := z.avail_in; 69 | b := s.bitb; 70 | k := s.bitk; 71 | q := s.write; 72 | if ptr2int(q) < ptr2int(s.read) then 73 | m := uInt(ptr2int(s.read)-ptr2int(q)-1) 74 | else 75 | m := uInt(ptr2int(s.zend)-ptr2int(q)); 76 | 77 | { initialize masks } 78 | ml := inflate_mask[bl]; 79 | md := inflate_mask[bd]; 80 | 81 | { do until not enough input or output space for fast loop } 82 | repeat { assume called with (m >= 258) and (n >= 10) } 83 | { get literal/length code } 84 | {GRABBITS(20);} { max bits for literal/length code } 85 | while (k < 20) do 86 | begin 87 | Dec(n); 88 | b := b or (uLong(p^) shl k); 89 | Inc(p); 90 | Inc(k, 8); 91 | end; 92 | 93 | t := @(huft_ptr(tl)^[uInt(b) and ml]); 94 | 95 | e := t^.exop; 96 | if (e = 0) then 97 | begin 98 | {DUMPBITS(t^.bits);} 99 | b := b shr t^.bits; 100 | Dec(k, t^.bits); 101 | {$IFDEF INFFAST_DEBUG} 102 | if (t^.base >= $20) and (t^.base < $7f) then 103 | Tracevv('inflate: * literal '+char(t^.base)) 104 | else 105 | Tracevv('inflate: * literal '+ IntToStr(t^.base)); 106 | {$ENDIF} 107 | q^ := Byte(t^.base); 108 | Inc(q); 109 | Dec(m); 110 | continue; 111 | end; 112 | repeat 113 | {DUMPBITS(t^.bits);} 114 | b := b shr t^.bits; 115 | Dec(k, t^.bits); 116 | 117 | if (e and 16 <> 0) then 118 | begin 119 | { get extra bits for length } 120 | e := e and 15; 121 | c := t^.base + (uInt(b) and inflate_mask[e]); 122 | {DUMPBITS(e);} 123 | b := b shr e; 124 | Dec(k, e); 125 | {$IFDEF INFFAST_DEBUG} 126 | Tracevv('inflate: * length ' + IntToStr(c)); 127 | {$ENDIF} 128 | { decode distance base of block to copy } 129 | {GRABBITS(15);} { max bits for distance code } 130 | while (k < 15) do 131 | begin 132 | Dec(n); 133 | b := b or (uLong(p^) shl k); 134 | Inc(p); 135 | Inc(k, 8); 136 | end; 137 | 138 | t := @huft_ptr(td)^[uInt(b) and md]; 139 | e := t^.exop; 140 | repeat 141 | {DUMPBITS(t^.bits);} 142 | b := b shr t^.bits; 143 | Dec(k, t^.bits); 144 | 145 | if (e and 16 <> 0) then 146 | begin 147 | { get extra bits to add to distance base } 148 | e := e and 15; 149 | {GRABBITS(e);} { get extra bits (up to 13) } 150 | while (k < e) do 151 | begin 152 | Dec(n); 153 | b := b or (uLong(p^) shl k); 154 | Inc(p); 155 | Inc(k, 8); 156 | end; 157 | 158 | d := t^.base + (uInt(b) and inflate_mask[e]); 159 | {DUMPBITS(e);} 160 | b := b shr e; 161 | Dec(k, e); 162 | 163 | {$IFDEF INFFAST_DEBUG} 164 | Tracevv('inflate: * distance '+IntToStr(d)); 165 | {$ENDIF} 166 | { do the copy } 167 | Dec(m, c); 168 | if (uInt(ptr2int(q) - ptr2int(s.window)) >= d) then { offset before dest } 169 | begin { just copy } 170 | r := q; 171 | Dec(r, d); 172 | q^ := r^; Inc(q); Inc(r); Dec(c); { minimum count is three, } 173 | q^ := r^; Inc(q); Inc(r); Dec(c); { so unroll loop a little } 174 | end 175 | else { else offset after destination } 176 | begin 177 | e := d - uInt(ptr2int(q) - ptr2int(s.window)); { bytes from offset to end } 178 | r := s.zend; 179 | Dec(r, e); { pointer to offset } 180 | if (c > e) then { if source crosses, } 181 | begin 182 | Dec(c, e); { copy to end of window } 183 | repeat 184 | q^ := r^; 185 | Inc(q); 186 | Inc(r); 187 | Dec(e); 188 | until (e=0); 189 | r := s.window; { copy rest from start of window } 190 | end; 191 | end; 192 | repeat { copy all or what's left } 193 | q^ := r^; 194 | Inc(q); 195 | Inc(r); 196 | Dec(c); 197 | until (c = 0); 198 | break; 199 | end 200 | else 201 | if (e and 64 = 0) then 202 | begin 203 | Inc(t, t^.base + (uInt(b) and inflate_mask[e])); 204 | e := t^.exop; 205 | end 206 | else 207 | begin 208 | z.msg := 'invalid distance code'; 209 | {UNGRAB} 210 | c := z.avail_in-n; 211 | if (k shr 3) < c then 212 | c := k shr 3; 213 | Inc(n, c); 214 | Dec(p, c); 215 | Dec(k, c shl 3); 216 | {UPDATE} 217 | s.bitb := b; 218 | s.bitk := k; 219 | z.avail_in := n; 220 | Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in)); 221 | z.next_in := p; 222 | s.write := q; 223 | 224 | inflate_fast := Z_DATA_ERROR; 225 | exit; 226 | end; 227 | until FALSE; 228 | break; 229 | end; 230 | if (e and 64 = 0) then 231 | begin 232 | {t += t->base; 233 | e = (t += ((uInt)b & inflate_mask[e]))->exop;} 234 | 235 | Inc(t, t^.base + (uInt(b) and inflate_mask[e])); 236 | e := t^.exop; 237 | if (e = 0) then 238 | begin 239 | {DUMPBITS(t^.bits);} 240 | b := b shr t^.bits; 241 | Dec(k, t^.bits); 242 | 243 | {$IFDEF INFFAST_DEBUG} 244 | if (t^.base >= $20) and (t^.base < $7f) then 245 | Tracevv('inflate: * literal '+char(t^.base)) 246 | else 247 | Tracevv('inflate: * literal '+IntToStr(t^.base)); 248 | {$ENDIF} 249 | q^ := Byte(t^.base); 250 | Inc(q); 251 | Dec(m); 252 | break; 253 | end; 254 | end 255 | else 256 | if (e and 32 <> 0) then 257 | begin 258 | {$IFDEF INFFAST_DEBUG} 259 | Tracevv('inflate: * end of block'); 260 | {$ENDIF} 261 | {UNGRAB} 262 | c := z.avail_in-n; 263 | if (k shr 3) < c then 264 | c := k shr 3; 265 | Inc(n, c); 266 | Dec(p, c); 267 | Dec(k, c shl 3); 268 | {UPDATE} 269 | s.bitb := b; 270 | s.bitk := k; 271 | z.avail_in := n; 272 | Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in)); 273 | z.next_in := p; 274 | s.write := q; 275 | inflate_fast := Z_STREAM_END; 276 | exit; 277 | end 278 | else 279 | begin 280 | z.msg := 'invalid literal/length code'; 281 | {UNGRAB} 282 | c := z.avail_in-n; 283 | if (k shr 3) < c then 284 | c := k shr 3; 285 | Inc(n, c); 286 | Dec(p, c); 287 | Dec(k, c shl 3); 288 | {UPDATE} 289 | s.bitb := b; 290 | s.bitk := k; 291 | z.avail_in := n; 292 | Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in)); 293 | z.next_in := p; 294 | s.write := q; 295 | inflate_fast := Z_DATA_ERROR; 296 | exit; 297 | end; 298 | until FALSE; 299 | until (m < 258) or (n < 10); 300 | 301 | { not enough input or output--restore pointers and return } 302 | {UNGRAB} 303 | c := z.avail_in-n; 304 | if (k shr 3) < c then 305 | c := k shr 3; 306 | Inc(n, c); 307 | Dec(p, c); 308 | Dec(k, c shl 3); 309 | {UPDATE} 310 | s.bitb := b; 311 | s.bitk := k; 312 | z.avail_in := n; 313 | Inc(z.total_in, ptr2int(p)-ptr2int(z.next_in)); 314 | z.next_in := p; 315 | s.write := q; 316 | inflate_fast := Z_OK; 317 | end; 318 | 319 | end. -------------------------------------------------------------------------------- /Source/ZLib/paszlib/README.txt: -------------------------------------------------------------------------------- 1 | 2 | This version of PASZLIB was modified by David J Butler, 04/2015 3 | for inclusion in the Fundamentals Library. 4 | https://github.com/fundamentalslib 5 | _____________________________________________________________________________ 6 | 7 | This version of PASZLIB was modified by Sergey A. Galin, 02/2003. 8 | See the 9 | README in directory above for details. 10 | 11 | 12 | _____________________________________________________________________________ 13 | 14 | PASZLIB 1.0 May 11th, 1998 15 | 16 | Based on the zlib 1.1.2, a general purpose data compression library. 17 | 18 | Copyright (C) 1998,1999,2000 by NOMSSI NZALI Jacques H. C. 19 | [kn&n DES] See "Legal issues" for conditions of distribution and use. 20 | _____________________________________________________________________________ 21 | 22 | 23 | Introduction 24 | ============ 25 | 26 | The 'zlib' compression library provides in-memory compression and 27 | decompression functions, including integrity checks of the uncompressed 28 | data. This version of the library supports only one compression method 29 | (deflation) but other algorithms will be added later and will have the same 30 | stream interface. 31 | 32 | Compression can be done in a single step if the buffers are large 33 | enough (for example if an input file is mmap'ed), or can be done by 34 | repeated calls of the compression function. In the latter case, the 35 | application must provide more input and/or consume the output 36 | (providing more output space) before each call. 37 | 38 | The default memory requirements for deflate are 256K plus a few kilobytes 39 | for small objects. The default memory requirements for inflate are 32K 40 | plus a few kilobytes for small objects. 41 | 42 | Change Log 43 | ========== 44 | 45 | March 24th 2000 - minizip code by Gilles Vollant ported to Pascal. 46 | z_stream.msg defined as string[255] to avoid problems 47 | with Delphi 2+ dynamic string handling. 48 | changes to silence Delphi 5 compiler warning. If you 49 | have Delphi 5, defines Delphi5 in zconf.inc 50 | 51 | May 7th 1999 - Some changes for FPC 52 | deflateCopy() has new parameters 53 | trees.pas - record constant definition 54 | June 17th 1998 - Applied official 1.1.2 patch. 55 | Memcheck turned off by default. 56 | zutil.pas patch for Delphi 1 memory allocation corrected. 57 | dzlib.txt file added. 58 | compress2() is now exported 59 | 60 | June 25th 1998 - fixed a conversion bug: in inftrees.pas, ZFREE(z, v) was 61 | missing in line 574; 62 | 63 | File list 64 | ========= 65 | 66 | Here is a road map to the files in the Paszlib distribution. 67 | 68 | readme.txt Introduction, Documentation 69 | dzlib.txt Changes to Delphi sources for Paszlib stream classes 70 | 71 | include file 72 | 73 | zconf.inc Configuration declarations. 74 | 75 | Pascal source code files: 76 | 77 | adler.pas compute the Adler-32 checksum of a data stream 78 | crc.pas compute the CRC-32 of a data stream 79 | gzio.pas IO on .gz files 80 | infblock.pas interpret and process block types to last block 81 | infcodes.pas process literals and length/distance pairs 82 | inffast.pas process literals and length/distance pairs fast 83 | inftrees.pas generate Huffman trees for efficient decoding 84 | infutil.pas types and macros common to blocks and codes 85 | strutils.pas string utilities 86 | trees.pas output deflated data using Huffman coding 87 | zcompres.pas compress a memory buffer 88 | zdeflate.pas compress data using the deflation algorithm 89 | zinflate.pas zlib interface to inflate modules 90 | zlib.pas zlib data structures. read the comments there! 91 | zuncompr.pas decompress a memory buffer 92 | zutil.pas 93 | 94 | minizip/ziputils.pas data structure and IO on .zip file 95 | minizip/unzip.pas 96 | minizip/zip.pas 97 | 98 | Test applications 99 | 100 | example.pas usage example of the zlib compression library 101 | minigzip.pas simulate gzip using the zlib compression library 102 | minizip/miniunz.pas simulates unzip using the zlib compression library 103 | minizip/minizip.pas simulates zip using the zlib compression library 104 | 105 | Legal issues 106 | ============ 107 | 108 | Copyright (C) 1998,1999,2000 by Jacques Nomssi Nzali 109 | 110 | This software is provided 'as-is', without any express or implied 111 | warranty. In no event will the author be held liable for any damages 112 | arising from the use of this software. 113 | 114 | Permission is granted to anyone to use this software for any purpose, 115 | including commercial applications, and to alter it and redistribute it 116 | freely, subject to the following restrictions: 117 | 118 | 1. The origin of this software must not be misrepresented; you must not 119 | claim that you wrote the original software. If you use this software 120 | in a product, an acknowledgment in the product documentation would be 121 | appreciated but is not required. 122 | 2. Altered source versions must be plainly marked as such, and must not be 123 | misrepresented as being the original software. 124 | 3. This notice may not be removed or altered from any source distribution. 125 | 126 | 127 | Archive Locations: 128 | ================== 129 | 130 | Check the Paszlib home page with links 131 | 132 | http://www.tu-chemnitz.de/~nomssi/paszlib.html 133 | 134 | The data format used by the zlib library is described by RFCs (Request for 135 | Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt 136 | (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). 137 | These documents are also available in other formats from 138 | ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html. 139 | ____________________________________________________________________________ 140 | Jacques Nomssi Nzali March 24th, 2000 -------------------------------------------------------------------------------- /Source/ZLib/paszlib/ZUtil.pas: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/ZLib/paszlib/ZUtil.pas -------------------------------------------------------------------------------- /Source/ZLib/paszlib/dzlib.txt: -------------------------------------------------------------------------------- 1 | The Delphi 3 CD-ROM contains in \INFO\EXTRAS\ZLIB a zlib unit that implements 2 | the TCompressionStream and TDecompressionStream classes. With some changes to 3 | this unit you can implement the same functionality using Paszlib. I can not 4 | publish the modified file (Copyright 1997 by Borland International), but this 5 | document tells you how to make the changes by hand. 6 | 7 | 8 | 1. zlib.pas conflicts to a Paszlib unit name, change the name to dzlib.pas. 9 | < unit dzlib; 10 | --- 11 | > unit zlib; 12 | 13 | 2. Add zlib to the uses clause: 14 | < uses zlib, Sysutils, Classes; 15 | --- 16 | > uses Sysutils, Classes; 17 | 18 | 3. Change the type declarations for TAlloc, TFree and TZStreamRec to 19 | < TAlloc = alloc_func; 20 | < TFree = free_func; 21 | < TZStreamRec = z_stream; 22 | 23 | 4. Remove the zlib_Version const. 24 | > const 25 | > zlib_Version = '1.0.4'; 26 | 27 | 5. In the implementation part, add the following uses clause 28 | < uses 29 | < zutil, zDeflate, zInflate; 30 | 31 | 6. remove all Z_xxx const, {$L xxx} and all external procedures up to 32 | (and including) the inflateReset() function and the _memset and _memcpy 33 | procedure definitions. 34 | 35 | 7. for compatibility with D1 you should change the type of the "Size" 36 | parameter of the zlibAllocMem() function from Integer to Cardinal 37 | and all comments of the // form into the {} form. 38 | 39 | 8. Now, make the following changes, so that the dzlib can compile, you 40 | can then use the modified unit dzlib in the test.pas source. 41 | 185c293 42 | < CCheck(deflateInit_(@strm, Z_BEST_COMPRESSION, zlib_version, sizeof(strm))); 43 | --- 44 | > CCheck(deflateInit_(strm, Z_BEST_COMPRESSION, zlib_version, sizeof(strm))); 45 | 192c300 46 | < strm.next_out := pBytef(Integer(OutBuf) + (Integer(strm.next_out) - Integer(P))); 47 | --- 48 | > strm.next_out := PChar(Integer(OutBuf) + (Integer(strm.next_out) - Integer(P))); 49 | 228c336 50 | < DCheck(inflateInit_(@strm, zlib_version, sizeof(strm))); 51 | --- 52 | > DCheck(inflateInit_(strm, zlib_version, sizeof(strm))); 53 | 235c343 54 | < strm.next_out := pBytef(Integer(OutBuf) + (Integer(strm.next_out) - Integer(P))); 55 | --- 56 | > strm.next_out := PChar(Integer(OutBuf) + (Integer(strm.next_out) - Integer(P))); 57 | 250c358 58 | 276c384 59 | < FZRec.next_out := @FBuffer; 60 | --- 61 | > FZRec.next_out := FBuffer; 62 | 278c386 63 | < CCheck(deflateInit_(@FZRec, Levels[CompressionLevel], zlib_version, sizeof(FZRec))); 64 | --- 65 | > CCheck(deflateInit_(FZRec, Levels[CompressionLevel], zlib_version, sizeof(FZRec))); 66 | 291c399 67 | < FZRec.next_out := @FBuffer; 68 | --- 69 | > FZRec.next_out := FBuffer; 70 | 318c426 71 | < FZRec.next_out := @FBuffer; 72 | --- 73 | > FZRec.next_out := FBuffer; 74 | 344c452 75 | < FZRec.next_in := @FBuffer; 76 | --- 77 | > FZRec.next_in := FBuffer; 78 | 351c459 79 | < DCheck(inflateInit_(@FZRec, zlib_version, sizeof(FZRec))); 80 | --- 81 | > DCheck(inflateInit_(FZRec, zlib_version, sizeof(FZRec))); 82 | 375c483 83 | < FZRec.next_in := @FBuffer; 84 | --- 85 | > FZRec.next_in := FBuffer; 86 | 397c505 87 | < FZRec.next_in := @FBuffer; 88 | --- 89 | > FZRec.next_in := FBuffer; 90 | 91 | 9. This is a bug fix: 92 | in CompressBuf() change 93 | < while CCheck(deflate(strm, Z_FINISH)) <> Z_STREAM_END do 94 | to 95 | > while deflate(strm, Z_FINISH) <> Z_STREAM_END do 96 | 97 | in DeCompressBuf() change 98 | < while CCheck(inflate(strm, Z_FINISH)) <> Z_STREAM_END do 99 | to 100 | > while inflate(strm, Z_FINISH) <> Z_STREAM_END do 101 | 102 | Jacques Nomssi Nzali [25.3.2000] -------------------------------------------------------------------------------- /Source/ZLib/paszlib/infutil.pas: -------------------------------------------------------------------------------- 1 | Unit infutil; 2 | 3 | { types and macros common to blocks and codes 4 | Copyright (C) 1995-1998 Mark Adler 5 | 6 | WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. 9 | 10 | Pascal tranlastion 11 | Copyright (C) 1998 by Jacques Nomssi Nzali 12 | For conditions of distribution and use, see copyright notice in readme.txt 13 | 14 | Modifiied 02/2003 by Sergey A. Galin for Delphi 6+ and Kylix compatibility. 15 | See README in directory above for more information. 16 | } 17 | 18 | interface 19 | 20 | {$I zconf.inc} 21 | 22 | uses 23 | ZUtil, gZlib; 24 | 25 | { copy as much as possible from the sliding window to the output area } 26 | function inflate_flush(var s : inflate_blocks_state; 27 | var z : z_stream; 28 | r : int) : int; 29 | 30 | { And'ing with mask[n] masks the lower n bits } 31 | const 32 | inflate_mask : array[0..17-1] of uInt = ( 33 | $0000, 34 | $0001, $0003, $0007, $000f, $001f, $003f, $007f, $00ff, 35 | $01ff, $03ff, $07ff, $0fff, $1fff, $3fff, $7fff, $ffff); 36 | 37 | {procedure GRABBITS(j : int);} 38 | {procedure DUMPBITS(j : int);} 39 | {procedure NEEDBITS(j : int);} 40 | 41 | implementation 42 | 43 | { macros for bit input with no checking and for returning unused bytes } 44 | procedure GRABBITS(j : int); 45 | begin 46 | {while (k < j) do 47 | begin 48 | Dec(z^.avail_in); 49 | Inc(z^.total_in); 50 | b := b or (uLong(z^.next_in^) shl k); 51 | Inc(z^.next_in); 52 | Inc(k, 8); 53 | end;} 54 | end; 55 | 56 | procedure DUMPBITS(j : int); 57 | begin 58 | {b := b shr j; 59 | Dec(k, j);} 60 | end; 61 | 62 | procedure NEEDBITS(j : int); 63 | begin 64 | (* 65 | while (k < j) do 66 | begin 67 | {NEEDBYTE;} 68 | if (n <> 0) then 69 | r :=Z_OK 70 | else 71 | begin 72 | {UPDATE} 73 | s.bitb := b; 74 | s.bitk := k; 75 | z.avail_in := n; 76 | Inc(z.total_in, LongInt(p)-LongInt(z.next_in)); 77 | z.next_in := p; 78 | s.write := q; 79 | result := inflate_flush(s,z,r); 80 | exit; 81 | end; 82 | Dec(n); 83 | b := b or (uLong(p^) shl k); 84 | Inc(p); 85 | Inc(k, 8); 86 | end; 87 | *) 88 | end; 89 | 90 | procedure NEEDOUT; 91 | begin 92 | (* 93 | if (m = 0) then 94 | begin 95 | {WRAP} 96 | if (q = s.zend) and (s.read <> s.window) then 97 | begin 98 | q := s.window; 99 | if LongInt(q) < LongInt(s.read) then 100 | m := uInt(LongInt(s.read)-LongInt(q)-1) 101 | else 102 | m := uInt(LongInt(s.zend)-LongInt(q)); 103 | end; 104 | 105 | if (m = 0) then 106 | begin 107 | {FLUSH} 108 | s.write := q; 109 | r := inflate_flush(s,z,r); 110 | q := s.write; 111 | if LongInt(q) < LongInt(s.read) then 112 | m := uInt(LongInt(s.read)-LongInt(q)-1) 113 | else 114 | m := uInt(LongInt(s.zend)-LongInt(q)); 115 | 116 | {WRAP} 117 | if (q = s.zend) and (s.read <> s.window) then 118 | begin 119 | q := s.window; 120 | if LongInt(q) < LongInt(s.read) then 121 | m := uInt(LongInt(s.read)-LongInt(q)-1) 122 | else 123 | m := uInt(LongInt(s.zend)-LongInt(q)); 124 | end; 125 | 126 | if (m = 0) then 127 | begin 128 | {UPDATE} 129 | s.bitb := b; 130 | s.bitk := k; 131 | z.avail_in := n; 132 | Inc(z.total_in, LongInt(p)-LongInt(z.next_in)); 133 | z.next_in := p; 134 | s.write := q; 135 | result := inflate_flush(s,z,r); 136 | exit; 137 | end; 138 | end; 139 | end; 140 | r := Z_OK; 141 | *) 142 | end; 143 | 144 | { copy as much as possible from the sliding window to the output area } 145 | function inflate_flush(var s : inflate_blocks_state; 146 | var z : z_stream; 147 | r : int) : int; 148 | var 149 | n : uInt; 150 | p : pBytef; 151 | q : pBytef; 152 | begin 153 | { local copies of source and destination pointers } 154 | p := z.next_out; 155 | q := s.read; 156 | 157 | { compute number of bytes to copy as far as end of window } 158 | if ptr2int(q) <= ptr2int(s.write) then 159 | n := uInt(ptr2int(s.write) - ptr2int(q)) 160 | else 161 | n := uInt(ptr2int(s.zend) - ptr2int(q)); 162 | if (n > z.avail_out) then 163 | n := z.avail_out; 164 | if (n <> 0) and (r = Z_BUF_ERROR) then 165 | r := Z_OK; 166 | 167 | { update counters } 168 | Dec(z.avail_out, n); 169 | Inc(z.total_out, n); 170 | 171 | 172 | { update check information } 173 | if Assigned(s.checkfn) then 174 | begin 175 | s.check := s.checkfn(s.check, q, n); 176 | z.adler := s.check; 177 | end; 178 | 179 | { copy as far as end of window } 180 | zmemcpy(p, q, n); 181 | Inc(p, n); 182 | Inc(q, n); 183 | 184 | { see if more to copy at beginning of window } 185 | if (q = s.zend) then 186 | begin 187 | { wrap pointers } 188 | q := s.window; 189 | if (s.write = s.zend) then 190 | s.write := s.window; 191 | 192 | { compute bytes to copy } 193 | n := uInt(ptr2int(s.write) - ptr2int(q)); 194 | if (n > z.avail_out) then 195 | n := z.avail_out; 196 | if (n <> 0) and (r = Z_BUF_ERROR) then 197 | r := Z_OK; 198 | 199 | { update counters } 200 | Dec( z.avail_out, n); 201 | Inc( z.total_out, n); 202 | 203 | { update check information } 204 | if Assigned(s.checkfn) then 205 | begin 206 | s.check := s.checkfn(s.check, q, n); 207 | z.adler := s.check; 208 | end; 209 | 210 | { copy } 211 | zmemcpy(p, q, n); 212 | Inc(p, n); 213 | Inc(q, n); 214 | end; 215 | 216 | 217 | { update pointers } 218 | z.next_out := p; 219 | s.read := q; 220 | 221 | { done } 222 | inflate_flush := r; 223 | end; 224 | 225 | end. 226 | -------------------------------------------------------------------------------- /Source/ZLib/paszlib/minigzip.pas: -------------------------------------------------------------------------------- 1 | program minigzip; 2 | 3 | { 4 | minigzip.c -- simulate gzip using the zlib compression library 5 | Copyright (C) 1995-1998 Jean-loup Gailly. 6 | 7 | minigzip is a minimal implementation of the gzip utility. This is 8 | only an example of using zlib and isn't meant to replace the 9 | full-featured gzip. No attempt is made to deal with file systems 10 | limiting names to 14 or 8+3 characters, etc... Error checking is 11 | very limited. So use minigzip only for testing; use gzip for the 12 | real thing. On MSDOS, use only on file names without extension 13 | or in pipe mode. 14 | 15 | Pascal tranlastion based on code contributed by Francisco Javier Crespo 16 | Copyright (C) 1998 by Jacques Nomssi Nzali 17 | For conditions of distribution and use, see copyright notice in readme.txt 18 | } 19 | 20 | uses 21 | {$IFDEF VER80} 22 | WinCrt, 23 | {$ENDIF} 24 | gzio, zutil; 25 | 26 | const 27 | BUFLEN = 16384 ; 28 | GZ_SUFFIX = '.gz' ; 29 | 30 | {$DEFINE MAXSEF_64K} 31 | 32 | var 33 | buf : packed array [0..BUFLEN-1] of byte; { Global uses BSS instead of stack } 34 | prog : string; 35 | 36 | { ERROR ===================================================================== 37 | 38 | Display error message and exit 39 | 40 | ============================================================================} 41 | 42 | procedure error (msg:string); 43 | begin 44 | writeln (prog,': ',msg); 45 | halt(1); 46 | end; 47 | 48 | 49 | { GZ_COMPRESS =============================================================== 50 | 51 | Compress input to output then close both files 52 | 53 | ============================================================================} 54 | 55 | procedure gz_compress (var infile:file; outfile:gzFile); 56 | var 57 | len : uInt; 58 | ioerr : integer; 59 | err : int; 60 | begin 61 | 62 | while true do begin 63 | 64 | {$I-} 65 | blockread (infile, buf, BUFLEN, len); 66 | {$I+} 67 | ioerr := IOResult; 68 | if (ioerr <> 0) then begin 69 | writeln ('read error: ',ioerr); 70 | halt(1); 71 | end; 72 | 73 | if (len = 0) then break; 74 | 75 | if (gzwrite (outfile, @buf, len) <> len) 76 | then error (gzerror (outfile, err)); 77 | 78 | end; {WHILE} 79 | 80 | close (infile); 81 | if (gzclose (outfile) <> 0{Z_OK}) 82 | then error ('gzclose error'); 83 | end; 84 | 85 | 86 | { GZ_UNCOMPRESS ============================================================= 87 | 88 | Uncompress input to output then close both files 89 | 90 | ============================================================================} 91 | 92 | procedure gz_uncompress (infile:gzFile; var outfile:file); 93 | var 94 | len : int; 95 | written : uInt; 96 | ioerr : integer; 97 | err : int; 98 | begin 99 | while true do begin 100 | 101 | len := gzread (infile, @buf, BUFLEN); 102 | if (len < 0) 103 | then error (gzerror (infile, err)); 104 | if (len = 0) 105 | then break; 106 | 107 | {$I-} 108 | blockwrite (outfile, buf, len, written); 109 | {$I+} 110 | if (written <> len) 111 | then error ('write error'); 112 | 113 | end; {WHILE} 114 | 115 | {$I-} 116 | close (outfile); 117 | {$I+} 118 | ioerr := IOResult; 119 | if (ioerr <> 0) then begin 120 | writeln ('close error: ',ioerr); 121 | halt(1); 122 | end; 123 | 124 | if (gzclose (infile) <> 0{Z_OK}) 125 | then error ('gzclose error'); 126 | end; 127 | 128 | 129 | { FILE_COMPRESS ============================================================= 130 | 131 | Compress the given file: 132 | create a corresponding .gz file and remove the original 133 | 134 | ============================================================================} 135 | 136 | procedure file_compress (filename:string; mode:string); 137 | var 138 | infile : file; 139 | outfile : gzFile; 140 | ioerr : integer; 141 | outname : string; 142 | begin 143 | Assign (infile, filename); 144 | {$I-} 145 | Reset (infile,1); 146 | {$I+} 147 | ioerr := IOResult; 148 | if (ioerr <> 0) then begin 149 | writeln ('open error: ',ioerr); 150 | halt(1); 151 | end; 152 | 153 | outname := filename + GZ_SUFFIX; 154 | outfile := gzopen (outname, mode); 155 | 156 | if (outfile = NIL) then begin 157 | writeln (prog,': can''t gzopen ',outname); 158 | halt(1); 159 | end; 160 | 161 | gz_compress(infile, outfile); 162 | erase (infile); 163 | end; 164 | 165 | 166 | { FILE_UNCOMPRESS =========================================================== 167 | 168 | Uncompress the given file and remove the original 169 | 170 | ============================================================================} 171 | 172 | procedure file_uncompress (filename:string); 173 | var 174 | inname : string; 175 | outname : string; 176 | infile : gzFile; 177 | outfile : file; 178 | ioerr : integer; 179 | len : integer; 180 | begin 181 | len := Length(filename); 182 | 183 | if (copy(filename,len-2,3) = GZ_SUFFIX) then begin 184 | inname := filename; 185 | outname := copy(filename,0,len-3); 186 | end 187 | else begin 188 | inname := filename + GZ_SUFFIX; 189 | outname := filename; 190 | end; 191 | 192 | infile := gzopen (inname, 'r'); 193 | if (infile = NIL) then begin 194 | writeln (prog,': can''t gzopen ',inname); 195 | halt(1); 196 | end; 197 | 198 | Assign (outfile, outname); 199 | {$I-} 200 | Rewrite (outfile,1); 201 | {$I+} 202 | ioerr := IOResult; 203 | if (ioerr <> 0) then begin 204 | writeln ('open error: ',ioerr); 205 | halt(1); 206 | end; 207 | 208 | gz_uncompress (infile, outfile); 209 | 210 | { erase (infile); } 211 | end; 212 | 213 | 214 | { MINIGZIP =================================================================} 215 | 216 | var 217 | 218 | uncompr : boolean; 219 | outmode : string[20]; 220 | i : integer; 221 | option : string; 222 | 223 | begin 224 | uncompr := false; 225 | outmode := 'w6 '; 226 | prog := ParamStr(0); 227 | 228 | if (ParamCount = 0) then begin 229 | writeln ('Error: STDIO/STDOUT not supported yet'); 230 | writeln; 231 | writeln ('Usage: minigzip [-d] [-f] [-h] [-1 to -9] '); 232 | writeln (' -d : decompress'); 233 | writeln (' -f : compress with Z_FILTERED'); 234 | writeln (' -h : compress with Z_HUFFMAN_ONLY'); 235 | writeln (' -1 to -9 : compression level'); 236 | exit; 237 | end; 238 | 239 | for i:=1 to ParamCount do begin 240 | option := ParamStr(i); 241 | if (option = '-d') then uncompr := true; 242 | if (option = '-f') then outmode[3] := 'f'; 243 | if (option = '-h') then outmode[3] := 'h'; 244 | if (option[1] = '-') and (option[2] >= '1') and (option[2] <= '9') 245 | then outmode[2] := option[2]; 246 | end; 247 | 248 | if (uncompr = true) 249 | then file_uncompress (ParamStr(ParamCount)) 250 | else file_compress (ParamStr(ParamCount), outmode); 251 | end. -------------------------------------------------------------------------------- /Source/ZLib/paszlib/minizip/MiniZip.pas: -------------------------------------------------------------------------------- 1 | Program MiniZip; 2 | { minizip demo package by Gilles Vollant 3 | 4 | Usage : minizip [-o] file.zip [files_to_add] 5 | 6 | a file.zip file is created, all files listed in [files_to_add] are added 7 | to the new .zip file. 8 | -o an existing .zip file with be overwritten without warning 9 | 10 | Pascal tranlastion 11 | Copyright (C) 2000 by Jacques Nomssi Nzali 12 | For conditions of distribution and use, see copyright notice in readme.txt 13 | } 14 | 15 | {$ifdef WIN32} 16 | {$define Delphi} 17 | {$ifndef FPC} 18 | {$define Delphi32} 19 | {$endif} 20 | {$endif} 21 | 22 | uses 23 | {$ifdef Delphi} 24 | SysUtils, Windows, 25 | {$else} 26 | WinDos, strings, 27 | {$endif} 28 | zutil, gzlib, ziputils, zip; 29 | 30 | const 31 | WRITEBUFFERSIZE = Z_BUFSIZE; 32 | MAXFILENAME = Z_MAXFILENAMEINZIP; 33 | 34 | {$ifdef Delphi32} 35 | function filetime(f : PChar; { name of file to get info on } 36 | var tmzip : tm_zip; { return value: access, modific. and creation times } 37 | var dt : uLong) : uLong; { dostime } 38 | var 39 | ret : int; 40 | var 41 | ftLocal : TFileTime; // FILETIME; 42 | hFind : THandle; // HANDLE; 43 | ff32 : TWIN32FindData; // WIN32_FIND_DATA; 44 | begin 45 | ret := 0; 46 | hFind := FindFirstFile(f, ff32); 47 | if (hFind <> INVALID_HANDLE_VALUE) then 48 | begin 49 | FileTimeToLocalFileTime(ff32.ftLastWriteTime,ftLocal); 50 | FileTimeToDosDateTime(ftLocal,LongRec(dt).hi,LongRec(dt).lo); 51 | FindClose(hFind); 52 | ret := 1; 53 | end; 54 | filetime := ret; 55 | end; 56 | {$else} 57 | {$ifdef FPC} 58 | function filetime(f : PChar; { name of file to get info on } 59 | var tmzip : tm_zip; { return value: access, modific. and creation times } 60 | var dt : uLong) : uLong; { dostime } 61 | var 62 | ret : int; 63 | var 64 | ftLocal : TFileTime; // FILETIME; 65 | hFind : THandle; // HANDLE; 66 | ff32 : TWIN32FindData; // WIN32_FIND_DATA; 67 | begin 68 | ret := 0; 69 | hFind := FindFirstFile(f, @ff32); 70 | if (hFind <> INVALID_HANDLE_VALUE) then 71 | begin 72 | FileTimeToLocalFileTime(ff32.ftLastWriteTime,@ftLocal); 73 | FileTimeToDosDateTime(ftLocal,@LongRec(dt).hi,@LongRec(dt).lo); 74 | FindClose(hFind); 75 | ret := 1; 76 | end; 77 | filetime := ret; 78 | end; 79 | {$else} 80 | function filetime(f : PChar; { name of file to get info on } 81 | var tmzip : tm_zip; { return value: access, modific. and creation times } 82 | var dt : uLong) : uLong; { dostime } 83 | var 84 | fl : file; 85 | yy, mm, dd, dow : Word; 86 | h, m, s, hund : Word; { For GetTime} 87 | dtrec : TDateTime; { For Pack/UnpackTime} 88 | begin 89 | {$i-} 90 | Assign(fl, f); 91 | Reset(fl, 1); 92 | if IOresult = 0 then 93 | begin 94 | GetFTime(fl,dt); { Get creation time } 95 | UnpackTime(dt, dtrec); 96 | Close(fl); 97 | tmzip.tm_sec := dtrec.sec; 98 | tmzip.tm_min := dtrec.min; 99 | tmzip.tm_hour := dtrec.hour; 100 | tmzip.tm_mday := dtrec.day; 101 | tmzip.tm_mon := dtrec.month; 102 | tmzip.tm_year := dtrec.year; 103 | end; 104 | 105 | filetime := 0; 106 | end; 107 | {$endif} 108 | {$endif} 109 | 110 | function check_exist_file(const filename : PChar) : int; 111 | var 112 | ftestexist : FILE; 113 | ret : int; 114 | begin 115 | ret := 1; 116 | Assign(ftestexist, filename); 117 | {$i-} 118 | reset(ftestexist); 119 | if IOresult <> 0 then 120 | ret := 0 121 | else 122 | system.close(ftestexist); 123 | check_exist_file := ret; 124 | end; 125 | 126 | procedure do_banner; 127 | begin 128 | WriteLn('MiniZip 0.15, demo package written by Gilles Vollant'); 129 | WriteLn('Pascal port by Jacques Nomssi Nzali'); 130 | WriteLn('more info at http://www.tu-chemnitz.de/~nomssi/paszlib.html'); 131 | WriteLn; 132 | end; 133 | 134 | procedure do_help; 135 | begin 136 | WriteLn('Usage : minizip [-o] file.zip [files_to_add]'); 137 | WriteLn; 138 | end; 139 | 140 | function main : int; 141 | var 142 | argstr : string; 143 | i : int; 144 | opt_overwrite : int; 145 | opt_compress_level : int; 146 | zipfilenamearg : int; 147 | filename_try : array[0..MAXFILENAME-1] of char; 148 | zipok : int; 149 | err : int; 150 | size_buf : int; 151 | buf : voidp; 152 | var 153 | p : PChar; 154 | c : char; 155 | var 156 | len : int; 157 | dot_found : int; 158 | var 159 | rep : char; 160 | answer : string[128]; 161 | var 162 | zf : zipFile; 163 | errclose : int; 164 | var 165 | fin : FILEptr; 166 | size_read : int; 167 | filenameinzip : {const} PChar; 168 | zi : zip_fileinfo; 169 | begin 170 | opt_overwrite := 0; 171 | opt_compress_level := Z_DEFAULT_COMPRESSION; 172 | zipfilenamearg := 0; 173 | err := 0; 174 | main := 0; 175 | 176 | do_banner; 177 | if (ParamCount=0) then 178 | begin 179 | do_help; 180 | main := 0; 181 | exit; 182 | end 183 | else 184 | begin 185 | for i:=1 to ParamCount-1+1 do 186 | begin 187 | argstr := ParamStr(i)+#0; 188 | if (argstr[1]='-') then 189 | begin 190 | p := @argstr[1+1]; {const char *p=argv[i]+1;} 191 | 192 | while (p^<>#0) do 193 | begin 194 | c := p^; 195 | Inc(p); 196 | if (c='o') or (c='O') then 197 | opt_overwrite := 1; 198 | if (c>='0') and (c<='9') then 199 | opt_compress_level := Byte(c)-Byte('0'); 200 | end; 201 | end 202 | else 203 | if (zipfilenamearg = 0) then 204 | zipfilenamearg := i; 205 | end; 206 | end; 207 | 208 | size_buf := WRITEBUFFERSIZE; 209 | buf := ALLOC(size_buf); 210 | if (buf=NIL) then 211 | begin 212 | WriteLn('Error allocating memory'); 213 | main := ZIP_INTERNALERROR; 214 | exit; 215 | end; 216 | 217 | if (zipfilenamearg=0) then 218 | zipok := 0 219 | else 220 | begin 221 | dot_found := 0; 222 | 223 | zipok := 1 ; 224 | argstr := ParamStr(zipfilenamearg) + #0; 225 | strcopy(filename_try, PChar(@argstr[1])); 226 | len := strlen(filename_try); 227 | for i:=0 to len-1 do 228 | if (filename_try[i]='.') then 229 | dot_found := 1; 230 | 231 | if (dot_found = 0) then 232 | strcat(filename_try,'.zip'); 233 | 234 | if (opt_overwrite=0) then 235 | if (check_exist_file(filename_try)<>0) then 236 | begin 237 | repeat 238 | WriteLn('The file ',filename_try, 239 | ' exist. Overwrite ? [y]es, [n]o : '); 240 | ReadLn(answer); 241 | rep := answer[1] ; 242 | if (rep>='a') and (rep<='z') then 243 | Dec(rep, $20); 244 | until (rep='Y') or (rep='N'); 245 | if (rep='N') then 246 | zipok := 0; 247 | end; 248 | end; 249 | 250 | if (zipok=1) then 251 | begin 252 | zf := zipOpen(filename_try,0); 253 | if (zf = NIL) then 254 | begin 255 | WriteLn('error opening ', filename_try); 256 | err := ZIP_ERRNO; 257 | end 258 | else 259 | WriteLn('creating ',filename_try); 260 | 261 | i := zipfilenamearg+1; 262 | while (i<=ParamCount) and (err=ZIP_OK) do 263 | begin 264 | argstr := ParamStr(i)+#0; 265 | if (argstr[1] <>'-') and (argstr[1] <>'/') then 266 | begin 267 | filenameinzip := PChar(@argstr[1]); 268 | 269 | zi.tmz_date.tm_sec := 0; 270 | zi.tmz_date.tm_min := 0; 271 | zi.tmz_date.tm_hour := 0; 272 | zi.tmz_date.tm_mday := 0; 273 | zi.tmz_date.tm_min := 0; 274 | zi.tmz_date.tm_year := 0; 275 | zi.dosDate := 0; 276 | zi.internal_fa := 0; 277 | zi.external_fa := 0; 278 | filetime(filenameinzip,zi.tmz_date,zi.dosDate); 279 | 280 | if (opt_compress_level <> 0) then 281 | err := zipOpenNewFileInZip(zf,filenameinzip, @zi, 282 | NIL,0,NIL,0,NIL { comment}, Z_DEFLATED, opt_compress_level) 283 | else 284 | err := zipOpenNewFileInZip(zf,filenameinzip, @zi, 285 | NIL,0,NIL,0,NIL, 0, opt_compress_level); 286 | 287 | if (err <> ZIP_OK) then 288 | WriteLn('error in opening ',filenameinzip,' in zipfile') 289 | else 290 | begin 291 | fin := fopen(filenameinzip, fopenread); 292 | if (fin=NIL) then 293 | begin 294 | err := ZIP_ERRNO; 295 | WriteLn('error in opening ',filenameinzip,' for reading'); 296 | end; 297 | 298 | if (err = ZIP_OK) then 299 | repeat 300 | err := ZIP_OK; 301 | size_read := fread(buf,1,size_buf,fin); 302 | 303 | if (size_read < size_buf) then 304 | if feof(fin)=0 then 305 | begin 306 | WriteLn('error in reading ',filenameinzip); 307 | err := ZIP_ERRNO; 308 | end; 309 | 310 | if (size_read>0) then 311 | begin 312 | err := zipWriteInFileInZip (zf,buf,size_read); 313 | if (err<0) then 314 | WriteLn('error in writing ',filenameinzip,' in the zipfile'); 315 | end; 316 | until (err <> ZIP_OK) or (size_read=0); 317 | 318 | fclose(fin); 319 | end; 320 | if (err<0) then 321 | err := ZIP_ERRNO 322 | else 323 | begin 324 | err := zipCloseFileInZip(zf); 325 | if (err<>ZIP_OK) then 326 | WriteLn('error in closing ',filenameinzip,' in the zipfile'); 327 | end; 328 | Inc(i); 329 | end; { while } 330 | end; { if } 331 | 332 | errclose := zipClose(zf,NIL); 333 | if (errclose <> ZIP_OK) then 334 | WriteLn('error in closing ',filename_try); 335 | end; 336 | 337 | TRYFREE(buf); {FreeMem(buf, size_buf);} 338 | end; 339 | 340 | begin 341 | main; 342 | Write('Done...'); 343 | ReadLn; 344 | end. 345 | -------------------------------------------------------------------------------- /Source/ZLib/paszlib/minizip/ZipUtil.pas: -------------------------------------------------------------------------------- 1 | Unit ziputils; 2 | 3 | { ziputils.pas - IO on .zip files using zlib 4 | - definitions, declarations and routines used by both 5 | zip.pas and unzip.pas 6 | The file IO is implemented here. 7 | 8 | based on work by Gilles Vollant 9 | 10 | March 23th, 2000, 11 | Copyright (C) 2000 Jacques Nomssi Nzali } 12 | 13 | interface 14 | 15 | {$undef UseStream} 16 | {$ifdef WIN32} 17 | {$define Delphi} 18 | {$ifdef UseStream} 19 | {$define Streams} 20 | {$endif} 21 | {$endif} 22 | 23 | uses 24 | {$ifdef Delphi} 25 | classes, SysUtils, 26 | {$endif} 27 | zutil; 28 | 29 | { -------------------------------------------------------------- } 30 | {$ifdef Streams} 31 | type 32 | FILEptr = TFileStream; 33 | {$else} 34 | type 35 | FILEptr = ^file; 36 | {$endif} 37 | type 38 | seek_mode = (SEEK_SET, SEEK_CUR, SEEK_END); 39 | open_mode = (fopenread, fopenwrite, fappendwrite); 40 | 41 | function fopen(filename : PChar; mode : open_mode) : FILEptr; 42 | 43 | procedure fclose(fp : FILEptr); 44 | 45 | function fseek(fp : FILEptr; recPos : uLong; mode : seek_mode) : int; 46 | 47 | function fread(buf : voidp; recSize : uInt; 48 | recCount : uInt; fp : FILEptr) : uInt; 49 | 50 | function fwrite(buf : voidp; recSize : uInt; 51 | recCount : uInt; fp : FILEptr) : uInt; 52 | 53 | function ftell(fp : FILEptr) : uLong; { ZIP } 54 | 55 | function feof(fp : FILEptr) : uInt; { MiniZIP } 56 | 57 | { ------------------------------------------------------------------- } 58 | 59 | type 60 | zipFile = voidp; 61 | unzFile = voidp; 62 | type 63 | z_off_t = long; 64 | 65 | { tm_zip contain date/time info } 66 | type 67 | tm_zip = record 68 | tm_sec : uInt; { seconds after the minute - [0,59] } 69 | tm_min : uInt; { minutes after the hour - [0,59] } 70 | tm_hour : uInt; { hours since midnight - [0,23] } 71 | tm_mday : uInt; { day of the month - [1,31] } 72 | tm_mon : uInt; { months since January - [0,11] } 73 | tm_year : uInt; { years - [1980..2044] } 74 | end; 75 | 76 | tm_unz = tm_zip; 77 | 78 | const 79 | Z_BUFSIZE = (16384); 80 | Z_MAXFILENAMEINZIP = (256); 81 | 82 | const 83 | CENTRALHEADERMAGIC = $02014b50; 84 | 85 | const 86 | SIZECENTRALDIRITEM = $2e; 87 | SIZEZIPLOCALHEADER = $1e; 88 | 89 | function ALLOC(size : int) : voidp; 90 | 91 | procedure TRYFREE(p : voidp); 92 | 93 | const 94 | Paszip_copyright : PChar = ' Paszip Copyright 2000 Jacques Nomssi Nzali '; 95 | 96 | implementation 97 | 98 | function ALLOC(size : int) : voidp; 99 | begin 100 | ALLOC := zcalloc (NIL, size, 1); 101 | end; 102 | 103 | procedure TRYFREE(p : voidp); 104 | begin 105 | if Assigned(p) then 106 | zcfree(NIL, p); 107 | end; 108 | 109 | {$ifdef Streams} 110 | { ---------------------------------------------------------------- } 111 | 112 | function fopen(filename : PChar; mode : open_mode) : FILEptr; 113 | var 114 | fp : FILEptr; 115 | begin 116 | fp := NIL; 117 | try 118 | Case mode of 119 | fopenread: fp := TFileStream.Create(filename, fmOpenRead); 120 | fopenwrite: fp := TFileStream.Create(filename, fmCreate); 121 | fappendwrite : 122 | begin 123 | fp := TFileStream.Create(filename, fmOpenReadWrite); 124 | fp.Seek(soFromEnd, 0); 125 | end; 126 | end; 127 | except 128 | on EFOpenError do 129 | fp := NIL; 130 | end; 131 | fopen := fp; 132 | end; 133 | 134 | procedure fclose(fp : FILEptr); 135 | begin 136 | fp.Free; 137 | end; 138 | 139 | function fread(buf : voidp; 140 | recSize : uInt; 141 | recCount : uInt; 142 | fp : FILEptr) : uInt; 143 | var 144 | totalSize, readcount : uInt; 145 | begin 146 | if Assigned(buf) then 147 | begin 148 | totalSize := recCount * uInt(recSize); 149 | readCount := fp.Read(buf^, totalSize); 150 | if (readcount <> totalSize) then 151 | fread := readcount div recSize 152 | else 153 | fread := recCount; 154 | end 155 | else 156 | fread := 0; 157 | end; 158 | 159 | function fwrite(buf : voidp; 160 | recSize : uInt; 161 | recCount : uInt; 162 | fp : FILEptr) : uInt; 163 | var 164 | totalSize, written : uInt; 165 | begin 166 | if Assigned(buf) then 167 | begin 168 | totalSize := recCount * uInt(recSize); 169 | written := fp.Write(buf^, totalSize); 170 | if (written <> totalSize) then 171 | fwrite := written div recSize 172 | else 173 | fwrite := recCount; 174 | end 175 | else 176 | fwrite := 0; 177 | end; 178 | 179 | function fseek(fp : FILEptr; 180 | recPos : uLong; 181 | mode : seek_mode) : int; 182 | const 183 | fsmode : array[seek_mode] of Word 184 | = (soFromBeginning, soFromCurrent, soFromEnd); 185 | begin 186 | fp.Seek(recPos, fsmode[mode]); 187 | fseek := 0; { = 0 for success } 188 | end; 189 | 190 | function ftell(fp : FILEptr) : uLong; 191 | begin 192 | ftell := fp.Position; 193 | end; 194 | 195 | function feof(fp : FILEptr) : uInt; 196 | begin 197 | feof := 0; 198 | if Assigned(fp) then 199 | if fp.Position = fp.Size then 200 | feof := 1 201 | else 202 | feof := 0; 203 | end; 204 | 205 | {$else} 206 | { ---------------------------------------------------------------- } 207 | 208 | function fopen(filename : PChar; mode : open_mode) : FILEptr; 209 | var 210 | fp : FILEptr; 211 | OldFileMode : byte; 212 | begin 213 | fp := NIL; 214 | OldFileMode := FileMode; 215 | 216 | GetMem(fp, SizeOf(file)); 217 | Assign(fp^, filename); 218 | {$i-} 219 | Case mode of 220 | fopenread: 221 | begin 222 | FileMode := 0; 223 | Reset(fp^, 1); 224 | end; 225 | fopenwrite: 226 | begin 227 | FileMode := 1; 228 | ReWrite(fp^, 1); 229 | end; 230 | fappendwrite : 231 | begin 232 | FileMode := 2; 233 | Reset(fp^, 1); 234 | Seek(fp^, FileSize(fp^)); 235 | end; 236 | end; 237 | FileMode := OldFileMode; 238 | if IOresult<>0 then 239 | begin 240 | FreeMem(fp, SizeOf(file)); 241 | fp := NIL; 242 | end; 243 | 244 | fopen := fp; 245 | end; 246 | 247 | procedure fclose(fp : FILEptr); 248 | begin 249 | if Assigned(fp) then 250 | begin 251 | {$i-} 252 | system.close(fp^); 253 | if IOresult=0 then; 254 | FreeMem(fp, SizeOf(file)); 255 | end; 256 | end; 257 | 258 | function fread(buf : voidp; 259 | recSize : uInt; 260 | recCount : uInt; 261 | fp : FILEptr) : uInt; 262 | var 263 | totalSize, readcount : uInt; 264 | begin 265 | if Assigned(buf) then 266 | begin 267 | totalSize := recCount * uInt(recSize); 268 | {$i-} 269 | system.BlockRead(fp^, buf^, totalSize, readcount); 270 | if (readcount <> totalSize) then 271 | fread := readcount div recSize 272 | else 273 | fread := recCount; 274 | end 275 | else 276 | fread := 0; 277 | end; 278 | 279 | function fwrite(buf : voidp; 280 | recSize : uInt; 281 | recCount : uInt; 282 | fp : FILEptr) : uInt; 283 | var 284 | totalSize, written : uInt; 285 | begin 286 | if Assigned(buf) then 287 | begin 288 | totalSize := recCount * uInt(recSize); 289 | {$i-} 290 | system.BlockWrite(fp^, buf^, totalSize, written); 291 | if (written <> totalSize) then 292 | fwrite := written div recSize 293 | else 294 | fwrite := recCount; 295 | end 296 | else 297 | fwrite := 0; 298 | end; 299 | 300 | function fseek(fp : FILEptr; 301 | recPos : uLong; 302 | mode : seek_mode) : int; 303 | begin 304 | {$i-} 305 | case mode of 306 | SEEK_SET : system.Seek(fp^, recPos); 307 | SEEK_CUR : system.Seek(fp^, FilePos(fp^)+recPos); 308 | SEEK_END : system.Seek(fp^, FileSize(fp^)-1-recPos); { ?? check } 309 | end; 310 | fseek := IOresult; { = 0 for success } 311 | end; 312 | 313 | function ftell(fp : FILEptr) : uLong; 314 | begin 315 | ftell := FilePos(fp^); 316 | end; 317 | 318 | function feof(fp : FILEptr) : uInt; 319 | begin 320 | feof := 0; 321 | if Assigned(fp) then 322 | if eof(fp^) then 323 | feof := 1 324 | else 325 | feof := 0; 326 | end; 327 | 328 | {$endif} 329 | { ---------------------------------------------------------------- } 330 | 331 | end. 332 | -------------------------------------------------------------------------------- /Source/ZLib/paszlib/zCompres.pas: -------------------------------------------------------------------------------- 1 | Unit zCompres; 2 | 3 | { compress.c -- compress a memory buffer 4 | Copyright (C) 1995-1998 Jean-loup Gailly. 5 | 6 | Pascal tranlastion 7 | Copyright (C) 1998 by Jacques Nomssi Nzali 8 | For conditions of distribution and use, see copyright notice in readme.txt 9 | 10 | Modifiied 02/2003 by Sergey A. Galin for Delphi 6+ and Kylix compatibility. 11 | See README in directory above for more information. 12 | } 13 | interface 14 | 15 | {$I zconf.inc} 16 | 17 | uses 18 | ZUtil, gZlib, zDeflate; 19 | 20 | { utility functions } 21 | 22 | {EXPORT} 23 | function compress (dest : pBytef; 24 | var destLen : uLong; 25 | const source : array of Byte; 26 | sourceLen : uLong) : int; 27 | 28 | { Compresses the source buffer into the destination buffer. sourceLen is 29 | the byte length of the source buffer. Upon entry, destLen is the total 30 | size of the destination buffer, which must be at least 0.1% larger than 31 | sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the 32 | compressed buffer. 33 | This function can be used to compress a whole file at once if the 34 | input file is mmap'ed. 35 | compress returns Z_OK if success, Z_MEM_ERROR if there was not 36 | enough memory, Z_BUF_ERROR if there was not enough room in the output 37 | buffer. } 38 | 39 | {EXPORT} 40 | function compress2 (dest : pBytef; 41 | var destLen : uLong; 42 | const source : array of byte; 43 | sourceLen : uLong; 44 | level : int) : int; 45 | { Compresses the source buffer into the destination buffer. The level 46 | parameter has the same meaning as in deflateInit. sourceLen is the byte 47 | length of the source buffer. Upon entry, destLen is the total size of the 48 | destination buffer, which must be at least 0.1% larger than sourceLen plus 49 | 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. 50 | 51 | compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 52 | memory, Z_BUF_ERROR if there was not enough room in the output buffer, 53 | Z_STREAM_ERROR if the level parameter is invalid. } 54 | 55 | implementation 56 | 57 | { =========================================================================== 58 | } 59 | function compress2 (dest : pBytef; 60 | var destLen : uLong; 61 | const source : array of byte; 62 | sourceLen : uLong; 63 | level : int) : int; 64 | var 65 | stream : z_stream; 66 | err : int; 67 | begin 68 | stream.next_in := pBytef(@source); 69 | stream.avail_in := uInt(sourceLen); 70 | {$ifdef MAXSEG_64K} 71 | { Check for source > 64K on 16-bit machine: } 72 | if (uLong(stream.avail_in) <> sourceLen) then 73 | begin 74 | compress2 := Z_BUF_ERROR; 75 | exit; 76 | end; 77 | {$endif} 78 | stream.next_out := dest; 79 | stream.avail_out := uInt(destLen); 80 | if (uLong(stream.avail_out) <> destLen) then 81 | begin 82 | compress2 := Z_BUF_ERROR; 83 | exit; 84 | end; 85 | 86 | stream.zalloc := NIL; { alloc_func(0); } 87 | stream.zfree := NIL; { free_func(0); } 88 | stream.opaque := NIL; { voidpf(0); } 89 | 90 | err := deflateInit(stream, level); 91 | if (err <> Z_OK) then 92 | begin 93 | compress2 := err; 94 | exit; 95 | end; 96 | 97 | err := deflate(stream, Z_FINISH); 98 | if (err <> Z_STREAM_END) then 99 | begin 100 | deflateEnd(stream); 101 | if err = Z_OK then 102 | compress2 := Z_BUF_ERROR 103 | else 104 | compress2 := err; 105 | exit; 106 | end; 107 | destLen := stream.total_out; 108 | 109 | err := deflateEnd(stream); 110 | compress2 := err; 111 | end; 112 | 113 | { =========================================================================== 114 | } 115 | function compress (dest : pBytef; 116 | var destLen : uLong; 117 | const source : array of Byte; 118 | sourceLen : uLong) : int; 119 | begin 120 | compress := compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); 121 | end; 122 | 123 | 124 | end. -------------------------------------------------------------------------------- /Source/ZLib/paszlib/zUnCompr.pas: -------------------------------------------------------------------------------- 1 | Unit zUnCompr; 2 | { uncompr.c -- decompress a memory buffer 3 | Copyright (C) 1995-1998 Jean-loup Gailly. 4 | 5 | Pascal tranlastion 6 | Copyright (C) 1998 by Jacques Nomssi Nzali 7 | For conditions of distribution and use, see copyright notice in readme.txt 8 | 9 | Modifiied 02/2003 by Sergey A. Galin for Delphi 6+ and Kylix compatibility. 10 | See README in directory above for more information. 11 | } 12 | 13 | interface 14 | 15 | {$I zconf.inc} 16 | 17 | uses 18 | zutil, gzlib, zInflate; 19 | 20 | { =========================================================================== 21 | Decompresses the source buffer into the destination buffer. sourceLen is 22 | the byte length of the source buffer. Upon entry, destLen is the total 23 | size of the destination buffer, which must be large enough to hold the 24 | entire uncompressed data. (The size of the uncompressed data must have 25 | been saved previously by the compressor and transmitted to the decompressor 26 | by some mechanism outside the scope of this compression library.) 27 | Upon exit, destLen is the actual size of the compressed buffer. 28 | This function can be used to decompress a whole file at once if the 29 | input file is mmap'ed. 30 | 31 | uncompress returns Z_OK if success, Z_MEM_ERROR if there was not 32 | enough memory, Z_BUF_ERROR if there was not enough room in the output 33 | buffer, or Z_DATA_ERROR if the input data was corrupted. 34 | } 35 | 36 | function uncompress (dest : pBytef; 37 | var destLen : uLong; 38 | const source : array of byte; 39 | sourceLen : uLong) : int; 40 | 41 | implementation 42 | 43 | function uncompress (dest : pBytef; 44 | var destLen : uLong; 45 | const source : array of byte; 46 | sourceLen : uLong) : int; 47 | var 48 | stream : z_stream; 49 | err : int; 50 | begin 51 | stream.next_in := pBytef(@source); 52 | stream.avail_in := uInt(sourceLen); 53 | { Check for source > 64K on 16-bit machine: } 54 | if (uLong(stream.avail_in) <> sourceLen) then 55 | begin 56 | uncompress := Z_BUF_ERROR; 57 | exit; 58 | end; 59 | 60 | stream.next_out := dest; 61 | stream.avail_out := uInt(destLen); 62 | if (uLong(stream.avail_out) <> destLen) then 63 | begin 64 | uncompress := Z_BUF_ERROR; 65 | exit; 66 | end; 67 | 68 | stream.zalloc := NIL; { alloc_func(0); } 69 | stream.zfree := NIL; { free_func(0); } 70 | 71 | err := inflateInit(stream); 72 | if (err <> Z_OK) then 73 | begin 74 | uncompress := err; 75 | exit; 76 | end; 77 | 78 | err := inflate(stream, Z_FINISH); 79 | if (err <> Z_STREAM_END) then 80 | begin 81 | inflateEnd(stream); 82 | if err = Z_OK then 83 | uncompress := Z_BUF_ERROR 84 | else 85 | uncompress := err; 86 | exit; 87 | end; 88 | destLen := stream.total_out; 89 | 90 | err := inflateEnd(stream); 91 | uncompress := err; 92 | end; 93 | 94 | end. -------------------------------------------------------------------------------- /Source/ZLib/paszlib/zconf.inc: -------------------------------------------------------------------------------- 1 | { -------------------------------------------------------------------- } 2 | 3 | { 4 | Modified 04/2015 by David J Butler for inclusion in Fundamentals library. 5 | } 6 | 7 | {$INCLUDE ..\..\cFundamentals.inc} 8 | 9 | { -------------------------------------------------------------------- } 10 | 11 | { 12 | Modifiied 02/2003 by Sergey A. Galin for Delphi 6+ and Kylix compatibility. 13 | See README in directory above for more information. 14 | } 15 | 16 | 17 | {$DEFINE X32} 18 | {$DEFINE Delphi32} 19 | {$DEFINE Delphi} 20 | {$DEFINE Kylix} 21 | 22 | {$WARN UNSAFE_CODE OFF} 23 | {$WARN UNSAFE_TYPE OFF} 24 | 25 | {$DEFINE MAX_MATCH_IS_258} 26 | 27 | {$IFNDEF X32} 28 | {$DEFINE UNALIGNED_OK} { requires SizeOf(ush) = 2 ! } 29 | {$ENDIF} 30 | 31 | {$UNDEF DYNAMIC_CRC_TABLE} 32 | {$UNDEF FASTEST} 33 | {$DEFINE patch112} { apply patch from the zlib home page } 34 | 35 | { -------------------------------------------------------------------- } 36 | 37 | -------------------------------------------------------------------------------- /Source/ZLib/zlib123/Compile.bat: -------------------------------------------------------------------------------- 1 | bcc32 -c -6 -O2 -Ve -X -pr -a8 -b -d -k- -vi -tWM -r -RT- -ff *.c -------------------------------------------------------------------------------- /Source/ZLib/zlib123/adler32.c: -------------------------------------------------------------------------------- 1 | /* adler32.c -- compute the Adler-32 checksum of a data stream 2 | * Copyright (C) 1995-2004 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #define ZLIB_INTERNAL 9 | #include "zlib.h" 10 | 11 | #define BASE 65521UL /* largest prime smaller than 65536 */ 12 | #define NMAX 5552 13 | /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ 14 | 15 | #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;} 16 | #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); 17 | #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); 18 | #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); 19 | #define DO16(buf) DO8(buf,0); DO8(buf,8); 20 | 21 | /* use NO_DIVIDE if your processor does not do division in hardware */ 22 | #ifdef NO_DIVIDE 23 | # define MOD(a) \ 24 | do { \ 25 | if (a >= (BASE << 16)) a -= (BASE << 16); \ 26 | if (a >= (BASE << 15)) a -= (BASE << 15); \ 27 | if (a >= (BASE << 14)) a -= (BASE << 14); \ 28 | if (a >= (BASE << 13)) a -= (BASE << 13); \ 29 | if (a >= (BASE << 12)) a -= (BASE << 12); \ 30 | if (a >= (BASE << 11)) a -= (BASE << 11); \ 31 | if (a >= (BASE << 10)) a -= (BASE << 10); \ 32 | if (a >= (BASE << 9)) a -= (BASE << 9); \ 33 | if (a >= (BASE << 8)) a -= (BASE << 8); \ 34 | if (a >= (BASE << 7)) a -= (BASE << 7); \ 35 | if (a >= (BASE << 6)) a -= (BASE << 6); \ 36 | if (a >= (BASE << 5)) a -= (BASE << 5); \ 37 | if (a >= (BASE << 4)) a -= (BASE << 4); \ 38 | if (a >= (BASE << 3)) a -= (BASE << 3); \ 39 | if (a >= (BASE << 2)) a -= (BASE << 2); \ 40 | if (a >= (BASE << 1)) a -= (BASE << 1); \ 41 | if (a >= BASE) a -= BASE; \ 42 | } while (0) 43 | # define MOD4(a) \ 44 | do { \ 45 | if (a >= (BASE << 4)) a -= (BASE << 4); \ 46 | if (a >= (BASE << 3)) a -= (BASE << 3); \ 47 | if (a >= (BASE << 2)) a -= (BASE << 2); \ 48 | if (a >= (BASE << 1)) a -= (BASE << 1); \ 49 | if (a >= BASE) a -= BASE; \ 50 | } while (0) 51 | #else 52 | # define MOD(a) a %= BASE 53 | # define MOD4(a) a %= BASE 54 | #endif 55 | 56 | /* ========================================================================= */ 57 | uLong ZEXPORT adler32(adler, buf, len) 58 | uLong adler; 59 | const Bytef *buf; 60 | uInt len; 61 | { 62 | unsigned long sum2; 63 | unsigned n; 64 | 65 | /* split Adler-32 into component sums */ 66 | sum2 = (adler >> 16) & 0xffff; 67 | adler &= 0xffff; 68 | 69 | /* in case user likes doing a byte at a time, keep it fast */ 70 | if (len == 1) { 71 | adler += buf[0]; 72 | if (adler >= BASE) 73 | adler -= BASE; 74 | sum2 += adler; 75 | if (sum2 >= BASE) 76 | sum2 -= BASE; 77 | return adler | (sum2 << 16); 78 | } 79 | 80 | /* initial Adler-32 value (deferred check for len == 1 speed) */ 81 | if (buf == Z_NULL) 82 | return 1L; 83 | 84 | /* in case short lengths are provided, keep it somewhat fast */ 85 | if (len < 16) { 86 | while (len--) { 87 | adler += *buf++; 88 | sum2 += adler; 89 | } 90 | if (adler >= BASE) 91 | adler -= BASE; 92 | MOD4(sum2); /* only added so many BASE's */ 93 | return adler | (sum2 << 16); 94 | } 95 | 96 | /* do length NMAX blocks -- requires just one modulo operation */ 97 | while (len >= NMAX) { 98 | len -= NMAX; 99 | n = NMAX / 16; /* NMAX is divisible by 16 */ 100 | do { 101 | DO16(buf); /* 16 sums unrolled */ 102 | buf += 16; 103 | } while (--n); 104 | MOD(adler); 105 | MOD(sum2); 106 | } 107 | 108 | /* do remaining bytes (less than NMAX, still just one modulo) */ 109 | if (len) { /* avoid modulos if none remaining */ 110 | while (len >= 16) { 111 | len -= 16; 112 | DO16(buf); 113 | buf += 16; 114 | } 115 | while (len--) { 116 | adler += *buf++; 117 | sum2 += adler; 118 | } 119 | MOD(adler); 120 | MOD(sum2); 121 | } 122 | 123 | /* return recombined sums */ 124 | return adler | (sum2 << 16); 125 | } 126 | 127 | /* ========================================================================= */ 128 | uLong ZEXPORT adler32_combine(adler1, adler2, len2) 129 | uLong adler1; 130 | uLong adler2; 131 | z_off_t len2; 132 | { 133 | unsigned long sum1; 134 | unsigned long sum2; 135 | unsigned rem; 136 | 137 | /* the derivation of this formula is left as an exercise for the reader */ 138 | rem = (unsigned)(len2 % BASE); 139 | sum1 = adler1 & 0xffff; 140 | sum2 = rem * sum1; 141 | MOD(sum2); 142 | sum1 += (adler2 & 0xffff) + BASE - 1; 143 | sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem; 144 | if (sum1 > BASE) sum1 -= BASE; 145 | if (sum1 > BASE) sum1 -= BASE; 146 | if (sum2 > (BASE << 1)) sum2 -= (BASE << 1); 147 | if (sum2 > BASE) sum2 -= BASE; 148 | return sum1 | (sum2 << 16); 149 | } 150 | -------------------------------------------------------------------------------- /Source/ZLib/zlib123/adler32.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/ZLib/zlib123/adler32.obj -------------------------------------------------------------------------------- /Source/ZLib/zlib123/compress.c: -------------------------------------------------------------------------------- 1 | /* compress.c -- compress a memory buffer 2 | * Copyright (C) 1995-2003 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #define ZLIB_INTERNAL 9 | #include "zlib.h" 10 | 11 | /* =========================================================================== 12 | Compresses the source buffer into the destination buffer. The level 13 | parameter has the same meaning as in deflateInit. sourceLen is the byte 14 | length of the source buffer. Upon entry, destLen is the total size of the 15 | destination buffer, which must be at least 0.1% larger than sourceLen plus 16 | 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. 17 | 18 | compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 19 | memory, Z_BUF_ERROR if there was not enough room in the output buffer, 20 | Z_STREAM_ERROR if the level parameter is invalid. 21 | */ 22 | int ZEXPORT compress2 (dest, destLen, source, sourceLen, level) 23 | Bytef *dest; 24 | uLongf *destLen; 25 | const Bytef *source; 26 | uLong sourceLen; 27 | int level; 28 | { 29 | z_stream stream; 30 | int err; 31 | 32 | stream.next_in = (Bytef*)source; 33 | stream.avail_in = (uInt)sourceLen; 34 | #ifdef MAXSEG_64K 35 | /* Check for source > 64K on 16-bit machine: */ 36 | if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; 37 | #endif 38 | stream.next_out = dest; 39 | stream.avail_out = (uInt)*destLen; 40 | if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; 41 | 42 | stream.zalloc = (alloc_func)0; 43 | stream.zfree = (free_func)0; 44 | stream.opaque = (voidpf)0; 45 | 46 | err = deflateInit(&stream, level); 47 | if (err != Z_OK) return err; 48 | 49 | err = deflate(&stream, Z_FINISH); 50 | if (err != Z_STREAM_END) { 51 | deflateEnd(&stream); 52 | return err == Z_OK ? Z_BUF_ERROR : err; 53 | } 54 | *destLen = stream.total_out; 55 | 56 | err = deflateEnd(&stream); 57 | return err; 58 | } 59 | 60 | /* =========================================================================== 61 | */ 62 | int ZEXPORT compress (dest, destLen, source, sourceLen) 63 | Bytef *dest; 64 | uLongf *destLen; 65 | const Bytef *source; 66 | uLong sourceLen; 67 | { 68 | return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); 69 | } 70 | 71 | /* =========================================================================== 72 | If the default memLevel or windowBits for deflateInit() is changed, then 73 | this function needs to be updated. 74 | */ 75 | uLong ZEXPORT compressBound (sourceLen) 76 | uLong sourceLen; 77 | { 78 | return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11; 79 | } 80 | -------------------------------------------------------------------------------- /Source/ZLib/zlib123/compress.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/ZLib/zlib123/compress.obj -------------------------------------------------------------------------------- /Source/ZLib/zlib123/crc32.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/ZLib/zlib123/crc32.obj -------------------------------------------------------------------------------- /Source/ZLib/zlib123/deflate.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/ZLib/zlib123/deflate.obj -------------------------------------------------------------------------------- /Source/ZLib/zlib123/gzio.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/ZLib/zlib123/gzio.obj -------------------------------------------------------------------------------- /Source/ZLib/zlib123/infback.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/ZLib/zlib123/infback.obj -------------------------------------------------------------------------------- /Source/ZLib/zlib123/inffast.h: -------------------------------------------------------------------------------- 1 | /* inffast.h -- header to use inffast.c 2 | * Copyright (C) 1995-2003 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | void inflate_fast OF((z_streamp strm, unsigned start)); 12 | -------------------------------------------------------------------------------- /Source/ZLib/zlib123/inffast.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/ZLib/zlib123/inffast.obj -------------------------------------------------------------------------------- /Source/ZLib/zlib123/inffixed.h: -------------------------------------------------------------------------------- 1 | /* inffixed.h -- table for decoding fixed codes 2 | * Generated automatically by makefixed(). 3 | */ 4 | 5 | /* WARNING: this file should *not* be used by applications. It 6 | is part of the implementation of the compression library and 7 | is subject to change. Applications should only use zlib.h. 8 | */ 9 | 10 | static const code lenfix[512] = { 11 | {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, 12 | {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, 13 | {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, 14 | {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176}, 15 | {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20}, 16 | {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100}, 17 | {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8}, 18 | {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216}, 19 | {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76}, 20 | {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114}, 21 | {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2}, 22 | {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148}, 23 | {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42}, 24 | {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86}, 25 | {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15}, 26 | {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236}, 27 | {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62}, 28 | {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142}, 29 | {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31}, 30 | {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162}, 31 | {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25}, 32 | {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105}, 33 | {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4}, 34 | {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202}, 35 | {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69}, 36 | {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125}, 37 | {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13}, 38 | {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195}, 39 | {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35}, 40 | {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91}, 41 | {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19}, 42 | {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246}, 43 | {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55}, 44 | {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135}, 45 | {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99}, 46 | {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190}, 47 | {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16}, 48 | {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96}, 49 | {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6}, 50 | {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209}, 51 | {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72}, 52 | {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116}, 53 | {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4}, 54 | {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153}, 55 | {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44}, 56 | {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82}, 57 | {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11}, 58 | {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229}, 59 | {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58}, 60 | {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138}, 61 | {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51}, 62 | {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173}, 63 | {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30}, 64 | {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110}, 65 | {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0}, 66 | {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195}, 67 | {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65}, 68 | {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121}, 69 | {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9}, 70 | {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258}, 71 | {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37}, 72 | {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93}, 73 | {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23}, 74 | {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251}, 75 | {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51}, 76 | {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131}, 77 | {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67}, 78 | {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183}, 79 | {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23}, 80 | {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103}, 81 | {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9}, 82 | {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223}, 83 | {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79}, 84 | {0,9,255} 85 | }; 86 | 87 | static const code distfix[32] = { 88 | {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, 89 | {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, 90 | {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, 91 | {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577}, 92 | {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073}, 93 | {22,5,193},{64,5,0} 94 | }; 95 | -------------------------------------------------------------------------------- /Source/ZLib/zlib123/inflate.h: -------------------------------------------------------------------------------- 1 | /* inflate.h -- internal inflate state definition 2 | * Copyright (C) 1995-2004 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* define NO_GZIP when compiling if you want to disable gzip header and 12 | trailer decoding by inflate(). NO_GZIP would be used to avoid linking in 13 | the crc code when it is not needed. For shared libraries, gzip decoding 14 | should be left enabled. */ 15 | #ifndef NO_GZIP 16 | # define GUNZIP 17 | #endif 18 | 19 | /* Possible inflate modes between inflate() calls */ 20 | typedef enum { 21 | HEAD, /* i: waiting for magic header */ 22 | FLAGS, /* i: waiting for method and flags (gzip) */ 23 | TIME, /* i: waiting for modification time (gzip) */ 24 | OS, /* i: waiting for extra flags and operating system (gzip) */ 25 | EXLEN, /* i: waiting for extra length (gzip) */ 26 | EXTRA, /* i: waiting for extra bytes (gzip) */ 27 | NAME, /* i: waiting for end of file name (gzip) */ 28 | COMMENT, /* i: waiting for end of comment (gzip) */ 29 | HCRC, /* i: waiting for header crc (gzip) */ 30 | DICTID, /* i: waiting for dictionary check value */ 31 | DICT, /* waiting for inflateSetDictionary() call */ 32 | TYPE, /* i: waiting for type bits, including last-flag bit */ 33 | TYPEDO, /* i: same, but skip check to exit inflate on new block */ 34 | STORED, /* i: waiting for stored size (length and complement) */ 35 | COPY, /* i/o: waiting for input or output to copy stored block */ 36 | TABLE, /* i: waiting for dynamic block table lengths */ 37 | LENLENS, /* i: waiting for code length code lengths */ 38 | CODELENS, /* i: waiting for length/lit and distance code lengths */ 39 | LEN, /* i: waiting for length/lit code */ 40 | LENEXT, /* i: waiting for length extra bits */ 41 | DIST, /* i: waiting for distance code */ 42 | DISTEXT, /* i: waiting for distance extra bits */ 43 | MATCH, /* o: waiting for output space to copy string */ 44 | LIT, /* o: waiting for output space to write literal */ 45 | CHECK, /* i: waiting for 32-bit check value */ 46 | LENGTH, /* i: waiting for 32-bit length (gzip) */ 47 | DONE, /* finished check, done -- remain here until reset */ 48 | BAD, /* got a data error -- remain here until reset */ 49 | MEM, /* got an inflate() memory error -- remain here until reset */ 50 | SYNC /* looking for synchronization bytes to restart inflate() */ 51 | } inflate_mode; 52 | 53 | /* 54 | State transitions between above modes - 55 | 56 | (most modes can go to the BAD or MEM mode -- not shown for clarity) 57 | 58 | Process header: 59 | HEAD -> (gzip) or (zlib) 60 | (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME 61 | NAME -> COMMENT -> HCRC -> TYPE 62 | (zlib) -> DICTID or TYPE 63 | DICTID -> DICT -> TYPE 64 | Read deflate blocks: 65 | TYPE -> STORED or TABLE or LEN or CHECK 66 | STORED -> COPY -> TYPE 67 | TABLE -> LENLENS -> CODELENS -> LEN 68 | Read deflate codes: 69 | LEN -> LENEXT or LIT or TYPE 70 | LENEXT -> DIST -> DISTEXT -> MATCH -> LEN 71 | LIT -> LEN 72 | Process trailer: 73 | CHECK -> LENGTH -> DONE 74 | */ 75 | 76 | /* state maintained between inflate() calls. Approximately 7K bytes. */ 77 | struct inflate_state { 78 | inflate_mode mode; /* current inflate mode */ 79 | int last; /* true if processing last block */ 80 | int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ 81 | int havedict; /* true if dictionary provided */ 82 | int flags; /* gzip header method and flags (0 if zlib) */ 83 | unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */ 84 | unsigned long check; /* protected copy of check value */ 85 | unsigned long total; /* protected copy of output count */ 86 | gz_headerp head; /* where to save gzip header information */ 87 | /* sliding window */ 88 | unsigned wbits; /* log base 2 of requested window size */ 89 | unsigned wsize; /* window size or zero if not using window */ 90 | unsigned whave; /* valid bytes in the window */ 91 | unsigned write; /* window write index */ 92 | unsigned char FAR *window; /* allocated sliding window, if needed */ 93 | /* bit accumulator */ 94 | unsigned long hold; /* input bit accumulator */ 95 | unsigned bits; /* number of bits in "in" */ 96 | /* for string and stored block copying */ 97 | unsigned length; /* literal or length of data to copy */ 98 | unsigned offset; /* distance back to copy string from */ 99 | /* for table and code decoding */ 100 | unsigned extra; /* extra bits needed */ 101 | /* fixed and dynamic code tables */ 102 | code const FAR *lencode; /* starting table for length/literal codes */ 103 | code const FAR *distcode; /* starting table for distance codes */ 104 | unsigned lenbits; /* index bits for lencode */ 105 | unsigned distbits; /* index bits for distcode */ 106 | /* dynamic table building */ 107 | unsigned ncode; /* number of code length code lengths */ 108 | unsigned nlen; /* number of length code lengths */ 109 | unsigned ndist; /* number of distance code lengths */ 110 | unsigned have; /* number of code lengths in lens[] */ 111 | code FAR *next; /* next available space in codes[] */ 112 | unsigned short lens[320]; /* temporary storage for code lengths */ 113 | unsigned short work[288]; /* work area for code table building */ 114 | code codes[ENOUGH]; /* space for code tables */ 115 | }; 116 | -------------------------------------------------------------------------------- /Source/ZLib/zlib123/inflate.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/ZLib/zlib123/inflate.obj -------------------------------------------------------------------------------- /Source/ZLib/zlib123/inftrees.h: -------------------------------------------------------------------------------- 1 | /* inftrees.h -- header to use inftrees.c 2 | * Copyright (C) 1995-2005 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* Structure for decoding tables. Each entry provides either the 12 | information needed to do the operation requested by the code that 13 | indexed that table entry, or it provides a pointer to another 14 | table that indexes more bits of the code. op indicates whether 15 | the entry is a pointer to another table, a literal, a length or 16 | distance, an end-of-block, or an invalid code. For a table 17 | pointer, the low four bits of op is the number of index bits of 18 | that table. For a length or distance, the low four bits of op 19 | is the number of extra bits to get after the code. bits is 20 | the number of bits in this code or part of the code to drop off 21 | of the bit buffer. val is the actual byte to output in the case 22 | of a literal, the base length or distance, or the offset from 23 | the current table to the next table. Each entry is four bytes. */ 24 | typedef struct { 25 | unsigned char op; /* operation, extra bits, table bits */ 26 | unsigned char bits; /* bits in this part of the code */ 27 | unsigned short val; /* offset in table or code value */ 28 | } code; 29 | 30 | /* op values as set by inflate_table(): 31 | 00000000 - literal 32 | 0000tttt - table link, tttt != 0 is the number of table index bits 33 | 0001eeee - length or distance, eeee is the number of extra bits 34 | 01100000 - end of block 35 | 01000000 - invalid code 36 | */ 37 | 38 | /* Maximum size of dynamic tree. The maximum found in a long but non- 39 | exhaustive search was 1444 code structures (852 for length/literals 40 | and 592 for distances, the latter actually the result of an 41 | exhaustive search). The true maximum is not known, but the value 42 | below is more than safe. */ 43 | #define ENOUGH 2048 44 | #define MAXD 592 45 | 46 | /* Type of code to build for inftable() */ 47 | typedef enum { 48 | CODES, 49 | LENS, 50 | DISTS 51 | } codetype; 52 | 53 | extern int inflate_table OF((codetype type, unsigned short FAR *lens, 54 | unsigned codes, code FAR * FAR *table, 55 | unsigned FAR *bits, unsigned short FAR *work)); 56 | -------------------------------------------------------------------------------- /Source/ZLib/zlib123/inftrees.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/ZLib/zlib123/inftrees.obj -------------------------------------------------------------------------------- /Source/ZLib/zlib123/minigzip.c: -------------------------------------------------------------------------------- 1 | /* minigzip.c -- simulate gzip using the zlib compression library 2 | * Copyright (C) 1995-2005 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* 7 | * minigzip is a minimal implementation of the gzip utility. This is 8 | * only an example of using zlib and isn't meant to replace the 9 | * full-featured gzip. No attempt is made to deal with file systems 10 | * limiting names to 14 or 8+3 characters, etc... Error checking is 11 | * very limited. So use minigzip only for testing; use gzip for the 12 | * real thing. On MSDOS, use only on file names without extension 13 | * or in pipe mode. 14 | */ 15 | 16 | /* @(#) $Id$ */ 17 | 18 | #include 19 | #include "zlib.h" 20 | 21 | #ifdef STDC 22 | # include 23 | # include 24 | #endif 25 | 26 | #ifdef USE_MMAP 27 | # include 28 | # include 29 | # include 30 | #endif 31 | 32 | #if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__) 33 | # include 34 | # include 35 | # define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) 36 | #else 37 | # define SET_BINARY_MODE(file) 38 | #endif 39 | 40 | #ifdef VMS 41 | # define unlink delete 42 | # define GZ_SUFFIX "-gz" 43 | #endif 44 | #ifdef RISCOS 45 | # define unlink remove 46 | # define GZ_SUFFIX "-gz" 47 | # define fileno(file) file->__file 48 | #endif 49 | #if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os 50 | # include /* for fileno */ 51 | #endif 52 | 53 | #ifndef WIN32 /* unlink already in stdio.h for WIN32 */ 54 | extern int unlink OF((const char *)); 55 | #endif 56 | 57 | #ifndef GZ_SUFFIX 58 | # define GZ_SUFFIX ".gz" 59 | #endif 60 | #define SUFFIX_LEN (sizeof(GZ_SUFFIX)-1) 61 | 62 | #define BUFLEN 16384 63 | #define MAX_NAME_LEN 1024 64 | 65 | #ifdef MAXSEG_64K 66 | # define local static 67 | /* Needed for systems with limitation on stack size. */ 68 | #else 69 | # define local 70 | #endif 71 | 72 | char *prog; 73 | 74 | void error OF((const char *msg)); 75 | void gz_compress OF((FILE *in, gzFile out)); 76 | #ifdef USE_MMAP 77 | int gz_compress_mmap OF((FILE *in, gzFile out)); 78 | #endif 79 | void gz_uncompress OF((gzFile in, FILE *out)); 80 | void file_compress OF((char *file, char *mode)); 81 | void file_uncompress OF((char *file)); 82 | int main OF((int argc, char *argv[])); 83 | 84 | /* =========================================================================== 85 | * Display error message and exit 86 | */ 87 | void error(msg) 88 | const char *msg; 89 | { 90 | fprintf(stderr, "%s: %s\n", prog, msg); 91 | exit(1); 92 | } 93 | 94 | /* =========================================================================== 95 | * Compress input to output then close both files. 96 | */ 97 | 98 | void gz_compress(in, out) 99 | FILE *in; 100 | gzFile out; 101 | { 102 | local char buf[BUFLEN]; 103 | int len; 104 | int err; 105 | 106 | #ifdef USE_MMAP 107 | /* Try first compressing with mmap. If mmap fails (minigzip used in a 108 | * pipe), use the normal fread loop. 109 | */ 110 | if (gz_compress_mmap(in, out) == Z_OK) return; 111 | #endif 112 | for (;;) { 113 | len = (int)fread(buf, 1, sizeof(buf), in); 114 | if (ferror(in)) { 115 | perror("fread"); 116 | exit(1); 117 | } 118 | if (len == 0) break; 119 | 120 | if (gzwrite(out, buf, (unsigned)len) != len) error(gzerror(out, &err)); 121 | } 122 | fclose(in); 123 | if (gzclose(out) != Z_OK) error("failed gzclose"); 124 | } 125 | 126 | #ifdef USE_MMAP /* MMAP version, Miguel Albrecht */ 127 | 128 | /* Try compressing the input file at once using mmap. Return Z_OK if 129 | * if success, Z_ERRNO otherwise. 130 | */ 131 | int gz_compress_mmap(in, out) 132 | FILE *in; 133 | gzFile out; 134 | { 135 | int len; 136 | int err; 137 | int ifd = fileno(in); 138 | caddr_t buf; /* mmap'ed buffer for the entire input file */ 139 | off_t buf_len; /* length of the input file */ 140 | struct stat sb; 141 | 142 | /* Determine the size of the file, needed for mmap: */ 143 | if (fstat(ifd, &sb) < 0) return Z_ERRNO; 144 | buf_len = sb.st_size; 145 | if (buf_len <= 0) return Z_ERRNO; 146 | 147 | /* Now do the actual mmap: */ 148 | buf = mmap((caddr_t) 0, buf_len, PROT_READ, MAP_SHARED, ifd, (off_t)0); 149 | if (buf == (caddr_t)(-1)) return Z_ERRNO; 150 | 151 | /* Compress the whole file at once: */ 152 | len = gzwrite(out, (char *)buf, (unsigned)buf_len); 153 | 154 | if (len != (int)buf_len) error(gzerror(out, &err)); 155 | 156 | munmap(buf, buf_len); 157 | fclose(in); 158 | if (gzclose(out) != Z_OK) error("failed gzclose"); 159 | return Z_OK; 160 | } 161 | #endif /* USE_MMAP */ 162 | 163 | /* =========================================================================== 164 | * Uncompress input to output then close both files. 165 | */ 166 | void gz_uncompress(in, out) 167 | gzFile in; 168 | FILE *out; 169 | { 170 | local char buf[BUFLEN]; 171 | int len; 172 | int err; 173 | 174 | for (;;) { 175 | len = gzread(in, buf, sizeof(buf)); 176 | if (len < 0) error (gzerror(in, &err)); 177 | if (len == 0) break; 178 | 179 | if ((int)fwrite(buf, 1, (unsigned)len, out) != len) { 180 | error("failed fwrite"); 181 | } 182 | } 183 | if (fclose(out)) error("failed fclose"); 184 | 185 | if (gzclose(in) != Z_OK) error("failed gzclose"); 186 | } 187 | 188 | 189 | /* =========================================================================== 190 | * Compress the given file: create a corresponding .gz file and remove the 191 | * original. 192 | */ 193 | void file_compress(file, mode) 194 | char *file; 195 | char *mode; 196 | { 197 | local char outfile[MAX_NAME_LEN]; 198 | FILE *in; 199 | gzFile out; 200 | 201 | strcpy(outfile, file); 202 | strcat(outfile, GZ_SUFFIX); 203 | 204 | in = fopen(file, "rb"); 205 | if (in == NULL) { 206 | perror(file); 207 | exit(1); 208 | } 209 | out = gzopen(outfile, mode); 210 | if (out == NULL) { 211 | fprintf(stderr, "%s: can't gzopen %s\n", prog, outfile); 212 | exit(1); 213 | } 214 | gz_compress(in, out); 215 | 216 | unlink(file); 217 | } 218 | 219 | 220 | /* =========================================================================== 221 | * Uncompress the given file and remove the original. 222 | */ 223 | void file_uncompress(file) 224 | char *file; 225 | { 226 | local char buf[MAX_NAME_LEN]; 227 | char *infile, *outfile; 228 | FILE *out; 229 | gzFile in; 230 | uInt len = (uInt)strlen(file); 231 | 232 | strcpy(buf, file); 233 | 234 | if (len > SUFFIX_LEN && strcmp(file+len-SUFFIX_LEN, GZ_SUFFIX) == 0) { 235 | infile = file; 236 | outfile = buf; 237 | outfile[len-3] = '\0'; 238 | } else { 239 | outfile = file; 240 | infile = buf; 241 | strcat(infile, GZ_SUFFIX); 242 | } 243 | in = gzopen(infile, "rb"); 244 | if (in == NULL) { 245 | fprintf(stderr, "%s: can't gzopen %s\n", prog, infile); 246 | exit(1); 247 | } 248 | out = fopen(outfile, "wb"); 249 | if (out == NULL) { 250 | perror(file); 251 | exit(1); 252 | } 253 | 254 | gz_uncompress(in, out); 255 | 256 | unlink(infile); 257 | } 258 | 259 | 260 | /* =========================================================================== 261 | * Usage: minigzip [-d] [-f] [-h] [-r] [-1 to -9] [files...] 262 | * -d : decompress 263 | * -f : compress with Z_FILTERED 264 | * -h : compress with Z_HUFFMAN_ONLY 265 | * -r : compress with Z_RLE 266 | * -1 to -9 : compression level 267 | */ 268 | 269 | int main(argc, argv) 270 | int argc; 271 | char *argv[]; 272 | { 273 | int uncompr = 0; 274 | gzFile file; 275 | char outmode[20]; 276 | 277 | strcpy(outmode, "wb6 "); 278 | 279 | prog = argv[0]; 280 | argc--, argv++; 281 | 282 | while (argc > 0) { 283 | if (strcmp(*argv, "-d") == 0) 284 | uncompr = 1; 285 | else if (strcmp(*argv, "-f") == 0) 286 | outmode[3] = 'f'; 287 | else if (strcmp(*argv, "-h") == 0) 288 | outmode[3] = 'h'; 289 | else if (strcmp(*argv, "-r") == 0) 290 | outmode[3] = 'R'; 291 | else if ((*argv)[0] == '-' && (*argv)[1] >= '1' && (*argv)[1] <= '9' && 292 | (*argv)[2] == 0) 293 | outmode[2] = (*argv)[1]; 294 | else 295 | break; 296 | argc--, argv++; 297 | } 298 | if (outmode[3] == ' ') 299 | outmode[3] = 0; 300 | if (argc == 0) { 301 | SET_BINARY_MODE(stdin); 302 | SET_BINARY_MODE(stdout); 303 | if (uncompr) { 304 | file = gzdopen(fileno(stdin), "rb"); 305 | if (file == NULL) error("can't gzdopen stdin"); 306 | gz_uncompress(file, stdout); 307 | } else { 308 | file = gzdopen(fileno(stdout), outmode); 309 | if (file == NULL) error("can't gzdopen stdout"); 310 | gz_compress(stdin, file); 311 | } 312 | } else { 313 | do { 314 | if (uncompr) { 315 | file_uncompress(*argv); 316 | } else { 317 | file_compress(*argv, outmode); 318 | } 319 | } while (argv++, --argc); 320 | } 321 | return 0; 322 | } 323 | -------------------------------------------------------------------------------- /Source/ZLib/zlib123/trees.h: -------------------------------------------------------------------------------- 1 | /* header created automatically with -DGEN_TREES_H */ 2 | 3 | local const ct_data static_ltree[L_CODES+2] = { 4 | {{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}}, 5 | {{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}}, 6 | {{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}}, 7 | {{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}}, 8 | {{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}}, 9 | {{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}}, 10 | {{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}}, 11 | {{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}}, 12 | {{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}}, 13 | {{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}}, 14 | {{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}}, 15 | {{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}}, 16 | {{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}}, 17 | {{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}}, 18 | {{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}}, 19 | {{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}}, 20 | {{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}}, 21 | {{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}}, 22 | {{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}}, 23 | {{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}}, 24 | {{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}}, 25 | {{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}}, 26 | {{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}}, 27 | {{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}}, 28 | {{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}}, 29 | {{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}}, 30 | {{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}}, 31 | {{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}}, 32 | {{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}}, 33 | {{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}}, 34 | {{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}}, 35 | {{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}}, 36 | {{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}}, 37 | {{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}}, 38 | {{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}}, 39 | {{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}}, 40 | {{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}}, 41 | {{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}}, 42 | {{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}}, 43 | {{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}}, 44 | {{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}}, 45 | {{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}}, 46 | {{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}}, 47 | {{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}}, 48 | {{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}}, 49 | {{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}}, 50 | {{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}}, 51 | {{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}}, 52 | {{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}}, 53 | {{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}}, 54 | {{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}}, 55 | {{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}}, 56 | {{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}}, 57 | {{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}}, 58 | {{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}}, 59 | {{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}}, 60 | {{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}}, 61 | {{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}} 62 | }; 63 | 64 | local const ct_data static_dtree[D_CODES] = { 65 | {{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}}, 66 | {{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}}, 67 | {{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}}, 68 | {{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}}, 69 | {{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}}, 70 | {{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}} 71 | }; 72 | 73 | const uch _dist_code[DIST_CODE_LEN] = { 74 | 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 75 | 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 76 | 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 77 | 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 78 | 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 79 | 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 80 | 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 81 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 82 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 83 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 84 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 85 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 86 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17, 87 | 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 88 | 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 89 | 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 90 | 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 91 | 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 92 | 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 93 | 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 94 | 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 95 | 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 96 | 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 97 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 98 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 99 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29 100 | }; 101 | 102 | const uch _length_code[MAX_MATCH-MIN_MATCH+1]= { 103 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12, 104 | 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 105 | 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 106 | 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 107 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 108 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, 109 | 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 110 | 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 111 | 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 112 | 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, 113 | 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 114 | 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 115 | 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28 116 | }; 117 | 118 | local const int base_length[LENGTH_CODES] = { 119 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, 120 | 64, 80, 96, 112, 128, 160, 192, 224, 0 121 | }; 122 | 123 | local const int base_dist[D_CODES] = { 124 | 0, 1, 2, 3, 4, 6, 8, 12, 16, 24, 125 | 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, 126 | 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576 127 | }; 128 | 129 | -------------------------------------------------------------------------------- /Source/ZLib/zlib123/trees.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/ZLib/zlib123/trees.obj -------------------------------------------------------------------------------- /Source/ZLib/zlib123/uncompr.c: -------------------------------------------------------------------------------- 1 | /* uncompr.c -- decompress a memory buffer 2 | * Copyright (C) 1995-2003 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #define ZLIB_INTERNAL 9 | #include "zlib.h" 10 | 11 | /* =========================================================================== 12 | Decompresses the source buffer into the destination buffer. sourceLen is 13 | the byte length of the source buffer. Upon entry, destLen is the total 14 | size of the destination buffer, which must be large enough to hold the 15 | entire uncompressed data. (The size of the uncompressed data must have 16 | been saved previously by the compressor and transmitted to the decompressor 17 | by some mechanism outside the scope of this compression library.) 18 | Upon exit, destLen is the actual size of the compressed buffer. 19 | This function can be used to decompress a whole file at once if the 20 | input file is mmap'ed. 21 | 22 | uncompress returns Z_OK if success, Z_MEM_ERROR if there was not 23 | enough memory, Z_BUF_ERROR if there was not enough room in the output 24 | buffer, or Z_DATA_ERROR if the input data was corrupted. 25 | */ 26 | int ZEXPORT uncompress (dest, destLen, source, sourceLen) 27 | Bytef *dest; 28 | uLongf *destLen; 29 | const Bytef *source; 30 | uLong sourceLen; 31 | { 32 | z_stream stream; 33 | int err; 34 | 35 | stream.next_in = (Bytef*)source; 36 | stream.avail_in = (uInt)sourceLen; 37 | /* Check for source > 64K on 16-bit machine: */ 38 | if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; 39 | 40 | stream.next_out = dest; 41 | stream.avail_out = (uInt)*destLen; 42 | if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; 43 | 44 | stream.zalloc = (alloc_func)0; 45 | stream.zfree = (free_func)0; 46 | 47 | err = inflateInit(&stream); 48 | if (err != Z_OK) return err; 49 | 50 | err = inflate(&stream, Z_FINISH); 51 | if (err != Z_STREAM_END) { 52 | inflateEnd(&stream); 53 | if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) 54 | return Z_DATA_ERROR; 55 | return err; 56 | } 57 | *destLen = stream.total_out; 58 | 59 | err = inflateEnd(&stream); 60 | return err; 61 | } 62 | -------------------------------------------------------------------------------- /Source/ZLib/zlib123/uncompr.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/ZLib/zlib123/uncompr.obj -------------------------------------------------------------------------------- /Source/ZLib/zlib123/zutil.c: -------------------------------------------------------------------------------- 1 | /* zutil.c -- target dependent utility functions for the compression library 2 | * Copyright (C) 1995-2005 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #include "zutil.h" 9 | 10 | #ifndef NO_DUMMY_DECL 11 | struct internal_state {int dummy;}; /* for buggy compilers */ 12 | #endif 13 | 14 | const char * const z_errmsg[10] = { 15 | "need dictionary", /* Z_NEED_DICT 2 */ 16 | "stream end", /* Z_STREAM_END 1 */ 17 | "", /* Z_OK 0 */ 18 | "file error", /* Z_ERRNO (-1) */ 19 | "stream error", /* Z_STREAM_ERROR (-2) */ 20 | "data error", /* Z_DATA_ERROR (-3) */ 21 | "insufficient memory", /* Z_MEM_ERROR (-4) */ 22 | "buffer error", /* Z_BUF_ERROR (-5) */ 23 | "incompatible version",/* Z_VERSION_ERROR (-6) */ 24 | ""}; 25 | 26 | 27 | const char * ZEXPORT zlibVersion() 28 | { 29 | return ZLIB_VERSION; 30 | } 31 | 32 | uLong ZEXPORT zlibCompileFlags() 33 | { 34 | uLong flags; 35 | 36 | flags = 0; 37 | switch (sizeof(uInt)) { 38 | case 2: break; 39 | case 4: flags += 1; break; 40 | case 8: flags += 2; break; 41 | default: flags += 3; 42 | } 43 | switch (sizeof(uLong)) { 44 | case 2: break; 45 | case 4: flags += 1 << 2; break; 46 | case 8: flags += 2 << 2; break; 47 | default: flags += 3 << 2; 48 | } 49 | switch (sizeof(voidpf)) { 50 | case 2: break; 51 | case 4: flags += 1 << 4; break; 52 | case 8: flags += 2 << 4; break; 53 | default: flags += 3 << 4; 54 | } 55 | switch (sizeof(z_off_t)) { 56 | case 2: break; 57 | case 4: flags += 1 << 6; break; 58 | case 8: flags += 2 << 6; break; 59 | default: flags += 3 << 6; 60 | } 61 | #ifdef DEBUG 62 | flags += 1 << 8; 63 | #endif 64 | #if defined(ASMV) || defined(ASMINF) 65 | flags += 1 << 9; 66 | #endif 67 | #ifdef ZLIB_WINAPI 68 | flags += 1 << 10; 69 | #endif 70 | #ifdef BUILDFIXED 71 | flags += 1 << 12; 72 | #endif 73 | #ifdef DYNAMIC_CRC_TABLE 74 | flags += 1 << 13; 75 | #endif 76 | #ifdef NO_GZCOMPRESS 77 | flags += 1L << 16; 78 | #endif 79 | #ifdef NO_GZIP 80 | flags += 1L << 17; 81 | #endif 82 | #ifdef PKZIP_BUG_WORKAROUND 83 | flags += 1L << 20; 84 | #endif 85 | #ifdef FASTEST 86 | flags += 1L << 21; 87 | #endif 88 | #ifdef STDC 89 | # ifdef NO_vsnprintf 90 | flags += 1L << 25; 91 | # ifdef HAS_vsprintf_void 92 | flags += 1L << 26; 93 | # endif 94 | # else 95 | # ifdef HAS_vsnprintf_void 96 | flags += 1L << 26; 97 | # endif 98 | # endif 99 | #else 100 | flags += 1L << 24; 101 | # ifdef NO_snprintf 102 | flags += 1L << 25; 103 | # ifdef HAS_sprintf_void 104 | flags += 1L << 26; 105 | # endif 106 | # else 107 | # ifdef HAS_snprintf_void 108 | flags += 1L << 26; 109 | # endif 110 | # endif 111 | #endif 112 | return flags; 113 | } 114 | 115 | #ifdef DEBUG 116 | 117 | # ifndef verbose 118 | # define verbose 0 119 | # endif 120 | int z_verbose = verbose; 121 | 122 | void z_error (m) 123 | char *m; 124 | { 125 | fprintf(stderr, "%s\n", m); 126 | exit(1); 127 | } 128 | #endif 129 | 130 | /* exported to allow conversion of error code to string for compress() and 131 | * uncompress() 132 | */ 133 | const char * ZEXPORT zError(err) 134 | int err; 135 | { 136 | return ERR_MSG(err); 137 | } 138 | 139 | #if defined(_WIN32_WCE) 140 | /* The Microsoft C Run-Time Library for Windows CE doesn't have 141 | * errno. We define it as a global variable to simplify porting. 142 | * Its value is always 0 and should not be used. 143 | */ 144 | int errno = 0; 145 | #endif 146 | 147 | #ifndef HAVE_MEMCPY 148 | 149 | void zmemcpy(dest, source, len) 150 | Bytef* dest; 151 | const Bytef* source; 152 | uInt len; 153 | { 154 | if (len == 0) return; 155 | do { 156 | *dest++ = *source++; /* ??? to be unrolled */ 157 | } while (--len != 0); 158 | } 159 | 160 | int zmemcmp(s1, s2, len) 161 | const Bytef* s1; 162 | const Bytef* s2; 163 | uInt len; 164 | { 165 | uInt j; 166 | 167 | for (j = 0; j < len; j++) { 168 | if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1; 169 | } 170 | return 0; 171 | } 172 | 173 | void zmemzero(dest, len) 174 | Bytef* dest; 175 | uInt len; 176 | { 177 | if (len == 0) return; 178 | do { 179 | *dest++ = 0; /* ??? to be unrolled */ 180 | } while (--len != 0); 181 | } 182 | #endif 183 | 184 | 185 | #ifdef SYS16BIT 186 | 187 | #ifdef __TURBOC__ 188 | /* Turbo C in 16-bit mode */ 189 | 190 | # define MY_ZCALLOC 191 | 192 | /* Turbo C malloc() does not allow dynamic allocation of 64K bytes 193 | * and farmalloc(64K) returns a pointer with an offset of 8, so we 194 | * must fix the pointer. Warning: the pointer must be put back to its 195 | * original form in order to free it, use zcfree(). 196 | */ 197 | 198 | #define MAX_PTR 10 199 | /* 10*64K = 640K */ 200 | 201 | local int next_ptr = 0; 202 | 203 | typedef struct ptr_table_s { 204 | voidpf org_ptr; 205 | voidpf new_ptr; 206 | } ptr_table; 207 | 208 | local ptr_table table[MAX_PTR]; 209 | /* This table is used to remember the original form of pointers 210 | * to large buffers (64K). Such pointers are normalized with a zero offset. 211 | * Since MSDOS is not a preemptive multitasking OS, this table is not 212 | * protected from concurrent access. This hack doesn't work anyway on 213 | * a protected system like OS/2. Use Microsoft C instead. 214 | */ 215 | 216 | voidpf zcalloc (voidpf opaque, unsigned items, unsigned size) 217 | { 218 | voidpf buf = opaque; /* just to make some compilers happy */ 219 | ulg bsize = (ulg)items*size; 220 | 221 | /* If we allocate less than 65520 bytes, we assume that farmalloc 222 | * will return a usable pointer which doesn't have to be normalized. 223 | */ 224 | if (bsize < 65520L) { 225 | buf = farmalloc(bsize); 226 | if (*(ush*)&buf != 0) return buf; 227 | } else { 228 | buf = farmalloc(bsize + 16L); 229 | } 230 | if (buf == NULL || next_ptr >= MAX_PTR) return NULL; 231 | table[next_ptr].org_ptr = buf; 232 | 233 | /* Normalize the pointer to seg:0 */ 234 | *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4; 235 | *(ush*)&buf = 0; 236 | table[next_ptr++].new_ptr = buf; 237 | return buf; 238 | } 239 | 240 | void zcfree (voidpf opaque, voidpf ptr) 241 | { 242 | int n; 243 | if (*(ush*)&ptr != 0) { /* object < 64K */ 244 | farfree(ptr); 245 | return; 246 | } 247 | /* Find the original pointer */ 248 | for (n = 0; n < next_ptr; n++) { 249 | if (ptr != table[n].new_ptr) continue; 250 | 251 | farfree(table[n].org_ptr); 252 | while (++n < next_ptr) { 253 | table[n-1] = table[n]; 254 | } 255 | next_ptr--; 256 | return; 257 | } 258 | ptr = opaque; /* just to make some compilers happy */ 259 | Assert(0, "zcfree: ptr not found"); 260 | } 261 | 262 | #endif /* __TURBOC__ */ 263 | 264 | 265 | #ifdef M_I86 266 | /* Microsoft C in 16-bit mode */ 267 | 268 | # define MY_ZCALLOC 269 | 270 | #if (!defined(_MSC_VER) || (_MSC_VER <= 600)) 271 | # define _halloc halloc 272 | # define _hfree hfree 273 | #endif 274 | 275 | voidpf zcalloc (voidpf opaque, unsigned items, unsigned size) 276 | { 277 | if (opaque) opaque = 0; /* to make compiler happy */ 278 | return _halloc((long)items, size); 279 | } 280 | 281 | void zcfree (voidpf opaque, voidpf ptr) 282 | { 283 | if (opaque) opaque = 0; /* to make compiler happy */ 284 | _hfree(ptr); 285 | } 286 | 287 | #endif /* M_I86 */ 288 | 289 | #endif /* SYS16BIT */ 290 | 291 | 292 | #ifndef MY_ZCALLOC /* Any system without a special alloc function */ 293 | 294 | #ifndef STDC 295 | extern voidp malloc OF((uInt size)); 296 | extern voidp calloc OF((uInt items, uInt size)); 297 | extern void free OF((voidpf ptr)); 298 | #endif 299 | 300 | voidpf zcalloc (opaque, items, size) 301 | voidpf opaque; 302 | unsigned items; 303 | unsigned size; 304 | { 305 | if (opaque) items += size - size; /* make compiler happy */ 306 | return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : 307 | (voidpf)calloc(items, size); 308 | } 309 | 310 | void zcfree (opaque, ptr) 311 | voidpf opaque; 312 | voidpf ptr; 313 | { 314 | free(ptr); 315 | if (opaque) return; /* make compiler happy */ 316 | } 317 | 318 | #endif /* MY_ZCALLOC */ 319 | -------------------------------------------------------------------------------- /Source/ZLib/zlib123/zutil.h: -------------------------------------------------------------------------------- 1 | /* zutil.h -- internal interface and configuration of the compression library 2 | * Copyright (C) 1995-2005 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* @(#) $Id$ */ 12 | 13 | #ifndef ZUTIL_H 14 | #define ZUTIL_H 15 | 16 | #define ZLIB_INTERNAL 17 | #include "zlib.h" 18 | 19 | #ifdef STDC 20 | # ifndef _WIN32_WCE 21 | # include 22 | # endif 23 | # include 24 | # include 25 | #endif 26 | #ifdef NO_ERRNO_H 27 | # ifdef _WIN32_WCE 28 | /* The Microsoft C Run-Time Library for Windows CE doesn't have 29 | * errno. We define it as a global variable to simplify porting. 30 | * Its value is always 0 and should not be used. We rename it to 31 | * avoid conflict with other libraries that use the same workaround. 32 | */ 33 | # define errno z_errno 34 | # endif 35 | extern int errno; 36 | #else 37 | # ifndef _WIN32_WCE 38 | # include 39 | # endif 40 | #endif 41 | 42 | #ifndef local 43 | # define local static 44 | #endif 45 | /* compile with -Dlocal if your debugger can't find static symbols */ 46 | 47 | typedef unsigned char uch; 48 | typedef uch FAR uchf; 49 | typedef unsigned short ush; 50 | typedef ush FAR ushf; 51 | typedef unsigned long ulg; 52 | 53 | extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ 54 | /* (size given to avoid silly warnings with Visual C++) */ 55 | 56 | #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] 57 | 58 | #define ERR_RETURN(strm,err) \ 59 | return (strm->msg = (char*)ERR_MSG(err), (err)) 60 | /* To be used only when the state is known to be valid */ 61 | 62 | /* common constants */ 63 | 64 | #ifndef DEF_WBITS 65 | # define DEF_WBITS MAX_WBITS 66 | #endif 67 | /* default windowBits for decompression. MAX_WBITS is for compression only */ 68 | 69 | #if MAX_MEM_LEVEL >= 8 70 | # define DEF_MEM_LEVEL 8 71 | #else 72 | # define DEF_MEM_LEVEL MAX_MEM_LEVEL 73 | #endif 74 | /* default memLevel */ 75 | 76 | #define STORED_BLOCK 0 77 | #define STATIC_TREES 1 78 | #define DYN_TREES 2 79 | /* The three kinds of block type */ 80 | 81 | #define MIN_MATCH 3 82 | #define MAX_MATCH 258 83 | /* The minimum and maximum match lengths */ 84 | 85 | #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ 86 | 87 | /* target dependencies */ 88 | 89 | #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) 90 | # define OS_CODE 0x00 91 | # if defined(__TURBOC__) || defined(__BORLANDC__) 92 | # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) 93 | /* Allow compilation with ANSI keywords only enabled */ 94 | void _Cdecl farfree( void *block ); 95 | void *_Cdecl farmalloc( unsigned long nbytes ); 96 | # else 97 | # include 98 | # endif 99 | # else /* MSC or DJGPP */ 100 | # include 101 | # endif 102 | #endif 103 | 104 | #ifdef AMIGA 105 | # define OS_CODE 0x01 106 | #endif 107 | 108 | #if defined(VAXC) || defined(VMS) 109 | # define OS_CODE 0x02 110 | # define F_OPEN(name, mode) \ 111 | fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") 112 | #endif 113 | 114 | #if defined(ATARI) || defined(atarist) 115 | # define OS_CODE 0x05 116 | #endif 117 | 118 | #ifdef OS2 119 | # define OS_CODE 0x06 120 | # ifdef M_I86 121 | #include 122 | # endif 123 | #endif 124 | 125 | #if defined(MACOS) || defined(TARGET_OS_MAC) 126 | # define OS_CODE 0x07 127 | # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os 128 | # include /* for fdopen */ 129 | # else 130 | # ifndef fdopen 131 | # define fdopen(fd,mode) NULL /* No fdopen() */ 132 | # endif 133 | # endif 134 | #endif 135 | 136 | #ifdef TOPS20 137 | # define OS_CODE 0x0a 138 | #endif 139 | 140 | #ifdef WIN32 141 | # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */ 142 | # define OS_CODE 0x0b 143 | # endif 144 | #endif 145 | 146 | #ifdef __50SERIES /* Prime/PRIMOS */ 147 | # define OS_CODE 0x0f 148 | #endif 149 | 150 | #if defined(_BEOS_) || defined(RISCOS) 151 | # define fdopen(fd,mode) NULL /* No fdopen() */ 152 | #endif 153 | 154 | #if (defined(_MSC_VER) && (_MSC_VER > 600)) 155 | # if defined(_WIN32_WCE) 156 | # define fdopen(fd,mode) NULL /* No fdopen() */ 157 | # ifndef _PTRDIFF_T_DEFINED 158 | typedef int ptrdiff_t; 159 | # define _PTRDIFF_T_DEFINED 160 | # endif 161 | # else 162 | # define fdopen(fd,type) _fdopen(fd,type) 163 | # endif 164 | #endif 165 | 166 | /* common defaults */ 167 | 168 | #ifndef OS_CODE 169 | # define OS_CODE 0x03 /* assume Unix */ 170 | #endif 171 | 172 | #ifndef F_OPEN 173 | # define F_OPEN(name, mode) fopen((name), (mode)) 174 | #endif 175 | 176 | /* functions */ 177 | 178 | #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550) 179 | # ifndef HAVE_VSNPRINTF 180 | # define HAVE_VSNPRINTF 181 | # endif 182 | #endif 183 | #if defined(__CYGWIN__) 184 | # ifndef HAVE_VSNPRINTF 185 | # define HAVE_VSNPRINTF 186 | # endif 187 | #endif 188 | #ifndef HAVE_VSNPRINTF 189 | # ifdef MSDOS 190 | /* vsnprintf may exist on some MS-DOS compilers (DJGPP?), 191 | but for now we just assume it doesn't. */ 192 | # define NO_vsnprintf 193 | # endif 194 | # ifdef __TURBOC__ 195 | # define NO_vsnprintf 196 | # endif 197 | # ifdef WIN32 198 | /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */ 199 | # if !defined(vsnprintf) && !defined(NO_vsnprintf) 200 | # define vsnprintf _vsnprintf 201 | # endif 202 | # endif 203 | # ifdef __SASC 204 | # define NO_vsnprintf 205 | # endif 206 | #endif 207 | #ifdef VMS 208 | # define NO_vsnprintf 209 | #endif 210 | 211 | #if defined(pyr) 212 | # define NO_MEMCPY 213 | #endif 214 | #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) 215 | /* Use our own functions for small and medium model with MSC <= 5.0. 216 | * You may have to use the same strategy for Borland C (untested). 217 | * The __SC__ check is for Symantec. 218 | */ 219 | # define NO_MEMCPY 220 | #endif 221 | #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) 222 | # define HAVE_MEMCPY 223 | #endif 224 | #ifdef HAVE_MEMCPY 225 | # ifdef SMALL_MEDIUM /* MSDOS small or medium model */ 226 | # define zmemcpy _fmemcpy 227 | # define zmemcmp _fmemcmp 228 | # define zmemzero(dest, len) _fmemset(dest, 0, len) 229 | # else 230 | # define zmemcpy memcpy 231 | # define zmemcmp memcmp 232 | # define zmemzero(dest, len) memset(dest, 0, len) 233 | # endif 234 | #else 235 | extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); 236 | extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); 237 | extern void zmemzero OF((Bytef* dest, uInt len)); 238 | #endif 239 | 240 | /* Diagnostic functions */ 241 | #ifdef DEBUG 242 | # include 243 | extern int z_verbose; 244 | extern void z_error OF((char *m)); 245 | # define Assert(cond,msg) {if(!(cond)) z_error(msg);} 246 | # define Trace(x) {if (z_verbose>=0) fprintf x ;} 247 | # define Tracev(x) {if (z_verbose>0) fprintf x ;} 248 | # define Tracevv(x) {if (z_verbose>1) fprintf x ;} 249 | # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} 250 | # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} 251 | #else 252 | # define Assert(cond,msg) 253 | # define Trace(x) 254 | # define Tracev(x) 255 | # define Tracevv(x) 256 | # define Tracec(c,x) 257 | # define Tracecv(c,x) 258 | #endif 259 | 260 | 261 | voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size)); 262 | void zcfree OF((voidpf opaque, voidpf ptr)); 263 | 264 | #define ZALLOC(strm, items, size) \ 265 | (*((strm)->zalloc))((strm)->opaque, (items), (size)) 266 | #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) 267 | #define TRY_FREE(s, p) {if (p) ZFREE(s, p);} 268 | 269 | #endif /* ZUTIL_H */ 270 | -------------------------------------------------------------------------------- /Source/ZLib/zlib123/zutil.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/ZLib/zlib123/zutil.obj -------------------------------------------------------------------------------- /Source/ZLib/zlib127/ZLibEx.inc: -------------------------------------------------------------------------------- 1 | {************************************************************************************************* 2 | * ZLibEx.inc * 3 | * copyright (c) 2006-2012 base2 technologies * 4 | * * 5 | * version information for delphi/c++ builder * 6 | * * 7 | * revision history * 8 | * 2012.05.01 updated for delphi xe2 (2012) * 9 | * 2010.09.18 updated for delphi xe (2011) * 10 | * 2010.01.27 updated for delphi 2010 * 11 | * 2009.04.11 updated to use CONDITIONALEXPRESSIONS and CompilerVersion * 12 | * 2009.01.28 updated for delphi 2009 * 13 | * 2007.10.01 updated for delphi 2007 * 14 | * 2005.11.29 created * 15 | * * 16 | * acknowledgments * 17 | * iztok kacin * 18 | * 2009.04.11 CONDITIONALEXPRESSIONS and CompilerVersion changes * 19 | *************************************************************************************************} 20 | 21 | {$ifndef CONDITIONALEXPRESSIONS} 22 | 23 | {** delphi ************************************************************************************} 24 | 25 | {$ifdef VER80} // delphi 1 26 | {$define Delphi} 27 | 28 | {$define Version1} 29 | {$endif} 30 | 31 | {$ifdef VER90} // delphi 2 32 | {$define Delphi} 33 | 34 | {$define Version2} 35 | {$endif} 36 | 37 | {$ifdef VER100} // delphi 3 38 | {$define Delphi} 39 | 40 | {$define Version3} 41 | {$endif} 42 | 43 | {$ifdef VER120} // delphi 4 44 | {$define Delphi} 45 | 46 | {$define Version4} 47 | {$endif} 48 | 49 | {** c++ builder *******************************************************************************} 50 | 51 | {$ifdef VER93} // c++ builder 1 52 | {$define CBuilder} 53 | 54 | {$define Version1} 55 | {$endif} 56 | 57 | {$ifdef VER110} // c++ builder 3 58 | {$define CBuilder} 59 | 60 | {$define Version3} 61 | {$endif} 62 | 63 | {$ifdef VER125} // c++ builder 4 64 | {$define CBuilder} 65 | 66 | {$define Version4} 67 | {$endif} 68 | 69 | {** delphi/c++ builder (common) ***************************************************************} 70 | 71 | {$ifdef VER130} // delphi/c++ builder 5 72 | {$ifdef BCB} 73 | {$define CBuilder} 74 | {$ELSE} 75 | {$define Delphi} 76 | {$endif} 77 | 78 | {$define Version5} 79 | 80 | {$define Version5Plus} 81 | {$endif} 82 | 83 | {$ELSE} 84 | 85 | {$ifdef BCB} 86 | {$define CBuilder} 87 | {$ELSE} 88 | {$define Delphi} 89 | {$endif} 90 | 91 | {$define Version5Plus} 92 | 93 | {$if CompilerVersion >= 14.0} // delphi 6 94 | {$ifdef VER140} 95 | {$define Version6} 96 | {$endif} 97 | 98 | {$define Version6Plus} 99 | {$ifend} 100 | 101 | {$if CompilerVersion >= 15.0} // delphi 7 102 | {$ifdef VER150} 103 | {$define Version7} 104 | {$endif} 105 | 106 | {$define Version7Plus} 107 | {$ifend} 108 | 109 | {$if CompilerVersion >= 16.0} // delphi 8 (.net) 110 | {$ifdef VER160} 111 | {$define Version8} 112 | {$endif} 113 | 114 | {$define Version8Plus} 115 | {$ifend} 116 | 117 | {$if CompilerVersion >= 17.0} // delphi 2005 118 | {$ifdef VER170} 119 | {$define Version2005} 120 | {$endif} 121 | 122 | {$define Version2005Plus} 123 | {$ifend} 124 | 125 | {$if CompilerVersion >= 18.0} // bds 2006 126 | {$ifdef VER180} 127 | {$define Version2006} 128 | {$endif} 129 | 130 | {$define Version2006Plus} 131 | {$ifend} 132 | 133 | {$if CompilerVersion >= 18.5} // bds 2007 134 | {$ifdef VER185} 135 | {$define Version2007} 136 | {$endif} 137 | 138 | {$define Version2007Plus} 139 | {$ifend} 140 | 141 | {$if CompilerVersion >= 20.0} // bds 2009 142 | {$ifdef VER200} 143 | {$define Version2009} 144 | {$endif} 145 | 146 | {$define Version2009Plus} 147 | {$ifend} 148 | 149 | {$if CompilerVersion >= 21.0} // bds 2010 150 | {$ifdef VER210} 151 | {$define Version2010} 152 | {$endif} 153 | 154 | {$define Version2010Plus} 155 | {$ifend} 156 | 157 | {$if CompilerVersion >= 22.0} // bds xe (2011) 158 | {$ifdef VER220} 159 | {$define Version2011} 160 | {$endif} 161 | 162 | {$define Version2011Plus} 163 | {$ifend} 164 | 165 | {$if CompilerVersion >= 23.0} // bds xe2 (2012) 166 | {$ifdef VER230} 167 | {$define Version2012} 168 | {$endif} 169 | 170 | {$define Version2012Plus} 171 | {$ifend} 172 | 173 | {$endif} 174 | -------------------------------------------------------------------------------- /Source/ZLib/zlib127/win32/adler32.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/ZLib/zlib127/win32/adler32.obj -------------------------------------------------------------------------------- /Source/ZLib/zlib127/win32/compress.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/ZLib/zlib127/win32/compress.obj -------------------------------------------------------------------------------- /Source/ZLib/zlib127/win32/crc32.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/ZLib/zlib127/win32/crc32.obj -------------------------------------------------------------------------------- /Source/ZLib/zlib127/win32/deflate.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/ZLib/zlib127/win32/deflate.obj -------------------------------------------------------------------------------- /Source/ZLib/zlib127/win32/infback.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/ZLib/zlib127/win32/infback.obj -------------------------------------------------------------------------------- /Source/ZLib/zlib127/win32/inffast.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/ZLib/zlib127/win32/inffast.obj -------------------------------------------------------------------------------- /Source/ZLib/zlib127/win32/inflate.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/ZLib/zlib127/win32/inflate.obj -------------------------------------------------------------------------------- /Source/ZLib/zlib127/win32/inftrees.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/ZLib/zlib127/win32/inftrees.obj -------------------------------------------------------------------------------- /Source/ZLib/zlib127/win32/trees.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/ZLib/zlib127/win32/trees.obj -------------------------------------------------------------------------------- /Source/ZLib/zlib127/win64/adler32.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/ZLib/zlib127/win64/adler32.obj -------------------------------------------------------------------------------- /Source/ZLib/zlib127/win64/compress.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/ZLib/zlib127/win64/compress.obj -------------------------------------------------------------------------------- /Source/ZLib/zlib127/win64/crc32.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/ZLib/zlib127/win64/crc32.obj -------------------------------------------------------------------------------- /Source/ZLib/zlib127/win64/deflate.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/ZLib/zlib127/win64/deflate.obj -------------------------------------------------------------------------------- /Source/ZLib/zlib127/win64/infback.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/ZLib/zlib127/win64/infback.obj -------------------------------------------------------------------------------- /Source/ZLib/zlib127/win64/inffast.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/ZLib/zlib127/win64/inffast.obj -------------------------------------------------------------------------------- /Source/ZLib/zlib127/win64/inflate.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/ZLib/zlib127/win64/inflate.obj -------------------------------------------------------------------------------- /Source/ZLib/zlib127/win64/inftrees.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/ZLib/zlib127/win64/inftrees.obj -------------------------------------------------------------------------------- /Source/ZLib/zlib127/win64/trees.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fundamentalslib/fundamentals4/1a3e4910549a19cbb9fea6651547506839d0657f/Source/ZLib/zlib127/win64/trees.obj -------------------------------------------------------------------------------- /Source/ZLib/zlib127/zlib/adler32.c: -------------------------------------------------------------------------------- 1 | /* adler32.c -- compute the Adler-32 checksum of a data stream 2 | * Copyright (C) 1995-2011 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #include "zutil.h" 9 | 10 | #define local static 11 | 12 | local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2)); 13 | 14 | #define BASE 65521 /* largest prime smaller than 65536 */ 15 | #define NMAX 5552 16 | /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ 17 | 18 | #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;} 19 | #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); 20 | #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); 21 | #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); 22 | #define DO16(buf) DO8(buf,0); DO8(buf,8); 23 | 24 | /* use NO_DIVIDE if your processor does not do division in hardware -- 25 | try it both ways to see which is faster */ 26 | #ifdef NO_DIVIDE 27 | /* note that this assumes BASE is 65521, where 65536 % 65521 == 15 28 | (thank you to John Reiser for pointing this out) */ 29 | # define CHOP(a) \ 30 | do { \ 31 | unsigned long tmp = a >> 16; \ 32 | a &= 0xffffUL; \ 33 | a += (tmp << 4) - tmp; \ 34 | } while (0) 35 | # define MOD28(a) \ 36 | do { \ 37 | CHOP(a); \ 38 | if (a >= BASE) a -= BASE; \ 39 | } while (0) 40 | # define MOD(a) \ 41 | do { \ 42 | CHOP(a); \ 43 | MOD28(a); \ 44 | } while (0) 45 | # define MOD63(a) \ 46 | do { /* this assumes a is not negative */ \ 47 | z_off64_t tmp = a >> 32; \ 48 | a &= 0xffffffffL; \ 49 | a += (tmp << 8) - (tmp << 5) + tmp; \ 50 | tmp = a >> 16; \ 51 | a &= 0xffffL; \ 52 | a += (tmp << 4) - tmp; \ 53 | tmp = a >> 16; \ 54 | a &= 0xffffL; \ 55 | a += (tmp << 4) - tmp; \ 56 | if (a >= BASE) a -= BASE; \ 57 | } while (0) 58 | #else 59 | # define MOD(a) a %= BASE 60 | # define MOD28(a) a %= BASE 61 | # define MOD63(a) a %= BASE 62 | #endif 63 | 64 | /* ========================================================================= */ 65 | uLong ZEXPORT adler32(adler, buf, len) 66 | uLong adler; 67 | const Bytef *buf; 68 | uInt len; 69 | { 70 | unsigned long sum2; 71 | unsigned n; 72 | 73 | /* split Adler-32 into component sums */ 74 | sum2 = (adler >> 16) & 0xffff; 75 | adler &= 0xffff; 76 | 77 | /* in case user likes doing a byte at a time, keep it fast */ 78 | if (len == 1) { 79 | adler += buf[0]; 80 | if (adler >= BASE) 81 | adler -= BASE; 82 | sum2 += adler; 83 | if (sum2 >= BASE) 84 | sum2 -= BASE; 85 | return adler | (sum2 << 16); 86 | } 87 | 88 | /* initial Adler-32 value (deferred check for len == 1 speed) */ 89 | if (buf == Z_NULL) 90 | return 1L; 91 | 92 | /* in case short lengths are provided, keep it somewhat fast */ 93 | if (len < 16) { 94 | while (len--) { 95 | adler += *buf++; 96 | sum2 += adler; 97 | } 98 | if (adler >= BASE) 99 | adler -= BASE; 100 | MOD28(sum2); /* only added so many BASE's */ 101 | return adler | (sum2 << 16); 102 | } 103 | 104 | /* do length NMAX blocks -- requires just one modulo operation */ 105 | while (len >= NMAX) { 106 | len -= NMAX; 107 | n = NMAX / 16; /* NMAX is divisible by 16 */ 108 | do { 109 | DO16(buf); /* 16 sums unrolled */ 110 | buf += 16; 111 | } while (--n); 112 | MOD(adler); 113 | MOD(sum2); 114 | } 115 | 116 | /* do remaining bytes (less than NMAX, still just one modulo) */ 117 | if (len) { /* avoid modulos if none remaining */ 118 | while (len >= 16) { 119 | len -= 16; 120 | DO16(buf); 121 | buf += 16; 122 | } 123 | while (len--) { 124 | adler += *buf++; 125 | sum2 += adler; 126 | } 127 | MOD(adler); 128 | MOD(sum2); 129 | } 130 | 131 | /* return recombined sums */ 132 | return adler | (sum2 << 16); 133 | } 134 | 135 | /* ========================================================================= */ 136 | local uLong adler32_combine_(adler1, adler2, len2) 137 | uLong adler1; 138 | uLong adler2; 139 | z_off64_t len2; 140 | { 141 | unsigned long sum1; 142 | unsigned long sum2; 143 | unsigned rem; 144 | 145 | /* for negative len, return invalid adler32 as a clue for debugging */ 146 | if (len2 < 0) 147 | return 0xffffffffUL; 148 | 149 | /* the derivation of this formula is left as an exercise for the reader */ 150 | MOD63(len2); /* assumes len2 >= 0 */ 151 | rem = (unsigned)len2; 152 | sum1 = adler1 & 0xffff; 153 | sum2 = rem * sum1; 154 | MOD(sum2); 155 | sum1 += (adler2 & 0xffff) + BASE - 1; 156 | sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem; 157 | if (sum1 >= BASE) sum1 -= BASE; 158 | if (sum1 >= BASE) sum1 -= BASE; 159 | if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1); 160 | if (sum2 >= BASE) sum2 -= BASE; 161 | return sum1 | (sum2 << 16); 162 | } 163 | 164 | /* ========================================================================= */ 165 | uLong ZEXPORT adler32_combine(adler1, adler2, len2) 166 | uLong adler1; 167 | uLong adler2; 168 | z_off_t len2; 169 | { 170 | return adler32_combine_(adler1, adler2, len2); 171 | } 172 | 173 | uLong ZEXPORT adler32_combine64(adler1, adler2, len2) 174 | uLong adler1; 175 | uLong adler2; 176 | z_off64_t len2; 177 | { 178 | return adler32_combine_(adler1, adler2, len2); 179 | } 180 | -------------------------------------------------------------------------------- /Source/ZLib/zlib127/zlib/compress.c: -------------------------------------------------------------------------------- 1 | /* compress.c -- compress a memory buffer 2 | * Copyright (C) 1995-2005 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #define ZLIB_INTERNAL 9 | #include "zlib.h" 10 | 11 | /* =========================================================================== 12 | Compresses the source buffer into the destination buffer. The level 13 | parameter has the same meaning as in deflateInit. sourceLen is the byte 14 | length of the source buffer. Upon entry, destLen is the total size of the 15 | destination buffer, which must be at least 0.1% larger than sourceLen plus 16 | 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. 17 | 18 | compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 19 | memory, Z_BUF_ERROR if there was not enough room in the output buffer, 20 | Z_STREAM_ERROR if the level parameter is invalid. 21 | */ 22 | int ZEXPORT compress2 (dest, destLen, source, sourceLen, level) 23 | Bytef *dest; 24 | uLongf *destLen; 25 | const Bytef *source; 26 | uLong sourceLen; 27 | int level; 28 | { 29 | z_stream stream; 30 | int err; 31 | 32 | stream.next_in = (Bytef*)source; 33 | stream.avail_in = (uInt)sourceLen; 34 | #ifdef MAXSEG_64K 35 | /* Check for source > 64K on 16-bit machine: */ 36 | if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; 37 | #endif 38 | stream.next_out = dest; 39 | stream.avail_out = (uInt)*destLen; 40 | if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; 41 | 42 | stream.zalloc = (alloc_func)0; 43 | stream.zfree = (free_func)0; 44 | stream.opaque = (voidpf)0; 45 | 46 | err = deflateInit(&stream, level); 47 | if (err != Z_OK) return err; 48 | 49 | err = deflate(&stream, Z_FINISH); 50 | if (err != Z_STREAM_END) { 51 | deflateEnd(&stream); 52 | return err == Z_OK ? Z_BUF_ERROR : err; 53 | } 54 | *destLen = stream.total_out; 55 | 56 | err = deflateEnd(&stream); 57 | return err; 58 | } 59 | 60 | /* =========================================================================== 61 | */ 62 | int ZEXPORT compress (dest, destLen, source, sourceLen) 63 | Bytef *dest; 64 | uLongf *destLen; 65 | const Bytef *source; 66 | uLong sourceLen; 67 | { 68 | return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); 69 | } 70 | 71 | /* =========================================================================== 72 | If the default memLevel or windowBits for deflateInit() is changed, then 73 | this function needs to be updated. 74 | */ 75 | uLong ZEXPORT compressBound (sourceLen) 76 | uLong sourceLen; 77 | { 78 | return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 79 | (sourceLen >> 25) + 13; 80 | } 81 | -------------------------------------------------------------------------------- /Source/ZLib/zlib127/zlib/inffast.h: -------------------------------------------------------------------------------- 1 | /* inffast.h -- header to use inffast.c 2 | * Copyright (C) 1995-2003, 2010 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start)); 12 | -------------------------------------------------------------------------------- /Source/ZLib/zlib127/zlib/inffixed.h: -------------------------------------------------------------------------------- 1 | /* inffixed.h -- table for decoding fixed codes 2 | * Generated automatically by makefixed(). 3 | */ 4 | 5 | /* WARNING: this file should *not* be used by applications. 6 | It is part of the implementation of this library and is 7 | subject to change. Applications should only use zlib.h. 8 | */ 9 | 10 | static const code lenfix[512] = { 11 | {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, 12 | {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, 13 | {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, 14 | {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176}, 15 | {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20}, 16 | {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100}, 17 | {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8}, 18 | {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216}, 19 | {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76}, 20 | {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114}, 21 | {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2}, 22 | {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148}, 23 | {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42}, 24 | {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86}, 25 | {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15}, 26 | {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236}, 27 | {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62}, 28 | {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142}, 29 | {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31}, 30 | {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162}, 31 | {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25}, 32 | {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105}, 33 | {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4}, 34 | {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202}, 35 | {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69}, 36 | {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125}, 37 | {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13}, 38 | {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195}, 39 | {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35}, 40 | {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91}, 41 | {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19}, 42 | {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246}, 43 | {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55}, 44 | {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135}, 45 | {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99}, 46 | {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190}, 47 | {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16}, 48 | {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96}, 49 | {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6}, 50 | {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209}, 51 | {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72}, 52 | {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116}, 53 | {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4}, 54 | {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153}, 55 | {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44}, 56 | {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82}, 57 | {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11}, 58 | {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229}, 59 | {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58}, 60 | {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138}, 61 | {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51}, 62 | {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173}, 63 | {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30}, 64 | {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110}, 65 | {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0}, 66 | {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195}, 67 | {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65}, 68 | {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121}, 69 | {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9}, 70 | {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258}, 71 | {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37}, 72 | {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93}, 73 | {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23}, 74 | {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251}, 75 | {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51}, 76 | {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131}, 77 | {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67}, 78 | {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183}, 79 | {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23}, 80 | {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103}, 81 | {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9}, 82 | {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223}, 83 | {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79}, 84 | {0,9,255} 85 | }; 86 | 87 | static const code distfix[32] = { 88 | {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, 89 | {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, 90 | {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, 91 | {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577}, 92 | {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073}, 93 | {22,5,193},{64,5,0} 94 | }; 95 | -------------------------------------------------------------------------------- /Source/ZLib/zlib127/zlib/inflate.h: -------------------------------------------------------------------------------- 1 | /* inflate.h -- internal inflate state definition 2 | * Copyright (C) 1995-2009 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* define NO_GZIP when compiling if you want to disable gzip header and 12 | trailer decoding by inflate(). NO_GZIP would be used to avoid linking in 13 | the crc code when it is not needed. For shared libraries, gzip decoding 14 | should be left enabled. */ 15 | #ifndef NO_GZIP 16 | # define GUNZIP 17 | #endif 18 | 19 | /* Possible inflate modes between inflate() calls */ 20 | typedef enum { 21 | HEAD, /* i: waiting for magic header */ 22 | FLAGS, /* i: waiting for method and flags (gzip) */ 23 | TIME, /* i: waiting for modification time (gzip) */ 24 | OS, /* i: waiting for extra flags and operating system (gzip) */ 25 | EXLEN, /* i: waiting for extra length (gzip) */ 26 | EXTRA, /* i: waiting for extra bytes (gzip) */ 27 | NAME, /* i: waiting for end of file name (gzip) */ 28 | COMMENT, /* i: waiting for end of comment (gzip) */ 29 | HCRC, /* i: waiting for header crc (gzip) */ 30 | DICTID, /* i: waiting for dictionary check value */ 31 | DICT, /* waiting for inflateSetDictionary() call */ 32 | TYPE, /* i: waiting for type bits, including last-flag bit */ 33 | TYPEDO, /* i: same, but skip check to exit inflate on new block */ 34 | STORED, /* i: waiting for stored size (length and complement) */ 35 | COPY_, /* i/o: same as COPY below, but only first time in */ 36 | COPY, /* i/o: waiting for input or output to copy stored block */ 37 | TABLE, /* i: waiting for dynamic block table lengths */ 38 | LENLENS, /* i: waiting for code length code lengths */ 39 | CODELENS, /* i: waiting for length/lit and distance code lengths */ 40 | LEN_, /* i: same as LEN below, but only first time in */ 41 | LEN, /* i: waiting for length/lit/eob code */ 42 | LENEXT, /* i: waiting for length extra bits */ 43 | DIST, /* i: waiting for distance code */ 44 | DISTEXT, /* i: waiting for distance extra bits */ 45 | MATCH, /* o: waiting for output space to copy string */ 46 | LIT, /* o: waiting for output space to write literal */ 47 | CHECK, /* i: waiting for 32-bit check value */ 48 | LENGTH, /* i: waiting for 32-bit length (gzip) */ 49 | DONE, /* finished check, done -- remain here until reset */ 50 | BAD, /* got a data error -- remain here until reset */ 51 | MEM, /* got an inflate() memory error -- remain here until reset */ 52 | SYNC /* looking for synchronization bytes to restart inflate() */ 53 | } inflate_mode; 54 | 55 | /* 56 | State transitions between above modes - 57 | 58 | (most modes can go to BAD or MEM on error -- not shown for clarity) 59 | 60 | Process header: 61 | HEAD -> (gzip) or (zlib) or (raw) 62 | (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME -> COMMENT -> 63 | HCRC -> TYPE 64 | (zlib) -> DICTID or TYPE 65 | DICTID -> DICT -> TYPE 66 | (raw) -> TYPEDO 67 | Read deflate blocks: 68 | TYPE -> TYPEDO -> STORED or TABLE or LEN_ or CHECK 69 | STORED -> COPY_ -> COPY -> TYPE 70 | TABLE -> LENLENS -> CODELENS -> LEN_ 71 | LEN_ -> LEN 72 | Read deflate codes in fixed or dynamic block: 73 | LEN -> LENEXT or LIT or TYPE 74 | LENEXT -> DIST -> DISTEXT -> MATCH -> LEN 75 | LIT -> LEN 76 | Process trailer: 77 | CHECK -> LENGTH -> DONE 78 | */ 79 | 80 | /* state maintained between inflate() calls. Approximately 10K bytes. */ 81 | struct inflate_state { 82 | inflate_mode mode; /* current inflate mode */ 83 | int last; /* true if processing last block */ 84 | int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ 85 | int havedict; /* true if dictionary provided */ 86 | int flags; /* gzip header method and flags (0 if zlib) */ 87 | unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */ 88 | unsigned long check; /* protected copy of check value */ 89 | unsigned long total; /* protected copy of output count */ 90 | gz_headerp head; /* where to save gzip header information */ 91 | /* sliding window */ 92 | unsigned wbits; /* log base 2 of requested window size */ 93 | unsigned wsize; /* window size or zero if not using window */ 94 | unsigned whave; /* valid bytes in the window */ 95 | unsigned wnext; /* window write index */ 96 | unsigned char FAR *window; /* allocated sliding window, if needed */ 97 | /* bit accumulator */ 98 | unsigned long hold; /* input bit accumulator */ 99 | unsigned bits; /* number of bits in "in" */ 100 | /* for string and stored block copying */ 101 | unsigned length; /* literal or length of data to copy */ 102 | unsigned offset; /* distance back to copy string from */ 103 | /* for table and code decoding */ 104 | unsigned extra; /* extra bits needed */ 105 | /* fixed and dynamic code tables */ 106 | code const FAR *lencode; /* starting table for length/literal codes */ 107 | code const FAR *distcode; /* starting table for distance codes */ 108 | unsigned lenbits; /* index bits for lencode */ 109 | unsigned distbits; /* index bits for distcode */ 110 | /* dynamic table building */ 111 | unsigned ncode; /* number of code length code lengths */ 112 | unsigned nlen; /* number of length code lengths */ 113 | unsigned ndist; /* number of distance code lengths */ 114 | unsigned have; /* number of code lengths in lens[] */ 115 | code FAR *next; /* next available space in codes[] */ 116 | unsigned short lens[320]; /* temporary storage for code lengths */ 117 | unsigned short work[288]; /* work area for code table building */ 118 | code codes[ENOUGH]; /* space for code tables */ 119 | int sane; /* if false, allow invalid distance too far */ 120 | int back; /* bits back of last unprocessed length/lit */ 121 | unsigned was; /* initial length of match */ 122 | }; 123 | -------------------------------------------------------------------------------- /Source/ZLib/zlib127/zlib/inftrees.h: -------------------------------------------------------------------------------- 1 | /* inftrees.h -- header to use inftrees.c 2 | * Copyright (C) 1995-2005, 2010 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* Structure for decoding tables. Each entry provides either the 12 | information needed to do the operation requested by the code that 13 | indexed that table entry, or it provides a pointer to another 14 | table that indexes more bits of the code. op indicates whether 15 | the entry is a pointer to another table, a literal, a length or 16 | distance, an end-of-block, or an invalid code. For a table 17 | pointer, the low four bits of op is the number of index bits of 18 | that table. For a length or distance, the low four bits of op 19 | is the number of extra bits to get after the code. bits is 20 | the number of bits in this code or part of the code to drop off 21 | of the bit buffer. val is the actual byte to output in the case 22 | of a literal, the base length or distance, or the offset from 23 | the current table to the next table. Each entry is four bytes. */ 24 | typedef struct { 25 | unsigned char op; /* operation, extra bits, table bits */ 26 | unsigned char bits; /* bits in this part of the code */ 27 | unsigned short val; /* offset in table or code value */ 28 | } code; 29 | 30 | /* op values as set by inflate_table(): 31 | 00000000 - literal 32 | 0000tttt - table link, tttt != 0 is the number of table index bits 33 | 0001eeee - length or distance, eeee is the number of extra bits 34 | 01100000 - end of block 35 | 01000000 - invalid code 36 | */ 37 | 38 | /* Maximum size of the dynamic table. The maximum number of code structures is 39 | 1444, which is the sum of 852 for literal/length codes and 592 for distance 40 | codes. These values were found by exhaustive searches using the program 41 | examples/enough.c found in the zlib distribtution. The arguments to that 42 | program are the number of symbols, the initial root table size, and the 43 | maximum bit length of a code. "enough 286 9 15" for literal/length codes 44 | returns returns 852, and "enough 30 6 15" for distance codes returns 592. 45 | The initial root table size (9 or 6) is found in the fifth argument of the 46 | inflate_table() calls in inflate.c and infback.c. If the root table size is 47 | changed, then these maximum sizes would be need to be recalculated and 48 | updated. */ 49 | #define ENOUGH_LENS 852 50 | #define ENOUGH_DISTS 592 51 | #define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS) 52 | 53 | /* Type of code to build for inflate_table() */ 54 | typedef enum { 55 | CODES, 56 | LENS, 57 | DISTS 58 | } codetype; 59 | 60 | int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens, 61 | unsigned codes, code FAR * FAR *table, 62 | unsigned FAR *bits, unsigned short FAR *work)); 63 | -------------------------------------------------------------------------------- /Source/ZLib/zlib127/zlib/trees.h: -------------------------------------------------------------------------------- 1 | /* header created automatically with -DGEN_TREES_H */ 2 | 3 | local const ct_data static_ltree[L_CODES+2] = { 4 | {{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}}, 5 | {{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}}, 6 | {{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}}, 7 | {{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}}, 8 | {{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}}, 9 | {{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}}, 10 | {{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}}, 11 | {{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}}, 12 | {{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}}, 13 | {{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}}, 14 | {{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}}, 15 | {{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}}, 16 | {{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}}, 17 | {{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}}, 18 | {{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}}, 19 | {{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}}, 20 | {{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}}, 21 | {{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}}, 22 | {{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}}, 23 | {{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}}, 24 | {{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}}, 25 | {{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}}, 26 | {{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}}, 27 | {{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}}, 28 | {{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}}, 29 | {{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}}, 30 | {{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}}, 31 | {{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}}, 32 | {{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}}, 33 | {{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}}, 34 | {{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}}, 35 | {{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}}, 36 | {{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}}, 37 | {{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}}, 38 | {{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}}, 39 | {{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}}, 40 | {{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}}, 41 | {{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}}, 42 | {{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}}, 43 | {{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}}, 44 | {{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}}, 45 | {{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}}, 46 | {{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}}, 47 | {{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}}, 48 | {{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}}, 49 | {{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}}, 50 | {{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}}, 51 | {{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}}, 52 | {{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}}, 53 | {{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}}, 54 | {{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}}, 55 | {{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}}, 56 | {{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}}, 57 | {{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}}, 58 | {{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}}, 59 | {{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}}, 60 | {{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}}, 61 | {{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}} 62 | }; 63 | 64 | local const ct_data static_dtree[D_CODES] = { 65 | {{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}}, 66 | {{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}}, 67 | {{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}}, 68 | {{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}}, 69 | {{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}}, 70 | {{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}} 71 | }; 72 | 73 | const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = { 74 | 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 75 | 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 76 | 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 77 | 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 78 | 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 79 | 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 80 | 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 81 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 82 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 83 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 84 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 85 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 86 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17, 87 | 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 88 | 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 89 | 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 90 | 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 91 | 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 92 | 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 93 | 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 94 | 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 95 | 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 96 | 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 97 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 98 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 99 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29 100 | }; 101 | 102 | const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= { 103 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12, 104 | 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 105 | 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 106 | 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 107 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 108 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, 109 | 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 110 | 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 111 | 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 112 | 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, 113 | 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 114 | 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 115 | 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28 116 | }; 117 | 118 | local const int base_length[LENGTH_CODES] = { 119 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, 120 | 64, 80, 96, 112, 128, 160, 192, 224, 0 121 | }; 122 | 123 | local const int base_dist[D_CODES] = { 124 | 0, 1, 2, 3, 4, 6, 8, 12, 16, 24, 125 | 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, 126 | 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576 127 | }; 128 | 129 | -------------------------------------------------------------------------------- /Source/ZLib/zlib127/zlib/zutil.c: -------------------------------------------------------------------------------- 1 | /* zutil.c -- target dependent utility functions for the compression library 2 | * Copyright (C) 1995-2005, 2010, 2011, 2012 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #include "zutil.h" 9 | #ifndef Z_SOLO 10 | # include "gzguts.h" 11 | #endif 12 | 13 | #ifndef NO_DUMMY_DECL 14 | struct internal_state {int dummy;}; /* for buggy compilers */ 15 | #endif 16 | 17 | const char * const z_errmsg[10] = { 18 | "need dictionary", /* Z_NEED_DICT 2 */ 19 | "stream end", /* Z_STREAM_END 1 */ 20 | "", /* Z_OK 0 */ 21 | "file error", /* Z_ERRNO (-1) */ 22 | "stream error", /* Z_STREAM_ERROR (-2) */ 23 | "data error", /* Z_DATA_ERROR (-3) */ 24 | "insufficient memory", /* Z_MEM_ERROR (-4) */ 25 | "buffer error", /* Z_BUF_ERROR (-5) */ 26 | "incompatible version",/* Z_VERSION_ERROR (-6) */ 27 | ""}; 28 | 29 | 30 | const char * ZEXPORT zlibVersion() 31 | { 32 | return ZLIB_VERSION; 33 | } 34 | 35 | uLong ZEXPORT zlibCompileFlags() 36 | { 37 | uLong flags; 38 | 39 | flags = 0; 40 | switch ((int)(sizeof(uInt))) { 41 | case 2: break; 42 | case 4: flags += 1; break; 43 | case 8: flags += 2; break; 44 | default: flags += 3; 45 | } 46 | switch ((int)(sizeof(uLong))) { 47 | case 2: break; 48 | case 4: flags += 1 << 2; break; 49 | case 8: flags += 2 << 2; break; 50 | default: flags += 3 << 2; 51 | } 52 | switch ((int)(sizeof(voidpf))) { 53 | case 2: break; 54 | case 4: flags += 1 << 4; break; 55 | case 8: flags += 2 << 4; break; 56 | default: flags += 3 << 4; 57 | } 58 | switch ((int)(sizeof(z_off_t))) { 59 | case 2: break; 60 | case 4: flags += 1 << 6; break; 61 | case 8: flags += 2 << 6; break; 62 | default: flags += 3 << 6; 63 | } 64 | #ifdef DEBUG 65 | flags += 1 << 8; 66 | #endif 67 | #if defined(ASMV) || defined(ASMINF) 68 | flags += 1 << 9; 69 | #endif 70 | #ifdef ZLIB_WINAPI 71 | flags += 1 << 10; 72 | #endif 73 | #ifdef BUILDFIXED 74 | flags += 1 << 12; 75 | #endif 76 | #ifdef DYNAMIC_CRC_TABLE 77 | flags += 1 << 13; 78 | #endif 79 | #ifdef NO_GZCOMPRESS 80 | flags += 1L << 16; 81 | #endif 82 | #ifdef NO_GZIP 83 | flags += 1L << 17; 84 | #endif 85 | #ifdef PKZIP_BUG_WORKAROUND 86 | flags += 1L << 20; 87 | #endif 88 | #ifdef FASTEST 89 | flags += 1L << 21; 90 | #endif 91 | #if defined(STDC) || defined(Z_HAVE_STDARG_H) 92 | # ifdef NO_vsnprintf 93 | flags += 1L << 25; 94 | # ifdef HAS_vsprintf_void 95 | flags += 1L << 26; 96 | # endif 97 | # else 98 | # ifdef HAS_vsnprintf_void 99 | flags += 1L << 26; 100 | # endif 101 | # endif 102 | #else 103 | flags += 1L << 24; 104 | # ifdef NO_snprintf 105 | flags += 1L << 25; 106 | # ifdef HAS_sprintf_void 107 | flags += 1L << 26; 108 | # endif 109 | # else 110 | # ifdef HAS_snprintf_void 111 | flags += 1L << 26; 112 | # endif 113 | # endif 114 | #endif 115 | return flags; 116 | } 117 | 118 | #ifdef DEBUG 119 | 120 | # ifndef verbose 121 | # define verbose 0 122 | # endif 123 | int ZLIB_INTERNAL z_verbose = verbose; 124 | 125 | void ZLIB_INTERNAL z_error (m) 126 | char *m; 127 | { 128 | fprintf(stderr, "%s\n", m); 129 | exit(1); 130 | } 131 | #endif 132 | 133 | /* exported to allow conversion of error code to string for compress() and 134 | * uncompress() 135 | */ 136 | const char * ZEXPORT zError(err) 137 | int err; 138 | { 139 | return ERR_MSG(err); 140 | } 141 | 142 | #if defined(_WIN32_WCE) 143 | /* The Microsoft C Run-Time Library for Windows CE doesn't have 144 | * errno. We define it as a global variable to simplify porting. 145 | * Its value is always 0 and should not be used. 146 | */ 147 | int errno = 0; 148 | #endif 149 | 150 | #ifndef HAVE_MEMCPY 151 | 152 | void ZLIB_INTERNAL zmemcpy(dest, source, len) 153 | Bytef* dest; 154 | const Bytef* source; 155 | uInt len; 156 | { 157 | if (len == 0) return; 158 | do { 159 | *dest++ = *source++; /* ??? to be unrolled */ 160 | } while (--len != 0); 161 | } 162 | 163 | int ZLIB_INTERNAL zmemcmp(s1, s2, len) 164 | const Bytef* s1; 165 | const Bytef* s2; 166 | uInt len; 167 | { 168 | uInt j; 169 | 170 | for (j = 0; j < len; j++) { 171 | if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1; 172 | } 173 | return 0; 174 | } 175 | 176 | void ZLIB_INTERNAL zmemzero(dest, len) 177 | Bytef* dest; 178 | uInt len; 179 | { 180 | if (len == 0) return; 181 | do { 182 | *dest++ = 0; /* ??? to be unrolled */ 183 | } while (--len != 0); 184 | } 185 | #endif 186 | 187 | #ifndef Z_SOLO 188 | 189 | #ifdef SYS16BIT 190 | 191 | #ifdef __TURBOC__ 192 | /* Turbo C in 16-bit mode */ 193 | 194 | # define MY_ZCALLOC 195 | 196 | /* Turbo C malloc() does not allow dynamic allocation of 64K bytes 197 | * and farmalloc(64K) returns a pointer with an offset of 8, so we 198 | * must fix the pointer. Warning: the pointer must be put back to its 199 | * original form in order to free it, use zcfree(). 200 | */ 201 | 202 | #define MAX_PTR 10 203 | /* 10*64K = 640K */ 204 | 205 | local int next_ptr = 0; 206 | 207 | typedef struct ptr_table_s { 208 | voidpf org_ptr; 209 | voidpf new_ptr; 210 | } ptr_table; 211 | 212 | local ptr_table table[MAX_PTR]; 213 | /* This table is used to remember the original form of pointers 214 | * to large buffers (64K). Such pointers are normalized with a zero offset. 215 | * Since MSDOS is not a preemptive multitasking OS, this table is not 216 | * protected from concurrent access. This hack doesn't work anyway on 217 | * a protected system like OS/2. Use Microsoft C instead. 218 | */ 219 | 220 | voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size) 221 | { 222 | voidpf buf = opaque; /* just to make some compilers happy */ 223 | ulg bsize = (ulg)items*size; 224 | 225 | /* If we allocate less than 65520 bytes, we assume that farmalloc 226 | * will return a usable pointer which doesn't have to be normalized. 227 | */ 228 | if (bsize < 65520L) { 229 | buf = farmalloc(bsize); 230 | if (*(ush*)&buf != 0) return buf; 231 | } else { 232 | buf = farmalloc(bsize + 16L); 233 | } 234 | if (buf == NULL || next_ptr >= MAX_PTR) return NULL; 235 | table[next_ptr].org_ptr = buf; 236 | 237 | /* Normalize the pointer to seg:0 */ 238 | *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4; 239 | *(ush*)&buf = 0; 240 | table[next_ptr++].new_ptr = buf; 241 | return buf; 242 | } 243 | 244 | void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) 245 | { 246 | int n; 247 | if (*(ush*)&ptr != 0) { /* object < 64K */ 248 | farfree(ptr); 249 | return; 250 | } 251 | /* Find the original pointer */ 252 | for (n = 0; n < next_ptr; n++) { 253 | if (ptr != table[n].new_ptr) continue; 254 | 255 | farfree(table[n].org_ptr); 256 | while (++n < next_ptr) { 257 | table[n-1] = table[n]; 258 | } 259 | next_ptr--; 260 | return; 261 | } 262 | ptr = opaque; /* just to make some compilers happy */ 263 | Assert(0, "zcfree: ptr not found"); 264 | } 265 | 266 | #endif /* __TURBOC__ */ 267 | 268 | 269 | #ifdef M_I86 270 | /* Microsoft C in 16-bit mode */ 271 | 272 | # define MY_ZCALLOC 273 | 274 | #if (!defined(_MSC_VER) || (_MSC_VER <= 600)) 275 | # define _halloc halloc 276 | # define _hfree hfree 277 | #endif 278 | 279 | voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size) 280 | { 281 | if (opaque) opaque = 0; /* to make compiler happy */ 282 | return _halloc((long)items, size); 283 | } 284 | 285 | void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) 286 | { 287 | if (opaque) opaque = 0; /* to make compiler happy */ 288 | _hfree(ptr); 289 | } 290 | 291 | #endif /* M_I86 */ 292 | 293 | #endif /* SYS16BIT */ 294 | 295 | 296 | #ifndef MY_ZCALLOC /* Any system without a special alloc function */ 297 | 298 | #ifndef STDC 299 | extern voidp malloc OF((uInt size)); 300 | extern voidp calloc OF((uInt items, uInt size)); 301 | extern void free OF((voidpf ptr)); 302 | #endif 303 | 304 | voidpf ZLIB_INTERNAL zcalloc (opaque, items, size) 305 | voidpf opaque; 306 | unsigned items; 307 | unsigned size; 308 | { 309 | if (opaque) items += size - size; /* make compiler happy */ 310 | return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : 311 | (voidpf)calloc(items, size); 312 | } 313 | 314 | void ZLIB_INTERNAL zcfree (opaque, ptr) 315 | voidpf opaque; 316 | voidpf ptr; 317 | { 318 | free(ptr); 319 | if (opaque) return; /* make compiler happy */ 320 | } 321 | 322 | #endif /* MY_ZCALLOC */ 323 | 324 | #endif /* !Z_SOLO */ 325 | -------------------------------------------------------------------------------- /Source/ZLib/zlib127/zlib/zutil.h: -------------------------------------------------------------------------------- 1 | /* zutil.h -- internal interface and configuration of the compression library 2 | * Copyright (C) 1995-2012 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* @(#) $Id$ */ 12 | 13 | #ifndef ZUTIL_H 14 | #define ZUTIL_H 15 | 16 | #ifdef HAVE_HIDDEN 17 | # define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) 18 | #else 19 | # define ZLIB_INTERNAL 20 | #endif 21 | 22 | #include "zlib.h" 23 | 24 | #if defined(STDC) && !defined(Z_SOLO) 25 | # if !(defined(_WIN32_WCE) && defined(_MSC_VER)) 26 | # include 27 | # endif 28 | # include 29 | # include 30 | #endif 31 | 32 | #ifdef Z_SOLO 33 | typedef long ptrdiff_t; /* guess -- will be caught if guess is wrong */ 34 | #endif 35 | 36 | #ifndef local 37 | # define local static 38 | #endif 39 | /* compile with -Dlocal if your debugger can't find static symbols */ 40 | 41 | typedef unsigned char uch; 42 | typedef uch FAR uchf; 43 | typedef unsigned short ush; 44 | typedef ush FAR ushf; 45 | typedef unsigned long ulg; 46 | 47 | extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ 48 | /* (size given to avoid silly warnings with Visual C++) */ 49 | 50 | #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] 51 | 52 | #define ERR_RETURN(strm,err) \ 53 | return (strm->msg = (char*)ERR_MSG(err), (err)) 54 | /* To be used only when the state is known to be valid */ 55 | 56 | /* common constants */ 57 | 58 | #ifndef DEF_WBITS 59 | # define DEF_WBITS MAX_WBITS 60 | #endif 61 | /* default windowBits for decompression. MAX_WBITS is for compression only */ 62 | 63 | #if MAX_MEM_LEVEL >= 8 64 | # define DEF_MEM_LEVEL 8 65 | #else 66 | # define DEF_MEM_LEVEL MAX_MEM_LEVEL 67 | #endif 68 | /* default memLevel */ 69 | 70 | #define STORED_BLOCK 0 71 | #define STATIC_TREES 1 72 | #define DYN_TREES 2 73 | /* The three kinds of block type */ 74 | 75 | #define MIN_MATCH 3 76 | #define MAX_MATCH 258 77 | /* The minimum and maximum match lengths */ 78 | 79 | #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ 80 | 81 | /* target dependencies */ 82 | 83 | #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) 84 | # define OS_CODE 0x00 85 | # ifndef Z_SOLO 86 | # if defined(__TURBOC__) || defined(__BORLANDC__) 87 | # if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) 88 | /* Allow compilation with ANSI keywords only enabled */ 89 | void _Cdecl farfree( void *block ); 90 | void *_Cdecl farmalloc( unsigned long nbytes ); 91 | # else 92 | # include 93 | # endif 94 | # else /* MSC or DJGPP */ 95 | # include 96 | # endif 97 | # endif 98 | #endif 99 | 100 | #ifdef AMIGA 101 | # define OS_CODE 0x01 102 | #endif 103 | 104 | #if defined(VAXC) || defined(VMS) 105 | # define OS_CODE 0x02 106 | # define F_OPEN(name, mode) \ 107 | fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") 108 | #endif 109 | 110 | #if defined(ATARI) || defined(atarist) 111 | # define OS_CODE 0x05 112 | #endif 113 | 114 | #ifdef OS2 115 | # define OS_CODE 0x06 116 | # if defined(M_I86) && !defined(Z_SOLO) 117 | # include 118 | # endif 119 | #endif 120 | 121 | #if defined(MACOS) || defined(TARGET_OS_MAC) 122 | # define OS_CODE 0x07 123 | # ifndef Z_SOLO 124 | # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os 125 | # include /* for fdopen */ 126 | # else 127 | # ifndef fdopen 128 | # define fdopen(fd,mode) NULL /* No fdopen() */ 129 | # endif 130 | # endif 131 | # endif 132 | #endif 133 | 134 | #ifdef TOPS20 135 | # define OS_CODE 0x0a 136 | #endif 137 | 138 | #ifdef WIN32 139 | # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */ 140 | # define OS_CODE 0x0b 141 | # endif 142 | #endif 143 | 144 | #ifdef __50SERIES /* Prime/PRIMOS */ 145 | # define OS_CODE 0x0f 146 | #endif 147 | 148 | #if defined(_BEOS_) || defined(RISCOS) 149 | # define fdopen(fd,mode) NULL /* No fdopen() */ 150 | #endif 151 | 152 | #if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX 153 | # if defined(_WIN32_WCE) 154 | # define fdopen(fd,mode) NULL /* No fdopen() */ 155 | # ifndef _PTRDIFF_T_DEFINED 156 | typedef int ptrdiff_t; 157 | # define _PTRDIFF_T_DEFINED 158 | # endif 159 | # else 160 | # define fdopen(fd,type) _fdopen(fd,type) 161 | # endif 162 | #endif 163 | 164 | #if defined(__BORLANDC__) && !defined(MSDOS) 165 | #pragma warn -8004 166 | #pragma warn -8008 167 | #pragma warn -8066 168 | #endif 169 | 170 | /* provide prototypes for these when building zlib without LFS */ 171 | #if !defined(_WIN32) && (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0) 172 | ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); 173 | ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); 174 | #endif 175 | 176 | /* common defaults */ 177 | 178 | #ifndef OS_CODE 179 | # define OS_CODE 0x03 /* assume Unix */ 180 | #endif 181 | 182 | #ifndef F_OPEN 183 | # define F_OPEN(name, mode) fopen((name), (mode)) 184 | #endif 185 | 186 | /* functions */ 187 | 188 | #if defined(pyr) || defined(Z_SOLO) 189 | # define NO_MEMCPY 190 | #endif 191 | #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) 192 | /* Use our own functions for small and medium model with MSC <= 5.0. 193 | * You may have to use the same strategy for Borland C (untested). 194 | * The __SC__ check is for Symantec. 195 | */ 196 | # define NO_MEMCPY 197 | #endif 198 | #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) 199 | # define HAVE_MEMCPY 200 | #endif 201 | #ifdef HAVE_MEMCPY 202 | # ifdef SMALL_MEDIUM /* MSDOS small or medium model */ 203 | # define zmemcpy _fmemcpy 204 | # define zmemcmp _fmemcmp 205 | # define zmemzero(dest, len) _fmemset(dest, 0, len) 206 | # else 207 | # define zmemcpy memcpy 208 | # define zmemcmp memcmp 209 | # define zmemzero(dest, len) memset(dest, 0, len) 210 | # endif 211 | #else 212 | void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); 213 | int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); 214 | void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len)); 215 | #endif 216 | 217 | /* Diagnostic functions */ 218 | #ifdef DEBUG 219 | # include 220 | extern int ZLIB_INTERNAL z_verbose; 221 | extern void ZLIB_INTERNAL z_error OF((char *m)); 222 | # define Assert(cond,msg) {if(!(cond)) z_error(msg);} 223 | # define Trace(x) {if (z_verbose>=0) fprintf x ;} 224 | # define Tracev(x) {if (z_verbose>0) fprintf x ;} 225 | # define Tracevv(x) {if (z_verbose>1) fprintf x ;} 226 | # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} 227 | # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} 228 | #else 229 | # define Assert(cond,msg) 230 | # define Trace(x) 231 | # define Tracev(x) 232 | # define Tracevv(x) 233 | # define Tracec(c,x) 234 | # define Tracecv(c,x) 235 | #endif 236 | 237 | #ifndef Z_SOLO 238 | voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items, 239 | unsigned size)); 240 | void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr)); 241 | #endif 242 | 243 | #define ZALLOC(strm, items, size) \ 244 | (*((strm)->zalloc))((strm)->opaque, (items), (size)) 245 | #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) 246 | #define TRY_FREE(s, p) {if (p) ZFREE(s, p);} 247 | 248 | /* Reverse the bytes in a 32-bit value */ 249 | #define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \ 250 | (((q) & 0xff00) << 8) + (((q) & 0xff) << 24)) 251 | 252 | #endif /* ZUTIL_H */ 253 | --------------------------------------------------------------------------------