Initial revision, contributed by Klaus Wiederaenders.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@997 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Thien-Thi Nguyen 2001-01-17 02:04:48 +00:00
commit 73c222a8c6
18 changed files with 1156 additions and 0 deletions

54
Examples/xml/Makefile.in Normal file
View file

@ -0,0 +1,54 @@
# Examples/xml/Makefile
top_srcdir = @top_srcdir@
cleanup = tail +2 \
| sed -e 's/ident="ID[0-9A-F]*"//g' \
-e 's,name="/[^"]*/\([^/]*\.swg\)",name="\1",g'
all-dot-i-files = \
error.i \
example.i \
example_apply.i \
example_const.i \
example_gif.i \
example_inl.i \
example_p5.i \
example_ro.i \
example_title_add.i \
example_xml.i \
gnarly.i
all: check
chk-swiglib = $(top_srcdir)/Lib
check:
for f in $(all-dot-i-files) ; do \
base=`basename $$f .i` ; \
xml=$$base.xml ; \
SWIG_LIB=$(chk-swiglib) $(top_srcdir)/swig -xml $$xml $$f ; \
cat $$xml | $(cleanup) | diff -c $$base.expected-xml - ; \
done
clean:
rm -f *.xml
distclean: clean
rm -f Makefile
# from here on, non-developers beware!
%.expected-xml : %.i
SWIG_LIB=$(top_srcdir)/Lib $(top_srcdir)/swig -xml tmp-file $^
cat tmp-file | $(cleanup) > $@
rm -f tmp-file
all-expected-xml:
for f in $(all-dot-i-files) ; do \
make `basename $$f .i`.expected-xml ; done
all-expected-xml-clean:
rm -f *.expected-xml
# Examples/xml/Makefile ends here

2
Examples/xml/error.i Normal file
View file

@ -0,0 +1,2 @@
%module error
enum { RED=10, GREEN, BLUE };

3
Examples/xml/example.h Normal file
View file

@ -0,0 +1,3 @@
// i add this file because it's referenced by other files.
// someone should replace these comments w/ proper content.
// --ttn, 2001/01/16 17:44:19

8
Examples/xml/example.i Normal file
View file

@ -0,0 +1,8 @@
/* File : example.i */
%module example
%apply int *OUTPUT { int *r };

View file

@ -0,0 +1,23 @@
/* File : example.i */
%module example
/* This example illustrates a couple of different techniques
for manipulating C pointers */
/* First we'll use the pointer library */
extern void add(int *x, int *y, int *result);
%include pointer.i
/* Next we'll use some typemaps */
%include typemaps.i
extern void sub(int *INPUT, int *INPUT, int *OUTPUT);
/* Next we'll use typemaps and the %apply directive */
%apply int *OUTPUT { int *r };
extern int divide(int n, int d, int *r);

View file

@ -0,0 +1,26 @@
/* File : example.i */
%module example
/* A few preprocessor macros */
#define ICONST 42
#define FCONST 2.1828
#define CCONST 'x'
#define CCONST2 '\n'
#define SCONST "Hello World"
#define SCONST2 "\"Hello World\""
/* This should work just fine */
#define EXPR ICONST + 3*(FCONST)
/* This shouldn't do anything */
#define EXTERN extern
/* Neither should this (BAR isn't defined) */
#define FOO (ICONST + BAR)
/* The following statements also produce constants */
const int iconst = 37;
const double fconst = 3.14;

329
Examples/xml/example_gif.i Normal file
View file

@ -0,0 +1,329 @@
/* -----------------------------------------------------------------------------
* gifplot.h
*
* Main header file for the GIFPlot library.
*
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
* Copyright (C) 1995-1996
*
* See the file LICENSE for information on usage and redistribution.
* ----------------------------------------------------------------------------- */
#include <stdio.h>
#include <fcntl.h>
#include <float.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#ifndef GIFPLOT_H
/* Pixel is 8-bits */
typedef unsigned char Pixel;
typedef float Zvalue;
/* ------------------------------------------------------------------------
ColorMap
Definition and methods for colormaps
------------------------------------------------------------------------ */
typedef struct ColorMap {
unsigned char *cmap;
char *name;
} ColorMap;
extern ColorMap *new_ColorMap(char *filename);
extern void delete_ColorMap(ColorMap *c);
extern void ColorMap_default(ColorMap *c);
extern void ColorMap_assign(ColorMap *c, int index, int r, int g, int b);
extern int ColorMap_getitem(ColorMap *c, int index);
extern void ColorMap_setitem(ColorMap *c, int index, int value);
extern int ColorMap_write(ColorMap *c, char *filename);
/* Some default colors */
#define BLACK 0
#define WHITE 1
#define RED 2
#define GREEN 3
#define BLUE 4
#define YELLOW 5
#define CYAN 6
#define MAGENTA 7
/*-------------------------------------------------------------------------
FrameBuffer
This structure defines a simple 8 bit framebuffer.
------------------------------------------------------------------------- */
typedef struct FrameBuffer {
Pixel **pixels;
Zvalue **zbuffer;
unsigned int height;
unsigned int width;
int xmin; /* These are used for clipping */
int ymin;
int xmax;
int ymax;
} FrameBuffer;
#define ZMIN 1e+36
/* FrameBuffer Methods */
extern FrameBuffer *new_FrameBuffer(unsigned int width, unsigned int height);
extern void delete_FrameBuffer(FrameBuffer *frame);
extern int FrameBuffer_resize(FrameBuffer *frame, int width, int height);
extern void FrameBuffer_clear(FrameBuffer *frame, Pixel color);
extern void FrameBuffer_plot(FrameBuffer *frame, int x, int y, Pixel color);
extern void FrameBuffer_horizontal(FrameBuffer *frame, int xmin, int xmax, int y, Pixel color);
extern void FrameBuffer_horizontalinterp(FrameBuffer *f, int xmin, int xmax, int y, Pixel c1, Pixel c2);
extern void FrameBuffer_vertical(FrameBuffer *frame, int ymin, int ymax, int x, Pixel color);
extern void FrameBuffer_box(FrameBuffer *frame, int x1, int y1, int x2, int y2, Pixel color);
extern void FrameBuffer_solidbox(FrameBuffer *frame, int x1, int y1, int x2, int y2, Pixel color);
extern void FrameBuffer_interpbox(FrameBuffer *f, int x1, int y1, int x2, int y2, Pixel c1, Pixel c2, Pixel c3, Pixel c4);
extern void FrameBuffer_circle(FrameBuffer *frame, int x1, int y1, int radius, Pixel color);
extern void FrameBuffer_solidcircle(FrameBuffer *frame, int x1, int y1, int radius, Pixel color);
extern void FrameBuffer_line(FrameBuffer *frame, int x1, int y1, int x2, int y2, Pixel color);
extern void FrameBuffer_setclip(FrameBuffer *frame, int xmin, int ymin, int xmax, int ymax);
extern void FrameBuffer_noclip(FrameBuffer *frame);
extern int FrameBuffer_makeGIF(FrameBuffer *frame, ColorMap *cmap, void *buffer, unsigned int maxsize);
extern int FrameBuffer_writeGIF(FrameBuffer *f, ColorMap *c, char *filename);
extern void FrameBuffer_zresize(FrameBuffer *f, int width, int height);
extern void FrameBuffer_zclear(FrameBuffer *f);
extern void FrameBuffer_solidtriangle(FrameBuffer *f, int x1, int y1, int x2, int y2, int x3, int y3, Pixel c);
extern void FrameBuffer_interptriangle(FrameBuffer *f, int tx1, int ty1, Pixel c1,
int tx2, int ty2, Pixel c2, int tx3, int ty3, Pixel c3);
#define HORIZONTAL 1
#define VERTICAL 2
extern void FrameBuffer_drawchar(FrameBuffer *frame, int x, int y, int fgcolor, int bgcolor, char chr, int orientation);
extern void FrameBuffer_drawstring(FrameBuffer *f, int x, int y, int fgcolor, int bgcolor, char *text, int orientation);
/* ------------------------------------------------------------------------
PixMap
The equivalent of "bit-maps".
------------------------------------------------------------------------ */
typedef struct PixMap {
int width;
int height;
int centerx;
int centery;
int *map;
} PixMap;
/* PIXMAP methods */
extern PixMap *new_PixMap(int width, int height, int centerx, int centery);
extern void delete_PixMap(PixMap *pm);
extern void PixMap_set(PixMap *pm, int x, int y, int pix);
extern void FrameBuffer_drawpixmap(FrameBuffer *f, PixMap *pm, int x, int y, int fgcolor, int bgcolor);
#define TRANSPARENT 0
#define FOREGROUND 1
#define BACKGROUND 2
/* ------------------------------------------------------------------------
Plot2D
Definition and methods for 2D plots.
------------------------------------------------------------------------ */
typedef struct Plot2D {
FrameBuffer *frame; /* what frame buffer are we using */
int view_xmin; /* Minimum coordinates of view region */
int view_ymin;
int view_xmax; /* Maximum coordinates of view region */
int view_ymax;
double xmin; /* Minimum coordinates of plot region */
double ymin;
double xmax; /* Maximum coordinates of plot region */
double ymax;
int xscale; /* Type of scaling (LINEAR, LOG, etc..) */
int yscale;
double dx; /* Private scaling parameters */
double dy;
} Plot2D;
/* 2D Plot methods */
extern Plot2D *new_Plot2D(FrameBuffer *frame,double xmin,double ymin, double xmax, double ymax);
extern void delete_Plot2D(Plot2D *p2);
extern Plot2D *Plot2D_copy(Plot2D *p2);
extern void Plot2D_clear(Plot2D *p2, Pixel c);
extern void Plot2D_setview(Plot2D *p2, int vxmin, int vymin, int vxmax, int vymax);
extern void Plot2D_setrange(Plot2D *p2, double xmin, double ymin, double xmax, double ymax);
extern void Plot2D_setscale(Plot2D *p2, int xscale, int yscale);
extern void Plot2D_plot(Plot2D *p2, double x, double y, Pixel color);
extern void Plot2D_box(Plot2D *p2, double x1, double y1, double x2, double y2, Pixel color);
extern void Plot2D_solidbox(Plot2D *p2, double x1, double y1,double x2, double y2, Pixel color);
extern void Plot2D_interpbox(Plot2D *p2, double x1, double y1, double x2, double y2, Pixel c1, Pixel c2, Pixel c3, Pixel c4);
extern void Plot2D_circle(Plot2D *p2, double x, double y, double radius, Pixel color);
extern void Plot2D_solidcircle(Plot2D *p2, double x, double y, double radius, Pixel color);
extern void Plot2D_line(Plot2D *p2, double x1, double y1, double x2, double y2, Pixel color);
extern void Plot2D_start(Plot2D *p2);
extern void Plot2D_drawpixmap(Plot2D *p2, PixMap *pm, double x, double y, Pixel color, Pixel bgcolor);
extern void Plot2D_xaxis(Plot2D *p2, double x, double y, double xtick, int ticklength, Pixel c);
extern void Plot2D_yaxis(Plot2D *p2, double x, double y, double ytick, int ticklength, Pixel c);
extern void Plot2D_triangle(Plot2D *p2, double x1, double y1, double x2, double y2, double x3, double y3, Pixel c);
extern void Plot2D_solidtriangle(Plot2D *p2, double x1, double y1, double x2, double y2, double x3, double y3, Pixel c);
extern void Plot2D_interptriangle(Plot2D *p2, double x1, double y1, Pixel c1,
double x2, double y2, Pixel c2,
double x3, double y3, Pixel c3);
#define LINEAR 10
#define LOG 11
/* -----------------------------------------------------------------------
Matrix
Operations on 4x4 transformation matrices and vectors.
Matrices are represented as a double array of 16 elements
----------------------------------------------------------------------- */
typedef double *Matrix;
typedef struct GL_Vector {
double x;
double y;
double z;
double w;
} GL_Vector;
extern Matrix new_Matrix();
extern void delete_Matrix(Matrix a);
extern Matrix Matrix_copy(Matrix a);
extern void Matrix_multiply(Matrix a, Matrix b, Matrix c);
extern void Matrix_identity(Matrix a);
extern void Matrix_zero(Matrix a);
extern void Matrix_transpose(Matrix a, Matrix result);
extern void Matrix_invert(Matrix a, Matrix inva);
extern void Matrix_transform(Matrix a, GL_Vector *r, GL_Vector *t);
extern void Matrix_transform4(Matrix a, double rx, double ry, double rz,
double rw, GL_Vector *t);
extern void Matrix_print(Matrix a);
extern void Matrix_translate(Matrix a, double tx, double ty, double tz);
extern void Matrix_rotatex(Matrix a, double deg);
extern void Matrix_rotatey(Matrix a, double deg);
extern void Matrix_rotatez(Matrix a, double deg);
/* -----------------------------------------------------------------------
Plot3D
Data Structure for 3-D plots
------------------------------------------------------------------------ */
typedef struct Plot3D {
FrameBuffer *frame; /* Frame buffer being used */
int view_xmin; /* Viewing region */
int view_ymin;
int view_xmax;
int view_ymax;
double xmin; /* Bounding box */
double ymin;
double zmin;
double xmax;
double ymax;
double zmax;
double xcenter; /* Center point */
double ycenter;
double zcenter;
double fovy; /* Field of view */
double aspect; /* Aspect ratio */
double znear; /* near "clipping" plane */
double zfar; /* far "clipping" plane */
Matrix center_mat; /* Matrix used for centering the model */
Matrix model_mat; /* Model rotation matrix */
Matrix view_mat; /* Viewing matrix */
Matrix fullmodel_mat; /* Full model matrix. Used by sphere plot */
Matrix trans_mat; /* Total transformation matrix */
double lookatz; /* Where is the z-lookat point */
double xshift; /* Used for translation and stuff */
double yshift;
double zoom;
int width;
int height;
int pers_mode; /* Perspective mode (private) */
double ortho_left,ortho_right,ortho_bottom,ortho_top;
} Plot3D;
extern Plot3D *new_Plot3D(FrameBuffer *frame, double xmin, double ymin, double zmin,
double xmax, double ymax, double zmax);
extern void delete_Plot3D(Plot3D *p3);
extern Plot3D *Plot3D_copy(Plot3D *p3);
extern void Plot3D_clear(Plot3D *p3, Pixel Color);
extern void Plot3D_perspective(Plot3D *p3, double fovy, double znear, double zfar);
extern void Plot3D_ortho(Plot3D *p3, double left, double right, double top, double bottom);
extern void Plot3D_lookat(Plot3D *p3, double z);
extern void Plot3D_autoperspective(Plot3D *p3, double fovy);
extern void Plot3D_autoortho(Plot3D *p3);
extern void Plot3D_rotx(Plot3D *p3, double deg);
extern void Plot3D_roty(Plot3D *p3, double deg);
extern void Plot3D_rotz(Plot3D *p3, double deg);
extern void Plot3D_rotl(Plot3D *p3, double deg);
extern void Plot3D_rotr(Plot3D *p3, double deg);
extern void Plot3D_rotd(Plot3D *p3, double deg);
extern void Plot3D_rotu(Plot3D *p3, double deg);
extern void Plot3D_rotc(Plot3D *p3, double deg);
extern void Plot3D_zoom(Plot3D *p3, double percent);
extern void Plot3D_left(Plot3D *p3, double percent);
extern void Plot3D_right(Plot3D *p3, double percent);
extern void Plot3D_down(Plot3D *p3, double percent);
extern void Plot3D_up(Plot3D *p3, double percent);
extern void Plot3D_center(Plot3D *p3, double cx, double cy);
extern void Plot3D_plot(Plot3D *p3, double x, double y, double z, Pixel Color);
extern void Plot3D_setview(Plot3D *p3, int vxmin, int vymin, int vxmax, int vymax);
extern void Plot3D_start(Plot3D *p3);
extern void Plot3D_line(Plot3D *p3, double x1, double y1, double z1,
double x2, double y2, double z2, Pixel color);
extern void Plot3D_triangle(Plot3D *p3, double x1, double y1, double z1,
double x2, double y2, double z2,
double x3, double y3, double z3, Pixel color);
extern void Plot3D_solidtriangle(Plot3D *p3, double x1, double y1, double z1,
double x2, double y2, double z2,
double x3, double y3, double z3, Pixel color);
extern void Plot3D_interptriangle(Plot3D *p3,
double x1, double y1, double z1, Pixel c1,
double x2, double y2, double z2, Pixel c2,
double x3, double y3, double z3, Pixel c3);
extern void Plot3D_quad(Plot3D *p3, double x1, double y1, double z1,
double x2, double y2, double z2,
double x3, double y3, double z3,
double x4, double y4, double z4,
Pixel color);
extern void Plot3D_solidquad(Plot3D *p3, double x1, double y1, double z1,
double x2, double y2, double z2,
double x3, double y3, double z3,
double x4, double y4, double z4,
Pixel color);
extern void Plot3D_interpquad(Plot3D *p3, double x1, double y1, double z1, Pixel c1,
double x2, double y2, double z2, Pixel c2,
double x3, double y3, double z3, Pixel c3,
double x4, double y4, double z4, Pixel c4);
extern void Plot3D_solidsphere(Plot3D *p3, double x, double y, double z, double radius,Pixel c);
extern void Plot3D_outlinesphere(Plot3D *p3, double x, double y, double z, double radius,Pixel c, Pixel bc);
extern PixMap PixMap_SQUARE;
extern PixMap PixMap_TRIANGLE;
extern PixMap PixMap_CROSS;
#endif
#define GIFPLOT_H

View file

@ -0,0 +1,5 @@
/* File : example.h */
typedef struct {
double x, y, z;
} Vector;

View file

@ -0,0 +1,30 @@
// Tests SWIG's handling of pass-by-value for complex datatypes
%module example
%{
#include "example.h"
%}
/* Some functions that manipulate Vectors by value */
extern double dot_product(Vector a, Vector b);
extern Vector vector_add(Vector a, Vector b);
/* Include this because the vector_add() function will leak memory */
void free(void *);
/* Some helper functions for our interface */
%inline %{
Vector *new_Vector(double x, double y, double z) {
Vector *v = (Vector *) malloc(sizeof(Vector));
v->x = x;
v->y = y;
v->z = z;
return v;
}
void vector_print(Vector *v) {
printf("Vector %x = (%g, %g, %g)\n", v, v->x, v->y, v->z);
}
%}

11
Examples/xml/example_p5.i Normal file
View file

@ -0,0 +1,11 @@
/* File : example.i */
%module example
%{
#include "example.h"
%}
/* Let's just grab the original header file here */
%include "example.h"

View file

@ -0,0 +1,6 @@
/* File : example.i */
%readonly
extern int status;
extern char path[256];

View file

@ -0,0 +1,47 @@
/* File : example.i */
%title "Matrix and vector package"
/* This file has a few "typical" uses of C++ references. */
%module example
%{
#include "example.h"
%}
class Vector {
public:
Vector(double x, double y, double z);
~Vector();
char *print();
};
/* This helper function calls an overloaded operator */
%inline %{
Vector addv(Vector &a, Vector &b) {
return a+b;
}
%}
/* Wrapper around an array of vectors class */
class VectorArray {
public:
VectorArray(int maxsize);
~VectorArray();
int size();
/* This wrapper provides an alternative to the [] operator */
%addmethods {
Vector &get(int index) {
return (*self)[index];
}
void set(int index, Vector &a) {
(*self)[index] = a;
}
}
};

View file

@ -0,0 +1,39 @@
/* File : example.h */
class Shape {
public:
Shape() {
nshapes++;
}
virtual ~Shape() {
nshapes--;
};
double x, y;
void move(double dx, double dy);
virtual double area() = 0;
virtual double perimeter() = 0;
static int nshapes;
};
class Circle : public Shape {
private:
double radius;
public:
Circle(double r) : radius(r) { };
virtual double area();
virtual double perimeter();
};
class Square : public Shape {
private:
double width;
public:
Square(double w) : width(w) { };
virtual double area();
virtual double perimeter();
};

View file

@ -0,0 +1,69 @@
/* File : example.i */
%module my_example
enum color { RED=10, BLUE, GREEN };
class Foo {
public:
Foo() { }
enum speed { IMPULSE, WARP, LUDICROUS };
void enum_test(speed s);
};
void enum_test(color c, Foo::speed s);
%include pointer.i
/* Next we'll use some typemaps */
%include typemaps.i
%typemap(out) int * {
WHATEVER MAKES YOU HAPPY AS RESULT
}
%typemap(in) int * {
WHATEVER MAKES YOU HAPPY AS PARAMETER
}
%pragma(xml) DEBUG="false";
extern int * my_gcd(const char * x, int * y[], int * r, int (*op)(int,int)) const;
extern double my_foo;
void my_void();
my_empty();
const double my_dutch = 1.0;
union my_union
{
int my_iii;
char my_ccc;
};
struct my_struct
{
public:
virtual ~my_struct();
int my_foo();
protected:
int my_bar;
double x, y;
virtual double area() = 0;
static int nshapes;
};
class my_class : public my_struct, public my_union
{
public:
my_class( char c );
private:
~my_class();
virtual const int * my_func( my_class , char * * x, int y[], const int & r) const;
double my_foo[128];
const my_int i;
};
typedef int my_int;

63
Examples/xml/gnarly.i Normal file
View file

@ -0,0 +1,63 @@
/* File : check.i */
%module my_check
enum color { RED=10, BLUE, GREEN };
class Foo {
public:
Foo() { }
enum speed { IMPULSE, WARP, LUDICROUS };
void enum_test(speed s);
};
void enum_test(color c, Foo::speed s);
%typemap(out) int * {
WHATEVER MAKES YOU HAPPY AS RESULT
}
%typemap(in) int * {
WHATEVER MAKES YOU HAPPY AS PARAMETER
}
%pragma(xml) DEBUG="false";
extern int * my_gcd(const char * x, int * y[], int * r, int (*op)(int,int)) const;
extern double my_foo;
void my_void();
my_empty();
const double my_dutch = 1.0;
union my_union
{
int my_iii;
char my_ccc;
};
struct my_struct
{
public:
virtual ~my_struct();
int my_foo();
protected:
int my_bar;
double x, y;
virtual double area() = 0;
static int nshapes;
};
class my_class : public my_struct, public my_union
{
public:
my_class( char c );
private:
~my_class();
virtual const int * my_func( my_class , char * * x, int y[], const int & r) const;
double my_foo[128];
const my_int i;
};
typedef int my_int;

304
Source/Modules1.1/xml.cxx Normal file
View file

@ -0,0 +1,304 @@
/* -----------------------------------------------------------------------------
* xml.cxx
*
* Generate XML representation
*
* Author(s) : SWIG core: David Beazley (beazley@cs.uchicago.edu)
* XML module: Klaus Wiederaenders (kwconsulting@compuserve.com)
* Copyright (C) 1999-2001. The University of Chicago
* See the file LICENSE for information on usage and redistribution.
* ----------------------------------------------------------------------------- */
/* DB: I had to take some features related to package naming out of this to
get the new type system to work. These need to be put back in at some
point. */
static char cvsroot[] = "$Header$";
#include <time.h>
#include "swig11.h"
#include "xml.h"
#include "dohobj.h"
static char *usage = (char*)"\
XML Options (available with -xml)\n\
-o filename - Output file\n\
-dtd filename - Stylsheet file\n\n";
static String *dtdfile = 0;
static String *xmlfile = 0;
static int indent = 0;
static const int indentsize = 2;
static const char * indentchar = " ";
FILE *f_xml = 0;
extern "C"
{
static String * emit_indent( int indent )
{
String *out;
out = NewString("");
for(int iX = 0; iX < indent; iX ++ )
Append( out, indentchar );
return Swig_temp_result(out);
}
void xml(DOH *node)
{
if (ObjGetMark(node))
{
Printf( f_xml, "%s<swigxml:node ident=\"ID%0X\" />\n",
emit_indent( indent ), node);
return;
}
indent += indentsize;
ObjSetMark(node, 1);
while (node)
{
DohBase * base = (DohBase *) node;
if( !base )
return;
switch( base->type )
{
case 1:
Replace( node, "<", "&lt;", DOH_REPLACE_ANY );
Replace( node, "&", "&amp;", DOH_REPLACE_ANY );
Printf( f_xml, "%s", node );
break;
case 2:
{
indent += indentsize;
DOH *item;
item = Firstitem(node);
while (item)
{
DohBase * itembase = (DohBase *) item;
if( itembase && itembase->type == DOHTYPE_STRING )
{
Printf( f_xml,
"%s<swigxml:item name=\"%s\" ident=\"ID%0X\" />\n",
emit_indent( indent ), Char( item ), item );
}
else
{
Printf( f_xml, "%s<swigxml:item ident=\"ID%0X\">\n",
emit_indent( indent ), item );
xml( item );
Printf( f_xml, "%s</swigxml:item>\n",
emit_indent( indent ) );
}
item = Nextitem(node);
}
indent -= indentsize;
break;
}
case 3:
{
String * none = NewString("swigxml:none");
DOH * tag = Getattr( node, "tag" );
if( !tag )
{
/*
ObjSetMark(node, 0);
Printf( f_xml, "------- %s\n", Char( Str( node )));
ObjSetMark(node, 1);
*/
tag = none;
}
DOH * name = Getattr( node, "name" );
char * ttt = Char( tag );
if( tag && ::strchr( Char(tag), ':' ) == 0 )
Insert( tag, 0, "swigxml:" );
// check for simple node
int length = Len( node );
if( Getattr( node, "tag" ) )
--length;
if( Getattr( node, "prev" ) )
--length;
if( Getattr( node, "next" ) )
--length;
if( Getattr( node, "parent" ) )
--length;
if( Getattr( node, "last" ) )
--length;
if( length == 1 && name )
{ // Yes, it's simple
if( Len( name) )
Printf( f_xml, "%s<%s name=\"%s\" ident=\"ID%0X\" />\n",
emit_indent( indent ), Char( tag ), Char( name ),
node );
else
Printf( f_xml, "%s<%s ident=\"ID%0X\" />\n",
emit_indent( indent ), Char( tag ), node );
Delete( none );
break;
}
if( Len( name) )
Printf( f_xml, "%s<%s name=\"%s\" ident=\"ID%0X\">\n",
emit_indent( indent ), Char( tag ), Char( name ), node );
else
Printf( f_xml, "%s<%s ident=\"ID%0X\">\n",
emit_indent( indent ), Char( tag ), node );
indent += indentsize;
DOH * key = Firstkey(node);
while (key)
{
char * kkkk = Char( key );
DOH * attr = Getattr( node, key );
char * aaaa = Char( Getattr( node, key ) );
DohBase * attrbase = (DohBase *) attr;
if( ::strcmp( Char( key ), "tag")
&& ::strcmp( Char( key ), "code")
&& ::strcmp( Char( key ), "name")
&& attrbase && attrbase->type == DOHTYPE_STRING)
{
Replace( attr, "\"", "&quot;", DOH_REPLACE_ANY );
Printf( f_xml,
"%s<swigxml:%s string=\"%s\" ident=\"ID%0X\" />\n",
emit_indent( indent ), Char( key ), Char( attr ),
attr );
}
else
{
if( ::strcmp( Char( key ), "prev" )
&& ::strcmp( Char( key ), "next" )
&& ::strcmp( Char( key ), "parent" )
&& ::strcmp( Char( key ), "tag" )
&& ::strcmp( Char( key ), "name" )
&& ::strcmp( Char( key ), "last" ) )
{
Printf( f_xml, "%s<swigxml:%s ident=\"ID%0X\">\n",
emit_indent( indent ), Char( key ), key );
xml( attr );
Printf( f_xml, "%s</swigxml:%s>\n",
emit_indent( indent ), Char( key ) );
}
}
key = Nextkey(node);
}
indent -= indentsize;
Printf( f_xml, "%s</%s>\n", emit_indent( indent ), Char( tag ) );
Delete( none );
break;
}
case 4:
Printf( f_xml, "%s ", "DOHTYPE_VOID" );
break;
case 5:
Printf( f_xml, "%s ", "DOHTYPE_FILE" );
break;
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
Printf( f_xml, "%d ", base->type );
;
}
ObjSetMark(node, 0);
node = Swig_next(node);
}
indent -= indentsize;
}
int xml_init(int argc, char *argv[])
{
int i;
int help = 0;
// Get options
for (i = 1; i < argc; i++)
{
if (argv[i])
{
if(strcmp(argv[i],"-xml") == 0)
{
if (argv[i+1])
{
xmlfile = NewString(argv[i+1]);
// don't do this: Swig_mark_arg(i);
Swig_mark_arg(i+1);
i++;
}
else
{
Swig_arg_error();
}
continue;
}
if(strcmp(argv[i],"-dtd") == 0)
{
if (argv[i+1])
{
dtdfile = NewString(argv[i+1]);
Swig_mark_arg(i);
Swig_mark_arg(i+1);
i++;
}
else
{
Swig_arg_error();
}
continue;
}
if (strcmp(argv[i],"-help") == 0)
{
fputs(usage,stderr);
Swig_mark_arg(i);
help = 1;
}
}
}
if (help) return 0;
Preprocessor_define((void *) "SWIGXML 1", 0);
if( ! Swig_swiglib_get() )
Swig_swiglib_set("xml");
return 0;
}
DOH *xml_run(DOH *node)
{
time_t now;
time( &now );
char buffer[32];
::strcpy( buffer, ctime(&now));
buffer[24] = '\0';
char * filename = Char(xmlfile);
if ((f_xml = fopen( filename,"w")) == 0) {
fprintf(stderr,"Unable to open %s\n", filename);
Swig_exit(1);
}
Printf( f_xml, "<!-- Generated by Swig XML at %s -->\n", buffer );
if( dtdfile )
{
Printf( f_xml, "<!DOCTYPE swigxml:swig SYSTEM \"%s\">\n", dtdfile);
}
Printf( f_xml, "<swigxml:swig"
" name=\"namespaces\""
" xmlns:swigxml=\"http://jniplusplus.sourceforge.net\""
" xmlns:swig=\"http://swig.sourceforge.net\""
" xmlns:c=\"http://www.ansi.org\""
" ident=\"ID000000\">\n" );
xml(node);
Printf( f_xml, "</swigxml:swig>\n" );
fclose(f_xml);
return node;
}
}

119
Source/Modules1.1/xml.dtd Normal file
View file

@ -0,0 +1,119 @@
<!ELEMENT swig:top (swigxml:child)>
<!ATTLIST swig:top name CDATA #IMPLIED ident CDATA #REQUIRED>
<!ELEMENT swig:pragma (swigxml:value,swigxml:lang?)>
<!ATTLIST swig:pragma name CDATA #REQUIRED ident CDATA #REQUIRED>
<!ELEMENT swig:file ((swigxml:type|swigxml:child)+)>
<!ATTLIST swig:file name CDATA #REQUIRED ident CDATA #REQUIRED>
<!ELEMENT swig:module EMPTY>
<!ATTLIST swig:module name CDATA #REQUIRED ident CDATA #REQUIRED>
<!ELEMENT swig:insert (swigxml:code,swigxml:section?,swigxml:method?,swigxml:type?)>
<!ATTLIST swig:insert name CDATA #IMPLIED ident CDATA #REQUIRED>
<!ELEMENT swig:types (swigxml:parms)>
<!ATTLIST swig:types name CDATA #IMPLIED ident CDATA #REQUIRED>
<!ELEMENT swig:typemap (swigxml:parms?,(swigxml:srctype|swigxml:code),swigxml:method,swigxml:type,swigxml:lang?,swigxml:srcname?)>
<!ATTLIST swig:typemap name CDATA #IMPLIED ident CDATA #REQUIRED>
<!ELEMENT swig:constant (swigxml:value,swigxml:type?)>
<!ATTLIST swig:constant name CDATA #IMPLIED ident CDATA #REQUIRED>
<!ELEMENT swig:apply (swigxml:parms?,swigxml:type)>
<!ATTLIST swig:apply name CDATA #REQUIRED ident CDATA #REQUIRED>
<!ELEMENT swig:addmethods (swigxml:child)>
<!ATTLIST swig:addmethods name CDATA #IMPLIED ident CDATA #REQUIRED>
<!ELEMENT c:class ((swigxml:child|swigxml:classtype|swigxml:namespace|swigxml:bases|swigxml:scriptname|swigxml:symbols|swigxml:altname)+)>
<!ATTLIST c:class name CDATA #REQUIRED ident CDATA #REQUIRED>
<!ELEMENT c:destructor (swigxml:code?,swigxml:storage?)>
<!ATTLIST c:destructor name CDATA #REQUIRED ident CDATA #REQUIRED>
<!ELEMENT c:function (swigxml:abstract?,swigxml:parms?,swigxml:code?,swigxml:storage?,swigxml:type)>
<!ATTLIST c:function name CDATA #REQUIRED ident CDATA #REQUIRED>
<!ELEMENT c:variable (swigxml:storage?,swigxml:value?,swigxml:type)>
<!ATTLIST c:variable name CDATA #REQUIRED ident CDATA #REQUIRED>
<!ELEMENT c:access EMPTY>
<!ATTLIST c:access name CDATA #REQUIRED ident CDATA #REQUIRED>
<!ELEMENT c:typedef (swigxml:type)>
<!ATTLIST c:typedef name CDATA #REQUIRED ident CDATA #REQUIRED>
<!ELEMENT c:enum (swigxml:child)>
<!ATTLIST c:enum name CDATA #REQUIRED ident CDATA #REQUIRED>
<!ELEMENT c:enumvalue (swigxml:value?)>
<!ATTLIST c:enumvalue name CDATA #REQUIRED ident CDATA #REQUIRED>
<!ELEMENT swigxml:child ((swig:addmethods|swig:apply|swig:constant|swig:types|swig:insert|swig:file|swig:module|swig:typemap|swig:pragma|c:class|c:destructor|c:function|c:access|c:variable|c:typedef|c:enum|c:enumvalue)+)>
<!ATTLIST swigxml:child name CDATA #IMPLIED ident CDATA #REQUIRED>
<!ELEMENT swigxml:swig (swig:top)>
<!ATTLIST swigxml:swig name CDATA #REQUIRED xmlns:swigxml CDATA #REQUIRED xmlns:swig CDATA #REQUIRED xmlns:c CDATA #REQUIRED ident CDATA #REQUIRED>
<!ELEMENT swigxml:type EMPTY>
<!ATTLIST swigxml:type name CDATA #IMPLIED string CDATA #REQUIRED ident CDATA #REQUIRED>
<!ELEMENT swigxml:code (#PCDATA)>
<!ATTLIST swigxml:code name CDATA #IMPLIED ident CDATA #REQUIRED>
<!ELEMENT swigxml:method EMPTY>
<!ATTLIST swigxml:method name CDATA #IMPLIED string CDATA #REQUIRED ident CDATA #REQUIRED>
<!ELEMENT swigxml:value EMPTY>
<!ATTLIST swigxml:value name CDATA #IMPLIED string CDATA #REQUIRED ident CDATA #REQUIRED>
<!ELEMENT swigxml:lang EMPTY>
<!ATTLIST swigxml:lang name CDATA #IMPLIED string CDATA #REQUIRED ident CDATA #REQUIRED>
<!ELEMENT swigxml:parms (swigxml:parm+|swigxml:none+)>
<!ATTLIST swigxml:parms name CDATA #IMPLIED ident CDATA #REQUIRED>
<!ELEMENT swigxml:parm (swigxml:value?,swigxml:type)>
<!ATTLIST swigxml:parm name CDATA #IMPLIED ident CDATA #REQUIRED>
<!ELEMENT swigxml:storage EMPTY>
<!ATTLIST swigxml:storage name CDATA #IMPLIED string CDATA #REQUIRED ident CDATA #REQUIRED>
<!ELEMENT swigxml:classtype EMPTY>
<!ATTLIST swigxml:classtype name CDATA #IMPLIED string (struct|class|union) #REQUIRED ident CDATA #REQUIRED>
<!ELEMENT swigxml:namespace EMPTY>
<!ATTLIST swigxml:namespace name CDATA #IMPLIED string CDATA #REQUIRED ident CDATA #REQUIRED>
<!ELEMENT swigxml:bases (swigxml:item+)>
<!ATTLIST swigxml:bases name CDATA #IMPLIED ident CDATA #REQUIRED>
<!ELEMENT swigxml:item EMPTY>
<!ATTLIST swigxml:item name CDATA #REQUIRED ident CDATA #REQUIRED>
<!ELEMENT swigxml:node EMPTY>
<!ATTLIST swigxml:node ident CDATA #REQUIRED>
<!ELEMENT swigxml:scriptname EMPTY>
<!ATTLIST swigxml:scriptname name CDATA #REQUIRED string CDATA #REQUIRED ident CDATA #REQUIRED>
<!ELEMENT swigxml:abstract EMPTY>
<!ATTLIST swigxml:abstract name CDATA #IMPLIED string CDATA #REQUIRED ident CDATA #REQUIRED>
<!ELEMENT swigxml:section EMPTY>
<!ATTLIST swigxml:section name CDATA #IMPLIED string CDATA #REQUIRED ident CDATA #REQUIRED>
<!ELEMENT swigxml:srctype EMPTY>
<!ATTLIST swigxml:srctype name CDATA #IMPLIED string CDATA #REQUIRED ident CDATA #REQUIRED>
<!ELEMENT swigxml:srcname EMPTY>
<!ATTLIST swigxml:srcname name CDATA #IMPLIED string CDATA #REQUIRED ident CDATA #REQUIRED>
<!ELEMENT swigxml:none (swigxml:type)>
<!ATTLIST swigxml:none name CDATA #IMPLIED ident CDATA #REQUIRED>
<!ELEMENT swigxml:altname EMPTY>
<!ATTLIST swigxml:altname name CDATA #IMPLIED string CDATA #REQUIRED ident CDATA #REQUIRED>

18
Source/Modules1.1/xml.h Normal file
View file

@ -0,0 +1,18 @@
/****************************************************************************
* Simplified Wrapper and Interface Generator (SWIG)
*
* Author : David Beazley
*
* Department of Computer Science
* University of Chicago
* 1100 E 58th Street
* Chicago, IL 60637
* beazley@cs.uchicago.edu
*
* Please read the file LICENSE for the copyright and terms by which SWIG
* can be used and distributed.
****************************************************************************/
extern "C" DOH *xml_run(DOH *node);
extern "C" int xml_init(int argc, char *argv[]);