Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / zlib / contrib / ada / zlib-thin.ads
blob7aaacdec060bd758ffceaec1011b36f4ce908bac
1 ----------------------------------------------------------------
2 -- ZLib for Ada thick binding. --
3 -- --
4 -- Copyright (C) 2002-2003 Dmitriy Anisimkov --
5 -- --
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
16 -- From zconf.h
18 MAX_MEM_LEVEL : constant := 9; -- zconf.h:105
19 -- zconf.h:105
20 MAX_WBITS : constant := 15; -- zconf.h:115
21 -- 32K LZ77 window
22 -- zconf.h:115
23 SEEK_SET : constant := 8#0000#; -- zconf.h:244
24 -- Seek from beginning of file.
25 -- zconf.h:244
26 SEEK_CUR : constant := 1; -- zconf.h:245
27 -- Seek from current position.
28 -- zconf.h:245
29 SEEK_END : constant := 2; -- zconf.h:246
30 -- Set file pointer to EOF plus "offset"
31 -- zconf.h:246
33 type Byte is new Interfaces.C.unsigned_char; -- 8 bits
34 -- zconf.h:214
35 type UInt is new Interfaces.C.unsigned; -- 16 bits or more
36 -- zconf.h:216
37 type Int is new Interfaces.C.int;
39 type ULong is new Interfaces.C.unsigned; -- 32 bits or more
40 -- zconf.h:217
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;
51 -- end from zconf
53 Z_NO_FLUSH : constant := 8#0000#; -- zlib.h:125
54 -- zlib.h:125
55 Z_PARTIAL_FLUSH : constant := 1; -- zlib.h:126
56 -- will be removed, use
57 -- Z_SYNC_FLUSH instead
58 -- zlib.h:126
59 Z_SYNC_FLUSH : constant := 2; -- zlib.h:127
60 -- zlib.h:127
61 Z_FULL_FLUSH : constant := 3; -- zlib.h:128
62 -- zlib.h:128
63 Z_FINISH : constant := 4; -- zlib.h:129
64 -- zlib.h:129
65 Z_OK : constant := 8#0000#; -- zlib.h:132
66 -- zlib.h:132
67 Z_STREAM_END : constant := 1; -- zlib.h:133
68 -- zlib.h:133
69 Z_NEED_DICT : constant := 2; -- zlib.h:134
70 -- zlib.h:134
71 Z_ERRNO : constant := -1; -- zlib.h:135
72 -- zlib.h:135
73 Z_STREAM_ERROR : constant := -2; -- zlib.h:136
74 -- zlib.h:136
75 Z_DATA_ERROR : constant := -3; -- zlib.h:137
76 -- zlib.h:137
77 Z_MEM_ERROR : constant := -4; -- zlib.h:138
78 -- zlib.h:138
79 Z_BUF_ERROR : constant := -5; -- zlib.h:139
80 -- zlib.h:139
81 Z_VERSION_ERROR : constant := -6; -- zlib.h:140
82 -- zlib.h:140
83 Z_NO_COMPRESSION : constant := 8#0000#; -- zlib.h:145
84 -- zlib.h:145
85 Z_BEST_SPEED : constant := 1; -- zlib.h:146
86 -- zlib.h:146
87 Z_BEST_COMPRESSION : constant := 9; -- zlib.h:147
88 -- zlib.h:147
89 Z_DEFAULT_COMPRESSION : constant := -1; -- zlib.h:148
90 -- zlib.h:148
91 Z_FILTERED : constant := 1; -- zlib.h:151
92 -- zlib.h:151
93 Z_HUFFMAN_ONLY : constant := 2; -- zlib.h:152
94 -- zlib.h:152
95 Z_DEFAULT_STRATEGY : constant := 8#0000#; -- zlib.h:153
96 -- zlib.h:153
97 Z_BINARY : constant := 8#0000#; -- zlib.h:156
98 -- zlib.h:156
99 Z_ASCII : constant := 1; -- zlib.h:157
100 -- zlib.h:157
101 Z_UNKNOWN : constant := 2; -- zlib.h:158
102 -- zlib.h:158
103 Z_DEFLATED : constant := 8; -- zlib.h:161
104 -- zlib.h:161
105 Z_NULL : constant := 8#0000#; -- zlib.h:164
106 -- for initializing zalloc, zfree, opaque
107 -- zlib.h:164
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
115 (Opaque : Voidp;
116 Items : UInt;
117 Size : UInt)
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
133 (strm : Z_Streamp;
134 dictionary : Byte_Access;
135 dictLength : UInt)
136 return Int;
138 function deflateCopy (dest : Z_Streamp; source : Z_Streamp) return Int;
139 -- zlib.h:478
141 function deflateReset (strm : Z_Streamp) return Int; -- zlib.h:495
143 function deflateParams
144 (strm : Z_Streamp;
145 level : Int;
146 strategy : Int)
147 return Int; -- zlib.h:506
149 function inflateSetDictionary
150 (strm : Z_Streamp;
151 dictionary : Byte_Access;
152 dictLength : UInt)
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
159 function compress
160 (dest : Byte_Access;
161 destLen : ULong_Access;
162 source : Byte_Access;
163 sourceLen : ULong)
164 return Int; -- zlib.h:601
166 function compress2
167 (dest : Byte_Access;
168 destLen : ULong_Access;
169 source : Byte_Access;
170 sourceLen : ULong;
171 level : Int)
172 return Int; -- zlib.h:615
174 function uncompress
175 (dest : Byte_Access;
176 destLen : ULong_Access;
177 source : Byte_Access;
178 sourceLen : ULong)
179 return Int;
181 function gzopen (path : Chars_Ptr; mode : Chars_Ptr) return gzFile;
183 function gzdopen (fd : Int; mode : Chars_Ptr) return gzFile;
185 function gzsetparams
186 (file : gzFile;
187 level : Int;
188 strategy : Int)
189 return Int;
191 function gzread
192 (file : gzFile;
193 buf : Voidp;
194 len : UInt)
195 return Int;
197 function gzwrite
198 (file : in gzFile;
199 buf : in Voidp;
200 len : in UInt)
201 return Int;
203 function gzprintf (file : in gzFile; format : in Chars_Ptr) return Int;
205 function gzputs (file : in gzFile; s : in Chars_Ptr) return Int;
207 function gzgets
208 (file : gzFile;
209 buf : Chars_Ptr;
210 len : Int)
211 return Chars_Ptr;
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;
219 function gzseek
220 (file : gzFile;
221 offset : Int;
222 whence : Int)
223 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;
235 function adler32
236 (adler : ULong;
237 buf : Byte_Access;
238 len : UInt)
239 return ULong;
241 function crc32
242 (crc : ULong;
243 buf : Byte_Access;
244 len : UInt)
245 return ULong;
247 function deflateInit
248 (strm : Z_Streamp;
249 level : Int;
250 version : Chars_Ptr;
251 stream_size : Int)
252 return Int;
254 function Deflate_Init
255 (strm : in Z_Streamp;
256 level : in Int := Z_DEFAULT_COMPRESSION)
257 return Int;
258 pragma Inline (Deflate_Init);
260 function deflateInit2
261 (strm : Z_Streamp;
262 level : Int;
263 method : Int;
264 windowBits : Int;
265 memLevel : Int;
266 strategy : Int;
267 version : Chars_Ptr;
268 stream_size : Int)
269 return Int;
271 function Deflate_Init
272 (strm : Z_Streamp;
273 level : Int;
274 method : Int;
275 windowBits : Int;
276 memLevel : Int;
277 strategy : Int)
278 return Int;
279 pragma Inline (Deflate_Init);
281 function inflateInit
282 (strm : Z_Streamp;
283 version : Chars_Ptr;
284 stream_size : Int)
285 return Int;
287 function Inflate_Init (strm : Z_Streamp) return Int;
288 pragma Inline (Inflate_Init);
290 function inflateInit2
291 (strm : in Z_Streamp;
292 windowBits : in Int;
293 version : in Chars_Ptr;
294 stream_size : in Int)
295 return Int;
297 function inflateBackInit
298 (strm : in Z_Streamp;
299 windowBits : in Int;
300 window : in Byte_Access;
301 version : in Chars_Ptr;
302 stream_size : in Int)
303 return 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);
329 procedure Set_In
330 (Strm : in out Z_Stream;
331 Buffer : in Byte_Access;
332 Size : in UInt);
333 pragma Inline (Set_In);
335 procedure Set_In
336 (Strm : in out Z_Stream;
337 Buffer : in Voidp;
338 Size : in UInt);
339 pragma Inline (Set_In);
341 procedure Set_Out
342 (Strm : in out Z_Stream;
343 Buffer : in Byte_Access;
344 Size : in UInt);
345 pragma Inline (Set_Out);
347 procedure Set_Out
348 (Strm : in out Z_Stream;
349 Buffer : in Voidp;
350 Size : in UInt);
351 pragma Inline (Set_Out);
353 procedure Set_Mem_Func
354 (Strm : in out Z_Stream;
355 Opaque : in Voidp;
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);
375 function inflateCopy
376 (dest : in Z_Streamp;
377 Source : in Z_Streamp)
378 return Int;
380 function compressBound (Source_Len : in ULong) return ULong;
382 function deflateBound
383 (Strm : in Z_Streamp;
384 Source_Len : in ULong)
385 return ULong;
387 function gzungetc (C : in Int; File : in gzFile) return Int;
389 function zlibCompileFlags return ULong;
391 function deflatePrime
392 (strm : Z_Streamp;
393 bits : Int;
394 value : Int)
395 return Int;
397 private
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
411 -- zalloc and zfree
412 data_type : Int; -- best guess about the data type:
413 -- ascii or binary
414 adler : ULong; -- adler32 value of the uncompressed
415 -- data
416 reserved : ULong; -- reserved for future use
417 end record;
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
480 -- routines.
482 -- pragma Import (C, inflateBack, "inflateBack");
483 -- pragma Import (C, inflateBackEnd, "inflateBackEnd");
485 end ZLib.Thin;