annotate src/zlib-1.2.8/contrib/pascal/zlibpas.pas @ 43:5ea0608b923f

Current zlib source
author Chris Cannam
date Tue, 18 Oct 2016 14:33:52 +0100
parents
children
rev   line source
Chris@43 1 (* zlibpas -- Pascal interface to the zlib data compression library
Chris@43 2 *
Chris@43 3 * Copyright (C) 2003 Cosmin Truta.
Chris@43 4 * Derived from original sources by Bob Dellaca.
Chris@43 5 * For conditions of distribution and use, see copyright notice in readme.txt
Chris@43 6 *)
Chris@43 7
Chris@43 8 unit zlibpas;
Chris@43 9
Chris@43 10 interface
Chris@43 11
Chris@43 12 const
Chris@43 13 ZLIB_VERSION = '1.2.8';
Chris@43 14 ZLIB_VERNUM = $1280;
Chris@43 15
Chris@43 16 type
Chris@43 17 alloc_func = function(opaque: Pointer; items, size: Integer): Pointer;
Chris@43 18 cdecl;
Chris@43 19 free_func = procedure(opaque, address: Pointer);
Chris@43 20 cdecl;
Chris@43 21
Chris@43 22 in_func = function(opaque: Pointer; var buf: PByte): Integer;
Chris@43 23 cdecl;
Chris@43 24 out_func = function(opaque: Pointer; buf: PByte; size: Integer): Integer;
Chris@43 25 cdecl;
Chris@43 26
Chris@43 27 z_streamp = ^z_stream;
Chris@43 28 z_stream = packed record
Chris@43 29 next_in: PChar; (* next input byte *)
Chris@43 30 avail_in: Integer; (* number of bytes available at next_in *)
Chris@43 31 total_in: LongInt; (* total nb of input bytes read so far *)
Chris@43 32
Chris@43 33 next_out: PChar; (* next output byte should be put there *)
Chris@43 34 avail_out: Integer; (* remaining free space at next_out *)
Chris@43 35 total_out: LongInt; (* total nb of bytes output so far *)
Chris@43 36
Chris@43 37 msg: PChar; (* last error message, NULL if no error *)
Chris@43 38 state: Pointer; (* not visible by applications *)
Chris@43 39
Chris@43 40 zalloc: alloc_func; (* used to allocate the internal state *)
Chris@43 41 zfree: free_func; (* used to free the internal state *)
Chris@43 42 opaque: Pointer; (* private data object passed to zalloc and zfree *)
Chris@43 43
Chris@43 44 data_type: Integer; (* best guess about the data type: ascii or binary *)
Chris@43 45 adler: LongInt; (* adler32 value of the uncompressed data *)
Chris@43 46 reserved: LongInt; (* reserved for future use *)
Chris@43 47 end;
Chris@43 48
Chris@43 49 gz_headerp = ^gz_header;
Chris@43 50 gz_header = packed record
Chris@43 51 text: Integer; (* true if compressed data believed to be text *)
Chris@43 52 time: LongInt; (* modification time *)
Chris@43 53 xflags: Integer; (* extra flags (not used when writing a gzip file) *)
Chris@43 54 os: Integer; (* operating system *)
Chris@43 55 extra: PChar; (* pointer to extra field or Z_NULL if none *)
Chris@43 56 extra_len: Integer; (* extra field length (valid if extra != Z_NULL) *)
Chris@43 57 extra_max: Integer; (* space at extra (only when reading header) *)
Chris@43 58 name: PChar; (* pointer to zero-terminated file name or Z_NULL *)
Chris@43 59 name_max: Integer; (* space at name (only when reading header) *)
Chris@43 60 comment: PChar; (* pointer to zero-terminated comment or Z_NULL *)
Chris@43 61 comm_max: Integer; (* space at comment (only when reading header) *)
Chris@43 62 hcrc: Integer; (* true if there was or will be a header crc *)
Chris@43 63 done: Integer; (* true when done reading gzip header *)
Chris@43 64 end;
Chris@43 65
Chris@43 66 (* constants *)
Chris@43 67 const
Chris@43 68 Z_NO_FLUSH = 0;
Chris@43 69 Z_PARTIAL_FLUSH = 1;
Chris@43 70 Z_SYNC_FLUSH = 2;
Chris@43 71 Z_FULL_FLUSH = 3;
Chris@43 72 Z_FINISH = 4;
Chris@43 73 Z_BLOCK = 5;
Chris@43 74 Z_TREES = 6;
Chris@43 75
Chris@43 76 Z_OK = 0;
Chris@43 77 Z_STREAM_END = 1;
Chris@43 78 Z_NEED_DICT = 2;
Chris@43 79 Z_ERRNO = -1;
Chris@43 80 Z_STREAM_ERROR = -2;
Chris@43 81 Z_DATA_ERROR = -3;
Chris@43 82 Z_MEM_ERROR = -4;
Chris@43 83 Z_BUF_ERROR = -5;
Chris@43 84 Z_VERSION_ERROR = -6;
Chris@43 85
Chris@43 86 Z_NO_COMPRESSION = 0;
Chris@43 87 Z_BEST_SPEED = 1;
Chris@43 88 Z_BEST_COMPRESSION = 9;
Chris@43 89 Z_DEFAULT_COMPRESSION = -1;
Chris@43 90
Chris@43 91 Z_FILTERED = 1;
Chris@43 92 Z_HUFFMAN_ONLY = 2;
Chris@43 93 Z_RLE = 3;
Chris@43 94 Z_FIXED = 4;
Chris@43 95 Z_DEFAULT_STRATEGY = 0;
Chris@43 96
Chris@43 97 Z_BINARY = 0;
Chris@43 98 Z_TEXT = 1;
Chris@43 99 Z_ASCII = 1;
Chris@43 100 Z_UNKNOWN = 2;
Chris@43 101
Chris@43 102 Z_DEFLATED = 8;
Chris@43 103
Chris@43 104 (* basic functions *)
Chris@43 105 function zlibVersion: PChar;
Chris@43 106 function deflateInit(var strm: z_stream; level: Integer): Integer;
Chris@43 107 function deflate(var strm: z_stream; flush: Integer): Integer;
Chris@43 108 function deflateEnd(var strm: z_stream): Integer;
Chris@43 109 function inflateInit(var strm: z_stream): Integer;
Chris@43 110 function inflate(var strm: z_stream; flush: Integer): Integer;
Chris@43 111 function inflateEnd(var strm: z_stream): Integer;
Chris@43 112
Chris@43 113 (* advanced functions *)
Chris@43 114 function deflateInit2(var strm: z_stream; level, method, windowBits,
Chris@43 115 memLevel, strategy: Integer): Integer;
Chris@43 116 function deflateSetDictionary(var strm: z_stream; const dictionary: PChar;
Chris@43 117 dictLength: Integer): Integer;
Chris@43 118 function deflateCopy(var dest, source: z_stream): Integer;
Chris@43 119 function deflateReset(var strm: z_stream): Integer;
Chris@43 120 function deflateParams(var strm: z_stream; level, strategy: Integer): Integer;
Chris@43 121 function deflateTune(var strm: z_stream; good_length, max_lazy, nice_length, max_chain: Integer): Integer;
Chris@43 122 function deflateBound(var strm: z_stream; sourceLen: LongInt): LongInt;
Chris@43 123 function deflatePending(var strm: z_stream; var pending: Integer; var bits: Integer): Integer;
Chris@43 124 function deflatePrime(var strm: z_stream; bits, value: Integer): Integer;
Chris@43 125 function deflateSetHeader(var strm: z_stream; head: gz_header): Integer;
Chris@43 126 function inflateInit2(var strm: z_stream; windowBits: Integer): Integer;
Chris@43 127 function inflateSetDictionary(var strm: z_stream; const dictionary: PChar;
Chris@43 128 dictLength: Integer): Integer;
Chris@43 129 function inflateSync(var strm: z_stream): Integer;
Chris@43 130 function inflateCopy(var dest, source: z_stream): Integer;
Chris@43 131 function inflateReset(var strm: z_stream): Integer;
Chris@43 132 function inflateReset2(var strm: z_stream; windowBits: Integer): Integer;
Chris@43 133 function inflatePrime(var strm: z_stream; bits, value: Integer): Integer;
Chris@43 134 function inflateMark(var strm: z_stream): LongInt;
Chris@43 135 function inflateGetHeader(var strm: z_stream; var head: gz_header): Integer;
Chris@43 136 function inflateBackInit(var strm: z_stream;
Chris@43 137 windowBits: Integer; window: PChar): Integer;
Chris@43 138 function inflateBack(var strm: z_stream; in_fn: in_func; in_desc: Pointer;
Chris@43 139 out_fn: out_func; out_desc: Pointer): Integer;
Chris@43 140 function inflateBackEnd(var strm: z_stream): Integer;
Chris@43 141 function zlibCompileFlags: LongInt;
Chris@43 142
Chris@43 143 (* utility functions *)
Chris@43 144 function compress(dest: PChar; var destLen: LongInt;
Chris@43 145 const source: PChar; sourceLen: LongInt): Integer;
Chris@43 146 function compress2(dest: PChar; var destLen: LongInt;
Chris@43 147 const source: PChar; sourceLen: LongInt;
Chris@43 148 level: Integer): Integer;
Chris@43 149 function compressBound(sourceLen: LongInt): LongInt;
Chris@43 150 function uncompress(dest: PChar; var destLen: LongInt;
Chris@43 151 const source: PChar; sourceLen: LongInt): Integer;
Chris@43 152
Chris@43 153 (* checksum functions *)
Chris@43 154 function adler32(adler: LongInt; const buf: PChar; len: Integer): LongInt;
Chris@43 155 function adler32_combine(adler1, adler2, len2: LongInt): LongInt;
Chris@43 156 function crc32(crc: LongInt; const buf: PChar; len: Integer): LongInt;
Chris@43 157 function crc32_combine(crc1, crc2, len2: LongInt): LongInt;
Chris@43 158
Chris@43 159 (* various hacks, don't look :) *)
Chris@43 160 function deflateInit_(var strm: z_stream; level: Integer;
Chris@43 161 const version: PChar; stream_size: Integer): Integer;
Chris@43 162 function inflateInit_(var strm: z_stream; const version: PChar;
Chris@43 163 stream_size: Integer): Integer;
Chris@43 164 function deflateInit2_(var strm: z_stream;
Chris@43 165 level, method, windowBits, memLevel, strategy: Integer;
Chris@43 166 const version: PChar; stream_size: Integer): Integer;
Chris@43 167 function inflateInit2_(var strm: z_stream; windowBits: Integer;
Chris@43 168 const version: PChar; stream_size: Integer): Integer;
Chris@43 169 function inflateBackInit_(var strm: z_stream;
Chris@43 170 windowBits: Integer; window: PChar;
Chris@43 171 const version: PChar; stream_size: Integer): Integer;
Chris@43 172
Chris@43 173
Chris@43 174 implementation
Chris@43 175
Chris@43 176 {$L adler32.obj}
Chris@43 177 {$L compress.obj}
Chris@43 178 {$L crc32.obj}
Chris@43 179 {$L deflate.obj}
Chris@43 180 {$L infback.obj}
Chris@43 181 {$L inffast.obj}
Chris@43 182 {$L inflate.obj}
Chris@43 183 {$L inftrees.obj}
Chris@43 184 {$L trees.obj}
Chris@43 185 {$L uncompr.obj}
Chris@43 186 {$L zutil.obj}
Chris@43 187
Chris@43 188 function adler32; external;
Chris@43 189 function adler32_combine; external;
Chris@43 190 function compress; external;
Chris@43 191 function compress2; external;
Chris@43 192 function compressBound; external;
Chris@43 193 function crc32; external;
Chris@43 194 function crc32_combine; external;
Chris@43 195 function deflate; external;
Chris@43 196 function deflateBound; external;
Chris@43 197 function deflateCopy; external;
Chris@43 198 function deflateEnd; external;
Chris@43 199 function deflateInit_; external;
Chris@43 200 function deflateInit2_; external;
Chris@43 201 function deflateParams; external;
Chris@43 202 function deflatePending; external;
Chris@43 203 function deflatePrime; external;
Chris@43 204 function deflateReset; external;
Chris@43 205 function deflateSetDictionary; external;
Chris@43 206 function deflateSetHeader; external;
Chris@43 207 function deflateTune; external;
Chris@43 208 function inflate; external;
Chris@43 209 function inflateBack; external;
Chris@43 210 function inflateBackEnd; external;
Chris@43 211 function inflateBackInit_; external;
Chris@43 212 function inflateCopy; external;
Chris@43 213 function inflateEnd; external;
Chris@43 214 function inflateGetHeader; external;
Chris@43 215 function inflateInit_; external;
Chris@43 216 function inflateInit2_; external;
Chris@43 217 function inflateMark; external;
Chris@43 218 function inflatePrime; external;
Chris@43 219 function inflateReset; external;
Chris@43 220 function inflateReset2; external;
Chris@43 221 function inflateSetDictionary; external;
Chris@43 222 function inflateSync; external;
Chris@43 223 function uncompress; external;
Chris@43 224 function zlibCompileFlags; external;
Chris@43 225 function zlibVersion; external;
Chris@43 226
Chris@43 227 function deflateInit(var strm: z_stream; level: Integer): Integer;
Chris@43 228 begin
Chris@43 229 Result := deflateInit_(strm, level, ZLIB_VERSION, sizeof(z_stream));
Chris@43 230 end;
Chris@43 231
Chris@43 232 function deflateInit2(var strm: z_stream; level, method, windowBits, memLevel,
Chris@43 233 strategy: Integer): Integer;
Chris@43 234 begin
Chris@43 235 Result := deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
Chris@43 236 ZLIB_VERSION, sizeof(z_stream));
Chris@43 237 end;
Chris@43 238
Chris@43 239 function inflateInit(var strm: z_stream): Integer;
Chris@43 240 begin
Chris@43 241 Result := inflateInit_(strm, ZLIB_VERSION, sizeof(z_stream));
Chris@43 242 end;
Chris@43 243
Chris@43 244 function inflateInit2(var strm: z_stream; windowBits: Integer): Integer;
Chris@43 245 begin
Chris@43 246 Result := inflateInit2_(strm, windowBits, ZLIB_VERSION, sizeof(z_stream));
Chris@43 247 end;
Chris@43 248
Chris@43 249 function inflateBackInit(var strm: z_stream;
Chris@43 250 windowBits: Integer; window: PChar): Integer;
Chris@43 251 begin
Chris@43 252 Result := inflateBackInit_(strm, windowBits, window,
Chris@43 253 ZLIB_VERSION, sizeof(z_stream));
Chris@43 254 end;
Chris@43 255
Chris@43 256 function _malloc(Size: Integer): Pointer; cdecl;
Chris@43 257 begin
Chris@43 258 GetMem(Result, Size);
Chris@43 259 end;
Chris@43 260
Chris@43 261 procedure _free(Block: Pointer); cdecl;
Chris@43 262 begin
Chris@43 263 FreeMem(Block);
Chris@43 264 end;
Chris@43 265
Chris@43 266 procedure _memset(P: Pointer; B: Byte; count: Integer); cdecl;
Chris@43 267 begin
Chris@43 268 FillChar(P^, count, B);
Chris@43 269 end;
Chris@43 270
Chris@43 271 procedure _memcpy(dest, source: Pointer; count: Integer); cdecl;
Chris@43 272 begin
Chris@43 273 Move(source^, dest^, count);
Chris@43 274 end;
Chris@43 275
Chris@43 276 end.