[Prophesy] C from Python Example

Rasmus Andersen rasmus at jaquet.dk
Tue Jun 11 15:48:20 EST 2002


On Mon, Jun 10, 2002 at 11:33:18PM +0200, Rasmus Andersen wrote:
> I have before used SWIG (www.swig.org) sucessfully as C/Python integrator.
> The v1.3 (newest, I think) I had on my system choked on some of your
> C constructs, using the attached patch helped.
> 
> Also, I had to use an interface file to get SWIG to grok other stuff.
> Also attached.

Sigh.

Rasmus
-------------- next part --------------
--- transform.c.org	Mon Jun 10 22:25:39 2002
+++ transform.c	Mon Jun 10 23:29:21 2002
@@ -67,7 +67,8 @@
 // should not allow leading 0 for high
 // should trap all invalid opcodes
 // should take ops string limit and check against it
-struct transinfo {int in; int out;} transcheck(uchar *ops)
+struct transinfo {int in; int out;};
+struct transinfo transcheck(uchar *ops)
 {
 	unsigned c, state = 0, count = 0, ilen = 0, olen = 0;
 
@@ -153,7 +154,8 @@
 
 unsigned emit_line, this_line, hold_lines, hold_length, emit_op;
 uchar *emit_text, *this_text, *end_text, *outmem, *output, *outlim;
-struct holdline {char *source; unsigned length;} *holdmem, *hold, *holdlim;
+struct holdline {char *source; unsigned length;};
+struct holdline *holdmem, *hold, *holdlim;
 
 int emit(unsigned op)
 {
-------------- next part --------------
%module foo
%{
#define max(a, b) (a > b? a: b)

#define trace trace_on
#define trace_on(cmd) cmd
#define trace_off(cmd)

#define text_op 0
#define copy_op 1
#define skip_op 2
#define high_op 3

#define text(n) (n | (text_op << 6))
#define copy(n) (n | (copy_op << 6))
#define skip(n) (n | (skip_op << 6))
#define move(n, s) copy(0), copy(s), copy(n)
struct holdline {char *source; unsigned length;};
struct transinfo {int in_org; int out;};

%}

extern int transform(unsigned char *ops, unsigned char *in, unsigned char *out);
extern struct transinfo transcheck(unsigned char *ops);
extern int _next_is(unsigned char c, unsigned char **stringv, unsigned char *limit);
extern int _skip_to(unsigned char c, unsigned char **stringv, unsigned char *limit);
extern void expand(void **pbase, void **plim, void **pcur, unsigned more);
extern int emit(unsigned op);
extern int diff2transform(unsigned char *input, unsigned inlen, unsigned char *string, unsigned length);

extern unsigned emit_line, this_line, hold_lines, hold_length, emit_op;
extern unsigned char *emit_text, *this_text, *end_text, *outmem, *output, *outlim;
extern struct holdline *holdmem, *hold, *holdlim;


More information about the Prophesy mailing list