diff options
Diffstat (limited to 'contrib/ada/zlib-thin.ads')
-rw-r--r-- | contrib/ada/zlib-thin.ads | 478 |
1 files changed, 478 insertions, 0 deletions
diff --git a/contrib/ada/zlib-thin.ads b/contrib/ada/zlib-thin.ads new file mode 100644 index 0000000..19cbb96 --- /dev/null +++ b/contrib/ada/zlib-thin.ads | |||
@@ -0,0 +1,478 @@ | |||
1 | ---------------------------------------------------------------- | ||
2 | -- ZLib for Ada thick binding. -- | ||
3 | -- -- | ||
4 | -- Copyright (C) 2002-2003 Dmitriy Anisimkov -- | ||
5 | -- -- | ||
6 | -- Open source license information is in the zlib.ads file. -- | ||
7 | ---------------------------------------------------------------- | ||
8 | |||
9 | -- $Id: zlib-thin.ads,v 1.8 2003/08/12 13:16:51 vagul Exp $ | ||
10 | |||
11 | with Interfaces.C.Strings; | ||
12 | with System.Address_To_Access_Conversions; | ||
13 | |||
14 | private package ZLib.Thin is | ||
15 | |||
16 | -- From zconf.h | ||
17 | |||
18 | MAX_MEM_LEVEL : constant := 9; -- zconf.h:105 | ||
19 | -- zconf.h:105 | ||
20 | MAX_WBITS : constant := 15; -- zconf.h:115 | ||
21 | -- 32K LZ77 window | ||
22 | -- zconf.h:115 | ||
23 | SEEK_SET : constant := 8#0000#; -- zconf.h:244 | ||
24 | -- Seek from beginning of file. | ||
25 | -- zconf.h:244 | ||
26 | SEEK_CUR : constant := 1; -- zconf.h:245 | ||
27 | -- Seek from current position. | ||
28 | -- zconf.h:245 | ||
29 | SEEK_END : constant := 2; -- zconf.h:246 | ||
30 | -- Set file pointer to EOF plus "offset" | ||
31 | -- zconf.h:246 | ||
32 | |||
33 | type Byte is new Interfaces.C.unsigned_char; -- 8 bits | ||
34 | -- zconf.h:214 | ||
35 | type UInt is new Interfaces.C.unsigned; -- 16 bits or more | ||
36 | -- zconf.h:216 | ||
37 | type Int is new Interfaces.C.int; | ||
38 | |||
39 | type ULong is new Interfaces.C.unsigned; -- 32 bits or more | ||
40 | -- zconf.h:217 | ||
41 | subtype Chars_Ptr is Interfaces.C.Strings.chars_ptr; | ||
42 | |||
43 | type ULong_Access is access ULong; | ||
44 | type Int_Access is access Int; | ||
45 | subtype Voidp is System.Address; -- zconf.h:232 | ||
46 | |||
47 | package Bytes is new System.Address_To_Access_Conversions (Byte); | ||
48 | |||
49 | subtype Byte_Access is Bytes.Object_Pointer; | ||
50 | |||
51 | -- end from zconf | ||
52 | |||
53 | Z_NO_FLUSH : constant := 8#0000#; -- zlib.h:125 | ||
54 | -- zlib.h:125 | ||
55 | Z_PARTIAL_FLUSH : constant := 1; -- zlib.h:126 | ||
56 | -- will be removed, use | ||
57 | -- Z_SYNC_FLUSH instead | ||
58 | -- zlib.h:126 | ||
59 | Z_SYNC_FLUSH : constant := 2; -- zlib.h:127 | ||
60 | -- zlib.h:127 | ||
61 | Z_FULL_FLUSH : constant := 3; -- zlib.h:128 | ||
62 | -- zlib.h:128 | ||
63 | Z_FINISH : constant := 4; -- zlib.h:129 | ||
64 | -- zlib.h:129 | ||
65 | Z_OK : constant := 8#0000#; -- zlib.h:132 | ||
66 | -- zlib.h:132 | ||
67 | Z_STREAM_END : constant := 1; -- zlib.h:133 | ||
68 | -- zlib.h:133 | ||
69 | Z_NEED_DICT : constant := 2; -- zlib.h:134 | ||
70 | -- zlib.h:134 | ||
71 | Z_ERRNO : constant := -1; -- zlib.h:135 | ||
72 | -- zlib.h:135 | ||
73 | Z_STREAM_ERROR : constant := -2; -- zlib.h:136 | ||
74 | -- zlib.h:136 | ||
75 | Z_DATA_ERROR : constant := -3; -- zlib.h:137 | ||
76 | -- zlib.h:137 | ||
77 | Z_MEM_ERROR : constant := -4; -- zlib.h:138 | ||
78 | -- zlib.h:138 | ||
79 | Z_BUF_ERROR : constant := -5; -- zlib.h:139 | ||
80 | -- zlib.h:139 | ||
81 | Z_VERSION_ERROR : constant := -6; -- zlib.h:140 | ||
82 | -- zlib.h:140 | ||
83 | Z_NO_COMPRESSION : constant := 8#0000#; -- zlib.h:145 | ||
84 | -- zlib.h:145 | ||
85 | Z_BEST_SPEED : constant := 1; -- zlib.h:146 | ||
86 | -- zlib.h:146 | ||
87 | Z_BEST_COMPRESSION : constant := 9; -- zlib.h:147 | ||
88 | -- zlib.h:147 | ||
89 | Z_DEFAULT_COMPRESSION : constant := -1; -- zlib.h:148 | ||
90 | -- zlib.h:148 | ||
91 | Z_FILTERED : constant := 1; -- zlib.h:151 | ||
92 | -- zlib.h:151 | ||
93 | Z_HUFFMAN_ONLY : constant := 2; -- zlib.h:152 | ||
94 | -- zlib.h:152 | ||
95 | Z_DEFAULT_STRATEGY : constant := 8#0000#; -- zlib.h:153 | ||
96 | -- zlib.h:153 | ||
97 | Z_BINARY : constant := 8#0000#; -- zlib.h:156 | ||
98 | -- zlib.h:156 | ||
99 | Z_ASCII : constant := 1; -- zlib.h:157 | ||
100 | -- zlib.h:157 | ||
101 | Z_UNKNOWN : constant := 2; -- zlib.h:158 | ||
102 | -- zlib.h:158 | ||
103 | Z_DEFLATED : constant := 8; -- zlib.h:161 | ||
104 | -- zlib.h:161 | ||
105 | Z_NULL : constant := 8#0000#; -- zlib.h:164 | ||
106 | -- for initializing zalloc, zfree, opaque | ||
107 | -- zlib.h:164 | ||
108 | type gzFile is new Voidp; -- zlib.h:646 | ||
109 | |||
110 | type Z_Stream is private; | ||
111 | |||
112 | type Z_Streamp is access all Z_Stream; -- zlib.h:89 | ||
113 | |||
114 | type alloc_func is access function | ||
115 | (Opaque : Voidp; | ||
116 | Items : UInt; | ||
117 | Size : UInt) | ||
118 | return Voidp; -- zlib.h:63 | ||
119 | |||
120 | type free_func is access procedure (opaque : Voidp; address : Voidp); | ||
121 | |||
122 | function zlibVersion return Chars_Ptr; | ||
123 | |||
124 | function Deflate (strm : Z_Streamp; flush : Int) return Int; | ||
125 | |||
126 | function DeflateEnd (strm : Z_Streamp) return Int; | ||
127 | |||
128 | function Inflate (strm : Z_Streamp; flush : Int) return Int; | ||
129 | |||
130 | function InflateEnd (strm : Z_Streamp) return Int; | ||
131 | |||
132 | function deflateSetDictionary | ||
133 | (strm : Z_Streamp; | ||
134 | dictionary : Byte_Access; | ||
135 | dictLength : UInt) | ||
136 | return Int; | ||
137 | |||
138 | function deflateCopy (dest : Z_Streamp; source : Z_Streamp) return Int; | ||
139 | -- zlib.h:478 | ||
140 | |||
141 | function deflateReset (strm : Z_Streamp) return Int; -- zlib.h:495 | ||
142 | |||
143 | function deflateParams | ||
144 | (strm : Z_Streamp; | ||
145 | level : Int; | ||
146 | strategy : Int) | ||
147 | return Int; -- zlib.h:506 | ||
148 | |||
149 | function inflateSetDictionary | ||
150 | (strm : Z_Streamp; | ||
151 | dictionary : Byte_Access; | ||
152 | dictLength : UInt) | ||
153 | return Int; -- zlib.h:548 | ||
154 | |||
155 | function inflateSync (strm : Z_Streamp) return Int; -- zlib.h:565 | ||
156 | |||
157 | function inflateReset (strm : Z_Streamp) return Int; -- zlib.h:580 | ||
158 | |||
159 | function compress | ||
160 | (dest : Byte_Access; | ||
161 | destLen : ULong_Access; | ||
162 | source : Byte_Access; | ||
163 | sourceLen : ULong) | ||
164 | return Int; -- zlib.h:601 | ||
165 | |||
166 | function compress2 | ||
167 | (dest : Byte_Access; | ||
168 | destLen : ULong_Access; | ||
169 | source : Byte_Access; | ||
170 | sourceLen : ULong; | ||
171 | level : Int) | ||
172 | return Int; -- zlib.h:615 | ||
173 | |||
174 | function uncompress | ||
175 | (dest : Byte_Access; | ||
176 | destLen : ULong_Access; | ||
177 | source : Byte_Access; | ||
178 | sourceLen : ULong) | ||
179 | return Int; | ||
180 | |||
181 | function gzopen (path : Chars_Ptr; mode : Chars_Ptr) return gzFile; | ||
182 | |||
183 | function gzdopen (fd : Int; mode : Chars_Ptr) return gzFile; | ||
184 | |||
185 | function gzsetparams | ||
186 | (file : gzFile; | ||
187 | level : Int; | ||
188 | strategy : Int) | ||
189 | return Int; | ||
190 | |||
191 | function gzread | ||
192 | (file : gzFile; | ||
193 | buf : Voidp; | ||
194 | len : UInt) | ||
195 | return Int; | ||
196 | |||
197 | function gzwrite | ||
198 | (file : in gzFile; | ||
199 | buf : in Voidp; | ||
200 | len : in UInt) | ||
201 | return Int; | ||
202 | |||
203 | function gzprintf (file : in gzFile; format : in Chars_Ptr) return Int; | ||
204 | |||
205 | function gzputs (file : in gzFile; s : in Chars_Ptr) return Int; | ||
206 | |||
207 | function gzgets | ||
208 | (file : gzFile; | ||
209 | buf : Chars_Ptr; | ||
210 | len : Int) | ||
211 | return Chars_Ptr; | ||
212 | |||
213 | function gzputc (file : gzFile; char : Int) return Int; | ||
214 | |||
215 | function gzgetc (file : gzFile) return Int; | ||
216 | |||
217 | function gzflush (file : gzFile; flush : Int) return Int; | ||
218 | |||
219 | function gzseek | ||
220 | (file : gzFile; | ||
221 | offset : Int; | ||
222 | whence : Int) | ||
223 | return Int; | ||
224 | |||
225 | function gzrewind (file : gzFile) return Int; | ||
226 | |||
227 | function gztell (file : gzFile) return Int; | ||
228 | |||
229 | function gzeof (file : gzFile) return Int; | ||
230 | |||
231 | function gzclose (file : gzFile) return Int; | ||
232 | |||
233 | function gzerror (file : gzFile; errnum : Int_Access) return Chars_Ptr; | ||
234 | |||
235 | function adler32 | ||
236 | (adler : ULong; | ||
237 | buf : Byte_Access; | ||
238 | len : UInt) | ||
239 | return ULong; | ||
240 | |||
241 | function crc32 | ||
242 | (crc : ULong; | ||
243 | buf : Byte_Access; | ||
244 | len : UInt) | ||
245 | return ULong; | ||
246 | |||
247 | function deflateInit | ||
248 | (strm : Z_Streamp; | ||
249 | level : Int; | ||
250 | version : Chars_Ptr; | ||
251 | stream_size : Int) | ||
252 | return Int; | ||
253 | |||
254 | function Deflate_Init | ||
255 | (strm : in Z_Streamp; | ||
256 | level : in Int := Z_DEFAULT_COMPRESSION) | ||
257 | return Int; | ||
258 | pragma Inline (Deflate_Init); | ||
259 | |||
260 | function deflateInit2 | ||
261 | (strm : Z_Streamp; | ||
262 | level : Int; | ||
263 | method : Int; | ||
264 | windowBits : Int; | ||
265 | memLevel : Int; | ||
266 | strategy : Int; | ||
267 | version : Chars_Ptr; | ||
268 | stream_size : Int) | ||
269 | return Int; | ||
270 | |||
271 | function Deflate_Init | ||
272 | (strm : Z_Streamp; | ||
273 | level : Int; | ||
274 | method : Int; | ||
275 | windowBits : Int; | ||
276 | memLevel : Int; | ||
277 | strategy : Int) | ||
278 | return Int; | ||
279 | pragma Inline (Deflate_Init); | ||
280 | |||
281 | function inflateInit | ||
282 | (strm : Z_Streamp; | ||
283 | version : Chars_Ptr; | ||
284 | stream_size : Int) | ||
285 | return Int; | ||
286 | |||
287 | function Inflate_Init (strm : Z_Streamp) return Int; | ||
288 | pragma Inline (Inflate_Init); | ||
289 | |||
290 | function inflateInit2 | ||
291 | (strm : in Z_Streamp; | ||
292 | windowBits : in Int; | ||
293 | version : in Chars_Ptr; | ||
294 | stream_size : in Int) | ||
295 | return Int; | ||
296 | |||
297 | function inflateBackInit | ||
298 | (strm : in Z_Streamp; | ||
299 | windowBits : in Int; | ||
300 | window : in Byte_Access; | ||
301 | version : in Chars_Ptr; | ||
302 | stream_size : in Int) | ||
303 | return Int; | ||
304 | -- Size of window have to be 2**windowBits. | ||
305 | |||
306 | function Inflate_Init (strm : Z_Streamp; windowBits : Int) return Int; | ||
307 | pragma Inline (Inflate_Init); | ||
308 | |||
309 | function zError (err : Int) return Chars_Ptr; | ||
310 | |||
311 | function inflateSyncPoint (z : Z_Streamp) return Int; | ||
312 | |||
313 | function get_crc_table return ULong_Access; | ||
314 | |||
315 | -- Interface to the available fields of the z_stream structure. | ||
316 | -- The application must update next_in and avail_in when avail_in has | ||
317 | -- dropped to zero. It must update next_out and avail_out when avail_out | ||
318 | -- has dropped to zero. The application must initialize zalloc, zfree and | ||
319 | -- opaque before calling the init function. | ||
320 | |||
321 | function Need_In (strm : in Z_Stream) return Boolean; | ||
322 | -- return true when we do not need to setup Next_In and Avail_In fields. | ||
323 | pragma Inline (Need_In); | ||
324 | |||
325 | function Need_Out (strm : in Z_Stream) return Boolean; | ||
326 | -- return true when we do not need to setup Next_Out and Avail_Out field. | ||
327 | pragma Inline (Need_Out); | ||
328 | |||
329 | procedure Set_In | ||
330 | (Strm : in out Z_Stream; | ||
331 | Buffer : in Byte_Access; | ||
332 | Size : in UInt); | ||
333 | pragma Inline (Set_In); | ||
334 | |||
335 | procedure Set_In | ||
336 | (Strm : in out Z_Stream; | ||
337 | Buffer : in Voidp; | ||
338 | Size : in UInt); | ||
339 | pragma Inline (Set_In); | ||
340 | |||
341 | procedure Set_Out | ||
342 | (Strm : in out Z_Stream; | ||
343 | Buffer : in Byte_Access; | ||
344 | Size : in UInt); | ||
345 | pragma Inline (Set_Out); | ||
346 | |||
347 | procedure Set_Out | ||
348 | (Strm : in out Z_Stream; | ||
349 | Buffer : in Voidp; | ||
350 | Size : in UInt); | ||
351 | pragma Inline (Set_Out); | ||
352 | |||
353 | procedure Set_Mem_Func | ||
354 | (Strm : in out Z_Stream; | ||
355 | Opaque : in Voidp; | ||
356 | Alloc : in alloc_func; | ||
357 | Free : in free_func); | ||
358 | pragma Inline (Set_Mem_Func); | ||
359 | |||
360 | function Last_Error_Message (Strm : in Z_Stream) return String; | ||
361 | pragma Inline (Last_Error_Message); | ||
362 | |||
363 | function Avail_Out (Strm : in Z_Stream) return UInt; | ||
364 | pragma Inline (Avail_Out); | ||
365 | |||
366 | function Avail_In (Strm : in Z_Stream) return UInt; | ||
367 | pragma Inline (Avail_In); | ||
368 | |||
369 | function Total_In (Strm : in Z_Stream) return ULong; | ||
370 | pragma Inline (Total_In); | ||
371 | |||
372 | function Total_Out (Strm : in Z_Stream) return ULong; | ||
373 | pragma Inline (Total_Out); | ||
374 | |||
375 | function inflateCopy | ||
376 | (dest : in Z_Streamp; | ||
377 | Source : in Z_Streamp) | ||
378 | return Int; | ||
379 | |||
380 | function compressBound (Source_Len : in ULong) return ULong; | ||
381 | |||
382 | function deflateBound | ||
383 | (Strm : in Z_Streamp; | ||
384 | Source_Len : in ULong) | ||
385 | return ULong; | ||
386 | |||
387 | function gzungetc (C : in Int; File : in gzFile) return Int; | ||
388 | |||
389 | function zlibCompileFlags return ULong; | ||
390 | |||
391 | private | ||
392 | |||
393 | type Z_Stream is record -- zlib.h:68 | ||
394 | Next_In : Byte_Access; -- next input byte | ||
395 | Avail_In : UInt := 0; -- number of bytes available at next_in | ||
396 | Total_In : ULong := 0; -- total nb of input bytes read so far | ||
397 | Next_Out : Byte_Access; -- next output byte should be put there | ||
398 | Avail_Out : UInt := 0; -- remaining free space at next_out | ||
399 | Total_Out : ULong := 0; -- total nb of bytes output so far | ||
400 | msg : Chars_Ptr; -- last error message, NULL if no error | ||
401 | state : Voidp; -- not visible by applications | ||
402 | zalloc : alloc_func := null; -- used to allocate the internal state | ||
403 | zfree : free_func := null; -- used to free the internal state | ||
404 | opaque : Voidp; -- private data object passed to | ||
405 | -- zalloc and zfree | ||
406 | data_type : Int; -- best guess about the data type: | ||
407 | -- ascii or binary | ||
408 | adler : ULong; -- adler32 value of the uncompressed | ||
409 | -- data | ||
410 | reserved : ULong; -- reserved for future use | ||
411 | end record; | ||
412 | |||
413 | pragma Convention (C, Z_Stream); | ||
414 | |||
415 | pragma Import (C, zlibVersion, "zlibVersion"); | ||
416 | pragma Import (C, Deflate, "deflate"); | ||
417 | pragma Import (C, DeflateEnd, "deflateEnd"); | ||
418 | pragma Import (C, Inflate, "inflate"); | ||
419 | pragma Import (C, InflateEnd, "inflateEnd"); | ||
420 | pragma Import (C, deflateSetDictionary, "deflateSetDictionary"); | ||
421 | pragma Import (C, deflateCopy, "deflateCopy"); | ||
422 | pragma Import (C, deflateReset, "deflateReset"); | ||
423 | pragma Import (C, deflateParams, "deflateParams"); | ||
424 | pragma Import (C, inflateSetDictionary, "inflateSetDictionary"); | ||
425 | pragma Import (C, inflateSync, "inflateSync"); | ||
426 | pragma Import (C, inflateReset, "inflateReset"); | ||
427 | pragma Import (C, compress, "compress"); | ||
428 | pragma Import (C, compress2, "compress2"); | ||
429 | pragma Import (C, uncompress, "uncompress"); | ||
430 | pragma Import (C, gzopen, "gzopen"); | ||
431 | pragma Import (C, gzdopen, "gzdopen"); | ||
432 | pragma Import (C, gzsetparams, "gzsetparams"); | ||
433 | pragma Import (C, gzread, "gzread"); | ||
434 | pragma Import (C, gzwrite, "gzwrite"); | ||
435 | pragma Import (C, gzprintf, "gzprintf"); | ||
436 | pragma Import (C, gzputs, "gzputs"); | ||
437 | pragma Import (C, gzgets, "gzgets"); | ||
438 | pragma Import (C, gzputc, "gzputc"); | ||
439 | pragma Import (C, gzgetc, "gzgetc"); | ||
440 | pragma Import (C, gzflush, "gzflush"); | ||
441 | pragma Import (C, gzseek, "gzseek"); | ||
442 | pragma Import (C, gzrewind, "gzrewind"); | ||
443 | pragma Import (C, gztell, "gztell"); | ||
444 | pragma Import (C, gzeof, "gzeof"); | ||
445 | pragma Import (C, gzclose, "gzclose"); | ||
446 | pragma Import (C, gzerror, "gzerror"); | ||
447 | pragma Import (C, adler32, "adler32"); | ||
448 | pragma Import (C, crc32, "crc32"); | ||
449 | pragma Import (C, deflateInit, "deflateInit_"); | ||
450 | pragma Import (C, inflateInit, "inflateInit_"); | ||
451 | pragma Import (C, deflateInit2, "deflateInit2_"); | ||
452 | pragma Import (C, inflateInit2, "inflateInit2_"); | ||
453 | pragma Import (C, zError, "zError"); | ||
454 | pragma Import (C, inflateSyncPoint, "inflateSyncPoint"); | ||
455 | pragma Import (C, get_crc_table, "get_crc_table"); | ||
456 | |||
457 | -- since zlib 1.2.0: | ||
458 | |||
459 | pragma Import (C, inflateCopy, "inflateCopy"); | ||
460 | pragma Import (C, compressBound, "compressBound"); | ||
461 | pragma Import (C, deflateBound, "deflateBound"); | ||
462 | pragma Import (C, gzungetc, "gzungetc"); | ||
463 | pragma Import (C, zlibCompileFlags, "zlibCompileFlags"); | ||
464 | |||
465 | pragma Import (C, inflateBackInit, "inflateBackInit_"); | ||
466 | |||
467 | -- I stopped binding the inflateBack routines, becouse realize that | ||
468 | -- it does not support zlib and gzip headers for now, and have no | ||
469 | -- symmetric deflateBack routines. | ||
470 | -- ZLib-Ada is symmetric regarding deflate/inflate data transformation | ||
471 | -- and has a similar generic callback interface for the | ||
472 | -- deflate/inflate transformation based on the regular Deflate/Inflate | ||
473 | -- routines. | ||
474 | |||
475 | -- pragma Import (C, inflateBack, "inflateBack"); | ||
476 | -- pragma Import (C, inflateBackEnd, "inflateBackEnd"); | ||
477 | |||
478 | end ZLib.Thin; | ||