zlib-thin.ads 15 KB

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