From 0990dbd863d8ca57a41aea44318ae43a7a604b7c Mon Sep 17 00:00:00 2001 From: "tg(x)" <*@tg-x.net> Date: Mon, 12 Sep 2011 11:44:48 +0200 Subject: [PATCH] some swig code, needs more work --- .gitignore | 8 ++++++++ perl/Makefile | 25 +++++++++++++++++++++++++ perl/psyc.i | 42 ++++++++++++++++++++++++++++++++++++++++++ python/Makefile | 24 ++++++++++++++++++++++++ python/psyc.i | 1 + 5 files changed, 100 insertions(+) create mode 100644 perl/Makefile create mode 100644 perl/psyc.i create mode 100644 python/Makefile create mode 120000 python/psyc.i diff --git a/.gitignore b/.gitignore index b6b2544..5f4516d 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,14 @@ test/testText test/isRoutingVar test/getVarType +perl/*.c +perl/*.so +perl/*.pm + +python/*.c +python/*.so +python/*.py + .config ~$* .DS_Store diff --git a/perl/Makefile b/perl/Makefile new file mode 100644 index 0000000..638b883 --- /dev/null +++ b/perl/Makefile @@ -0,0 +1,25 @@ +CFLAGS = -I../include -Wall -std=c99 -fPIC +SWIG = swig +PERL = perl + +I = psyc.i +S = psyc_wrap.c +O = psyc_wrap.o +SO = PSYC.so +PM = PSYC.pm +PSYCO = ../src/packet.o ../src/parse.o ../src/match.o ../src/render.o ../src/memmem.o ../src/itoa.o ../src/variable.o ../src/text.o + +all: swig lib + +swig: + ${SWIG} -I../include -perl5 $I + +CFLAGS = ${CFLAGS_COMMON} $(shell ${PERL} -MConfig -e 'print join(" ", @Config{qw(ccflags optimize cccdlflags)}, "-I$$Config{archlib}/CORE")') -D_XOPEN_SOURCE +$O: $S + +lib: $O + ${MAKE} -C ../src ${PSYCO} + ${CC} ${CFLAGS} $(shell ${PERL} -MConfig -e 'print $$Config{lddlflags}') ${PSYCO} $O -o ${SO} + +clean: + rm -f $S $O ${SO} ${PM} diff --git a/perl/psyc.i b/perl/psyc.i new file mode 100644 index 0000000..5906435 --- /dev/null +++ b/perl/psyc.i @@ -0,0 +1,42 @@ + %module PSYC + %{ + /* Includes the headers in the wrapper code */ + #include "psyc.h" + #include "psyc/packet.h" + #include "psyc/parse.h" + #include "psyc/render.h" + #include "psyc/syntax.h" + #include "psyc/text.h" + %} + +/* Parse the headers to generate wrappers */ +%include "cdata.i" + +%rename("%(regex:/^PSYC_(.*)/\\1/)s") ""; +%rename("%(regex:/^psyc_?(.*)/\\1/)s") ""; +%rename("%(regex:/^psyc_(.*)2$/\\1/)s") ""; + +%apply (char *STRING, size_t LENGTH) { (const char *buffer, size_t length) }; +%apply (char *STRING, size_t LENGTH) { (const char *name, size_t len) }; +%apply (char *STRING, size_t LENGTH) { (const char *value, size_t len) }; + +// initTextState +%apply (char *STRING, size_t LENGTH) { (char *template, size_t tlen) }; +%apply (char *STRING, size_t LENGTH) { (char *buffer, size_t blen) }; +// setTextBrackets +%apply (char *STRING, size_t LENGTH) { (char *open, size_t openlen) }; +%apply (char *STRING, size_t LENGTH) { (char *close, size_t closelen) }; + +//%apply (char *STRING, size_t LENGTH) { }; + +psycParseRC psyc_parse2 (psycParseState *state, char *oper, + char *name, size_t namelen, + char *value, size_t valuelen); + + +%include "psyc.h" +%include "psyc/packet.h" +%include "psyc/parse.h" +%include "psyc/render.h" +%include "psyc/syntax.h" +%include "psyc/text.h" diff --git a/python/Makefile b/python/Makefile new file mode 100644 index 0000000..f223c93 --- /dev/null +++ b/python/Makefile @@ -0,0 +1,24 @@ +CFLAGS = -Wall -std=c99 -fPIC -I../include $(shell ${PYTHON_CONFIG} --includes) +SWIG = swig +PYTHON_CONFIG = python-config + +I = psyc.i +S = psyc_wrap.c +O = psyc_wrap.o +SO = _PSYC.so +PY = PSYC.py +PSYCO = ../src/packet.o ../src/parse.o ../src/match.o ../src/render.o ../src/memmem.o ../src/itoa.o ../src/variable.o ../src/text.o + +all: swig lib + +swig: + ${SWIG} -I../include -python $I + +$O: $S + +lib: $O + ${MAKE} -C ../src ${PSYCO} + ${CC} -shared ${PSYCO} $O -o ${SO} + +clean: + rm -f $S $O ${SO} ${PY} ${PY}c diff --git a/python/psyc.i b/python/psyc.i new file mode 120000 index 0000000..327cba2 --- /dev/null +++ b/python/psyc.i @@ -0,0 +1 @@ +../perl/psyc.i \ No newline at end of file