Initial addition.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4313 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Jonah Beckford 2003-02-15 01:56:34 +00:00
commit 6901abdf17
70 changed files with 9710 additions and 0 deletions

View file

@ -0,0 +1 @@
example_wrap.c

View file

@ -0,0 +1,62 @@
@SET_MAKE@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
SOURCE_DIR = $(top_srcdir)/Examples/chicken/zlib
TOP = ../..
CC = @CC@
CXX = @CXX@
OBJEXT = @OBJEXT@
EXEEXT = @EXEEXT@
SWIG = $(TOP)/../swig$(EXEEXT)
CHICKGEN = example_wrap.$(OBJEXT) csi.$(OBJEXT) precsi.$(OBJEXT) \
oexample.$(OBJEXT)
CHICKSRC = csi.c precsi.c oexample.c
SRCS = $(CHICKGEN)
TARGET = zlib$(EXEEXT)
INCLUDE = -I$(SOURCE_DIR)
LIBS = -lz
SWIGOPT = -prefix zlib -mixed -I/usr/include
all:: $(TARGET)
.SUFFIXES: .cxx
.c.o:
$(CC) $(INCLUDE) $(CFLAGS) -c -o $*.o $<
.cxx.o:
$(CXX) $(INCLUDE) $(CFLAGS) -c -o $*.o $<
csi.c:
$(MAKE) -f $(TOP)/Makefile TARGET='csi.c' \
INTERFACE='precsi' chicken_csi
precsi.c: $(SOURCE_DIR)/precsi.scm
$(MAKE) -f $(TOP)/Makefile TARGET='precsi.c' \
INTERFACE='$<' chicken
example_wrap.c example.scm: $(SOURCE_DIR)/example.i
(test $< -nt example.i && cp -p $< example.i) || echo example.i is up-to-date
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
INCLUDE='$(INCLUDE)' INTERFACE='example.i' chicken_c || \
(echo Did you read the README? && exit 1)
oexample.c: example.scm
$(MAKE) -f $(TOP)/Makefile TARGET='oexample.c' \
INTERFACE='$<' chicken
$(TARGET): $(SRCS)
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \
LIBS='$(LIBS)' INTERFACE='$(INTERFACE)' chicken_static || \
(echo Did you read the README? && exit 1)
clean::
rm -f *_wrap* *.$(OBJEXT) core *~ *.so *.stackdump STACKTRACE
rm -f $(CHICKGEN) $(CHICKSRC)
rm -f example.scm
rm -f $(TARGET)
check:

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,84 @@
/* File : example.i */
%module example
%{
/* Put headers and other declarations here */
#include "zlib.h"
%}
%include typemaps.i
%rename(VERSION) ZLIB_VERSION;
%rename(z_error) zError;
%apply char * { Bytef * };
/* Allow the sourceLen to be automatically filled in from the length
of the 'source' string */
%typemap(chicken,in) (const Bytef *source, uLong sourceLen)
%{ if (!C_swig_is_string ($input)) {
swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Argument $input is not a string");
}
$2 = (uLong) C_header_size ($input);
$1 = C_c_string ($input);
%}
/* Allocate space the size of which is determined by the Scheme
integer argument, and make a temporary integer so we can set
destLen. */
%typemap(chicken,in) (Bytef *dest, uLongf *destLen) (uLong len)
%{ if (!C_swig_is_fixnum ($input)) {
swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Argument $input is not a integer");
}
len = (uLong) C_unfix ($input);
$2 = &len;
$1 = (char *) malloc (*$2);
%}
/* Return the mutated string as a new object. Notice the if MANY construct ... they must be at column 0. */
%typemap(chicken,argout,fragment="list_output_helper",chicken_words="0") (Bytef *dest, uLongf *destLen)
(C_word *scmstr)
%{ scmstr = C_alloc (C_SIZEOF_STRING (*$2));
/*if MANY*/
$result = list_output_helper (&known_space, $result, C_string (&scmstr, *$2, $1));
/*else*/
$result = C_string (&scmstr, *$2, $1);
/*endif*/
free ($1);
%}
%include "zconf.h"
%include "zlib.h"
/* Ignore destLen as an input argument, and make a temporary integer so
we can set destLen. */
%typemap(in, numinputs=0) uLongf *destLen (uLong len)
"$1 = &len;";
/* Return a sized string as a new object. */
%typemap(chicken,argout,fragment="list_output_helper",chicken_words="0")
(void *outstr, uLongf *destLen) (C_word *scmstr)
%{ scmstr = C_alloc (C_SIZEOF_STRING (*$2));
/*if MANY*/
$result = list_output_helper (&known_space, $result, C_string (&scmstr, *$2, $1));
/*else*/
$result = C_string (&scmstr, *$2, $1);
/*endif*/
%}
%inline %{
/* %inline blocks are seen by SWIG and are inserted into the header
portion of example_wrap.c, so that they are also seen by the C
compiler. */
int deflate_init(z_streamp strm, int level) {
return deflateInit(strm,level); /* call macro */
}
int inflate_init(z_streamp strm) {
return inflateInit(strm); /* call macro */
}
void* z_stream_save_next_out(z_streamp strm) {
return (void*) strm->next_out;
}
void z_stream_get_next_chunk(z_streamp strm, void *outstr, uLongf *destLen) {
*destLen = strm->next_out - (Bytef*)outstr;
}
%}

View file

@ -0,0 +1,123 @@
(declare (unit precsi))
(declare (uses example))
;; display prelude to csi
(display "zlib\n\n")
(display " A SWIG example for the CHICKEN compiler\n")
(display " Author: Jonah Beckford, February 2003\n\n")
(display "Scheme Procedures:\n")
(display "
zlib-max-mem-level
zlib-max-wbits
zlib-seek-set
zlib-seek-cur
zlib-seek-end
zlib-version
zlib-z-stream-next-in-set
zlib-z-stream-next-in-get
zlib-z-stream-avail-in-set
zlib-z-stream-avail-in-get
zlib-z-stream-total-in-set
zlib-z-stream-total-in-get
zlib-z-stream-next-out-set
zlib-z-stream-next-out-get
zlib-z-stream-avail-out-set
zlib-z-stream-avail-out-get
zlib-z-stream-total-out-set
zlib-z-stream-total-out-get
zlib-z-stream-msg-set
zlib-z-stream-msg-get
zlib-z-stream-state-set
zlib-z-stream-state-get
zlib-z-stream-zalloc-set
zlib-z-stream-zalloc-get
zlib-z-stream-zfree-set
zlib-z-stream-zfree-get
zlib-z-stream-opaque-set
zlib-z-stream-opaque-get
zlib-z-stream-data-type-set
zlib-z-stream-data-type-get
zlib-z-stream-adler-set
zlib-z-stream-adler-get
zlib-z-stream-reserved-set
zlib-z-stream-reserved-get
zlib-new-z-stream
zlib-delete-z-stream
zlib-z-no-flush
zlib-z-partial-flush
zlib-z-sync-flush
zlib-z-full-flush
zlib-z-finish
zlib-z-ok
zlib-z-stream-end
zlib-z-need-dict
zlib-z-errno
zlib-z-stream-error
zlib-z-data-error
zlib-z-mem-error
zlib-z-buf-error
zlib-z-version-error
zlib-z-no-compression
zlib-z-best-speed
zlib-z-best-compression
zlib-z-default-compression
zlib-z-filtered
zlib-z-huffman-only
zlib-z-default-strategy
zlib-z-binary
zlib-z-ascii
zlib-z-unknown
zlib-z-deflated
zlib-z-null
zlib-version
zlib-deflate
zlib-deflate-end
zlib-inflate
zlib-inflate-end
zlib-deflate-set-dictionary
zlib-deflate-copy
zlib-deflate-reset
zlib-deflate-params
zlib-inflate-set-dictionary
zlib-inflate-sync
zlib-inflate-reset
zlib-compress
zlib-compress2
zlib-uncompress
zlib-gzopen
zlib-gzdopen
zlib-gzsetparams
zlib-gzread
zlib-gzwrite
zlib-gzprintf
zlib-gzputs
zlib-gzgets
zlib-gzputc
zlib-gzgetc
zlib-gzflush
zlib-gzseek
zlib-gzrewind
zlib-gztell
zlib-gzeof
zlib-gzclose
zlib-gzerror
zlib-adler32
zlib-crc32
zlib-deflate-init-
zlib-inflate-init-
zlib-deflate-init2-
zlib-inflate-init2-
zlib-internal-state-dummy-set
zlib-internal-state-dummy-get
zlib-new-internal-state
zlib-delete-internal-state
zlib-z-error
zlib-inflate-sync-point
zlib-get-crc-table
zlib-deflate-init
zlib-inflate-init
zlib-z-stream-save-next-out
zlib-z-stream-get-next-chunk
")

View file

@ -0,0 +1,42 @@
;; run with './zlib test-zlib.scm'
;; Init zstream
(define s (zlib-new-z-stream))
(zlib-z-stream-zalloc-set s #f)
(zlib-z-stream-zfree-set s #f)
(zlib-z-stream-opaque-set s #f)
(zlib-deflate-init s (zlib-z-default-compression))
;; Deflate something small so we don't need to loop/stream data
(define in "some pony et jumping et jack et flash et had a jack pony")
(define out (make-string 1000))
(format #t "to be compressed: ~A~%to be compressed bytes: ~D~%~%" in (string-length in))
(zlib-z-stream-next-in-set s in)
(zlib-z-stream-avail-in-set s (string-length in))
(zlib-z-stream-next-out-set s out)
(zlib-z-stream-avail-out-set s (string-length out))
(let*
((saved-out (zlib-z-stream-save-next-out s))
(ret (zlib-deflate s (zlib-z-finish))))
(cond
((= ret (zlib-z-stream-end))
(format #t "deflated properly!~%compressed bytes: ~D~%compressed stream: ~S~%"
(zlib-z-stream-total-out-get s) (zlib-z-stream-get-next-chunk s saved-out)))
((= ret (zlib-z-ok))
(display "only partial deflation ... not enough output space\n"))
(else
(format #t "deflate error(~D): ~A ~%" ret (zlib-z-stream-msg-get s)))))
;; Use simple compress routine, and set max output size to 100
(define c (zlib-compress 100 in))
(newline)
(let
((ret (car c))
(compressed (cadr c)))
(cond
((= ret (zlib-z-ok))
(format #t "compressed properly!~%compressed bytes: ~D~%compressed stream: ~S~%"
(string-length compressed) compressed))
(else
(format #t "compress error(~D): ~A ~%" ret (zlib-z-error ret)))))