Added lots to the interface file

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@143 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dustin Mitchell 2000-01-22 23:53:07 +00:00
commit 8d45fab2af
4 changed files with 242 additions and 27 deletions

View file

@ -1,28 +1,108 @@
CC = @CC@
AR = @AR@
RANLIB = @RANLIB@
prefix = @prefix@
exec_prefix = @exec_prefix@
RPATH = @RPATH@
SO = @SO@
CCSHARED = @CCSHARED@
LDSHARED = @LDSHARED@
INCLUDE = -I. -I../DOH/Include
# ---------------------------------------------------------------
# $Header$
# SWIG Makefile
#
# This file can be used to build various Python extensions with SWIG.
# By default this file is set up for dynamic loading, but it can
# be easily customized for static extensions by modifying various
# portions of the file.
#
# SRCS = C source files
# CXXSRCS = C++ source files
# OBJCSRCS = Objective-C source files
# OBJS = Additional .o files (compiled previously)
# INTERFACE = SWIG interface file
# TARGET = Name of target module or executable
#
#----------------------------------------------------------------
SRCS = types.c scanner.c include.c getopt.c misc.c super.c
OBJS = types.o scanner.o include.o getopt.o misc.o super.o
SRCS = types.c scanner.c include.c getopt.c misc.c super.c
INTERFACE = swig.i
WRAPFILE = $(INTERFACE:.i=_wrap.c)
WRAPOBJ = $(INTERFACE:.i=_wrap.o)
TARGET = swigmodule@SO@ # Use this kind of target for dynamic loading
prefix = @prefix@
exec_prefix = @exec_prefix@
CC = @CC@
AR = @AR@
RANLIB = @RANLIB@
RPATH = @RPATH@
CC = @CC@
CFLAGS =
INCLUDE = -I. -I../DOH/Include
LIBS = -L. -L../DOH/ -ldoh
# SWIG Options
# SWIG = location of the SWIG executable
# SWIGOPT = SWIG compiler options
# SWIGCC = Compiler used to compile the wrapper file
SWIG = $(exec_prefix)/bin/swig
SWIGOPT = -python -shadow
SWIGCC = $(CC)
# SWIG Library files. Uncomment if rebuilding the Python interpreter
#SWIGLIB = -lembed.i
# Rules for creating .o files from source.
OBJS = $(SRCS:.c=.o)
ALLOBJS = $(OBJS)
# Command that will be used to build the final extension.
BUILD = $(SWIGCC)
# Uncomment the following if you are using dynamic loading
CCSHARED = @CCSHARED@
BUILD = @LDSHARED@
# Python installation
PY_INCLUDE = -DHAVE_CONFIG_H @PYINCLUDE@
PY_LIB = @PYLIB@
# Build libraries (needed for static builds)
LIBM = @LIBM@
LIBC = @LIBC@
SYSLIBS = $(LIBM) $(LIBC) @LIBS@
# Build options
BUILD_LIBS = $(LIBS) # Dynamic loading
# Compilation rules for non-SWIG components
.c.o:
$(CC) $(CCSHARED) $(INCLUDE) $(CFLAGS) -c -o $*.o $<
all: $(OBJS)
# ----------------------------------------------------------------------
# Toplevel Targets
# ----------------------------------------------------------------------
supertest: super.c
all: $(OBJS) # the object files
python: $(TARGET) # the python module
supertest: super.c # test the super module
$(CC) $(CCSHARED) $(INCLUDE) $(CFLAGS) -g -DSUPER_TEST -c \
-o supertest.o super.c
$(CC) supertest.o -ldoh -o supertest
clean:
rm -f *.o *~ core *.so *.a
rm -f *.o *~ core *.so *.a *_wrap.*
# ----------------------------------------------------------------------
# Rules for building the extension
# ----------------------------------------------------------------------
$(WRAPOBJ) : $(WRAPFILE)
$(SWIGCC) -c $(CCSHARED) $(CFLAGS) $(WRAPFILE) $(INCLUDE) $(PY_INCLUDE)
$(WRAPFILE) : $(INTERFACE)
$(SWIG) $(SWIGOPT) -o $(WRAPFILE) $(SWIGLIB) $(INTERFACE)
$(TARGET): $(WRAPOBJ) $(ALLOBJS)
$(BUILD) $(WRAPOBJ) $(ALLOBJS) $(BUILD_LIBS) -o $(TARGET)

View file

@ -166,7 +166,7 @@ static DohObjInfo SuperType =
* NewSuperString(const char *c) - Create a new SuperString
* ------------------------------------------------------------------------- */
DOH *
NewSuper(char *s, DOH *filename, int firstline)
NewSuperString(char *s, DOH *filename, int firstline)
{
int l = 0, max;
Super *str;
@ -1434,7 +1434,7 @@ Super_raw_replace(Super *str, char *token, int flags,
return repcount;
}
#ifdef SUPER_TEST
#if defined(SUPER_TEST)
#include <stdio.h>
static void dump_tags(DOH *so)

View file

@ -39,7 +39,7 @@ extern DOH *Swig_include(DOH *name);
/* --- Super Strings --- */
extern DOH *NewSuper(char *s, DOH *filename, int firstline);
extern DOH *NewSuperString(char *s, DOH *filename, int firstline);
extern int SuperString_check(DOH *s);
/* --- Command line parsing --- */

View file

@ -27,16 +27,156 @@
$target = PyFile_FromFile($source, "unknown", "?", fclose);
}
%typemap(python,in) DOH * {
$target = PyString_AsString($source);
%{
/* -------------------------------------------------------------------------
* An extension type for DOH objects -- we could use shadow classes,
* but this will be lots faster.
* ------------------------------------------------------------------------- */
typedef struct PyDOH {
PyObject_HEAD
DOH *doh;
} PyDOH;
staticforward PyTypeObject PyDOHType;
/* methods */
static PyObject * Swig_PyDOH_new(DOH *in) {
PyDOH *self = PyObject_NEW(PyDOH, &PyDOHType);
if (!self) return (PyObject *)self;
self->doh = in;
Incref(in); /* increase the DOH refcount */
return (PyObject *)self;
}
static void Swig_PyDOH_delete(PyDOH *self) {
Delete(self->doh); /* decrease the DOH refcount */
PyMem_DEL(self);
}
static int Swig_PyDOH_check(void *self) {
return (((PyObject *)self)->ob_type == &PyDOHType);
}
static PyObject *Swig_PyDOH_repr(PyDOH *self) {
return PyString_FromString(Char(self->doh));
}
static char PyDOH_docstring[] =
" Interface to DOH objects from Python. DOH objects behave largely\n\
like Python objects, although some functionality may be different.";
/* Type object */
static PyTypeObject PyDOHType = {
PyObject_HEAD_INIT(&PyType_Type)
0,
"DOH",
sizeof(PyDOH),
0,
(destructor)Swig_PyDOH_delete,
(printfunc)0,
(getattrfunc)0,
(setattrfunc)0,
(cmpfunc)0,
(reprfunc)Swig_PyDOH_repr,
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
(hashfunc)0, /* tp_hash */
(ternaryfunc)0, /* tp_call */
(reprfunc)0, /* tp_str */
(getattrofunc)0, /* tp_getattro */
(setattrofunc)0, /* tp_setattro */
0, /* tp_as_buffer */
0, /* tp_xxx4 */
PyDOH_docstring
};
%}
%typemap(python,in) DOH * {
if (Swig_PyDOH_check($source))
$target = ((PyDOH *)$source)->doh, printf("PyDOH\n");
else if (PyString_Check($source))
$target = (DOH *)PyString_AsString($source), printf("String\n");
else if (PySequence_Check($source))
$target = 0, printf("Sequence\n");
else if (PyMapping_Check($source))
$target = 0, printf("Mapping\n");
else if (PyNumber_Check($source))
$target = (DOH *)$source, printf("Number\n");
else if (PyFile_Check($source))
$target = (DOH *)PyFile_AsFile($source), printf("File\n");
else
$target = (DOH *)NULL; /* do better later? */
}
%typemap(python,out) DOH * {
$target = PyString_FromString(Char($source));
$target = Swig_PyDOH_new($source);
}
%title "SWIG", after
%section "DOH Objects", before
%subsection "Constants"
/* The beginning of a sequence */
#define DOH_BEGIN -1
/* The end of a sequence */
#define DOH_END -2
/* The current point in a sequence */
#define DOH_CUR -3
/* Synonymous with DOH_CUR */
#define DOH_CURRENT -3
/* Replace any matches of the given text */
#define DOH_REPLACE_ANY 0x00
/* Replace, but not inside of quotes */
#define DOH_REPLACE_NOQUOTE 0x01
/* Replace only full identifiers */
#define DOH_REPLACE_ID 0x02
/* Replace only the first match */
#define DOH_REPLACE_FIRST 0x04
%subsection "SuperStrings"
/* SuperString constructor */
extern DOH *NewSuperString(char *string, DOH *filename, int firstline);
/* Is this a SuperString? */
extern int SuperString_check(DOH *);
%subsection "Strings"
/* String constructor */
extern DOH *NewString(char *c);
/* Is this a string? */
extern int String_check(DOH *);
%subsection "Files"
/* File constructor */
extern DOH *NewFile(DOH *file, char *mode);
/* File constructor from Python file */
extern DOH *NewFileFromFile(FILE *file);
/* File constructor from a file descriptor */
extern DOH *NewFileFromFd(int fd);
/* Copy from file to file */
%name(CopyTo) extern int DohCopyto(DOH *input, DOH *output);
%subsection "Lists"
/* List constructor */
extern DOH *NewList();
/* Is this a list? */
extern int List_check(DOH *);
/* Sort a list */
extern void List_sort(DOH *);
%subsection "Hash tables"
/* Hash table constructor */
extern DOH *NewHash();
/* Is this a hash table? */
extern int Hash_check(DOH *);
/* Get a List of the keys in a hash table */
extern DOH *Hash_keys(DOH *);
%section "Files"
extern void Swig_add_directory(DOH *dirname);
@ -48,11 +188,6 @@ extern DOH *Swig_include(DOH *name);
#define SWIG_FILE_DELIMETER "/"
%section "Super Strings"
extern DOH *NewSuper(char *string, DOH *filename, int firstline);
extern int SuperString_check(DOH *string);
%section "Command Line Parsing"
extern void Swig_init_args(int argc, char **argv);