Chris@4: ---------------------------------------------------------------- Chris@4: -- ZLib for Ada thick binding. -- Chris@4: -- -- Chris@4: -- Copyright (C) 2002-2003 Dmitriy Anisimkov -- Chris@4: -- -- Chris@4: -- Open source license information is in the zlib.ads file. -- Chris@4: ---------------------------------------------------------------- Chris@4: Chris@4: -- $Id: zlib-thin.ads,v 1.11 2004/07/23 06:33:11 vagul Exp $ Chris@4: Chris@4: with Interfaces.C.Strings; Chris@4: Chris@4: with System; Chris@4: Chris@4: private package ZLib.Thin is Chris@4: Chris@4: -- From zconf.h Chris@4: Chris@4: MAX_MEM_LEVEL : constant := 9; -- zconf.h:105 Chris@4: -- zconf.h:105 Chris@4: MAX_WBITS : constant := 15; -- zconf.h:115 Chris@4: -- 32K LZ77 window Chris@4: -- zconf.h:115 Chris@4: SEEK_SET : constant := 8#0000#; -- zconf.h:244 Chris@4: -- Seek from beginning of file. Chris@4: -- zconf.h:244 Chris@4: SEEK_CUR : constant := 1; -- zconf.h:245 Chris@4: -- Seek from current position. Chris@4: -- zconf.h:245 Chris@4: SEEK_END : constant := 2; -- zconf.h:246 Chris@4: -- Set file pointer to EOF plus "offset" Chris@4: -- zconf.h:246 Chris@4: Chris@4: type Byte is new Interfaces.C.unsigned_char; -- 8 bits Chris@4: -- zconf.h:214 Chris@4: type UInt is new Interfaces.C.unsigned; -- 16 bits or more Chris@4: -- zconf.h:216 Chris@4: type Int is new Interfaces.C.int; Chris@4: Chris@4: type ULong is new Interfaces.C.unsigned_long; -- 32 bits or more Chris@4: -- zconf.h:217 Chris@4: subtype Chars_Ptr is Interfaces.C.Strings.chars_ptr; Chris@4: Chris@4: type ULong_Access is access ULong; Chris@4: type Int_Access is access Int; Chris@4: Chris@4: subtype Voidp is System.Address; -- zconf.h:232 Chris@4: Chris@4: subtype Byte_Access is Voidp; Chris@4: Chris@4: Nul : constant Voidp := System.Null_Address; Chris@4: -- end from zconf Chris@4: Chris@4: Z_NO_FLUSH : constant := 8#0000#; -- zlib.h:125 Chris@4: -- zlib.h:125 Chris@4: Z_PARTIAL_FLUSH : constant := 1; -- zlib.h:126 Chris@4: -- will be removed, use Chris@4: -- Z_SYNC_FLUSH instead Chris@4: -- zlib.h:126 Chris@4: Z_SYNC_FLUSH : constant := 2; -- zlib.h:127 Chris@4: -- zlib.h:127 Chris@4: Z_FULL_FLUSH : constant := 3; -- zlib.h:128 Chris@4: -- zlib.h:128 Chris@4: Z_FINISH : constant := 4; -- zlib.h:129 Chris@4: -- zlib.h:129 Chris@4: Z_OK : constant := 8#0000#; -- zlib.h:132 Chris@4: -- zlib.h:132 Chris@4: Z_STREAM_END : constant := 1; -- zlib.h:133 Chris@4: -- zlib.h:133 Chris@4: Z_NEED_DICT : constant := 2; -- zlib.h:134 Chris@4: -- zlib.h:134 Chris@4: Z_ERRNO : constant := -1; -- zlib.h:135 Chris@4: -- zlib.h:135 Chris@4: Z_STREAM_ERROR : constant := -2; -- zlib.h:136 Chris@4: -- zlib.h:136 Chris@4: Z_DATA_ERROR : constant := -3; -- zlib.h:137 Chris@4: -- zlib.h:137 Chris@4: Z_MEM_ERROR : constant := -4; -- zlib.h:138 Chris@4: -- zlib.h:138 Chris@4: Z_BUF_ERROR : constant := -5; -- zlib.h:139 Chris@4: -- zlib.h:139 Chris@4: Z_VERSION_ERROR : constant := -6; -- zlib.h:140 Chris@4: -- zlib.h:140 Chris@4: Z_NO_COMPRESSION : constant := 8#0000#; -- zlib.h:145 Chris@4: -- zlib.h:145 Chris@4: Z_BEST_SPEED : constant := 1; -- zlib.h:146 Chris@4: -- zlib.h:146 Chris@4: Z_BEST_COMPRESSION : constant := 9; -- zlib.h:147 Chris@4: -- zlib.h:147 Chris@4: Z_DEFAULT_COMPRESSION : constant := -1; -- zlib.h:148 Chris@4: -- zlib.h:148 Chris@4: Z_FILTERED : constant := 1; -- zlib.h:151 Chris@4: -- zlib.h:151 Chris@4: Z_HUFFMAN_ONLY : constant := 2; -- zlib.h:152 Chris@4: -- zlib.h:152 Chris@4: Z_DEFAULT_STRATEGY : constant := 8#0000#; -- zlib.h:153 Chris@4: -- zlib.h:153 Chris@4: Z_BINARY : constant := 8#0000#; -- zlib.h:156 Chris@4: -- zlib.h:156 Chris@4: Z_ASCII : constant := 1; -- zlib.h:157 Chris@4: -- zlib.h:157 Chris@4: Z_UNKNOWN : constant := 2; -- zlib.h:158 Chris@4: -- zlib.h:158 Chris@4: Z_DEFLATED : constant := 8; -- zlib.h:161 Chris@4: -- zlib.h:161 Chris@4: Z_NULL : constant := 8#0000#; -- zlib.h:164 Chris@4: -- for initializing zalloc, zfree, opaque Chris@4: -- zlib.h:164 Chris@4: type gzFile is new Voidp; -- zlib.h:646 Chris@4: Chris@4: type Z_Stream is private; Chris@4: Chris@4: type Z_Streamp is access all Z_Stream; -- zlib.h:89 Chris@4: Chris@4: type alloc_func is access function Chris@4: (Opaque : Voidp; Chris@4: Items : UInt; Chris@4: Size : UInt) Chris@4: return Voidp; -- zlib.h:63 Chris@4: Chris@4: type free_func is access procedure (opaque : Voidp; address : Voidp); Chris@4: Chris@4: function zlibVersion return Chars_Ptr; Chris@4: Chris@4: function Deflate (strm : Z_Streamp; flush : Int) return Int; Chris@4: Chris@4: function DeflateEnd (strm : Z_Streamp) return Int; Chris@4: Chris@4: function Inflate (strm : Z_Streamp; flush : Int) return Int; Chris@4: Chris@4: function InflateEnd (strm : Z_Streamp) return Int; Chris@4: Chris@4: function deflateSetDictionary Chris@4: (strm : Z_Streamp; Chris@4: dictionary : Byte_Access; Chris@4: dictLength : UInt) Chris@4: return Int; Chris@4: Chris@4: function deflateCopy (dest : Z_Streamp; source : Z_Streamp) return Int; Chris@4: -- zlib.h:478 Chris@4: Chris@4: function deflateReset (strm : Z_Streamp) return Int; -- zlib.h:495 Chris@4: Chris@4: function deflateParams Chris@4: (strm : Z_Streamp; Chris@4: level : Int; Chris@4: strategy : Int) Chris@4: return Int; -- zlib.h:506 Chris@4: Chris@4: function inflateSetDictionary Chris@4: (strm : Z_Streamp; Chris@4: dictionary : Byte_Access; Chris@4: dictLength : UInt) Chris@4: return Int; -- zlib.h:548 Chris@4: Chris@4: function inflateSync (strm : Z_Streamp) return Int; -- zlib.h:565 Chris@4: Chris@4: function inflateReset (strm : Z_Streamp) return Int; -- zlib.h:580 Chris@4: Chris@4: function compress Chris@4: (dest : Byte_Access; Chris@4: destLen : ULong_Access; Chris@4: source : Byte_Access; Chris@4: sourceLen : ULong) Chris@4: return Int; -- zlib.h:601 Chris@4: Chris@4: function compress2 Chris@4: (dest : Byte_Access; Chris@4: destLen : ULong_Access; Chris@4: source : Byte_Access; Chris@4: sourceLen : ULong; Chris@4: level : Int) Chris@4: return Int; -- zlib.h:615 Chris@4: Chris@4: function uncompress Chris@4: (dest : Byte_Access; Chris@4: destLen : ULong_Access; Chris@4: source : Byte_Access; Chris@4: sourceLen : ULong) Chris@4: return Int; Chris@4: Chris@4: function gzopen (path : Chars_Ptr; mode : Chars_Ptr) return gzFile; Chris@4: Chris@4: function gzdopen (fd : Int; mode : Chars_Ptr) return gzFile; Chris@4: Chris@4: function gzsetparams Chris@4: (file : gzFile; Chris@4: level : Int; Chris@4: strategy : Int) Chris@4: return Int; Chris@4: Chris@4: function gzread Chris@4: (file : gzFile; Chris@4: buf : Voidp; Chris@4: len : UInt) Chris@4: return Int; Chris@4: Chris@4: function gzwrite Chris@4: (file : in gzFile; Chris@4: buf : in Voidp; Chris@4: len : in UInt) Chris@4: return Int; Chris@4: Chris@4: function gzprintf (file : in gzFile; format : in Chars_Ptr) return Int; Chris@4: Chris@4: function gzputs (file : in gzFile; s : in Chars_Ptr) return Int; Chris@4: Chris@4: function gzgets Chris@4: (file : gzFile; Chris@4: buf : Chars_Ptr; Chris@4: len : Int) Chris@4: return Chars_Ptr; Chris@4: Chris@4: function gzputc (file : gzFile; char : Int) return Int; Chris@4: Chris@4: function gzgetc (file : gzFile) return Int; Chris@4: Chris@4: function gzflush (file : gzFile; flush : Int) return Int; Chris@4: Chris@4: function gzseek Chris@4: (file : gzFile; Chris@4: offset : Int; Chris@4: whence : Int) Chris@4: return Int; Chris@4: Chris@4: function gzrewind (file : gzFile) return Int; Chris@4: Chris@4: function gztell (file : gzFile) return Int; Chris@4: Chris@4: function gzeof (file : gzFile) return Int; Chris@4: Chris@4: function gzclose (file : gzFile) return Int; Chris@4: Chris@4: function gzerror (file : gzFile; errnum : Int_Access) return Chars_Ptr; Chris@4: Chris@4: function adler32 Chris@4: (adler : ULong; Chris@4: buf : Byte_Access; Chris@4: len : UInt) Chris@4: return ULong; Chris@4: Chris@4: function crc32 Chris@4: (crc : ULong; Chris@4: buf : Byte_Access; Chris@4: len : UInt) Chris@4: return ULong; Chris@4: Chris@4: function deflateInit Chris@4: (strm : Z_Streamp; Chris@4: level : Int; Chris@4: version : Chars_Ptr; Chris@4: stream_size : Int) Chris@4: return Int; Chris@4: Chris@4: function deflateInit2 Chris@4: (strm : Z_Streamp; Chris@4: level : Int; Chris@4: method : Int; Chris@4: windowBits : Int; Chris@4: memLevel : Int; Chris@4: strategy : Int; Chris@4: version : Chars_Ptr; Chris@4: stream_size : Int) Chris@4: return Int; Chris@4: Chris@4: function Deflate_Init Chris@4: (strm : Z_Streamp; Chris@4: level : Int; Chris@4: method : Int; Chris@4: windowBits : Int; Chris@4: memLevel : Int; Chris@4: strategy : Int) Chris@4: return Int; Chris@4: pragma Inline (Deflate_Init); Chris@4: Chris@4: function inflateInit Chris@4: (strm : Z_Streamp; Chris@4: version : Chars_Ptr; Chris@4: stream_size : Int) Chris@4: return Int; Chris@4: Chris@4: function inflateInit2 Chris@4: (strm : in Z_Streamp; Chris@4: windowBits : in Int; Chris@4: version : in Chars_Ptr; Chris@4: stream_size : in Int) Chris@4: return Int; Chris@4: Chris@4: function inflateBackInit Chris@4: (strm : in Z_Streamp; Chris@4: windowBits : in Int; Chris@4: window : in Byte_Access; Chris@4: version : in Chars_Ptr; Chris@4: stream_size : in Int) Chris@4: return Int; Chris@4: -- Size of window have to be 2**windowBits. Chris@4: Chris@4: function Inflate_Init (strm : Z_Streamp; windowBits : Int) return Int; Chris@4: pragma Inline (Inflate_Init); Chris@4: Chris@4: function zError (err : Int) return Chars_Ptr; Chris@4: Chris@4: function inflateSyncPoint (z : Z_Streamp) return Int; Chris@4: Chris@4: function get_crc_table return ULong_Access; Chris@4: Chris@4: -- Interface to the available fields of the z_stream structure. Chris@4: -- The application must update next_in and avail_in when avail_in has Chris@4: -- dropped to zero. It must update next_out and avail_out when avail_out Chris@4: -- has dropped to zero. The application must initialize zalloc, zfree and Chris@4: -- opaque before calling the init function. Chris@4: Chris@4: procedure Set_In Chris@4: (Strm : in out Z_Stream; Chris@4: Buffer : in Voidp; Chris@4: Size : in UInt); Chris@4: pragma Inline (Set_In); Chris@4: Chris@4: procedure Set_Out Chris@4: (Strm : in out Z_Stream; Chris@4: Buffer : in Voidp; Chris@4: Size : in UInt); Chris@4: pragma Inline (Set_Out); Chris@4: Chris@4: procedure Set_Mem_Func Chris@4: (Strm : in out Z_Stream; Chris@4: Opaque : in Voidp; Chris@4: Alloc : in alloc_func; Chris@4: Free : in free_func); Chris@4: pragma Inline (Set_Mem_Func); Chris@4: Chris@4: function Last_Error_Message (Strm : in Z_Stream) return String; Chris@4: pragma Inline (Last_Error_Message); Chris@4: Chris@4: function Avail_Out (Strm : in Z_Stream) return UInt; Chris@4: pragma Inline (Avail_Out); Chris@4: Chris@4: function Avail_In (Strm : in Z_Stream) return UInt; Chris@4: pragma Inline (Avail_In); Chris@4: Chris@4: function Total_In (Strm : in Z_Stream) return ULong; Chris@4: pragma Inline (Total_In); Chris@4: Chris@4: function Total_Out (Strm : in Z_Stream) return ULong; Chris@4: pragma Inline (Total_Out); Chris@4: Chris@4: function inflateCopy Chris@4: (dest : in Z_Streamp; Chris@4: Source : in Z_Streamp) Chris@4: return Int; Chris@4: Chris@4: function compressBound (Source_Len : in ULong) return ULong; Chris@4: Chris@4: function deflateBound Chris@4: (Strm : in Z_Streamp; Chris@4: Source_Len : in ULong) Chris@4: return ULong; Chris@4: Chris@4: function gzungetc (C : in Int; File : in gzFile) return Int; Chris@4: Chris@4: function zlibCompileFlags return ULong; Chris@4: Chris@4: private Chris@4: Chris@4: type Z_Stream is record -- zlib.h:68 Chris@4: Next_In : Voidp := Nul; -- next input byte Chris@4: Avail_In : UInt := 0; -- number of bytes available at next_in Chris@4: Total_In : ULong := 0; -- total nb of input bytes read so far Chris@4: Next_Out : Voidp := Nul; -- next output byte should be put there Chris@4: Avail_Out : UInt := 0; -- remaining free space at next_out Chris@4: Total_Out : ULong := 0; -- total nb of bytes output so far Chris@4: msg : Chars_Ptr; -- last error message, NULL if no error Chris@4: state : Voidp; -- not visible by applications Chris@4: zalloc : alloc_func := null; -- used to allocate the internal state Chris@4: zfree : free_func := null; -- used to free the internal state Chris@4: opaque : Voidp; -- private data object passed to Chris@4: -- zalloc and zfree Chris@4: data_type : Int; -- best guess about the data type: Chris@4: -- ascii or binary Chris@4: adler : ULong; -- adler32 value of the uncompressed Chris@4: -- data Chris@4: reserved : ULong; -- reserved for future use Chris@4: end record; Chris@4: Chris@4: pragma Convention (C, Z_Stream); Chris@4: Chris@4: pragma Import (C, zlibVersion, "zlibVersion"); Chris@4: pragma Import (C, Deflate, "deflate"); Chris@4: pragma Import (C, DeflateEnd, "deflateEnd"); Chris@4: pragma Import (C, Inflate, "inflate"); Chris@4: pragma Import (C, InflateEnd, "inflateEnd"); Chris@4: pragma Import (C, deflateSetDictionary, "deflateSetDictionary"); Chris@4: pragma Import (C, deflateCopy, "deflateCopy"); Chris@4: pragma Import (C, deflateReset, "deflateReset"); Chris@4: pragma Import (C, deflateParams, "deflateParams"); Chris@4: pragma Import (C, inflateSetDictionary, "inflateSetDictionary"); Chris@4: pragma Import (C, inflateSync, "inflateSync"); Chris@4: pragma Import (C, inflateReset, "inflateReset"); Chris@4: pragma Import (C, compress, "compress"); Chris@4: pragma Import (C, compress2, "compress2"); Chris@4: pragma Import (C, uncompress, "uncompress"); Chris@4: pragma Import (C, gzopen, "gzopen"); Chris@4: pragma Import (C, gzdopen, "gzdopen"); Chris@4: pragma Import (C, gzsetparams, "gzsetparams"); Chris@4: pragma Import (C, gzread, "gzread"); Chris@4: pragma Import (C, gzwrite, "gzwrite"); Chris@4: pragma Import (C, gzprintf, "gzprintf"); Chris@4: pragma Import (C, gzputs, "gzputs"); Chris@4: pragma Import (C, gzgets, "gzgets"); Chris@4: pragma Import (C, gzputc, "gzputc"); Chris@4: pragma Import (C, gzgetc, "gzgetc"); Chris@4: pragma Import (C, gzflush, "gzflush"); Chris@4: pragma Import (C, gzseek, "gzseek"); Chris@4: pragma Import (C, gzrewind, "gzrewind"); Chris@4: pragma Import (C, gztell, "gztell"); Chris@4: pragma Import (C, gzeof, "gzeof"); Chris@4: pragma Import (C, gzclose, "gzclose"); Chris@4: pragma Import (C, gzerror, "gzerror"); Chris@4: pragma Import (C, adler32, "adler32"); Chris@4: pragma Import (C, crc32, "crc32"); Chris@4: pragma Import (C, deflateInit, "deflateInit_"); Chris@4: pragma Import (C, inflateInit, "inflateInit_"); Chris@4: pragma Import (C, deflateInit2, "deflateInit2_"); Chris@4: pragma Import (C, inflateInit2, "inflateInit2_"); Chris@4: pragma Import (C, zError, "zError"); Chris@4: pragma Import (C, inflateSyncPoint, "inflateSyncPoint"); Chris@4: pragma Import (C, get_crc_table, "get_crc_table"); Chris@4: Chris@4: -- since zlib 1.2.0: Chris@4: Chris@4: pragma Import (C, inflateCopy, "inflateCopy"); Chris@4: pragma Import (C, compressBound, "compressBound"); Chris@4: pragma Import (C, deflateBound, "deflateBound"); Chris@4: pragma Import (C, gzungetc, "gzungetc"); Chris@4: pragma Import (C, zlibCompileFlags, "zlibCompileFlags"); Chris@4: Chris@4: pragma Import (C, inflateBackInit, "inflateBackInit_"); Chris@4: Chris@4: -- I stopped binding the inflateBack routines, becouse realize that Chris@4: -- it does not support zlib and gzip headers for now, and have no Chris@4: -- symmetric deflateBack routines. Chris@4: -- ZLib-Ada is symmetric regarding deflate/inflate data transformation Chris@4: -- and has a similar generic callback interface for the Chris@4: -- deflate/inflate transformation based on the regular Deflate/Inflate Chris@4: -- routines. Chris@4: Chris@4: -- pragma Import (C, inflateBack, "inflateBack"); Chris@4: -- pragma Import (C, inflateBackEnd, "inflateBackEnd"); Chris@4: Chris@4: end ZLib.Thin;