~ubuntu-branches/ubuntu/utopic/critcl/utopic

« back to all changes in this revision

Viewing changes to examples/zlibwrap/zlib.tcl

  • Committer: Package Import Robot
  • Author(s): Andrew Shadura
  • Date: 2013-05-11 00:08:06 UTC
  • Revision ID: package-import@ubuntu.com-20130511000806-7hq1zc3fnn0gat79
Tags: upstream-3.1.9
ImportĀ upstreamĀ versionĀ 3.1.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# zlib.tcl --
 
2
#
 
3
#       Low-level wrapper around libz, making it a Tcl package.
 
4
#
 
5
# Copyright (c) 2011 Andreas Kupries <andreas_kupries@users.sourceforge.net>
 
6
 
 
7
# Example of exporting a C-level stubs API through critcl v3, linking
 
8
# against an external library and/or baking in the library using its sources.
 
9
 
 
10
# # ## ### ##### ######## ############# #####################
 
11
## Requirements
 
12
 
 
13
package require Tcl 8.4
 
14
package require critcl 3 ;# stubs management
 
15
 
 
16
# # ## ### ##### ######## ############# #####################
 
17
## Administrivia
 
18
 
 
19
critcl::license {Andreas Kupries} BSD
 
20
 
 
21
critcl::summary {A C-level wrapper of the zlib compression library}
 
22
critcl::description {
 
23
    This package wraps around zlib, making its
 
24
    C-level functions available as Tcl package,
 
25
    with stubs. No Tcl-binding is provided.
 
26
}
 
27
 
 
28
critcl::subject gzip zip zlib libz
 
29
critcl::subject compression {data compression}
 
30
critcl::subject decompression {data decompression}
 
31
 
 
32
# # ## ### ##### ######## ############# #####################
 
33
## Configuration
 
34
 
 
35
critcl::userconfig define mode {
 
36
    choose the zlib to build and link against.
 
37
} {
 
38
    system
 
39
    system-static
 
40
    local
 
41
}
 
42
 
 
43
# # ## ### ##### ######## ############# #####################
 
44
## Exported API
 
45
 
 
46
critcl::api scspec ZEXTERN
 
47
 
 
48
# # ## ### ##### ######## ############# #####################
 
49
##  Misc. interfaces
 
50
 
 
51
critcl::api function {const char *} zlibVersion {}
 
52
critcl::api function {const char *} zError      {int err}
 
53
 
 
54
critcl::api function uLong crc32 {
 
55
    uLong crc
 
56
    {const Bytef *} buf
 
57
    uInt len
 
58
}
 
59
 
 
60
critcl::api function uLong adler32 {
 
61
    uLong adler
 
62
    {const Bytef *} buf
 
63
    uInt len
 
64
}
 
65
 
 
66
# # ## ### ##### ######## ############# #####################
 
67
##  Deflate = Compression
 
68
 
 
69
critcl::api function int deflateInit_ {
 
70
    z_streamp      stream
 
71
    int            level
 
72
    {const char *} version
 
73
    int            stream_size
 
74
}
 
75
 
 
76
critcl::api function int deflateInit2_ {
 
77
    z_streamp stream
 
78
    int            level
 
79
    int            method
 
80
    int            windowBits
 
81
    int            memLevel
 
82
    int            strategy
 
83
    {const char *} version
 
84
    int            stream_size
 
85
}
 
86
 
 
87
critcl::api function int deflate {
 
88
    z_streamp stream
 
89
    int       flush
 
90
}
 
91
 
 
92
critcl::api function int deflateEnd {
 
93
    z_streamp stream
 
94
}
 
95
 
 
96
critcl::api function int deflateSetDictionary {
 
97
    z_streamp       stream
 
98
    {const Bytef *} dict
 
99
    uInt            dictLength
 
100
}
 
101
 
 
102
critcl::api function int deflateCopy {
 
103
    z_streamp dst
 
104
    z_streamp src
 
105
}
 
106
 
 
107
critcl::api function int deflateReset {
 
108
    z_streamp stream
 
109
}
 
110
 
 
111
critcl::api function int deflateParams {
 
112
    z_streamp stream
 
113
    int       level
 
114
    int       strategy
 
115
}
 
116
 
 
117
# # ## ### ##### ######## ############# #####################
 
118
##
 
119
 
 
120
critcl::api function int compress {
 
121
    {Bytef *}       dest
 
122
    {uLongf *}      destLen
 
123
    {const Bytef *} source
 
124
    uLong           sourceLen
 
125
}
 
126
 
 
127
critcl::api function int compress2 {
 
128
    {Bytef *}       dest
 
129
    {uLongf *}      destLen
 
130
    {const Bytef *} source
 
131
    uLong           sourceLen
 
132
    int             level
 
133
}
 
134
 
 
135
# # ## ### ##### ######## ############# #####################
 
136
##  Inflate = Decompression
 
137
 
 
138
critcl::api function int inflateInit_ {
 
139
    z_streamp      stream
 
140
    {const char *} version
 
141
    int            stream_size
 
142
}
 
143
 
 
144
critcl::api function int inflateInit2_ {
 
145
    z_streamp      stream
 
146
    int            windowBits
 
147
    {const char *} version
 
148
    int            stream_size
 
149
}
 
150
 
 
151
critcl::api function int inflate {
 
152
    z_streamp stream
 
153
    int       flush
 
154
}
 
155
 
 
156
critcl::api function int inflateEnd {
 
157
    z_streamp stream
 
158
}
 
159
 
 
160
critcl::api function int inflateSetDictionary {
 
161
    z_streamp       stream
 
162
    {const Bytef *} dict
 
163
    uInt            dictLength
 
164
}
 
165
 
 
166
critcl::api function int inflateSync  {z_streamp stream}
 
167
critcl::api function int inflateReset {z_streamp stream}
 
168
 
 
169
# # ## ### ##### ######## ############# #####################
 
170
##
 
171
 
 
172
critcl::api function int uncompress {
 
173
    {Bytef *}       dest
 
174
    {uLongf *}      destLen
 
175
    {const Bytef *} source
 
176
    uLong           sourceLen
 
177
}
 
178
 
 
179
# # ## ### ##### ######## ############# #####################
 
180
## gz'ip layer
 
181
 
 
182
critcl::api function gzFile gzopen {
 
183
    {const char *} path
 
184
    {const char *} mode
 
185
}
 
186
 
 
187
critcl::api function gzFile gzdopen {
 
188
    int            fd
 
189
    {const char *} mode
 
190
}
 
191
 
 
192
critcl::api function int gzsetparams {
 
193
    gzFile file
 
194
    int    level
 
195
    int    strategy
 
196
}
 
197
 
 
198
critcl::api function int gzread {
 
199
    gzFile   file
 
200
    voidp    buf
 
201
    unsigned len
 
202
}
 
203
 
 
204
critcl::api function int gzwrite {
 
205
    gzFile   file
 
206
    voidpc   buf
 
207
    unsigned len
 
208
}
 
209
 
 
210
critcl::api function int gzprintf {
 
211
    gzFile file
 
212
    {const char *} format
 
213
    ...
 
214
}
 
215
 
 
216
critcl::api function int gzputs {
 
217
    gzFile         file
 
218
    {const char *} s
 
219
}
 
220
 
 
221
critcl::api function {char *} gzgets {
 
222
    gzFile   file
 
223
    {char *} buf
 
224
    int      len
 
225
}
 
226
 
 
227
critcl::api function int gzputc {
 
228
    gzFile file
 
229
    int    c
 
230
}
 
231
 
 
232
critcl::api function int gzgetc {
 
233
    gzFile file
 
234
}
 
235
 
 
236
critcl::api function int gzflush {
 
237
    gzFile file
 
238
    int    flush
 
239
}
 
240
 
 
241
critcl::api function z_off_t gzseek {
 
242
    gzFile   file
 
243
    z_off_t offset
 
244
    int     whence
 
245
}
 
246
 
 
247
critcl::api function int     gzrewind {gzFile file}
 
248
critcl::api function z_off_t gztell   {gzFile file}
 
249
critcl::api function int     gzeof    {gzFile file}
 
250
critcl::api function int     gzclose  {gzFile file}
 
251
 
 
252
critcl::api function {const char *} gzerror {
 
253
    gzFile  file
 
254
    {int *} errnum
 
255
}
 
256
 
 
257
# # ## ### ##### ######## ############# #####################
 
258
## Implementation.
 
259
 
 
260
namespace eval ::zlib {}
 
261
 
 
262
# Export zlib version number. Together with the 'variant' (see below),
 
263
# we know what this package is an interface to.
 
264
critcl::cproc ::zlib::version {} vstring {
 
265
    return zlibVersion ();
 
266
}
 
267
 
 
268
critcl::cdata ::zlib::variant [critcl::userconfig query mode]
 
269
critcl::msg -nonewline " /[critcl::userconfig query mode]"
 
270
 
 
271
switch -exact -- [critcl::userconfig query mode] {
 
272
    local {
 
273
        # Build against the local z/lib/z sources.
 
274
        critcl::api header zlib/zconf.h
 
275
        critcl::api header zlib/zlib.h
 
276
 
 
277
        critcl::cheaders zlib/*.h
 
278
        critcl::csources zlib/adler32.c
 
279
        critcl::csources zlib/compress.c
 
280
        critcl::csources zlib/crc32.c
 
281
        critcl::csources zlib/deflate.c
 
282
        critcl::csources zlib/gzclose.c
 
283
        critcl::csources zlib/gzlib.c
 
284
        critcl::csources zlib/gzread.c
 
285
        critcl::csources zlib/gzwrite.c
 
286
        critcl::csources zlib/infback.c
 
287
        critcl::csources zlib/inffast.c
 
288
        critcl::csources zlib/inflate.c
 
289
        critcl::csources zlib/inftrees.c
 
290
        critcl::csources zlib/trees.c
 
291
        critcl::csources zlib/uncompr.c
 
292
        critcl::csources zlib/zutil.c
 
293
    }
 
294
    system {
 
295
        # Build against system z/lib/z
 
296
 
 
297
        critcl::api extheader zconf.h
 
298
        critcl::api extheader zlib.h
 
299
 
 
300
        critcl::clibraries -lz
 
301
    }
 
302
    system-static {
 
303
        # Build against system z/lib/z, statically
 
304
 
 
305
        critcl::api extheader zconf.h
 
306
        critcl::api extheader zlib.h
 
307
 
 
308
        set ok 0
 
309
        foreach p {
 
310
            /lib
 
311
            /usr/lib
 
312
            /usr/local/lib
 
313
        } {
 
314
            if {![file exists $p/libz.a]} continue
 
315
            critcl::clibraries $p/libz.a
 
316
            set ok 1
 
317
            break
 
318
        }
 
319
        if {!$ok} {
 
320
            critcl::error "Unable to find static libz.a"
 
321
        }
 
322
    }
 
323
}
 
324
 
 
325
# ### ### ### ######### ######### #########
 
326
## Ready
 
327
package provide zlib 1 ; # for libz 1.2.5