1 ----------------------------------------------------------------
2 -- ZLib for Ada thick binding. --
4 -- Copyright (C) 2002-2003 Dmitriy Anisimkov --
6 -- Open source license information is in the zlib.ads file. --
7 ----------------------------------------------------------------
9 -- $Id: zlib-thin.ads,v 1.1.1.1 2004/10/11 17:44:23 tromey Exp $
11 with Interfaces
.C
.Strings
;
12 with System
.Address_To_Access_Conversions
;
14 private package ZLib
.Thin
is
18 MAX_MEM_LEVEL
: constant := 9; -- zconf.h:105
20 MAX_WBITS
: constant := 15; -- zconf.h:115
23 SEEK_SET
: constant := 8#
0000#
; -- zconf.h:244
24 -- Seek from beginning of file.
26 SEEK_CUR
: constant := 1; -- zconf.h:245
27 -- Seek from current position.
29 SEEK_END
: constant := 2; -- zconf.h:246
30 -- Set file pointer to EOF plus "offset"
33 type Byte
is new Interfaces
.C
.unsigned_char
; -- 8 bits
35 type UInt
is new Interfaces
.C
.unsigned
; -- 16 bits or more
37 type Int
is new Interfaces
.C
.int
;
39 type ULong
is new Interfaces
.C
.unsigned
; -- 32 bits or more
41 subtype Chars_Ptr
is Interfaces
.C
.Strings
.chars_ptr
;
43 type ULong_Access
is access ULong
;
44 type Int_Access
is access Int
;
45 subtype Voidp
is System
.Address
; -- zconf.h:232
47 package Bytes
is new System
.Address_To_Access_Conversions
(Byte
);
49 subtype Byte_Access
is Bytes
.Object_Pointer
;
53 Z_NO_FLUSH
: constant := 8#
0000#
; -- zlib.h:125
55 Z_PARTIAL_FLUSH
: constant := 1; -- zlib.h:126
56 -- will be removed, use
57 -- Z_SYNC_FLUSH instead
59 Z_SYNC_FLUSH
: constant := 2; -- zlib.h:127
61 Z_FULL_FLUSH
: constant := 3; -- zlib.h:128
63 Z_FINISH
: constant := 4; -- zlib.h:129
65 Z_OK
: constant := 8#
0000#
; -- zlib.h:132
67 Z_STREAM_END
: constant := 1; -- zlib.h:133
69 Z_NEED_DICT
: constant := 2; -- zlib.h:134
71 Z_ERRNO
: constant := -1; -- zlib.h:135
73 Z_STREAM_ERROR
: constant := -2; -- zlib.h:136
75 Z_DATA_ERROR
: constant := -3; -- zlib.h:137
77 Z_MEM_ERROR
: constant := -4; -- zlib.h:138
79 Z_BUF_ERROR
: constant := -5; -- zlib.h:139
81 Z_VERSION_ERROR
: constant := -6; -- zlib.h:140
83 Z_NO_COMPRESSION
: constant := 8#
0000#
; -- zlib.h:145
85 Z_BEST_SPEED
: constant := 1; -- zlib.h:146
87 Z_BEST_COMPRESSION
: constant := 9; -- zlib.h:147
89 Z_DEFAULT_COMPRESSION
: constant := -1; -- zlib.h:148
91 Z_FILTERED
: constant := 1; -- zlib.h:151
93 Z_HUFFMAN_ONLY
: constant := 2; -- zlib.h:152
95 Z_DEFAULT_STRATEGY
: constant := 8#
0000#
; -- zlib.h:153
97 Z_BINARY
: constant := 8#
0000#
; -- zlib.h:156
99 Z_ASCII
: constant := 1; -- zlib.h:157
101 Z_UNKNOWN
: constant := 2; -- zlib.h:158
103 Z_DEFLATED
: constant := 8; -- zlib.h:161
105 Z_NULL
: constant := 8#
0000#
; -- zlib.h:164
106 -- for initializing zalloc, zfree, opaque
108 type gzFile
is new Voidp
; -- zlib.h:646
110 type Z_Stream
is private;
112 type Z_Streamp
is access all Z_Stream
; -- zlib.h:89
114 type alloc_func
is access function
118 return Voidp
; -- zlib.h:63
120 type free_func
is access procedure (opaque
: Voidp
; address
: Voidp
);
122 function zlibVersion
return Chars_Ptr
;
124 function Deflate
(strm
: Z_Streamp
; flush
: Int
) return Int
;
126 function DeflateEnd
(strm
: Z_Streamp
) return Int
;
128 function Inflate
(strm
: Z_Streamp
; flush
: Int
) return Int
;
130 function InflateEnd
(strm
: Z_Streamp
) return Int
;
132 function deflateSetDictionary
134 dictionary
: Byte_Access
;
138 function deflateCopy
(dest
: Z_Streamp
; source
: Z_Streamp
) return Int
;
141 function deflateReset
(strm
: Z_Streamp
) return Int
; -- zlib.h:495
143 function deflateParams
147 return Int
; -- zlib.h:506
149 function inflateSetDictionary
151 dictionary
: Byte_Access
;
153 return Int
; -- zlib.h:548
155 function inflateSync
(strm
: Z_Streamp
) return Int
; -- zlib.h:565
157 function inflateReset
(strm
: Z_Streamp
) return Int
; -- zlib.h:580
161 destLen
: ULong_Access
;
162 source
: Byte_Access
;
164 return Int
; -- zlib.h:601
168 destLen
: ULong_Access
;
169 source
: Byte_Access
;
172 return Int
; -- zlib.h:615
176 destLen
: ULong_Access
;
177 source
: Byte_Access
;
181 function gzopen
(path
: Chars_Ptr
; mode
: Chars_Ptr
) return gzFile
;
183 function gzdopen
(fd
: Int
; mode
: Chars_Ptr
) return gzFile
;
203 function gzprintf
(file
: in gzFile
; format
: in Chars_Ptr
) return Int
;
205 function gzputs
(file
: in gzFile
; s
: in Chars_Ptr
) return Int
;
213 function gzputc
(file
: gzFile
; char
: Int
) return Int
;
215 function gzgetc
(file
: gzFile
) return Int
;
217 function gzflush
(file
: gzFile
; flush
: Int
) return Int
;
225 function gzrewind
(file
: gzFile
) return Int
;
227 function gztell
(file
: gzFile
) return Int
;
229 function gzeof
(file
: gzFile
) return Int
;
231 function gzclose
(file
: gzFile
) return Int
;
233 function gzerror
(file
: gzFile
; errnum
: Int_Access
) return Chars_Ptr
;
254 function Deflate_Init
255 (strm
: in Z_Streamp
;
256 level
: in Int
:= Z_DEFAULT_COMPRESSION
)
258 pragma Inline
(Deflate_Init
);
260 function deflateInit2
271 function Deflate_Init
279 pragma Inline
(Deflate_Init
);
287 function Inflate_Init
(strm
: Z_Streamp
) return Int
;
288 pragma Inline
(Inflate_Init
);
290 function inflateInit2
291 (strm
: in Z_Streamp
;
293 version
: in Chars_Ptr
;
294 stream_size
: in Int
)
297 function inflateBackInit
298 (strm
: in Z_Streamp
;
300 window
: in Byte_Access
;
301 version
: in Chars_Ptr
;
302 stream_size
: in Int
)
304 -- Size of window have to be 2**windowBits.
306 function Inflate_Init
(strm
: Z_Streamp
; windowBits
: Int
) return Int
;
307 pragma Inline
(Inflate_Init
);
309 function zError
(err
: Int
) return Chars_Ptr
;
311 function inflateSyncPoint
(z
: Z_Streamp
) return Int
;
313 function get_crc_table
return ULong_Access
;
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.
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
);
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
);
330 (Strm
: in out Z_Stream
;
331 Buffer
: in Byte_Access
;
333 pragma Inline
(Set_In
);
336 (Strm
: in out Z_Stream
;
339 pragma Inline
(Set_In
);
342 (Strm
: in out Z_Stream
;
343 Buffer
: in Byte_Access
;
345 pragma Inline
(Set_Out
);
348 (Strm
: in out Z_Stream
;
351 pragma Inline
(Set_Out
);
353 procedure Set_Mem_Func
354 (Strm
: in out Z_Stream
;
356 Alloc
: in alloc_func
;
357 Free
: in free_func
);
358 pragma Inline
(Set_Mem_Func
);
360 function Last_Error_Message
(Strm
: in Z_Stream
) return String;
361 pragma Inline
(Last_Error_Message
);
363 function Avail_Out
(Strm
: in Z_Stream
) return UInt
;
364 pragma Inline
(Avail_Out
);
366 function Avail_In
(Strm
: in Z_Stream
) return UInt
;
367 pragma Inline
(Avail_In
);
369 function Total_In
(Strm
: in Z_Stream
) return ULong
;
370 pragma Inline
(Total_In
);
372 function Total_Out
(Strm
: in Z_Stream
) return ULong
;
373 pragma Inline
(Total_Out
);
376 (dest
: in Z_Streamp
;
377 Source
: in Z_Streamp
)
380 function compressBound
(Source_Len
: in ULong
) return ULong
;
382 function deflateBound
383 (Strm
: in Z_Streamp
;
384 Source_Len
: in ULong
)
387 function gzungetc
(C
: in Int
; File
: in gzFile
) return Int
;
389 function zlibCompileFlags
return ULong
;
391 function deflatePrime
399 type Z_Stream
is record -- zlib.h:68
400 Next_In
: Byte_Access
; -- next input byte
401 Avail_In
: UInt
:= 0; -- number of bytes available at next_in
402 Total_In
: ULong
:= 0; -- total nb of input bytes read so far
403 Next_Out
: Byte_Access
; -- next output byte should be put there
404 Avail_Out
: UInt
:= 0; -- remaining free space at next_out
405 Total_Out
: ULong
:= 0; -- total nb of bytes output so far
406 msg
: Chars_Ptr
; -- last error message, NULL if no error
407 state
: Voidp
; -- not visible by applications
408 zalloc
: alloc_func
:= null; -- used to allocate the internal state
409 zfree
: free_func
:= null; -- used to free the internal state
410 opaque
: Voidp
; -- private data object passed to
412 data_type
: Int
; -- best guess about the data type:
414 adler
: ULong
; -- adler32 value of the uncompressed
416 reserved
: ULong
; -- reserved for future use
419 pragma Convention
(C
, Z_Stream
);
421 pragma Import
(C
, zlibVersion
, "zlibVersion");
422 pragma Import
(C
, Deflate
, "deflate");
423 pragma Import
(C
, DeflateEnd
, "deflateEnd");
424 pragma Import
(C
, Inflate
, "inflate");
425 pragma Import
(C
, InflateEnd
, "inflateEnd");
426 pragma Import
(C
, deflateSetDictionary
, "deflateSetDictionary");
427 pragma Import
(C
, deflateCopy
, "deflateCopy");
428 pragma Import
(C
, deflateReset
, "deflateReset");
429 pragma Import
(C
, deflateParams
, "deflateParams");
430 pragma Import
(C
, inflateSetDictionary
, "inflateSetDictionary");
431 pragma Import
(C
, inflateSync
, "inflateSync");
432 pragma Import
(C
, inflateReset
, "inflateReset");
433 pragma Import
(C
, compress
, "compress");
434 pragma Import
(C
, compress2
, "compress2");
435 pragma Import
(C
, uncompress
, "uncompress");
436 pragma Import
(C
, gzopen
, "gzopen");
437 pragma Import
(C
, gzdopen
, "gzdopen");
438 pragma Import
(C
, gzsetparams
, "gzsetparams");
439 pragma Import
(C
, gzread
, "gzread");
440 pragma Import
(C
, gzwrite
, "gzwrite");
441 pragma Import
(C
, gzprintf
, "gzprintf");
442 pragma Import
(C
, gzputs
, "gzputs");
443 pragma Import
(C
, gzgets
, "gzgets");
444 pragma Import
(C
, gzputc
, "gzputc");
445 pragma Import
(C
, gzgetc
, "gzgetc");
446 pragma Import
(C
, gzflush
, "gzflush");
447 pragma Import
(C
, gzseek
, "gzseek");
448 pragma Import
(C
, gzrewind
, "gzrewind");
449 pragma Import
(C
, gztell
, "gztell");
450 pragma Import
(C
, gzeof
, "gzeof");
451 pragma Import
(C
, gzclose
, "gzclose");
452 pragma Import
(C
, gzerror
, "gzerror");
453 pragma Import
(C
, adler32
, "adler32");
454 pragma Import
(C
, crc32
, "crc32");
455 pragma Import
(C
, deflateInit
, "deflateInit_");
456 pragma Import
(C
, inflateInit
, "inflateInit_");
457 pragma Import
(C
, deflateInit2
, "deflateInit2_");
458 pragma Import
(C
, inflateInit2
, "inflateInit2_");
459 pragma Import
(C
, zError
, "zError");
460 pragma Import
(C
, inflateSyncPoint
, "inflateSyncPoint");
461 pragma Import
(C
, get_crc_table
, "get_crc_table");
463 -- added in zlib 1.2.1:
465 pragma Import
(C
, inflateCopy
, "inflateCopy");
466 pragma Import
(C
, compressBound
, "compressBound");
467 pragma Import
(C
, deflateBound
, "deflateBound");
468 pragma Import
(C
, gzungetc
, "gzungetc");
469 pragma Import
(C
, zlibCompileFlags
, "zlibCompileFlags");
470 pragma Import
(C
, deflatePrime
, "deflatePrime");
472 pragma Import
(C
, inflateBackInit
, "inflateBackInit_");
474 -- I stopped binding the inflateBack routines, becouse realize that
475 -- it does not support zlib and gzip headers for now, and have no
476 -- symmetric deflateBack routines.
477 -- ZLib-Ada is symmetric regarding deflate/inflate data transformation
478 -- and has a similar generic callback interface for the
479 -- deflate/inflate transformation based on the regular Deflate/Inflate
482 -- pragma Import (C, inflateBack, "inflateBack");
483 -- pragma Import (C, inflateBackEnd, "inflateBackEnd");