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