annotate src/zlib-1.2.8/contrib/pascal/zlibpas.pas @ 128:5b4145a0d408

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