zlib-thin.ads revision 1.1.1.3 1 1.1 christos ----------------------------------------------------------------
2 1.1 christos -- ZLib for Ada thick binding. --
3 1.1 christos -- --
4 1.1 christos -- Copyright (C) 2002-2003 Dmitriy Anisimkov --
5 1.1 christos -- --
6 1.1 christos -- Open source license information is in the zlib.ads file. --
7 1.1 christos ----------------------------------------------------------------
8 1.1 christos
9 1.1.1.3 christos -- Id: zlib-thin.ads,v 1.11 2004/07/23 06:33:11 vagul Exp
10 1.1 christos
11 1.1 christos with Interfaces.C.Strings;
12 1.1 christos
13 1.1 christos with System;
14 1.1 christos
15 1.1 christos private package ZLib.Thin is
16 1.1 christos
17 1.1 christos -- From zconf.h
18 1.1 christos
19 1.1 christos MAX_MEM_LEVEL : constant := 9; -- zconf.h:105
20 1.1 christos -- zconf.h:105
21 1.1 christos MAX_WBITS : constant := 15; -- zconf.h:115
22 1.1 christos -- 32K LZ77 window
23 1.1 christos -- zconf.h:115
24 1.1 christos SEEK_SET : constant := 8#0000#; -- zconf.h:244
25 1.1 christos -- Seek from beginning of file.
26 1.1 christos -- zconf.h:244
27 1.1 christos SEEK_CUR : constant := 1; -- zconf.h:245
28 1.1 christos -- Seek from current position.
29 1.1 christos -- zconf.h:245
30 1.1 christos SEEK_END : constant := 2; -- zconf.h:246
31 1.1 christos -- Set file pointer to EOF plus "offset"
32 1.1 christos -- zconf.h:246
33 1.1 christos
34 1.1 christos type Byte is new Interfaces.C.unsigned_char; -- 8 bits
35 1.1 christos -- zconf.h:214
36 1.1 christos type UInt is new Interfaces.C.unsigned; -- 16 bits or more
37 1.1 christos -- zconf.h:216
38 1.1 christos type Int is new Interfaces.C.int;
39 1.1 christos
40 1.1 christos type ULong is new Interfaces.C.unsigned_long; -- 32 bits or more
41 1.1 christos -- zconf.h:217
42 1.1 christos subtype Chars_Ptr is Interfaces.C.Strings.chars_ptr;
43 1.1 christos
44 1.1 christos type ULong_Access is access ULong;
45 1.1 christos type Int_Access is access Int;
46 1.1 christos
47 1.1 christos subtype Voidp is System.Address; -- zconf.h:232
48 1.1 christos
49 1.1 christos subtype Byte_Access is Voidp;
50 1.1 christos
51 1.1 christos Nul : constant Voidp := System.Null_Address;
52 1.1 christos -- end from zconf
53 1.1 christos
54 1.1 christos Z_NO_FLUSH : constant := 8#0000#; -- zlib.h:125
55 1.1 christos -- zlib.h:125
56 1.1 christos Z_PARTIAL_FLUSH : constant := 1; -- zlib.h:126
57 1.1 christos -- will be removed, use
58 1.1 christos -- Z_SYNC_FLUSH instead
59 1.1 christos -- zlib.h:126
60 1.1 christos Z_SYNC_FLUSH : constant := 2; -- zlib.h:127
61 1.1 christos -- zlib.h:127
62 1.1 christos Z_FULL_FLUSH : constant := 3; -- zlib.h:128
63 1.1 christos -- zlib.h:128
64 1.1 christos Z_FINISH : constant := 4; -- zlib.h:129
65 1.1 christos -- zlib.h:129
66 1.1 christos Z_OK : constant := 8#0000#; -- zlib.h:132
67 1.1 christos -- zlib.h:132
68 1.1 christos Z_STREAM_END : constant := 1; -- zlib.h:133
69 1.1 christos -- zlib.h:133
70 1.1 christos Z_NEED_DICT : constant := 2; -- zlib.h:134
71 1.1 christos -- zlib.h:134
72 1.1 christos Z_ERRNO : constant := -1; -- zlib.h:135
73 1.1 christos -- zlib.h:135
74 1.1 christos Z_STREAM_ERROR : constant := -2; -- zlib.h:136
75 1.1 christos -- zlib.h:136
76 1.1 christos Z_DATA_ERROR : constant := -3; -- zlib.h:137
77 1.1 christos -- zlib.h:137
78 1.1 christos Z_MEM_ERROR : constant := -4; -- zlib.h:138
79 1.1 christos -- zlib.h:138
80 1.1 christos Z_BUF_ERROR : constant := -5; -- zlib.h:139
81 1.1 christos -- zlib.h:139
82 1.1 christos Z_VERSION_ERROR : constant := -6; -- zlib.h:140
83 1.1 christos -- zlib.h:140
84 1.1 christos Z_NO_COMPRESSION : constant := 8#0000#; -- zlib.h:145
85 1.1 christos -- zlib.h:145
86 1.1 christos Z_BEST_SPEED : constant := 1; -- zlib.h:146
87 1.1 christos -- zlib.h:146
88 1.1 christos Z_BEST_COMPRESSION : constant := 9; -- zlib.h:147
89 1.1 christos -- zlib.h:147
90 1.1 christos Z_DEFAULT_COMPRESSION : constant := -1; -- zlib.h:148
91 1.1 christos -- zlib.h:148
92 1.1 christos Z_FILTERED : constant := 1; -- zlib.h:151
93 1.1 christos -- zlib.h:151
94 1.1 christos Z_HUFFMAN_ONLY : constant := 2; -- zlib.h:152
95 1.1 christos -- zlib.h:152
96 1.1 christos Z_DEFAULT_STRATEGY : constant := 8#0000#; -- zlib.h:153
97 1.1 christos -- zlib.h:153
98 1.1 christos Z_BINARY : constant := 8#0000#; -- zlib.h:156
99 1.1 christos -- zlib.h:156
100 1.1 christos Z_ASCII : constant := 1; -- zlib.h:157
101 1.1 christos -- zlib.h:157
102 1.1 christos Z_UNKNOWN : constant := 2; -- zlib.h:158
103 1.1 christos -- zlib.h:158
104 1.1 christos Z_DEFLATED : constant := 8; -- zlib.h:161
105 1.1 christos -- zlib.h:161
106 1.1 christos Z_NULL : constant := 8#0000#; -- zlib.h:164
107 1.1 christos -- for initializing zalloc, zfree, opaque
108 1.1 christos -- zlib.h:164
109 1.1 christos type gzFile is new Voidp; -- zlib.h:646
110 1.1 christos
111 1.1 christos type Z_Stream is private;
112 1.1 christos
113 1.1 christos type Z_Streamp is access all Z_Stream; -- zlib.h:89
114 1.1 christos
115 1.1 christos type alloc_func is access function
116 1.1 christos (Opaque : Voidp;
117 1.1 christos Items : UInt;
118 1.1 christos Size : UInt)
119 1.1 christos return Voidp; -- zlib.h:63
120 1.1 christos
121 1.1 christos type free_func is access procedure (opaque : Voidp; address : Voidp);
122 1.1 christos
123 1.1 christos function zlibVersion return Chars_Ptr;
124 1.1 christos
125 1.1 christos function Deflate (strm : Z_Streamp; flush : Int) return Int;
126 1.1 christos
127 1.1 christos function DeflateEnd (strm : Z_Streamp) return Int;
128 1.1 christos
129 1.1 christos function Inflate (strm : Z_Streamp; flush : Int) return Int;
130 1.1 christos
131 1.1 christos function InflateEnd (strm : Z_Streamp) return Int;
132 1.1 christos
133 1.1 christos function deflateSetDictionary
134 1.1 christos (strm : Z_Streamp;
135 1.1 christos dictionary : Byte_Access;
136 1.1 christos dictLength : UInt)
137 1.1 christos return Int;
138 1.1 christos
139 1.1 christos function deflateCopy (dest : Z_Streamp; source : Z_Streamp) return Int;
140 1.1 christos -- zlib.h:478
141 1.1 christos
142 1.1 christos function deflateReset (strm : Z_Streamp) return Int; -- zlib.h:495
143 1.1 christos
144 1.1 christos function deflateParams
145 1.1 christos (strm : Z_Streamp;
146 1.1 christos level : Int;
147 1.1 christos strategy : Int)
148 1.1 christos return Int; -- zlib.h:506
149 1.1 christos
150 1.1 christos function inflateSetDictionary
151 1.1 christos (strm : Z_Streamp;
152 1.1 christos dictionary : Byte_Access;
153 1.1 christos dictLength : UInt)
154 1.1 christos return Int; -- zlib.h:548
155 1.1 christos
156 1.1 christos function inflateSync (strm : Z_Streamp) return Int; -- zlib.h:565
157 1.1 christos
158 1.1 christos function inflateReset (strm : Z_Streamp) return Int; -- zlib.h:580
159 1.1 christos
160 1.1 christos function compress
161 1.1 christos (dest : Byte_Access;
162 1.1 christos destLen : ULong_Access;
163 1.1 christos source : Byte_Access;
164 1.1 christos sourceLen : ULong)
165 1.1 christos return Int; -- zlib.h:601
166 1.1 christos
167 1.1 christos function compress2
168 1.1 christos (dest : Byte_Access;
169 1.1 christos destLen : ULong_Access;
170 1.1 christos source : Byte_Access;
171 1.1 christos sourceLen : ULong;
172 1.1 christos level : Int)
173 1.1 christos return Int; -- zlib.h:615
174 1.1 christos
175 1.1 christos function uncompress
176 1.1 christos (dest : Byte_Access;
177 1.1 christos destLen : ULong_Access;
178 1.1 christos source : Byte_Access;
179 1.1 christos sourceLen : ULong)
180 1.1 christos return Int;
181 1.1 christos
182 1.1 christos function gzopen (path : Chars_Ptr; mode : Chars_Ptr) return gzFile;
183 1.1 christos
184 1.1 christos function gzdopen (fd : Int; mode : Chars_Ptr) return gzFile;
185 1.1 christos
186 1.1 christos function gzsetparams
187 1.1 christos (file : gzFile;
188 1.1 christos level : Int;
189 1.1 christos strategy : Int)
190 1.1 christos return Int;
191 1.1 christos
192 1.1 christos function gzread
193 1.1 christos (file : gzFile;
194 1.1 christos buf : Voidp;
195 1.1 christos len : UInt)
196 1.1 christos return Int;
197 1.1 christos
198 1.1 christos function gzwrite
199 1.1 christos (file : in gzFile;
200 1.1 christos buf : in Voidp;
201 1.1 christos len : in UInt)
202 1.1 christos return Int;
203 1.1 christos
204 1.1 christos function gzprintf (file : in gzFile; format : in Chars_Ptr) return Int;
205 1.1 christos
206 1.1 christos function gzputs (file : in gzFile; s : in Chars_Ptr) return Int;
207 1.1 christos
208 1.1 christos function gzgets
209 1.1 christos (file : gzFile;
210 1.1 christos buf : Chars_Ptr;
211 1.1 christos len : Int)
212 1.1 christos return Chars_Ptr;
213 1.1 christos
214 1.1 christos function gzputc (file : gzFile; char : Int) return Int;
215 1.1 christos
216 1.1 christos function gzgetc (file : gzFile) return Int;
217 1.1 christos
218 1.1 christos function gzflush (file : gzFile; flush : Int) return Int;
219 1.1 christos
220 1.1 christos function gzseek
221 1.1 christos (file : gzFile;
222 1.1 christos offset : Int;
223 1.1 christos whence : Int)
224 1.1 christos return Int;
225 1.1 christos
226 1.1 christos function gzrewind (file : gzFile) return Int;
227 1.1 christos
228 1.1 christos function gztell (file : gzFile) return Int;
229 1.1 christos
230 1.1 christos function gzeof (file : gzFile) return Int;
231 1.1 christos
232 1.1 christos function gzclose (file : gzFile) return Int;
233 1.1 christos
234 1.1 christos function gzerror (file : gzFile; errnum : Int_Access) return Chars_Ptr;
235 1.1 christos
236 1.1 christos function adler32
237 1.1 christos (adler : ULong;
238 1.1 christos buf : Byte_Access;
239 1.1 christos len : UInt)
240 1.1 christos return ULong;
241 1.1 christos
242 1.1 christos function crc32
243 1.1 christos (crc : ULong;
244 1.1 christos buf : Byte_Access;
245 1.1 christos len : UInt)
246 1.1 christos return ULong;
247 1.1 christos
248 1.1 christos function deflateInit
249 1.1 christos (strm : Z_Streamp;
250 1.1 christos level : Int;
251 1.1 christos version : Chars_Ptr;
252 1.1 christos stream_size : Int)
253 1.1 christos return Int;
254 1.1 christos
255 1.1 christos function deflateInit2
256 1.1 christos (strm : Z_Streamp;
257 1.1 christos level : Int;
258 1.1 christos method : Int;
259 1.1 christos windowBits : Int;
260 1.1 christos memLevel : Int;
261 1.1 christos strategy : Int;
262 1.1 christos version : Chars_Ptr;
263 1.1 christos stream_size : Int)
264 1.1 christos return Int;
265 1.1 christos
266 1.1 christos function Deflate_Init
267 1.1 christos (strm : Z_Streamp;
268 1.1 christos level : Int;
269 1.1 christos method : Int;
270 1.1 christos windowBits : Int;
271 1.1 christos memLevel : Int;
272 1.1 christos strategy : Int)
273 1.1 christos return Int;
274 1.1 christos pragma Inline (Deflate_Init);
275 1.1 christos
276 1.1 christos function inflateInit
277 1.1 christos (strm : Z_Streamp;
278 1.1 christos version : Chars_Ptr;
279 1.1 christos stream_size : Int)
280 1.1 christos return Int;
281 1.1 christos
282 1.1 christos function inflateInit2
283 1.1 christos (strm : in Z_Streamp;
284 1.1 christos windowBits : in Int;
285 1.1 christos version : in Chars_Ptr;
286 1.1 christos stream_size : in Int)
287 1.1 christos return Int;
288 1.1 christos
289 1.1 christos function inflateBackInit
290 1.1 christos (strm : in Z_Streamp;
291 1.1 christos windowBits : in Int;
292 1.1 christos window : in Byte_Access;
293 1.1 christos version : in Chars_Ptr;
294 1.1 christos stream_size : in Int)
295 1.1 christos return Int;
296 1.1 christos -- Size of window have to be 2**windowBits.
297 1.1 christos
298 1.1 christos function Inflate_Init (strm : Z_Streamp; windowBits : Int) return Int;
299 1.1 christos pragma Inline (Inflate_Init);
300 1.1 christos
301 1.1 christos function zError (err : Int) return Chars_Ptr;
302 1.1 christos
303 1.1 christos function inflateSyncPoint (z : Z_Streamp) return Int;
304 1.1 christos
305 1.1 christos function get_crc_table return ULong_Access;
306 1.1 christos
307 1.1 christos -- Interface to the available fields of the z_stream structure.
308 1.1 christos -- The application must update next_in and avail_in when avail_in has
309 1.1 christos -- dropped to zero. It must update next_out and avail_out when avail_out
310 1.1 christos -- has dropped to zero. The application must initialize zalloc, zfree and
311 1.1 christos -- opaque before calling the init function.
312 1.1 christos
313 1.1 christos procedure Set_In
314 1.1 christos (Strm : in out Z_Stream;
315 1.1 christos Buffer : in Voidp;
316 1.1 christos Size : in UInt);
317 1.1 christos pragma Inline (Set_In);
318 1.1 christos
319 1.1 christos procedure Set_Out
320 1.1 christos (Strm : in out Z_Stream;
321 1.1 christos Buffer : in Voidp;
322 1.1 christos Size : in UInt);
323 1.1 christos pragma Inline (Set_Out);
324 1.1 christos
325 1.1 christos procedure Set_Mem_Func
326 1.1 christos (Strm : in out Z_Stream;
327 1.1 christos Opaque : in Voidp;
328 1.1 christos Alloc : in alloc_func;
329 1.1 christos Free : in free_func);
330 1.1 christos pragma Inline (Set_Mem_Func);
331 1.1 christos
332 1.1 christos function Last_Error_Message (Strm : in Z_Stream) return String;
333 1.1 christos pragma Inline (Last_Error_Message);
334 1.1 christos
335 1.1 christos function Avail_Out (Strm : in Z_Stream) return UInt;
336 1.1 christos pragma Inline (Avail_Out);
337 1.1 christos
338 1.1 christos function Avail_In (Strm : in Z_Stream) return UInt;
339 1.1 christos pragma Inline (Avail_In);
340 1.1 christos
341 1.1 christos function Total_In (Strm : in Z_Stream) return ULong;
342 1.1 christos pragma Inline (Total_In);
343 1.1 christos
344 1.1 christos function Total_Out (Strm : in Z_Stream) return ULong;
345 1.1 christos pragma Inline (Total_Out);
346 1.1 christos
347 1.1 christos function inflateCopy
348 1.1 christos (dest : in Z_Streamp;
349 1.1 christos Source : in Z_Streamp)
350 1.1 christos return Int;
351 1.1 christos
352 1.1 christos function compressBound (Source_Len : in ULong) return ULong;
353 1.1 christos
354 1.1 christos function deflateBound
355 1.1 christos (Strm : in Z_Streamp;
356 1.1 christos Source_Len : in ULong)
357 1.1 christos return ULong;
358 1.1 christos
359 1.1 christos function gzungetc (C : in Int; File : in gzFile) return Int;
360 1.1 christos
361 1.1 christos function zlibCompileFlags return ULong;
362 1.1 christos
363 1.1 christos private
364 1.1 christos
365 1.1 christos type Z_Stream is record -- zlib.h:68
366 1.1 christos Next_In : Voidp := Nul; -- next input byte
367 1.1 christos Avail_In : UInt := 0; -- number of bytes available at next_in
368 1.1 christos Total_In : ULong := 0; -- total nb of input bytes read so far
369 1.1 christos Next_Out : Voidp := Nul; -- next output byte should be put there
370 1.1 christos Avail_Out : UInt := 0; -- remaining free space at next_out
371 1.1 christos Total_Out : ULong := 0; -- total nb of bytes output so far
372 1.1 christos msg : Chars_Ptr; -- last error message, NULL if no error
373 1.1 christos state : Voidp; -- not visible by applications
374 1.1 christos zalloc : alloc_func := null; -- used to allocate the internal state
375 1.1 christos zfree : free_func := null; -- used to free the internal state
376 1.1 christos opaque : Voidp; -- private data object passed to
377 1.1 christos -- zalloc and zfree
378 1.1 christos data_type : Int; -- best guess about the data type:
379 1.1 christos -- ascii or binary
380 1.1 christos adler : ULong; -- adler32 value of the uncompressed
381 1.1 christos -- data
382 1.1 christos reserved : ULong; -- reserved for future use
383 1.1 christos end record;
384 1.1 christos
385 1.1 christos pragma Convention (C, Z_Stream);
386 1.1 christos
387 1.1 christos pragma Import (C, zlibVersion, "zlibVersion");
388 1.1 christos pragma Import (C, Deflate, "deflate");
389 1.1 christos pragma Import (C, DeflateEnd, "deflateEnd");
390 1.1 christos pragma Import (C, Inflate, "inflate");
391 1.1 christos pragma Import (C, InflateEnd, "inflateEnd");
392 1.1 christos pragma Import (C, deflateSetDictionary, "deflateSetDictionary");
393 1.1 christos pragma Import (C, deflateCopy, "deflateCopy");
394 1.1 christos pragma Import (C, deflateReset, "deflateReset");
395 1.1 christos pragma Import (C, deflateParams, "deflateParams");
396 1.1 christos pragma Import (C, inflateSetDictionary, "inflateSetDictionary");
397 1.1 christos pragma Import (C, inflateSync, "inflateSync");
398 1.1 christos pragma Import (C, inflateReset, "inflateReset");
399 1.1 christos pragma Import (C, compress, "compress");
400 1.1 christos pragma Import (C, compress2, "compress2");
401 1.1 christos pragma Import (C, uncompress, "uncompress");
402 1.1 christos pragma Import (C, gzopen, "gzopen");
403 1.1 christos pragma Import (C, gzdopen, "gzdopen");
404 1.1 christos pragma Import (C, gzsetparams, "gzsetparams");
405 1.1 christos pragma Import (C, gzread, "gzread");
406 1.1 christos pragma Import (C, gzwrite, "gzwrite");
407 1.1 christos pragma Import (C, gzprintf, "gzprintf");
408 1.1 christos pragma Import (C, gzputs, "gzputs");
409 1.1 christos pragma Import (C, gzgets, "gzgets");
410 1.1 christos pragma Import (C, gzputc, "gzputc");
411 1.1 christos pragma Import (C, gzgetc, "gzgetc");
412 1.1 christos pragma Import (C, gzflush, "gzflush");
413 1.1 christos pragma Import (C, gzseek, "gzseek");
414 1.1 christos pragma Import (C, gzrewind, "gzrewind");
415 1.1 christos pragma Import (C, gztell, "gztell");
416 1.1 christos pragma Import (C, gzeof, "gzeof");
417 1.1 christos pragma Import (C, gzclose, "gzclose");
418 1.1 christos pragma Import (C, gzerror, "gzerror");
419 1.1 christos pragma Import (C, adler32, "adler32");
420 1.1 christos pragma Import (C, crc32, "crc32");
421 1.1 christos pragma Import (C, deflateInit, "deflateInit_");
422 1.1 christos pragma Import (C, inflateInit, "inflateInit_");
423 1.1 christos pragma Import (C, deflateInit2, "deflateInit2_");
424 1.1 christos pragma Import (C, inflateInit2, "inflateInit2_");
425 1.1 christos pragma Import (C, zError, "zError");
426 1.1 christos pragma Import (C, inflateSyncPoint, "inflateSyncPoint");
427 1.1 christos pragma Import (C, get_crc_table, "get_crc_table");
428 1.1 christos
429 1.1 christos -- since zlib 1.2.0:
430 1.1 christos
431 1.1 christos pragma Import (C, inflateCopy, "inflateCopy");
432 1.1 christos pragma Import (C, compressBound, "compressBound");
433 1.1 christos pragma Import (C, deflateBound, "deflateBound");
434 1.1 christos pragma Import (C, gzungetc, "gzungetc");
435 1.1 christos pragma Import (C, zlibCompileFlags, "zlibCompileFlags");
436 1.1 christos
437 1.1 christos pragma Import (C, inflateBackInit, "inflateBackInit_");
438 1.1 christos
439 1.1.1.2 christos -- I stopped binding the inflateBack routines, because realize that
440 1.1 christos -- it does not support zlib and gzip headers for now, and have no
441 1.1 christos -- symmetric deflateBack routines.
442 1.1 christos -- ZLib-Ada is symmetric regarding deflate/inflate data transformation
443 1.1 christos -- and has a similar generic callback interface for the
444 1.1 christos -- deflate/inflate transformation based on the regular Deflate/Inflate
445 1.1 christos -- routines.
446 1.1 christos
447 1.1 christos -- pragma Import (C, inflateBack, "inflateBack");
448 1.1 christos -- pragma Import (C, inflateBackEnd, "inflateBackEnd");
449 1.1 christos
450 1.1 christos end ZLib.Thin;
451