annotate src/zlib-1.2.7/contrib/ada/zlib.ads @ 143:e95e00bdc3eb

Further win32 build updates
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 09 Jan 2017 13:51:38 +0000
parents 8a15ff55d9af
children
rev   line source
cannam@89 1 ------------------------------------------------------------------------------
cannam@89 2 -- ZLib for Ada thick binding. --
cannam@89 3 -- --
cannam@89 4 -- Copyright (C) 2002-2004 Dmitriy Anisimkov --
cannam@89 5 -- --
cannam@89 6 -- This library is free software; you can redistribute it and/or modify --
cannam@89 7 -- it under the terms of the GNU General Public License as published by --
cannam@89 8 -- the Free Software Foundation; either version 2 of the License, or (at --
cannam@89 9 -- your option) any later version. --
cannam@89 10 -- --
cannam@89 11 -- This library is distributed in the hope that it will be useful, but --
cannam@89 12 -- WITHOUT ANY WARRANTY; without even the implied warranty of --
cannam@89 13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
cannam@89 14 -- General Public License for more details. --
cannam@89 15 -- --
cannam@89 16 -- You should have received a copy of the GNU General Public License --
cannam@89 17 -- along with this library; if not, write to the Free Software Foundation, --
cannam@89 18 -- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. --
cannam@89 19 -- --
cannam@89 20 -- As a special exception, if other files instantiate generics from this --
cannam@89 21 -- unit, or you link this unit with other files to produce an executable, --
cannam@89 22 -- this unit does not by itself cause the resulting executable to be --
cannam@89 23 -- covered by the GNU General Public License. This exception does not --
cannam@89 24 -- however invalidate any other reasons why the executable file might be --
cannam@89 25 -- covered by the GNU Public License. --
cannam@89 26 ------------------------------------------------------------------------------
cannam@89 27
cannam@89 28 -- $Id: zlib.ads,v 1.26 2004/09/06 06:53:19 vagul Exp $
cannam@89 29
cannam@89 30 with Ada.Streams;
cannam@89 31
cannam@89 32 with Interfaces;
cannam@89 33
cannam@89 34 package ZLib is
cannam@89 35
cannam@89 36 ZLib_Error : exception;
cannam@89 37 Status_Error : exception;
cannam@89 38
cannam@89 39 type Compression_Level is new Integer range -1 .. 9;
cannam@89 40
cannam@89 41 type Flush_Mode is private;
cannam@89 42
cannam@89 43 type Compression_Method is private;
cannam@89 44
cannam@89 45 type Window_Bits_Type is new Integer range 8 .. 15;
cannam@89 46
cannam@89 47 type Memory_Level_Type is new Integer range 1 .. 9;
cannam@89 48
cannam@89 49 type Unsigned_32 is new Interfaces.Unsigned_32;
cannam@89 50
cannam@89 51 type Strategy_Type is private;
cannam@89 52
cannam@89 53 type Header_Type is (None, Auto, Default, GZip);
cannam@89 54 -- Header type usage have a some limitation for inflate.
cannam@89 55 -- See comment for Inflate_Init.
cannam@89 56
cannam@89 57 subtype Count is Ada.Streams.Stream_Element_Count;
cannam@89 58
cannam@89 59 Default_Memory_Level : constant Memory_Level_Type := 8;
cannam@89 60 Default_Window_Bits : constant Window_Bits_Type := 15;
cannam@89 61
cannam@89 62 ----------------------------------
cannam@89 63 -- Compression method constants --
cannam@89 64 ----------------------------------
cannam@89 65
cannam@89 66 Deflated : constant Compression_Method;
cannam@89 67 -- Only one method allowed in this ZLib version
cannam@89 68
cannam@89 69 ---------------------------------
cannam@89 70 -- Compression level constants --
cannam@89 71 ---------------------------------
cannam@89 72
cannam@89 73 No_Compression : constant Compression_Level := 0;
cannam@89 74 Best_Speed : constant Compression_Level := 1;
cannam@89 75 Best_Compression : constant Compression_Level := 9;
cannam@89 76 Default_Compression : constant Compression_Level := -1;
cannam@89 77
cannam@89 78 --------------------------
cannam@89 79 -- Flush mode constants --
cannam@89 80 --------------------------
cannam@89 81
cannam@89 82 No_Flush : constant Flush_Mode;
cannam@89 83 -- Regular way for compression, no flush
cannam@89 84
cannam@89 85 Partial_Flush : constant Flush_Mode;
cannam@89 86 -- Will be removed, use Z_SYNC_FLUSH instead
cannam@89 87
cannam@89 88 Sync_Flush : constant Flush_Mode;
cannam@89 89 -- All pending output is flushed to the output buffer and the output
cannam@89 90 -- is aligned on a byte boundary, so that the decompressor can get all
cannam@89 91 -- input data available so far. (In particular avail_in is zero after the
cannam@89 92 -- call if enough output space has been provided before the call.)
cannam@89 93 -- Flushing may degrade compression for some compression algorithms and so
cannam@89 94 -- it should be used only when necessary.
cannam@89 95
cannam@89 96 Block_Flush : constant Flush_Mode;
cannam@89 97 -- Z_BLOCK requests that inflate() stop
cannam@89 98 -- if and when it get to the next deflate block boundary. When decoding the
cannam@89 99 -- zlib or gzip format, this will cause inflate() to return immediately
cannam@89 100 -- after the header and before the first block. When doing a raw inflate,
cannam@89 101 -- inflate() will go ahead and process the first block, and will return
cannam@89 102 -- when it gets to the end of that block, or when it runs out of data.
cannam@89 103
cannam@89 104 Full_Flush : constant Flush_Mode;
cannam@89 105 -- All output is flushed as with SYNC_FLUSH, and the compression state
cannam@89 106 -- is reset so that decompression can restart from this point if previous
cannam@89 107 -- compressed data has been damaged or if random access is desired. Using
cannam@89 108 -- Full_Flush too often can seriously degrade the compression.
cannam@89 109
cannam@89 110 Finish : constant Flush_Mode;
cannam@89 111 -- Just for tell the compressor that input data is complete.
cannam@89 112
cannam@89 113 ------------------------------------
cannam@89 114 -- Compression strategy constants --
cannam@89 115 ------------------------------------
cannam@89 116
cannam@89 117 -- RLE stategy could be used only in version 1.2.0 and later.
cannam@89 118
cannam@89 119 Filtered : constant Strategy_Type;
cannam@89 120 Huffman_Only : constant Strategy_Type;
cannam@89 121 RLE : constant Strategy_Type;
cannam@89 122 Default_Strategy : constant Strategy_Type;
cannam@89 123
cannam@89 124 Default_Buffer_Size : constant := 4096;
cannam@89 125
cannam@89 126 type Filter_Type is tagged limited private;
cannam@89 127 -- The filter is for compression and for decompression.
cannam@89 128 -- The usage of the type is depend of its initialization.
cannam@89 129
cannam@89 130 function Version return String;
cannam@89 131 pragma Inline (Version);
cannam@89 132 -- Return string representation of the ZLib version.
cannam@89 133
cannam@89 134 procedure Deflate_Init
cannam@89 135 (Filter : in out Filter_Type;
cannam@89 136 Level : in Compression_Level := Default_Compression;
cannam@89 137 Strategy : in Strategy_Type := Default_Strategy;
cannam@89 138 Method : in Compression_Method := Deflated;
cannam@89 139 Window_Bits : in Window_Bits_Type := Default_Window_Bits;
cannam@89 140 Memory_Level : in Memory_Level_Type := Default_Memory_Level;
cannam@89 141 Header : in Header_Type := Default);
cannam@89 142 -- Compressor initialization.
cannam@89 143 -- When Header parameter is Auto or Default, then default zlib header
cannam@89 144 -- would be provided for compressed data.
cannam@89 145 -- When Header is GZip, then gzip header would be set instead of
cannam@89 146 -- default header.
cannam@89 147 -- When Header is None, no header would be set for compressed data.
cannam@89 148
cannam@89 149 procedure Inflate_Init
cannam@89 150 (Filter : in out Filter_Type;
cannam@89 151 Window_Bits : in Window_Bits_Type := Default_Window_Bits;
cannam@89 152 Header : in Header_Type := Default);
cannam@89 153 -- Decompressor initialization.
cannam@89 154 -- Default header type mean that ZLib default header is expecting in the
cannam@89 155 -- input compressed stream.
cannam@89 156 -- Header type None mean that no header is expecting in the input stream.
cannam@89 157 -- GZip header type mean that GZip header is expecting in the
cannam@89 158 -- input compressed stream.
cannam@89 159 -- Auto header type mean that header type (GZip or Native) would be
cannam@89 160 -- detected automatically in the input stream.
cannam@89 161 -- Note that header types parameter values None, GZip and Auto are
cannam@89 162 -- supported for inflate routine only in ZLib versions 1.2.0.2 and later.
cannam@89 163 -- Deflate_Init is supporting all header types.
cannam@89 164
cannam@89 165 function Is_Open (Filter : in Filter_Type) return Boolean;
cannam@89 166 pragma Inline (Is_Open);
cannam@89 167 -- Is the filter opened for compression or decompression.
cannam@89 168
cannam@89 169 procedure Close
cannam@89 170 (Filter : in out Filter_Type;
cannam@89 171 Ignore_Error : in Boolean := False);
cannam@89 172 -- Closing the compression or decompressor.
cannam@89 173 -- If stream is closing before the complete and Ignore_Error is False,
cannam@89 174 -- The exception would be raised.
cannam@89 175
cannam@89 176 generic
cannam@89 177 with procedure Data_In
cannam@89 178 (Item : out Ada.Streams.Stream_Element_Array;
cannam@89 179 Last : out Ada.Streams.Stream_Element_Offset);
cannam@89 180 with procedure Data_Out
cannam@89 181 (Item : in Ada.Streams.Stream_Element_Array);
cannam@89 182 procedure Generic_Translate
cannam@89 183 (Filter : in out Filter_Type;
cannam@89 184 In_Buffer_Size : in Integer := Default_Buffer_Size;
cannam@89 185 Out_Buffer_Size : in Integer := Default_Buffer_Size);
cannam@89 186 -- Compress/decompress data fetch from Data_In routine and pass the result
cannam@89 187 -- to the Data_Out routine. User should provide Data_In and Data_Out
cannam@89 188 -- for compression/decompression data flow.
cannam@89 189 -- Compression or decompression depend on Filter initialization.
cannam@89 190
cannam@89 191 function Total_In (Filter : in Filter_Type) return Count;
cannam@89 192 pragma Inline (Total_In);
cannam@89 193 -- Returns total number of input bytes read so far
cannam@89 194
cannam@89 195 function Total_Out (Filter : in Filter_Type) return Count;
cannam@89 196 pragma Inline (Total_Out);
cannam@89 197 -- Returns total number of bytes output so far
cannam@89 198
cannam@89 199 function CRC32
cannam@89 200 (CRC : in Unsigned_32;
cannam@89 201 Data : in Ada.Streams.Stream_Element_Array)
cannam@89 202 return Unsigned_32;
cannam@89 203 pragma Inline (CRC32);
cannam@89 204 -- Compute CRC32, it could be necessary for make gzip format
cannam@89 205
cannam@89 206 procedure CRC32
cannam@89 207 (CRC : in out Unsigned_32;
cannam@89 208 Data : in Ada.Streams.Stream_Element_Array);
cannam@89 209 pragma Inline (CRC32);
cannam@89 210 -- Compute CRC32, it could be necessary for make gzip format
cannam@89 211
cannam@89 212 -------------------------------------------------
cannam@89 213 -- Below is more complex low level routines. --
cannam@89 214 -------------------------------------------------
cannam@89 215
cannam@89 216 procedure Translate
cannam@89 217 (Filter : in out Filter_Type;
cannam@89 218 In_Data : in Ada.Streams.Stream_Element_Array;
cannam@89 219 In_Last : out Ada.Streams.Stream_Element_Offset;
cannam@89 220 Out_Data : out Ada.Streams.Stream_Element_Array;
cannam@89 221 Out_Last : out Ada.Streams.Stream_Element_Offset;
cannam@89 222 Flush : in Flush_Mode);
cannam@89 223 -- Compress/decompress the In_Data buffer and place the result into
cannam@89 224 -- Out_Data. In_Last is the index of last element from In_Data accepted by
cannam@89 225 -- the Filter. Out_Last is the last element of the received data from
cannam@89 226 -- Filter. To tell the filter that incoming data are complete put the
cannam@89 227 -- Flush parameter to Finish.
cannam@89 228
cannam@89 229 function Stream_End (Filter : in Filter_Type) return Boolean;
cannam@89 230 pragma Inline (Stream_End);
cannam@89 231 -- Return the true when the stream is complete.
cannam@89 232
cannam@89 233 procedure Flush
cannam@89 234 (Filter : in out Filter_Type;
cannam@89 235 Out_Data : out Ada.Streams.Stream_Element_Array;
cannam@89 236 Out_Last : out Ada.Streams.Stream_Element_Offset;
cannam@89 237 Flush : in Flush_Mode);
cannam@89 238 pragma Inline (Flush);
cannam@89 239 -- Flushing the data from the compressor.
cannam@89 240
cannam@89 241 generic
cannam@89 242 with procedure Write
cannam@89 243 (Item : in Ada.Streams.Stream_Element_Array);
cannam@89 244 -- User should provide this routine for accept
cannam@89 245 -- compressed/decompressed data.
cannam@89 246
cannam@89 247 Buffer_Size : in Ada.Streams.Stream_Element_Offset
cannam@89 248 := Default_Buffer_Size;
cannam@89 249 -- Buffer size for Write user routine.
cannam@89 250
cannam@89 251 procedure Write
cannam@89 252 (Filter : in out Filter_Type;
cannam@89 253 Item : in Ada.Streams.Stream_Element_Array;
cannam@89 254 Flush : in Flush_Mode := No_Flush);
cannam@89 255 -- Compress/Decompress data from Item to the generic parameter procedure
cannam@89 256 -- Write. Output buffer size could be set in Buffer_Size generic parameter.
cannam@89 257
cannam@89 258 generic
cannam@89 259 with procedure Read
cannam@89 260 (Item : out Ada.Streams.Stream_Element_Array;
cannam@89 261 Last : out Ada.Streams.Stream_Element_Offset);
cannam@89 262 -- User should provide data for compression/decompression
cannam@89 263 -- thru this routine.
cannam@89 264
cannam@89 265 Buffer : in out Ada.Streams.Stream_Element_Array;
cannam@89 266 -- Buffer for keep remaining data from the previous
cannam@89 267 -- back read.
cannam@89 268
cannam@89 269 Rest_First, Rest_Last : in out Ada.Streams.Stream_Element_Offset;
cannam@89 270 -- Rest_First have to be initialized to Buffer'Last + 1
cannam@89 271 -- Rest_Last have to be initialized to Buffer'Last
cannam@89 272 -- before usage.
cannam@89 273
cannam@89 274 Allow_Read_Some : in Boolean := False;
cannam@89 275 -- Is it allowed to return Last < Item'Last before end of data.
cannam@89 276
cannam@89 277 procedure Read
cannam@89 278 (Filter : in out Filter_Type;
cannam@89 279 Item : out Ada.Streams.Stream_Element_Array;
cannam@89 280 Last : out Ada.Streams.Stream_Element_Offset;
cannam@89 281 Flush : in Flush_Mode := No_Flush);
cannam@89 282 -- Compress/Decompress data from generic parameter procedure Read to the
cannam@89 283 -- Item. User should provide Buffer and initialized Rest_First, Rest_Last
cannam@89 284 -- indicators. If Allow_Read_Some is True, Read routines could return
cannam@89 285 -- Last < Item'Last only at end of stream.
cannam@89 286
cannam@89 287 private
cannam@89 288
cannam@89 289 use Ada.Streams;
cannam@89 290
cannam@89 291 pragma Assert (Ada.Streams.Stream_Element'Size = 8);
cannam@89 292 pragma Assert (Ada.Streams.Stream_Element'Modulus = 2**8);
cannam@89 293
cannam@89 294 type Flush_Mode is new Integer range 0 .. 5;
cannam@89 295
cannam@89 296 type Compression_Method is new Integer range 8 .. 8;
cannam@89 297
cannam@89 298 type Strategy_Type is new Integer range 0 .. 3;
cannam@89 299
cannam@89 300 No_Flush : constant Flush_Mode := 0;
cannam@89 301 Partial_Flush : constant Flush_Mode := 1;
cannam@89 302 Sync_Flush : constant Flush_Mode := 2;
cannam@89 303 Full_Flush : constant Flush_Mode := 3;
cannam@89 304 Finish : constant Flush_Mode := 4;
cannam@89 305 Block_Flush : constant Flush_Mode := 5;
cannam@89 306
cannam@89 307 Filtered : constant Strategy_Type := 1;
cannam@89 308 Huffman_Only : constant Strategy_Type := 2;
cannam@89 309 RLE : constant Strategy_Type := 3;
cannam@89 310 Default_Strategy : constant Strategy_Type := 0;
cannam@89 311
cannam@89 312 Deflated : constant Compression_Method := 8;
cannam@89 313
cannam@89 314 type Z_Stream;
cannam@89 315
cannam@89 316 type Z_Stream_Access is access all Z_Stream;
cannam@89 317
cannam@89 318 type Filter_Type is tagged limited record
cannam@89 319 Strm : Z_Stream_Access;
cannam@89 320 Compression : Boolean;
cannam@89 321 Stream_End : Boolean;
cannam@89 322 Header : Header_Type;
cannam@89 323 CRC : Unsigned_32;
cannam@89 324 Offset : Stream_Element_Offset;
cannam@89 325 -- Offset for gzip header/footer output.
cannam@89 326 end record;
cannam@89 327
cannam@89 328 end ZLib;