arch/ppc-native/processor: Don't build for non-native PPC targets
[AROS.git] / workbench / devs / diskimage / bz2_library / init.c
blob2e79a241308b68dac89fc04508e989d41e22ca44
1 /* Copyright 2007-2012 Fredrik Wikstrom. All rights reserved.
2 **
3 ** Redistribution and use in source and binary forms, with or without
4 ** modification, are permitted provided that the following conditions
5 ** are met:
6 **
7 ** 1. Redistributions of source code must retain the above copyright
8 ** notice, this list of conditions and the following disclaimer.
9 **
10 ** 2. Redistributions in binary form must reproduce the above copyright
11 ** notice, this list of conditions and the following disclaimer in the
12 ** documentation and/or other materials provided with the distribution.
14 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
15 ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
18 ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 ** POSSIBILITY OF SUCH DAMAGE.
27 #include <exec/exec.h>
28 #include <dos/dos.h>
29 #include <proto/exec.h>
30 #include <bzlib.h>
31 #include "support.h"
32 #include <SDI_compiler.h>
33 #include "bz2.library_rev.h"
35 #define LIBNAME "bz2.library"
36 const char USED verstag[] = VERSTAG;
38 #ifndef __AROS__
39 #define IPTR ULONG
40 #endif
42 struct ExecBase *SysBase;
44 struct BZ2Base {
45 struct Library libNode;
46 UWORD pad;
47 BPTR seglist;
50 int malloc_init(void);
51 void malloc_exit(void);
53 #ifdef __AROS__
54 static AROS_UFP3(struct BZ2Base *, LibInit,
55 AROS_UFPA(struct BZ2Base *, libBase, D0),
56 AROS_UFPA(BPTR, seglist, A0),
57 AROS_UFPA(struct ExecBase *, exec_base, A6)
59 static AROS_LD1(struct BZ2Base *, LibOpen,
60 AROS_LPA(ULONG, version, D0),
61 struct BZ2Base *, libBase, 1, BZlib
63 static AROS_LD0(BPTR, LibClose,
64 struct BZ2Base *, libBase, 2, BZlib
66 static AROS_LD0(BPTR, LibExpunge,
67 struct BZ2Base *, libBase, 3, BZlib
69 static AROS_LD0(APTR, LibReserved,
70 struct BZ2Base *, libBase, 4, BZlib
72 static AROS_LD0(const char *, BZlibVersion,
73 struct BZ2Base *, libBase, 5, BZlib
75 static AROS_LD4(LONG, CompressInit,
76 AROS_LPA(bz_stream *, strm, A0),
77 AROS_LPA(LONG, blockSize100k, D0),
78 AROS_LPA(LONG, verbosity, D1),
79 AROS_LPA(LONG, workFactor, D2),
80 struct BZ2Base *, libBase, 6, BZlib
82 static AROS_LD2(LONG, Compress,
83 AROS_LPA(bz_stream *, strm, A0),
84 AROS_LPA(LONG, action, D0),
85 struct BZ2Base *, libBase, 7, BZlib
87 static AROS_LD1(LONG, CompressEnd,
88 AROS_LPA(bz_stream *, strm, A0),
89 struct BZ2Base *, libBase, 8, BZlib
91 static AROS_LD3(LONG, DecompressInit,
92 AROS_LPA(bz_stream *, strm, A0),
93 AROS_LPA(LONG, verbosity, D0),
94 AROS_LPA(LONG, small, D1),
95 struct BZ2Base *, libBase, 9, BZlib
97 static AROS_LD1(LONG, Decompress,
98 AROS_LPA(bz_stream *, strm, A0),
99 struct BZ2Base *, libBase, 10, BZlib
101 static AROS_LD1(LONG, DecompressEnd,
102 AROS_LPA(bz_stream *, strm, A0),
103 struct BZ2Base *, libBase, 11, BZlib
105 static AROS_LD7(LONG, BuffToBuffCompress,
106 AROS_LPA(APTR, dest, A0),
107 AROS_LPA(ULONG *, destLen, A1),
108 AROS_LPA(APTR, source, A2),
109 AROS_LPA(ULONG, sourceLen, D0),
110 AROS_LPA(LONG, blockSize100k, D1),
111 AROS_LPA(LONG, verbosity, D2),
112 AROS_LPA(LONG, workFactor, D3),
113 struct BZ2Base *, libBase, 12, BZlib
115 static AROS_LD6(LONG, BuffToBuffDecompress,
116 AROS_LPA(APTR, dest, A0),
117 AROS_LPA(ULONG *, destLen, A1),
118 AROS_LPA(APTR, source, A2),
119 AROS_LPA(ULONG, sourceLen, D0),
120 AROS_LPA(LONG, small, D1),
121 AROS_LPA(LONG, verbosity, D2),
122 struct BZ2Base *, libBase, 13, BZlib
124 #else
125 static struct BZ2Base *LibInit (REG(d0, struct BZ2Base *libBase), REG(a0, BPTR seglist),
126 REG(a6, struct ExecBase *exec_base));
127 static struct BZ2Base *BZlib_LibOpen (REG(a6, struct BZ2Base *libBase), REG(d0, ULONG version));
128 static BPTR BZlib_LibClose (REG(a6, struct BZ2Base *libBase));
129 static BPTR BZlib_LibExpunge (REG(a6, struct BZ2Base *libBase));
130 static APTR BZlib_LibReserved (REG(a6, struct BZ2Base *libBase));
131 static const char *BZlib_BZlibVersion(void);
132 static LONG BZlib_CompressInit(REG(a0, bz_stream *strm), REG(d0, LONG blockSize100k),
133 REG(d1, LONG verbosity), REG(d2, LONG workFactor));
134 static LONG BZlib_Compress(REG(a0, bz_stream *strm), REG(d0, LONG action));
135 static LONG BZlib_CompressEnd(REG(a0, bz_stream *strm));
136 static LONG BZlib_DecompressInit(REG(a0, bz_stream *strm), REG(d0, LONG verbosity),
137 REG(d1, LONG small));
138 static LONG BZlib_Decompress(REG(a0, bz_stream *strm));
139 static LONG BZlib_DecompressEnd(REG(a0, bz_stream *strm));
140 static LONG BZlib_BuffToBuffCompress(REG(a0, APTR dest), REG(a1, ULONG *destLen),
141 REG(a2, APTR source), REG(d0, ULONG sourceLen), REG(d1, LONG blockSize100k),
142 REG(d2, LONG verbosity), REG(d3, LONG workFactor));
143 static LONG BZlib_BuffToBuffDecompress(REG(a0, APTR dest), REG(a1, ULONG *destLen),
144 REG(a2, APTR source), REG(d0, ULONG sourceLen), REG(d1, LONG small),
145 REG(d2, LONG verbosity));
146 #endif
148 #ifdef __AROS__
149 #ifdef ABIV1
150 #define LIB_ENTRY(a,b) AROS_SLIB_ENTRY(a, BZlib, b)
151 #else
152 #define LIB_ENTRY(a,b) AROS_SLIB_ENTRY(a, BZlib)
153 #endif
154 #else
155 #define LIB_ENTRY(a,b) BZlib_##a
156 #endif
158 const CONST_APTR LibVectors[] = {
159 (APTR)LIB_ENTRY(LibOpen, 1),
160 (APTR)LIB_ENTRY(LibClose, 2),
161 (APTR)LIB_ENTRY(LibExpunge, 3),
162 (APTR)LIB_ENTRY(LibReserved, 4),
163 (APTR)LIB_ENTRY(BZlibVersion, 5),
164 (APTR)LIB_ENTRY(CompressInit, 6),
165 (APTR)LIB_ENTRY(Compress, 7),
166 (APTR)LIB_ENTRY(CompressEnd, 8),
167 (APTR)LIB_ENTRY(DecompressInit, 9),
168 (APTR)LIB_ENTRY(Decompress, 10),
169 (APTR)LIB_ENTRY(DecompressEnd, 11),
170 (APTR)LIB_ENTRY(BuffToBuffCompress, 12),
171 (APTR)LIB_ENTRY(BuffToBuffDecompress, 13),
172 (APTR)-1
175 const IPTR LibInitTab[] = {
176 sizeof(struct BZ2Base),
177 (IPTR)LibVectors,
178 (IPTR)NULL,
179 (IPTR)LibInit
182 CONST struct Resident USED lib_res = {
183 RTC_MATCHWORD,
184 (struct Resident *)&lib_res,
185 (APTR)(&lib_res + 1),
186 RTF_AUTOINIT,
187 VERSION,
188 NT_LIBRARY,
190 (STRPTR)LIBNAME,
191 (STRPTR)VSTRING,
192 (APTR)&LibInitTab
195 #ifdef __AROS__
196 static AROS_UFH3(struct BZ2Base *, LibInit,
197 AROS_UFHA(struct BZ2Base *, libBase, D0),
198 AROS_UFHA(BPTR, seglist, A0),
199 AROS_UFHA(struct ExecBase *, exec_base, A6)
202 AROS_USERFUNC_INIT
203 #else
204 static struct BZ2Base *LibInit (REG(d0, struct BZ2Base *libBase), REG(a0, BPTR seglist),
205 REG(a6, struct ExecBase *exec_base))
207 #endif
208 libBase->libNode.lib_Node.ln_Type = NT_LIBRARY;
209 libBase->libNode.lib_Node.ln_Pri = 0;
210 libBase->libNode.lib_Node.ln_Name = LIBNAME;
211 libBase->libNode.lib_Flags = LIBF_SUMUSED|LIBF_CHANGED;
212 libBase->libNode.lib_Version = VERSION;
213 libBase->libNode.lib_Revision = REVISION;
214 libBase->libNode.lib_IdString = VSTRING;
216 SysBase = exec_base;
217 libBase->seglist = seglist;
219 if (malloc_init()) {
220 return libBase;
223 DeleteLibrary((struct Library *)libBase);
225 return NULL;
226 #ifdef __AROS__
227 AROS_USERFUNC_EXIT
228 #endif
231 #ifdef __AROS__
232 static AROS_LH1(struct BZ2Base *, LibOpen,
233 AROS_LHA(ULONG, version, D0),
234 struct BZ2Base *, libBase, 1, BZlib
237 AROS_LIBFUNC_INIT
238 #else
239 static struct BZ2Base *BZlib_LibOpen (REG(a6, struct BZ2Base *libBase), REG(d0, ULONG version)) {
240 #endif
241 libBase->libNode.lib_OpenCnt++;
242 libBase->libNode.lib_Flags &= ~LIBF_DELEXP;
243 return libBase;
244 #ifdef __AROS__
245 AROS_LIBFUNC_EXIT
246 #endif
249 #ifdef __AROS__
250 static AROS_LH0(BPTR, LibClose,
251 struct BZ2Base *, libBase, 2, BZlib
254 AROS_LIBFUNC_INIT
255 #else
256 static BPTR BZlib_LibClose (REG(a6, struct BZ2Base *libBase)) {
257 #endif
258 libBase->libNode.lib_OpenCnt--;
259 return 0;
260 #ifdef __AROS__
261 AROS_LIBFUNC_EXIT
262 #endif
265 #ifdef __AROS__
266 static AROS_LH0(BPTR, LibExpunge,
267 struct BZ2Base *, libBase, 3, BZlib
270 AROS_LIBFUNC_INIT
271 #else
272 static BPTR BZlib_LibExpunge (REG(a6, struct BZ2Base *libBase)) {
273 #endif
274 BPTR result = 0;
276 if (libBase->libNode.lib_OpenCnt > 0) {
277 libBase->libNode.lib_Flags |= LIBF_DELEXP;
278 return 0;
281 Remove(&libBase->libNode.lib_Node);
283 result = libBase->seglist;
285 malloc_exit();
287 DeleteLibrary((struct Library *)libBase);
289 return result;
290 #ifdef __AROS__
291 AROS_LIBFUNC_EXIT
292 #endif
295 #ifdef __AROS__
296 static AROS_LH0(APTR, LibReserved,
297 struct BZ2Base *, libBase, 4, BZlib
300 AROS_LIBFUNC_INIT
301 return NULL;
302 AROS_LIBFUNC_EXIT
304 #else
305 static APTR BZlib_LibReserved (REG(a6, struct BZ2Base *libBase)) {
306 return NULL;
308 #endif
310 #ifdef __AROS__
311 static AROS_LH0(const char *, BZlibVersion,
312 struct BZ2Base *, libBase, 5, BZlib
315 AROS_LIBFUNC_INIT
316 #else
317 static const char *BZlib_BZlibVersion(void) {
318 #endif
319 return BZ2_bzlibVersion();
320 #ifdef __AROS__
321 AROS_LIBFUNC_EXIT
322 #endif
325 #ifdef __AROS__
326 static AROS_LH4(LONG, CompressInit,
327 AROS_LHA(bz_stream *, strm, A0),
328 AROS_LHA(LONG, blockSize100k, D0),
329 AROS_LHA(LONG, verbosity, D1),
330 AROS_LHA(LONG, workFactor, D2),
331 struct BZ2Base *, libBase, 6, BZlib
334 AROS_LIBFUNC_INIT
335 #else
336 static LONG BZlib_CompressInit(REG(a0, bz_stream *strm), REG(d0, LONG blockSize100k),
337 REG(d1, LONG verbosity), REG(d2, LONG workFactor))
339 #endif
340 return BZ2_bzCompressInit(strm, blockSize100k, verbosity, workFactor);
341 #ifdef __AROS__
342 AROS_LIBFUNC_EXIT
343 #endif
346 #ifdef __AROS__
347 static AROS_LH2(LONG, Compress,
348 AROS_LHA(bz_stream *, strm, A0),
349 AROS_LHA(LONG, action, D0),
350 struct BZ2Base *, libBase, 7, BZlib
353 AROS_LIBFUNC_INIT
354 #else
355 static LONG BZlib_Compress(REG(a0, bz_stream *strm), REG(d0, LONG action)) {
356 #endif
357 return BZ2_bzCompress(strm, action);
358 #ifdef __AROS__
359 AROS_LIBFUNC_EXIT
360 #endif
363 #ifdef __AROS__
364 static AROS_LH1(LONG, CompressEnd,
365 AROS_LHA(bz_stream *, strm, A0),
366 struct BZ2Base *, libBase, 8, BZlib
369 AROS_LIBFUNC_INIT
370 #else
371 static LONG BZlib_CompressEnd(REG(a0, bz_stream *strm)) {
372 #endif
373 return BZ2_bzCompressEnd(strm);
374 #ifdef __AROS__
375 AROS_LIBFUNC_EXIT
376 #endif
379 #ifdef __AROS__
380 static AROS_LH3(LONG, DecompressInit,
381 AROS_LHA(bz_stream *, strm, A0),
382 AROS_LHA(LONG, verbosity, D0),
383 AROS_LHA(LONG, small, D1),
384 struct BZ2Base *, libBase, 9, BZlib
387 AROS_LIBFUNC_INIT
388 #else
389 static LONG BZlib_DecompressInit(REG(a0, bz_stream *strm), REG(d0, LONG verbosity),
390 REG(d1, LONG small))
392 #endif
393 return BZ2_bzDecompressInit(strm, verbosity, small);
394 #ifdef __AROS__
395 AROS_LIBFUNC_EXIT
396 #endif
399 #ifdef __AROS__
400 static AROS_LH1(LONG, Decompress,
401 AROS_LHA(bz_stream *, strm, A0),
402 struct BZ2Base *, libBase, 10, BZlib
405 AROS_LIBFUNC_INIT
406 #else
407 static LONG BZlib_Decompress(REG(a0, bz_stream *strm)) {
408 #endif
409 return BZ2_bzDecompress(strm);
410 #ifdef __AROS__
411 AROS_LIBFUNC_EXIT
412 #endif
415 #ifdef __AROS__
416 static AROS_LH1(LONG, DecompressEnd,
417 AROS_LHA(bz_stream *, strm, A0),
418 struct BZ2Base *, libBase, 11, BZlib
421 AROS_LIBFUNC_INIT
422 #else
423 static LONG BZlib_DecompressEnd(REG(a0, bz_stream *strm)) {
424 #endif
425 return BZ2_bzDecompressEnd(strm);
426 #ifdef __AROS__
427 AROS_LIBFUNC_EXIT
428 #endif
431 #ifdef __AROS__
432 static AROS_LH7(LONG, BuffToBuffCompress,
433 AROS_LHA(APTR, dest, A0),
434 AROS_LHA(ULONG *, destLen, A1),
435 AROS_LHA(APTR, source, A2),
436 AROS_LHA(ULONG, sourceLen, D0),
437 AROS_LHA(LONG, blockSize100k, D1),
438 AROS_LHA(LONG, verbosity, D2),
439 AROS_LHA(LONG, workFactor, D3),
440 struct BZ2Base *, libBase, 12, BZlib
443 AROS_LIBFUNC_INIT
444 #else
445 static LONG BZlib_BuffToBuffCompress(REG(a0, APTR dest), REG(a1, ULONG *destLen),
446 REG(a2, APTR source), REG(d0, ULONG sourceLen), REG(d1, LONG blockSize100k),
447 REG(d2, LONG verbosity), REG(d3, LONG workFactor))
449 #endif
450 return BZ2_bzBuffToBuffCompress(dest, (unsigned int *)destLen, source, sourceLen,
451 blockSize100k, verbosity, workFactor);
452 #ifdef __AROS__
453 AROS_LIBFUNC_EXIT
454 #endif
457 #ifdef __AROS__
458 static AROS_LH6(LONG, BuffToBuffDecompress,
459 AROS_LHA(APTR, dest, A0),
460 AROS_LHA(ULONG *, destLen, A1),
461 AROS_LHA(APTR, source, A2),
462 AROS_LHA(ULONG, sourceLen, D0),
463 AROS_LHA(LONG, small, D1),
464 AROS_LHA(LONG, verbosity, D2),
465 struct BZ2Base *, libBase, 13, BZlib
468 AROS_LIBFUNC_INIT
469 #else
470 static LONG BZlib_BuffToBuffDecompress(REG(a0, APTR dest), REG(a1, ULONG *destLen),
471 REG(a2, APTR source), REG(d0, ULONG sourceLen), REG(d1, LONG small),
472 REG(d2, LONG verbosity))
474 #endif
475 return BZ2_bzBuffToBuffDecompress(dest, (unsigned int *)destLen, source, sourceLen,
476 small, verbosity);
477 #ifdef __AROS__
478 AROS_LIBFUNC_EXIT
479 #endif
482 void bz_internal_error (int errcode) {
483 Alert(errcode);