diff options
Diffstat (limited to '')
-rw-r--r-- | contrib/pascal/zlibpas.pas | 234 |
1 files changed, 234 insertions, 0 deletions
diff --git a/contrib/pascal/zlibpas.pas b/contrib/pascal/zlibpas.pas new file mode 100644 index 0000000..f81893f --- /dev/null +++ b/contrib/pascal/zlibpas.pas | |||
@@ -0,0 +1,234 @@ | |||
1 | (* zlibpas -- Pascal interface to the zlib data compression library | ||
2 | * | ||
3 | * Copyright (C) 2003 Cosmin Truta. | ||
4 | * Derived from original sources by Bob Dellaca. | ||
5 | * For conditions of distribution and use, see copyright notice in readme.txt | ||
6 | *) | ||
7 | |||
8 | unit zlibpas; | ||
9 | |||
10 | interface | ||
11 | |||
12 | const | ||
13 | ZLIB_VERSION = '1.2.0'; | ||
14 | |||
15 | type | ||
16 | alloc_func = function(opaque: Pointer; items, size: Integer): Pointer; | ||
17 | cdecl; | ||
18 | free_func = procedure(opaque, address: Pointer); | ||
19 | cdecl; | ||
20 | |||
21 | in_func = function(opaque: Pointer; var buf: PByte): Integer; | ||
22 | cdecl; | ||
23 | out_func = function(opaque: Pointer; buf: PByte; size: Integer): Integer; | ||
24 | cdecl; | ||
25 | |||
26 | z_streamp = ^z_stream; | ||
27 | z_stream = packed record | ||
28 | next_in: PChar; (* next input byte *) | ||
29 | avail_in: Integer; (* number of bytes available at next_in *) | ||
30 | total_in: LongInt; (* total nb of input bytes read so far *) | ||
31 | |||
32 | next_out: PChar; (* next output byte should be put there *) | ||
33 | avail_out: Integer; (* remaining free space at next_out *) | ||
34 | total_out: LongInt; (* total nb of bytes output so far *) | ||
35 | |||
36 | msg: PChar; (* last error message, NULL if no error *) | ||
37 | state: Pointer; (* not visible by applications *) | ||
38 | |||
39 | zalloc: alloc_func; (* used to allocate the internal state *) | ||
40 | zfree: free_func; (* used to free the internal state *) | ||
41 | opaque: Pointer; (* private data object passed to zalloc and zfree *) | ||
42 | |||
43 | data_type: Integer; (* best guess about the data type: ascii or binary *) | ||
44 | adler: LongInt; (* adler32 value of the uncompressed data *) | ||
45 | reserved: LongInt; (* reserved for future use *) | ||
46 | end; | ||
47 | |||
48 | (* constants *) | ||
49 | const | ||
50 | Z_NO_FLUSH = 0; | ||
51 | Z_PARTIAL_FLUSH = 1; | ||
52 | Z_SYNC_FLUSH = 2; | ||
53 | Z_FULL_FLUSH = 3; | ||
54 | Z_FINISH = 4; | ||
55 | |||
56 | Z_OK = 0; | ||
57 | Z_STREAM_END = 1; | ||
58 | Z_NEED_DICT = 2; | ||
59 | Z_ERRNO = -1; | ||
60 | Z_STREAM_ERROR = -2; | ||
61 | Z_DATA_ERROR = -3; | ||
62 | Z_MEM_ERROR = -4; | ||
63 | Z_BUF_ERROR = -5; | ||
64 | Z_VERSION_ERROR = -6; | ||
65 | |||
66 | Z_NO_COMPRESSION = 0; | ||
67 | Z_BEST_SPEED = 1; | ||
68 | Z_BEST_COMPRESSION = 9; | ||
69 | Z_DEFAULT_COMPRESSION = -1; | ||
70 | |||
71 | Z_FILTERED = 1; | ||
72 | Z_HUFFMAN_ONLY = 2; | ||
73 | Z_RLE = 3; | ||
74 | Z_DEFAULT_STRATEGY = 0; | ||
75 | |||
76 | Z_BINARY = 0; | ||
77 | Z_ASCII = 1; | ||
78 | Z_UNKNOWN = 2; | ||
79 | |||
80 | Z_DEFLATED = 8; | ||
81 | |||
82 | (* basic functions *) | ||
83 | function zlibVersion: PChar; | ||
84 | function deflateInit(var strm: z_stream; level: Integer): Integer; | ||
85 | function deflate(var strm: z_stream; flush: Integer): Integer; | ||
86 | function deflateEnd(var strm: z_stream): Integer; | ||
87 | function inflateInit(var strm: z_stream): Integer; | ||
88 | function inflate(var strm: z_stream; flush: Integer): Integer; | ||
89 | function inflateEnd(var strm: z_stream): Integer; | ||
90 | |||
91 | (* advanced functions *) | ||
92 | function deflateInit2(var strm: z_stream; level, method, windowBits, | ||
93 | memLevel, strategy: Integer): Integer; | ||
94 | function deflateSetDictionary(var strm: z_stream; const dictionary: PChar; | ||
95 | dictLength: Integer): Integer; | ||
96 | function deflateCopy(var dest, source: z_stream): Integer; | ||
97 | function deflateReset(var strm: z_stream): Integer; | ||
98 | function deflateParams(var strm: z_stream; level, strategy: Integer): Integer; | ||
99 | function deflateBound(var strm: z_stream; sourceLen: LongInt): LongInt; | ||
100 | function inflateInit2(var strm: z_stream; windowBits: Integer): Integer; | ||
101 | function inflateSetDictionary(var strm: z_stream; const dictionary: PChar; | ||
102 | dictLength: Integer): Integer; | ||
103 | function inflateSync(var strm: z_stream): Integer; | ||
104 | function inflateCopy(var dest, source: z_stream): Integer; | ||
105 | function inflateReset(var strm: z_stream): Integer; | ||
106 | function inflateBackInit(var strm: z_stream; | ||
107 | windowBits: Integer; window: PChar): Integer; | ||
108 | function inflateBack(var strm: z_stream; in_fn: in_func; in_desc: Pointer; | ||
109 | out_fn: out_func; out_desc: Pointer): Integer; | ||
110 | function inflateBackEnd(var strm: z_stream): Integer; | ||
111 | function zlibCompileFlags: LongInt; | ||
112 | |||
113 | (* utility functions *) | ||
114 | function compress(dest: PChar; var destLen: LongInt; | ||
115 | const source: PChar; sourceLen: LongInt): Integer; | ||
116 | function compress2(dest: PChar; var destLen: LongInt; | ||
117 | const source: PChar; sourceLen: LongInt; | ||
118 | level: Integer): Integer; | ||
119 | function compressBound(sourceLen: LongInt): LongInt; | ||
120 | function uncompress(dest: PChar; var destLen: LongInt; | ||
121 | const source: PChar; sourceLen: LongInt): Integer; | ||
122 | |||
123 | (* checksum functions *) | ||
124 | function adler32(adler: LongInt; const buf: PChar; len: Integer): LongInt; | ||
125 | function crc32(crc: LongInt; const buf: PChar; len: Integer): LongInt; | ||
126 | |||
127 | (* various hacks, don't look :) *) | ||
128 | function deflateInit_(var strm: z_stream; level: Integer; | ||
129 | const version: PChar; stream_size: Integer): Integer; | ||
130 | function inflateInit_(var strm: z_stream; const version: PChar; | ||
131 | stream_size: Integer): Integer; | ||
132 | function deflateInit2_(var strm: z_stream; | ||
133 | level, method, windowBits, memLevel, strategy: Integer; | ||
134 | const version: PChar; stream_size: Integer): Integer; | ||
135 | function inflateInit2_(var strm: z_stream; windowBits: Integer; | ||
136 | const version: PChar; stream_size: Integer): Integer; | ||
137 | function inflateBackInit_(var strm: z_stream; | ||
138 | windowBits: Integer; window: PChar; | ||
139 | const version: PChar; stream_size: Integer): Integer; | ||
140 | |||
141 | |||
142 | implementation | ||
143 | |||
144 | {$L adler32.obj} | ||
145 | {$L compress.obj} | ||
146 | {$L crc32.obj} | ||
147 | {$L deflate.obj} | ||
148 | {$L infback.obj} | ||
149 | {$L inffast.obj} | ||
150 | {$L inflate.obj} | ||
151 | {$L inftrees.obj} | ||
152 | {$L trees.obj} | ||
153 | {$L uncompr.obj} | ||
154 | {$L zutil.obj} | ||
155 | |||
156 | function adler32; external; | ||
157 | function compress; external; | ||
158 | function compress2; external; | ||
159 | function compressBound; external; | ||
160 | function crc32; external; | ||
161 | function deflate; external; | ||
162 | function deflateBound; external; | ||
163 | function deflateCopy; external; | ||
164 | function deflateEnd; external; | ||
165 | function deflateInit_; external; | ||
166 | function deflateInit2_; external; | ||
167 | function deflateParams; external; | ||
168 | function deflateReset; external; | ||
169 | function deflateSetDictionary; external; | ||
170 | function inflate; external; | ||
171 | function inflateBack; external; | ||
172 | function inflateBackEnd; external; | ||
173 | function inflateBackInit_; external; | ||
174 | function inflateCopy; external; | ||
175 | function inflateEnd; external; | ||
176 | function inflateInit_; external; | ||
177 | function inflateInit2_; external; | ||
178 | function inflateReset; external; | ||
179 | function inflateSetDictionary; external; | ||
180 | function inflateSync; external; | ||
181 | function uncompress; external; | ||
182 | function zlibCompileFlags; external; | ||
183 | function zlibVersion; external; | ||
184 | |||
185 | function deflateInit(var strm: z_stream; level: Integer): Integer; | ||
186 | begin | ||
187 | Result := deflateInit_(strm, level, ZLIB_VERSION, sizeof(z_stream)); | ||
188 | end; | ||
189 | |||
190 | function deflateInit2(var strm: z_stream; level, method, windowBits, memLevel, | ||
191 | strategy: Integer): Integer; | ||
192 | begin | ||
193 | Result := deflateInit2_(strm, level, method, windowBits, memLevel, strategy, | ||
194 | ZLIB_VERSION, sizeof(z_stream)); | ||
195 | end; | ||
196 | |||
197 | function inflateInit(var strm: z_stream): Integer; | ||
198 | begin | ||
199 | Result := inflateInit_(strm, ZLIB_VERSION, sizeof(z_stream)); | ||
200 | end; | ||
201 | |||
202 | function inflateInit2(var strm: z_stream; windowBits: Integer): Integer; | ||
203 | begin | ||
204 | Result := inflateInit2_(strm, windowBits, ZLIB_VERSION, sizeof(z_stream)); | ||
205 | end; | ||
206 | |||
207 | function inflateBackInit(var strm: z_stream; | ||
208 | windowBits: Integer; window: PChar): Integer; | ||
209 | begin | ||
210 | Result := inflateBackInit_(strm, windowBits, window, | ||
211 | ZLIB_VERSION, sizeof(z_stream)); | ||
212 | end; | ||
213 | |||
214 | function _malloc(Size: Integer): Pointer; cdecl; | ||
215 | begin | ||
216 | GetMem(Result, Size); | ||
217 | end; | ||
218 | |||
219 | procedure _free(Block: Pointer); cdecl; | ||
220 | begin | ||
221 | FreeMem(Block); | ||
222 | end; | ||
223 | |||
224 | procedure _memset(P: Pointer; B: Byte; count: Integer); cdecl; | ||
225 | begin | ||
226 | FillChar(P^, count, B); | ||
227 | end; | ||
228 | |||
229 | procedure _memcpy(dest, source: Pointer; count: Integer); cdecl; | ||
230 | begin | ||
231 | Move(source^, dest^, count); | ||
232 | end; | ||
233 | |||
234 | end. | ||