Debian Codegraph @

ext/zlib/gauche-zlib.h

raw
1 /*
2 * Gauche-zlib - zlib module
3 *
4 * Copyright (c) 2006 Rui Ueyama, All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * 3. Neither the name of the authors nor the names of its contributors
18 * may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
27 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 /* Prologue */
35 #ifndef GAUCHE_ZLIB_H
36 #define GAUCHE_ZLIB_H
37
38 #include <gauche.h>
39 #include <gauche/extend.h>
40 #include <zlib.h>
41
42 #if defined(EXTZLIB_EXPORTS)
43 #define LIBGAUCHE_EXT_BODY
44 #endif
45 #include <gauche/extern.h> /* redefine SCM_EXTERN */
46
47
48 SCM_DECL_BEGIN
49
50 typedef struct ScmZlibInfoRec {
51 z_streamp strm;
52 ScmPort *remote; /* source or drain port */
53 int ownerp;
54 int flush;
55 int stream_endp;
56 ScmSize bufsiz;
57 char *buf;
58 char *ptr;
59 unsigned char *dict;
60 ScmSize dictlen;
61 int level;
62 int strategy;
63 ScmObj dict_adler;
64 } ScmZlibInfo;
65
66 #define SCM_PORT_ZLIB_INFO(p) ((ScmZlibInfo*)Scm_PortBufferStruct(p)->data)
67 #define SCM_PORT_ZSTREAM(p) (SCM_PORT_ZLIB_INFO(p)->strm)
68
69 SCM_CLASS_DECL(Scm_DeflatingPortClass);
70 #define SCM_CLASS_DEFLATING_PORT (&Scm_DeflatingPortClass)
71 #define SCM_DEFLATING_PORT_P(obj) SCM_ISA(obj, SCM_CLASS_DEFLATING_PORT)
72 SCM_CLASS_DECL(Scm_InflatingPortClass);
73 #define SCM_CLASS_INFLATING_PORT (&Scm_InflatingPortClass)
74 #define SCM_INFLATING_PORT_P(obj) SCM_ISA(obj, SCM_CLASS_INFLATING_PORT)
75
76 extern ScmObj Scm_MakeDeflatingPort(ScmPort *source, int level,
77 int window_bits, int memlevel,
78 int strategy, ScmObj dict,
79 ScmSize bufsiz, int ownerp);
80 extern ScmObj Scm_MakeInflatingPort(ScmPort *sink, ScmSize bufsiz,
81 int window_bits, ScmObj dict,
82 int ownerp);
83
84 /*================================================================
85 * Conditions
86 */
87
88 typedef ScmError ScmZlibError;
89
90 SCM_CLASS_DECL(Scm_ZlibErrorClass);
91 #define SCM_CLASS_ZLIB_ERROR (&Scm_ZlibErrorClass)
92 #define SCM_ZLIB_ERROR(obj) ((ScmZlibError*)(obj))
93 #define SCM_ZLIB_ERRORP(obj) SCM_ISA(obj, SCM_CLASS_ZLIB_ERROR)
94
95 typedef ScmZlibError ScmZlibNeedDictError;
96 SCM_CLASS_DECL(Scm_ZlibNeedDictErrorClass);
97 #define SCM_CLASS_ZLIB_NEED_DICT_ERROR (&Scm_ZlibNeedDictErrorClass)
98 #define SCM_ZLIB_NEED_DICT_ERROR(obj) ((ScmZlibNeedDictError*)(obj))
99 #define SCM_ZLIB_NEED_DICT_ERRORP(obj) SCM_ISA(obj, SCM_CLASS_ZLIB_NEED_DICT_ERROR)
100
101 typedef ScmZlibError ScmZlibStreamError;
102 SCM_CLASS_DECL(Scm_ZlibStreamErrorClass);
103 #define SCM_CLASS_ZLIB_STREAM_ERROR (&Scm_ZlibStreamErrorClass)
104 #define SCM_ZLIB_STREAM_ERROR(obj) ((ScmZlibStreamError*)(obj))
105 #define SCM_ZLIB_STREAM_ERRORP(obj) SCM_ISA(obj, SCM_CLASS_ZLIB_STREAM_ERROR)
106
107 typedef ScmZlibError ScmZlibDataError;
108 SCM_CLASS_DECL(Scm_ZlibDataErrorClass);
109 #define SCM_CLASS_ZLIB_DATA_ERROR (&Scm_ZlibDataErrorClass)
110 #define SCM_ZLIB_DATA_ERROR(obj) ((ScmZlibDataError*)(obj))
111 #define SCM_ZLIB_DATA_ERRORP(obj) SCM_ISA(obj, SCM_CLASS_ZLIB_DATA_ERROR)
112
113 typedef ScmZlibError ScmZlibMemoryError;
114 SCM_CLASS_DECL(Scm_ZlibMemoryErrorClass);
115 #define SCM_CLASS_ZLIB_MEMORY_ERROR (&Scm_ZlibMemoryErrorClass)
116 #define SCM_ZLIB_MEMORY_ERROR(obj) ((ScmZlibMemoryError*)(obj))
117 #define SCM_ZLIB_MEMORY_ERRORP(obj) SCM_ISA(obj, SCM_CLASS_ZLIB_MEMORY_ERROR)
118
119 typedef ScmZlibError ScmZlibVersionError;
120 SCM_CLASS_DECL(Scm_ZlibVersionErrorClass);
121 #define SCM_CLASS_ZLIB_VERSION_ERROR (&Scm_ZlibVersionErrorClass)
122 #define SCM_ZLIB_VERSION_ERROR(obj) ((ScmZlibVersionError*)(obj))
123 #define SCM_ZLIB_VERSION_ERRORP(obj) SCM_ISA(obj, SCM_CLASS_ZLIB_VERSION_ERROR)
124
125 extern ScmObj Scm_MakeZlibError(ScmObj message, int error_code);
126 extern void Scm_ZlibError(int error_code, const char *msg, ...);
127 extern ScmObj Scm_InflateSync(ScmPort *port);
128
129 extern void Scm_Init_zlib(void);
130
131 /* Epilogue */
132 SCM_DECL_END
133
134 #endif /* GAUCHE_ZLIB_H */