annotate src/zlib-1.2.8/contrib/ada/zlib.ads @ 169:223a55898ab9 tip default

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