Since I have made several changes to SWIG over the years to accomodate

special cases and other things in wxPython, and since I plan on making
several more, I've decided to put the SWIG sources in wxPython's CVS
instead of relying on maintaining patches.  This effectivly becomes a
fork of an obsolete version of SWIG, :-( but since SWIG 1.3 still
doesn't have some things I rely on in 1.1, not to mention that my
custom patches would all have to be redone, I felt that this is the
easier road to take.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15307 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2002-04-29 19:56:57 +00:00
parent 3bd1e03385
commit c90f71dd8c
135 changed files with 51307 additions and 1 deletions

View File

@@ -465,7 +465,7 @@ def run_swig(files, dir, gendir, package, USE_SWIG, force, swig_args, swig_deps=
cpp_file = string.join(string.split(cpp_file, '\\'), '/')
i_file = string.join(string.split(i_file, '\\'), '/')
cmd = ['swig'] + swig_args + ['-I'+dir, '-c', '-o', cpp_file, i_file]
cmd = ['./wxSWIG/wxswig'] + swig_args + ['-I'+dir, '-c', '-o', cpp_file, i_file]
spawn(cmd, verbose=1)
# copy the generated python file to the package directory

View File

@@ -0,0 +1 @@
wxSWIG.dsp

View File

@@ -0,0 +1,676 @@
/*******************************************************************************
* 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.
*******************************************************************************/
/***********************************************************************
* $Header$
*
* swig.h
*
* This is the header file containing the main class definitions and
* declarations. Should be included in all extensions and code
* modules.
*
***********************************************************************/
#ifndef __swig_h_
#define __swig_h_
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "swigver.h"
/* Global variables. Needs to be cleaned up */
#ifdef MACSWIG
#define Status Swig_Status
#undef stderr
#define stderr swig_log
extern FILE *swig_log;
#endif
extern FILE *f_header; // Some commonly used
extern FILE *f_wrappers; // FILE pointers
extern FILE *f_init;
extern FILE *f_input;
extern char InitName[256];
extern char LibDir[512]; // Library directory
extern char **InitNames; // List of other init functions
extern int Status; // Variable creation status
extern int TypeStrict; // Type checking strictness
extern int Verbose;
extern int yyparse();
extern int line_number;
extern int start_line;
extern char *input_file; // Current input file
extern int CPlusPlus; // C++ mode
extern int ObjC; // Objective-C mode
extern int ObjCClass; // Objective-C style class
extern int AddMethods; // AddMethods mode
extern int NewObject; // NewObject mode
extern int Inline; // Inline mode
extern int NoInclude; // NoInclude flag
extern char *typemap_lang; // Current language name
extern int error_count;
extern char *copy_string(char *);
extern char output_dir[512]; // Output directory
#define FatalError() if ((error_count++) > 20) { fprintf(stderr,"Confused by earlier errors. Bailing out\n"); SWIG_exit(1); }
/* Miscellaneous stuff */
#define STAT_READONLY 1
#define MAXSCOPE 16
extern char* getSwigLib();
// -----------------------------------------------------------------------
// String class
// -----------------------------------------------------------------------
class String {
private:
int maxsize; // Max size of current string
void add(const char *newstr); // Function to add a new string
void add(char c); // Add a character
void insert(const char *newstr);
int len;
public:
String();
String(const char *s);
~String();
char *get() const;
char *str; // String data
friend String& operator<<(String&,const char *s);
friend String& operator<<(String&,const int);
friend String& operator<<(String&,const char);
friend String& operator<<(String&,String&);
friend String& operator>>(const char *s, String&);
friend String& operator>>(String&,String&);
String& operator=(const char *);
operator char*() const { return str; }
void untabify();
void replace(const char *token, const char *rep);
void replaceid(const char *id, const char *rep);
void strip();
};
#define tab2 " "
#define tab4 " "
#define tab8 " "
#define br "\n"
#define endl "\n"
#define quote "\""
// -------------------------------------------------------------------
// Hash table class
// -------------------------------------------------------------------
class Hash {
private:
struct Node {
Node(const char *k, void *obj, void (*d)(void *)) {
key = new char[strlen(k)+1];
strcpy(key,k);
object = obj;
del_proc = d;
next = 0;
};
~Node() {
delete key;
if (del_proc) (*del_proc)(object);
};
char *key;
void *object;
struct Node *next;
void (*del_proc)(void *);
};
int h1(const char *key); // Hashing function
int hashsize; // Size of hash table
Node **hashtable; // Actual hash table
int index; // Current index (used by iterators)
Node *current; // Current item in hash table
public:
Hash();
~Hash();
int add(const char *key, void *object);
int add(const char *key, void *object, void (*del)(void *));
void *lookup(const char *key);
void remove(const char *key);
void *first();
void *next();
char *firstkey();
char *nextkey();
};
/************************************************************************
* class DataType
*
* Defines the basic datatypes supported by the translator.
*
************************************************************************/
#define T_INT 1
#define T_SHORT 2
#define T_LONG 3
#define T_UINT 4
#define T_USHORT 5
#define T_ULONG 6
#define T_UCHAR 7
#define T_SCHAR 8
#define T_BOOL 9
#define T_DOUBLE 10
#define T_FLOAT 11
#define T_CHAR 12
#define T_USER 13
#define T_VOID 14
#define T_SYMBOL 98
#define T_ERROR 99
// These types are now obsolete, but defined for backwards compatibility
#define T_SINT 90
#define T_SSHORT 91
#define T_SLONG 92
// Class for storing data types
#define MAX_NAME 96
class DataType {
private:
static Hash *typedef_hash[MAXSCOPE];
static int scope;
public:
int type; // SWIG Type code
char name[MAX_NAME]; // Name of type
char is_pointer; // Is this a pointer?
char implicit_ptr; // Implicit ptr
char is_reference; // A C++ reference type
char status; // Is this datatype read-only?
char *qualifier; // A qualifier string (ie. const).
char *arraystr; // String containing array part
int id; // type identifier (unique for every type).
DataType();
DataType(DataType *);
DataType(int type);
~DataType();
void primitive(); // Turn a datatype into its primitive type
char *print_type(); // Return string containing datatype
char *print_full(); // Return string with full datatype
char *print_cast(); // Return string for type casting
char *print_mangle();// Return mangled version of type
char *print_real(char *local=0); // Print the real datatype (as far as we can determine)
char *print_arraycast(); // Prints an array cast
char *print_mangle_default(); // Default mangling scheme
// Array query functions
int array_dimensions(); // Return number of array dimensions (if any)
char *get_dimension(int); // Return string containing a particular dimension
char *get_array(); // Returns the array string for a datatype
// typedef support
void typedef_add(char *name, int mode = 0); // Add this type to typedef list
void typedef_resolve(int level = 0); // See if this type has been typedef'd
void typedef_replace(); // Replace this type with it's original type
static int is_typedef(char *name); // See if this is a typedef
void typedef_updatestatus(int newstatus); // Change status of a typedef
static void init_typedef(void); // Initialize typedef manager
static void merge_scope(Hash *h); // Functions for managing scoping of datatypes
static void new_scope(Hash *h = 0);
static Hash *collapse_scope(char *);
int check_defined(); // Check to see if type is defined by a typedef.
};
#define STAT_REPLACETYPE 2
/************************************************************************
* class Parm
*
* Structure for holding information about function parameters
*
* CALL_VALUE --> Call by value even though function parameter
* is a pointer.
* ex : foo(&_arg0);
* CALL_REF --> Call by reference even though function parameter
* is by value
* ex : foo(*_arg0);
*
************************************************************************/
#define CALL_VALUE 0x01
#define CALL_REFERENCE 0x02
#define CALL_OUTPUT 0x04
struct Parm {
DataType *t; // Datatype of this parameter
int call_type; // Call type (value or reference or value)
char *name; // Name of parameter (optional)
char *defvalue; // Default value (as a string)
int ignore; // Ignore flag
char *objc_separator; // Parameter separator for Objective-C
Parm(DataType *type, char *n);
Parm(Parm *p);
~Parm();
};
// -------------------------------------------------------------
// class ParmList
//
// This class is used for manipulating parameter lists in
// function and type declarations.
// -------------------------------------------------------------
#define MAXPARMS 16
class ParmList {
private:
int maxparms; // Max parms possible in current list
Parm **parms; // Pointer to parms array
void moreparms(); // Increase number of stored parms
int current_parm; // Internal state for get_first,get_next
public:
int nparms; // Number of parms in list
void append(Parm *p); // Append a parameter to the end
void insert(Parm *p, int pos); // Insert a parameter into the list
void del(int pos); // Delete a parameter at position pos
int numopt(); // Get number of optional arguments
int numarg(); // Get number of active arguments
Parm *get(int pos); // Get the parameter at position pos
Parm &operator[](int); // An alias for get().
ParmList();
ParmList(ParmList *l);
~ParmList();
// Keep this for backwards compatibility
Parm *get_first(); // Get first parameter from list
Parm *get_next(); // Get next parameter from list
void print_types(FILE *f); // Print list of datatypes
void print_types(String &f); // Generate list of datatypes.
void print_args(FILE *f); // Print argument list
int check_defined(); // Checks to make sure the arguments are defined
void sub_parmnames(String &s); // Remaps real parameter names in code fragment
};
// Modes for different types of inheritance
#define INHERIT_FUNC 0x1
#define INHERIT_VAR 0x2
#define INHERIT_CONST 0x4
#define INHERIT_ALL (INHERIT_FUNC | INHERIT_VAR | INHERIT_CONST)
struct Pragma {
Pragma() { next = 0; }
String filename;
int lineno;
String lang;
String name;
String value;
Pragma *next;
};
/************************************************************************
* class language:
*
* This class defines the functions that need to be supported by the
* scripting language being used. The translator calls these virtual
* functions to output different types of code for different languages.
*
* By implementing this using virtual functions, hopefully it will be
* easy to support different types of scripting languages.
*
* The following functions are used :
*
* parse_args(argc, argv)
* Parse the arguments used by this language.
*
* parse()
* Entry function that starts parsing of a particular language
*
* create_function(fname, iname, rtype, parmlist)
* Creates a function wrappper.
*
* link_variable(vname, iname, type)
* Creates a link to a variable.
*
* declare_const(cname, type, value)
* Creates a constant (for #define).
*
* initialize(char *fn)
* Produces initialization code.
*
* headers()
* Produce code for headers
*
* close()
* Close up files
*
* usage_var(iname,type,string)
* Produces usage string for variable declaration.
*
* usage_func(iname,rttype, parmlist, string)
* Produces usage string for function declaration.
*
* usage_const(iname, type, value, string)
* Produces usage string for constants
*
* set_module(char *modname)
* Sets the name of the module (%module directive)
*
* set_init(char *initname)
* Sets name of initialization function (an alternative to set_module)
* add_native(char *name, char *funcname);
* Adds a native wrapper function to the initialize process
*
* type_mangle(DataType *t);
* Mangles the name of a datatype.
* --- C++ Functions ---
*
* These functions are optional additions to any of the target
* languages. SWIG handles inheritance, symbol tables, and other
* information.
*
* cpp_open_class(char *classname, char *rname)
* Open a new C++ class definition.
* cpp_close_class(char *)
* Close current C++ class
* cpp_member_func(char *name, char *rname, DataType *rt, ParmList *l)
* Create a C++ member function
* cpp_constructor(char *name, char *iname, ParmList *l)
* Create a C++ constructor.
* cpp_destructor(char *name, char *iname)
* Create a C++ destructor
* cpp_variable(char *name, char *iname, DataType *t)
* Create a C++ member data item.
* cpp_declare_const(char *name, char *iname, int type, char *value)
* Create a C++ constant.
* cpp_inherit(char *baseclass)
* Inherit data from baseclass.
* cpp_static_func(char *name, char *iname, DataType *t, ParmList *l)
* A C++ static member function.
* cpp_static_var(char *name, char *iname, DataType *t)
* A C++ static member data variable.
*
*************************************************************************/
class Language {
public:
virtual void parse_args(int argc, char *argv[]) = 0;
virtual void parse() = 0;
virtual void create_function(char *, char *, DataType *, ParmList *) = 0;
virtual void link_variable(char *, char *, DataType *) = 0;
virtual void declare_const(char *, char *, DataType *, char *) = 0;
virtual void initialize(void) = 0;
virtual void headers(void) = 0;
virtual void close(void) = 0;
virtual void set_module(char *mod_name,char **mod_list) = 0;
virtual void set_init(char *init_name);
virtual void add_native(char *, char *);
virtual char *type_mangle(DataType *t) {
return t->print_mangle_default();
}
virtual void add_typedef(DataType *t, char *name);
virtual void create_command(char *cname, char *iname);
//
// C++ language extensions.
// You can redefine these, or use the defaults below
//
virtual void cpp_member_func(char *name, char *iname, DataType *t, ParmList *l);
virtual void cpp_constructor(char *name, char *iname, ParmList *l);
virtual void cpp_destructor(char *name, char *newname);
virtual void cpp_open_class(char *name, char *rename, char *ctype, int strip);
virtual void cpp_close_class();
virtual void cpp_cleanup();
virtual void cpp_inherit(char **baseclass, int mode = INHERIT_ALL);
virtual void cpp_variable(char *name, char *iname, DataType *t);
virtual void cpp_static_func(char *name, char *iname, DataType *t, ParmList *l);
virtual void cpp_declare_const(char *name, char *iname, DataType *type, char *value);
virtual void cpp_static_var(char *name, char *iname, DataType *t);
virtual void cpp_pragma(Pragma *plist);
// Pragma directive
virtual void pragma(char *, char *, char *);
// Declaration of a class, but not a full definition
virtual void cpp_class_decl(char *, char *, char *);
// Import directive
virtual void import(char *filename);
};
class Documentation;
// --------------------------------------------------------------------
// class DocEntry
//
// Base class for the documentation system. Basically everything is
// a documentation entry of some sort. Specific derived classes
// are created internally and shouldn't be accessed by third-party
// modules.
// --------------------------------------------------------------------
class DocEntry {
public:
char *name; // Name of the entry
String usage; // Short description (optional)
String cinfo; // Information about C interface (optional).
String text; // Supporting text (optional)
DocEntry *parent; // Parent of this entry (optional)
DocEntry *child; // Children of this entry (optional)
DocEntry *next; // Next entry (or sibling)
DocEntry *previous; // Previous entry
int counter; // Counter for section control
int is_separator; // Is this a separator entry?
int sorted; // Sorted?
int line_number; // Line number
int end_line; // Ending line number
int format; // Format this documentation entry
int print_info; // Print C information about this entry
char *file; // File
virtual ~DocEntry(); // Destructor (common to all subclasses)
// Methods applicable to all documentation entries
virtual void output(Documentation *d);
void add(DocEntry *de); // Add documentation entry to the list
void addchild(DocEntry *de); // Add documentation entry as a child
void sort_children(); // Sort all of the children
void remove(); // Remove this doc entry
void parse_args(int argc, char **argv); // Parse command line options
void style(char *name,char *value);// Change doc style.
static DocEntry *dead_entries; // Dead documentation entries
};
extern DocEntry *doc_entry;
// Default DocEntry style parameters
#define SWIGDEFAULT_SORT 0
#define SWIGDEFAULT_FORMAT 1
#define SWIGDEFAULT_INFO 1
// ----------------------------------------------------------------------
// Documentation module base class
//
// This class defines methods that need to be implemented for a
// documentation module.
//
// title() - Print out a title entry
// newsection() - Start a new section (may be nested to form subsections)
// endsection() - End a section
// print_decl() - Print a standard declaration
// print_text() - Print standard text
// init() - Initialize the documentation module
// close() - Close documentation module
// ----------------------------------------------------------------------
class Documentation {
public:
virtual void parse_args(int argc, char **argv) = 0;
virtual void title(DocEntry *de) = 0;
virtual void newsection(DocEntry *de, int sectnum) = 0;
virtual void endsection() = 0;
virtual void print_decl(DocEntry *de) = 0;
virtual void print_text(DocEntry *de) = 0;
virtual void separator() = 0;
virtual void init(char *filename) = 0;
virtual void close(void) = 0;
virtual void style(char *name, char *value) = 0;
};
/* Emit functions */
extern void emit_extern_var(char *, DataType *, int, FILE *);
extern void emit_extern_func(char *, DataType *, ParmList *, int, FILE *);
extern int emit_args(DataType *, ParmList *, FILE *);
extern void emit_func_call(char *, DataType *, ParmList *, FILE *);
extern void emit_hex(FILE *);
extern void emit_set_get(char *, char *, DataType *);
extern void emit_banner(FILE *);
extern void emit_ptr_equivalence(FILE *);
extern int SWIG_main(int, char **, Language *, Documentation *);
extern void make_wrap_name(char *);
// Some functions for emitting some C++ helper code
extern void cplus_emit_member_func(char *classname, char *classtype, char *classrename,
char *mname, char *mrename, DataType *type, ParmList *l,
int mode);
extern void cplus_emit_static_func(char *classname, char *classtype, char *classrename,
char *mname, char *mrename, DataType *type, ParmList *l,
int mode);
extern void cplus_emit_destructor(char *classname, char *classtype, char *classrename,
char *name, char *iname, int mode);
extern void cplus_emit_constructor(char *classname, char *classtype, char *classrename,
char *name, char *iname, ParmList *l, int mode);
extern void cplus_emit_variable_get(char *classname, char *classtype, char *classrename,
char *name, char *iname, DataType *type, int mode);
extern void cplus_emit_variable_set(char *classname, char *classtype, char *classrename,
char *name, char *iname, DataType *type, int mode);
extern char *cplus_base_class(char *name);
extern void cplus_support_doc(String &f);
/* Function for building search directories */
extern void add_directory(char *dirname);
extern int insert_file(char *, FILE *);
extern int get_file(char *filename, String &str);
extern int checkout_file(char *filename, char *dest);
extern int checkin_file(char *dir, char *lang, char *source, char *dest);
extern int include_file(char *filename);
/* Miscellaneous */
extern void check_options();
extern void init_args(int argc, char **);
extern void mark_arg(int n);
extern void arg_error();
extern void library_add(char *name);
extern void library_insert();
// -----------------------------------------------------------------------
// Class for Creating Wrapper Functions
// -----------------------------------------------------------------------
class WrapperFunction {
private:
Hash h;
public:
String def;
String locals;
String code;
String init;
void print(FILE *f);
void print(String &f);
void add_local(char *type, char *name, char *defvalue = 0);
char *new_local(char *type, char *name, char *defvalue = 0);
static void del_type(void *obj);
};
extern int emit_args(DataType *, ParmList *, WrapperFunction &f);
extern void emit_func_call(char *, DataType *, ParmList *, WrapperFunction &f);
extern void SWIG_exit(int);
// Symbol table management
extern int add_symbol(char *, DataType *, char *);
extern void remove_symbol(char *);
extern int update_symbol(char *, DataType *, char *);
extern char *lookup_symvalue(char *);
extern DataType *lookup_symtype(char *);
extern int lookup_symbol(char *);
// -----------------------------------------------------------------------
// Typemap support
// -----------------------------------------------------------------------
extern void typemap_register(char *op, char *lang, DataType *type, char *pname, char *code, ParmList *l = 0);
extern void typemap_register(char *op, char *lang, char *type, char *pname, char *code,ParmList *l = 0);
extern void typemap_register_default(char *op, char *lang, int type, int ptr, char *arraystr, char *code, ParmList *l = 0);
extern char *typemap_lookup(char *op, char *lang, DataType *type, char *pname, char *source, char *target,
WrapperFunction *f = 0);
extern void typemap_clear(char *op, char *lang, DataType *type, char *pname);
extern void typemap_copy(char *op, char *lang, DataType *stype, char *sname, DataType *ttype, char *tname);
extern char *typemap_check(char *op, char *lang, DataType *type, char *pname);
extern void typemap_apply(DataType *tm_type, char *tmname, DataType *type, char *pname);
extern void typemap_clear_apply(DataType *type, char *pname);
// -----------------------------------------------------------------------
// Code fragment support
// -----------------------------------------------------------------------
extern void fragment_register(char *op, char *lang, char *code);
extern char *fragment_lookup(char *op, char *lang, int age);
extern void fragment_clear(char *op, char *lang);
extern void emit_ptr_equivalence(WrapperFunction &);
// -----------------------------------------------------------------------
// Naming system
// -----------------------------------------------------------------------
#define AS_IS 1
extern void name_register(char *method, char *format);
extern int name_scope(int);
extern char *name_wrapper(char *fname, char *prefix, int suppress=0);
extern char *name_member(char *fname, char *classname, int suppress=0);
extern char *name_get(char *vname, int suppress=0);
extern char *name_set(char *vname, int suppress=0);
extern char *name_construct(char *classname, int suppress=0);
extern char *name_destroy(char *classname, int suppress=0);
#endif

View File

@@ -0,0 +1,6 @@
/* SWIG version information */
#define SWIG_MAJOR_VERSION 1
#define SWIG_MINOR_VERSION 1
#define SWIG_SPIN "(Build 883)"

View File

@@ -0,0 +1,6 @@
/* SWIG version information */
#define SWIG_MAJOR_VERSION 1
#define SWIG_MINOR_VERSION 1
#define SWIG_SPIN "(@BUILD@)"

43
wxPython/wxSWIG/LICENSE Normal file
View File

@@ -0,0 +1,43 @@
Simplified Wrapper and Interface Generator (SWIG)
David Beazley
Department of Computer Science
University of Chicago
1100 E 58th Street
Chicago, IL 60637
beazley@cs.uchicago.edu
All versions of SWIG 1.1 are distributed under the following
license:
====================================================================
Copyright (c) 1995-1998
The University of Utah and the Regents of the University of California
All Rights Reserved
Permission is hereby granted, without written agreement and without
license or royalty fees, to use, copy, modify, and distribute this
software and its documentation for any purpose, provided that
(1) The above copyright notice and the following two paragraphs
appear in all copies of the source code and (2) redistributions
including binaries reproduces these notices in the supporting
documentation. Substantial modifications to this software may be
copyrighted by their authors and need not follow the licensing terms
described here, provided that the new terms are clearly indicated in
all files where they apply.
IN NO EVENT SHALL THE AUTHOR, THE UNIVERSITY OF CALIFORNIA, THE
UNIVERSITY OF UTAH OR DISTRIBUTORS OF THIS SOFTWARE BE LIABLE TO ANY
PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
THE AUTHOR, THE UNIVERSITY OF CALIFORNIA, AND THE UNIVERSITY OF UTAH
SPECIFICALLY DISCLAIM ANY WARRANTIES,INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND
THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE,
SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

231
wxPython/wxSWIG/Makefile.in Normal file
View File

@@ -0,0 +1,231 @@
#######################################################################
# $Header$
# Simplified Wrapper and Interface Generator (SWIG)
#
# Makefile for version 1.1
# Dave Beazley
# January 7, 1997
#
# This makefile is now mostly constructed by ./configure.
#
# $Log$
# Revision 1.1 2002/04/29 19:56:47 RD
# Since I have made several changes to SWIG over the years to accomodate
# special cases and other things in wxPython, and since I plan on making
# several more, I've decided to put the SWIG sources in wxPython's CVS
# instead of relying on maintaining patches. This effectivly becomes a
# fork of an obsolete version of SWIG, :-( but since SWIG 1.3 still
# doesn't have some things I rely on in 1.1, not to mention that my
# custom patches would all have to be redone, I felt that this is the
# easier road to take.
#
# Revision 1.3 1999/08/17 03:31:30 beazley
# Minor cleanup. Removed Perl4
#
# Revision 1.2 1999/02/28 02:44:43 beazley
# Initial cleanup
#
# Revision 1.1.1.1 1999/02/28 02:00:49 beazley
# Swig1.1
#
# Revision 1.1 1996/08/12 01:55:02 dmb
# Initial revision
#
#######################################################################
srcdir = @srcdir@
VPATH = @srcdir@
#
# Set the prefix below to indicate where you want SWIG to install its
# files. Normally this is /usr/local
#
prefix = @prefix@
exec_prefix= @exec_prefix@
# Location of the SWIG library. Is normally put in /usr/local/lib/swig_lib
# The SWIG library contains configuration files and library modules
# so you should install it someplace where it can be easily accessed.
SWIG_LIB = $(prefix)/lib/swig_lib
# Change these prefixes to set where you would like the
# SWIG binary file (swig) and C library (libswig.a) installed.
# Usually you don't need to change these unless you are
# installing SWIG into a CPU dependent directory such as /usr/local/bin/cpu-type/bin
#
BIN_DIR = $(exec_prefix)/bin
LIB_DIR = $(exec_prefix)/lib
# Other installation locations. Shouldn't need to change these unless you want
INCLUDE_DIR = $(prefix)/include
MAN_DIR = $(prefix)/man/man1
SHELL = /bin/sh
# --with-PACKAGE options for configure script.
WITH=
#
#
#
# Rules for creation of a .o file from .cxx
all: wxswig
@echo "Compilation complete."
wxswig: Makefiles
@echo "Making the SWIG Parser..."
@cd SWIG; $(MAKE)
@echo "Make Modules..."
@cd Modules; $(MAKE)
Makefiles: config.status
@cd SWIG; echo "making Makefile in subdirectory SWIG"; $(MAKE) Makefile
@cd Modules; echo "making Makefile in subdirectory Modules"; $(MAKE) Makefile
Makefile: Makefile.in config.status
CONFIG_FILES=Makefile $(SHELL) config.status
config.status: $(srcdir)/configure
if test -f config.status; \
then $(SHELL) config.status --recheck; \
$(SHELL) config.status; \
else $(SHELL) $(srcdir)/configure $(WITH); \
fi
.PRECIOUS: config.status swig
clean:
rm -f *.o *.so libswig.a swig *~ core
@cd SWIG; $(MAKE) clean
@cd Modules; $(MAKE) clean
@cd Runtime; $(MAKE) clean
nuke: clean
@cd SWIG; $(MAKE) nuke
@cd Modules; $(MAKE) nuke
@cd Examples; $(MAKE) nuke
@cd Tests; $(MAKE) clean
@cd Runtime; $(MAKE) clean
rm -f Makefile Makefile.template config.*
doc: swig
@echo "Building Documentation for SWIG library..."
./swig -Iswig_lib -d ./Doc/swiglib ./swig_lib/autodoc.i
@rm -f swig_lib/autodoc_wrap*
runtime: swig
@cd Runtime; $(MAKE)
test::
cd Tests; $(MAKE) parser; $(MAKE) doc; $(MAKE) huge;
@echo "See test.log for errors"
@echo "type 'make testclean' to cleanup."
testbuild::
cd Tests; $(MAKE) build
testall::
cd Tests; $(MAKE) all; $(MAKE) clean
# Only do this before releasing a distribution
testclean::
cd Tests; $(MAKE) clean;
## # Install the SWIG program
##
## INSTALL = ./install-sh -c
## INSTALL_DATA = ${INSTALL} -m 644
## INSTALL_PROGRAM= ${INSTALL} -m 755
##
## install: install-main install-lib install-runtime
## @echo "Installation complete"
##
## install-runtime:
## @cd Runtime; $(MAKE) install
##
## smallinstall: install-main
##
## install-main:
## @for i in $(LIB_DIR) $(INCLUDE_DIR) $(BIN_DIR) $(prefix)/man $(MAN_DIR); \
## do \
## if [ ! -d $$i ] ; then \
## mkdir $$i; \
## echo "Making directory $$i"; \
## chmod 755 $$i;\
## else true; \
## fi; \
## done;
## @echo "Installing $(BIN_DIR)/swig"
## @$(INSTALL_PROGRAM) swig $(BIN_DIR)/swig
## @echo "Installing $(LIB_DIR)/libswig.a..."
## @$(INSTALL_DATA) libswig.a $(LIB_DIR)/libswig.a
## @echo "Installing $(INCLUDE_DIR)/swig.h..."
## @$(INSTALL_DATA) Include/swig.h $(INCLUDE_DIR)/swig.h
## @echo "Installing $(INCLUDE_DIR)/swigver.h..."
## @$(INSTALL_DATA) Include/swigver.h $(INCLUDE_DIR)/swigver.h
## @echo "Installing $(MAN_DIR)/swig.1..."
## @$(INSTALL_DATA) swig.1 $(MAN_DIR)/swig.1
## install-lib:
## @for i in $(SWIG_LIB) ; \
## do \
## if [ ! -d $$i ] ; then \
## mkdir $$i; \
## echo "Making directory $$i"; \
## chmod 755 $$i;\
## else true; \
## fi; \
## done;
## @echo "Installing the SWIG library"
## # cd $(SWIG_LIB); rm -rf *
## @for i in $(SWIG_LIB)/tcl $(SWIG_LIB)/perl5 $(SWIG_LIB)/python $(SWIG_LIB)/guile $(SWIG_LIB)/config ; \
## do \
## if [ ! -d $$i ] ; then \
## mkdir $$i; \
## echo "Making directory $$i"; \
## chmod 755 $$i;\
## else true; \
## fi; \
## done;
## @cd swig_lib; for i in *.i *.swg; \
## do \
## echo "Installing swig_lib/$$i"; \
## ../$(INSTALL_DATA) $$i $(SWIG_LIB)/$$i; \
## done;
## @cd swig_lib/tcl; for i in *.i *.swg Makefile; \
## do \
## echo "Installing swig_lib/tcl/$$i"; \
## ../../$(INSTALL_DATA) $$i $(SWIG_LIB)/tcl/$$i; \
## done;
## @cd swig_lib/perl5; for i in *.i *.swg Makefile Makefile.pl; \
## do \
## echo "Installing swig_lib/perl5/$$i"; \
## ../../$(INSTALL_DATA) $$i $(SWIG_LIB)/perl5/$$i; \
## done;
## @cd swig_lib/python; for i in *.i *.swg Makefile; \
## do \
## echo "Installing swig_lib/python/$$i"; \
## ../../$(INSTALL_DATA) $$i $(SWIG_LIB)/python/$$i; \
## done;
## @cd swig_lib/guile; for i in *.i *.swg; \
## do \
## echo "Installing swig_lib/guile/$$i"; \
## ../../$(INSTALL_DATA) $$i $(SWIG_LIB)/guile/$$i; \
## done;
## @cd swig_lib/config; for i in *.swg; \
## do \
## echo "Installing swig_lib/config/$$i"; \
## ../../$(INSTALL_DATA) $$i $(SWIG_LIB)/config/$$i; \
## done;
## @echo "Installing Makefile"
## $(INSTALL_DATA) Makefile.template $(SWIG_LIB)/Makefile

View File

@@ -0,0 +1,105 @@
#######################################################################
# $Header$
# Simplified Wrapper and Interface Generator (SWIG)
#
# Makefile for version 1.0 Final
# Dave Beazley
# August 1, 1996
#
# This makefile is now mostly constructed by ./configure.
#
# $Log$
# Revision 1.1 2002/04/29 19:56:47 RD
# Since I have made several changes to SWIG over the years to accomodate
# special cases and other things in wxPython, and since I plan on making
# several more, I've decided to put the SWIG sources in wxPython's CVS
# instead of relying on maintaining patches. This effectivly becomes a
# fork of an obsolete version of SWIG, :-( but since SWIG 1.3 still
# doesn't have some things I rely on in 1.1, not to mention that my
# custom patches would all have to be redone, I felt that this is the
# easier road to take.
#
# Revision 1.2 1999/08/17 03:31:30 beazley
# Minor cleanup. Removed Perl4
#
# Revision 1.1.1.1 1999/02/28 02:00:50 beazley
# Swig1.1
#
# Revision 1.1 1996/08/12 01:55:02 dmb
# Initial revision
#
#######################################################################
#.KEEP_STATE:
srcdir = @srcdir@
VPATH = @srcdir@
# Set your C++ compiler here. g++ works on most machines,
# but you might have to change it depending on your installation.
#
CC = @CXX@
#
# Set the prefix below to indicate where you want SWIG to install its
# files. Normally this is /usr/local
#
prefix = @prefix@
# Location of the SWIG library. Is normally put in /usr/local/lib/swig_lib
# The SWIG library contains configuration files and library modules
# so you should install it someplace where it can be easily accessed.
SWIG_LIB = $(prefix)/lib/swig_lib
########################################################################
# Normally, you shouldn't have to change anything below this point #
########################################################################
WRAPOBJS = swigmain.o tcl.o tcl8.o perl5.o python.o pycpp.o guile.o debug.o
WRAPSRCS = swigmain.cxx tcl.cxx tcl8.cxx perl5.cxx python.cxx pycpp.cxx guile.cxx debug.cxx
WRAPHEADERS = ../Include/swig.h swigtcl.h perl5.h python.h guile.h debug.h wrap.h
TARGET = ../wxswig
##-DSWIG_LIB='"$(SWIG_LIB)"'
CFLAGS = @CFLAGS@ -DSWIG_CC='"$(CC)"' @DEFS@
INCLUDE = -I../Include -I../SWIG
LIBS = -L.. -lswig
SHELL = /bin/sh
#
#
#
# Rules for creation of a .o file from .cxx
.SUFFIXES: .cxx
.cxx.o:
$(CC) $(INCLUDE) $(CFLAGS) -c -o $*.o $<
all: $(TARGET)
$(TARGET): $(WRAPOBJS) $(WRAPHEADERS) ../libswig.a
$(CC) $(INCLUDE) $(WRAPOBJS) $(LIBS) -o $(TARGET)
swigmain.o: swigmain.cxx
tcl.o: tcl.cxx
perl5.o: perl5.cxx
python.o: python.cxx
pycpp.o: pycpp.cxx
guile.o: guile.cxx
Makefile: $(srcdir)/Makefile.in ../config.status
(cd ..; CONFIG_FILES=Modules/Makefile $(SHELL) config.status)
.PRECIOUS: Makefile
clean::
rm -f *.o $(TARGET)
nuke::
rm -f Makefile *~ #* core a.out
wc::
wc $(WRAPSRCS) *.h

View File

@@ -0,0 +1,198 @@
/*******************************************************************************
* 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.
*******************************************************************************/
/**************************************************************************
* $Header$
*
* debug.cxx
*
* This is a dummy language module that is used only for testing the SWIG
* parser.
*
* It creates a wrapper file, but only containing descriptions of what
* was wrapped.
*
***************************************************************************/
#include "swig.h"
#include "debug.h"
void DEBUGLANG::parse_args(int, char **) {
sprintf(LibDir,"%s",path);
typemap_lang = "debug";
}
void DEBUGLANG::parse() {
headers();
yyparse();
}
void DEBUGLANG::set_module(char *mod_name, char **) {
if (module) return;
module = new char[strlen(mod_name)+1];
strcpy(module,mod_name);
}
void DEBUGLANG::set_init(char *init_name) {
set_module(init_name,0);
}
void DEBUGLANG::headers(void) {
fprintf(f_header,"/* DEBUG : Language specific headers go here */\n\n");
fprintf(f_header,"/* DEBUG : Pointer conversion function here */\n\n");
fprintf(f_header,"/* DEBUG : Language specific code here */\n\n");
}
void DEBUGLANG::initialize(void) {
fprintf(f_header,"#define SWIG_init %s_init\n\n", module);
fprintf(f_header,"#define SWIG_name \"%s\"\n", module);
fprintf(f_init,"\n/* MODULE INITIALIZATION */\n\n");
fprintf(f_init,"void %s_init() {\n", module);
}
void DEBUGLANG::close(void) {
fprintf(f_init,"} /* END INIT */\n");
fprintf(f_wrappers,"SWIG POINTER-MAPPING TABLE\n\n");
emit_ptr_equivalence(f_init);
}
void DEBUGLANG::create_function(char *name, char *iname, DataType *d, ParmList *l) {
fprintf(f_wrappers,"WRAPPER : ");
emit_extern_func(name,d,l,0,f_wrappers);
fprintf(f_wrappers,"\n");
fprintf(f_init," ADD COMMAND : %s --> ", iname);
emit_extern_func(name,d,l,0,f_init);
}
void DEBUGLANG::link_variable(char *name, char *iname, DataType *t) {
fprintf(f_wrappers,"WRAPPER : ");
emit_extern_var(name,t,0,f_wrappers);
fprintf(f_init," ADD VARIABLE : %s --> ", iname);
emit_extern_var(name,t,0,f_init);
}
void DEBUGLANG::declare_const(char *name, char *, DataType *type, char *value) {
if (!value) value = "[None]";
fprintf(f_init," ADD CONSTANT : %s %s = %s\n", type->print_cast(),name,value);
}
void DEBUGLANG::add_native(char *name, char *funcname) {
fprintf(f_init," ADD NATIVE : %s --> %s\n", name, funcname);
}
void DEBUGLANG::cpp_member_func(char *name, char *iname, DataType *t, ParmList *l) {
fprintf(f_wrappers," MEMBER FUNC : ");
emit_extern_func(name,t,l,0,f_wrappers);
fprintf(f_wrappers,"\n");
if (!iname) iname = name;
fprintf(f_init," ADD MEMBER FUN : %s --> ", iname);
emit_extern_func(name,t,l,0,f_init);
}
void DEBUGLANG::cpp_constructor(char *name, char *iname, ParmList *l) {
DataType *t;
fprintf(f_wrappers," CONSTRUCTOR : ");
t = new DataType(T_USER);
sprintf(t->name,"%s",name);
t->is_pointer=1;
emit_extern_func(name,t,l,0,f_wrappers);
if (!iname) iname = name;
fprintf(f_init," ADD CONSTRUCT : %s --> ", iname);
emit_extern_func(name,t,l,0,f_init);
}
void DEBUGLANG::cpp_destructor(char *name, char *iname) {
fprintf(f_wrappers," DESTRUCTOR : ~%s();\n", name);
if (!iname) iname = name;
fprintf(f_init," ADD DESTRUCT : %s --> ~%s();\n",iname,name);
}
void DEBUGLANG::cpp_open_class(char *name, char *iname, char *ctype, int strip) {
this->Language::cpp_open_class(name, iname, ctype,strip);
fprintf(f_wrappers,"C++ CLASS START : %s %s ========================================\n\n",ctype,name);
fprintf(f_init,"\n // C++ CLASS START : %s %s\n",ctype,name);
}
void DEBUGLANG::cpp_close_class() {
fprintf(f_wrappers,"C++ CLASS END ===================================================\n\n");
fprintf(f_init," // C++ CLASS END \n\n");
}
void DEBUGLANG::cpp_inherit(char **baseclass, int) {
int i = 0;
if (baseclass) {
fprintf(f_wrappers,"inheriting from baseclass :");
while (baseclass[i]) {
fprintf(f_wrappers," %s",baseclass[i]);
i++;
}
fprintf(f_wrappers,"\n");
}
this->Language::cpp_inherit(baseclass);
}
void DEBUGLANG::cpp_variable(char *name, char *iname, DataType *t) {
fprintf(f_wrappers," ATTRIBUTE : ");
emit_extern_var(name,t,0,f_wrappers);
if (!iname) iname = name;
fprintf(f_init," ADD MEMBER : %s --> ", iname);
emit_extern_var(name,t,0,f_init);
}
void DEBUGLANG::cpp_static_func(char *name, char *iname, DataType *t, ParmList *l) {
fprintf(f_wrappers," STATIC FUNC : ");
emit_extern_func(name,t,l,0,f_wrappers);
fprintf(f_init," ADD STATIC FUNC: %s --> ", iname);
emit_extern_func(name,t,l,0,f_init);
}
void DEBUGLANG::cpp_declare_const(char *name, char *iname, DataType *t, char *value) {
if (!value) value = "[None]";
fprintf(f_wrappers," C++ CONST : %s %s = %s\n", t->print_cast(), name, value);
if (!iname) iname = name;
fprintf(f_init," ADD C++ CONST : %s --> %s = %s\n", iname, t->print_cast(), value);
}
void DEBUGLANG::cpp_static_var(char *name, char *iname, DataType *t) {
fprintf(f_wrappers," C++ STATIC VAR: ");
emit_extern_var(name,t,0,f_wrappers);
if (!iname) iname = name;
fprintf(f_init," ADD STATIC VAR : %s --> ",iname);
emit_extern_var(name,t,0,f_init);
}
void DEBUGLANG::pragma(char *lname, char *name, char *value) {
fprintf(f_wrappers,"PRAGMA : LANG = %s, NAME = %s ", lname, name);
if (value) {
fprintf(f_wrappers,", VALUE = %s\n", value);
} else {
fprintf(f_wrappers,"\n");
}
}
void DEBUGLANG::cpp_class_decl(char *name, char *, char *type) {
fprintf(f_wrappers,"C++ CLASS DECLARATION : %s %s\n", type,name);
}

View File

@@ -0,0 +1,52 @@
/*******************************************************************************
* 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.
*******************************************************************************/
class DEBUGLANG : public Language {
private:
char *path;
char *module;
public:
DEBUGLANG() {
path = "debug";
module = "swig";
}
void parse_args(int argc, char *argv[]);
void parse();
void create_function(char *, char *, DataType *, ParmList *);
void link_variable(char *, char *, DataType *) ;
void declare_const(char *, char *, DataType *, char *);
void initialize(void);
void headers(void);
void close(void);
void set_module(char *mod_name, char **mod_list);
void set_init(char *init_name);
void add_native(char *, char *);
char *type_mangle(DataType *t) {
return t->print_mangle_default();
}
void cpp_member_func(char *, char *, DataType *, ParmList *);
void cpp_constructor(char *, char *, ParmList *);
void cpp_destructor(char *, char *);
void cpp_open_class(char *, char *, char *, int strip);
void cpp_close_class();
void cpp_inherit(char **, int mode = INHERIT_ALL);
void cpp_variable(char *, char *, DataType *);
void cpp_static_func(char *, char *, DataType *, ParmList *);
void cpp_declare_const(char *, char *, DataType *, char *);
void cpp_static_var(char *, char *, DataType *);
void pragma(char *, char *, char *);
void cpp_class_decl(char *, char *, char *);
};

View File

@@ -0,0 +1,841 @@
/*******************************************************************************
* 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.
*******************************************************************************/
/***********************************************************************
* $Header$
*
* guile.cxx
*
* Definitions for adding functions to Guile 3.0
***********************************************************************/
#include "swig.h"
#include "guile.h"
static char *guile_usage = "\
Guile Options (available with -guile)\n\
None available. \n\n";
// ---------------------------------------------------------------------
// GUILE::parse_args(int argc, char *argv[])
//
// Parse arguments.
// ---------------------------------------------------------------------
void GUILE::parse_args(int argc, char *argv[]) {
int i;
sprintf(LibDir,"%s",guile_path);
// Look for certain command line options
// Look for additional command line options.
for (i = 1; i < argc; i++) {
if (argv[i]) {
if (strcmp(argv[i],"-help") == 0) {
fputs(guile_usage,stderr);
SWIG_exit(0);
}
}
}
// Add a symbol for this module
add_symbol("SWIGGUILE",0,0);
// Set name of typemaps
typemap_lang = "guile";
}
// --------------------------------------------------------------------
// GUILE::parse()
//
// Parse the input file
// --------------------------------------------------------------------
void GUILE::parse()
{
printf("Generating wrappers for Guile\n");
// Print out GUILE specific headers
headers();
// Run the parser
yyparse();
}
// ---------------------------------------------------------------------
// GUILE::set_module(char *mod_name)
//
// Sets the module name.
// Does nothing if it's already set (so it can be overridden as a command
// line option).
//
//----------------------------------------------------------------------
void GUILE::set_module(char *mod_name, char **) {
if (module) return;
module = new char[strlen(mod_name)+1];
strcpy(module,mod_name);
}
// ---------------------------------------------------------------------
// GUILE::set_init(char *iname)
//
// Sets the initialization function name.
// Does nothing if it's already set
//
//----------------------------------------------------------------------
void GUILE::set_init(char *iname) {
set_module(iname,0);
}
// ---------------------------------------------------------------------
// GUILE::headers(void)
//
// Generate the appropriate header files for GUILE interface.
// ----------------------------------------------------------------------
void GUILE::headers(void)
{
emit_banner(f_header);
fprintf(f_header,"/* Implementation : GUILE */\n\n");
fprintf(f_header,"#define SWIGGUILE\n");
fprintf(f_header,"#include <stdio.h>\n");
fprintf(f_header,"#include <string.h>\n");
fprintf(f_header,"#include <stdlib.h>\n");
// Write out hex conversion functions
if (!NoInclude) {
if (insert_file("guile.swg", f_header) == -1) {
fprintf(stderr,"SWIG : Fatal error. Unable to locate 'guile.swg' in SWIG library.\n");
SWIG_exit(1);
}
emit_hex(f_header);
} else {
fprintf(f_header,"#ifdef __cplusplus\n");
fprintf(f_header,"extern \"C\" {\n");
fprintf(f_header,"#endif\n");
fprintf(f_header,"extern void SWIG_MakePtr(char *, void *, char *);\n");
fprintf(f_header,"extern void SWIG_RegisterMapping(char *, char *, void *(*)(void *));\n");
fprintf(f_header,"extern char *SWIG_GetPtr(char *, void **, char *);\n");
fprintf(f_header,"#ifdef __cplusplus\n");
fprintf(f_header,"}\n");
fprintf(f_header,"#endif\n");
}
}
// --------------------------------------------------------------------
// GUILE::initialize()
//
// Output initialization code that registers functions with the
// interface.
// ---------------------------------------------------------------------
void GUILE::initialize()
{
int i;
if (!module) {
module = "swig_init";
fprintf(stderr,"SWIG : *** Warning. No module name specified.\n");
}
fprintf(f_header,"#define SWIG_init %s\n\n", module);
fprintf(f_init,"void %s() {\n", module);
if (InitNames) {
i = 0;
while (InitNames[i]) {
fprintf(f_init,"\t %s();\n",InitNames[i]);
i++;
}
}
}
// ---------------------------------------------------------------------
// GUILE::close(void)
//
// Wrap things up. Close initialization function.
// ---------------------------------------------------------------------
void GUILE::close(void)
{
emit_ptr_equivalence(f_init);
fprintf(f_init,"}\n");
}
// ----------------------------------------------------------------------
// GUILE::get_pointer(int parm, DataType *t)
//
// Emits code to get a pointer from a parameter and do type checking.
// parm is the parameter number. This function is only used
// in create_function().
// ----------------------------------------------------------------------
void GUILE::get_pointer(char *iname, int parm, DataType *t) {
// Pointers are read as hex-strings with encoded type information
fprintf(f_wrappers,"\t _tempc = gh_scm2newstr(s_%d, &_len);\n",parm);
fprintf(f_wrappers,"\t if (SWIG_GetPtr(_tempc, (void **) &_arg%d,",parm);
if (t->type == T_VOID) fprintf(f_wrappers,"(char *) 0)) {\n");
else
fprintf(f_wrappers,"\"%s\")) {\n", t->print_mangle());
// Now emit code according to the level of strictness desired
switch(TypeStrict) {
case 0: // No type checking
fprintf(f_wrappers,"\t}\n");
break;
case 1: // Warning message only
fprintf(f_wrappers,
"\t fprintf(stderr,\"Warning : type mismatch in argument %d of %s. Expected %s, received %%s\\n\", _tempc);\n", parm+1,iname, t->print_mangle());
fprintf(f_wrappers,"\t }\n");
break;
case 2: // Super strict mode.
// fprintf(f_wrappers,"\t\t gscm_error(\"Type error in argument %d of %s. Expected %s.\", s_%d);\n", parm+1,iname,t->print_mangle(),parm);
fprintf(f_wrappers,"\t}\n");
break;
default :
fprintf(stderr,"Unknown strictness level\n");
break;
}
}
// ----------------------------------------------------------------------
// GUILE::create_function(char *name, char *iname, DataType *d,
// ParmList *l)
//
// Create a function declaration and register it with the interpreter.
// ----------------------------------------------------------------------
void GUILE::create_function(char *name, char *iname, DataType *d, ParmList *l)
{
Parm *p;
int pcount;
char wname[256];
char source[64];
char target[64];
char *tm;
String cleanup;
int need_len = 0;
int need_tempc = 0;
// Make a wrapper name for this
strcpy(wname,iname);
make_wrap_name(wname);
// Now write the wrapper function itself....this is pretty ugly
fprintf(f_wrappers,"SCM _wrap_gscm_%s(",wname);
int i = 0;
p = l->get_first();
while (p != 0) {
if (p->t->is_pointer)
need_len = 1;
if ((p->t->type != T_CHAR) && (p->t->is_pointer))
need_tempc = 1;
if ((p->t->type != T_VOID) || (p->t->is_pointer))
fprintf(f_wrappers,"SCM s_%d", i);
if ((p = l->get_next()))
fprintf(f_wrappers,", ");
i++;
}
fprintf(f_wrappers,")\n{\n");
// Declare return variable and arguments
pcount = emit_args(d,l,f_wrappers);
// Now declare a few helper variables here
if (d->is_pointer && (d->type != T_CHAR) &&
!typemap_lookup("out","guile",d,name,"_result","scmresult"))
fprintf(f_wrappers," char _ptemp[128];\n");
if (need_tempc)
fprintf(f_wrappers," char *_tempc;\n");
if (need_len)
fprintf(f_wrappers," int _len;\n");
fprintf(f_wrappers," SCM scmresult; /* fun1 */\n");
// Now write code to extract the parameters(this is super ugly)
i = 0;
p = l->get_first();
while (p != 0) {
// Produce names of source and target
sprintf(source,"s_%d",i);
sprintf(target,"_arg%d",i);
if ((tm = typemap_lookup("in","guile",p->t,p->name,source,target))) {
// Yep. Use it instead of the default
fprintf(f_wrappers,"%s\n", tm);
} else {
if (!p->t->is_pointer) {
switch(p->t->type) {
// Signed Integers
case T_INT :
case T_SINT :
case T_SHORT:
case T_SSHORT:
case T_LONG:
case T_SLONG:
case T_SCHAR:
fprintf(f_wrappers,"\t _arg%d = %s gh_scm2long(s_%d);\n",i, p->t->print_cast(), i);
break;
// Unsigned Integers
case T_UINT:
case T_USHORT:
case T_ULONG:
case T_UCHAR:
fprintf(f_wrappers,"\t _arg%d = %s gh_scm2ulong(s_%d);\n", i, p->t->print_cast(), i);
break;
// A single character
case T_CHAR :
fprintf(f_wrappers,"\t _arg%d = %s gh_scm2char(s_%d);\n", i, p->t->print_cast(), i);
break;
// Floating point
case T_DOUBLE :
case T_FLOAT:
fprintf(f_wrappers,"\t _arg%d = %s gh_scm2double(s_%d);\n", i, p->t->print_cast(), i);
break;
// Void.. Do nothing.
case T_VOID :
break;
// This is some sort of user-defined call by value type. We're
// going to try and wing it here....
case T_USER:
// User defined type not allowed by value.
default :
fprintf(stderr,"%s : Line %d. Unable to use type %s as a function argument.\n",
input_file, line_number, p->t->print_type());
break;
}
} else {
// Argument is a pointer type. Special case is for char *
// since that is usually a string.
if ((p->t->type == T_CHAR) && (p->t->is_pointer == 1)) {
fprintf(f_wrappers,"\t _arg%d = gh_scm2newstr(s_%d, &_len);\n",i,i);
} else {
// Have a generic pointer type here.
get_pointer(iname, i, p->t);
}
}
}
if ((tm = typemap_lookup("check","guile",p->t,p->name,source,target))) {
// Yep. Use it instead of the default
fprintf(f_wrappers,"%s\n",tm);
}
if ((tm = typemap_lookup("freearg","guile",p->t,p->name,target,"scmresult"))) {
// Yep. Use it instead of the default
cleanup << tm << "\n";
}
p = l->get_next();
i++;
}
// Now write code to make the function call
fprintf(f_wrappers,"\t SCM_DEFER_INTS;\n");
emit_func_call(name,d,l,f_wrappers);
fprintf(f_wrappers,"\t SCM_ALLOW_INTS;\n");
// Now have return value, figure out what to do with it.
if ((d->type != T_VOID) || (d->is_pointer)) {
if ((tm = typemap_lookup("out","guile",d,name,"_result","scmresult"))) {
// Yep. Use it instead of the default
fprintf(f_wrappers,"%s\n",tm);
} else {
if (!d->is_pointer) {
switch(d->type) {
case T_INT: case T_SINT:
case T_SHORT: case T_SSHORT:
case T_LONG: case T_SLONG:
case T_SCHAR:
fprintf(f_wrappers,"\t scmresult = gh_long2scm((long) _result);\n");
break;
case T_UINT:
case T_USHORT:
case T_ULONG:
case T_UCHAR:
fprintf(f_wrappers,"\t scmresult = gh_ulong2scm((unsigned long) _result);\n");
break;
case T_DOUBLE :
case T_FLOAT:
fprintf(f_wrappers,"\t scmresult = gh_double2scm((double) _result);\n");
break;
case T_CHAR :
fprintf(f_wrappers,"\t scmresult = gh_char2scm(_result);\n");
break;
default:
fprintf(stderr,"%s : Line %d: Unable to use return type %s in function %s.\n",
input_file, line_number, d->print_type(), name);
break;
}
} else {
// Is a pointer return type
if ((d->type == T_CHAR) && (d->is_pointer == 1)) {
fprintf(f_wrappers,"\t scmresult = gh_str02scm(_result);\n");
} else {
// Is an ordinary pointer type.
fprintf(f_wrappers,"\t SWIG_MakePtr(_ptemp, _result,\"%s\");\n",
d->print_mangle());
fprintf(f_wrappers,"\t scmresult = gh_str02scm(_ptemp);\n");
}
}
}
} else {
/* Some void type. Need to return something. I'll return 1 */
fprintf(f_wrappers,"\t scmresult = gh_int2scm(1);\n");
}
// Dump the argument cleanup code
fprintf(f_wrappers,"%s\n",cleanup.get());
// Look for any remaining cleanup
if (NewObject) {
if ((tm = typemap_lookup("newfree","guile",d,iname,"_result",""))) {
fprintf(f_wrappers,"%s\n",tm);
}
}
if ((tm = typemap_lookup("ret","guile",d,name,"_result",""))) {
// Yep. Use it instead of the default
fprintf(f_wrappers,"%s\n",tm);
}
// Wrap things up (in a manner of speaking)
fprintf(f_wrappers,"\t return scmresult;\n");
fprintf(f_wrappers,"}\n");
// Now register the function
fprintf(f_init,"\t gh_new_procedure(\"%s\", _wrap_gscm_%s, %d, 0, 0);\n",
iname, wname, pcount);
// Make a documentation entry for this
if (doc_entry) {
static DocEntry *last_doc_entry = 0;
char *usage = 0;
usage_func(iname,d,l,&usage);
doc_entry->usage << usage;
if (last_doc_entry != doc_entry) {
doc_entry->cinfo << "returns " << d->print_type();
last_doc_entry = doc_entry;
}
delete usage;
}
}
// -----------------------------------------------------------------------
// GUILE::link_variable(char *name, char *iname, DataType *d)
//
// Create a link to a C variable.
// This creates a single function _wrap_gscm_var_varname().
// This function takes a single optional argument. If supplied, it means
// we are setting this variable to some value. If ommitted, it means we are
// simply evaluating this variable. Either way, we return the variables
// value.
// -----------------------------------------------------------------------
void GUILE::link_variable(char *name, char *iname, DataType *t)
{
char var_name[256];
char *tm;
char *tm2 = typemap_lookup("varout","guile",t,name,name,"scmresult");
// evaluation function names
sprintf(var_name,"_wrap_gscm_var_%s",iname);
if ((t->type != T_USER) || (t->is_pointer)) {
fprintf(f_wrappers,"SCM %s(SCM s_0) {\n", var_name);
if (!(Status & STAT_READONLY) && (t->is_pointer)) {
fprintf(f_wrappers,"\t char *_temp;\n");
fprintf(f_wrappers,"\t int _len;\n");
}
if (tm2) {
fprintf(f_wrappers,"\t char _ptemp[128];\n");
}
fprintf(f_wrappers,"\t SCM scmresult; /* fun2 */\n");
// Check for a setting of the variable value
fprintf(f_wrappers,"\t if (s_0 != GH_NOT_PASSED) {\n");
// Yup. Extract the type from s_0 and set variable value
if (Status & STAT_READONLY) {
// fprintf(f_wrappers,"\t\t gscm_error(\"Unable to set %s. Variable is read only.\", s_0);\n", iname);
} else {
if ((tm = typemap_lookup("varin","guile",t,name,"s_0",name))) {
// Yep. Use it instead of the default
fprintf(f_wrappers,"%s\n",tm);
} else {
if (!t->is_pointer) {
switch(t->type) {
// Signed Integer
case T_INT: case T_SINT:
case T_SHORT: case T_SSHORT:
case T_LONG: case T_SLONG:
case T_SCHAR:
fprintf(f_wrappers,"\t\t %s = %s gh_scm2long(s_0);\n",name, t->print_cast());
break;
// Unsigned integer
case T_UINT:
case T_USHORT:
case T_ULONG:
case T_UCHAR:
fprintf(f_wrappers,"\t\t %s = %s gh_scm2ulong(s_0);\n",name, t->print_cast());
break;
// Floating point
case T_FLOAT:
case T_DOUBLE:
fprintf(f_wrappers,"\t\t %s = %s gh_scm2double(s_0);\n",name, t->print_cast());
break;
// Character value
case T_CHAR:
fprintf(f_wrappers,"\t\t %s = gh_scm2char(s_0);\n", name);
break;
// Unknown value
default:
fprintf(stderr,"Line %d. Error, unsupported data-type.\n", line_number);
break;
}
} else {
// Have some sort of pointer type here, Process it differently
if ((t->type == T_CHAR) && (t->is_pointer == 1)) {
fprintf(f_wrappers,"\t\t _temp = gh_scm2newstr(s_0, &_len);\n");
fprintf(f_wrappers,"\t\t if (%s) { free(%s);}\n", name,name);
fprintf(f_wrappers,"\t\t %s = (char *) malloc((_len+1)*sizeof(char));\n",name);
fprintf(f_wrappers,"\t\t strncpy(%s,_temp,_len);\n",name);
fprintf(f_wrappers,"\t\t %s[_len] = 0;\n", name);
} else {
// Set the value of a pointer
fprintf(f_wrappers,"\t\t _temp = gh_scm2newstr(s_0,&_len);\n");
fprintf(f_wrappers,"\t if (SWIG_GetPtr(_temp, (void **) &%s,",name);
if (t->type == T_VOID) fprintf(f_wrappers,"(char *) 0)) {\n");
else
fprintf(f_wrappers,"\"%s\")) {\n", t->print_mangle());
// Now emit code according to the level of strictness desired
switch(TypeStrict) {
case 0: // No type checking
fprintf(f_wrappers,"\t}\n");
break;
case 1: // Warning message only
fprintf(f_wrappers,
"\t fprintf(stderr,\"Warning : type mismatch in variable %s. Expected %s, received %%s\\n\", _temp);\n", name, t->print_mangle());
fprintf(f_wrappers,"\t }\n");
break;
case 2: // Super strict mode.
// fprintf(f_wrappers,"\t\t gscm_error(\"Type error in variable %s. Expected %s.\", s_0);\n", name,t->print_mangle());
fprintf(f_wrappers,"\t}\n");
break;
default :
fprintf(stderr,"Unknown strictness level\n");
break;
}
}
}
}
}
fprintf(f_wrappers,"\t}\n");
// Now return the value of the variable (regardless of evaluating or setting)
if (tm2) {
// Yep. Use it instead of the default
fprintf(f_wrappers,"%s\n",tm);
} else {
if (!t->is_pointer) {
/* Return variable by value */
switch(t->type) {
// Signed Integer
case T_INT: case T_SINT:
case T_SHORT: case T_SSHORT:
case T_LONG: case T_SLONG:
case T_SCHAR:
fprintf(f_wrappers,"\t scmresult = gh_long2scm((long) %s);\n", name);
break;
// Unsigned integer
case T_UINT:
case T_USHORT:
case T_ULONG:
case T_UCHAR:
fprintf(f_wrappers,"\t scmresult = gh_ulong2scm((unsigned long) %s);\n",name);
break;
// Floats
case T_DOUBLE:
case T_FLOAT:
fprintf(f_wrappers,"\t scmresult = gh_double2scm((double) %s);\n", name);
break;
case T_CHAR:
fprintf(f_wrappers,"\t scmresult = gh_char2scm(%s);\n",name);
break;
default :
/* Unknown type */
break;
}
} else {
// Is a pointer return type
if ((t->type == T_CHAR) && (t->is_pointer == 1)) {
fprintf(f_wrappers,"\t scmresult = gh_str02scm(%s);\n",name);
} else {
// Is an ordinary pointer type.
fprintf(f_wrappers,"\t SWIG_MakePtr(_ptemp, %s,\"%s\");\n",name,
t->print_mangle());
fprintf(f_wrappers,"\t scmresult = gh_str02scm(_ptemp);\n");
}
}
}
fprintf(f_wrappers,"\t return scmresult;\n");
fprintf(f_wrappers,"}\n");
// Now add symbol to the Guile interpreter
fprintf(f_init,"\t gh_new_procedure(\"%s\", %s, 0, 1, 0);\n",iname, var_name);
} else {
fprintf(stderr,"%s : Line %d. ** Warning. Unable to link with type %s (ignored).\n",
input_file, line_number, t->print_type());
}
// Add a documentation entry
if (doc_entry) {
char *usage = 0;
usage_var(iname,t,&usage);
doc_entry->usage << usage;
doc_entry->cinfo << "Global : " << t->print_type() << " " << name;
delete usage;
}
}
// -----------------------------------------------------------------------
// GUILE::declare_const(char *name, char *iname, DataType *type, char *value)
//
// Makes a constant. Not sure how this is really supposed to work.
// I'm going to fake out SWIG and create a variable instead.
// ------------------------------------------------------------------------
void GUILE::declare_const(char *name, char *, DataType *type, char *value) {
int OldStatus = Status; // Save old status flags
char var_name[256];
Status = STAT_READONLY; // Enable readonly mode.
// Make a static variable;
sprintf(var_name,"_wrap_const_%s",name);
if ((type->type == T_USER) && (!type->is_pointer)) {
fprintf(stderr,"%s : Line %d. Unsupported constant value.\n", input_file, line_number);
return;
}
// Create variable and assign it a value
fprintf(f_header,"static %s %s = ", type->print_type(), var_name);
if ((type->type == T_CHAR) && (type->is_pointer <= 1)) {
fprintf(f_header,"\"%s\";\n", value);
} else {
fprintf(f_header,"%s;\n", value);
}
// Now create a variable declaration
link_variable(var_name, name, type);
Status = OldStatus;
if (doc_entry) {
char *usage = 0;
usage_const(name,type,value,&usage);
doc_entry->usage = "";
doc_entry->usage << usage;
doc_entry->cinfo = "";
doc_entry->cinfo << "Constant: " << type->print_type();
delete usage;
}
}
// ----------------------------------------------------------------------
// GUILE::usage_var(char *iname, DataType *t, char **s)
//
// Produces a usage string for a Guile variable.
// ----------------------------------------------------------------------
void GUILE::usage_var(char *iname, DataType *t, char **s) {
char temp[1024], *c;
sprintf(temp,"(%s)", iname);
c = temp + strlen(temp);
if (!((t->type != T_USER) || (t->is_pointer))) {
sprintf(c," - unsupported");
}
if (*s == 0)
*s = new char[strlen(temp)+1];
strcpy(*s,temp);
}
// ---------------------------------------------------------------------------
// GUILE::usage_func(char *iname, DataType *t, ParmList *l, char **s)
//
// Produces a usage string for a function in Guile
// ---------------------------------------------------------------------------
void GUILE::usage_func(char *iname, DataType *, ParmList *l,
char **s) {
char temp[1024];
char *c;
int i;
Parm *p;
sprintf(temp,"(%s ", iname);
c = temp + strlen(temp);
/* Now go through and print parameters */
p = l->get_first();
while (p != 0) {
/* If parameter has been named, use that. Otherwise, just print a type */
if ((p->t->type != T_VOID) || (p->t->is_pointer)) {
if (strlen(p->name) > 0) {
sprintf(c,"%s ",p->name);
c += strlen(p->name)+1;
}
else {
sprintf(c,"%s",p->t->name);
c += strlen(p->t->name);
if (p->t->is_pointer) {
for (i = 0; i < (p->t->is_pointer-p->t->implicit_ptr); i++) {
sprintf(c,"*");
c++;
}
}
}
}
p = l->get_next();
if (p != 0) {
sprintf(c," ");
c++;
}
}
sprintf(c,")");
if (*s == 0)
*s = new char[strlen(temp)+1];
strcpy(*s,temp);
}
// ----------------------------------------------------------------------
// GUILE::usage_const(char *iname, DataType *type, char *value, char **s)
//
// Produces a usage string for a Guile constant
// ----------------------------------------------------------------------
void GUILE::usage_const(char *iname, DataType *, char *value, char **s) {
char temp[1024];
sprintf(temp,"(%s %s)", iname, value);
if (*s == 0)
*s = new char[strlen(temp)+1];
strcpy(*s,temp);
}

View File

@@ -0,0 +1,57 @@
/*******************************************************************************
* 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.
*******************************************************************************/
/**************************************************************************
* $Header$
*
* class GUILE
*
* Guile implementation
* (Caution : This is *somewhat* experimental)
*
* Seeking : highly motivated individual with plenty of spare time and
* a love of Guile. Must be willing to modify this code and
* make it better.
**************************************************************************/
class GUILE : public Language {
private:
char *guile_path;
char *module;
void get_pointer(char *iname, int parm, DataType *t);
void usage_var(char *, DataType *, char **);
void usage_func(char *, DataType *, ParmList *, char **);
void usage_const(char *, DataType *, char *, char **);
public :
GUILE() {
module = 0;
guile_path = "guile";
}
void parse_args(int, char *argv[]);
void parse();
void create_function(char *, char *, DataType *, ParmList *);
void link_variable(char *, char *, DataType *);
void declare_const(char *, char *, DataType *, char *);
void initialize();
void headers(void);
void close(void);
void set_module(char *, char **);
void set_init(char *);
void create_command(char *, char *) { };
};

View File

@@ -0,0 +1,79 @@
# Modified from automatic creation by Kevin Butler (butler@byu.edu)
# for Microsoft Visual C++ (11/22/96)
#
#######################################################################
# $Header$
# Simplified Wrapper and Interface Generator (SWIG)
#
# Makefile for version 1.0 Final
# Dave Beazley
# August 1, 1996
#
# This makefile is now mostly constructed by ./configure.
#
# $Log$
# Revision 1.1 2002/04/29 19:56:47 RD
# Since I have made several changes to SWIG over the years to accomodate
# special cases and other things in wxPython, and since I plan on making
# several more, I've decided to put the SWIG sources in wxPython's CVS
# instead of relying on maintaining patches. This effectivly becomes a
# fork of an obsolete version of SWIG, :-( but since SWIG 1.3 still
# doesn't have some things I rely on in 1.1, not to mention that my
# custom patches would all have to be redone, I felt that this is the
# easier road to take.
#
# Revision 1.2 1999/08/17 03:31:30 beazley
# Minor cleanup. Removed Perl4
#
# Revision 1.1.1.1 1999/02/28 02:00:50 beazley
# Swig1.1
#
# Revision 1.1 1996/08/12 01:55:02 dmb
# Initial revision
#
#######################################################################
#.KEEP_STATE:
rootdir = ..
!include <..\make_win.in>
########################################################################
# Normally, you shouldn't have to change anything below this point #
########################################################################
WRAPOBJS = swigmain.obj tcl.obj tcl8.obj perl5.obj python.obj pycpp.obj debug.obj guile.obj
WRAPSRCS = swigmain.cxx tcl.cxx tcl8.cxx perl5.cxx python.cxx pycpp.cxx debug.cxx guile.cxx
WRAPHEADERS = $(rootdir)/Include/swig.h swigtcl.h tcl8.h perl5.h python.h guile.h debug.h \
wrap.h
TARGET = $(rootdir)\wxswig.exe
LIBNAME = $(rootdir)\libswig.lib
LIBS = $(LIBNAME)
#
# Rules for creation of a .obj file from .cxx
.SUFFIXES: .cxx
.cxx.obj:
$(CC) $(INCFLAGS) $(CFLAGS) -c -o $*.obj $<
all: $(TARGET)
$(TARGET): $(WRAPOBJS) $(WRAPHEADERS) $(LIBNAME)
$(CC) -o $(TARGET) $(INCFLAGS) $(WRAPOBJS) $(LIBS)
swigmain.obj: swigmain.cxx
tcl.obj: tcl.cxx
perl5.obj: perl5.cxx
python.obj: python.cxx
pycpp.obj: pycpp.cxx
guile.obj: guile.cxx
clean::
del *.obj
del $(TARGET)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,105 @@
/****************************************************************************
* 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.
****************************************************************************/
/**************************************************************************
* class PERL5
*
* A Perl 5 implementation
**************************************************************************/
class PERL5 : public Language {
private:
int export_all;
char *package;
char *module;
String cmodule;
String vinit;
FILE *f_pm;
String pm; // Package initialization code
String magic; // Magic variable wrappers
char *perl_path;
int is_static;
void get_pointer(char *iname, char *srcname, char *src, char *dest,
DataType *t, String &f, char *ret);
char *usage_var(char *, DataType *);
char *usage_func(char *, DataType *, ParmList *);
char *usage_const(char *, DataType *, char *);
char *alt_header;
// The following variables are used to manage Perl5 classes
int blessed; // Enable object oriented features
Hash classes; // A hash table for storing the classes we've seen so far
int have_constructor;
int have_destructor;
int have_data_members;
char *class_name; // Name of the class (what Perl thinks it is)
char *class_type; // Type of class "struct", "class", "union"
char *real_classname; // Real name of C/C++ class
String *base_class; // Base class (if using inheritance)
String *pcode; // Perl code associated with each class
String *blessedmembers; // Member data associated with each class
int member_func; // Set to 1 when wrapping a member function
char *realpackage; // Name of real module
String func_stubs; // Function stubs
String var_stubs; // Variable stubs
String *member_keys; // Keys for all member data
String exported; // Exported symbols
public :
PERL5() {
package = 0;
module = 0;
perl_path = "perl5";
is_static = 0;
blessed = 0;
alt_header = 0;
member_func = 0;
};
void parse_args(int, char *argv[]);
void parse();
void create_function(char *, char *, DataType *, ParmList *);
void link_variable(char *, char *, DataType *);
void declare_const(char *, char *, DataType *, char *);
void initialize(void);
void headers(void);
void close(void);
void set_module(char *, char **);
void set_init(char *);
void add_native(char *, char *);
void create_command(char *, char *);
char *type_mangle(DataType *);
// Support for blessed perl thingies....
void cpp_open_class(char *classname, char *rename, char *ctype, int strip);
void cpp_close_class();
void cpp_member_func(char *name, char *iname, DataType *t, ParmList *l);
void cpp_static_func(char *name, char *iname, DataType *t, ParmList *l);
void cpp_variable(char *name, char *iname, DataType *t);
void cpp_constructor(char *name, char *iname, ParmList *l);
void cpp_destructor(char *name, char *newname);
void cpp_inherit(char **baseclass, int mode = INHERIT_ALL);
void cpp_declare_const(char *name, char *iname, DataType *type, char *value);
void cpp_class_decl(char *, char *, char *);
void add_typedef(DataType *t, char *name);
void pragma(char *, char *, char *);
void import(char *filename);
};

View File

@@ -0,0 +1,517 @@
/*******************************************************************************
* 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.
*******************************************************************************/
/**********************************************************************
* $Header$
*
* pycpp.cxx
*
* This module contains code to generate Python shadow classes of C/C++
* objects.
**************************************************************************/
#include "swig.h"
#include "python.h"
static String *setattr;
static String *getattr;
static String *pyclass;
static String *construct;
static String *cinit;
static String *additional;
static int have_constructor;
static int have_destructor;
static int have_getattr;
static int have_setattr;
static int have_repr;
static char *class_name;
static char *class_type;
static char *real_classname;
static String *base_class;
static String base_getattr;
static String base_setattr;
static int class_renamed = 0;
// --------------------------------------------------------------------------
// PYTHON::cpp_open_class(char *classname, char *rname, char *ctype, int strip)
//
// Opens a new C++ class or structure.
// --------------------------------------------------------------------------
void PYTHON::cpp_open_class(char *classname, char *rname, char *ctype, int strip) {
char temp[256];
this->Language::cpp_open_class(classname, rname, ctype, strip);
if (shadow) {
/* Create new strings for building up a wrapper function */
setattr = new String();
getattr = new String();
pyclass = new String();
construct = new String();
cinit = new String();
additional= new String();
base_class = 0;
base_getattr = "";
base_setattr = "";
// *pyclass << "class " << rname << ":\n";
*setattr << tab4 << "def __setattr__(self,name,value):\n";
*getattr << tab4 << "def __getattr__(self,name):\n";
have_constructor = 0;
have_destructor = 0;
have_getattr = 0;
have_setattr = 0;
have_repr = 0;
if (rname) {
class_name = copy_string(rname);
class_renamed = 1;
} else {
class_name = copy_string(classname);
class_renamed = 0;
}
}
real_classname = copy_string(classname);
class_type = copy_string(ctype);
// Build up the hash table
hash.add(real_classname,copy_string(class_name));
sprintf(temp,"%s %s", class_type, real_classname);
hash.add(temp,copy_string(class_name));
}
// --------------------------------------------------------------------------
// PYTHON::cpp_member_func(char *name, char *iname, DataType *t, ParmList *l)
//
// Creates a C++ member function
// --------------------------------------------------------------------------
void PYTHON::cpp_member_func(char *name, char *iname, DataType *t, ParmList *l) {
Parm *p;
int i;
char *realname;
int oldshadow;
int pcount;
int numopt;
int have_optional;
String cname = "python:";
String translate = "";
// Create the default member function
oldshadow = shadow; // Disable shadowing when wrapping member functions
if (shadow) shadow = shadow | PYSHADOW_MEMBER;
this->Language::cpp_member_func(name,iname,t,l);
shadow = oldshadow;
if (shadow) {
if (!iname)
realname = name;
else
realname = iname;
// Check to see if we've already seen this
cname << class_name << "::" << realname;
if (add_symbol(cname.get(), 0,0)) {
return; // Forget it, already saw it
}
if (strcmp(realname,"__repr__") == 0)
have_repr = 1;
// Now add it to the class
*pyclass << tab4 << "def " << realname << "(self, *_args, **_kwargs):\n";
// Create a doc string
if (docstring && doc_entry) {
*pyclass << tab8 << "\"\"\"" << add_docstring(doc_entry) << "\"\"\"\n";
}
*pyclass << tab8 << "val = apply(" << module << "." << name_member(realname,class_name) << ",(self,) + _args, _kwargs)\n";
// Check to see if the return type is an object
if ((hash.lookup(t->name)) && (t->is_pointer <= 1)) {
if (!typemap_check("out",typemap_lang,t,name_member(realname,class_name))) {
if (!have_output) {
*pyclass << tab8 << "if val: val = " << (char *) hash.lookup(t->name) << "Ptr(val) ";
if (((hash.lookup(t->name)) && (t->is_pointer < 1)) ||
((hash.lookup(t->name)) && (t->is_pointer == 1) && NewObject))
*pyclass << "; val.thisown = 1\n";
else
*pyclass << "\n";
} else {
// Do nothing!
}
}
}
emitAddPragmas(*pyclass, realname, tab8);
*pyclass << tab8 << "return val\n";
// Change the usage string to reflect our shadow class
if (doc_entry) {
doc_entry->usage = "";
doc_entry->usage << usage_func(realname,t,l);
}
}
}
// -----------------------------------------------------------------------------
// void PYTHON::cpp_constructor(char *name, char *iname, ParmList *l)
//
// Make a constructor for our class
// -----------------------------------------------------------------------------
void PYTHON::cpp_constructor(char *name, char *iname, ParmList *l) {
char *realname;
Parm *p;
int i;
int oldshadow = shadow;
String cname = "python:constructor:";
String translate = "";
int pcount, numopt;
int have_optional;
if (shadow) shadow = shadow | PYSHADOW_MEMBER;
this->Language::cpp_constructor(name,iname,l);
shadow = oldshadow;
if (shadow) {
if (iname)
realname = iname;
else {
if (class_renamed) realname = class_name;
else realname = class_name;
}
// Check to see if we've already seen this
cname << class_name << "::" << realname;
if (add_symbol(cname.get(), 0,0)) {
return; // Forget it, already seen it
}
if (!have_constructor) {
// Create a new constructor
*construct << tab4 << "def __init__(self,*_args,**_kwargs):\n";
if (docstring && doc_entry)
*construct << tab8 << "\"\"\"" << add_docstring(doc_entry) << "\"\"\"\n";
*construct << tab8 << "self.this = apply(" << module << "." << name_construct(realname) << ",_args,_kwargs)\n";
*construct << tab8 << "self.thisown = 1\n";
emitAddPragmas(*construct,"__init__",tab8);
have_constructor = 1;
} else {
// Hmmm. We seem to be creating a different constructor. We're just going to create a
// function for it.
*additional << "def " << realname << "(*_args,**_kwargs):\n";
*additional << tab4 << "val = " << class_name << "Ptr(apply("
<< module << "." << name_construct(realname) << ",_args,_kwargs))\n"
<< tab4 << "val.thisown = 1\n";
emitAddPragmas(*additional, realname, tab4);
*additional << tab4 << "return val\n\n";
}
// Patch up the documentation entry
if (doc_entry) {
doc_entry->usage = "";
doc_entry->usage << usage_func(class_name,0,l);
}
}
}
// ------------------------------------------------------------------------------
// void PYTHON::cpp_destructor(char *name, char *newname)
//
// Creates a destructor for this object
// ------------------------------------------------------------------------------
void PYTHON::cpp_destructor(char *name, char *newname) {
char *realname;
int oldshadow = shadow;
if (shadow) shadow = shadow | PYSHADOW_MEMBER;
this->Language::cpp_destructor(name,newname);
shadow = oldshadow;
if (shadow) {
if (newname) realname = newname;
else {
if (class_renamed) realname = class_name;
else realname = name;
}
*pyclass << tab4 << "def __del__(self," << module << "=" << module << "):\n";
emitAddPragmas(*pyclass,"__del__",tab8);
*pyclass << tab8 << "if self.thisown == 1 :\n"
<< tab8 << tab4 << module << "." << name_destroy(realname) << "(self)\n";
have_destructor = 1;
if (doc_entry) {
doc_entry->usage = "";
doc_entry->usage << "del this";
}
}
}
// -------------------------------------------------------------------------------
// PYTHON::cpp_close_class()
//
// Closes a Python class and writes out a wrapper
// -------------------------------------------------------------------------------
void PYTHON::cpp_close_class() {
String ptrclass;
String repr;
if (shadow) {
if (!have_constructor) {
// Build a constructor that takes a pointer to this kind of object
*construct << tab4 << "def __init__(self,this):\n";
*construct << tab8 << "self.this = this\n";
}
// First, build the pointer base class
if (base_class) {
ptrclass << "class " << class_name << "Ptr(" << *base_class << "):\n";
} else {
ptrclass << "class " << class_name << "Ptr :\n";
}
// *getattr << tab8 << "return self.__dict__[name]\n";
*getattr << tab8 << "raise AttributeError,name\n";
*setattr << tab8 << "self.__dict__[name] = value\n";
ptrclass << *cinit
<< tab4 << "def __init__(self,this):\n"
<< tab8 << "self.this = this\n"
<< tab8 << "self.thisown = 0\n";
classes << ptrclass
<< *pyclass;
if (have_setattr)
classes << *setattr;
if (have_getattr)
classes << *getattr;
if (!have_repr) {
// Supply a repr method for this class
repr << tab4 << "def __repr__(self):\n"
<< tab8 << "return \"<C " << class_name <<" instance at %s>\" % (self.this,)\n";
classes << repr;
emitAddPragmas(classes,"__class__",tab4);
}
// Now build the real class with a normal constructor
classes << "class " << class_name << "(" << class_name << "Ptr):\n";
if (docstring && doc_entry) {
classes << tab4 << "\"\"\"" << add_docstring(doc_entry) << "\"\"\"\n";
}
classes << *construct << "\n\n"
<< "\n" << *additional << "\n";
delete pyclass;
delete setattr;
delete getattr;
delete additional;
}
}
void PYTHON::cpp_cleanup() { };
void PYTHON::cpp_inherit(char **baseclass,int) {
char *bc;
int i = 0, first_base = 0;
if (!shadow) {
this->Language::cpp_inherit(baseclass);
return;
}
// We'll inherit variables and constants, but not methods
this->Language::cpp_inherit(baseclass, INHERIT_VAR);
if (!baseclass) return;
base_class = new String;
// Now tell the Python module that we're inheriting from a base class
while (baseclass[i]) {
bc = (char *) hash.lookup(baseclass[i]);
if (bc) {
if (first_base) *base_class << ",";
*base_class << bc << "Ptr";
first_base = 1;
}
i++;
}
if (!first_base) {
delete base_class;
base_class = 0;
}
}
// --------------------------------------------------------------------------------
// PYTHON::cpp_variable(char *name, char *iname, DataType *t)
//
// Adds an instance member.
// --------------------------------------------------------------------------------
void PYTHON::cpp_variable(char *name, char *iname, DataType *t) {
char *realname;
int inhash = 0;
int oldshadow = shadow;
String cname = "python:";
if (shadow) shadow = shadow | PYSHADOW_MEMBER;
this->Language::cpp_variable(name,iname,t);
shadow = oldshadow;
if (shadow) {
have_getattr = 1;
have_setattr = 1;
if (!iname)
realname = name;
else
realname = iname;
// Check to see if we've already seen this
cname << class_name << "::" << realname;
if (add_symbol(cname.get(), 0,0)) {
return; // Forget it, already seen it
}
// Figure out if we've seen this datatype before
if ((hash.lookup(t->name)) && (t->is_pointer <= 1)) inhash = 1;
// Now write some code to set the variable
*setattr << tab8 << "if name == \"" << realname << "\" :\n";
if (inhash) {
*setattr << tab8 << tab4 << module << "." << name_set(name_member(realname,class_name)) << "(self,value.this)\n";
} else {
*setattr << tab8 << tab4 << module << "." << name_set(name_member(realname,class_name)) << "(self,value)\n";
}
*setattr << tab8 << tab4 << "return\n";
// Write some code to get the variable
*getattr << tab8 << "if name == \"" << realname << "\" : \n";
if (inhash) {
*getattr << tab8 << tab4 << "return " << (char *) hash.lookup(t->name) << "Ptr(" << module << "."
<< name_get(name_member(realname,class_name)) << "(self))\n";
} else {
*getattr << tab8 << tab4 << "return " << module << "." << name_get(name_member(realname,class_name)) << "(self)\n";
}
// Patch up ye old documentation entry
if (doc_entry) {
doc_entry->usage = "";
doc_entry->usage << "self." << realname;
}
}
}
// --------------------------------------------------------------------------------
// PYTHON::cpp_declare_const(char *name, char *iname, DataType *type, char *value)
//
// Add access to a C++ constant
// --------------------------------------------------------------------------------
void PYTHON::cpp_declare_const(char *name, char *iname, DataType *type, char *value) {
char *realname;
int oldshadow = shadow;
String cname = "python:";
if (shadow) shadow = shadow | PYSHADOW_MEMBER;
this->Language::cpp_declare_const(name,iname,type,value);
shadow = oldshadow;
if (shadow) {
if (!iname)
realname = name;
else
realname = iname;
// Check to see if we've already seen this
cname << class_name << "::" << realname;
if (add_symbol(cname.get(), 0,0)) {
return; // Forget it, already seen it
}
*cinit << tab4 << realname << " = " << module << "." << name_member(realname,class_name) << "\n";
if (doc_entry) {
doc_entry->usage = "";
doc_entry->usage << "self." << realname;
if (value) {
doc_entry->usage << " = " << value;
}
}
}
}
// --------------------------------------------------------------------------------
// PYTHON::add_typedef(DataType *t, char *name)
//
// This is called whenever a typedef is encountered. When shadow classes are
// used, this function lets us discovered hidden uses of a class. For example :
//
// struct FooBar {
// ...
// }
//
// typedef FooBar *FooBarPtr;
//
// --------------------------------------------------------------------------------
void PYTHON::add_typedef(DataType *t, char *name) {
if (!shadow) return;
// First check to see if there aren't too many pointers
if (t->is_pointer > 1) return;
if (hash.lookup(name)) return; // Already added
// Now look up the datatype in our shadow class hash table
if (hash.lookup(t->name)) {
// Yep. This datatype is in the hash
// Put this types 'new' name into the hash
hash.add(name,copy_string((char *) hash.lookup(t->name)));
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,111 @@
/*******************************************************************************
* 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.
*******************************************************************************/
/**************************************************************************
* $Header$
*
* python.h
*
* Header file for Python module. Warning ; this is work in progress.
**************************************************************************/
class PYTHON : public Language {
protected:
char *module; // Module name
char *path; // Pathname of where to look for library files
char *methods; // Method table name
char *global_name; // Name of global variables.
void get_pointer(char *iname, char *srcname, char *src, char *dest, DataType *t, String &f, char *ret);
int shadow;
int have_defarg;
int docstring;
int have_output;
int use_kw;
FILE *f_shadow;
struct Method { // Methods list. Needed to build methods
char *name; // Array at very end.
char *function;
Method *next;
};
Method *head;
Hash hash;
String classes;
String func;
String vars;
String modinit;
String modextern;
char *import_file;
void add_method(char *name, char *function);
void print_methods();
char *usage_var(char *, DataType *);
char *usage_func(char *, DataType *, ParmList *);
char *usage_const(char *, DataType *, char *);
char *add_docstring(DocEntry *de);
// Add for Python-COM support
virtual void initialize_cmodule();
virtual void close_cmodule();
virtual void emit_function_header(WrapperFunction &emit_to, char *wname);
virtual char *convert_self(WrapperFunction &f);
virtual char *make_funcname_wrapper(char *fnName);
void emitAddPragmas(String& output, char* name, char* spacing);
public :
PYTHON() {
module = (char *) 0;
path = "python"; // Set this to subdirectory where language
// Dependent library files will be stored
head = 0; // Head of method list
global_name = "cvar";
shadow = 0;
have_defarg = 0;
import_file = 0;
use_kw = 0;
};
// Don't change any of this
void parse_args(int, char *argv[]);
void parse();
void create_function(char *, char *, DataType *, ParmList *);
void link_variable(char *, char *, DataType *);
void declare_const(char *, char *, DataType *, char *);
void initialize(void);
void headers(void);
void close(void);
void set_module(char *, char **);
void set_init(char *);
void add_native(char *, char *);
void create_command(char *, char *);
void import(char *);
// C++ extensions---for creating shadow classes
void cpp_member_func(char *name, char *iname, DataType *t, ParmList *l);
void cpp_constructor(char *name, char *iname, ParmList *l);
void cpp_destructor(char *name, char *newname);
void cpp_open_class(char *classname, char *rname, char *ctype, int strip);
void cpp_close_class();
void cpp_cleanup();
void cpp_inherit(char **baseclass, int mode = INHERIT_ALL);
void cpp_variable(char *name, char *iname, DataType *t);
void cpp_declare_const(char *name, char *iname, DataType *type, char *value);
void cpp_class_decl(char *, char *,char *);
void pragma(char *, char *, char *);
void cpp_pragma(Pragma *);
void add_typedef(DataType *t, char *name);
};
#define PYSHADOW_MEMBER 0x2

View File

@@ -0,0 +1,168 @@
/*******************************************************************************
* 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.
*******************************************************************************/
/***********************************************************************
* $Header$
*
* swigmain.cxx
*
* The main program.
*
***********************************************************************/
#include "wrap.h"
#include "swigtcl.h"
#include "tcl8.h"
#include "perl5.h"
#include "python.h"
// #include "pythoncom.h"
#include "guile.h"
#include "debug.h"
#include "ascii.h"
#include "latex.h"
#include "html.h"
#include "nodoc.h"
#include <ctype.h>
static char *usage = "\
swig <options> filename\n\n\
Target Language Options:\n\
-tcl - Generate Tcl wrappers.\n\
-tcl8 - Generate Tcl 8.0 wrappers.\n\
-python - Generate Python wrappers.\n\
-perl5 - Generate Perl5 wrappers.\n\
-guile - Generate Guile wrappers.\n\
-debug - Parser debugging module.\n";
#ifdef MACSWIG
static char *macmessage = "\
Copyright (c) 1995-1997\n\
University of Utah and the Regents of the University of California\n\n\
Enter SWIG processing options and filename below. For example :\n\
\n\
-tcl -c++ interface.i\n\
\n\
-help displays a list of all available options.\n\
\n\
Note : Macintosh filenames should be enclosed in quotes if they contain whitespace.\n\
\n";
#endif
//-----------------------------------------------------------------
// main()
//
// Main program. Initializes the files and starts the parser.
//-----------------------------------------------------------------
#ifndef MACSWIG
int main(int argc, char **argv) {
#else
int Mac_main(int argc, char **argv) {
#endif
int i;
Language *dl = new SWIG_LANG;
Documentation *dd = new SWIG_DOC;
extern int SWIG_main(int, char **, Language *, Documentation *);
init_args(argc,argv);
// Get options
for (i = 1; i < argc; i++) {
if (argv[i]) {
if(strcmp(argv[i],"-tcl") == 0) {
dl = new TCL;
mark_arg(i);
} else if (strcmp(argv[i],"-tcl8") == 0) {
dl = new TCL8;
mark_arg(i);
} else if (strcmp(argv[i],"-perl5") == 0) {
dl = new PERL5;
mark_arg(i);
} else if (strcmp(argv[i],"-python") == 0) {
dl = new PYTHON;
mark_arg(i);
} else if (strcmp(argv[i],"-debug") == 0) {
dl = new DEBUGLANG;
mark_arg(i);
} else if (strcmp(argv[i],"-guile") == 0) {
dl = new GUILE;
mark_arg(i);
} else if (strcmp(argv[i],"-help") == 0) {
fputs(usage,stderr);
mark_arg(i);
}
}
}
SWIG_main(argc,argv,dl,dd);
return 0;
}
#ifdef MACSWIG
int MacMainEntry(char *options) {
static char *_argv[256];
int i,argc;
char *c,*s,*t;
swig_log = fopen("swig_log","w");
fprintf(swig_log,"SWIG 1.1\n");
fprintf(swig_log,"Options : %s\n", options);
fprintf(swig_log,"-----------------------------------------------------\n");
// Tokenize the user input
_argv[0] = "swig";
i=1;
c = options;
while (*c) {
while(isspace(*c)) c++;
if (*c) {
s = c; // Starting character
while(isgraph(*c)) {
if (*c == '\"') {
c++;
while ((*c) && (*c != '\"'))
c++;
c++;
} else {
c++;
}
}
// Found some whitespace
if (*c) {
*c = 0;
c++;
}
_argv[i] = copy_string(s);
// Go through and remove quotes (if necessary)
t = _argv[i];
while(*s) {
if (*s != '\"')
*(t++) = *s;
s++;
}
*t = 0;
i++;
}
}
argc = i;
_argv[i] = 0;
return Mac_main(argc,_argv);
}
#endif

View File

@@ -0,0 +1,115 @@
/*******************************************************************************
* 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.
*******************************************************************************/
/**************************************************************************
* class TCL
*
* A Simple TCL implementation.
**************************************************************************/
class TCL : public Language {
private:
char interp_name[256];
char *prefix; // Package prefix
char *module; // Name of the module
char *tcl_path;
char *init_name;
int Plugin;
int nspace;
char *safe_name;
void get_pointer(char *iname, char *srcname, char *src, char *dest, DataType *t,
String &f, char *ret);
char *char_result;
char *usage_string(char *, DataType *, ParmList *);
char *usage_func(char *, DataType *, ParmList *);
char *usage_var(char *, DataType *);
char *usage_const(char *, DataType *, char *);
// C++ handling
int have_constructor;
int have_destructor;
int have_methods;
int have_config;
int have_cget;
String config;
String cget;
String methods;
String options;
String config_options;
String methodnames;
String postinit;
int shadow;
char *class_name;
char *class_type;
char *real_classname;
char *base_class;
Hash hash;
Hash repeatcmd;
// C++ Code generation strings
String delcmd;
String methodcmd;
String objcmd;
public :
TCL() {
prefix = 0;
module = 0;
init_name = 0;
nspace = 0;
shadow = 1;
char_result = "TCL_VOLATILE";
tcl_path = "tcl";
sprintf(interp_name,"interp");
class_name = 0;
class_type = 0;
real_classname = 0;
base_class = 0;
};
void parse_args(int, char *argv[]);
void parse();
void create_function(char *, char *, DataType *, ParmList *);
void link_variable(char *, char *, DataType *);
void declare_const(char *, char *, DataType *, char *);
void initialize(void);
void headers(void);
void close(void);
void set_module(char *,char **);
void set_init(char *);
void add_native(char *, char *);
void pragma(char *,char *, char *);
void create_command(char *, char *);
// Stubs for processing C++ classes in Tcl
void cpp_open_class(char *classname, char *rename, char *ctype, int strip);
void cpp_close_class();
void cpp_member_func(char *name, char *iname, DataType *t, ParmList *l);
void cpp_variable(char *name, char *iname, DataType *t);
void cpp_constructor(char *name, char *iname, ParmList *l);
void cpp_destructor(char *name, char *newname);
void cpp_inherit(char **baseclass, int mode = INHERIT_ALL);
void cpp_declare_const(char *name, char *iname, DataType *type, char *value);
void cpp_class_decl(char *, char *, char *);
void add_typedef(DataType *, char *);
};

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,115 @@
/*******************************************************************************
* 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.
*******************************************************************************/
/**************************************************************************
* class TCL8
*
* A TCL implementation for Tcl 8.0. Basically the same as the other
* Tcl module, but with different code generation.
**************************************************************************/
class TCL8 : public Language {
private:
char interp_name[256];
char *prefix; // Package prefix
char *module; // Name of the module
char *tcl_path;
char *init_name;
int nspace;
void get_pointer(char *iname, char *srcname, char *src, char *dest, DataType *t,
String &f, char *ret);
char *char_result;
char *usage_func(char *, DataType *, ParmList *);
char *usage_string(char *, DataType *, ParmList *);
char *usage_var(char *, DataType *);
char *usage_const(char *, DataType *, char *);
// C++ handling
int have_constructor;
int have_destructor;
int have_methods;
int have_config;
int have_cget;
String config;
String cget;
String methods;
String options;
String config_options;
String methodnames;
String postinit;
int shadow;
char *class_name;
char *class_type;
char *real_classname;
char *base_class;
Hash hash;
Hash repeatcmd;
// Code generation options
String delcmd;
String methodcmd;
String objcmd;
public :
TCL8() {
prefix = 0;
module = 0;
init_name = 0;
nspace = 0;
shadow = 1;
char_result = "TCL_VOLATILE";
tcl_path = "tcl";
sprintf(interp_name,"interp");
class_name = 0;
class_type = 0;
real_classname = 0;
base_class = 0;
};
void parse_args(int, char *argv[]);
void parse();
void create_function(char *, char *, DataType *, ParmList *);
void link_variable(char *, char *, DataType *);
void declare_const(char *, char *, DataType *, char *);
void initialize(void);
void headers(void);
void close(void);
void set_module(char *,char **);
void set_init(char *);
void add_native(char *, char *);
void pragma(char *,char *, char *);
void create_command(char *, char *);
// Stubs for processing C++ classes in Tcl
void cpp_open_class(char *classname, char *rename, char *ctype, int strip);
void cpp_close_class();
void cpp_member_func(char *name, char *iname, DataType *t, ParmList *l);
void cpp_variable(char *name, char *iname, DataType *t);
void cpp_constructor(char *name, char *iname, ParmList *l);
void cpp_destructor(char *name, char *newname);
void cpp_inherit(char **baseclass, int mode = INHERIT_ALL);
void cpp_declare_const(char *name, char *iname, DataType *type, char *value);
void add_typedef(DataType *, char *);
void cpp_class_decl(char *, char *, char *);
};

View File

@@ -0,0 +1,38 @@
/*******************************************************************************
* 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.
*******************************************************************************/
/***********************************************************************
* $Header$
*
* wrap.h
***********************************************************************/
#include "swig.h"
#ifndef SWIG_LIB
#define SWIG_LIB getSwigLib() /*"./swig_lib"*/
#endif
#ifndef SWIG_LANG
#define SWIG_LANG PYTHON
#endif
#ifndef SWIG_DOC
#define SWIG_DOC ASCII
#endif

381
wxPython/wxSWIG/README Normal file
View File

@@ -0,0 +1,381 @@
SWIG (Simplified Wrapper and Interface Generator)
Version 1.1 (Maintenance)
Copyright (C) 1995-1999
University of Utah and the Regents of the University of California
August 8, 1999
1. Introduction
---------------
SWIG is a compiler that attempts to make it easy to integrate C, C++,
or Objective-C code with scripting languages including Perl, Tcl, and
Python. In a nutshell, you give it a bunch of ANSI C/C++ declarations
and it generates an interface between C and your favorite scripting
language. However, this is only scratching the surface of what SWIG
can do--some of its more advanced features include automatic
documentation generation, module and library management, extensive
customization options, and more.
SWIG is entirely the product of users who have used the system and
suggested new ideas. There are far too many people to thank
individually, but without this support, SWIG would be not be nearly as
powerful or fun to use as it is now. Many thanks!
2. Currently Supported Languages
----------------------------------
To use SWIG, you will need at least one of the following scripting
languages :
Tcl7.3, Tk3.6 (and all newer versions)
Tcl8.0, Tk8.0 (somewhat experimental)
Python1.3 (or newer)
Perl5.003 (or newer)
Perl4
FSF Guile 1.0 (experimental)
If you don't have any of these, SWIG will still compile, but it won't
be particularly useful. Note : it is not necessary to have *all* of
these languages installed to use SWIG--only the scripting languages you
want to use.
3. Installation (Unix)
------------------------
To compile and use SWIG, you will need the following on your machine:
A C++ compiler (ie. g++)
An ANSI C compiler (ie. gcc)
yacc or bison (only needed if you are going to rebuild the SWIG parser)
To compile and install SWIG, type the following :
./configure
make
make runtime (optional. see below)
make install
The configuration script will attempt to locate various packages on
your machine, including Tcl, Perl5, and Python. Don't panic if
you get 'not found' messages--SWIG does not need these packages
to compile or run. The configure script is actually looking for
these packages so that you can try out the SWIG examples contained
in the 'Examples' directory without having to hack Makefiles.
See the Examples section below for more details.
The 'make runtime' option is an optional step that can be used to
build the SWIG runtime libraries. These libraries are only used with
larger packages and are not necessary for learning SWIG or trying
the examples (please refer to the "Advanced topics" section of the
SWIG Users manual for more details about this).
Typing 'make test' will run a rather extensive series of tests
and can be run before running 'make install' (if you are paranoid).
There are a number of configuration options that you can give to
'configure' :
--prefix=/usr/local
Set the installation prefix. SWIG installs into
/usr/local by default.
--exec_prefix=/usr/local
Set the prefix used to install platform specific
files (binaries and libraries). Use this if the
location is different than that given with --prefix.
--with-lang={TCL,TCL8,PYTHON,PERL5,PERL4,GUILE}
This lets you choose the default SWIG target language.
By default, SWIG chooses TCL, but you can select
another as shown :
./configure --with-lang=PYTHON
--with-doc={ASCII,LATEX,HTML,NODOC}
This lets you choose the default SWIG documentation
method. By default, SWIG chooses ASCII.
4. Site specific installation
-------------------------------
While not required for compiling SWIG, the configuration script looks
for various packages in order to create a makefile for compiling the
examples. This makefile is also installed with the SWIG package.
The following configuration options can be used to set the location
of various packages.
--with-tcl=pathname - Set root directory of Tcl installation.
SWIG will use $pathname/include and
$pathname/lib.
--with-tclincl=pathname - Set exact location of Tcl include files
--with-tcllib=pathname - Set exact location of Tcl library files
--with-itcl=pathname - Same as above but for [incr Tcl]
--with-itclincl=pathname - Location of [incr Tcl] include files
--with-itcllib=pathname - Location of [incr Tcl] libraries
--with-py=pathname - Set package location of Python. This is usually
something like /usr/local. configure will attempt
to locate the appropriate include and library files.
--with-pyincl=pathname - Set location of Python include files
(for example, /usr/local/include)
--with-pylib=pathname - Set location of Python library files
(for example, /usr/local/lib)
--with-perl5=executable - Specify your perl5 executable. SWIG will figure
out where files are by running this version of
Perl and grabbing its configuration data.
Other options :
--without-yacc - Try to compile SWIG using a pregenerated YACC
file generated by Berkeley YACC (byacc). Only recommended
if you get compiler errors when trying to compile parser.y
or parser.cxx.
Changing the C++ compiler:
By default, SWIG will look for g++. You can change the C++ compile as follows :
env CXX=CC configure --prefix=/usr/local ... etc...
or
setenv CXX=CC
./configure ... etc ...
SWIG has been successfully compiled and tested under g++, the SGI C++
compiler, and the SunPro C++ compiler.
5. Testing
-----------
The SWIG parser and language modules can be tested by typing 'make test'.
Be forewarned, this runs a large collection of tests on all of SWIG's
language modules and documentation methods. The tests may take 5-10
minutes to run, but a report of errors will be written to 'test.log'.
If this exists, it will contain error messages for failed tests. If
the file is missing, it means all tests were considered successful.
The testing process requires approximately 30-40 Mbytes of disk space.
After testing, you may wish to type 'make testclean' which will
return the testing directory to its original state.
Note : The testing procedure requires both 'sh' and 'perl'. If you
don't have these installed, some of the tests won't work.
6. Installation for Windows 95 and NT
-------------------------------------
The Win directory contains makefiles for Microsoft Visual C++ 4.x/5.x and
Borland C++. See the README.txt file in the Win directory for specific
build instructions. Many thanks to Kevin Butler (butler@cs.byu.edu)
and Pier Giorgio Esposito for supplying these Makefiles.
7. Installation for Macintosh
-----------------------------
A Macintosh version of SWIG is available separately as a PowerPC
executable. A source version is also available, but is somewhat
complicated to build due to dependencies on other packages
including Tcl 8.0. Please refer to the SWIG homepage for more
information.
8. Examples
------------
The 'Examples' directory contains examples for all of the supported
scripting languages. All of the examples rely on the file
'Makefile.template' located in the top-level directory. This makefile
is created by 'configure', but the configuration process is not
foolproof. To check this Makefile type
make testbuild
This will attempt to build various kinds of extensions and report its
success or failure. If this fails, you may need to edit the file
'Makefile.template' by hand. This usually isn't difficult--just
follow the instructions contained within the file. Once the 'make
testbuild' works for the language you are interested in using, you
should be able to build the examples.
The examples will not compile properly if you have not installed SWIG.
If you would like to try the examples before installation, set the
SWIG_LIB environment variable as follows :
setenv SWIG_LIB ${pathname}/SWIG1.1/swig_lib
Where ${pathname} the location of the SWIG source.
*** NOTE *** If you are replacing an older version of SWIG with a new
one, the examples may not compile correctly unless you set the
above environment variable or do a 'make install' first.
9. Resources
--------------
Up-to-date SWIG related information can be found at
http://www.swig.org
SWIG source code and software updates are also available via anonymous
ftp at
ftp://ftp.swig.org
You can join the SWIG mailing list by going to the following location:
http://www.cs.uchicago.edu/mailman/listinfo/swig
The SWIG mailing list is a forum for discussing various applications
of SWIG, installation problems, ideas for system improvements and
future work.
*** NEWSFLASH *** SWIG development has moved to the Univerity of
Chicago. Developer information can be found at
http://swig.cs.uchicago.edu
10. Installation Problems
-------------------------
As far as I know the installation works on the following platforms :
- SunOS 4.1.3
- Solaris
- Irix 5.3
- Irix 6.2
- HPUX
- AIX 4.1
- Linux
- MkLinux
- MachTen
- UNICOS
- Windows 95
- Windows NT 4.0
- MacOS System 7.5.3
SWIG development takes place primarily on Linux and Solaris 2.6. I've
tested most of the examples on these platforms. I have also tested
SWIG under Win95 and MacOS, but that is still somewhat experimental.
If you've tried everything and can't get SWIG to compile, please send
me e-mail at beazley@cs.uchicago.edu, and we'll try to figure it out.
I try to answer all e-mail that I receive. However, occasionally I
receive messages with bad return addresses and can't respond. If you
don't hear back within a few days, try sending a message to
'swig@cs.uchicago.edu'.
11. Documentation
-----------------
Over 300 pages of documentation describing almost every aspect of SWIG
is available in the Doc directory. Don't let the amount of
documentation scare you--SWIG is easy enough to use that you can
probably start using it by only looking at a few simple examples.
However, at some point you will probably want to know more so I hope
that the manual will come in useful. Besides, I hate black boxes...
The documentation is distributed in Adobe PDF format and can be viewed
using the Adobe Acrobat Reader. Acrobat is available for virtually
all machines and can be freely obtained from Adobe at www.adobe.com.
Postscript and HTML versions of the manual are also available from the
SWIG FTP site.
12. Incompatibilities
---------------------
This release should be mostly compatible with SWIG 1.0
(Final). However, the SWIG documentation system has been completely
rewritten and the C API has been changed greatly. It is unlikely that
any custom SWIG language modules written in C++ for 1.0 will work with
1.1. While porting to 1.1 is not that difficult, there are a number
of important changes. See the file 'Doc/Porting' for a list of
changes to the C++ API and how to convert an older SWIG module to work
with 1.1.
13. Bug Reports
----------------
Bug reports should be submitted to the online bug-tracking system
which is available at :
http://swig.cs.uchicago.edu/cgi-bin/swig
Before submitting a bug, please check this site to see if it has
already been reported. If not, provide as much information as
possible including the SWIG version number, operating system, and
compiler being used. Note : I tend to fix bugs in batches and may
only respond to a bug report when it has actually been fixed---posting
to the mailing list is often a better way to get an immediate response
to a problem.
14. Legal Stuff
---------------
SWIG is completely free and non-proprietary. You can do whatever you
want with it (including distribution), provided that you follow these
rules, 1) Keep all of the copyright notices intact, 2) don't claim
that you wrote it, and 3) Don't sue anyone if it breaks. Otherwise,
have fun.
15. Disclaimer
----------------
While I believe that SWIG is reasonably stable, I'm always tinkering
with it and trying to make it better. There may be a few bugs hiding
around so if you experience any problems let me know. If you think
that SWIG is missing some capability that would be useful to have
have, post a message on the SWIG mailing list. Most of the previous
suggestions have already been incorporated into this release.
16. Acknowledgments
---------------------
SWIG would not be possible without the contributions of people who
tried out the beta versions and offered feedback and bug reports.
While there are far too many people to list at point, I'd like to
especially acknowledge the following individuals and organizations
for supporting SWIG and making major contributions :
David Ascher, Erik Bierwagen, Kurtis Bleeker, John Buckman, Kevin
Butler, Pier Giorgio Esposito, David Fletcher, Mark Hammond, Mark
Harrison, Brad Holian, Gary Holt, Chris Johnson, Peter Lomdahl, Mark
Lutz, Chris Myers, Paul Saxe, John Schmidt, Tom Schwaller, Peter-Pike
Sloan, Patrick Tullmann, Larry Virden, Tser-Yuan Yang, Shujia Zhou.
and
Los Alamos National Laboratory
Lawrence Livermore National Laboratory
Cornell Theory Center
University of Utah
The Scientific Computing and Imaging Group (University of Utah)
(My apologies to anyone I missed...)
If you find SWIG to be useful, I'd like to know about it.
Enjoy!
Dave Beazley
Department of Computer Science
University of Chicago
Chicago, IL 60637
beazley@cs.uchicago.edu

View File

@@ -0,0 +1,19 @@
This directory contains a copy of SWIG 1.1p5-883 that has been heavily
patched to do some things specific for wxPython. You do not need to
build this version of SWIG if you do not plan on making any changes to
wxPython's *.i files. However, if you set USE_SWIG=1 in setup.py then
you *will* need to build this version of SWIG. To do so, just run:
Unix:
configure
make
Win32:
nmake -f makefile.vc
The executable created *does not* need to be installed as wxPython's
setup.py expects to find it here in this directory. Also, the name of
the executable has been renamed to wxswig to simplify having both
versions of SWIG on the system.

View File

@@ -0,0 +1,131 @@
# Generated automatically from Makefile.in by configure.
# Makefile for producing SWIG runtime libraries.
#
# The SWIG runtime library consists of the pointer-type checker
# and other support functions. Multi-file SWIG modules
# generally link with these libraries.
#
# By default, the installation processs will attempt to
# build shared libraries. If that doesn't work, a static
# library is built instead.
prefix = /usr/local
exec_prefix = ${prefix}
CC = cc
AR = ar
RANLIB = ranlib
SO = .so
CCSHARED =
LDSHARED = ld -G
DYN_LIBS = libswigtcl8$(SO) libswigtcl$(SO) libswigpl$(SO) libswigpy$(SO)
STATIC_LIBS = libswigtcl8.a libswigtcl.a libswigpl.a libswigpy.a
LIBS = $(STATIC_LIBS) $(DYN_LIBS)
LIB_DIR = $(exec_prefix)/lib
INSTALL_DATA = ../install-sh -c -m 644
INSTALL_SHLB = ../install-sh -c -m 555
all:
@sh make.sh
install:
@echo "Installing runtime libraries"
@for i in $(STATIC_LIBS); \
do \
if [ -f $$i ]; then \
echo "Installing $$i in $(LIB_DIR)/$$i"; \
$(INSTALL_DATA) $$i $(LIB_DIR)/$$i; \
fi; \
done;
@for i in $(DYN_LIBS); \
do \
if [ -f $$i ]; then \
echo "Installing $$i in $(LIB_DIR)/$$i"; \
$(INSTALL_SHLB) $$i $(LIB_DIR)/$$i; \
fi; \
done;
clean::
rm -rf *.o *.a *$(SO) *.c *.swg *~ core
# ----------------------------------------------------------------------
# Tcl runtime library
# ----------------------------------------------------------------------
TCL_INCLUDE = -I/usr/local/include
TCL_LIB = -L/usr/local/lib
# Tcl 7.x shared
tcl_shared:
../swig -tcl -co -o libtcl.c -I../swig_lib swigtcl.swg
$(CC) $(CCSHARED) -c -DSWIG_GLOBAL libtcl.c
$(LDSHARED) libtcl.o -o libswigtcl$(SO)
# Tcl 7.x library
tcl_lib:
../swig -tcl -co -o libtcl.c -I../swig_lib swigtcl.swg
$(CC) -c -DSWIG_GLOBAL libtcl.c
$(AR) cr libswigtcl.a libtcl.o
# Tcl 8.x shared
tcl8_shared:
../swig -tcl -co -o libtcl8.c -I../swig_lib swigtcl8.swg
$(CC) $(CCSHARED) -c -DSWIG_GLOBAL $(TCL_INCLUDE) libtcl8.c
$(LDSHARED) libtcl8.o -o libswigtcl8$(SO)
tcl8_lib:
../swig -tcl -co -o libtcl8.c -I../swig_lib swigtcl8.swg
$(CC) -c -DSWIG_GLOBAL $(TCL_INCLUDE) libtcl8.c
$(AR) cr libswigtcl8.a libtcl8.o
# ----------------------------------------------------------------------
# Python run-time library
# ----------------------------------------------------------------------
PYTHON_INCLUDE= -DHAVE_CONFIG_H -I/usr/local/include/python1.5 -I/usr/local/lib/python1.5/config
PYTHON_LIB = /usr/local/lib/python1.5/config
# Python shared
py_shared:
../swig -python -co -o libpy.c -I../swig_lib python.swg
$(CC) $(CCSHARED) -c -DSWIG_RUNTIME -DSWIG_GLOBAL $(PYTHON_INCLUDE) libpy.c
$(LDSHARED) libpy.o -o libswigpy$(SO)
# Python library
py_lib:
../swig -python -co -o libpy.c -I../swig_lib python.swg
$(CC) -c -DSWIG_RUNTIME -DSWIG_GLOBAL $(PYTHON_INCLUDE) libpy.c
$(AR) cr libswigpy.a libpy.o
# ----------------------------------------------------------------------
# Perl run-time library
# ----------------------------------------------------------------------
PERL5_INCLUDE= -I/usr/local/lib/perl5/5.00503/sun4-solaris/CORE
# Perl shared
perl_shared:
rm -f libperl.c libperl.swg
../swig -perl5 -co -o libperl.swg -I../swig_lib perl5.swg
cat perlrun.h >> libperl.c
cat libperl.swg >> libperl.c
$(CC) $(CCSHARED) -c -Dexplicit= -Dbool=char -DSWIG_GLOBAL $(PERL5_INCLUDE) libperl.c
$(LDSHARED) libperl.o -o libswigpl$(SO)
# Perl library
perl_lib:
rm -f libperl.c libperl.swg
../swig -perl5 -co -o libperl.swg -I../swig_lib perl5.swg
cat perlrun.h >> libperl.c
cat libperl.swg >> libperl.c
$(CC) -c -Dexplicit= -Dbool=char -DSWIG_GLOBAL $(PERL5_INCLUDE) libperl.c
$(AR) cr libswigpl.a libperl.o

View File

@@ -0,0 +1,130 @@
# Makefile for producing SWIG runtime libraries.
#
# The SWIG runtime library consists of the pointer-type checker
# and other support functions. Multi-file SWIG modules
# generally link with these libraries.
#
# By default, the installation processs will attempt to
# build shared libraries. If that doesn't work, a static
# library is built instead.
prefix = @prefix@
exec_prefix = @exec_prefix@
CC = @CC@
AR = @AR@
RANLIB = @RANLIB@
SO = @SO@
CCSHARED = @CCSHARED@
LDSHARED = @LDSHARED@
DYN_LIBS = libswigtcl8$(SO) libswigtcl$(SO) libswigpl$(SO) libswigpy$(SO)
STATIC_LIBS = libswigtcl8.a libswigtcl.a libswigpl.a libswigpy.a
LIBS = $(STATIC_LIBS) $(DYN_LIBS)
LIB_DIR = $(exec_prefix)/lib
INSTALL_DATA = ../install-sh -c -m 644
INSTALL_SHLB = ../install-sh -c -m 555
all:
@sh make.sh
install:
@echo "Installing runtime libraries"
@for i in $(STATIC_LIBS); \
do \
if [ -f $$i ]; then \
echo "Installing $$i in $(LIB_DIR)/$$i"; \
$(INSTALL_DATA) $$i $(LIB_DIR)/$$i; \
fi; \
done;
@for i in $(DYN_LIBS); \
do \
if [ -f $$i ]; then \
echo "Installing $$i in $(LIB_DIR)/$$i"; \
$(INSTALL_SHLB) $$i $(LIB_DIR)/$$i; \
fi; \
done;
clean::
rm -rf *.o *.a *$(SO) *.c *.swg *~ core
# ----------------------------------------------------------------------
# Tcl runtime library
# ----------------------------------------------------------------------
TCL_INCLUDE = @TCLINCLUDE@
TCL_LIB = @TCLLIB@
# Tcl 7.x shared
tcl_shared:
../swig -tcl -co -o libtcl.c -I../swig_lib swigtcl.swg
$(CC) $(CCSHARED) -c -DSWIG_GLOBAL libtcl.c
$(LDSHARED) libtcl.o -o libswigtcl$(SO)
# Tcl 7.x library
tcl_lib:
../swig -tcl -co -o libtcl.c -I../swig_lib swigtcl.swg
$(CC) -c -DSWIG_GLOBAL libtcl.c
$(AR) cr libswigtcl.a libtcl.o
# Tcl 8.x shared
tcl8_shared:
../swig -tcl -co -o libtcl8.c -I../swig_lib swigtcl8.swg
$(CC) $(CCSHARED) -c -DSWIG_GLOBAL $(TCL_INCLUDE) libtcl8.c
$(LDSHARED) libtcl8.o -o libswigtcl8$(SO)
tcl8_lib:
../swig -tcl -co -o libtcl8.c -I../swig_lib swigtcl8.swg
$(CC) -c -DSWIG_GLOBAL $(TCL_INCLUDE) libtcl8.c
$(AR) cr libswigtcl8.a libtcl8.o
# ----------------------------------------------------------------------
# Python run-time library
# ----------------------------------------------------------------------
PYTHON_INCLUDE= -DHAVE_CONFIG_H @PYINCLUDE@
PYTHON_LIB = @PYLIB@
# Python shared
py_shared:
../swig -python -co -o libpy.c -I../swig_lib python.swg
$(CC) $(CCSHARED) -c -DSWIG_RUNTIME -DSWIG_GLOBAL $(PYTHON_INCLUDE) libpy.c
$(LDSHARED) libpy.o -o libswigpy$(SO)
# Python library
py_lib:
../swig -python -co -o libpy.c -I../swig_lib python.swg
$(CC) -c -DSWIG_RUNTIME -DSWIG_GLOBAL $(PYTHON_INCLUDE) libpy.c
$(AR) cr libswigpy.a libpy.o
# ----------------------------------------------------------------------
# Perl run-time library
# ----------------------------------------------------------------------
PERL5_INCLUDE= -I@PERL5EXT@
# Perl shared
perl_shared:
rm -f libperl.c libperl.swg
../swig -perl5 -co -o libperl.swg -I../swig_lib perl5.swg
cat perlrun.h >> libperl.c
cat libperl.swg >> libperl.c
$(CC) $(CCSHARED) -c -Dexplicit= -Dbool=char -DSWIG_GLOBAL $(PERL5_INCLUDE) libperl.c
$(LDSHARED) libperl.o -o libswigpl$(SO)
# Perl library
perl_lib:
rm -f libperl.c libperl.swg
../swig -perl5 -co -o libperl.swg -I../swig_lib perl5.swg
cat perlrun.h >> libperl.c
cat libperl.swg >> libperl.c
$(CC) -c -Dexplicit= -Dbool=char -DSWIG_GLOBAL $(PERL5_INCLUDE) libperl.c
$(AR) cr libswigpl.a libperl.o

View File

@@ -0,0 +1,364 @@
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
/* Definitions for compiling Perl extensions on a variety of machines */
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
# if defined(_MSC_VER)
# define SWIGEXPORT(a) __declspec(dllexport) a
# else
# if defined(__BORLANDC__)
# define SWIGEXPORT(a) a _export
# else
# define SWIGEXPORT(a) a
# endif
# endif
#else
# define SWIGEXPORT(a) a
#endif
#ifdef PERL_OBJECT
#define MAGIC_PPERL CPerlObj *pPerl = (CPerlObj *) this;
#define MAGIC_CAST (int (CPerlObj::*)(SV *, MAGIC *))
#define SWIGCLASS_STATIC
#else
#define MAGIC_PPERL
#define MAGIC_CAST
#define SWIGCLASS_STATIC static
#endif
#if defined(WIN32) && defined(PERL_OBJECT) && !defined(PerlIO_exportFILE)
#define PerlIO_exportFILE(fh,fl) (FILE*)(fh)
#endif
/* Modifications for newer Perl 5.005 releases */
#if !defined(PERL_REVISION) || ((PERL_REVISION >= 5) && ((PERL_VERSION < 5) || ((PERL_VERSION == 5) && (PERL_SUBVERSION < 50))))
#ifndef PL_sv_yes
#define PL_sv_yes sv_yes
#endif
#ifndef PL_sv_undef
#define PL_sv_undef sv_undef
#endif
#ifndef PL_na
#define PL_na na
#endif
#endif
/******************************************************************************
* Pointer type-checking code
*****************************************************************************/
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef SWIG_NOINCLUDE
extern void SWIG_MakePtr(char *, void *, char *);
#ifndef PERL_OBJECT
extern void SWIG_RegisterMapping(char *, char *, void *(*)(void *));
#else
#define SWIG_RegisterMapping(a,b,c) _SWIG_RegisterMapping(pPerl,a,b,c);
extern void _SWIG_RegisterMapping(CPerlObj *,char *, char *, void *(*)(void *),int);
#endif
#ifndef PERL_OBJECT
extern char *SWIG_GetPtr(SV *, void **, char *);
#else
extern char *_SWIG_GetPtr(CPerlObj *, SV *, void **, char *);
#define SWIG_GetPtr(a,b,c) _SWIG_GetPtr(pPerl,a,b,c)
#endif
#else
#ifdef SWIG_GLOBAL
#define SWIGSTATICRUNTIME(a) SWIGEXPORT(a)
#else
#define SWIGSTATICRUNTIME(a) static a
#endif
/* These are internal variables. Should be static */
typedef struct SwigPtrType {
char *name;
int len;
void *(*cast)(void *);
struct SwigPtrType *next;
} SwigPtrType;
/* Pointer cache structure */
typedef struct {
int stat; /* Status (valid) bit */
SwigPtrType *tp; /* Pointer to type structure */
char name[256]; /* Given datatype name */
char mapped[256]; /* Equivalent name */
} SwigCacheType;
static int SwigPtrMax = 64; /* Max entries that can be currently held */
static int SwigPtrN = 0; /* Current number of entries */
static int SwigPtrSort = 0; /* Status flag indicating sort */
static SwigPtrType *SwigPtrTable = 0; /* Table containing pointer equivalences */
static int SwigStart[256]; /* Table containing starting positions */
/* Cached values */
#define SWIG_CACHESIZE 8
#define SWIG_CACHEMASK 0x7
static SwigCacheType SwigCache[SWIG_CACHESIZE];
static int SwigCacheIndex = 0;
static int SwigLastCache = 0;
/* Sort comparison function */
static int swigsort(const void *data1, const void *data2) {
SwigPtrType *d1 = (SwigPtrType *) data1;
SwigPtrType *d2 = (SwigPtrType *) data2;
return strcmp(d1->name,d2->name);
}
/* Binary Search function */
static int swigcmp(const void *key, const void *data) {
char *k = (char *) key;
SwigPtrType *d = (SwigPtrType *) data;
return strncmp(k,d->name,d->len);
}
/* Register a new datatype with the type-checker */
#ifndef PERL_OBJECT
SWIGSTATICRUNTIME(void)
SWIG_RegisterMapping(char *origtype, char *newtype, void *(*cast)(void *)) {
#else
#define SWIG_RegisterMapping(a,b,c) _SWIG_RegisterMapping(pPerl, a,b,c)
SWIGSTATICRUNTIME(void)
_SWIG_RegisterMapping(CPerlObj *pPerl, char *origtype, char *newtype, void *(*cast)(void *)) {
#endif
int i;
SwigPtrType *t = 0, *t1;
if (!SwigPtrTable) {
SwigPtrTable = (SwigPtrType *) malloc(SwigPtrMax*sizeof(SwigPtrType));
SwigPtrN = 0;
}
if (SwigPtrN >= SwigPtrMax) {
SwigPtrMax = 2*SwigPtrMax;
SwigPtrTable = (SwigPtrType *) realloc(SwigPtrTable,SwigPtrMax*sizeof(SwigPtrType));
}
for (i = 0; i < SwigPtrN; i++)
if (strcmp(SwigPtrTable[i].name,origtype) == 0) {
t = &SwigPtrTable[i];
break;
}
if (!t) {
t = &SwigPtrTable[SwigPtrN];
t->name = origtype;
t->len = strlen(t->name);
t->cast = 0;
t->next = 0;
SwigPtrN++;
}
while (t->next) {
if (strcmp(t->name,newtype) == 0) {
if (cast) t->cast = cast;
return;
}
t = t->next;
}
t1 = (SwigPtrType *) malloc(sizeof(SwigPtrType));
t1->name = newtype;
t1->len = strlen(t1->name);
t1->cast = cast;
t1->next = 0;
t->next = t1;
SwigPtrSort = 0;
}
/* Make a pointer value string */
SWIGSTATICRUNTIME(void)
SWIG_MakePtr(char *_c, const void *_ptr, char *type) {
static char _hex[16] =
{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f'};
unsigned long _p, _s;
char _result[20], *_r; /* Note : a 64-bit hex number = 16 digits */
_r = _result;
_p = (unsigned long) _ptr;
if (_p > 0) {
while (_p > 0) {
_s = _p & 0xf;
*(_r++) = _hex[_s];
_p = _p >> 4;
}
*_r = '_';
while (_r >= _result)
*(_c++) = *(_r--);
} else {
strcpy (_c, "NULL");
}
if (_ptr)
strcpy (_c, type);
}
/* Function for getting a pointer value */
#ifndef PERL_OBJECT
SWIGSTATICRUNTIME(char *)
SWIG_GetPtr(SV *sv, void **ptr, char *_t)
#else
#define SWIG_GetPtr(a,b,c) _SWIG_GetPtr(pPerl,a,b,c)
SWIGSTATICRUNTIME(char *)
_SWIG_GetPtr(CPerlObj *pPerl, SV *sv, void **ptr, char *_t)
#endif
{
char temp_type[256];
char *name,*_c;
int len,i,start,end;
IV tmp;
SwigPtrType *sp,*tp;
SwigCacheType *cache;
/* If magical, apply more magic */
if (SvGMAGICAL(sv))
mg_get(sv);
/* Check to see if this is an object */
if (sv_isobject(sv)) {
SV *tsv = (SV*) SvRV(sv);
if ((SvTYPE(tsv) == SVt_PVHV)) {
MAGIC *mg;
if (SvMAGICAL(tsv)) {
mg = mg_find(tsv,'P');
if (mg) {
SV *rsv = mg->mg_obj;
if (sv_isobject(rsv)) {
tmp = SvIV((SV*)SvRV(rsv));
}
}
} else {
return "Not a valid pointer value";
}
} else {
tmp = SvIV((SV*)SvRV(sv));
}
if (!_t) {
*(ptr) = (void *) tmp;
return (char *) 0;
}
} else if (! SvOK(sv)) { /* Check for undef */
*(ptr) = (void *) 0;
return (char *) 0;
} else if (SvTYPE(sv) == SVt_RV) { /* Check for NULL pointer */
*(ptr) = (void *) 0;
if (!SvROK(sv))
return (char *) 0;
else
return "Not a valid pointer value";
} else { /* Don't know what it is */
*(ptr) = (void *) 0;
return "Not a valid pointer value";
}
if (_t) {
/* Now see if the types match */
if (!sv_isa(sv,_t)) {
_c = HvNAME(SvSTASH(SvRV(sv)));
if (!SwigPtrSort) {
qsort((void *) SwigPtrTable, SwigPtrN, sizeof(SwigPtrType), swigsort);
for (i = 0; i < 256; i++) {
SwigStart[i] = SwigPtrN;
}
for (i = SwigPtrN-1; i >= 0; i--) {
SwigStart[SwigPtrTable[i].name[0]] = i;
}
for (i = 255; i >= 1; i--) {
if (SwigStart[i-1] > SwigStart[i])
SwigStart[i-1] = SwigStart[i];
}
SwigPtrSort = 1;
for (i = 0; i < SWIG_CACHESIZE; i++)
SwigCache[i].stat = 0;
}
/* First check cache for matches. Uses last cache value as starting point */
cache = &SwigCache[SwigLastCache];
for (i = 0; i < SWIG_CACHESIZE; i++) {
if (cache->stat) {
if (strcmp(_t,cache->name) == 0) {
if (strcmp(_c,cache->mapped) == 0) {
cache->stat++;
*ptr = (void *) tmp;
if (cache->tp->cast) *ptr = (*(cache->tp->cast))(*ptr);
return (char *) 0;
}
}
}
SwigLastCache = (SwigLastCache+1) & SWIG_CACHEMASK;
if (!SwigLastCache) cache = SwigCache;
else cache++;
}
start = SwigStart[_t[0]];
end = SwigStart[_t[0]+1];
sp = &SwigPtrTable[start];
while (start < end) {
if (swigcmp(_t,sp) == 0) break;
sp++;
start++;
}
if (start > end) sp = 0;
while (start <= end) {
if (swigcmp(_t,sp) == 0) {
name = sp->name;
len = sp->len;
tp = sp->next;
while(tp) {
if (tp->len >= 255) {
return _c;
}
strcpy(temp_type,tp->name);
strncat(temp_type,_t+len,255-tp->len);
if (sv_isa(sv,temp_type)) {
/* Get pointer value */
*ptr = (void *) tmp;
if (tp->cast) *ptr = (*(tp->cast))(*ptr);
strcpy(SwigCache[SwigCacheIndex].mapped,_c);
strcpy(SwigCache[SwigCacheIndex].name,_t);
SwigCache[SwigCacheIndex].stat = 1;
SwigCache[SwigCacheIndex].tp = tp;
SwigCacheIndex = SwigCacheIndex & SWIG_CACHEMASK;
return (char *) 0;
}
tp = tp->next;
}
}
sp++;
start++;
}
/* Didn't find any sort of match for this data.
Get the pointer value and return the received type */
*ptr = (void *) tmp;
return _c;
} else {
/* Found a match on the first try. Return pointer value */
*ptr = (void *) tmp;
return (char *) 0;
}
}
*ptr = (void *) tmp;
return (char *) 0;
}
#endif
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,361 @@
/* Definitions for compiling Perl extensions on a variety of machines */
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
# if defined(_MSC_VER)
# define SWIGEXPORT(a) __declspec(dllexport) a
# else
# if defined(__BORLANDC__)
# define SWIGEXPORT(a) a _export
# else
# define SWIGEXPORT(a) a
# endif
# endif
#else
# define SWIGEXPORT(a) a
#endif
#ifdef PERL_OBJECT
#define MAGIC_PPERL CPerlObj *pPerl = (CPerlObj *) this;
#define MAGIC_CAST (int (CPerlObj::*)(SV *, MAGIC *))
#define SWIGCLASS_STATIC
#else
#define MAGIC_PPERL
#define MAGIC_CAST
#define SWIGCLASS_STATIC static
#endif
#if defined(WIN32) && defined(PERL_OBJECT) && !defined(PerlIO_exportFILE)
#define PerlIO_exportFILE(fh,fl) (FILE*)(fh)
#endif
/* Modifications for newer Perl 5.005 releases */
#if !defined(PERL_REVISION) || ((PERL_REVISION >= 5) && ((PERL_VERSION < 5) || ((PERL_VERSION == 5) && (PERL_SUBVERSION < 50))))
#ifndef PL_sv_yes
#define PL_sv_yes sv_yes
#endif
#ifndef PL_sv_undef
#define PL_sv_undef sv_undef
#endif
#ifndef PL_na
#define PL_na na
#endif
#endif
/******************************************************************************
* Pointer type-checking code
*****************************************************************************/
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef SWIG_NOINCLUDE
extern void SWIG_MakePtr(char *, void *, char *);
#ifndef PERL_OBJECT
extern void SWIG_RegisterMapping(char *, char *, void *(*)(void *));
#else
#define SWIG_RegisterMapping(a,b,c) _SWIG_RegisterMapping(pPerl,a,b,c);
extern void _SWIG_RegisterMapping(CPerlObj *,char *, char *, void *(*)(void *),int);
#endif
#ifndef PERL_OBJECT
extern char *SWIG_GetPtr(SV *, void **, char *);
#else
extern char *_SWIG_GetPtr(CPerlObj *, SV *, void **, char *);
#define SWIG_GetPtr(a,b,c) _SWIG_GetPtr(pPerl,a,b,c)
#endif
#else
#ifdef SWIG_GLOBAL
#define SWIGSTATICRUNTIME(a) SWIGEXPORT(a)
#else
#define SWIGSTATICRUNTIME(a) static a
#endif
/* These are internal variables. Should be static */
typedef struct SwigPtrType {
char *name;
int len;
void *(*cast)(void *);
struct SwigPtrType *next;
} SwigPtrType;
/* Pointer cache structure */
typedef struct {
int stat; /* Status (valid) bit */
SwigPtrType *tp; /* Pointer to type structure */
char name[256]; /* Given datatype name */
char mapped[256]; /* Equivalent name */
} SwigCacheType;
static int SwigPtrMax = 64; /* Max entries that can be currently held */
static int SwigPtrN = 0; /* Current number of entries */
static int SwigPtrSort = 0; /* Status flag indicating sort */
static SwigPtrType *SwigPtrTable = 0; /* Table containing pointer equivalences */
static int SwigStart[256]; /* Table containing starting positions */
/* Cached values */
#define SWIG_CACHESIZE 8
#define SWIG_CACHEMASK 0x7
static SwigCacheType SwigCache[SWIG_CACHESIZE];
static int SwigCacheIndex = 0;
static int SwigLastCache = 0;
/* Sort comparison function */
static int swigsort(const void *data1, const void *data2) {
SwigPtrType *d1 = (SwigPtrType *) data1;
SwigPtrType *d2 = (SwigPtrType *) data2;
return strcmp(d1->name,d2->name);
}
/* Binary Search function */
static int swigcmp(const void *key, const void *data) {
char *k = (char *) key;
SwigPtrType *d = (SwigPtrType *) data;
return strncmp(k,d->name,d->len);
}
/* Register a new datatype with the type-checker */
#ifndef PERL_OBJECT
SWIGSTATICRUNTIME(void)
SWIG_RegisterMapping(char *origtype, char *newtype, void *(*cast)(void *)) {
#else
#define SWIG_RegisterMapping(a,b,c) _SWIG_RegisterMapping(pPerl, a,b,c)
SWIGSTATICRUNTIME(void)
_SWIG_RegisterMapping(CPerlObj *pPerl, char *origtype, char *newtype, void *(*cast)(void *)) {
#endif
int i;
SwigPtrType *t = 0, *t1;
if (!SwigPtrTable) {
SwigPtrTable = (SwigPtrType *) malloc(SwigPtrMax*sizeof(SwigPtrType));
SwigPtrN = 0;
}
if (SwigPtrN >= SwigPtrMax) {
SwigPtrMax = 2*SwigPtrMax;
SwigPtrTable = (SwigPtrType *) realloc(SwigPtrTable,SwigPtrMax*sizeof(SwigPtrType));
}
for (i = 0; i < SwigPtrN; i++)
if (strcmp(SwigPtrTable[i].name,origtype) == 0) {
t = &SwigPtrTable[i];
break;
}
if (!t) {
t = &SwigPtrTable[SwigPtrN];
t->name = origtype;
t->len = strlen(t->name);
t->cast = 0;
t->next = 0;
SwigPtrN++;
}
while (t->next) {
if (strcmp(t->name,newtype) == 0) {
if (cast) t->cast = cast;
return;
}
t = t->next;
}
t1 = (SwigPtrType *) malloc(sizeof(SwigPtrType));
t1->name = newtype;
t1->len = strlen(t1->name);
t1->cast = cast;
t1->next = 0;
t->next = t1;
SwigPtrSort = 0;
}
/* Make a pointer value string */
SWIGSTATICRUNTIME(void)
SWIG_MakePtr(char *_c, const void *_ptr, char *type) {
static char _hex[16] =
{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f'};
unsigned long _p, _s;
char _result[20], *_r; /* Note : a 64-bit hex number = 16 digits */
_r = _result;
_p = (unsigned long) _ptr;
if (_p > 0) {
while (_p > 0) {
_s = _p & 0xf;
*(_r++) = _hex[_s];
_p = _p >> 4;
}
*_r = '_';
while (_r >= _result)
*(_c++) = *(_r--);
} else {
strcpy (_c, "NULL");
}
if (_ptr)
strcpy (_c, type);
}
/* Function for getting a pointer value */
#ifndef PERL_OBJECT
SWIGSTATICRUNTIME(char *)
SWIG_GetPtr(SV *sv, void **ptr, char *_t)
#else
#define SWIG_GetPtr(a,b,c) _SWIG_GetPtr(pPerl,a,b,c)
SWIGSTATICRUNTIME(char *)
_SWIG_GetPtr(CPerlObj *pPerl, SV *sv, void **ptr, char *_t)
#endif
{
char temp_type[256];
char *name,*_c;
int len,i,start,end;
IV tmp;
SwigPtrType *sp,*tp;
SwigCacheType *cache;
/* If magical, apply more magic */
if (SvGMAGICAL(sv))
mg_get(sv);
/* Check to see if this is an object */
if (sv_isobject(sv)) {
SV *tsv = (SV*) SvRV(sv);
if ((SvTYPE(tsv) == SVt_PVHV)) {
MAGIC *mg;
if (SvMAGICAL(tsv)) {
mg = mg_find(tsv,'P');
if (mg) {
SV *rsv = mg->mg_obj;
if (sv_isobject(rsv)) {
tmp = SvIV((SV*)SvRV(rsv));
}
}
} else {
return "Not a valid pointer value";
}
} else {
tmp = SvIV((SV*)SvRV(sv));
}
if (!_t) {
*(ptr) = (void *) tmp;
return (char *) 0;
}
} else if (! SvOK(sv)) { /* Check for undef */
*(ptr) = (void *) 0;
return (char *) 0;
} else if (SvTYPE(sv) == SVt_RV) { /* Check for NULL pointer */
*(ptr) = (void *) 0;
if (!SvROK(sv))
return (char *) 0;
else
return "Not a valid pointer value";
} else { /* Don't know what it is */
*(ptr) = (void *) 0;
return "Not a valid pointer value";
}
if (_t) {
/* Now see if the types match */
if (!sv_isa(sv,_t)) {
_c = HvNAME(SvSTASH(SvRV(sv)));
if (!SwigPtrSort) {
qsort((void *) SwigPtrTable, SwigPtrN, sizeof(SwigPtrType), swigsort);
for (i = 0; i < 256; i++) {
SwigStart[i] = SwigPtrN;
}
for (i = SwigPtrN-1; i >= 0; i--) {
SwigStart[SwigPtrTable[i].name[0]] = i;
}
for (i = 255; i >= 1; i--) {
if (SwigStart[i-1] > SwigStart[i])
SwigStart[i-1] = SwigStart[i];
}
SwigPtrSort = 1;
for (i = 0; i < SWIG_CACHESIZE; i++)
SwigCache[i].stat = 0;
}
/* First check cache for matches. Uses last cache value as starting point */
cache = &SwigCache[SwigLastCache];
for (i = 0; i < SWIG_CACHESIZE; i++) {
if (cache->stat) {
if (strcmp(_t,cache->name) == 0) {
if (strcmp(_c,cache->mapped) == 0) {
cache->stat++;
*ptr = (void *) tmp;
if (cache->tp->cast) *ptr = (*(cache->tp->cast))(*ptr);
return (char *) 0;
}
}
}
SwigLastCache = (SwigLastCache+1) & SWIG_CACHEMASK;
if (!SwigLastCache) cache = SwigCache;
else cache++;
}
start = SwigStart[_t[0]];
end = SwigStart[_t[0]+1];
sp = &SwigPtrTable[start];
while (start < end) {
if (swigcmp(_t,sp) == 0) break;
sp++;
start++;
}
if (start > end) sp = 0;
while (start <= end) {
if (swigcmp(_t,sp) == 0) {
name = sp->name;
len = sp->len;
tp = sp->next;
while(tp) {
if (tp->len >= 255) {
return _c;
}
strcpy(temp_type,tp->name);
strncat(temp_type,_t+len,255-tp->len);
if (sv_isa(sv,temp_type)) {
/* Get pointer value */
*ptr = (void *) tmp;
if (tp->cast) *ptr = (*(tp->cast))(*ptr);
strcpy(SwigCache[SwigCacheIndex].mapped,_c);
strcpy(SwigCache[SwigCacheIndex].name,_t);
SwigCache[SwigCacheIndex].stat = 1;
SwigCache[SwigCacheIndex].tp = tp;
SwigCacheIndex = SwigCacheIndex & SWIG_CACHEMASK;
return (char *) 0;
}
tp = tp->next;
}
}
sp++;
start++;
}
/* Didn't find any sort of match for this data.
Get the pointer value and return the received type */
*ptr = (void *) tmp;
return _c;
} else {
/* Found a match on the first try. Return pointer value */
*ptr = (void *) tmp;
return (char *) 0;
}
}
*ptr = (void *) tmp;
return (char *) 0;
}
#endif
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,417 @@
/***********************************************************************
* $Header$
* swig_lib/python/python.cfg
*
* Contains variable linking and pointer type-checking code.
************************************************************************/
#include <string.h>
#include <stdlib.h>
#include "Python.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Definitions for Windows/Unix exporting */
#if defined(_WIN32) || defined(__WIN32__)
# if defined(_MSC_VER)
# define SWIGEXPORT(a) __declspec(dllexport) a
# else
# if defined(__BORLANDC__)
# define SWIGEXPORT(a) a _export
# else
# define SWIGEXPORT(a) a
# endif
# endif
#else
# define SWIGEXPORT(a) a
#endif
#ifdef SWIG_GLOBAL
#define SWIGSTATICRUNTIME(a) SWIGEXPORT(a)
#else
#define SWIGSTATICRUNTIME(a) static a
#endif
typedef struct {
char *name;
PyObject *(*get_attr)(void);
int (*set_attr)(PyObject *);
} swig_globalvar;
typedef struct swig_varlinkobject {
PyObject_HEAD
swig_globalvar **vars;
int nvars;
int maxvars;
} swig_varlinkobject;
/* ----------------------------------------------------------------------
swig_varlink_repr()
Function for python repr method
---------------------------------------------------------------------- */
static PyObject *
swig_varlink_repr(swig_varlinkobject *v)
{
v = v;
return PyString_FromString("<Global variables>");
}
/* ---------------------------------------------------------------------
swig_varlink_print()
Print out all of the global variable names
--------------------------------------------------------------------- */
static int
swig_varlink_print(swig_varlinkobject *v, FILE *fp, int flags)
{
int i = 0;
flags = flags;
fprintf(fp,"Global variables { ");
while (v->vars[i]) {
fprintf(fp,"%s", v->vars[i]->name);
i++;
if (v->vars[i]) fprintf(fp,", ");
}
fprintf(fp," }\n");
return 0;
}
/* --------------------------------------------------------------------
swig_varlink_getattr
This function gets the value of a variable and returns it as a
PyObject. In our case, we'll be looking at the datatype and
converting into a number or string
-------------------------------------------------------------------- */
static PyObject *
swig_varlink_getattr(swig_varlinkobject *v, char *n)
{
int i = 0;
char temp[128];
while (v->vars[i]) {
if (strcmp(v->vars[i]->name,n) == 0) {
return (*v->vars[i]->get_attr)();
}
i++;
}
sprintf(temp,"C global variable %s not found.", n);
PyErr_SetString(PyExc_NameError,temp);
return NULL;
}
/* -------------------------------------------------------------------
swig_varlink_setattr()
This function sets the value of a variable.
------------------------------------------------------------------- */
static int
swig_varlink_setattr(swig_varlinkobject *v, char *n, PyObject *p)
{
char temp[128];
int i = 0;
while (v->vars[i]) {
if (strcmp(v->vars[i]->name,n) == 0) {
return (*v->vars[i]->set_attr)(p);
}
i++;
}
sprintf(temp,"C global variable %s not found.", n);
PyErr_SetString(PyExc_NameError,temp);
return 1;
}
statichere PyTypeObject varlinktype = {
/* PyObject_HEAD_INIT(&PyType_Type) Note : This doesn't work on some machines */
PyObject_HEAD_INIT(0)
0,
"varlink", /* Type name */
sizeof(swig_varlinkobject), /* Basic size */
0, /* Itemsize */
0, /* Deallocator */
(printfunc) swig_varlink_print, /* Print */
(getattrfunc) swig_varlink_getattr, /* get attr */
(setattrfunc) swig_varlink_setattr, /* Set attr */
0, /* tp_compare */
(reprfunc) swig_varlink_repr, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_mapping*/
0, /* tp_hash */
};
/* Create a variable linking object for use later */
SWIGSTATICRUNTIME(PyObject *)
SWIG_newvarlink(void)
{
swig_varlinkobject *result = 0;
result = PyMem_NEW(swig_varlinkobject,1);
varlinktype.ob_type = &PyType_Type; /* Patch varlinktype into a PyType */
result->ob_type = &varlinktype;
/* _Py_NewReference(result); Does not seem to be necessary */
result->nvars = 0;
result->maxvars = 64;
result->vars = (swig_globalvar **) malloc(64*sizeof(swig_globalvar *));
result->vars[0] = 0;
result->ob_refcnt = 0;
Py_XINCREF((PyObject *) result);
return ((PyObject*) result);
}
SWIGSTATICRUNTIME(void)
SWIG_addvarlink(PyObject *p, char *name,
PyObject *(*get_attr)(void), int (*set_attr)(PyObject *p))
{
swig_varlinkobject *v;
v= (swig_varlinkobject *) p;
if (v->nvars >= v->maxvars -1) {
v->maxvars = 2*v->maxvars;
v->vars = (swig_globalvar **) realloc(v->vars,v->maxvars*sizeof(swig_globalvar *));
if (v->vars == NULL) {
fprintf(stderr,"SWIG : Fatal error in initializing Python module.\n");
exit(1);
}
}
v->vars[v->nvars] = (swig_globalvar *) malloc(sizeof(swig_globalvar));
v->vars[v->nvars]->name = (char *) malloc(strlen(name)+1);
strcpy(v->vars[v->nvars]->name,name);
v->vars[v->nvars]->get_attr = get_attr;
v->vars[v->nvars]->set_attr = set_attr;
v->nvars++;
v->vars[v->nvars] = 0;
}
/* -----------------------------------------------------------------------------
* Pointer type-checking
* ----------------------------------------------------------------------------- */
/* SWIG pointer structure */
typedef struct SwigPtrType {
char *name; /* Datatype name */
int len; /* Length (used for optimization) */
void *(*cast)(void *); /* Pointer casting function */
struct SwigPtrType *next; /* Linked list pointer */
} SwigPtrType;
/* Pointer cache structure */
typedef struct {
int stat; /* Status (valid) bit */
SwigPtrType *tp; /* Pointer to type structure */
char name[256]; /* Given datatype name */
char mapped[256]; /* Equivalent name */
} SwigCacheType;
static int SwigPtrMax = 64; /* Max entries that can be currently held */
static int SwigPtrN = 0; /* Current number of entries */
static int SwigPtrSort = 0; /* Status flag indicating sort */
static int SwigStart[256]; /* Starting positions of types */
static SwigPtrType *SwigPtrTable = 0; /* Table containing pointer equivalences */
/* Cached values */
#define SWIG_CACHESIZE 8
#define SWIG_CACHEMASK 0x7
static SwigCacheType SwigCache[SWIG_CACHESIZE];
static int SwigCacheIndex = 0;
static int SwigLastCache = 0;
/* Sort comparison function */
static int swigsort(const void *data1, const void *data2) {
SwigPtrType *d1 = (SwigPtrType *) data1;
SwigPtrType *d2 = (SwigPtrType *) data2;
return strcmp(d1->name,d2->name);
}
/* Register a new datatype with the type-checker */
SWIGSTATICRUNTIME(void)
SWIG_RegisterMapping(char *origtype, char *newtype, void *(*cast)(void *)) {
int i;
SwigPtrType *t = 0,*t1;
/* Allocate the pointer table if necessary */
if (!SwigPtrTable) {
SwigPtrTable = (SwigPtrType *) malloc(SwigPtrMax*sizeof(SwigPtrType));
}
/* Grow the table */
if (SwigPtrN >= SwigPtrMax) {
SwigPtrMax = 2*SwigPtrMax;
SwigPtrTable = (SwigPtrType *) realloc((char *) SwigPtrTable,SwigPtrMax*sizeof(SwigPtrType));
}
for (i = 0; i < SwigPtrN; i++) {
if (strcmp(SwigPtrTable[i].name,origtype) == 0) {
t = &SwigPtrTable[i];
break;
}
}
if (!t) {
t = &SwigPtrTable[SwigPtrN++];
t->name = origtype;
t->len = strlen(t->name);
t->cast = 0;
t->next = 0;
}
/* Check for existing entries */
while (t->next) {
if ((strcmp(t->name,newtype) == 0)) {
if (cast) t->cast = cast;
return;
}
t = t->next;
}
t1 = (SwigPtrType *) malloc(sizeof(SwigPtrType));
t1->name = newtype;
t1->len = strlen(t1->name);
t1->cast = cast;
t1->next = 0;
t->next = t1;
SwigPtrSort = 0;
}
/* Make a pointer value string */
SWIGSTATICRUNTIME(void)
SWIG_MakePtr(char *c, const void *ptr, char *type) {
static char hex[17] = "0123456789abcdef";
unsigned long p, s;
char result[24], *r;
r = result;
p = (unsigned long) ptr;
if (p > 0) {
while (p > 0) {
s = p & 0xf;
*(r++) = hex[s];
p = p >> 4;
}
*r = '_';
while (r >= result)
*(c++) = *(r--);
strcpy (c, type);
} else {
strcpy (c, "NULL");
}
}
/* Function for getting a pointer value */
SWIGSTATICRUNTIME(char *)
SWIG_GetPtr(char *c, void **ptr, char *t)
{
unsigned long p;
char temp_type[256], *name;
int i, len, start, end;
SwigPtrType *sp,*tp;
SwigCacheType *cache;
register int d;
p = 0;
/* Pointer values must start with leading underscore */
if (*c != '_') {
*ptr = (void *) 0;
if (strcmp(c,"NULL") == 0) return (char *) 0;
else c;
}
c++;
/* Extract hex value from pointer */
while (d = *c) {
if ((d >= '0') && (d <= '9'))
p = (p << 4) + (d - '0');
else if ((d >= 'a') && (d <= 'f'))
p = (p << 4) + (d - ('a'-10));
else
break;
c++;
}
*ptr = (void *) p;
if ((!t) || (strcmp(t,c)==0)) return (char *) 0;
if (!SwigPtrSort) {
qsort((void *) SwigPtrTable, SwigPtrN, sizeof(SwigPtrType), swigsort);
for (i = 0; i < 256; i++) SwigStart[i] = SwigPtrN;
for (i = SwigPtrN-1; i >= 0; i--) SwigStart[(int) (SwigPtrTable[i].name[1])] = i;
for (i = 255; i >= 1; i--) {
if (SwigStart[i-1] > SwigStart[i])
SwigStart[i-1] = SwigStart[i];
}
SwigPtrSort = 1;
for (i = 0; i < SWIG_CACHESIZE; i++) SwigCache[i].stat = 0;
}
/* First check cache for matches. Uses last cache value as starting point */
cache = &SwigCache[SwigLastCache];
for (i = 0; i < SWIG_CACHESIZE; i++) {
if (cache->stat && (strcmp(t,cache->name) == 0) && (strcmp(c,cache->mapped) == 0)) {
cache->stat++;
if (cache->tp->cast) *ptr = (*(cache->tp->cast))(*ptr);
return (char *) 0;
}
SwigLastCache = (SwigLastCache+1) & SWIG_CACHEMASK;
if (!SwigLastCache) cache = SwigCache;
else cache++;
}
/* Type mismatch. Look through type-mapping table */
start = SwigStart[(int) t[1]];
end = SwigStart[(int) t[1]+1];
sp = &SwigPtrTable[start];
/* Try to find a match */
while (start <= end) {
if (strncmp(t,sp->name,sp->len) == 0) {
name = sp->name;
len = sp->len;
tp = sp->next;
/* Try to find entry for our given datatype */
while(tp) {
if (tp->len >= 255) {
return c;
}
strcpy(temp_type,tp->name);
strncat(temp_type,t+len,255-tp->len);
if (strcmp(c,temp_type) == 0) {
strcpy(SwigCache[SwigCacheIndex].mapped,c);
strcpy(SwigCache[SwigCacheIndex].name,t);
SwigCache[SwigCacheIndex].stat = 1;
SwigCache[SwigCacheIndex].tp = tp;
SwigCacheIndex = SwigCacheIndex & SWIG_CACHEMASK;
/* Get pointer value */
*ptr = (void *) p;
if (tp->cast) *ptr = (*(tp->cast))(*ptr);
return (char *) 0;
}
tp = tp->next;
}
}
sp++;
start++;
}
return c;
}
/* New object-based GetPointer function. This uses the Python abstract
* object interface to automatically dereference the 'this' attribute
* of shadow objects. */
SWIGSTATICRUNTIME(char *)
SWIG_GetPtrObj(PyObject *obj, void **ptr, char *type) {
PyObject *sobj = obj;
char *str;
if (!PyString_Check(obj)) {
sobj = PyObject_GetAttrString(obj,"this");
if (!sobj) return "";
}
str = PyString_AsString(sobj);
return SWIG_GetPtr(str,ptr,type);
}
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,249 @@
/*
* $Header$
*
* swigtcl.swg
*/
#if defined(_WIN32) || defined(__WIN32__)
# if defined(_MSC_VER)
# define SWIGEXPORT(a) __declspec(dllexport) a
# else
# if defined(__BORLANDC__)
# define SWIGEXPORT(a) a _export
# else
# define SWIGEXPORT(a) a
# endif
# endif
#else
# define SWIGEXPORT(a) a
#endif
/*****************************************************************************
* $Header$
*
* swigptr.swg
*****************************************************************************/
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef SWIG_NOINCLUDE
extern void SWIG_MakePtr(char *, void *, char *);
extern void SWIG_RegisterMapping(char *, char *, void *(*)(void *));
extern char *SWIG_GetPtr(char *, void **, char *);
#else
#ifdef SWIG_GLOBAL
#define SWIGSTATICRUNTIME(a) SWIGEXPORT(a)
#else
#define SWIGSTATICRUNTIME(a) static a
#endif
/* SWIG pointer structure */
typedef struct SwigPtrType {
char *name; /* Datatype name */
int len; /* Length (used for optimization) */
void *(*cast)(void *); /* Pointer casting function */
struct SwigPtrType *next; /* Linked list pointer */
} SwigPtrType;
/* Pointer cache structure */
typedef struct {
int stat; /* Status (valid) bit */
SwigPtrType *tp; /* Pointer to type structure */
char name[256]; /* Given datatype name */
char mapped[256]; /* Equivalent name */
} SwigCacheType;
static int SwigPtrMax = 64; /* Max entries that can be currently held */
static int SwigPtrN = 0; /* Current number of entries */
static int SwigPtrSort = 0; /* Status flag indicating sort */
static int SwigStart[256]; /* Starting positions of types */
static SwigPtrType *SwigPtrTable = 0; /* Table containing pointer equivalences */
/* Cached values */
#define SWIG_CACHESIZE 8
#define SWIG_CACHEMASK 0x7
static SwigCacheType SwigCache[SWIG_CACHESIZE];
static int SwigCacheIndex = 0;
static int SwigLastCache = 0;
/* Sort comparison function */
static int swigsort(const void *data1, const void *data2) {
SwigPtrType *d1 = (SwigPtrType *) data1;
SwigPtrType *d2 = (SwigPtrType *) data2;
return strcmp(d1->name,d2->name);
}
/* Register a new datatype with the type-checker */
SWIGSTATICRUNTIME(void)
SWIG_RegisterMapping(char *origtype, char *newtype, void *(*cast)(void *)) {
int i;
SwigPtrType *t = 0,*t1;
/* Allocate the pointer table if necessary */
if (!SwigPtrTable) {
SwigPtrTable = (SwigPtrType *) malloc(SwigPtrMax*sizeof(SwigPtrType));
}
/* Grow the table */
if (SwigPtrN >= SwigPtrMax) {
SwigPtrMax = 2*SwigPtrMax;
SwigPtrTable = (SwigPtrType *) realloc((char *) SwigPtrTable,SwigPtrMax*sizeof(SwigPtrType));
}
for (i = 0; i < SwigPtrN; i++) {
if (strcmp(SwigPtrTable[i].name,origtype) == 0) {
t = &SwigPtrTable[i];
break;
}
}
if (!t) {
t = &SwigPtrTable[SwigPtrN++];
t->name = origtype;
t->len = strlen(t->name);
t->cast = 0;
t->next = 0;
}
/* Check for existing entries */
while (t->next) {
if ((strcmp(t->name,newtype) == 0)) {
if (cast) t->cast = cast;
return;
}
t = t->next;
}
t1 = (SwigPtrType *) malloc(sizeof(SwigPtrType));
t1->name = newtype;
t1->len = strlen(t1->name);
t1->cast = cast;
t1->next = 0;
t->next = t1;
SwigPtrSort = 0;
}
/* Make a pointer value string */
SWIGSTATICRUNTIME(void)
SWIG_MakePtr(char *c, const void *ptr, char *type) {
static char hex[17] = "0123456789abcdef";
unsigned long p, s;
char result[24], *r;
r = result;
p = (unsigned long) ptr;
if (p > 0) {
while (p > 0) {
s = p & 0xf;
*(r++) = hex[s];
p = p >> 4;
}
*r = '_';
while (r >= result)
*(c++) = *(r--);
strcpy (c, type);
} else {
strcpy (c, "NULL");
}
}
/* Function for getting a pointer value */
SWIGSTATICRUNTIME(char *)
SWIG_GetPtr(char *c, void **ptr, char *t)
{
unsigned long p;
char temp_type[256], *name;
int i, len, start, end;
SwigPtrType *sp,*tp;
SwigCacheType *cache;
register int d;
p = 0;
/* Pointer values must start with leading underscore */
if (*c != '_') {
*ptr = (void *) 0;
if (strcmp(c,"NULL") == 0) return (char *) 0;
else c;
}
c++;
/* Extract hex value from pointer */
while (d = *c) {
if ((d >= '0') && (d <= '9'))
p = (p << 4) + (d - '0');
else if ((d >= 'a') && (d <= 'f'))
p = (p << 4) + (d - ('a'-10));
else
break;
c++;
}
*ptr = (void *) p;
if ((!t) || (strcmp(t,c)==0)) return (char *) 0;
if (!SwigPtrSort) {
qsort((void *) SwigPtrTable, SwigPtrN, sizeof(SwigPtrType), swigsort);
for (i = 0; i < 256; i++) SwigStart[i] = SwigPtrN;
for (i = SwigPtrN-1; i >= 0; i--) SwigStart[(int) (SwigPtrTable[i].name[1])] = i;
for (i = 255; i >= 1; i--) {
if (SwigStart[i-1] > SwigStart[i])
SwigStart[i-1] = SwigStart[i];
}
SwigPtrSort = 1;
for (i = 0; i < SWIG_CACHESIZE; i++) SwigCache[i].stat = 0;
}
/* First check cache for matches. Uses last cache value as starting point */
cache = &SwigCache[SwigLastCache];
for (i = 0; i < SWIG_CACHESIZE; i++) {
if (cache->stat && (strcmp(t,cache->name) == 0) && (strcmp(c,cache->mapped) == 0)) {
cache->stat++;
if (cache->tp->cast) *ptr = (*(cache->tp->cast))(*ptr);
return (char *) 0;
}
SwigLastCache = (SwigLastCache+1) & SWIG_CACHEMASK;
if (!SwigLastCache) cache = SwigCache;
else cache++;
}
/* Type mismatch. Look through type-mapping table */
start = SwigStart[(int) t[1]];
end = SwigStart[(int) t[1]+1];
sp = &SwigPtrTable[start];
/* Try to find a match */
while (start <= end) {
if (strncmp(t,sp->name,sp->len) == 0) {
name = sp->name;
len = sp->len;
tp = sp->next;
/* Try to find entry for our given datatype */
while(tp) {
if (tp->len >= 255) {
return c;
}
strcpy(temp_type,tp->name);
strncat(temp_type,t+len,255-tp->len);
if (strcmp(c,temp_type) == 0) {
strcpy(SwigCache[SwigCacheIndex].mapped,c);
strcpy(SwigCache[SwigCacheIndex].name,t);
SwigCache[SwigCacheIndex].stat = 1;
SwigCache[SwigCacheIndex].tp = tp;
SwigCacheIndex = SwigCacheIndex & SWIG_CACHEMASK;
/* Get pointer value */
*ptr = (void *) p;
if (tp->cast) *ptr = (*(tp->cast))(*ptr);
return (char *) 0;
}
tp = tp->next;
}
}
sp++;
start++;
}
return c;
}
#endif
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,367 @@
/**************************************************************************
* $Header$
*
* swigtcl8.swg
*
* This file provides type-checked pointer support to Tcl 8.0.
**********************************************************************/
#if defined(_WIN32) || defined(__WIN32__)
# if defined(_MSC_VER)
# define SWIGEXPORT(a) __declspec(dllexport) a
# else
# if defined(__BORLANDC__)
# define SWIGEXPORT(a) a _export
# else
# define SWIGEXPORT(a) a
# endif
# endif
#else
# define SWIGEXPORT(a) a
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifdef SWIG_GLOBAL
#include <tcl.h>
#define SWIGSTATICRUNTIME(a) SWIGEXPORT(a)
#else
#define SWIGSTATICRUNTIME(a) static a
#endif
#ifdef SWIG_NOINCLUDE
extern void SWIG_SetPointerObj(Tcl_Obj *, void *, char *);
extern void SWIG_RegisterMapping(char *, char *, void *(*)(void *));
extern char *SWIG_GetPointerObj(Tcl_Interp *, Tcl_Obj *, void **, char *);
extern int SWIG_MakePtr(char *, const void *, char *);
extern void SWIG_RegisterType();
#else
/* These are internal variables. Should be static */
typedef struct SwigPtrType {
char *name;
int len;
void *(*cast)(void *);
struct SwigPtrType *next;
} SwigPtrType;
/* Pointer cache structure */
typedef struct {
int stat; /* Status (valid) bit */
SwigPtrType *tp; /* Pointer to type structure */
char name[256]; /* Given datatype name */
char mapped[256]; /* Equivalent name */
} SwigCacheType;
static int SwigPtrMax = 64; /* Max entries that can be currently held */
static int SwigPtrN = 0; /* Current number of entries */
static int SwigPtrSort = 0; /* Status flag indicating sort */
static int SwigStart[256]; /* Array containing start locations (for searching) */
static SwigPtrType *SwigPtrTable = 0; /* Table containing pointer equivalences */
/* Cached values */
#define SWIG_CACHESIZE 8
#define SWIG_CACHEMASK 0x7
static SwigCacheType SwigCache[SWIG_CACHESIZE];
static int SwigCacheIndex = 0;
static int SwigLastCache = 0;
/* Sort comparison function */
static int swigsort(const void *data1, const void *data2) {
SwigPtrType *d1 = (SwigPtrType *) data1;
SwigPtrType *d2 = (SwigPtrType *) data2;
return strcmp(d1->name,d2->name);
}
/* Binary Search function */
static int swigcmp(const void *key, const void *data) {
char *k = (char *) key;
SwigPtrType *d = (SwigPtrType *) data;
return strncmp(k,d->name,d->len);
}
/*---------------------------------------------------------------------
* SWIG_RegisterMapping(char *origtype, char *newtype, void *(*cast)(void *))
*
* Register a new type-mapping with the type-checking system.
*---------------------------------------------------------------------*/
SWIGSTATICRUNTIME(void)
SWIG_RegisterMapping(char *origtype, char *newtype, void *(*cast)(void *)) {
int i;
SwigPtrType *t = 0, *t1;
if (!SwigPtrTable) {
SwigPtrTable = (SwigPtrType *) malloc(SwigPtrMax*sizeof(SwigPtrType));
SwigPtrN = 0;
}
if (SwigPtrN >= SwigPtrMax) {
SwigPtrMax = 2*SwigPtrMax;
SwigPtrTable = (SwigPtrType *) realloc(SwigPtrTable,SwigPtrMax*sizeof(SwigPtrType));
}
for (i = 0; i < SwigPtrN; i++)
if (strcmp(SwigPtrTable[i].name,origtype) == 0) {
t = &SwigPtrTable[i];
break;
}
if (!t) {
t = &SwigPtrTable[SwigPtrN];
t->name = origtype;
t->len = strlen(origtype);
t->cast = 0;
t->next = 0;
SwigPtrN++;
}
while (t->next) {
if (strcmp(t->name,newtype) == 0) {
if (cast) t->cast = cast;
return;
}
t = t->next;
}
t1 = (SwigPtrType *) malloc(sizeof(SwigPtrType));
t1->name = newtype;
t1->len = strlen(newtype);
t1->cast = cast;
t1->next = 0;
t->next = t1;
SwigPtrSort = 0;
}
/*---------------------------------------------------------------------
* void SWIG_SetPointerObj(Tcl_Obj *objPtr, void *ptr, char *type)
*
* Sets a Tcl object to a pointer value.
* ptr = void pointer value
* type = string representing type
*
*---------------------------------------------------------------------*/
SWIGSTATICRUNTIME(void)
SWIG_SetPointerObj(Tcl_Obj *objPtr, void *_ptr, char *type) {
static char _hex[16] =
{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f'};
unsigned long _p, _s;
char _result[20], *_r; /* Note : a 64-bit hex number = 16 digits */
char _temp[20], *_c;
_r = _result;
_p = (unsigned long) _ptr;
if (_p > 0) {
while (_p > 0) {
_s = _p & 0xf;
*(_r++) = _hex[_s];
_p = _p >> 4;
}
*_r = '_';
_c = &_temp[0];
while (_r >= _result)
*(_c++) = *(_r--);
*_c = 0;
Tcl_SetStringObj(objPtr,_temp,-1);
} else {
Tcl_SetStringObj(objPtr,"NULL",-1);
}
if (_ptr)
Tcl_AppendToObj(objPtr,type,-1);
}
/* This is for backwards compatibility */
SWIGSTATICRUNTIME(int)
SWIG_MakePtr(char *_c, const void *_ptr, char *type)
{
static char _hex[16] =
{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f'};
unsigned long _p, _s;
char _result[20], *_r;
int l = 0;
_r = _result;
_p = (unsigned long) _ptr;
if (_p > 0) {
while (_p > 0) {
_s = _p & 0xf;
*(_r++) = _hex[_s];
_p = _p >> 4;
l++;
}
*_r = '_';
l++;
while (_r >= _result)
*(_c++) = *(_r--);
_r = type;
while (*_r)
*(_c++) = *(_r++);
*(_c) = 0;
} else {
strcpy (_c, "NULL");
}
return l;
}
/*---------------------------------------------------------------------
* char *SWIG_GetPointerObj(Tcl_Interp *interp, Tcl_Obj *objPtr, void **ptr, char *type)
*
* Attempts to extract a pointer value from our pointer type.
* Upon failure, returns a string corresponding to the actual datatype.
* Upon success, returns NULL and sets the pointer value in ptr.
*---------------------------------------------------------------------*/
SWIGSTATICRUNTIME(char *)
SWIG_GetPointerObj(Tcl_Interp *interp, Tcl_Obj *objPtr, void **ptr, char *_t) {
unsigned long _p;
char temp_type[256];
char *name;
int i, len;
SwigPtrType *sp,*tp;
SwigCacheType *cache;
int start, end;
char *_c;
_p = 0;
/* Extract the pointer value as a string */
_c = Tcl_GetStringFromObj(objPtr, &i);
/* Pointer values must start with leading underscore */
if (*_c == '_') {
_c++;
/* Extract hex value from pointer */
while (*_c) {
if ((*_c >= '0') && (*_c <= '9'))
_p = (_p << 4) + (*_c - '0');
else if ((*_c >= 'a') && (*_c <= 'f'))
_p = (_p << 4) + ((*_c - 'a') + 10);
else
break;
_c++;
}
if (_t) {
if (strcmp(_t,_c)) {
if (!SwigPtrSort) {
qsort((void *) SwigPtrTable, SwigPtrN, sizeof(SwigPtrType), swigsort);
for (i = 0; i < 256; i++) {
SwigStart[i] = SwigPtrN;
}
for (i = SwigPtrN-1; i >= 0; i--) {
SwigStart[(int) (SwigPtrTable[i].name[1])] = i;
}
for (i = 255; i >= 1; i--) {
if (SwigStart[i-1] > SwigStart[i])
SwigStart[i-1] = SwigStart[i];
}
SwigPtrSort = 1;
for (i = 0; i < SWIG_CACHESIZE; i++)
SwigCache[i].stat = 0;
}
/* First check cache for matches. Uses last cache value as starting point */
cache = &SwigCache[SwigLastCache];
for (i = 0; i < SWIG_CACHESIZE; i++) {
if (cache->stat) {
if (strcmp(_t,cache->name) == 0) {
if (strcmp(_c,cache->mapped) == 0) {
cache->stat++;
*ptr = (void *) _p;
if (cache->tp->cast) *ptr = (*(cache->tp->cast))(*ptr);
return (char *) 0;
}
}
}
SwigLastCache = (SwigLastCache+1) & SWIG_CACHEMASK;
if (!SwigLastCache) cache = SwigCache;
else cache++;
}
/* We have a type mismatch. Will have to look through our type
mapping table to figure out whether or not we can accept this datatype */
start = SwigStart[(int) _t[1]];
end = SwigStart[(int) _t[1]+1];
sp = &SwigPtrTable[start];
while (start < end) {
if (swigcmp(_t,sp) == 0) break;
sp++;
start++;
}
if (start > end) sp = 0;
/* Try to find a match for this */
while (start <= end) {
if (swigcmp(_t,sp) == 0) {
name = sp->name;
len = sp->len;
tp = sp->next;
/* Try to find entry for our given datatype */
while(tp) {
if (tp->len >= 255) {
return _c;
}
strcpy(temp_type,tp->name);
strncat(temp_type,_t+len,255-tp->len);
if (strcmp(_c,temp_type) == 0) {
strcpy(SwigCache[SwigCacheIndex].mapped,_c);
strcpy(SwigCache[SwigCacheIndex].name,_t);
SwigCache[SwigCacheIndex].stat = 1;
SwigCache[SwigCacheIndex].tp = tp;
SwigCacheIndex = SwigCacheIndex & SWIG_CACHEMASK;
/* Get pointer value */
*ptr = (void *) _p;
if (tp->cast) *ptr = (*(tp->cast))(*ptr);
return (char *) 0;
}
tp = tp->next;
}
}
sp++;
start++;
}
/* Didn't find any sort of match for this data.
Get the pointer value and return the received type */
*ptr = (void *) _p;
return _c;
} else {
/* Found a match on the first try. Return pointer value */
*ptr = (void *) _p;
return (char *) 0;
}
} else {
/* No type specified. Good luck */
*ptr = (void *) _p;
return (char *) 0;
}
} else {
if (strcmp (_c, "NULL") == 0) {
*ptr = (void *) 0;
return (char *) 0;
}
*ptr = (void *) 0;
return _c;
}
}
/*---------------------------------------------------------------------
* void SWIG_RegisterType()
*
* Registers our new datatype with an interpreter.
*---------------------------------------------------------------------*/
SWIGSTATICRUNTIME(void)
SWIG_RegisterType() {
/* Does nothing at the moment */
}
#endif
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,30 @@
#!/bin/sh
necho() {
if [ "`echo -n`" = "-n" ]; then
echo "${@}\c"
else
echo -n "${@}"
fi
}
# Script that attempts to produce different run-time libraries
TARGET='perl_lib perl_shared py_lib py_shared tcl_lib tcl_shared tcl8_lib tcl8_shared'
echo "Building the SWIG runtime libraries..."
echo ""
echo "*** Note : Some builds may fail due to uninstalled packages or"
echo "unsupported features such as dynamic loading (don't panic)."
echo ""
for i in ${TARGET}; do
necho " Building ${i}";
if make ${i} >/dev/null 2>&1; then
# See if SWIG generated any errors at all
echo " ....... OK.";
else
echo " ....... failed.";
fi;
done

View File

@@ -0,0 +1,99 @@
# Modified for use with Microsoft Developer Studio V6.0
# Bob Techentin, February 10, 1999
#
# Makefile for producing SWIG runtime libraries.
#
# The SWIG runtime library consists of the pointer-type checker
# and other support functions. Multi-file SWIG modules
# generally link with these libraries.
#
# The Windows version of the runtime libraries are static.
# Note the "-" command prefix ignores errors during compiles
# and links, because you might not have all languages.
!include <..\make_win.in>
SWIG_RUNTIME = $(prefix)/lib
dSWIG_RUNTIME = $(dprefix)\lib
AR = lib.exe
all: tcl_lib tcl8_lib py_lib perl_lib
install:
@echo "Installing runtime libraries"
@if not exist $(dSWIG_RUNTIME) mkdir $(dSWIG_RUNTIME)
if exist swigtcl.lib copy swigtcl.lib $(dSWIG_RUNTIME)
if exist swigtcl8.lib copy swigtcl8.lib $(dSWIG_RUNTIME)
if exist swigpy.lib copy swigpy.lib $(dSWIG_RUNTIME)
if exist swigpl.lib copy swigpl.lib $(dSWIG_RUNTIME)
install95:
@echo "Installing runtime libraries"
@if not exist $(dSWIG_RUNTIME) mkdir $(dSWIG_RUNTIME)
if exist swigtcl.lib copy swigtcl.lib $(dSWIG_RUNTIME) /Y
if exist swigtcl8.lib copy swigtcl8.lib $(dSWIG_RUNTIME) /Y
if exist swigpy.lib copy swigpy.lib $(dSWIG_RUNTIME) /Y
if exist swigpl.lib copy swigpl.lib $(dSWIG_RUNTIME) /Y
clean::
del /f *.obj
del /f *.lib
del /f *.c
del /f *.swg
del /f core
# ----------------------------------------------------------------------
# Tcl runtime library
# ----------------------------------------------------------------------
TCL_INCLUDE = -Ic:\apps\TclPro1.1\include
# Tcl 7.x library
tcl_lib:
-..\swig.exe -tcl -co -o libtcl.c -I..\swig_lib swigtcl.swg
-$(CC) -c -DSWIG_GLOBAL libtcl.c
-$(AR) /out:swigtcl.lib libtcl.obj
tcl8_lib:
-..\swig.exe -tcl -co -o libtcl8.c -I..\swig_lib swigtcl8.swg
-$(CC) -c -DSWIG_GLOBAL $(TCL_INCLUDE) libtcl8.c
-$(AR) /out:swigtcl8.lib libtcl8.obj
# ----------------------------------------------------------------------
# Python run-time library
# ----------------------------------------------------------------------
PYTHON_INCLUDE = -Ic:\apps\python-1.5\Include -Ic:\apps\python-1.5 -Ic:\apps\python-1.5\PC
# Python library
py_lib:
-..\swig.exe -python -co -o libpy.c -I../swig_lib python.swg
-$(CC) -c -DSWIG_GLOBAL $(PYTHON_INCLUDE) libpy.c
-$(AR) /out:swigpy.lib libpy.obj
# ----------------------------------------------------------------------
# Perl run-time library
# ----------------------------------------------------------------------
# These are for Perl5.004
PERL_INCLUDE = -Ic:\apps\perl\lib\CORE
PERLFLAGS = /DWIN32 /DMSWIN32 /DWIN32IO_IS_STDIO
# Uncomment the following if you are using ActiveWare Perl for Win32
#PERL_INCLUDE =-Id:\perl315 -Id:\perl315\inc
#PERLFLAGS = /DWIN32 /DMSWIN32 /DPERL_OBJECT
# Perl library
perl_lib:
-del /f libperl.c libperl.swg
-..\swig.exe -perl5 -co -o libperl.swg -I..\swig_lib perl5.swg
-copy perlrun.h+libperl.swg libperl.c
-$(CC) -c -Dexplicit= -Dbool=char -DSWIG_GLOBAL $(PERFLAGS) $(PERL_INCLUDE) libperl.c
-$(AR) /out:swigpl.lib libperl.obj

View File

@@ -0,0 +1,3 @@
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

View File

@@ -0,0 +1,126 @@
#######################################################################
# $Header$
# Simplified Wrapper and Interface Generator (SWIG)
#
# Makefile for version 1.0 Final
# Dave Beazley
# August 1, 1996
#
# This makefile is now mostly constructed by ./configure.
#
# $Log$
# Revision 1.1 2002/04/29 19:56:48 RD
# Since I have made several changes to SWIG over the years to accomodate
# special cases and other things in wxPython, and since I plan on making
# several more, I've decided to put the SWIG sources in wxPython's CVS
# instead of relying on maintaining patches. This effectivly becomes a
# fork of an obsolete version of SWIG, :-( but since SWIG 1.3 still
# doesn't have some things I rely on in 1.1, not to mention that my
# custom patches would all have to be redone, I felt that this is the
# easier road to take.
#
# Revision 1.1.1.1 1999/02/28 02:00:51 beazley
# Swig1.1
#
# Revision 1.1 1996/08/12 01:55:02 dmb
# Initial revision
#
#######################################################################
#.KEEP_STATE:
srcdir = @srcdir@
VPATH = @srcdir@
# Set your C++ compiler here. g++ works on most machines,
# but you might have to change it depending on your installation.
#
CC = @CXX@
#
# Set the prefix below to indicate where you want SWIG to install its
# files. Normally this is /usr/local
#
prefix = @prefix@
# Location of the SWIG library. Is normally put in /usr/local/lib/swig_lib
# The SWIG library contains configuration files and library modules
# so you should install it someplace where it can be easily accessed.
SWIG_LIB = $(prefix)/lib/swig_lib
# YACC parser. Use bison by default. if this doesn't work, switch
# it over to yacc. If that still doesn't work, let me know...
YACC = @YACC@
# Comment out the following line if you're on an SGI or don't have ranlib!
RANLIB = @RANLIB@
AR = @AR@
########################################################################
# Normally, you shouldn't have to change anything below this point #
########################################################################
LIBOBJS = main.o scanner.o symbol.o include.o types.o parms.o emit.o newdoc.o ascii.o \
html.o latex.o cplus.o lang.o hash.o sstring.o wrapfunc.o getopt.o comment.o \
typemap.o naming.o
LIBSRCS = main.cxx scanner.cxx symbol.cxx include.cxx types.cxx parms.cxx emit.cxx \
newdoc.cxx ascii.cxx html.cxx latex.cxx cplus.cxx lang.cxx hash.cxx \
sstring.cxx wrapfunc.cxx getopt.cxx comment.cxx typemap.cxx naming.cxx
LIBHEADERS = internal.h ../Include/swig.h latex.h ascii.h html.h nodoc.h
LIB = ../libswig.a
PARSER = parser.y
INCLUDE = -I../Include
##-DSWIG_LIB='"$(SWIG_LIB)"'
CFLAGS = @CFLAGS@ -DSWIG_CC='"$(CC)"' @DEFS@
SHELL = /bin/sh
#
#
#
# Rules for creation of a .o file from .cxx
.SUFFIXES: .cxx
.cxx.o:
$(CC) $(INCLUDE) $(CFLAGS) -c -o $*.o $<
all: $(LIB)
$(LIB): parser.o $(LIBOBJS)
@echo "Building library"
$(AR) cr $(LIB) $(LIBOBJS) parser.o
$(RANLIB) $(LIB)
parser.o: parser.cxx $(LIBHEADERS)
$(CC) $(INCLUDE) $(CFLAGS) parser.cxx -c -o parser.o
parser.cxx: $(PARSER)
$(YACC) @YACCFLAGS@
@cp y.tab.h parser.h
@cp y.tab.c parser.cxx
parser::
@cp y.tab.c.bison parser.cxx
@cp y.tab.h.bison parser.h
@cp y.tab.h.bison y.tab.h
$(CC) $(CFLAGS) parser.cxx -c -o parser.o
Makefile: $(srcdir)/Makefile.in ../config.status
(cd ..; CONFIG_FILES=SWIG/Makefile $(SHELL) config.status)
.PRECIOUS: Makefile
clean::
rm -f *.o libswig.a y.tab.c y.tab.h
nuke::
rm -f Makefile *~ #* core a.out
wc::
wc $(LIBSRCS) *.h parser.y

View File

@@ -0,0 +1,464 @@
/*******************************************************************************
* 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.
*******************************************************************************/
#include "swig.h"
#include "ascii.h"
#include <ctype.h>
/*******************************************************************************
* $Header$
*
* File : ascii.cxx
*
* Module for producing ASCII documentation.
*
*******************************************************************************/
// -----------------------------------------------------------------------------
// ASCII::ASCII()
//
// Constructor. Initializes the ASCII module.
//
// Inputs : None
//
// Output : Documentation module object
//
// Side Effects :
// Sets page-width and indentation.
// -----------------------------------------------------------------------------
ASCII::ASCII() {
sect_count = 0;
indent = 8;
columns = 70;
}
// -----------------------------------------------------------------------------
// void ASCII::print_string(char *s, int margin, int mode)
//
// Prints a string to the documentation file. Performs line wrapping and
// other formatting.
//
// Inputs :
// s = NULL terminate ASCII string
// margin = Number of characters to be inserted on left side
// mode = If set, text will be reformatted. Otherwise, it's
// printed verbatim (with indentation).
//
// Output : None
//
// Side Effects : None
// -----------------------------------------------------------------------------
void ASCII::print_string(char *s, int margin, int mode) {
char *c;
int i;
int lbreak = 0;
int col;
c = s;
if (!s) return;
// Apply indentation
for (i = 0; i < margin; i++)
fputc(' ',f_doc);
col = margin;
if (mode) {
// Dump out text in formatted mode
// Strip leading white-space
while ((*c) && (isspace(*c))) {
c++;
}
while (*c) {
switch(*c) {
case '\n':
case '\\':
if (lbreak) {
col = margin;
fputc('\n',f_doc);
for (i = 0; i < margin; i++)
fputc(' ',f_doc);
lbreak = 0;
} else {
if ((*c) == '\n') {
col++;
}
lbreak++;
}
break;
case ' ':
case '\t':
case '\r':
case '\f':
if (col > columns) {
fputc('\n',f_doc);
for (i = 0; i < margin; i++)
fputc(' ',f_doc);
col = margin;
} else {
fputc(' ',f_doc);
col++;
}
// Skip over rest of white space found
while ((*c) && isspace(*c)) c++;
c--;
lbreak = 0;
break;
default :
if (lbreak) fputc(' ',f_doc);
lbreak = 0;
fputc(*c,f_doc);
col++;
break;
}
c++;
}
} else {
// Dump out text in pre-formatted mode
while (*c) {
switch(*c) {
case '\n':
fputc('\n',f_doc);
for (i = 0; i < margin; i++)
fputc(' ',f_doc);
break;
default :
fputc(*c,f_doc);
col++;
break;
}
c++;
}
}
}
// -----------------------------------------------------------------------------
// void ASCII::print_decl(DocEntry *de)
//
// Prints the documentation entry corresponding to a declaration
//
// Inputs :
// de = Documentation entry (which should be for a declaration)
//
// Output : None
//
// Side Effects : None
// -----------------------------------------------------------------------------
void ASCII::print_decl(DocEntry *de) {
int i;
char *c;
c = de->usage.get();
fprintf(f_doc,"%s\n",c);
// If there is any C annotation, print that
if (de->print_info) {
c = de->cinfo.get();
if (strlen(c) > 0) {
for (i = 0; i < indent; i++)
fputc(' ',f_doc);
fprintf(f_doc,"[ ");
print_string(c,0,1);
fprintf(f_doc," ]\n");
}
}
c = de->text.get();
if (strlen(c) > 0) {
print_string(c,indent,de->format);
fprintf(f_doc,"\n");
if (de->format) fputc('\n',f_doc);
} else {
fprintf(f_doc,"\n");
}
}
// -----------------------------------------------------------------------------
// void ASCII::print_text(DocEntry *de)
//
// Prints the documentation for a block of text. Will strip any leading white
// space from the text block.
//
// Inputs :
// de = Documentation entry of text
//
// Output : None
//
// Side Effects : None
// -----------------------------------------------------------------------------
void ASCII::print_text(DocEntry *de) {
char *c;
c = de->text.get();
if (strlen(c) > 0) {
while ((*c == '\n')) c++;
print_string(c,0,de->format);
fprintf(f_doc,"\n\n");
}
}
// -----------------------------------------------------------------------------
// void ASCII::title(DocEntry *de)
//
// Sets the title of the documentation file.
//
// Inputs :
// de = Documentation entry of the title.
//
// Output : None
//
// Side Effects : None
// -----------------------------------------------------------------------------
void ASCII::title(DocEntry *de) {
char *c;
c = de->usage.get();
if (strlen(c) > 0) {
fprintf(f_doc,"%s\n\n",c);
}
// If there is any C annotation, print that
if (de->print_info) {
c = de->cinfo.get();
if (strlen(c) > 0) {
fprintf(f_doc,"[ ");
print_string(c,0,1);
fprintf(f_doc," ]\n");
}
}
c = de->text.get();
if (strlen(c)) {
print_string(c,0,de->format);
}
fprintf(f_doc,"\n\n");
}
// -----------------------------------------------------------------------------
// void ASCII::newsection(DocEntry *de, int sectnum)
//
// Starts a new section. Will underline major sections and subsections, but
// not minor subsections.
//
// Inputs :
// de = Documentation entry of the section
// sectnum = Section number.
//
// Output : None
//
// Side Effects :
// Forces a new subsection to be created within the ASCII module.
// -----------------------------------------------------------------------------
void ASCII::newsection(DocEntry *de,int sectnum) {
int i,len = 0;
char temp[256];
char *c;
sect_num[sect_count] = sectnum;
sect_count++;
for (i = 0; i < sect_count; i++) {
sprintf(temp,"%d.",sect_num[i]);
fprintf(f_doc,"%s",temp);
len += strlen(temp);
}
c = de->usage.get();
fprintf(f_doc," %s\n", c);
len += strlen(c) + 2;
// Print an underline if this is a major category
if (sect_count <= 1) {
for (i = 0; i < len; i++)
fputc('=',f_doc);
fputc('\n',f_doc);
} else if (sect_count == 2) {
for (i = 0; i < len; i++)
fputc('-',f_doc);
fputc('\n',f_doc);
} else {
fputc('\n',f_doc);
}
// If there is any C annotation, print that
if (de->print_info) {
c = de->cinfo.get();
if (strlen(c) > 0) {
fprintf(f_doc,"[ ");
print_string(c,0,1);
fprintf(f_doc," ]\n\n");
}
}
// If there is a description text. Print it
c = de->text.get();
if (strlen(c) > 0) {
print_string(c,0,de->format);
fprintf(f_doc,"\n");
}
fprintf(f_doc,"\n");
}
// -----------------------------------------------------------------------------
// void ASCII::endsection()
//
// Ends the current section. It is an error to call this without having first
// called newsection().
//
// Inputs : None
//
// Output : None
//
// Side Effects :
// Pops out of the current section, moving back into the parent section
// -----------------------------------------------------------------------------
void ASCII::endsection() {
if (sect_count > 0) sect_count--;
}
// -----------------------------------------------------------------------------
// void ASCII::separator()
//
// Prints a small dashed line that is used to designate the end of C++ class
// subsections.
//
// Inputs : None
//
// Output : None
//
// Side Effects : None
// -----------------------------------------------------------------------------
void ASCII::separator() {
int i;
for (i = 0; i < 10; i++)
fputc('-',f_doc);
fprintf(f_doc,"\n\n");
}
// -----------------------------------------------------------------------------
// void ASCII::init(char *filename)
//
// Initializes the documentation module and opens up the documentation file.
//
// Inputs : filename = name of documentation file (without suffix)
//
// Output : None
//
// Side Effects : Opens the documentation file.
// -----------------------------------------------------------------------------
void ASCII::init(char *filename) {
char f[256];
sprintf(f,"%s.doc",filename);
sprintf(fn,"%s",filename);
f_doc = fopen(f,"w");
if (f_doc == NULL) {
fprintf(stderr, "Unable to open %s\n", fn);
SWIG_exit(1);
}
}
// -----------------------------------------------------------------------------
// void ASCII::close()
//
// Closes the documentation module. This function should only be called once
//
// Inputs : None
//
// Output : None
//
// Side Effects : Closes the documentation file.
// -----------------------------------------------------------------------------
void ASCII::close(void) {
fclose(f_doc);
if (Verbose)
fprintf(stderr,"Documentation written to %s.doc\n", fn);
}
// -----------------------------------------------------------------------------
// void ASCII::style(char *name, char *value)
//
// Looks for style parameters that the user might have supplied using the
// %style directive. Unrecognized options are simply ignored.
//
// Inputs :
// name = name of the style parameter
// value = value of the style parameter (optional)
//
// Output : None
//
// Side Effects : Can change internal settings of 'indent' and 'columns' members.
// -----------------------------------------------------------------------------
void ASCII::style(char *name, char *value) {
if (strcmp(name,"ascii_indent") == 0) {
if (value) {
indent = atoi(value);
}
} else if (strcmp(name,"ascii_columns") == 0) {
if (value) {
columns = atoi(value);
}
}
}
// -----------------------------------------------------------------------------
// void ASCII::parse_args(int argc, char **argv)
//
// Function for processing options supplied on the SWIG command line.
//
// Inputs :
// argc = Number of arguments
// argv = Argument strings
//
// Output : None
//
// Side Effects : May set various internal parameters.
// -----------------------------------------------------------------------------
static char *ascii_usage = "\
ASCII Documentation Options (available with -dascii)\n\
None available.\n\n";
void ASCII::parse_args(int argc, char **argv) {
int i;
for (i = 0; i < argc; i++) {
if (argv[i]) {
if (strcmp(argv[i],"-help") == 0) {
fputs(ascii_usage,stderr);
}
}
}
}

View File

@@ -0,0 +1,64 @@
/*******************************************************************************
* 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.
*******************************************************************************/
/***********************************************************************
* $Header$
*
* ascii.h
*
* ASCII specific functions for producing documentation. Basically
* prints things out as 80 column ASCII.
***********************************************************************/
class ASCII : public Documentation {
private:
FILE *f_doc;
char fn[256];
void print_string(char *s,int indent,int mode);
int indent; // Indentation (for formatting)
int columns; // Number of columns (for formatting)
int sect_count; // Section counter
int sect_num[20]; // Section numbers
// Style parameters
public:
ASCII();
void parse_args(int argc, char **argv);
void title(DocEntry *de);
void newsection(DocEntry *de, int sectnum);
void endsection();
void print_decl(DocEntry *de);
void print_text(DocEntry *de);
void separator();
void init(char *filename);
void close(void);
void style(char *name, char *value);
};

View File

@@ -0,0 +1,697 @@
/*******************************************************************************
* 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.
*******************************************************************************/
#include "internal.h"
/*******************************************************************************
* $Header$
*
* File : comment.cxx
*
* This is a semi-magical module for associating C/C++ comments with
* documentation entries. While this sounds like it might be easy,
* there are a number of subtle problems getting things to associate
* correctly.
*
* Here's the general idea :
*
* 1. The parser and scanner feed both C comments and documentation
* entries to this class. These may show up in really bizarre
* orders (not necessarily the order seen in an interface file).
*
* 2. We maintain separate lists of comments and documentation
* entries.
*
* 3. Periodically, we go through the list of documentation entries
* and see if we can associate any comments.
*
* 4. Upon completion of parsing, it's critical that we cleanup
* the lists using the cleanup() method.
*
*******************************************************************************/
// -----------------------------------------------------------------------------
// struct Comment
//
// Structure used to maintain a linked list of comments for later use.
// -----------------------------------------------------------------------------
class Comment {
public:
String *text; // Text of the comment
int first_line; // First line of the comment
int last_line; // Last line of the comment
int column; // First column of comment
char *file; // Name of the file that it was in
Comment *next; // Next comment (when in a linked list)
Comment *prev; // Previous comment
static Comment *comment_list; // List of all comments
Comment(char *t, int line, int col, char *f);
~Comment();
static Comment *find(DocEntry *de, CommentHandler *ch);
void attach(DocEntry *de, CommentHandler *ch);
};
// -----------------------------------------------------------------------
// Create a new comment. Automatically puts it on the linked list
// -----------------------------------------------------------------------
Comment::Comment(char *t, int line, int col, char *f) {
int nlines = 0;
char *c;
text = new String(t);
c = t;
while (*c) {
if (*c == '\n') nlines++;
c++;
}
first_line = line;
column = col;
last_line = line + nlines - 1;
file = copy_string(f);
if (comment_list) {
comment_list->prev = this;
}
next = comment_list;
comment_list = this;
prev = 0;
}
// -----------------------------------------------------------------------
// Destroy a comment
// -----------------------------------------------------------------------
Comment::~Comment() {
delete text;
delete file;
// Remove from linked list (if applicable)
if (prev) {
prev->next = next;
}
if (next) {
next->prev = prev;
}
if (this == comment_list) comment_list = next;
}
// -----------------------------------------------------------------------
// find(DocEntry *de, CommentHandler *ch)
//
// This function tries to a find a comment matching the search criteria
// of a given comment handler and documentation entry.
// -----------------------------------------------------------------------
Comment *Comment::find(DocEntry *de, CommentHandler *ch) {
Comment *c;
c = comment_list;
// Start walking down our list of stored comments
while (c) {
// printf("Searching %x : %s\n", c, c->text->get());
if (strcmp(de->file,c->file) == 0) {
// At least comment is in the right file. Now check line numbers
if (ch->location == BEFORE) {
// Check to see if the last line of the comment is close
// enough to our declaration.
if ((c->last_line <= de->line_number) &&
((de->line_number - c->last_line) <= ch->skip_lines)) {
return c;
}
} else { // AFTER mode
// Check to see if the first line of the comment is close
// enough to our declaration.
if ((c->first_line >= de->end_line) &&
((c->first_line - de->end_line) <= ch->skip_lines)) {
return c;
}
}
// Check to see if the line numbers are too small. Comments
// are processed in order so there's no sense in checking
// all entries.
if (c->last_line < de->line_number)
return 0;
}
c = c->next;
}
return 0;
}
// -----------------------------------------------------------------------
// void attach(DocEntry *de, CommentHandler *ch)
//
// This function attachs a comment to a documentation entry and applies
// all of the style information in the comment handler.
// -----------------------------------------------------------------------
void Comment::attach(DocEntry *de, CommentHandler *ch) {
int nlines = 0;
char **split = 0;
char *c;
int i,lnum,el;
if (!de) return;
// If we're ignoring comments, forget it
if (ch->ignore) {
return;
}
// If the comment is formatted, no style processing is applied
if (de->format) {
de->text << *text;
return;
}
// Untabify the comment
if (ch->untabify) text->untabify();
// Count how many lines we have
c = text->get();
while (*c) {
if (*c == '\n') nlines++;
c++;
}
if (nlines == 0) return;
// Tokenize the documentation string into lines
split = new char*[nlines+1];
c = text->get();
i = 0;
split[i] = c;
while (*c) {
if (*c == '\n') {
*(c++) = 0;
split[++i] = c;
} else c++;
}
lnum = 0;
// Now process the chop_top and chop_bottom values
// if nlines < (chop_top + chop_bottom), then we do nothing
if (nlines > (ch->chop_top + ch->chop_bottom)) {
lnum += ch->chop_top;
el = nlines-ch->chop_bottom;
} else {
el = nlines;
}
// Now process in-between lines
while (lnum < el) {
/* Chop line */
if (split[lnum]) {
if (strlen(split[lnum]) > (unsigned) (ch->chop_left+ch->chop_right)) {
if (ch->chop_right > 0)
split[lnum][strlen(split[lnum]) - ch->chop_right] = 0;
de->text << &split[lnum][ch->chop_left];
}
}
lnum++;
de->text << "\n";
}
// printf("*** ATTACHING %s : %s\n", de->usage.get(), de->text.get());
delete split;
}
CommentHandler *comment_handler = 0;
Comment *Comment::comment_list = 0;
// ------------------------------------------------------------------------
// struct DocEntryList
//
// This structure manages a linked list of documentation entries that
// haven't had comments attached to them yet.
//
// As a general rule, this list tends to remain rather short.
// ------------------------------------------------------------------------
struct DocEntryList {
DocEntry *de;
CommentHandler *ch;
DocEntryList *next;
DocEntryList *prev;
static DocEntryList *doc_list;
// -----------------------------------------------------------------------
// Create a new list entry
// -----------------------------------------------------------------------
DocEntryList(DocEntry *d, CommentHandler *c) {
de = d;
ch = c;
next = doc_list;
prev = 0;
if (doc_list)
doc_list->prev = this;
doc_list = this;
// Only allow a few doc entries to survive
if (this->next) {
if (this->next->next) {
delete this->next->next;
}
}
}
// -----------------------------------------------------------------------
// Destroy a list entry
// -----------------------------------------------------------------------
~DocEntryList() {
if (prev) {
prev->next = next;
}
if (next) {
next->prev = prev;
}
if (this == doc_list) doc_list = next;
};
// -----------------------------------------------------------------------
// static check()
//
// Checks the list of documentation entries to see if any can be associated.
// -----------------------------------------------------------------------
static void check() {
DocEntryList *dl, *dl_temp;
Comment *cmt;
// printf ("Checking\n");
dl = doc_list;
while (dl) {
cmt = Comment::find(dl->de,dl->ch);
if (cmt) {
// Okay, we found a matching comment. Attach it to this
// documentation entry.
cmt->attach(dl->de,dl->ch);
// Destroy the comment and doc list entry
delete cmt;
// Declarations are always coming in order so we're going
// to blow away all of them past this point
dl_temp = dl->next;
delete dl;
dl = dl_temp;
} else {
dl = dl->next;
}
}
}
};
DocEntryList *DocEntryList::doc_list = 0;
// -----------------------------------------------------------------------------
// CommentHandler::CommentHandler()
//
// Constructor. Creates a new comment handler. Sets up some default values
// for comment handling.
//
// Inputs : None
//
// Output : New CommentHandler object.
//
// Side Effects : Sets default comment handling parameters.
// -----------------------------------------------------------------------------
CommentHandler::CommentHandler() {
skip_lines = 1;
location = AFTER;
chop_top = 0;
chop_bottom = 0;
chop_left = 3;
chop_right = 0;
untabify = 1;
ignore = 0;
}
// -----------------------------------------------------------------------------
// CommentHandler::CommentHandler(CommentHandler *c)
//
// Constructor. Creates a new comment handler, but copies attributes from
// another handler.
//
// Inputs :
// c = A different comment handler.
//
// Output : A new CommentHandler object.
//
// Side Effects : None
// -----------------------------------------------------------------------------
CommentHandler::CommentHandler(CommentHandler *c) {
skip_lines = c->skip_lines;
location = c->location;
chop_top = c->chop_top;
chop_bottom = c->chop_bottom;
chop_left = c->chop_left;
chop_right = c->chop_right;
untabify = c->untabify;
ignore = c->ignore;
}
// -----------------------------------------------------------------------------
// CommentHandler::~CommentHandler()
//
// Destructor. Destroys a comment handler. Does nothing interesting at the
// moment.
//
// Inputs : None
//
// Output : None
//
// Side Effects : None
// -----------------------------------------------------------------------------
CommentHandler::~CommentHandler() {
}
// -----------------------------------------------------------------------------
// void CommentHandler::add_comment(char *text, int line_num, int col, char *file)
//
// This function takes a character string as comment text and appends
// it to the current comment string (which is held in Comment::comment_list)
//
// 1. If two comments appear in successive lines, they are
// concatenated. This is to handle C++ style comments like the
// one surrounding this text.
//
// 2. If a new comment appears, we simply create a new one
//
// Inputs :
// text = Text of the comment
// line_num = Starting line number of the comment
// col = Starting column of the comment
// file = File in which the comment was located.
//
// Output : None
//
// Side Effects :
// Saves the comment in an internal linked list.
// If multiple comments appear in succession, some may end up
// in our comment list permanently (ie. never attached to any
// particular declaration).
// -----------------------------------------------------------------------------
void CommentHandler::add_comment(char *text, int line_num, int col, char *file) {
char *c;
int nlines = 0;
Comment *cmt;
// printf("line_num = %d, %s\n", line_num,text);
// Count up how many lines are in this comment
c = text;
while (*c) {
if (*c == '\n') nlines++;
c++;
}
// Check to see if this comment is in a successive line to the last one
cmt = Comment::comment_list;
if (cmt) {
// Check for column alignment
if ((cmt->column == col) && (line_num == (cmt->last_line + 1)) &&
(nlines <= 1)) {
*(cmt->text) << text;
cmt->last_line = line_num + nlines - 1;
} else {
// This is a new comment, add it to our list
cmt = new Comment(text,line_num,col,file);
}
} else {
cmt = new Comment(text,line_num,col,file);
}
}
// -----------------------------------------------------------------------------
// void CommentHanlder::set_entry(DocEntry *d)
//
// This grabs a DocEntry and hangs onto it.
//
// We will place the doc entry into our documentation list and then
// check it to see if any comments are sitting around.
//
// Inputs : d = Documentation Entry
//
// Output : None
//
// Side Effects :
// May attach comments to the documentation entry. In this case,
// comments and DocEntries may be removed from internal lists.
// -----------------------------------------------------------------------------
void CommentHandler::set_entry(DocEntry *d) {
// printf("Set entry : file: %s, line %d, %s\n", d->file, d->line_number, d->usage.get());
// Create a new list entry and save it
new DocEntryList(d,this);
// Check all of the documentation entries to see if they can be placed
DocEntryList::check();
}
// -----------------------------------------------------------------------------
// static void CommentHandler::cleanup()
//
// Checks all documentation entries and sees if there are any comments available.
// If so, they are attached. This function is usually only called upon completion
// of parsing.
//
// Inputs : None
//
// Output : None
//
// Side Effects :
// Removes documentation entries and comments from internal lists.
//
// -----------------------------------------------------------------------------
void CommentHandler::cleanup() {
int nc, nd;
Comment *c;
DocEntryList *d;
DocEntryList::check();
// Figure out how bad we're doing on memory
nc = 0;
nd = 0;
c = Comment::comment_list;
while (c) {
nc++;
c = c->next;
}
d = DocEntryList::doc_list;
while(d) {
nd++;
d = d->next;
}
if (Verbose) {
printf("%d unprocessed comments, %d unprocessed doc entries.\n",nc,nd);
}
}
// -----------------------------------------------------------------------------
// void CommentHandler::style(char *name, char *value)
//
// Processes comment handling style parameters. The following parameters
// are available :
//
// after - Comments appear after a declaration
// before - Comments appear before a declaration
// skip - Number of blank lines between comment and decl.
// chop_top - Number of lines to chop from top of a comment
// chop_bottom - Number of lines to chop from bottom of a comment
// chop_left - Number of characters to chop from left
// chop_right - Number of characters to chop from right
// tabify - Leave tabs in comment text
// untabify - Strip tabs and convert them into spaces.
// ignore - Ignore comments
// enable - Enable comments
//
// Inputs :
// name - Name of style parameter
// value - Optional parameter value
//
// Output : None
//
// Side Effects : Changes style of comment handler object.
//
// -----------------------------------------------------------------------------
void CommentHandler::style(char *name, char *value) {
if (strcmp(name,"before") == 0) {
location = BEFORE;
} else if (strcmp(name,"after") == 0) {
location = AFTER;
} else if (strcmp(name,"skip") == 0) {
if (value)
skip_lines = atoi(value);
} else if (strcmp(name,"chop_top") == 0) {
if (value)
chop_top = atoi(value);
} else if (strcmp(name,"chop_bottom") == 0) {
if (value)
chop_bottom = atoi(value);
} else if (strcmp(name,"chop_left") == 0) {
if (value)
chop_left = atoi(value);
} else if (strcmp(name,"chop_right") == 0) {
if (value)
chop_right = atoi(value);
} else if (strcmp(name,"tabify") == 0) {
untabify = 0;
} else if (strcmp(name,"untabify") == 0) {
untabify = 1;
} else if (strcmp(name,"ignore") == 0) {
ignore = 1;
} else if (strcmp(name,"enable") == 0) {
ignore = 0;
}
}
// -----------------------------------------------------------------------------
// void CommentHandler::parse_args(int argc, char **argv)
//
// Function for processing command line options given on the SWIG command line.
// See the help string below for available options.
//
// Inputs :
// argc = Argument count
// argv = Argument strings
//
// Output : None
//
// Side Effects :
// Changes various style parameters for the top-level CommentHandler.
// -----------------------------------------------------------------------------
static char *comment_usage = "\
Comment Style Options : \n\
-Safter - Use comments after a declaration.\n\
-Sbefore - Use comments before a declaration.\n\
-Schop_bottom n - Chop n lines from bottom of comments.\n\
-Schop_left n - Chop n characters from left of a comment.\n\
-Schop_right n - Chop n characters from right of a comment.\n\
-Schop_top n - Chop n lines from top of comments.\n\
-Signore - Ignore comments.\n\
-Sskip n - Max lines between comment and declaration.\n\
-Stabify - Do not convert tabs.\n\
-Suntabify - Convert tabs into spaces (the default).\n\n";
void CommentHandler::parse_args(int argc, char **argv) {
int i;
for (i = 1; i < argc; i++) {
if (argv[i]) {
if (strcmp(argv[i],"-Sbefore") == 0) {
this->style("before",0);
mark_arg(i);
} else if (strcmp(argv[i],"-Safter") == 0) {
this->style("after",0);
mark_arg(i);
} else if (strcmp(argv[i],"-Schop_top") == 0) {
if (argv[i+1]) {
this->style("chop_top",argv[i+1]);
mark_arg(i);
mark_arg(i+1);
i++;
} else {
arg_error();
}
} else if (strcmp(argv[i],"-Schop_bottom") == 0) {
if (argv[i+1]) {
this->style("chop_bottom",argv[i+1]);
mark_arg(i);
mark_arg(i+1);
i++;
} else {
arg_error();
}
} else if (strcmp(argv[i],"-Schop_left") == 0) {
if (argv[i+1]) {
this->style("chop_left",argv[i+1]);
mark_arg(i);
mark_arg(i+1);
i++;
} else {
arg_error();
}
} else if (strcmp(argv[i],"-Schop_right") == 0) {
if (argv[i+1]) {
this->style("chop_right",argv[i+1]);
mark_arg(i);
mark_arg(i+1);
i++;
} else {
arg_error();
}
} else if (strcmp(argv[i],"-Sskip") == 0) {
if (argv[i+1]) {
this->style("skip",argv[i+1]);
mark_arg(i);
mark_arg(i+1);
i++;
} else {
arg_error();
}
} else if (strcmp(argv[i],"-Suntabify") == 0) {
this->style("untabify",0);
mark_arg(i);
} else if (strcmp(argv[i],"-Stabify") == 0) {
this->style("tabify",0);
mark_arg(i);
} else if (strcmp(argv[i],"-Signore") == 0) {
this->style("ignore",0);
} else if (strcmp(argv[i],"-help") == 0) {
fputs(comment_usage,stderr);
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,829 @@
/*******************************************************************************
* 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.
*******************************************************************************/
#include "internal.h"
/*******************************************************************************
* $Header$
*
* File : emit.cxx
*
* This file contains some useful functions for emitting code that would be
* common to all of the interface languages. Mainly this function deals with
* declaring functions external, creating lists of arguments, and making
* function calls.
*******************************************************************************/
// -----------------------------------------------------------------------------
// void emit_banner(FILE *f)
//
// Emits the SWIG identifying banner in the wrapper file
//
// Inputs : f = FILE handle
//
// Output : None
//
// Side Effects : None
// -----------------------------------------------------------------------------
void emit_banner(FILE *f) {
extern char *get_time();
extern char fn_header[];
fprintf(f,
"/*\n\
* FILE : %s\n\
* \n\
* This file was automatically generated by :\n\
* Simplified Wrapper and Interface Generator (SWIG)\n\
* Version %d.%d %s\n\
* \n\
* Portions Copyright (c) 1995-1998\n\
* The University of Utah and The Regents of the University of California.\n\
* Permission is granted to distribute this file in any manner provided\n\
* this notice remains intact.\n\
* \n\
* Do not make changes to this file--changes will be lost!\n\
*\n\
*/\n\n", fn_header, SWIG_MAJOR_VERSION, SWIG_MINOR_VERSION, SWIG_SPIN);
fprintf(f,"\n#define SWIGCODE\n");
}
// -----------------------------------------------------------------------------
// emit_extern_var(char *decl, DataType *t, int extern_type, FILE *f)
//
// Emits an external variables declaration. Extern_type defines the
// type of external declaration. Currently, only C/C++ declarations
// are allowed, but this might be extended to allow Fortran linkage
// someday
//
// Inputs :
// decl = Name of the declaration
// t = Datatype
// extern_type = Numeric code indicating type of extern
// 0 - No "extern"
// 1,2 - Normal extern (C/C++)
// f = FILE handle
//
// Output : None
//
// Side Effects : None
// -----------------------------------------------------------------------------
void emit_extern_var(char *decl, DataType *t, int extern_type, FILE *f) {
char *arr = 0;
if (t->arraystr) arr = t->arraystr;
else arr = "";
switch(extern_type) {
case 0:
// No extern. Just a forward reference
if (t->arraystr)
t->is_pointer--;
if (t->is_reference) {
t->is_pointer--;
fprintf(f,"%s& %s%s; \n", t->print_full(), decl, arr);
t->is_pointer++;
} else {
fprintf(f,"%s %s%s; \n", t->print_full(), decl,arr);
}
if (t->arraystr)
t->is_pointer++;
break;
case 1: case 2:
if (t->arraystr)
t->is_pointer--;
// Normal C/C++ extern
// fprintf(f,"#line %d \"%s\"\n", line_number, input_file);
if (t->is_reference) {
t->is_pointer--;
fprintf(f,"extern %s& %s%s; \n", t->print_full(), decl,arr);
t->is_pointer++;
} else {
fprintf(f,"extern %s %s%s; \n", t->print_full(), decl,arr);
}
if (t->arraystr)
t->is_pointer++;
default:
break;
}
}
// -----------------------------------------------------------------------------
// emit_extern_func(char *decl, DataType *t, ParmList *L, int extern_type,
// FILE *f)
//
// Emits an external function declaration (similiar to emit_extern_var).
//
// Inputs :
// decl = Name of declaration
// t = Return datatype
// L = parameter list
// extern_type = Type of extern
// 0 - No "extern"
// 1 - extern
// 2 - extern "C"
// 3 - Function declaration (with arg names)
// f = FILE Handle
//
// Output : None
//
// Side Effects : None
//
// -----------------------------------------------------------------------------
void emit_extern_func(char *decl, DataType *t, ParmList *L, int extern_type, FILE *f) {
switch(extern_type) {
case 0:
if (t->is_reference) {
t->is_pointer--;
fprintf(f,"%s&", t->print_full());
t->is_pointer++;
} else {
fprintf(f,"%s", t->print_full());
}
fprintf(f,"%s(", decl);
L->print_types(f);
fprintf(f,");\n");
break;
case 1:
// Normal C/C++ extern
// fprintf(f,"#line %d \"%s\"\n", line_number, input_file);
if (t->is_reference) {
t->is_pointer--;
fprintf(f,"extern %s&", t->print_full());
t->is_pointer++;
} else {
fprintf(f,"extern %s", t->print_full());
}
fprintf(f,"%s(", decl);
L->print_types(f);
fprintf(f,");\n");
break;
case 2:
// A C++ --- > C Extern
// fprintf(f,"#line %d \"%s\"\n", line_number, input_file);
if (t->is_reference) {
t->is_pointer--;
fprintf(f,"extern \"C\" %s&", t->print_full());
t->is_pointer++;
} else {
fprintf(f,"extern \"C\" %s", t->print_full());
}
fprintf(f,"%s(", decl);
L->print_types(f);
fprintf(f,");\n");
break;
case 3:
// A function declaration (for inlining )
if (t->is_reference) {
t->is_pointer--;
fprintf(f,"%s&", t->print_full());
t->is_pointer++;
} else {
fprintf(f,"%s", t->print_full());
}
fprintf(f,"%s(", decl);
L->print_args(f);
fprintf(f,")\n");
break;
default:
break;
}
}
// -----------------------------------------------------------------------------
// char *emit_local(int i)
//
// Returns the name of local variable for parameter i
//
// Inputs : i = Parameter number
//
// Output : NULL terminated ASCII string
//
// Side Effects : Result is left in a static local variable.
// -----------------------------------------------------------------------------
char *emit_local(int i) {
static char arg[64];
sprintf(arg,"_arg%d", i);
return arg;
}
// -----------------------------------------------------------------------------
// int emit_args(char *d, DataType *rt, ParmList *l, FILE *f)
//
// Creates a list of variable declarations for both the return value
// and function parameters.
//
// The return value is always called _result and arguments label as
// _arg0, _arg1, _arg2, etc...
//
// Returns the number of parameters associated with a function.
//
// Inputs :
// d = Name of function
// rt = Return type
// l = Parameter list
// f = FILE Handle
//
// Output : Number of function arguments
//
// Side Effects : None
//
// Note : This function is obsolete. Use emit_args below...
// -----------------------------------------------------------------------------
int emit_args(DataType *rt, ParmList *l, FILE *f) {
Parm *p;
int i;
char temp[64];
String def;
char *tm;
// Declare the return variable
if ((rt->type != T_VOID) || (rt->is_pointer)) {
if ((rt->type == T_USER) && (!rt->is_pointer)) {
// Special case for return by "value"
rt->is_pointer++;
fprintf(f,"\t %s _result;\n", rt->print_type());
rt->is_pointer--;
} else {
// Normal return value
fprintf(f,"\t %s _result;\n", rt->print_type());
}
}
// Emit function arguments
i = 0;
p = l->get_first();
while (p != 0) {
if ((p->t->type != T_VOID) || (p->t->is_pointer)) {
sprintf(temp,"_arg%d", i);
if (p->defvalue) {
if ((p->t->is_reference) || ((p->t->type == T_USER) && (p->call_type == CALL_REFERENCE)))
fprintf(f,"\t %s _arg%d = &%s;\n", p->t->print_type(),i, p->defvalue);
else
fprintf(f,"\t %s _arg%d = %s;\n", p->t->print_type(),i, p->defvalue);
} else {
fprintf(f,"\t %s _arg%d;\n", p->t->print_type(),i);
tm = typemap_lookup("arginit", typemap_lang, p->t, p->name,"",temp);
if (tm) {
def << tm;
}
}
// Check for ignore or default typemaps
tm = typemap_lookup("default",typemap_lang,p->t,p->name,"",temp);
if (tm)
def << tm;
tm = typemap_lookup("ignore",typemap_lang,p->t,p->name,"",temp);
if (tm) {
def << tm;
p->ignore = 1;
}
tm = typemap_check("build",typemap_lang,p->t,p->name);
if (tm) {
p->ignore = 1;
}
i++;
}
p = l->get_next();
}
fprintf(f,"%s",def.get());
// i now contains number of parameters
return(i);
}
// -----------------------------------------------------------------------------
// int emit_args(char *d, DataType *rt, ParmList *l, WrapperFunction &f)
//
// Creates a list of variable declarations for both the return value
// and function parameters.
//
// The return value is always called _result and arguments label as
// _arg0, _arg1, _arg2, etc...
//
// Returns the number of parameters associated with a function.
//
// Inputs :
// d = Name of function
// rt = Return type
// l = Parameter list
// f = Wrapper function object
//
// Output : Number of function arguments
//
// Side Effects : None
//
// -----------------------------------------------------------------------------
int emit_args(DataType *rt, ParmList *l, WrapperFunction &f) {
Parm *p;
int i;
char *tm;
// Declare the return variable
if ((rt->type != T_VOID) || (rt->is_pointer)) {
if ((rt->type == T_USER) && (!rt->is_pointer)) {
// Special case for return by "value"
rt->is_pointer++;
f.add_local(rt->print_type(), "_result");
rt->is_pointer--;
} else {
// Normal return value
f.add_local(rt->print_type(), "_result");
}
}
// Emit function arguments
i = 0;
p = l->get_first();
while (p != 0) {
if ((p->t->type != T_VOID) || (p->t->is_pointer)) {
char *temp = emit_local(i);
// Figure out default values
if (((p->t->is_reference) && (p->defvalue)) ||
((p->t->type == T_USER) && (p->call_type == CALL_REFERENCE) && (p->defvalue))) {
String deftmp;
deftmp << "(" << p->t->print_type() << ") &" << p->defvalue;
f.add_local(p->t->print_type(),temp,deftmp.get());
} else {
String deftmp;
char *dv = 0;
if (p->defvalue) {
deftmp << "(" << p->t->print_type() << ") " << p->defvalue;
dv = deftmp.get();
}
f.add_local(p->t->print_type(), temp, dv);
tm = typemap_lookup("arginit", typemap_lang, p->t,p->name,"",temp,&f);
if (tm) {
f.code << tm << "\n";
}
}
// Check for ignore or default typemaps
tm = typemap_lookup("default",typemap_lang,p->t,p->name,"",temp,&f);
if (tm)
f.code << tm << "\n";
tm = typemap_lookup("ignore",typemap_lang,p->t,p->name,"",temp,&f);
if (tm) {
f.code << tm << "\n";
p->ignore = 1;
}
tm = typemap_check("build",typemap_lang,p->t,p->name);
if (tm) {
p->ignore = 1;
}
i++;
}
p = l->get_next();
}
// i now contains number of parameters
return(i);
}
// -----------------------------------------------------------------------------
// int emit_func_call(char *decl, DataType *t, ParmList *l, FILE *f)
//
// Emits code for a function call.
//
// Inputs :
// decl = name of function
// t = Return datatype
// l = Parameter list
// f = FILE Handle
//
// Output : None
//
// Side Effects : None
//
// Note : This function is obsolete
// -----------------------------------------------------------------------------
void emit_func_call(char *decl, DataType *t, ParmList *l, FILE *f) {
int i;
Parm *p;
// fprintf(f,"#line %d \"%s\"\n", line_number, input_file);
fprintf(f,"\t ");
// First check if there is a return value
if ((t->type != T_VOID) || (t->is_pointer)) {
if ((t->type == T_USER) && (!t->is_pointer)) {
// Special case for return by "value"
// Caution : This *will* cause a memory leak if not
// used properly.
if (CPlusPlus) {
fprintf(f,"_result = new %s(", t->print_type());
} else {
t->is_pointer++;
fprintf(f,"_result = %s malloc(sizeof(", t->print_cast());
t->is_pointer--;
fprintf(f,"%s));\n", t->print_type());
fprintf(f,"\t*(_result) = ");
}
} else {
// Check if this is a C++ reference
if (t->is_reference) {
t->is_pointer--;
fprintf(f,"%s& _result_ref = ", t->print_full());
t->is_pointer++;
} else {
// Normal return values
fprintf(f,"_result = %s", t->print_cast());
}
}
}
// Now print out function call
fprintf(f,"%s(",decl);
i = 0;
p = l->get_first();
while(p != 0) {
if ((p->t->type != T_VOID) || (p->t->is_pointer)){
fprintf(f,"%s",p->t->print_arraycast());
if ((!p->t->is_reference) && (p->call_type & CALL_VALUE)) fprintf(f,"&");
if ((!(p->call_type & CALL_VALUE)) &&
((p->t->is_reference) || (p->call_type & CALL_REFERENCE)))
fprintf(f,"*");
fprintf(f,"_arg%d",i);
i++;
}
p = l->get_next();
if (p != 0)
fprintf(f,",");
}
fprintf(f,")");
if ((t->type == T_USER) && (!t->is_pointer)) {
if (CPlusPlus) {
fprintf(f,")");
}
}
fprintf(f,";\n");
if (t->is_reference) {
fprintf(f,"\t _result = %s &_result_ref;\n", t->print_cast());
}
}
// -----------------------------------------------------------------------------
// int emit_func_call(char *decl, DataType *t, ParmList *l, WrapperFunction &f)
//
// Emits code for a function call (new version).
//
// Exception handling support :
//
// - This function checks to see if any sort of exception mechanism
// has been defined. If so, we emit the function call in an exception
// handling block.
//
// Inputs :
// decl = name of function
// t = Return datatype
// l = Parameter list
// f = WrapperFunction object
//
// Output : None
//
// Side Effects : None
//
// -----------------------------------------------------------------------------
void emit_func_call(char *decl, DataType *t, ParmList *l, WrapperFunction &f) {
int i;
Parm *p;
String fcall;
String exc;
char *tm;
// f.code << "#line " << line_number << " \"" << input_file << "\"\n";
fcall << tab4;
// First check if there is a return value
if ((t->type != T_VOID) || (t->is_pointer)) {
if ((t->type == T_USER) && (!t->is_pointer)) {
// Special case for return by "value"
// Caution : This *will* cause a memory leak if not
// used properly.
if (CPlusPlus) {
fcall << "_result = new " << t->print_type() << "(";
} else {
t->is_pointer++;
fcall << "_result = " << t->print_cast() << " malloc(sizeof(";
t->is_pointer--;
fcall << t->print_type() << "));\n";
fcall << tab4 << "*(_result) = ";
}
} else {
// Check if this is a C++ reference
if (t->is_reference) {
t->is_pointer--;
fcall << t->print_full() << "& _result_ref = ";
t->is_pointer++;
} else {
// Normal return value
fcall << "_result = " << t->print_cast();
}
}
}
// Now print out function call
fcall << decl << "(";
i = 0;
p = l->get_first();
while(p != 0) {
if ((p->t->type != T_VOID) || (p->t->is_pointer)){
fcall << p->t->print_arraycast();
if ((!p->t->is_reference) && (p->call_type & CALL_VALUE))
fcall << "&";
if ((!(p->call_type & CALL_VALUE)) &&
((p->t->is_reference) || (p->call_type & CALL_REFERENCE)))
fcall << "*";
fcall << emit_local(i);
i++;
}
p = l->get_next();
if (p != 0)
fcall << ",";
}
fcall << ")";
if ((t->type == T_USER) && (!t->is_pointer)) {
if (CPlusPlus) {
fcall << ")";
}
}
fcall << ";\n";
if (t->is_reference) {
fcall << tab4 << "_result = "<< t->print_cast() << " &_result_ref;\n";
}
// Check for exception handling
if ((tm = typemap_lookup("except",typemap_lang,t,decl,"_result",""))) {
// Found a type-specific mapping
exc << tm;
exc.replace("$function",fcall);
exc.replace("$name",decl);
f.code << exc;
} else if ((tm = fragment_lookup("except",typemap_lang, t->id))) {
exc << tm;
exc.replace("$function",fcall);
exc.replace("$name",decl);
f.code << exc;
} else {
f.code << fcall;
}
}
// -----------------------------------------------------------------------------
// void emit_hex(FILE *f)
//
// Emits the default C-code to handle pointers. This is normally contained
// in the SWIG library file 'swigptr.swg'
//
// Inputs : f = FILE handle
//
// Output : None
//
// Side Effects : None
// -----------------------------------------------------------------------------
void emit_hex(FILE *f) {
int stat;
// Look for a pointer configuration file
stat = insert_file("swigptr.swg", f);
if (stat == -1) {
fprintf(stderr,"** Fatal error. Unable to locate 'swigptr.swg'\n");
SWIG_exit(1);
}
}
// -----------------------------------------------------------------------------
// void emit_set_get(char *name, char *iname, DataType *type)
//
// Emits a pair of functions to set/get the value of a variable.
// This should be used as backup in case the target language can't
// provide variable linking.
//
// double foo;
//
// Gets translated into the following :
//
// double foo_set(double x) {
// return foo = x;
// }
//
// double foo_get() {
// return foo;
// }
//
// Need to handle special cases for char * and for user
// defined types.
//
// 1. char *
//
// Will free previous contents (if any) and allocate
// new storage. Could be risky, but it's a reasonably
// natural thing to do.
//
// 2. User_Defined
// Will assign value from a pointer.
// Will return a pointer to current value.
//
//
// Inputs :
// name = Name of variable
// iname = Renamed version of variable
// type = Datatype of the variable
//
// Output : None
//
// Side Effects : None
// -----------------------------------------------------------------------------
void emit_set_get(char *name, char *iname, DataType *t) {
Parm *p;
ParmList *l;
String new_name;
String new_iname;
String wname;
// First write a function to set the variable of the variable
if (!(Status & STAT_READONLY)) {
if ((t->type == T_USER) && (!t->is_pointer)) {
t->is_pointer++;
fprintf(f_header,"static %s %s(%s val) {\n",
t->print_type(), name_set(name), t->print_type());
t->is_pointer--;
} else {
fprintf(f_header,"static %s %s(%s val) {\n",
t->print_type(), name_set(name), t->print_type());
}
if ((t->type != T_VOID) || (t->is_pointer)) {
if (!t->is_pointer) {
// Have a real value here
// If it's a user defined type, we'll do something special.
// Otherwise, just assign it.
if (t->type != T_USER) {
fprintf(f_header,"\t return (%s) (%s = val);\n", t->print_type(), name);
} else {
fprintf(f_header,"\t %s = *(val);\n", name);
t->is_pointer++;
fprintf(f_header,"\t return (%s) &%s;\n", t->print_type(),name);
t->is_pointer--;
}
} else {
// Is a pointer type here. If string, we do something
// special. Otherwise. No problem.
if ((t->type == T_CHAR) && (t->is_pointer == 1)) {
if (CPlusPlus) {
fprintf(f_header,"\t if (%s) delete %s;\n", name,name);
fprintf(f_header,"\t %s = new char[strlen(val)+1];\n",name);
fprintf(f_header,"\t strcpy(%s,val);\n", name);
fprintf(f_header,"\t return %s;\n", name);
} else {
fprintf(f_header,"\t if (%s) free(%s);\n", name,name);
fprintf(f_header,"\t %s = (char *) malloc(strlen(val)+1);\n",name);
fprintf(f_header,"\t strcpy(%s,val);\n", name);
fprintf(f_header,"\t return %s;\n", name);
}
} else {
fprintf(f_header,"\t return (%s) (%s = val);\n", t->print_type(), name);
}
}
}
fprintf(f_header,"}\n");
// Now wrap it.
l = new ParmList;
p = new Parm(t,0);
if ((t->type == T_USER) && (!t->is_pointer)) p->t->is_pointer++;
p->name = new char[1];
p->name[0] = 0;
l->append(p);
new_name = name_set(name);
new_iname = name_set(iname);
if ((t->type == T_USER) && (!t->is_pointer)) {
t->is_pointer++;
lang->create_function(new_name, new_iname, t, l);
t->is_pointer--;
} else {
lang->create_function(new_name, new_iname, t, l);
}
delete l;
delete p;
if (doc_entry) doc_entry->usage << "\n";
}
// Now write a function to get the value of the variable
if ((t->type == T_USER) && (!t->is_pointer)) {
t->is_pointer++;
fprintf(f_header,"static %s %s() { \n",
t->print_type(), name_get(name));
fprintf(f_header,"\t return (%s) &%s;\n", t->print_type(), name);
t->is_pointer--;
} else {
fprintf(f_header,"static %s %s() { \n",
t->print_type(), name_get(name));
fprintf(f_header,"\t return (%s) %s;\n", t->print_type(), name);
}
fprintf(f_header,"}\n");
// Wrap this function
l = new ParmList;
new_name = name_get(name);
new_iname = name_get(iname);
if ((t->type == T_USER) && (!t->is_pointer)) {
t->is_pointer++;
lang->create_function(new_name, new_iname, t, l);
t->is_pointer--;
} else {
lang->create_function(new_name, new_iname, t, l);
}
delete l;
}

View File

@@ -0,0 +1,141 @@
/*******************************************************************************
* 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.
*******************************************************************************/
#include "internal.h"
/*******************************************************************************
* $Header$
*
* File : getopt.cxx
*
* This file defines a few functions for handling command line arguments.
* C++ makes this really funky---especially since each language module
* may want to extract it's own command line arguments.
*
* My own special version of getopt. This is a bit weird, because we
* don't know what the options are in advance (they could be determined
* by a language module).
*******************************************************************************/
static char **args;
static int numargs;
static int *marked;
// -----------------------------------------------------------------------------
// void init_args(int argc, char **argv)
//
// Initializes the argument list.
//
// Inputs :
// argc = Argument count
// argv = Argument array
//
// Output : None
//
// Side Effects : Saves local copy of argc and argv
// -----------------------------------------------------------------------------
void
init_args(int argc, char **argv)
{
int i;
numargs = argc;
args = argv;
marked = new int[numargs];
for (i = 0; i < argc; i++) {
marked[i] = 0;
}
marked[0] = 1;
}
// -----------------------------------------------------------------------------
// void mark_arg(int n)
//
// Marks an argument as being parsed. All modules should do this whenever they
// parse a command line option.
//
// Inputs : n = Argument number
//
// Output : None
//
// Side Effects : Sets a status bit internally
// -----------------------------------------------------------------------------
void
mark_arg(int n) {
if (marked)
marked[n] = 1;
}
// -----------------------------------------------------------------------------
// void check_options()
//
// Checks for unparsed command line options. If so, issues an error and exits.
//
// Inputs : None
//
// Output : None
//
// Side Effects : exits if there are unparsed options
// -----------------------------------------------------------------------------
void check_options() {
int error = 0;
int i;
if (!marked) {
fprintf(stderr,"Must specify an input file. Use -help for available options.\n");
SWIG_exit(1);
}
for (i = 1; i < numargs-1; i++) {
if (!marked[i]) {
fprintf(stderr,"swig error : Unrecognized option %s\n", args[i]);
error=1;
}
}
if (error) {
fprintf(stderr,"Use 'swig -help' for available options.\n");
SWIG_exit(1);
}
if (marked[numargs-1]) {
fprintf(stderr,"Must specify an input file. Use -help for available options.\n");
SWIG_exit(1);
}
}
// -----------------------------------------------------------------------------
// void arg_error()
//
// Generates a generic error message and exits.
//
// Inputs : None
//
// Output : None
//
// Side Effects : Exits
// -----------------------------------------------------------------------------
void arg_error() {
fprintf(stderr,"SWIG : Unable to parse command line options.\n");
fprintf(stderr,"Use 'swig -help' for available options.\n");
SWIG_exit(1);
}

View File

@@ -0,0 +1,359 @@
/*******************************************************************************
* 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.
*******************************************************************************/
#include "internal.h"
/*******************************************************************************
* $Header$
*
* File : hash.cxx
*
* A very simple Hash table class. Could probably make it more elegant with
* templates, but templates are pure evil...
*******************************************************************************/
#define INIT_SIZE 119
// -----------------------------------------------------------------------------
// Hash::Hash()
//
// Constructor. Creates a new hash table.
//
// Inputs : None
//
// Output : New Hash object.
//
// Side Effects : None
// -----------------------------------------------------------------------------
Hash::Hash() {
int i;
hashsize = INIT_SIZE;
hashtable = new Node *[hashsize];
for (i = 0; i < hashsize; i++) {
hashtable[i] = 0;
}
index = -1;
current = 0;
}
// -----------------------------------------------------------------------------
// Hash::~Hash()
//
// Destructor.
//
// Inputs : None
//
// Output : None
//
// Side Effects : Total destruction.
// -----------------------------------------------------------------------------
Hash::~Hash() {
int i;
Node *n,*next;
for (i = 0; i < hashsize; i++) {
if (hashtable[i]) {
n = hashtable[i];
while (n) {
next = n->next;
delete n;
n = next;
}
}
}
delete [] hashtable;
}
// -----------------------------------------------------------------------------
// int Hash::h1(const char *key)
//
// Hashing function.
//
// Inputs : ASCII character string.
//
// Output : Hash table index.
//
// Side Effects : None
// -----------------------------------------------------------------------------
int Hash::h1(const char *key) {
int h = 0;
const char *c;
c = key;
while (*c) {
h = (128*h + *c) % hashsize;
c++;
}
return h;
}
// -----------------------------------------------------------------------------
// int Hash::add(const char *k, void *obj)
//
// Adds a new object to the hash table.
//
// Inputs :
// k = Hash key
// obj = Pointer to an object
//
// Output : 0 on success, -1 if item is already in hash table.
//
// Side Effects :
// Makes a new hash table entry.
// -----------------------------------------------------------------------------
int Hash::add(const char *k, void *obj) {
int hv;
Node *n,*prev;
hv = h1(k); // Get hash value
n = hashtable[hv];
prev = n;
while (n) {
if (strcmp(n->key,k) == 0) return -1; // Already in hash table
prev = n;
n = n->next;
}
// Safe to add this to the table
n = new Node(k,obj,0);
if (prev) prev->next = n;
else hashtable[hv] = n;
return 0;
}
// -----------------------------------------------------------------------------
// int Hash::add(const char *k, void *obj, void (*d)(void *))
//
// Adds a new object to the hash table. Allows additional specification of
// a callback function for object deletion.
//
// Inputs :
// k = Hash key
// obj = Object pointer
// d = Deletion function
//
// Output : 0 on success, -1 if item is already in hash table.
//
// Side Effects :
// Adds an entry to the hash table
// -----------------------------------------------------------------------------
int Hash::add(const char *k, void *obj, void (*d)(void *)) {
int hv;
Node *n,*prev;
hv = h1(k); // Get hash value
n = hashtable[hv];
prev = n;
while (n) {
if (strcmp(n->key,k) == 0) return -1; // Already in hash table
prev = n;
n = n->next;
}
// Safe to add this to the table
n = new Node(k,obj,d);
if (prev) prev->next = n;
else hashtable[hv] = n;
return 0;
}
// -----------------------------------------------------------------------------
// void *Hash::lookup(const char *k)
//
// Looks up a value in the hash table. Returns a pointer to the object if found.
//
// Inputs : k = key value
//
// Output : Pointer to object or NULL if not found.
//
// Side Effects : None
// -----------------------------------------------------------------------------
void *Hash::lookup(const char *k) {
int hv;
Node *n;
hv = h1(k); // Get hash value
n = hashtable[hv];
while (n) {
if (strcmp(n->key,k) == 0) return n->object;
n = n->next;
}
return 0;
}
// -----------------------------------------------------------------------------
// void Hash::remove(const char *k)
//
// Removes an item from the hash table. Does nothing if item isn't in the
// hash table to begin with.
//
// Inputs : k = Key value
//
// Output : None
//
// Side Effects : Deletes item from hash table.
// -----------------------------------------------------------------------------
void Hash::remove(const char *k) {
int hv;
Node *n,*prev;
hv = h1(k); // Get hash value
n = hashtable[hv];
prev = 0;
while (n) {
if (strcmp(n->key,k) == 0) {
// Found it, kill the thing
if (prev) {
prev->next = n->next;
} else {
hashtable[hv] = n->next;
}
delete n;
return;
}
prev = n;
n = n->next;
}
}
// -----------------------------------------------------------------------------
// void *Hash::first()
//
// Gets the first item from the hash table or NULL if empty.
//
// Inputs : None
//
// Output : First object in hash table or NULL if hash table is empty.
//
// Side Effects : Resets an internal iterator variable on the hash table.
// -----------------------------------------------------------------------------
void *Hash::first() {
index = 0;
current = 0;
while (!hashtable[index] && (index < hashsize))
index++;
if (index >= hashsize) return 0;
current = hashtable[index];
return current->object;
}
// -----------------------------------------------------------------------------
// char *Hash::firstkey()
//
// Gets the first key from the hash table or NULL if empty.
//
// Inputs : None
//
// Output : First key in hash table or NULL if hash table is empty.
//
// Side Effects : Resets an internal iterator variable on the hash table.
// -----------------------------------------------------------------------------
char *Hash::firstkey() {
index = 0;
current = 0;
while ((index < hashsize) && (!hashtable[index]))
index++;
if (index >= hashsize) return 0;
current = hashtable[index];
return current->key;
}
// -----------------------------------------------------------------------------
// void *Hash::next()
//
// Returns the next item in the hash table or NULL if there are no more entries.
// A call to first() should generally be made before using this function.
//
// Inputs : None
//
// Output : Pointer to next object or NULL if there are no more objects.
//
// Side Effects : Updates an iterator variable private to the hash table.
// -----------------------------------------------------------------------------
void *Hash::next() {
if (index < 0) return first();
// Try to move to the next entry
current = current->next;
if (current) {
return current->object;
} else {
index++;
while ((index < hashsize) && (!hashtable[index]))
index++;
if (index >= hashsize) return 0;
current = hashtable[index];
return current->object;
}
}
// -----------------------------------------------------------------------------
// char *Hash::nextkey()
//
// Returns the next key in the hash table or NULL if there are no more entries.
// A call to firstkey() should generally be made before using this function.
//
// Inputs : None
//
// Output : Pointer to next key or NULL if there are no more objects.
//
// Side Effects : Updates an iterator variable private to the hash table.
// -----------------------------------------------------------------------------
char *Hash::nextkey() {
if (index < 0) return firstkey();
// Try to move to the next entry
current = current->next;
if (current) {
return current->key;
} else {
index++;
while (!hashtable[index] && (index < hashsize))
index++;
if (index >= hashsize) return 0;
current = hashtable[index];
return current->key;
}
}

View File

@@ -0,0 +1,598 @@
/*******************************************************************************
* 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.
*******************************************************************************/
#include "swig.h"
#include "html.h"
/*******************************************************************************
* $Header$
*
* File : html.cxx
*
* HTML specific functions for producing documentation.
*******************************************************************************/
#define PRE 0
#define FORMAT 1
// -----------------------------------------------------------------------------
// HTML::HTML()
//
// Constructor. Creates a new HTML documentation module object.
//
// Inputs : None
//
// Output : HTML Object
//
// Side Effects : None
// -----------------------------------------------------------------------------
HTML::HTML() {
sect_count = 0;
last_section = 0;
// Initialize default tags for various parts of the documentation
tag_body = "<BODY BGCOLOR=\"#ffffff\">:</BODY>";
tag_title = "<H1>:</H1>";
tag_contents = "<HR><H1>:</H1>";
tag_section = "<HR><H2>:</H2>";
tag_subsection = "<H3>:</H3>";
tag_subsubsection = "<H4>:</H4>";
tag_usage = "<P><TT><B>:</B></TT>";
tag_descrip = "<BLOCKQUOTE>:</BLOCKQUOTE>";
tag_text = "<P>";
tag_cinfo = "";
tag_preformat = "<PRE>:</PRE>";
}
// -----------------------------------------------------------------------------
// char *HTML::start_tag(char *tag)
//
// Utility function for returning the first part of an HTML tag variable.
// A tag must look like this :
//
// "<b>:</b>"
//
// The start tag for this would be "<b>"
//
// Inputs : tag = HTML tag string
//
// Output : Staring portion of the tag variable.
//
// Side Effects : None.
// -----------------------------------------------------------------------------
char *HTML::start_tag(char *tag) {
static String stag;
char *c;
stag = "";
c = tag;
while ((*c) && (*c != ':')) {
stag << *c;
c++;
}
return stag.get();
}
// -----------------------------------------------------------------------------
// char *HTML::end_tag(char *tag)
//
// Utility for returning an end-tag. The counterpart to start_tag().
//
// Inputs : tag = HTML tag string
//
// Output : Ending portion of tag variable.
//
// Side Effects : None
// -----------------------------------------------------------------------------
char *HTML::end_tag(char *tag) {
static String etag;
char *c;
etag = "";
c = tag;
while ((*c) && (*c != ':')) {
c++;
}
if (*c) {
c++;
while (*c) {
etag << *c;
c++;
}
}
return etag.get();
}
// -----------------------------------------------------------------------------
// void HTML::print_string(char *s, String &str, int mode)
//
// Outputs the contents of string s into String str. If mode is 1, we
// will reformat the text and apply a few common HTML character
// substitutions.
//
// Inputs : s = Documentation text string
// mode = Formatting mode (0 = preformat, 1 = formatted)
//
// Output : str = Output is append to str.
//
// Side Effects : None
// -----------------------------------------------------------------------------
void HTML::print_string(char *s, String &str,int mode) {
char *c;
c = s;
while (*c) {
switch(*c) {
case '\"':
str << "&quot;";
break;
case '&':
str << "&amp;";
break;
case '<':
if (mode == PRE)
str << "&lt;";
else
str << (char) *c;
break;
case '>':
if (mode == PRE)
str << "&gt;";
else
str << (char) *c;
break;
default :
str << (char ) *c;
break;
}
c++;
}
}
// -----------------------------------------------------------------------------
// void HTML::print_decl(DocEntry *de)
//
// Generates documentation for a declaration.
//
// Inputs : de = Documentation entry
//
// Output : None
//
// Side Effects : None
// -----------------------------------------------------------------------------
void HTML::print_decl(DocEntry *de) {
char *c;
c = de->usage.get();
while ((*c) && ((*c == ' ') || (*c == '\t') || (*c == '\n'))) c++;
if (c) {
s_doc << start_tag(tag_usage);
print_string(c,s_doc,PRE);
s_doc << end_tag(tag_usage) << "\n";
} else return;
// Only print this if there is information
if ((strlen(de->cinfo.get()) && de->print_info) || strlen(de->text.get())) {
s_doc << start_tag(tag_descrip);
if (!de->format)
s_doc << start_tag(tag_preformat);
}
// If there is any C annotation, print that
if (de->print_info) {
c = de->cinfo.get();
if (strlen(c) > 0) {
s_doc << start_tag(tag_cinfo);
s_doc << "[ ";
print_string(c,s_doc,PRE);
s_doc << " ]" << end_tag(tag_cinfo) << "\n";
if (de->format) s_doc << "<BR>";
}
}
c = de->text.get();
if (strlen(c) > 0) {
print_string(c,s_doc,de->format);
}
if ((strlen(de->cinfo.get()) && de->print_info) || strlen(de->text.get())) {
if (!de->format) s_doc << end_tag(tag_preformat);
s_doc << end_tag(tag_descrip) << "\n";
}
s_doc << "\n";
}
// -----------------------------------------------------------------------------
// void HTML::print_text(DocEntry *de)
//
// Generates documentation for a text-block. Strips any leading whitespace.
//
// Inputs : de = Documentation entry
//
// Output : None
//
// Side Effects : None
// -----------------------------------------------------------------------------
void HTML::print_text(DocEntry *de) {
char *c;
c = de->text.get();
if (strlen(c) > 0) {
s_doc << start_tag(tag_text);
if (!de->format)
s_doc << start_tag(tag_preformat);
print_string(c,s_doc,de->format);
if (!de->format)
s_doc << end_tag(tag_preformat) << "\n";
s_doc << end_tag(tag_text) << "\n";
}
}
// -----------------------------------------------------------------------------
// void HTML::title(DocEntry *de)
//
// Generates the title for an HTML document.
//
// Inputs : de = Title documentation entry
//
// Output : None
//
// Side Effects : None
// -----------------------------------------------------------------------------
void HTML::title(DocEntry *de) {
char *c;
c = de->usage.get();
if (strlen(c) > 0) {
s_title << "<HEAD>\n"
<< "<TITLE>\n";
print_string(c,s_title,PRE);
s_title << "</TITLE>\n"
<< start_tag(tag_body) << "\n";
s_title << start_tag(tag_title);
print_string(c,s_title,PRE);
s_title << end_tag(tag_title) << "\n";
}
if (!de->format)
s_title << start_tag(tag_preformat);
// If there is any C annotation, print that
if (de->print_info) {
c = de->cinfo.get();
if (strlen(c) > 0) {
s_title << start_tag(tag_cinfo) << "[ ";
print_string(c,s_title,de->format);
s_title << " ]" << end_tag(tag_cinfo);
if (de->format)
s_title << "<BR>\n";
else
s_title << "\n";
}
}
c = de->text.get();
if (strlen(c)) {
print_string(c,s_title,de->format);
}
if (!de->format)
s_title << end_tag(tag_preformat) << "\n";
}
// -----------------------------------------------------------------------------
// void HTML::newsection(DocEntry *de, int sectnum)
//
// Creates a new section. sect_count is used to determine the formatting of
// the header. Also fills in a table of contents
//
// Inputs :
// de = Documentation Entry
// sectnum = Section number
//
// Output : None
//
// Side Effects :
// Creates a new subsection. Updates HTML table of contents.
// -----------------------------------------------------------------------------
void HTML::newsection(DocEntry *de,int sectnum) {
int i,f;
char *c;
char *tag;
sect_num[sect_count] = sectnum;
sect_count++;
f = sect_count + 1;
if (f > 5) f = 5;
// Form table of contents
// if sect_count > last_section. We need to indent
// if sect_count < last_section. We need to pop out
if (sect_count > last_section) {
for (i = 0; i < sect_count - last_section; i++)
contents << "<UL>";
} else if (sect_count < last_section) {
for (i = 0; i < last_section - sect_count; i++)
contents << "</UL>";
}
last_section = sect_count;
contents << "<LI> <A HREF=\"#s";
s_doc << "<A name=\"s";
for (i = 0; i < sect_count; i++) {
s_doc << sect_num[i] << "_";
contents << sect_num[i] << "_";
}
contents << "\">";
// Figure out the tag fields
switch(f) {
case 1:
tag = tag_title;
break;
case 2:
tag = tag_section;
break;
case 3:
tag = tag_subsection;
break;
case 4:
tag = tag_subsubsection;
break;
default:
tag = tag_subsubsection;
}
s_doc << "\">\n"
<< start_tag(tag);
for (i = 0; i < sect_count; i++) {
s_doc << sect_num[i] << ".";
contents << sect_num[i] << ".";
}
c = de->usage.get();
s_doc << " ";
contents << " ";
print_string(c,s_doc,PRE);
print_string(c,contents,PRE);
s_doc << end_tag(tag) << "</A>\n";
contents << "</A>\n";
if (!de->format)
s_doc << start_tag(tag_preformat);
// If there is any C annotation, print that
if (de->print_info) {
c = de->cinfo.get();
if (strlen(c) > 0) {
s_doc << start_tag(tag_cinfo) << "[ ";
print_string(c,s_doc,de->format);
s_doc << " ]" << end_tag(tag_cinfo);
if (de->format)
s_doc << "<BR>\n";
else
s_doc << "\n";
}
}
// If there is a description text. Print it
c = de->text.get();
if (strlen(c) > 0) {
print_string(c,s_doc,de->format);
s_doc << "\n";
}
if (!de->format)
s_doc << end_tag(tag_preformat) << "\n";
}
// -----------------------------------------------------------------------------
// void HTML::endsection()
//
// Ends a subsection. It is an error to call this without first calling
// newsection previously.
//
// Inputs : None
//
// Output : None
//
// Side Effects : Closes current section and goes back to parent.
//
// -----------------------------------------------------------------------------
void HTML::endsection() {
if (sect_count > 0) sect_count--;
}
// -----------------------------------------------------------------------------
// void HTML::separator()
//
// Prints a separator after the declaration of a C++ class. Currently
// does nothing in HTML mode.
//
// Inputs : None
//
// Output : None
//
// Side Effects : None
// -----------------------------------------------------------------------------
void HTML::separator() {
}
// -----------------------------------------------------------------------------
// void HTML::init(char *filename)
//
// Initializes the HTML module and opens up the documentation file.
//
// Inputs : filename = Name of documentation file (without a suffix)
//
// Output : None
//
// Side Effects : Opens documentation file.
// -----------------------------------------------------------------------------
void HTML::init(char *filename) {
char f[256];
sprintf(f,"%s.html",filename);
f_doc = fopen(f,"w");
if (f_doc == NULL) {
fprintf(stderr,"Unable to open %s\n",f);
SWIG_exit(1);
}
/* Print a HTML banner */
fprintf(f_doc,"<HTML>\n");
}
// -----------------------------------------------------------------------------
// void HTML::close(void)
//
// Dumps the table of contents and forms the final documentation file. Closes
// the documentation file upon completion.
//
// Inputs : None
//
// Output : None
//
// Side Effects : Closes documentation file.
// -----------------------------------------------------------------------------
void HTML::close(void) {
int i;
for (i = 0; i < last_section; i++)
contents << "</UL>\n";
fprintf(f_doc,"%s\n",s_title.get());
if (last_section) {
fprintf(f_doc,"%s Contents %s\n",start_tag(tag_contents),end_tag(tag_contents));
fprintf(f_doc,"%s\n",contents.get());
}
fprintf(f_doc,"%s\n",s_doc.get());
fprintf(f_doc,"%s\n", end_tag(tag_body));
fprintf(f_doc,"</HTML>\n");
fclose(f_doc);
}
// -----------------------------------------------------------------------------
// void HTML::style(char *name, char *value)
//
// Process parameters given with the %style directive. Does nothing if an
// unrecognized parameter is given.
//
// Inputs :
// name = name of style parameter
// value = ASCII string with value of parameter.
//
// Output : None
//
// Side Effects : Updates internal style parameters.
// -----------------------------------------------------------------------------
void HTML::style(char *name, char *value) {
if (strcmp(name,"html_title") == 0) {
if (value)
tag_title = copy_string(value);
} else if (strcmp(name,"html_contents") == 0) {
if (value)
tag_contents = copy_string(value);
} else if (strcmp(name,"html_section") == 0) {
if (value)
tag_section = copy_string(value);
} else if (strcmp(name,"html_subsection") == 0) {
if (value)
tag_subsection = copy_string(value);
} else if (strcmp(name,"html_subsubsection") == 0) {
if (value)
tag_subsubsection = copy_string(value);
} else if (strcmp(name,"html_usage") == 0) {
if (value)
tag_usage = copy_string(value);
} else if (strcmp(name,"html_descrip") == 0) {
if (value)
tag_descrip = copy_string(value);
} else if (strcmp(name,"html_text") == 0) {
if (value)
tag_text = copy_string(value);
} else if (strcmp(name,"html_cinfo") == 0) {
if (value)
tag_cinfo = copy_string(value);
} else if (strcmp(name,"html_preformat") == 0) {
if (value)
tag_preformat = copy_string(value);
} else if (strcmp(name,"html_body") == 0) {
if (value)
tag_body = copy_string(value);
}
}
// -----------------------------------------------------------------------------
// void HTML::parse_args(int argc, char **argv)
//
// Parse command line options given on the SWIG command line.
//
// Inputs :
// argc = argument count
// argv = argument array
//
// Output : None
//
// Side Effects : Marks arguments as being parsed.
// -----------------------------------------------------------------------------
static char *html_usage = "\
HTML Documentation Options (available with -dhtml)\n\
None available.\n\n";
void HTML::parse_args(int argc, char **argv) {
int i;
for (i = 0; i < argc; i++) {
if (argv[i]) {
if (strcmp(argv[i],"-help") == 0) {
fputs(html_usage,stderr);
}
}
}
}

View File

@@ -0,0 +1,76 @@
/*******************************************************************************
* 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.
*******************************************************************************/
/***********************************************************************
* $Header$
*
* html.h
*
* HTML specific functions for producing documentation.
***********************************************************************/
class HTML : public Documentation {
private:
FILE *f_doc;
void print_string(char *s, String &str, int mode);
char *start_tag(char *);
char *end_tag(char *);
int sect_count;
int sect_num[20];
int last_section;
String s_doc;
String s_title;
String contents;
char *tag_body;
char *tag_title;
char *tag_contents;
char *tag_section;
char *tag_subsection;
char *tag_subsubsection;
char *tag_usage;
char *tag_descrip;
char *tag_text;
char *tag_cinfo;
char *tag_preformat;
public:
HTML();
void parse_args(int argc, char **argv);
void title(DocEntry *de);
void newsection(DocEntry *de, int sectnum);
void endsection();
void print_decl(DocEntry *de);
void print_text(DocEntry *de);
void separator();
void init(char *filename);
void close(void);
void style(char *name, char *value);
};

View File

@@ -0,0 +1,586 @@
/*******************************************************************************
* 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.
*******************************************************************************/
#include "internal.h"
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
/*******************************************************************************
* $Header$
*
* File : include.cxx
*
* Code for including files into a wrapper file.
*
*******************************************************************************/
/* Delimeter used in accessing files and directories */
#ifdef MACSWIG
#define DELIMETER ':'
#else
#define DELIMETER '/'
#endif
/* Linked list containing search directories */
struct Dnode {
char *dirname;
Dnode *next;
};
Dnode ihead, iz;
int include_init = 0;
/* Linked list containing included files */
struct Inode {
char *name;
Inode *next;
};
Inode *include_list = 0;
// -----------------------------------------------------------------------------
// void add_directory(char *dirname)
//
// Adds a directory to the SWIG search path.
//
// Inputs : dirname = Pathname
//
// Output : None
//
// Side Effects : Adds dirname to linked list of pathnames.
// -----------------------------------------------------------------------------
void add_directory(char *dirname) {
Dnode *d;
if (!include_init) {
ihead.next = &iz;
iz.next = &iz;
iz.dirname = new char[2];
iz.dirname[0] = 0;
include_init = 1;
}
d = new Dnode;
d->dirname = new char[strlen(dirname)+1];
strcpy(d->dirname,dirname);
d->next = ihead.next;
ihead.next = d;
}
// -----------------------------------------------------------------------------
// int add_iname(char *name)
//
// Adds an include file to the list of processed files. If already present,
// returns 1.
//
// Inputs : name = filename
//
// Output : 0 on success, 1 on failure.
//
// Side Effects : Adds name to linked list.
// -----------------------------------------------------------------------------
int add_iname(char *name) {
Inode *newi, *i;
// if (WrapExtern) return 0; // Still thinking about this patch.
if (include_list) {
/* Search list */
i = include_list;
while (i) {
if (strcmp(i->name, name) == 0) return 1;
i = i->next;
}
}
newi = new Inode;
newi->name = new char[strlen(name)+1];
strcpy(newi->name, name);
newi->next = include_list;
include_list = newi;
return 0;
}
// -----------------------------------------------------------------------------
// void check_suffix(char *name)
//
// Checks the suffix of an include file to see if we need to handle it
// differently. C and C++ source files need a little extra help.
//
// Inputs : name = include file name.
//
// Output : None
//
// Side Effects :
// Sets ForceExtern status variable if a C/C++ source file
// is detected.
//
// -----------------------------------------------------------------------------
void check_suffix(char *name) {
char *c;
if (!name) return;
if (strlen(name) == 0) return;
c = name+strlen(name)-1;
while (c != name) {
if (*c == '.') break;
c--;
}
if (c == name) return;
/* Check suffixes */
if (strcmp(c,".c") == 0) {
ForceExtern = 1;
} else if (strcmp(c,".C") == 0) {
ForceExtern = 1;
} else if (strcmp(c,".cc") == 0) {
ForceExtern = 1;
} else if (strcmp(c,".cxx") == 0) {
ForceExtern = 1;
} else if (strcmp(c,".c++") == 0) {
ForceExtern = 1;
} else if (strcmp(c,".cpp") == 0) {
ForceExtern = 1;
} else {
ForceExtern = 0;
}
}
// -----------------------------------------------------------------------------
// int include_file(char *name)
//
// Includes a new SWIG wrapper file. Returns -1 if file not found.
//
// Inputs : name = filename
//
// Output : 0 on success. -1 on failure.
//
// Side Effects : sets scanner to read from new file.
// -----------------------------------------------------------------------------
int include_file(char *name) {
FILE *f;
char filename[256];
int found = 0;
Dnode *d;
extern void scanner_file(FILE *);
if (!include_init) return -1; // Not initialized yet
if (add_iname(name)) {
if (Verbose) fprintf(stderr,"file %s already included.\n", name);
return -1; // Already included this file
}
if (Verbose) {
fprintf(stderr,"Wrapping %s...\n", name);
fprintf(stderr,"Looking for ./%s\n", name);
}
if ((f = fopen(name,"r")) != NULL) {
input_file = new char[strlen(name)+1];
strcpy(input_file,name);
scanner_file(f);
check_suffix(name);
return 0;
}
// Now start searching libraries
d = ihead.next; // Start of search list
while (d != &iz) {
// Look for the wrap file in language directory
sprintf(filename,"%s%c%s%c%s", d->dirname,DELIMETER,LibDir,DELIMETER,name);
if (Verbose) fprintf(stderr,"Looking for %s\n", filename);
if((f = fopen(filename,"r")) != NULL) {
found = 1;
} else {
sprintf(filename,"%s%c%s", d->dirname, DELIMETER,name);
if (Verbose) fprintf(stderr,"Looking for %s\n", filename);
if ((f = fopen(filename,"r")) != NULL) {
found = 1;
}
}
if (found) {
// Found it, open it up for input
input_file = new char[strlen(filename)+1];
strcpy(input_file,filename);
scanner_file(f);
check_suffix(name);
return 0;
}
d = d->next;
}
if (!found) fprintf(stderr,"%s : Line %d. Unable to find include file %s (ignored).\n",input_file, line_number, name);
return -1;
}
static char buffer[1024];
// -----------------------------------------------------------------------------
// void copy_data(FILE *f1, FILE *f2)
//
// Copies data from file f1 to file f2.
//
// Inputs : f1 = FILE 1
// f2 = FILE 2
//
// Output : None
//
// Side Effects : Closes file f1 upon exit.
// -----------------------------------------------------------------------------
void copy_data(FILE *f1, FILE *f2) {
while (fgets(buffer,1023,f1)) {
fputs(buffer, f2);
}
fclose(f1);
}
// -----------------------------------------------------------------------------
// void copy_data(FILE *f1, String *s2)
//
// Copies data from file f1 to String s2.
//
// Inputs : f1 = FILE 1
// s2 = String
//
// Output : None
//
// Side Effects : Closes file f1 upon exit.
// -----------------------------------------------------------------------------
void copy_data(FILE *f1, String &s2) {
while (fgets(buffer,1023,f1)) {
s2 << buffer;
}
fclose(f1);
}
// -----------------------------------------------------------------------------
// int insert_file(char *name, FILE *f)
//
// Looks for a file and inserts into file f.
//
// Inputs : name = filename
// f = FILE
//
// Output : 0 on success, -1 on failure.
//
// Side Effects : None
// -----------------------------------------------------------------------------
int insert_file(char *name, FILE *f_out) {
FILE *f;
char filename[256];
int found = 0;
Dnode *d;
if (!include_init) return -1; // Not initialized yet
if (add_iname(name)) {
if (Verbose) fprintf(stderr,"file %s already included.\n", name);
return -1; // Already included this file
}
if (Verbose) fprintf(stderr,"Looking for ./%s\n", name);
if ((f = fopen(name,"r")) != NULL) {
copy_data(f,f_out);
return 0;
}
// Now start searching libraries
d = ihead.next; // Start of search list
while (d != &iz) {
// Look for the wrap file in language directory
sprintf(filename,"%s%c%s%c%s", d->dirname,DELIMETER,LibDir,DELIMETER,name);
if (Verbose) fprintf(stderr,"Looking for %s\n", filename);
if((f = fopen(filename,"r")) != NULL) {
found = 1;
} else {
sprintf(filename,"%s%c%s", d->dirname, DELIMETER, name);
if (Verbose) fprintf(stderr,"Looking for %s\n", filename);
if ((f = fopen(filename,"r")) != NULL) {
found = 1;
}
}
if (found) {
copy_data(f,f_out);
return 0;
}
d = d->next;
}
if ((!found) && (Verbose)) fprintf(stderr,"unable to find %s. (Ignored)\n",name);
return -1;
}
// -----------------------------------------------------------------------------
// void swig_append(char *filename, FILE *f)
//
// Appends the contents of filename to stream f.
//
// Inputs :
// filename = File to append
// f = FILE handle
//
// Output : None
//
// Side Effects : None
// -----------------------------------------------------------------------------
void swig_append(char *filename, FILE *f) {
FILE *in_file;
if ((in_file = fopen(filename,"r")) == NULL) {
fprintf(stderr,"** SWIG ERROR ** file %s not found.\n",filename);
FatalError();
return;
}
while (fgets(buffer,1023,in_file)) {
fputs(buffer, f);
}
fclose(in_file);
}
// -----------------------------------------------------------------------------
// int get_file(char *name, String &str)
//
// Looks for a file and converts it into a String.
//
// Inputs : name = filename
// str = String
//
// Output : 0 on success, -1 on failure.
//
// Side Effects : None
// -----------------------------------------------------------------------------
int get_file(char *name, String &str) {
FILE *f;
char filename[256];
int found = 0;
Dnode *d;
if (!include_init) return -1; // Not initialized yet
if (Verbose) fprintf(stderr,"Looking for %s\n", name);
if ((f = fopen(name,"r")) != NULL) {
copy_data(f,str);
return 0;
}
// Now start searching libraries
d = ihead.next; // Start of search list
while (d != &iz) {
// Look for the wrap file in language directory
sprintf(filename,"%s%c%s%c%s", d->dirname,DELIMETER,LibDir,DELIMETER,name);
if (Verbose) fprintf(stderr,"Looking for %s\n", filename);
if((f = fopen(filename,"r")) != NULL) {
found = 1;
} else {
sprintf(filename,"%s%c%s", d->dirname, DELIMETER, name);
if (Verbose) fprintf(stderr,"Looking for %s\n", filename);
if ((f = fopen(filename,"r")) != NULL) {
found = 1;
}
}
if (found) {
copy_data(f,str);
return 0;
}
d = d->next;
}
if ((!found)) fprintf(stderr,"SWIG Error. Unable to find %s. Possible installation problem.\n",name);
FatalError();
return -1;
}
static char *libs[1000];
static int nlibs = 0;
// -----------------------------------------------------------------------------
// void library_add(char *name)
//
// Adds a filename to the list of libraries. This is usually only called by
// the SWIG main program.
//
// Inputs : name = library name
//
// Outputs: None
//
// Side Effects : Adds the library name to the libs array above
// -----------------------------------------------------------------------------
void library_add(char *name) {
int i;
// Check to make sure it's not already added
if (!(*name)) return;
for (i = 0; i < nlibs; i++) {
if (strcmp(libs[i],name) == 0) return;
}
libs[nlibs] = copy_string(name);
nlibs++;
}
// -----------------------------------------------------------------------------
// void library_insert()
//
// Starts parsing all of the SWIG library files.
//
// Inputs : None
//
// Output : None
//
// Side Effects : Opens and attaches all of the specified library files to
// the scanner.
//
// Bugs : Opens all of the files. Will fail if there are too many open files.
//
// -----------------------------------------------------------------------------
void library_insert() {
int i;
i = nlibs-1;
while (i >= 0) {
include_file(libs[i]);
i--;
}
}
// -----------------------------------------------------------------------------
// int checkout(char *filename,char *dest)
//
// Tries to check a file out of the SWIG library. If found, it will save it in
// the current directory. This is a useful mechanism for using SWIG as a code
// manager and for extracting library files.
//
// Inputs : filename = Library file
// dest = Destination file
//
// Output : 0 on success
// -1 on failure.
//
// Side Effects : None
// -----------------------------------------------------------------------------
int checkout_file(char *filename,char *dest) {
FILE *f1;
char tempn[256];
// First check to see if the file already exists in current directory
f1 = fopen(dest,"r");
if (f1) {
if (Verbose)
fprintf(stderr,"Warning. Unable to check-out %s. File already exists.\n", filename);
fclose(f1);
return -1;
}
while (!f1) {
sprintf(tempn,"%s%d",dest,rand());
f1 = fopen(tempn,"r");
if (f1) {
fclose(f1);
f1 = 0;
} else {
f1 = fopen(tempn,"w");
if (!f1) {
fprintf(stderr,"Unable to open %s for writing\n", tempn);
return -1;
}
}
}
// Now try to insert the library file into the destination file
if ((insert_file(filename,f1)) == -1) {
fprintf(stderr,"Unable to check-out '%s'. File does not exist in SWIG library.\n",filename);
fclose(f1);
remove(tempn); // Unsuccessful, remove file we created
return -1;
}
fclose(f1);
// Now move the file
rename(tempn,dest);
return 0;
}
// -----------------------------------------------------------------------------
// int checkin_file(char *dir, char *lang, char *source,char *dest)
//
// Attempts to check a file into the SWIG library.
//
// Inputs : dir = Location of the SWIG library.
// lang = Language specific subdirectory.
// source = Source file.
// dest = Destination file.
//
// Output : 0 on success
// -1 on failure.
//
// Side Effects : None
// -----------------------------------------------------------------------------
int checkin_file(char *dir, char *lang, char *source, char *dest) {
FILE *f1;
char tempn[256];
String s;
// First check to see if the file exists
f1 = fopen(source,"r");
if (!f1) return -1;
copy_data(f1,s);
// Now try to open the destination file
sprintf(tempn,"%s/%s/%s", dir,lang,dest);
f1 = fopen(tempn,"w");
if (!f1) return -1;
fprintf(f1,"%s",s.get());
fclose(f1);
return 0;
}

View File

@@ -0,0 +1,215 @@
/*******************************************************************************
* 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.
*******************************************************************************/
/***********************************************************************
* $Header$
*
* internals.h
*
* Contains global variables used in libswig, but which are otherwise
* inaccessible to the user.
*
***********************************************************************/
#include "swig.h"
// -------------------------------------------------------------------
// class DocTitle : public DocEntry
//
// Top level class for managing documentation. Prints out a title,
// date, etc...
// -------------------------------------------------------------------
class DocTitle : public DocEntry {
public:
DocTitle(char *title, DocEntry *_parent); // Create a new title
void output(Documentation *d); // Output documentation
};
// --------------------------------------------------------------------
// class DocSection : public DocEntry
//
// Documentation entry for a section
// --------------------------------------------------------------------
class DocSection : public DocEntry {
public:
DocSection(char *section, DocEntry *_parent);
void output(Documentation *d);
};
// --------------------------------------------------------------------
// class DocFunction : public DocEntry
//
// Documentation entry for generic sorts of declarations
// --------------------------------------------------------------------
class DocDecl : public DocEntry {
public:
DocDecl(char *fname, DocEntry *_parent);
DocDecl(DocEntry *de, DocEntry *_parent);
void output(Documentation *d);
};
// --------------------------------------------------------------------
// class DocClass : public DocEntry
//
// Documentation entry for a C++ class or C struct
// --------------------------------------------------------------------
class DocClass : public DocEntry {
public:
DocClass(char *classname, DocEntry *_parent);
void output(Documentation *d);
};
// --------------------------------------------------------------------
// class DocText : public DocEntry
//
// Documentation entry for some plain ole text. Declared using
// the %text %{,%} directive.
// --------------------------------------------------------------------
class DocText : public DocEntry {
public:
DocText(char *_text, DocEntry *_parent);
void output(Documentation *d);
};
// --------------------------------------------------------------------
// class CommentHandler
//
// Class for managing comment processing.
// --------------------------------------------------------------------
class CommentHandler {
public:
CommentHandler();
CommentHandler(CommentHandler *c);
~CommentHandler();
void add_comment(char *text, int line_num, int col, char *file); // Add a comment
void set_entry(DocEntry *d); // Set documentation entry
static void cleanup(); // Clean-up everything before quitting
void style(char *name, char *value);
void parse_args(int argc, char **argv); // Parse command line options
// Comment handling style parameters
int skip_lines; // # blank lines before comment is throw away
int location; // Comment location (BEFORE or AFTER)
int chop_top; // Lines to chop from the top of a comment
int chop_bottom; // Lines to chop from the bottom
int chop_left; // Characters to chop from left
int chop_right; // Characters to chop from right
int untabify; // Expand tabs
int ignore; // Ignore comments
};
#define BEFORE 0
#define AFTER 1
extern int include_file(char *); // Insert library file
extern char category[256];
extern char title[256];
extern DocEntry *doc_entry;
extern DocEntry *doctitle; // The very first docentry
extern DocEntry *doc_stack[256]; // Stack of documentation entries
extern CommentHandler *handler_stack[256]; // Stack of comment handlers
extern int doc_stack_top; // Top of stack
extern Language *lang;
extern Documentation *doc;
extern CommentHandler *comment_handler; // Comment handling system
extern void swig_append(char *, FILE *);
extern int Stat_func, Stat_var, Stat_const;
extern int IgnoreDoc;
extern int ForceExtern;
extern int WrapExtern;
extern String CCode;
extern int GenerateDefault;
extern int type_id;
extern char *ConfigFile;
extern char *objc_construct;
extern char *objc_destruct;
extern int DocOnly;
// Structure for holding typemap parameters
// A typemap parameter consists of a single parameter (type + name)
// and an optional list of arguments corresponding to local variables.
// Has an optional link for building linked lists of parameter lists
struct TMParm {
Parm *p;
ParmList *args;
TMParm *next;
TMParm() {
next = 0;
}
};
/* Global variables. Needs to be cleaned up */
#ifdef WRAP
FILE *f_header; // Some commonly used
FILE *f_wrappers; // FILE pointers
FILE *f_init;
FILE *f_input;
char InitName[256];
char LibDir[512]; // Library directory
char **InitNames = 0;
int Status;
int TypeStrict; // Type checking strictness
int Verbose;
char category[256]; // Variables for documentation
char title[256];
DocEntry *doc_entry = 0; // Current documentation entry
DocEntry *doctitle = 0; // First doc entry
DocEntry *doc_stack[256]; // Stack of documentation entries
CommentHandler *handler_stack[256]; // Stack of comment handlers
int doc_stack_top = 0; // Top of stack
Language *lang; // Language method
Documentation *doc; // Documentation method
int Stat_func = 0;
int Stat_var = 0;
int Stat_const = 0;
int CPlusPlus = 0;
int ObjC = 0;
int ObjCClass = 0;
int AddMethods = 0; // AddMethods flag
int NewObject = 0; // NewObject flag
int Inline = 0; // Inline mode
int Stats = 0;
int IgnoreDoc = 0; // Ignore documentation mode
int ForceExtern = 0; // Force extern mode
int WrapExtern = 0;
int GenerateDefault = 0; // Generate default constructors
char *Config = 0;
int NoInclude = 0;
char *typemap_lang = 0; // Typemap name
int type_id = 0; // Type identifier
int error_count = 0; // Error count
char *ConfigFile = 0;
int DocOnly = 0; // Only produce documentation
#endif
/* Number of initialization names that can be used */
#define NI_NAMES 512
extern void type_undefined_check(void);

View File

@@ -0,0 +1,621 @@
/*******************************************************************************
* 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.
*******************************************************************************/
#include "internal.h"
#include <ctype.h>
// -----------------------------------------------------------------------
// $Header$
//
// lang.cxx
//
// This file contains some default methods for the SWIG language class.
// Default C++ handling is implemented here as well as a few utility functions.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------
// void Language::set_init(char *iname)
//
// Called to make an initialization function by %init (obsolete)
// -----------------------------------------------------------------
void Language::set_init(char *iname) {
set_module(iname,0);
}
// -----------------------------------------------------------------
// void Language::create_command(char *cname, char *iname
//
// Method for adding a previous wrapped C function.
// -----------------------------------------------------------------
void Language::create_command(char *, char *) {
fprintf(stderr,"SWIG Warning. No command creation procedure defined.\n");
fprintf(stderr,"C++ inheritance may not work correctly.\n");
}
// -----------------------------------------------------------------
// void Language::add_native(char *targetlang, char *funcname)
//
// Method for adding a native function
// -----------------------------------------------------------------
void
Language::add_native(char *, char *funcname) {
fprintf(stderr,"%s : Line %d. Adding native function %s not supported (ignored).\n", input_file, line_number, funcname);
}
static char *ClassName = 0; // This is the real name of the current class
static char *ClassRename = 0; // This is non-NULL if the class has been renamed
static char *ClassType = 0; // Type of class (ie. union, struct, class)
// ---------------------------------------------------------------------------------
// void Language::cpp_open_class(char *classname, char *classrename, char *ctype, int strip)
//
// Open a new C++ class.
//
// INPUTS:
// classname = Real name of the C++ class
// classrename = New name of the class (if %name was used)
// ctype = Class type (struct, class, union, etc...)
// strip = Flag indicating whether we should strip the class type off
//
// This function is in charge of creating a new class. The SWIG parser has
// already processed the entire class definition prior to calling this
// function (which should simplify things considerably).
//
// ---------------------------------------------------------------------------------
void Language::cpp_open_class(char *classname, char *classrename, char *ctype, int strip) {
// Copy the class name
if (ClassName) delete ClassName;
ClassName = copy_string(classname);
// Copy the class renaming
if (ClassRename) delete ClassRename;
if (classrename) {
ClassRename = copy_string(classrename);
} else {
ClassRename = 0; // No renaming
}
// Make the class type
if (ClassType) delete ClassType;
ClassType = new char[strlen(ctype)+2];
if (strip) ClassType[0] = 0;
else sprintf(ClassType,"%s ",ctype);
if (doc_entry) {
doc_entry->usage = "";
doc_entry->name = copy_string(classname);
doc_entry->usage << "class ";
if (ClassRename) doc_entry->usage << ClassRename;
else doc_entry->usage << ClassName;
doc_entry->cinfo << "created from " << ctype
<< " " << classname;
}
}
// ---------------------------------------------------------------------------------
// void Language::cpp_close_class()
//
// Close the current class
// ---------------------------------------------------------------------------------
void Language::cpp_close_class() {
// Doesn't really do anything
}
// ---------------------------------------------------------------------------------
// void Language::cpp_member_func(char *name, char *iname, DataType *t, ParmList *l)
//
// Method for adding C++ member function
//
// INPUTS:
// name - name of the member function
// iname - renaming (if given)
// t - Return datatype
// l - Parameter list
//
// By default, we're going to create a function of the form :
//
// Foo_bar(this,args)
//
// Where Foo is the classname, bar is the member name and the this pointer is
// explicitly attached to the beginning.
//
// The renaming only applies to the member function part, not the full classname.
//
// ---------------------------------------------------------------------------------
void Language::cpp_member_func(char *name, char *iname, DataType *t, ParmList *l) {
char cname[256]; // Name of the C function
char new_name[256];
char *prefix;
// Generate the C wrapper function name and interpreter name of this function
// Set the classname prefix
if (ClassRename) {
prefix = ClassRename;
} else {
prefix = ClassName;
}
// Generate the C wrapper name for this method
if (AddMethods) {
char *bc = cplus_base_class(name); // Get base class name of this method
if (bc)
strcpy(cname, name_member(name,bc));
else
strcpy(cname, name_member(name,ClassName));
} else {
strcpy(cname, name_member(name,ClassName));
}
// Create the actual function name
if (iname) {
strcpy(new_name, name_member(iname, prefix));
} else {
strcpy(new_name, name_member(name,prefix));
}
// Now do a symbol table lookup on it :
if (add_symbol(new_name, 0,0)) {
fprintf(stderr,"%s : Line %d. Function %s (member %s) multiply defined (2nd definition ignored).\n",
input_file, line_number, cname, name);
return;
}
// Now produce the resulting wrapper function
if (doc_entry) {
doc_entry->cinfo << "Member : ";
}
cplus_emit_member_func(ClassName, ClassType, ClassRename, name, iname, t, l, AddMethods);
}
// ---------------------------------------------------------------------------------
// void Language::cpp_constructor(char *name, char *iname, ParmList *l)
//
// Method for adding C++ member constructor
//
// INPUTS:
// name - Name of the constructor (usually same as classname)
// iname - Renamed version
// l - parameters
// ---------------------------------------------------------------------------------
void Language::cpp_constructor(char *name, char *iname, ParmList *l) {
char *prefix, *cname;
if ((strcmp(name,ClassName)) && (!ObjCClass)) {
fprintf(stderr,"%s : Line %d. Function %s must have a return type.\n",
input_file, line_number, name);
return;
}
// Set the prefix
if (ClassRename)
prefix = ClassRename;
else
prefix = ClassName;
if (iname)
cname = name_construct(iname);
else
cname = name_construct(prefix);
// Add this function to the SWIG symbol table
if (add_symbol(cname, 0,0)) {
fprintf(stderr,"%s : Line %d. Constructor %s multiply defined (2nd definition ignored).\n",
input_file, line_number, cname);
return;
}
// Attach a note to the cinfo field.
if (doc_entry)
doc_entry->cinfo << "Constructor: ";
// Call our default method
cplus_emit_constructor(ClassName, ClassType, ClassRename, name, iname, l, AddMethods);
}
// ---------------------------------------------------------------------------------
// void Language::cpp_destructor(char *name, char *iname)
//
// Method for adding C++ member destructor
//
// INPUT:
// name - Name of the destructor (classname)
// iname - Renamed destructor
//
// ---------------------------------------------------------------------------------
void Language::cpp_destructor(char *name, char *iname) {
char *cname;
if (ClassRename)
cname = name_destroy(ClassRename);
else
cname = name_destroy(ClassName);
// Add this function to the SWIG symbol table
if (add_symbol(cname, 0,0)) {
fprintf(stderr,"%s : Line %d. Destructor %s multiply defined (2nd definition ignored).\n",
input_file, line_number, cname);
return;
}
// Attach a note to the description
if (doc_entry)
doc_entry->cinfo << "Destructor: ";
// Call our default method
cplus_emit_destructor(ClassName, ClassType, ClassRename, name, iname, AddMethods);
}
// ---------------------------------------------------------------------------------
// void Language::cleanup()
//
// Perform any necessary cleanup after reaching end of interface file
// ---------------------------------------------------------------------------------
void Language::cpp_cleanup() {
// This doesn't do anything (well, not be default)
}
// ---------------------------------------------------------------------------------
// void Language::cpp_inherit(char **baseclass, int mode)
//
// Inherit attributes from given baseclass.
//
// INPUT:
// baseclass = NULL terminate list of baseclasses
//
// ---------------------------------------------------------------------------------
void Language::cpp_inherit(char **baseclass, int mode) {
extern void cplus_inherit_members(char *, int);
int i = 0;
if (!baseclass) return;
while (baseclass[i]) {
cplus_inherit_members(baseclass[i],mode);
i++;
}
}
// ---------------------------------------------------------------------------------
// void Language::cpp_variable(char *name, char *iname, DataType *t)
//
// Wrap a C++ data member
//
// INPUTS :
// name = Name of the C++ member
// iname = Name as used in the interpreter
// t = Datatype
//
// This creates a pair of functions to set/get the variable of a member.
// ---------------------------------------------------------------------------------
void Language::cpp_variable(char *name, char *iname, DataType *t) {
char *prefix, *cname;
// Set the class prefix
if (ClassRename) {
prefix = ClassRename;
} else {
prefix = ClassName;
}
if (iname)
cname = name_get(name_member(iname,prefix));
else
cname = name_get(name_member(name,prefix));
// Check the symbol table
if (add_symbol(cname,(DataType *) 0,(char *) 0)) {
fprintf(stderr,"%s : Line %d. Variable %s multiply defined (2nd definition ignored).\n", input_file, line_number, cname);
return;
}
// Attach a c descriptor
if (doc_entry)
doc_entry->cinfo << "Member data: ";
// Create a function to set the value of the variable
if (!(Status & STAT_READONLY)) {
cplus_emit_variable_set(ClassName, ClassType, ClassRename, name, iname, t, AddMethods);
// Add a new line to the documentation entry
if (doc_entry) doc_entry->usage << "\n";
}
// Create a function to get the value of a variable
cplus_emit_variable_get(ClassName,ClassType, ClassRename, name, iname, t, AddMethods);
}
// ---------------------------------------------------------------------------------
// void Language::cpp_static_func(char *name, char *iname, DataType *t, ParmList *l)
//
// Wrap a static C++ function
//
// INPUTS:
// name = Real name of the function
// iname = New name in interpreter
// t = Return datatype
// l = Parameters
// ---------------------------------------------------------------------------------
void Language::cpp_static_func(char *name, char *iname, DataType *t, ParmList *l) {
char *prefix;
char *mname;
char *cname;
// Set the classname prefix
if (ClassRename)
prefix = ClassRename;
else
prefix = ClassName;
// Set the member function name
if (iname)
mname = iname;
else
mname = name;
cname = name_member(mname,prefix);
// Now do a symbol table lookup on it :
if (add_symbol(cname, 0,0)) {
if (ObjCClass)
fprintf(stderr,"%s : Line %d. class function %s multiply defined (2nd definition ignored).\n",
input_file, line_number, cname);
else
fprintf(stderr,"%s : Line %d. static function %s multiply defined (2nd definition ignored).\n",
input_file, line_number, cname);
return;
}
if (doc_entry) {
if (ObjCClass)
doc_entry->cinfo << "Class method : ";
else
doc_entry->cinfo << "Static member : ";
}
cplus_emit_static_func(ClassName,ClassType, ClassRename, name, iname, t, l, AddMethods);
}
// ---------------------------------------------------------------------------------
// void Language::cpp_declare_const(char *name, char *iname, DataType *t, char *value)
//
// Create a C++ constant
//
// INPUTS :
// name = Real name of the constant
// iname = new name
// t = Datatype
// value = value as a string
//
// ---------------------------------------------------------------------------------
void Language::cpp_declare_const(char *name, char *iname, DataType *type, char *value)
{
char *cname;
char mname[256];
char *new_value;
char *prefix;
// Set the classname prefix
if (ClassRename) {
prefix = ClassRename;
} else {
prefix = ClassName;
}
// Set the constant name
if (iname)
cname = name_member(iname,prefix);
else
cname = name_member(name,prefix);
// Now do a symbol table lookup on it :
if (add_symbol(cname, 0,0)) {
fprintf(stderr,"%s : Line %d. Constant %s (member %s) multiply defined (2nd definition ignored).\n",
input_file, line_number, cname, name);
return;
}
// Form correct C++ name
sprintf(mname,"%s::%s",ClassName,name);
// Declare a constant
if (!value) {
new_value = new char[strlen(ClassName)+strlen(name)+3];
sprintf(new_value,"%s::%s",ClassName,name);
} else {
new_value = value;
}
lang->declare_const(cname,cname,type, new_value);
if (!value) {
delete new_value;
}
}
// ---------------------------------------------------------------------------------
// void Language::cpp_static_var(char *name, char *iname, DataType *t)
//
// Wrap a static C++ variable
//
// INPUT :
// name = name of the variable
// iname = interpreter name
// t = Datatype
//
// ---------------------------------------------------------------------------------
void Language::cpp_static_var(char *name, char *iname, DataType *t) {
char *cname;
char mname[256];
char *prefix;
// Set the classname prefix
if (ClassRename) {
prefix = ClassRename;
} else {
prefix = ClassName;
}
// Create the variable name
if (iname)
cname = name_member(iname,prefix);
else
cname = name_member(name,prefix);
// Now do a symbol table lookup on it :
if (add_symbol(cname, 0,0)) {
fprintf(stderr,"%s : Line %d. Variable %s (member %s) multiply defined (2nd definition ignored).\n",
input_file, line_number, cname, name);
return;
}
// Form correct C++ name
sprintf(mname,"%s::%s",ClassName,name);
if (doc_entry)
doc_entry->cinfo << "Static member : ";
// Link with this variable
lang->link_variable(mname,cname,t);
}
// ---------------------------------------------------------------------------------
// void Language::cpp_class_decl(char *classtype, char *classrename, char *classname)
//
// A forward class declaration
// ---------------------------------------------------------------------------------
void Language::cpp_class_decl(char *, char *, char *) {
// Does nothing by default
}
// -----------------------------------------------------------------------------
// void Language::cpp_pragma(Pragma *plist)
//
// Handler C++ pragmas
// -----------------------------------------------------------------------------
void Language::cpp_pragma(Pragma *) {
// Does nothing by default
}
// ---------------------------------------------------------------------------------
// void Language::add_typedef(DataType *t, char *name)
//
// Process a typedef declaration.
// ---------------------------------------------------------------------------------
void Language::add_typedef(DataType *, char *) {
}
// ---------------------------------------------------------------------------------
// void Language::pragma(char *target, char *var, char *value)
//
// A pragma declaration
// ---------------------------------------------------------------------------------
void Language::pragma(char *, char *, char *) {
// Does nothing by default
}
// ---------------------------------------------------------------------------------
// void Language::import(char *filename)
//
// An import directive
// ---------------------------------------------------------------------------------
void Language::import(char *) {
// Does nothing by default
}

View File

@@ -0,0 +1,490 @@
/*******************************************************************************
* 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.
*******************************************************************************/
/***********************************************************************
* $Header$
*
* latex.c
*
* Latex specific functions for producing documentation.
*
***********************************************************************/
#include "swig.h"
#include "latex.h"
// -------------------------------------------------------------------
// LATEX::LATEX()
//
// Create new LaTeX handler
// -------------------------------------------------------------------
LATEX::LATEX() {
sect_count = 0;
tag_pagestyle = "\\pagestyle{headings}";
tag_parindent = "0.0in";
tag_textwidth = "6.5in";
tag_documentstyle = "[11pt]{article}";
tag_oddsidemargin = "0.0in";
tag_title = "{\\Large \\bf : }";
tag_preformat = "{\\small \\begin{verbatim}:\\end{verbatim}}";
tag_usage = "{\\tt \\bf : }";
tag_descrip = "\\\\\n\\makebox[0.5in]{}\\begin{minipage}[t]{6in}:\n\\end{minipage}\\\\\n";
tag_text = ":\\\\";
tag_cinfo = "{\\tt : }\\\\";
tag_section = "\\section{:}";
tag_subsection="\\subsection{:}";
tag_subsubsection="\\subsubsection{:}";
}
// -------------------------------------------------------------------
// char *start_tag(char *tag) {
//
// Returns the start of a tag
// -------------------------------------------------------------------
char *LATEX::start_tag(char *tag) {
static String stag;
char *c;
stag = "";
c = tag;
while ((*c) && (*c != ':')) {
stag << *c;
c++;
}
return stag.get();
}
// -------------------------------------------------------------------
// char *end_tag(char *tag) {
//
// Returns the end of a tag
// -------------------------------------------------------------------
char *LATEX::end_tag(char *tag) {
static String etag;
char *c;
etag = "";
c = tag;
while ((*c) && (*c != ':')) {
c++;
}
if (*c) {
c++;
while (*c) {
etag << *c;
c++;
}
}
return etag.get();
}
// -------------------------------------------------------------------
// LATEX::print_string(char *s, String &str)
//
// Dumps string s to str, but performs some LaTeX character replacements
// -------------------------------------------------------------------
void LATEX::print_string(char *s, String &str) {
char *c;
c = s;
while (*c) {
switch(*c) {
case '*':
case '<':
case '>':
case '+':
case '=':
case '|':
str << "$" << *c << "$";
break;
case '\\':
str << "\\\\";
break;
case '_':
str << "\\_";
break;
case '%':
str << "\\%";
break;
case '$':
str << "\\$";
break;
case '&':
str << "\\&";
break;
case '#':
str << "\\#";
break;
case '\n':
str << "\\\\\n";
break;
default :
str << *c;
break;
}
c++;
}
}
// --------------------------------------------------------------
// LATEX::print_decl(DocEntry *)
//
// Print a documentation entry
// --------------------------------------------------------------
void LATEX::print_decl(DocEntry *de) {
char *c;
c = de->usage.get();
if (c) {
s_doc << start_tag(tag_usage);
print_string(c,s_doc);
s_doc << end_tag(tag_usage) << "\n";
}
// Check to see if there any information available
if ((strlen(de->cinfo.get()) && de->print_info) || strlen(de->text.get())) {
// There is additional information now. If we're in preformatting mode,
// we need to handle things differently
s_doc << start_tag(tag_descrip) << "\n";
if (!de->format) {
// Verbatim mode
s_doc << start_tag(tag_preformat) << "\n";
// If there is any C annotation, print that
if (de->print_info) {
c = de->cinfo.get();
if (strlen(c) > 0) {
s_doc << "[ " << c << " ]\n";
}
}
c = de->text.get();
if (strlen(c) > 0) {
s_doc << c;
}
s_doc << end_tag(tag_preformat) << "\n";
} else {
// We are in format mode now
// We need to emit some stubs for the description format
// If there is any C annotation, print that
if (de->print_info) {
c = de->cinfo.get();
if (strlen(c) > 0) {
s_doc << start_tag(tag_cinfo) << "[ ";
print_string(c,s_doc);
s_doc << " ] " << end_tag(tag_cinfo) << "\n";
}
}
// Print out descriptive text (if any).
c = de->text.get();
if (strlen(c) > 0) {
s_doc << c << "\\\\\n";
}
}
s_doc << end_tag(tag_descrip) << "\n";
} else {
s_doc << "\\\\\n"; // No description available, move to next line
}
}
// --------------------------------------------------------------
// LATEX::print_text(DocEntry *de)
//
// Print out some text. We use verbatim mode because of formatting
// problems.
// --------------------------------------------------------------
void LATEX::print_text(DocEntry *de) {
char *c;
c = de->text.get();
if (strlen(c) > 0) {
if (de->format) {
s_doc << start_tag(tag_text) << "\n";
s_doc << c;
s_doc << end_tag(tag_text) << "\n\n";
} else {
s_doc << start_tag(tag_preformat) << "\n";
s_doc << c;
s_doc << end_tag(tag_preformat) << "\n\n";
}
}
}
void LATEX::title(DocEntry *de) {
char *c;
c = de->usage.get();
if (strlen(c) > 0) {
s_doc << start_tag(tag_title) << " ";
print_string(c,s_doc);
s_doc << end_tag(tag_title) << "\\\\\n";
}
// Print out any C annotation and descriptive text
// Check to see if there any information available
if ((strlen(de->cinfo.get()) && de->print_info) || strlen(de->text.get())) {
// There is additional information now. If we're in preformatting mode,
// we need to handle things differently
if (!de->format) {
// Verbatim mode
s_doc << start_tag(tag_preformat) << "\n";
// If there is any C annotation, print that
if (de->print_info) {
c = de->cinfo.get();
if (strlen(c) > 0) {
s_doc << "[ " << c << " ]\n";
}
}
c = de->text.get();
if (strlen(c) > 0) {
s_doc << c;
}
s_doc << end_tag(tag_preformat) << "\n\n";
} else {
// We are in format mode now
// We need to emit some stubs for the description format
s_doc << start_tag(tag_text);
// If there is any C annotation, print that
if (de->print_info) {
c = de->cinfo.get();
if (strlen(c) > 0) {
s_doc << start_tag(tag_cinfo) << "[ ";
print_string(c,s_doc);
s_doc << " ] " << end_tag(tag_cinfo) << "\n";
}
}
// Print out descriptive text (if any).
c = de->text.get();
if (strlen(c) > 0) {
s_doc << c;
}
s_doc << end_tag(tag_text);
}
}
}
void LATEX::newsection(DocEntry *de,int sectnum) {
char *c;
char *tag;
sect_num[sect_count] = sectnum;
sect_count++;
switch (sect_count) {
case 1: /* Section */
tag = tag_section;
break;
case 2: /* Subsection */
tag = tag_subsection;
break;
default: /* subsubsection */
tag = tag_subsubsection;
break;
}
s_doc << start_tag(tag);
c = de->usage.get();
print_string(c,s_doc);
s_doc << end_tag(tag);
// Print out any C annotation and descriptive text
// Check to see if there any information available
if ((strlen(de->cinfo.get()) && de->print_info) || strlen(de->text.get())) {
// There is additional information now. If we're in preformatting mode,
// we need to handle things differently
if (!de->format) {
// Verbatim mode
s_doc << start_tag(tag_preformat) << "\n";
// If there is any C annotation, print that
if (de->print_info) {
c = de->cinfo.get();
if (strlen(c) > 0) {
s_doc << "[ " << c << " ]\n";
}
}
c = de->text.get();
if (strlen(c) > 0) {
s_doc << c;
}
s_doc << end_tag(tag_preformat) << "\n\n";
} else {
// We are in format mode now
// We need to emit some stubs for the description format
s_doc << start_tag(tag_text);
// If there is any C annotation, print that
if (de->print_info) {
c = de->cinfo.get();
if (strlen(c) > 0) {
s_doc << start_tag(tag_cinfo) << "[ ";
print_string(c,s_doc);
s_doc << " ] " << end_tag(tag_cinfo) << "\n";
}
}
// Print out descriptive text (if any).
c = de->text.get();
if (strlen(c) > 0) {
s_doc << c;
}
s_doc << end_tag(tag_text);
}
}
}
void LATEX::endsection() {
if (sect_count > 0) sect_count--;
}
void LATEX::separator() {
}
void LATEX::init(char *filename) {
char f[256];
sprintf(f,"%s.tex",filename);
sprintf(fn,"%s",filename);
f_doc = fopen(f,"w");
if (f_doc == NULL) {
fprintf(stderr, "Unable to open %s\n", fn);
SWIG_exit(1);
}
}
void LATEX::close(void) {
fprintf(f_doc,"\\documentstyle%s\n",tag_documentstyle);
fprintf(f_doc,"\\setlength{\\parindent}{%s}\n",tag_parindent);
fprintf(f_doc,"\\setlength{\\textwidth}{%s}\n",tag_textwidth);
fprintf(f_doc,"\\setlength{\\oddsidemargin}{%s}\n",tag_oddsidemargin);
fprintf(f_doc,"%s\n",tag_pagestyle);
fprintf(f_doc,"\\begin{document}\n");
fprintf(f_doc,"%s\n",s_doc.get());
fprintf(f_doc,"\\end{document}\n");
fclose(f_doc);
if (Verbose)
fprintf(stderr,"Documentation written to %s.tex\n", fn);
}
// -------------------------------------------------------------------
// LATEX::style(char *name, char *value)
//
// Process style parameters
// -------------------------------------------------------------------
void LATEX::style(char *name, char *value) {
if (strcmp(name,"latex_title") == 0) {
if (value)
tag_title = copy_string(value);
} else if (strcmp(name,"latex_pagestyle") == 0) {
if (value)
tag_pagestyle = copy_string(value);
} else if (strcmp(name,"latex_section") == 0) {
if (value)
tag_section = copy_string(value);
} else if (strcmp(name,"latex_subsection") == 0) {
if (value)
tag_subsection = copy_string(value);
} else if (strcmp(name,"latex_subsubsection") == 0) {
if (value)
tag_subsubsection = copy_string(value);
} else if (strcmp(name,"latex_usage") == 0) {
if (value)
tag_usage = copy_string(value);
} else if (strcmp(name,"latex_descrip") == 0) {
if (value)
tag_descrip = copy_string(value);
} else if (strcmp(name,"latex_text") == 0) {
if (value)
tag_text = copy_string(value);
} else if (strcmp(name,"latex_cinfo") == 0) {
if (value)
tag_cinfo = copy_string(value);
} else if (strcmp(name,"latex_preformat") == 0) {
if (value)
tag_preformat = copy_string(value);
} else if (strcmp(name,"latex_parindent") == 0) {
if (value)
tag_parindent = copy_string(value);
} else if (strcmp(name,"latex_textwidth") == 0) {
if (value)
tag_textwidth = copy_string(value);
} else if (strcmp(name,"latex_documentstyle") == 0) {
if (value)
tag_documentstyle = copy_string(value);
} else if (strcmp(name,"latex_oddsidemargin") == 0) {
if (value)
tag_oddsidemargin = copy_string(value);
}
}
// -------------------------------------------------------------------
// LATEX::parse_args(int argc, char **argv)
//
// Parse command line options
// -------------------------------------------------------------------
static char *latex_usage = "\
LATEX Documentation Options (available with -dlatex)\n\
None available.\n\n";
void LATEX::parse_args(int argc, char **argv) {
int i;
for (i = 0; i < argc; i++) {
if (argv[i]) {
if (strcmp(argv[i],"-help") == 0) {
fputs(latex_usage,stderr);
}
}
}
}

View File

@@ -0,0 +1,79 @@
/*******************************************************************************
* 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.
*******************************************************************************/
/***********************************************************************
* $Header$
*
* latex.h
*
* Latex specific functions for producing documentation.
***********************************************************************/
class LATEX : public Documentation {
private:
FILE *f_doc;
String s_doc;
char fn[256];
char *start_tag(char *);
char *end_tag(char *);
void print_string(char *s, String &str);
int sect_count; // Section counter
int sect_num[20]; // Section numbers
// Style parameters
char *tag_parindent;
char *tag_textwidth;
char *tag_documentstyle;
char *tag_oddsidemargin;
char *tag_title;
char *tag_preformat;
char *tag_usage;
char *tag_descrip;
char *tag_text;
char *tag_cinfo;
char *tag_pagestyle;
char *tag_section;
char *tag_subsection;
char *tag_subsubsection;
public:
LATEX();
void parse_args(int argc, char **argv);
void title(DocEntry *de);
void newsection(DocEntry *de, int sectnum);
void endsection();
void print_decl(DocEntry *de);
void print_text(DocEntry *de);
void separator();
void init(char *filename);
void close(void);
void style(char *name, char *value);
};

View File

@@ -0,0 +1,643 @@
/*******************************************************************************
* 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.
*******************************************************************************/
/***********************************************************************
* $Header$
*
* main.cxx
*
* The main program.
*
***********************************************************************/
#define WRAP
#include "internal.h"
#include "ascii.h"
#include "latex.h"
#include "html.h"
#include "nodoc.h"
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
class SwigException {};
static char *usage = "\
\nDocumentation Options\n\
-dascii - ASCII documentation.\n\
-dhtml - HTML documentation.\n\
-dlatex - LaTeX documentation.\n\
-dnone - No documentation.\n\n\
General Options\n\
-c - Produce raw wrapper code (omit support code)\n\
-c++ - Enable C++ processing\n\
-ci - Check a file into the SWIG library\n\
-co - Check a file out of the SWIG library\n\
-d docfile - Set name of the documentation file.\n\
-Dsymbol - Define a symbol (for conditional compilation)\n\
-I<dir> - Look for SWIG files in <dir>\n\
-l<ifile> - Include SWIG library file.\n\
-make_default - Create default constructors/destructors\n\
-nocomment - Ignore all comments (for documentation).\n\
-o outfile - Set name of the output file.\n\
-objc - Enable Objective C processing\n\
-stat - Print statistics\n\
-strict n - Set pointer type-checking strictness\n\
-swiglib - Report location of SWIG library and exit\n\
-t typemap_file - Use a typemap file.\n\
-v - Run in verbose mode\n\
-version - Print SWIG version number\n\
-help - This output.\n\n";
//-----------------------------------------------------------------
// main()
//
// Main program. Initializes the files and starts the parser.
//-----------------------------------------------------------------
char infilename[256];
char filename[256];
char fn_header[256];
char fn_wrapper[256];
char fn_init[256];
char output_dir[512];
#ifdef MACSWIG
FILE *swig_log;
#endif
char *SwigLib;
//char** __argv;
//int __argc;
int SWIG_main(int argc, char *argv[], Language *l, Documentation *d) {
int i;
char *c;
extern FILE *LEX_in;
extern void add_directory(char *);
extern char *get_time();
char temp[512];
char infile[512];
char *outfile_name = 0;
extern int add_iname(char *);
int help = 0;
int ignorecomments = 0;
int checkout = 0;
int checkin = 0;
char *typemap_file = 0;
char *includefiles[256];
int includecount = 0;
extern void check_suffix(char *);
extern void scanner_file(FILE *);
#ifdef MACSWIG
try {
#endif
f_wrappers = 0;
f_init = 0;
f_header = 0;
//__argc = argc;
//__argv = argv;
lang = l;
doc = d;
Status = 0;
TypeStrict = 2; // Very strict type checking
Verbose = 0;
char *doc_file = 0;
DataType::init_typedef(); // Initialize the type handler
// Set up some default symbols (available in both SWIG interface files
// and C files)
add_symbol("SWIG",0,0); // Define the SWIG symbol
#ifdef MACSWIG
add_symbol("SWIGMAC",0,0);
#endif
#ifdef SWIGWIN32
add_symbol("SWIGWIN32",0,0);
#endif
strcpy(LibDir, getSwigLib());
SwigLib = copy_string(LibDir); // Make a copy of the real library location
#ifdef MACSWIG
sprintf(temp,"%s:config", LibDir);
add_directory(temp);
add_directory(":swig_lib:config");
add_directory(LibDir);
add_directory(":swig_lib");
#else
sprintf(temp,"%s/config", LibDir);
add_directory(temp);
add_directory("./swig_lib/config");
add_directory(LibDir);
add_directory("./swig_lib");
sprintf(InitName,"init_wrap");
#endif
sprintf(InitName,"init_wrap");
// Get options
for (i = 1; i < argc; i++) {
if (argv[i]) {
if (strncmp(argv[i],"-I",2) == 0) {
// Add a new directory search path
includefiles[includecount++] = copy_string(argv[i]+2);
mark_arg(i);
} else if (strncmp(argv[i],"-D",2) == 0) {
// Create a symbol
add_symbol(argv[i]+2, (DataType *) 0, (char *) 0);
mark_arg(i);
} else if (strcmp(argv[i],"-strict") == 0) {
if (argv[i+1]) {
TypeStrict = atoi(argv[i+1]);
mark_arg(i);
mark_arg(i+1);
i++;
} else {
arg_error();
}
} else if ((strcmp(argv[i],"-verbose") == 0) || (strcmp(argv[i],"-v") == 0)) {
Verbose = 1;
mark_arg(i);
} else if (strcmp(argv[i],"-dascii") == 0) {
doc = new ASCII;
mark_arg(i);
} else if (strcmp(argv[i],"-dnone") == 0) {
doc = new NODOC;
mark_arg(i);
} else if (strcmp(argv[i],"-dhtml") == 0) {
doc = new HTML;
mark_arg(i);
} else if (strcmp(argv[i],"-dlatex") == 0) {
doc = new LATEX;
mark_arg(i);
} else if (strcmp(argv[i],"-nocomment") == 0) {
ignorecomments = 1;
mark_arg(i);
} else if (strcmp(argv[i],"-stat") == 0) {
Stats=1;
mark_arg(i);
} else if (strcmp(argv[i],"-c++") == 0) {
CPlusPlus=1;
mark_arg(i);
} else if (strcmp(argv[i],"-objc") == 0) {
ObjC = 1;
mark_arg(i);
} else if (strcmp(argv[i],"-c") == 0) {
NoInclude=1;
mark_arg(i);
} else if (strcmp(argv[i],"-make_default") == 0) {
GenerateDefault = 1;
mark_arg(i);
} else if (strcmp(argv[i],"-swiglib") == 0) {
printf("%s\n", LibDir);
SWIG_exit(0);
} else if (strcmp(argv[i],"-o") == 0) {
mark_arg(i);
if (argv[i+1]) {
outfile_name = copy_string(argv[i+1]);
mark_arg(i+1);
i++;
} else {
arg_error();
}
} else if (strcmp(argv[i],"-d") == 0) {
mark_arg(i);
if (argv[i+1]) {
doc_file = copy_string(argv[i+1]);
mark_arg(i+1);
i++;
} else {
arg_error();
}
} else if (strcmp(argv[i],"-t") == 0) {
mark_arg(i);
if (argv[i+1]) {
typemap_file = copy_string(argv[i+1]);
mark_arg(i+1);
i++;
} else {
arg_error();
}
} else if (strcmp(argv[i],"-version") == 0) {
fprintf(stderr,"\nSWIG Version %d.%d %s\n", SWIG_MAJOR_VERSION,
SWIG_MINOR_VERSION, SWIG_SPIN);
fprintf(stderr,"Copyright (c) 1995-98\n");
fprintf(stderr,"University of Utah and the Regents of the University of California\n");
fprintf(stderr,"\nCompiled with %s\n", SWIG_CC);
SWIG_exit(0);
} else if (strncmp(argv[i],"-l",2) == 0) {
// Add a new directory search path
library_add(argv[i]+2);
mark_arg(i);
} else if (strcmp(argv[i],"-co") == 0) {
checkout = 1;
mark_arg(i);
} else if (strcmp(argv[i],"-ci") == 0) {
checkin = 1;
mark_arg(i);
} else if (strcmp(argv[i],"-help") == 0) {
fputs(usage,stderr);
mark_arg(i);
help = 1;
}
}
}
while (includecount > 0) {
add_directory(includefiles[--includecount]);
}
// Create a new documentation handler
if (doc == 0) doc = new ASCII;
// Open up a comment handler
comment_handler = new CommentHandler();
comment_handler->parse_args(argc,argv);
if (ignorecomments) comment_handler->style("ignore",0);
// Create a new documentation entry
doctitle = new DocTitle("",0);
doctitle->parse_args(argc,argv);
doc_entry = doctitle;
// Handle documentation module options
doc->parse_args(argc,argv);
// Parse language dependent options
lang->parse_args(argc,argv);
if (help) SWIG_exit(0); // Exit if we're in help mode
// Check all of the options to make sure we're cool.
check_options();
// If we made it this far, looks good. go for it....
// Create names of temporary files that are created
sprintf(infilename,"%s", argv[argc-1]);
input_file = new char[strlen(infilename)+1];
strcpy(input_file, infilename);
// If the user has requested to check out a file, handle that
if (checkout) {
int stat;
char *outfile = input_file;
if (outfile_name)
outfile = outfile_name;
stat = checkout_file(input_file,outfile);
if (!stat) {
fprintf(stderr,"%s checked out from the SWIG library\n",input_file);
} else {
FILE * f = fopen(input_file,"r");
if (f) {
fprintf(stderr,"Unable to check-out %s. File already exists.\n", input_file);
fclose(f);
} else {
fprintf(stderr,"Unable to check-out %s\n", input_file);
}
}
} else if (checkin) {
// Try to check-in a file to the SWIG library
int stat;
char *outname = input_file;
if (outfile_name)
outname = outfile_name;
stat = checkin_file(SwigLib, LibDir, input_file, outname);
if (!stat) {
fprintf(stderr,"%s checked-in to %s/%s/%s\n", input_file, SwigLib, LibDir, outname);
} else {
fprintf(stderr,"Unable to check-in %s to %s/%s\n", input_file, SwigLib, LibDir);
}
} else {
doctitle->file = copy_string(input_file);
doctitle->line_number = -1000;
doctitle->end_line = -1000;
// Check the suffix for a .c file. If so, we're going to
// declare everything we see as "extern"
check_suffix(infilename);
// Strip off suffix
c = infilename + strlen(infilename);
while (c != infilename) {
if (*c == '.') {
*c = 0;
break;
} else {
c--;
}
}
if (!outfile_name) {
sprintf(fn_header,"%s_wrap.c",infilename);
strcpy(infile,infilename);
strcpy(output_dir,"");
} else {
sprintf(fn_header,"%s",outfile_name);
// Try to identify the output directory
char *cc = outfile_name;
char *lastc = outfile_name;
while (*cc) {
#ifdef MACSWIG
if (*cc == ':') lastc = cc+1;
#else
if (*cc == '/') lastc = cc+1;
#endif
cc++;
}
cc = outfile_name;
char *dd = output_dir;
while (cc != lastc) {
*dd = *cc;
dd++;
cc++;
}
*dd = 0;
// Patch up the input filename
cc = infilename + strlen(infilename);
while (cc != infilename) {
#ifdef MACSWIG
if (*cc == ':') {
cc++;
break;
}
#else
if (*cc == '/') {
cc++;
break;
}
#endif
cc--;
}
strcpy(infile,cc);
}
sprintf(fn_wrapper,"%s%s_wrap.wrap",output_dir,infile);
sprintf(fn_init,"%s%s_wrap.init",output_dir,infile);
sprintf(title,"%s", fn_header);
// Open up files
if ((f_input = fopen(input_file,"r")) == 0) {
// Okay. File wasn't found right away. Let's see if we can
// extract it from the SWIG library instead.
if ((checkout_file(input_file,input_file)) == -1) {
fprintf(stderr,"Unable to open %s\n", input_file);
SWIG_exit(0);
} else {
// Successfully checked out a file from the library, print a warning and
// continue
checkout = 1;
fprintf(stderr,"%s checked out from the SWIG library.\n",input_file);
if ((f_input = fopen(input_file,"r")) == 0) {
fprintf(stderr,"Unable to open %s\n", input_file);
SWIG_exit(0);
}
}
}
// Add to the include list
add_iname(infilename);
// Initialize the scanner
LEX_in = f_input;
scanner_file(LEX_in);
// printf("fn_header = %s\n", fn_header);
// printf("fn_wrapper = %s\n", fn_wrapper);
// printf("fn_init = %s\n", fn_init);
if((f_header = fopen(fn_header,"w")) == 0) {
fprintf(stderr,"Unable to open %s\n", fn_header);
exit(0);
}
if((f_wrappers = fopen(fn_wrapper,"w")) == 0) {
fprintf(stderr,"Unable to open %s\n",fn_wrapper);
exit(0);
}
if ((f_init = fopen(fn_init,"w")) == 0) {
fprintf(stderr,"Unable to open %s\n",fn_init);
exit(0);
}
// Open up documentation
if (doc_file) {
doc->init(doc_file);
} else {
doc_file = new char[strlen(infile)+strlen(output_dir)+8];
sprintf(doc_file,"%s%s_wrap",output_dir,infile);
doc->init(doc_file);
}
// Set up the typemap for handling new return strings
{
DataType *temp_t = new DataType(T_CHAR);
temp_t->is_pointer++;
if (CPlusPlus)
typemap_register("newfree",typemap_lang,temp_t,"","delete [] $source;\n",0);
else
typemap_register("newfree",typemap_lang,temp_t,"","free($source);\n",0);
delete temp_t;
}
// Define the __cplusplus symbol
if (CPlusPlus)
add_symbol("__cplusplus",0,0);
// Load up the typemap file if given
if (typemap_file) {
if (include_file(typemap_file) == -1) {
fprintf(stderr,"Unable to locate typemap file %s. Aborting.\n", typemap_file);
SWIG_exit(1);
}
}
// If in Objective-C mode. Load in a configuration file
if (ObjC) {
// Add the 'id' object type as a void *
/* DataType *t = new DataType(T_VOID);
t->is_pointer = 1;
t->implicit_ptr = 0;
t->typedef_add("id");
delete t;
*/
}
// Pass control over to the specific language interpreter
lang->parse();
fclose(f_wrappers);
fclose(f_init);
swig_append(fn_wrapper,f_header);
swig_append(fn_init,f_header);
fclose(f_header);
// Print out documentation. Due to tree-like nature of documentation,
// printing out the title prints out everything.
while(doctitle) {
doctitle->output(doc);
doctitle = doctitle->next;
}
doc->close();
// Remove temporary files
remove(fn_wrapper);
remove(fn_init);
// If only producing documentation, remove the wrapper file as well
if (DocOnly)
remove(fn_header);
// Check for undefined types that were used.
if (Verbose)
type_undefined_check();
if (Stats) {
fprintf(stderr,"Wrapped %d functions\n", Stat_func);
fprintf(stderr,"Wrapped %d variables\n", Stat_var);
fprintf(stderr,"Wrapped %d constants\n", Stat_const);
type_undefined_check();
}
if (checkout) {
// File was checked out from the SWIG library. Remove it now
remove(input_file);
}
}
#ifdef MACSWIG
fclose(swig_log);
} catch (SwigException) {
fclose(swig_log);
}
#else
exit(error_count);
#endif
return(error_count);
}
// --------------------------------------------------------------------------
// SWIG_exit()
//
// Fatal parser error. Exit and cleanup
// --------------------------------------------------------------------------
void SWIG_exit(int) {
if (f_wrappers) {
fclose(f_wrappers);
remove(fn_wrapper);
}
if (f_header) {
fclose(f_header);
remove(fn_header);
}
if (f_init) {
fclose(f_init);
remove(fn_init);
}
#ifndef MACSWIG
exit(1);
#else
throw SwigException();
#endif
}
// --------------------------------------------------------------------------
// swig_pragma(char *name, char *value)
//
// Handle pragma directives. Not many supported right now
// --------------------------------------------------------------------------
void swig_pragma(char *name, char *value) {
if (strcmp(name,"make_default") == 0) {
GenerateDefault = 1;
}
if (strcmp(name,"no_default") == 0) {
GenerateDefault = 0;
}
if (strcmp(name,"objc_new") == 0) {
objc_construct = copy_string(value);
}
if (strcmp(name,"objc_delete") == 0) {
objc_destruct = copy_string(value);
}
}
char* getSwigLib() {
char* c;
char* rv;
// Check for SWIG_LIB environment variable
if ((c = getenv("SWIG_LIB")) != (char *) 0) {
rv = c;
} else {
#ifdef SWIG_LIB
rv = SWIG_LIB;
#else
// use executable location
static char path[256];
char* last;
strcpy(path, __argv[0]);
last = strrchr(path, '/');
if (! last) last = strrchr(path, '\\');
if (last)
strcpy(last+1, "swig_lib");
else
strcpy(path, "swig_lib");
rv = path;
#endif
}
printf("Using swig lib at: %s\n", rv);
return rv;
}

View File

@@ -0,0 +1,107 @@
# Modified from automatic creation by Kevin Butler (butler@byu.edu)
# for Microsoft Visual C++ (11/22/96)
#
#######################################################################
# $Header$
# Simplified Wrapper and Interface Generator (SWIG)
#
# Makefile for version 1.1
# Dave Beazley
# March 12, 1997
#
# This makefile is now mostly constructed by ./configure.
#
# $Log$
# Revision 1.1 2002/04/29 19:56:48 RD
# Since I have made several changes to SWIG over the years to accomodate
# special cases and other things in wxPython, and since I plan on making
# several more, I've decided to put the SWIG sources in wxPython's CVS
# instead of relying on maintaining patches. This effectivly becomes a
# fork of an obsolete version of SWIG, :-( but since SWIG 1.3 still
# doesn't have some things I rely on in 1.1, not to mention that my
# custom patches would all have to be redone, I felt that this is the
# easier road to take.
#
# Revision 1.1.1.1 1999/02/28 02:00:52 beazley
# Swig1.1
#
# Revision 1.1 1996/08/12 01:55:02 dmb
# Initial revision
#
#######################################################################
#.KEEP_STATE:
rootdir = ..
!include <..\make_win.in>
########################################################################
# Normally, you shouldn't have to change anything below this point #
########################################################################
LIBOBJS = main.obj scanner.obj symbol.obj include.obj types.obj parms.obj emit.obj newdoc.obj ascii.obj \
html.obj latex.obj cplus.obj lang.obj hash.obj sstring.obj wrapfunc.obj getopt.obj comment.obj typemap.obj naming.obj
LIBSRCS = main.cxx scanner.cxx symbol.cxx include.cxx types.cxx parms.cxx emit.cxx \
newdoc.cxx ascii.cxx html.cxx latex.cxx cplus.cxx lang.cxx hash.cxx \
sstring.cxx wrapfunc.cxx getopt.cxx comment.cxx typemap.cxx naming.cxx
LIBHEADERS = internal.h $(rootdir)/Include/swig.h latex.h ascii.h html.h nodoc.h
LIBNAME = $(rootdir)\libswig.lib
#
# Rules for creation of a .obj file from .cxx
.SUFFIXES: .cxx
.cxx.obj:
$(CC) $(INCFLAGS) $(CFLAGS) -c -o $*.obj $<
all: $(LIBNAME)
$(LIBNAME): parser.obj $(LIBOBJS)
@echo "Building library"
@$(LD) $(LD_FLAGS) -out:$(LIBNAME) $(LIBOBJS) parser.obj
parser.obj: parser.cxx $(LIBHEADERS)
$(CC) $(INCFLAGS) $(CFLAGS) parser.cxx -c -o parser.obj
parser.cxx: $(PARSER)
@echo "Must rebuild the parser with yacc"
parser::
@cp y.tab.c.bison parser.cxx
@cp y.tab.h.bison parser.h
@cp y.tab.h.bison y.tab.h
$(CC) $(CFLAGS) parser.cxx -c -o parser.obj
main.obj: main.cxx
scanner.obj: scanner.cxx
wrapper.obj: wrapper.cxx
include.obj: include.cxx
types.obj: types.cxx
emit.obj: emit.cxx
cplus.obj: cplus.cxx
misc.obj: misc.cxx
hash.obj: hash.cxx
sstring.obj: sstring.cxx
getopt.obj: getopt.cxx
wrapfunc.obj: wrapfunc.cxx
swigmain.obj: swigmain.cxx
symbol.obj: symbol.cxx
parms.obj: parms.cxx
newdoc.obj: newdoc.cxx
lang.obj: lang.cxx
comment.obj: comment.cxx
latex.obj: latex.cxx
ascii.obj: ascii.cxx
html.obj: html.cxx
typemap.obj: typemap.cxx
naming.obj: naming.cxx
clean::
@del *.obj
@del $(LIBNAME)

View File

@@ -0,0 +1,299 @@
/*******************************************************************************
* 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.
*******************************************************************************/
#include "internal.h"
#include <limits.h>
#include <ctype.h>
// --------------------------------------------------------------------------------
// $Header$
//
// naming.cxx
//
// SWIG naming service.
//
// This module provides universal naming services for manufacturing function names.
// All language modules use this so it provides a convenient centralized
// mechanism for producing names.
// --------------------------------------------------------------------------------
// Structure for holding names
struct NamingScheme {
char *format;
int first; // Scoping information
int last; // Scoping information
NamingScheme *next;
NamingScheme(char *n) {
format = copy_string(n);
first = type_id;
last = INT_MAX;
next = 0;
};
};
// Hash table containing naming data
static Hash naming_hash;
// Variable indicating naming scope
static int naming_scope = -1;
//-----------------------------------------------------------------
// make_wrap_name(char *s)
//
// Takes the name at src, and converts it into a syntactically
// valid identifier name. This is a hack to get the wrapper
// generator to support class member functions and other things.
//
// ie. We can define a function name as obj->foo(),
// but we'll need to call the wrapper function something like
// _wrap_obj__foo()
//-----------------------------------------------------------------
void make_wrap_name(char *s) {
char *c1 = s;
int i;
for (i = 0; i < (int) strlen(s); i++, c1++) {
if(!isalnum(*c1)) *c1 = '_';
}
}
// --------------------------------------------------------------------------------
// int name_scope(int scope)
//
// Set the scope variable. This is used to determine what naming scheme to
// use. Returns the current value of the scope.
// --------------------------------------------------------------------------------
int name_scope(int scope) {
int s = naming_scope;
naming_scope = scope;
return s;
}
// --------------------------------------------------------------------------------
// void name_register(char *method, char *format)
//
// Registers a new naming scheme.
// --------------------------------------------------------------------------------
void name_register(char *method, char *format) {
NamingScheme *ns, *nns;
ns = (NamingScheme *) naming_hash.lookup(method);
if (ns) {
naming_hash.remove(method);
}
nns = new NamingScheme(format); // Create a new naming scheme
if (ns) ns->last = type_id;
nns->next = ns;
naming_hash.add(method,nns);
};
// --------------------------------------------------------------------------------
// char *name_getformat(char *method)
//
// Looks up a naming scheme in the hash table. The scope of the name should have
// been set prior to calling this. If not set, we just use the last name entered.
// Returns the format string or NULL if no name has been set.
// --------------------------------------------------------------------------------
static char *name_getformat(char *method) {
NamingScheme *ns;
int scope;
if (naming_scope == -1) scope = type_id;
else scope = naming_scope;
ns = (NamingScheme *) naming_hash.lookup(method);
while (ns) {
if ((ns->first <= scope) && (scope < ns->last))
return ns->format;
ns = ns->next;
}
return 0;
}
// --------------------------------------------------------------------------------
// char *name_wrapper(char *fname, char *prefix, int suppress)
//
// Returns the name of a wrapper function. The following variables are
// available :
//
// %f -> fname
// %p -> prefix
// %l -> language
//
// By default a wrapper function gets the name _wrap_prefixfname.
//
// --------------------------------------------------------------------------------
char *name_wrapper(char *fname, char *prefix, int suppress) {
static String fmt;
char *f;
f = name_getformat("wrapper");
if (!f) {
f = "_wrap_%p%f"; // Default wrapper name
}
fmt = f;
fmt.replace("%f",fname);
fmt.replace("%l",typemap_lang);
fmt.replace("%p",prefix);
if (!suppress)
make_wrap_name(fmt);
return fmt;
}
// --------------------------------------------------------------------------------
// char *name_member(char *fname, char *classname, int suppress)
//
// Returns the name of a method function. The following variables are
// available :
//
// %f -> fname
// %c -> classname
// %l -> language
//
// By default, the name of a method is given as Classname_method.
// --------------------------------------------------------------------------------
char *name_member(char *fname, char *classname, int suppress) {
static String fmt;
char *f;
f = name_getformat("member");
if (!f) {
f = "%c_%f";
}
fmt = f;
fmt.replace("%f",fname);
fmt.replace("%l",typemap_lang);
fmt.replace("%c",classname);
if (!suppress)
make_wrap_name(fmt);
return fmt;
}
// --------------------------------------------------------------------------------
// char *name_get(char *vname, int suppress)
//
// Returns the name of the accessor function used to get a variable.
//
// %v -> variable name
//
// --------------------------------------------------------------------------------
char *name_get(char *vname, int suppress) {
static String fmt;
char *f;
f = name_getformat("get");
if (!f) {
f = "%v_get";
}
fmt = f;
fmt.replace("%v",vname);
if (!suppress)
make_wrap_name(fmt);
return fmt;
}
// --------------------------------------------------------------------------------
// char *name_set(char *vname, int suppress)
//
// Returns the name of the accessor function used to set a variable.
//
// %v -> variable name
// --------------------------------------------------------------------------------
char *name_set(char *vname, int suppress) {
static String fmt;
char *f;
f = name_getformat("set");
if (!f) {
f = "%v_set";
}
fmt = f;
fmt.replace("%v",vname);
if (!suppress)
make_wrap_name(fmt);
return fmt;
}
// --------------------------------------------------------------------------------
// char *name_construct(char *classname, int suppress)
//
// Returns the name of the accessor function used to create an object.
// By default this is "new_classname"
//
// %c -> classname
// %l -> language
//
// --------------------------------------------------------------------------------
char *name_construct(char *classname, int suppress) {
static String fmt;
char *f;
f = name_getformat("construct");
if (!f) {
f = "new_%c";
}
fmt = f;
fmt.replace("%l",typemap_lang);
fmt.replace("%c",classname);
if (!suppress)
make_wrap_name(fmt);
return fmt;
}
// --------------------------------------------------------------------------------
// char *name_destroy(char *classname, int suppress)
//
// Returns the name of the accessor function used to destroy an object.
// By default this is "delete_classname"
//
// %c -> classname
// %l -> language
//
// --------------------------------------------------------------------------------
char *name_destroy(char *classname, int suppress) {
static String fmt;
char *f;
f = name_getformat("destroy");
if (!f) {
f = "delete_%c";
}
fmt = f;
fmt.replace("%l",typemap_lang);
fmt.replace("%c",classname);
if (!suppress)
make_wrap_name(fmt);
return fmt;
}

View File

@@ -0,0 +1,607 @@
/*******************************************************************************
* 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.
*******************************************************************************/
/***********************************************************************
* $Header$
*
* newdoc.cxx
*
* SWIG Documentation system. (2nd attempt)
*
* SWIG organizes documentation as a tree structure where each node is a
* documentation entry (DocEntry) of some kind. To generate documentation,
* we simply traverse the tree and call output methods.
*
* A sample documentation tree looks something like the following :
*
* TITLE ----> SECTION 1 ----> func1
* ----> func2
* ----> func3
* ----> class ---> func1
* ---> func2
* ---> var1
* ----> func4
*
* ----> SECTION 2 ----> func1
* ----> var1
*
* and so on.
*
* This structure makes it possible to organize C++ classes and more
* complicated structures. Hopefully this will provide enough structure
* for later versions of SWIG.
*
*************************************************************************/
#include "internal.h"
#include <ctype.h>
extern char *get_time();
static char *last_name = 0;
DocEntry *DocEntry::dead_entries = 0;
// Utility function for converting a string to upper case
static void str_toupper(char *str) {
char *c;
c = str;
while (*c) {
*c = toupper(*c);
c++;
}
}
// --------------------------------------------------------------------
// DocEntry::~DocEntry
//
// Destroy a documentation entry. Destroys this entry and all of
// its children.
// --------------------------------------------------------------------
DocEntry::~DocEntry() {
DocEntry *de, *de1;
if (name) delete name;
// Now kill all of the children (well, figuratively speaking)
de = child;
while (de) {
de1 = de->next;
delete de;
de = de1;
}
}
// --------------------------------------------------------------------
// void DocEntry::sort_children()
//
// Sort children by name (not height). This function gathers all
// of the children up into an array of pointers. Then we do an
// insertion sort on it and place the children back in order.
// --------------------------------------------------------------------
void DocEntry::sort_children() {
int count = 0;
int i,j;
DocEntry *d;
DocEntry **list;
DocEntry *v;
if (!child) return; // Nothing to sort
d = child;
while (d) {
count++;
d = d->next;
}
// allocate a temporary array for sorting everything
list = new DocEntry *[count+2];
// Now put pointers into list
d = child;
i = 0;
while (d) {
list[i] = d;
d = d->next;
i++;
}
// Do an insertion sort by name
for (i = 1; i < count; i++) {
v = list[i];
j = i;
while((j > 0) && (strcmp(list[j-1]->name,v->name) > 0)) {
list[j] = list[j-1];
j--;
}
list[j] = v;
}
// Now, we're going to reorganize the children in order
list[count] = 0;
child = list[0]; // Our child is the first one in the list
d = child;
for (i = 0; i < count; i++) {
d->next = list[i+1];
d = d->next;
}
delete list;
}
// --------------------------------------------------------------------
// void DocEntry::output()
//
// Output this entry
// --------------------------------------------------------------------
void DocEntry::output(Documentation *) {
fprintf(stderr,"SWIG (internal) : No output method defined for DocEntry.\n");
}
// --------------------------------------------------------------------
// DocEntry::add(DocEntry *de)
//
// Adds a new DocEntry as a sibling. Basically we just walk down the
// linked list and append ourselves to the end. The documentation
// Entry we're adding may, in fact, have siblings too, but this function
// Should still work.
// --------------------------------------------------------------------
void DocEntry::add(DocEntry *de) {
DocEntry *d,*d1;
d = next;
d1 = this;
while (d) {
d1 = d;
d = d->next;
}
d1->next = de;
de->previous = d1; // Set up the previous list member
}
// --------------------------------------------------------------------
// DocEntry::addchild(DocEntry *de)
//
// Adds a new DocEntry as a child. If we're in Ignore mode, the
// documentation entry is still created, but we simply abandon it.
// --------------------------------------------------------------------
void DocEntry::addchild(DocEntry *de) {
if (!IgnoreDoc) {
if (child) child->add(de);
else child = de;
} else {
if (dead_entries) dead_entries->add(de);
else dead_entries = de;
}
}
// -------------------------------------------------------------------
// DocEntry::remove()
//
// Removes a documentation entry from the tree and places it on
// the dead_entries list
// -------------------------------------------------------------------
void DocEntry::remove() {
if (previous) {
if (next)
previous->next = next; // Take out of the linked list
else
previous->next = 0;
} else { // Make sure our parent isn't pointing to us
if (parent)
parent->child = next;
}
previous = 0;
next = 0;
if (!dead_entries) dead_entries = this;
else dead_entries->add(this);
}
// -------------------------------------------------------------------
// void DocEntry::style(char *name, char *value)
//
// Set style parameters of a documentation entry
// -------------------------------------------------------------------
void DocEntry::style(char *pname, char *) {
if (strcmp(pname,"sort") == 0) {
sorted = 1;
} else if (strcmp(pname,"nosort") == 0) {
sorted = 0;
} else if (strcmp(pname,"info") == 0) {
print_info = 1;
} else if (strcmp(pname,"noinfo") == 0) {
print_info = 0;
} else if (strcmp(pname,"pre") == 0) {
format = 0;
} else if (strcmp(pname,"format") == 0) {
format = 1;
}
}
// -------------------------------------------------------------------
// void DocEntry::parse_args(int argc, char **argv)
//
// Take command line options and process them. This really only
// applies to the top-level documentation entry.
// -------------------------------------------------------------------
static char *doc_usage = "\
Documentation Processing : \n\
-Sformat - Reformat comment text\n\
-Sinfo - Print C formatting information (the default)\n\
-Snoinfo - Omit C formatting information.\n\
-Snosort - Print everything in order (the default)\n\
-Spre - Assume comments are pre-formatted (the default)\n\
-Ssort - Sort documentation alphabetically\n\n";
void DocEntry::parse_args(int argc, char **argv) {
int i;
for (i = 1; i < argc; i++) {
if (argv[i]) {
if (strcmp(argv[i],"-Ssort") == 0) {
this->style("sort",0);
mark_arg(i);
} else if (strcmp(argv[i],"-Snosort") == 0) {
this->style("nosort",0);
mark_arg(i);
} else if (strcmp(argv[i],"-Sinfo") == 0) {
this->style("info",0);
mark_arg(i);
} else if (strcmp(argv[i],"-Snoinfo") == 0) {
this->style("noinfo",0);
mark_arg(i);
} else if (strcmp(argv[i],"-Spre") == 0) {
this->style("pre",0);
mark_arg(i);
} else if (strcmp(argv[i],"-Sformat") == 0) {
this->style("format",0);
mark_arg(i);
} else if (strcmp(argv[i],"-help") == 0) {
fputs(doc_usage,stderr);
}
}
}
}
// -------------------------------------------------------------------
// DocTitle::DocTitle(char *title, DocEntry *_parent);
//
// Create a new title documentation entry. The name of the entry
// is the title.
//
// The body text is optional, but may be filled in with a description
// as well.
// -------------------------------------------------------------------
DocTitle::DocTitle(char *title, DocEntry *_parent) {
name = copy_string(title);
str_toupper(name);
parent = _parent;
child = 0;
next = 0;
previous = 0;
usage << title << "\n";
counter = 1;
is_separator = 1;
line_number = ::start_line;
end_line = ::line_number;
file = copy_string(input_file);
if (_parent) {
sorted = _parent->sorted;
format = _parent->format;
print_info = _parent->print_info;
} else {
sorted = SWIGDEFAULT_SORT;
format = SWIGDEFAULT_FORMAT;
print_info = SWIGDEFAULT_INFO;
}
comment_handler->set_entry(this);
if (last_name) delete last_name;
last_name = 0;
}
// --------------------------------------------------------------------
// DocTitle::output(Documentation *d)
//
// Output a title to the Documentation module
// --------------------------------------------------------------------
void DocTitle::output(Documentation *d) {
DocEntry *de;
d->title(this);
if (sorted) {
sort_children();
}
// Now output my children
de = child;
while (de) {
de->output(d);
de = de->next;
}
}
// -------------------------------------------------------------------
// DocSection::DocSection(char *section, DocEntry *_parent);
//
// Create a new documentation section. The name and description is
// set to the name of the section. The text field is optional
// but could contain a more complete description.
//
// The sorted field indicates whether members of this section are
// sorted or not.
// -------------------------------------------------------------------
DocSection::DocSection(char *section, DocEntry *_parent) {
name = copy_string(section);
str_toupper(name);
parent = _parent;
child = 0;
next = 0;
previous = 0;
usage << section;
counter = 1;
is_separator = 1;
if (_parent) _parent->addchild(this);
line_number = ::start_line;
end_line = ::line_number;
file = copy_string(input_file);
if (_parent) {
sorted = _parent->sorted;
format = _parent->format;
print_info = _parent->print_info;
} else {
sorted = SWIGDEFAULT_SORT;
format = SWIGDEFAULT_FORMAT;
print_info = SWIGDEFAULT_INFO;
}
comment_handler->set_entry(this);
if (last_name) delete last_name;
last_name = 0;
}
// --------------------------------------------------------------------
// DocSection::output(Documentation *d)
//
// Output a section to the documentation module
// --------------------------------------------------------------------
void DocSection::output(Documentation *d) {
DocEntry *de;
// Make a new section
d->newsection(this,this->parent->counter++); // Make a new section
// Sort the children if necessary
if (sorted) {
sort_children();
}
// Now output my children
de = child;
while (de) {
de->output(d);
de = de->next;
}
// End this section
d->endsection();
}
// -------------------------------------------------------------------
// DocDecl::DocDecl(char *fname, DocEntry *_parent);
//
// Create documentation for a function declaration.
// -------------------------------------------------------------------
DocDecl::DocDecl(char *fname, DocEntry *_parent) {
name = copy_string(fname);
str_toupper(name);
parent = _parent;
child = 0;
next = 0;
previous = 0;
is_separator = 0;
if (_parent) _parent->addchild(this);
line_number = ::start_line;
end_line = ::line_number;
file = copy_string(input_file);
if (_parent) {
sorted = _parent->sorted;
format = _parent->format;
print_info = _parent->print_info;
} else {
sorted = SWIGDEFAULT_SORT;
format = SWIGDEFAULT_FORMAT;
print_info = SWIGDEFAULT_INFO;
}
comment_handler->set_entry(this);
if (last_name) delete last_name;
last_name = copy_string(name);
}
// --------------------------------------------------------------------
// DocDecl::DocDecl(DocEntry *de, DocEntry *_parent)
//
// Make a new declaration entry, but copy attributes from someone else
// --------------------------------------------------------------------
DocDecl::DocDecl(DocEntry *de, DocEntry *_parent) {
name = copy_string(de->name);
usage = de->usage.get();
cinfo = de->cinfo.get();
text = de->text.get();
line_number = de->line_number;
end_line = de->end_line;
file = copy_string(de->file);
print_info = de->print_info;
format = de->format;
if (_parent) {
_parent->addchild(this);
}
}
// --------------------------------------------------------------------
// DocDecl::output(Documentation *d)
//
// Output a function to the documentation module
// --------------------------------------------------------------------
void DocDecl::output(Documentation *d) {
d->print_decl(this);
}
// -------------------------------------------------------------------
// DocClass::DocClass(char *classname, DocEntry *_parent);
//
// Create a new class section. Classes are created as funny sorts of
// sections.
//
// The sorted field indicates whether members of this section are
// sorted or not.
// -------------------------------------------------------------------
DocClass::DocClass(char *classname, DocEntry *_parent) {
name = copy_string(classname);
str_toupper(name);
parent = _parent;
child = 0;
next = 0;
previous = 0;
usage << classname<< "\n";
counter = 1;
is_separator = 1;
if (_parent) _parent->addchild(this);
line_number = ::start_line;
end_line = ::line_number;
file = copy_string(input_file);
if (_parent) {
sorted = _parent->sorted;
format = _parent->format;
print_info = _parent->print_info;
} else {
sorted = SWIGDEFAULT_SORT;
format = SWIGDEFAULT_FORMAT;
print_info = SWIGDEFAULT_INFO;
}
comment_handler->set_entry(this);
if (last_name) delete last_name;
last_name = copy_string(name);
}
// --------------------------------------------------------------------
// DocClass::output(Documentation *d)
//
// Output a section to the documentation module
// --------------------------------------------------------------------
void DocClass::output(Documentation *d) {
DocEntry *de;
// Make a new section
d->newsection(this,this->parent->counter++); // Make a subsection for this
// Sort the children if necessary
if (sorted) {
sort_children();
}
// Now output my children
de = child;
while (de) {
de->output(d);
de = de->next;
}
// End this section
d->endsection();
// We now check to see if the next thing is a separator. If not, we'll
// emit a separator
if (next) {
if (!next->is_separator)
d->separator();
}
}
// -------------------------------------------------------------------
// DocText::DocText(char *_text, DocEntry *_parent);
//
// Create documentation for a function declaration.
// -------------------------------------------------------------------
DocText::DocText(char *_text, DocEntry *_parent) {
if (!last_name)
name = copy_string(""); // There is no name for text
else
name = copy_string(last_name);
parent = _parent;
child = 0;
next = 0;
previous = 0;
text << _text;
is_separator = 0;
if (_parent) _parent->addchild(this);
if (_parent) {
sorted = _parent->sorted;
format = _parent->format;
print_info = _parent->print_info;
} else {
sorted = SWIGDEFAULT_SORT;
format = SWIGDEFAULT_FORMAT;
print_info = SWIGDEFAULT_INFO;
}
}
// --------------------------------------------------------------------
// DocText::output(Documentation *d)
//
// Output a function to the documentation module
// --------------------------------------------------------------------
void DocText::output(Documentation *d) {
d->print_text(this);
}

View File

@@ -0,0 +1,54 @@
/*******************************************************************************
* 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.
*******************************************************************************/
/***********************************************************************
* $Header$
*
* nodoc.h
*
* A null documentation header. Does nothing.
***********************************************************************/
class NODOC : public Documentation {
private:
public:
NODOC() { };
void parse_args(int, char **) { };
void title(DocEntry *) { };
void newsection(DocEntry *, int) { };
void endsection() { };
void print_decl(DocEntry *) { };
void print_text(DocEntry *) { };
void separator() { };
void init(char *) { };
void close(void) { };
void style(char *, char *) { };
};

View File

@@ -0,0 +1,478 @@
/*******************************************************************************
* 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.
*******************************************************************************/
/* ------------------------------------------------------------------------
$Header$
parms.cxx
This file is used to manage function parameters and parameter lists.
Rewritten (10/27) to solve a bunch of problems with memory management
and proper cleanup of things.
------------------------------------------------------------------------ */
#include "swig.h"
// ------------------------------------------------------------------------
// Parm::Parm(DataType *type, char *n)
//
// Create a new parameter from datatype 'type' and name 'n'.
// Copies will be made of type and n, unless they aren't specified.
// ------------------------------------------------------------------------
Parm::Parm(DataType *type, char *n) {
if (type) {
t = new DataType(type);
} else {
t = 0;
}
name = copy_string(n);
call_type = 0;
defvalue = 0;
ignore = 0;
objc_separator = 0;
}
// ------------------------------------------------------------------------
// Parm::Parm(Parm *p)
//
// Make a copy of a parameter
// ------------------------------------------------------------------------
Parm::Parm(Parm *p) {
if (p->t) t = new DataType(p->t);
name = copy_string(p->name);
call_type = p->call_type;
defvalue = copy_string(p->defvalue);
ignore = p->ignore;
objc_separator = copy_string(p->objc_separator);
}
// ------------------------------------------------------------------------
// Parm::~Parm()
//
// Destroy a parameter
// ------------------------------------------------------------------------
Parm::~Parm() {
if (t) delete t;
if (name) delete name;
if (defvalue) delete defvalue;
if (objc_separator) delete objc_separator;
}
/********************************************************************
class ParmList
These functions are used to manipulate lists of parameters
********************************************************************/
// ------------------------------------------------------------------
// ParmList::ParmList()
//
// Create a new (empty) parameter list
// ------------------------------------------------------------------
ParmList::ParmList() {
nparms = 0;
maxparms = MAXPARMS;
parms = new Parm *[maxparms]; // Create an array of parms
for (int i = 0; i < MAXPARMS; i++)
parms[i] = (Parm *) 0;
}
// ------------------------------------------------------------------
// ParmList::ParmList(ParmList *l)
//
// Make a copy of parameter list
// ------------------------------------------------------------------
ParmList::ParmList(ParmList *l) {
int i;
if (l) {
nparms = l->nparms;
maxparms = l->maxparms;
parms = new Parm *[maxparms];
for (i = 0; i < maxparms; i++) {
if (l->parms[i])
parms[i] = new Parm(l->parms[i]);
else
parms[i] = 0;
}
} else {
nparms = 0;
maxparms = MAXPARMS;
parms = new Parm *[maxparms]; // Create an array of parms
for (i = 0; i < MAXPARMS; i++)
parms[i] = (Parm *) 0;
}
}
// ------------------------------------------------------------------
// ParmList::~ParmList()
//
// Delete a parameter list
// ------------------------------------------------------------------
ParmList::~ParmList() {
for (int i = 0; i < maxparms; i++) {
if (parms[i]) delete parms[i];
}
}
// ------------------------------------------------------------------
// void ParmList::moreparms() (PRIVATE)
//
// Doubles the amount of parameter memory available.
// ------------------------------------------------------------------
void ParmList::moreparms() {
Parm **newparms;
int i;
newparms = new Parm *[maxparms*2];
for (i = 0; i < 2*maxparms; i++)
newparms[i] = (Parm *) 0;
for (i = 0; i < maxparms; i++) {
newparms[i] = parms[i];
}
maxparms = 2*maxparms;
delete parms;
parms = newparms;
}
// ------------------------------------------------------------------
// void ParmList::append(Parm *p)
//
// Add a new parameter to the end of a parameter list
// ------------------------------------------------------------------
void ParmList::append(Parm *p) {
if (nparms == maxparms) moreparms();
// Add parm onto the end
parms[nparms] = new Parm(p);
nparms++;
}
// ------------------------------------------------------------------
// void ParmList::insert(Parm *p, int pos)
//
// Inserts a parameter at position pos. Parameters are inserted
// *before* any existing parameter at position pos.
// ------------------------------------------------------------------
void ParmList::insert(Parm *p, int pos) {
// If pos is out of range, we'd better fix it
if (pos < 0) pos = 0;
if (pos > nparms) pos = nparms;
// If insertion is going to need more memory, take care of that now
if (nparms >= maxparms) moreparms();
// Now shift all of the existing parms to the right
for (int i = nparms; i > pos; i--) {
parms[i] = parms[i-1];
}
// Set new parameter
parms[pos] = new Parm(p);
nparms++;
}
// ------------------------------------------------------------------
// void ParmList::del(int pos)
//
// Deletes the parameter at position pos.
// ------------------------------------------------------------------
void ParmList::del(int pos) {
if (nparms <= 0) return;
if (pos < 0) pos = 0;
if (pos >= nparms) pos = nparms-1;
// Delete the parameter (if it exists)
if (parms[pos]) delete parms[pos];
// Now slide all of the parameters to the left
for (int i = pos; i < nparms-1; i++) {
parms[i] = parms[i+1];
}
nparms--;
}
// ------------------------------------------------------------------
// Parm *ParmList::get(int pos)
//
// Gets the parameter at location pos. Returns 0 if invalid
// position.
// ------------------------------------------------------------------
Parm *ParmList::get(int pos) {
if ((pos < 0) || (pos >= nparms)) return 0;
return parms[pos];
}
// ------------------------------------------------------------------
// int ParmList::numopt()
//
// Gets the number of optional arguments.
// ------------------------------------------------------------------
int ParmList::numopt() {
int n = 0;
int state = 0;
for (int i = 0; i < nparms; i++) {
if (parms[i]->defvalue) {
n++;
state = 1;
} else if (typemap_check("default",typemap_lang,parms[i]->t,parms[i]->name)) {
n++;
state = 1;
} else if (typemap_check("ignore",typemap_lang,parms[i]->t,parms[i]->name)) {
n++;
} else if (typemap_check("build",typemap_lang,parms[i]->t,parms[i]->name)) {
n++;
} else {
if (state) {
fprintf(stderr,"%s : Line %d. Argument %d must have a default value!\n", input_file,line_number,i+1);
}
}
}
return n;
}
// ------------------------------------------------------------------
// int ParmList::numarg()
//
// Gets the number of arguments
// ------------------------------------------------------------------
int ParmList::numarg() {
int n = 0;
for (int i = 0; i < nparms; i++) {
if (!parms[i]->ignore)
n++;
}
return n;
}
// ------------------------------------------------------------------
// Parm &ParmList::operator[](int n)
//
// Returns parameter n in the parameter list. May generate
// an error if that parameter is out of range.
// ------------------------------------------------------------------
Parm &ParmList::operator[](int n) {
if ((n < 0) || (n >= nparms)) {
fprintf(stderr,"ParmList : Fatal error. subscript out of range in ParmList.operator[]\n");
SWIG_exit(1);
}
return *parms[n];
}
// ---------------------------------------------------------------------
// Parm * ParmList::get_first()
//
// Returns the first item on a parameter list.
// ---------------------------------------------------------------------
Parm *ParmList::get_first() {
current_parm = 0;
if (nparms > 0) return parms[current_parm++];
else return (Parm *) 0;
}
// ----------------------------------------------------------------------
// Parm *ParmList::get_next()
//
// Returns the next item on the parameter list.
// ----------------------------------------------------------------------
Parm * ParmList::get_next() {
if (current_parm >= nparms) return 0;
else return parms[current_parm++];
}
// ---------------------------------------------------------------------
// void ParmList::print_types(FILE *f)
//
// Prints a comma separated list of all of the parameter types.
// This is for generating valid C prototypes. Has to do some
// manipulation of pointer types depending on how the call_type
// variable has been set.
// ----------------------------------------------------------------------
void ParmList::print_types(FILE *f) {
int is_pointer;
int pn;
pn = 0;
while(pn < nparms) {
is_pointer = parms[pn]->t->is_pointer;
if (parms[pn]->t->is_reference) {
if (parms[pn]->t->is_pointer) {
parms[pn]->t->is_pointer--;
fprintf(f,"%s&", parms[pn]->t->print_real());
parms[pn]->t->is_pointer++;
} else {
fprintf(f,"%s&", parms[pn]->t->print_real());
}
} else {
if (parms[pn]->call_type & CALL_VALUE) parms[pn]->t->is_pointer++;
if (parms[pn]->call_type & CALL_REFERENCE) parms[pn]->t->is_pointer--;
fprintf(f,"%s", parms[pn]->t->print_real());
parms[pn]->t->is_pointer = is_pointer;
}
pn++;
if (pn < nparms)
fprintf(f,",");
}
}
// ---------------------------------------------------------------------
// void ParmList::print_types(String &f)
//
// Generates a comma separated list of function types. Is used in
// C++ code generation when generating hash keys and for function overloading.
// ----------------------------------------------------------------------
void ParmList::print_types(String &f) {
int is_pointer;
int pn;
pn = 0;
while(pn < nparms) {
is_pointer = parms[pn]->t->is_pointer;
if (parms[pn]->t->is_reference) {
if (parms[pn]->t->is_pointer) {
parms[pn]->t->is_pointer--;
f << parms[pn]->t->print_real() << "&";
parms[pn]->t->is_pointer++;
} else {
f << parms[pn]->t->print_real() << "&";
}
} else {
if (parms[pn]->call_type & CALL_VALUE) parms[pn]->t->is_pointer++;
if (parms[pn]->call_type & CALL_REFERENCE) parms[pn]->t->is_pointer--;
f << parms[pn]->t->print_real();
parms[pn]->t->is_pointer = is_pointer;
}
pn++;
if (pn < nparms)
f << ",";
}
}
// ---------------------------------------------------------------------
// void ParmList::print_args(FILE *f)
//
// Prints a comma separated list of all of the parameter arguments.
// ----------------------------------------------------------------------
void ParmList::print_args(FILE *f) {
int is_pointer;
int pn;
pn = 0;
while(pn < nparms) {
is_pointer = parms[pn]->t->is_pointer;
if (parms[pn]->t->is_reference) {
if (parms[pn]->t->is_pointer) {
parms[pn]->t->is_pointer--;
fprintf(f,"%s&", parms[pn]->t->print_full());
parms[pn]->t->is_pointer++;
} else {
fprintf(f,"%s&", parms[pn]->t->print_full());
}
} else {
if (parms[pn]->call_type & CALL_VALUE) parms[pn]->t->is_pointer++;
if (parms[pn]->call_type & CALL_REFERENCE) parms[pn]->t->is_pointer--;
fprintf(f,"%s", parms[pn]->t->print_full());
parms[pn]->t->is_pointer = is_pointer;
}
fprintf(f,"%s",parms[pn]->name);
pn++;
if (pn < nparms)
fprintf(f,",");
}
}
// -------------------------------------------------------------------
// int check_defined()
//
// Checks to see if all of the datatypes are defined.
// -------------------------------------------------------------------
int ParmList::check_defined() {
int a = 0;
int i;
for (i = 0; i < nparms; i++) {
if (parms[i]) {
a+=parms[i]->t->check_defined();
}
}
if (a) return 1;
else return 0;
}
// -------------------------------------------------------------------
// void ParmList::sub_parmnames(String &s)
//
// Given a string, this function substitutes all of the parameter
// names with their internal representation. Used in very special
// kinds of typemaps.
// -------------------------------------------------------------------
void ParmList::sub_parmnames(String &s) {
Parm *p;
extern char *emit_local(int i);
for (int i = 0; i < nparms; i++) {
p = get(i);
if (strlen(p->name) > 0) {
s.replaceid(p->name, emit_local(i));
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,149 @@
typedef union {
char *id;
struct Declaration {
char *id;
int is_pointer;
int is_reference;
} decl;
struct InitList {
char **names;
int count;
} ilist;
struct DocList {
char **names;
char **values;
int count;
} dlist;
struct Define {
char *id;
int type;
} dtype;
DataType *type;
Parm *p;
TMParm *tmparm;
ParmList *pl;
int ivalue;
} YYSTYPE;
#define ID 258
#define HBLOCK 259
#define WRAPPER 260
#define POUND 261
#define STRING 262
#define NUM_INT 263
#define NUM_FLOAT 264
#define CHARCONST 265
#define NUM_UNSIGNED 266
#define NUM_LONG 267
#define NUM_ULONG 268
#define TYPEDEF 269
#define TYPE_INT 270
#define TYPE_UNSIGNED 271
#define TYPE_SHORT 272
#define TYPE_LONG 273
#define TYPE_FLOAT 274
#define TYPE_DOUBLE 275
#define TYPE_CHAR 276
#define TYPE_VOID 277
#define TYPE_SIGNED 278
#define TYPE_BOOL 279
#define TYPE_TYPEDEF 280
#define LPAREN 281
#define RPAREN 282
#define COMMA 283
#define SEMI 284
#define EXTERN 285
#define INIT 286
#define LBRACE 287
#define RBRACE 288
#define DEFINE 289
#define PERIOD 290
#define CONST 291
#define STRUCT 292
#define UNION 293
#define EQUAL 294
#define SIZEOF 295
#define MODULE 296
#define LBRACKET 297
#define RBRACKET 298
#define WEXTERN 299
#define ILLEGAL 300
#define READONLY 301
#define READWRITE 302
#define NAME 303
#define RENAME 304
#define INCLUDE 305
#define CHECKOUT 306
#define ADDMETHODS 307
#define PRAGMA 308
#define CVALUE 309
#define COUT 310
#define ENUM 311
#define ENDDEF 312
#define MACRO 313
#define CLASS 314
#define PRIVATE 315
#define PUBLIC 316
#define PROTECTED 317
#define COLON 318
#define STATIC 319
#define VIRTUAL 320
#define FRIEND 321
#define OPERATOR 322
#define THROW 323
#define TEMPLATE 324
#define NATIVE 325
#define INLINE 326
#define IFDEF 327
#define IFNDEF 328
#define ENDIF 329
#define ELSE 330
#define UNDEF 331
#define IF 332
#define DEFINED 333
#define ELIF 334
#define RAW_MODE 335
#define ALPHA_MODE 336
#define TEXT 337
#define DOC_DISABLE 338
#define DOC_ENABLE 339
#define STYLE 340
#define LOCALSTYLE 341
#define TYPEMAP 342
#define EXCEPT 343
#define IMPORT 344
#define ECHO 345
#define NEW 346
#define APPLY 347
#define CLEAR 348
#define DOCONLY 349
#define TITLE 350
#define SECTION 351
#define SUBSECTION 352
#define SUBSUBSECTION 353
#define LESSTHAN 354
#define GREATERTHAN 355
#define USERDIRECTIVE 356
#define OC_INTERFACE 357
#define OC_END 358
#define OC_PUBLIC 359
#define OC_PRIVATE 360
#define OC_PROTECTED 361
#define OC_CLASS 362
#define OC_IMPLEMENT 363
#define OC_PROTOCOL 364
#define OR 365
#define XOR 366
#define AND 367
#define LSHIFT 368
#define RSHIFT 369
#define PLUS 370
#define MINUS 371
#define STAR 372
#define SLASH 373
#define UMINUS 374
#define NOT 375
#define LNOT 376
#define DCOLON 377
extern YYSTYPE yylval;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,587 @@
/*******************************************************************************
* 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.
*******************************************************************************/
#include "internal.h"
#include <ctype.h>
//-----------------------------------------------------------------------
// char *copy_string(char *str)
//
// Makes a copy of string str. Returns a pointer to it.
//-----------------------------------------------------------------------
char *copy_string(char *str) {
char *res = 0;
if (str) {
res = new char[strlen(str)+1];
strcpy(res,str);
}
return res;
}
//-----------------------------------------------------------------------
// void format_string(char *str)
//
// Replace all of the escape sequences in the string str. It is
// assumed that the new string is smaller than the original!
//-----------------------------------------------------------------------
void format_string(char *str) {
char *newstr, *c,*c1;
int state;
if (!str) return;
newstr = copy_string(str);
c = newstr;
c1 = str;
state = 0;
while (*c) {
switch(state) {
case 0:
if (*c == '\\')
state = 1;
else {
*(c1++) = *c;
state = 0;
}
break;
case 1:
// We're in a simple escape sequence figure out what to do
switch(*c) {
case 'n':
*(c1++) = '\n';
break;
case 'f':
*(c1++) = '\f';
break;
case 'r':
*(c1++) = '\r';
break;
case 't':
*(c1++) = '\t';
break;
case '\\':
*(c1++) = '\\';
break;
case '\"':
*(c1++) = '\"';
break;
case '\'':
*(c1++) = '\'';
break;
default:
*(c1++) = '\\';
*(c1++) = *c;
}
state = 0;
break;
default:
*(c1++) = *c;
state = 0;
}
c++;
}
*c1 = 0;
delete newstr;
}
// ---------------------------------------------------------------------------
// $Header$
// sstring.cxx
//
// SWIG String class.
// This class is used to construct long strings when writing
// wrapper functions. It also "mimicks" the C++ streams I/O
// library for creating strings. For example :
//
// str << "hi there" << 3 << "\n";
//
// Will append the given strings to str.
//
// The idea here is to provide a mechanism for writing wrapper
// functions as strings before writing them out to a file.
//
// ---------------------------------------------------------------------------
#define INIT_MAXSIZE 64
// ---------------------------------------------------------------
// Pools. This is a list of available strings for memory allocation
// and deletion.
// ---------------------------------------------------------------
struct StrMem {
char *str;
int len;
};
#define POOLSIZE 100
static StrMem pool[POOLSIZE];
static int pool_index = 0;
// Returns an item from the pool that can accomodate len
static char *get_pool(int len, int &newlen) {
int i,j;
char *nc;
if (pool_index < 1) {
newlen = len;
return new char[len];
}
i = pool_index-1;
j = 0;
while(i >= 0) {
if ((pool[i].len >= len) && (pool[i].len <= 4*len)) {
nc = pool[i].str;
newlen = pool[i].len;
pool[i].str = pool[pool_index-1].str;
pool[i].len = pool[pool_index-1].len;
pool_index--;
return nc;
}
j++;
i--;
}
newlen = len;
return new char[len];
}
// Puts an item onto the pool
static void put_pool(char *str, int len) {
if (len < INIT_MAXSIZE) {
delete [] str;
return;
}
if (pool_index == POOLSIZE) {
delete [] pool[pool_index-1].str;
pool_index--;
}
pool[pool_index].str = str;
pool[pool_index].len = len;
if (pool_index != POOLSIZE)
pool_index++;
}
// ---------------------------------------------------------------
// String::String()
//
// Create a new string with nothing in it
// ---------------------------------------------------------------
String::String() {
maxsize = INIT_MAXSIZE;
str = get_pool(maxsize,maxsize); // May return a pool that is larger
str[0] = 0;
len = 0;
}
// ---------------------------------------------------------------
// String::String(const char *s)
//
// Create a new string copied from a normal C-style string
// ---------------------------------------------------------------
String::String(const char *s) {
int max = INIT_MAXSIZE;
int l = 0;
if (s) {
l = (int) strlen(s);
if ((l+1) > max) max = l+1;
}
str = get_pool(max,maxsize);
if (s) {
strcpy(str,s);
len = l;
} else {
str[0] = 0;
len = 0;
}
}
// ---------------------------------------------------------------
// String::~String(const char *s)
//
// Destroy a string
// ---------------------------------------------------------------
String::~String() {
put_pool(str,maxsize);
}
// ---------------------------------------------------------------
// String::add(const char *newstr)
//
// Concatenate newstr onto the current string
// ---------------------------------------------------------------
void String::add(const char *newstr) {
int newlen;
char *nstr = 0;
int newmaxsize;
int l;
l = (int) strlen(newstr);
newlen = len+l + 1;
if (newlen >= maxsize-1) {
newmaxsize = 2*maxsize;
if (newlen >= newmaxsize -1) newmaxsize = newlen + 1;
nstr = get_pool(newmaxsize,newmaxsize);
strcpy(nstr,str);
put_pool(str,maxsize);
maxsize = newmaxsize;
str = nstr;
}
strcpy(str+len,newstr);
len += l;
}
// ---------------------------------------------------------------
// String::add(char)
//
// Adds a single character to the current string
// ---------------------------------------------------------------
void String::add(char nc) {
int newlen;
char *nstr = 0;
int newmaxsize;
newlen = len+ 1;
if (newlen >= maxsize-1) {
newmaxsize = 2*maxsize;
if (newlen >= newmaxsize -1) newmaxsize = newlen + 1;
nstr = get_pool(newmaxsize,newmaxsize);
strcpy(nstr,str);
put_pool(str,maxsize);
maxsize = newmaxsize;
str = nstr;
}
str[len++] = nc;
str[len] = 0;
}
// -----------------------------------------------------------------
// String::insert(const char *newstr)
//
// Inserts a string into the front of a string. (Primarily used
// for documentation generation)
// -----------------------------------------------------------------
void String::insert(const char *newstr) {
int newlen;
char *nstr = 0;
int newmaxsize;
int i,l;
l = strlen(newstr);
newlen = len + l + 1;
if (newlen >= maxsize-1) {
newmaxsize = 2*maxsize;
if (newlen >= newmaxsize -1) newmaxsize = newlen + 1;
nstr = get_pool(newmaxsize,newmaxsize);
strcpy(nstr,str);
put_pool(str,maxsize);
maxsize = newmaxsize;
str = nstr;
}
/* Shift all of the characters over */
for (i = len -1; i >= 0; i--) {
str[i+l] = str[i];
}
/* Now insert the new string */
strncpy(str,newstr,l);
len += l;
str[len] = 0;
}
// -----------------------------------------------------------------
// char *String::get()
//
// Get the current value of the string
// -----------------------------------------------------------------
char *String::get() const {
return str;
}
// -----------------------------------------------------------------
// String &operator<<(...)
//
// Shorthand for appending to the end of a string
// -----------------------------------------------------------------
String &operator<<(String &t,const char *s) {
t.add(s);
return t;
}
String &operator<<(String &t,const char s) {
t.add(s);
return t;
}
String &operator<<(String &t,const int a) {
char temp[64];
sprintf(temp,"%d",a);
t.add(temp);
return t;
}
String &operator<<(String &t, String &s) {
t.add(s.get());
return t;
}
String &String::operator=(const char *s) {
int newlen;
if (s) {
newlen = strlen(s);
if ((newlen >= maxsize) && (str)) {
put_pool(str,maxsize);
str = get_pool(newlen+1,maxsize);
maxsize = newlen+1;
}
strcpy(str,s);
len = newlen;
} else {
str[0] = 0;
len = 0;
}
return *this;
}
// -----------------------------------------------------------------
// String &operator>>(...)
//
// Shorthand for inserting into the beginning of a string
// -----------------------------------------------------------------
String &operator>>(const char *s, String &t) {
t.insert(s);
return t;
}
String &operator>>(String &s, String &t) {
t.insert(s.get());
return t;
}
// -----------------------------------------------------------------
// void String::untabify()
//
// Expand all tabs into spaces. This is useful for producing
// documentation and other things.
// -----------------------------------------------------------------
void String::untabify() {
char *s;
char *c;
int pos;
int i;
int oldmaxsize;
// Copy the current string representation
s = str;
oldmaxsize = maxsize;
// Reset the internal state of this string
len = 0;
str = get_pool(maxsize,maxsize);
str[0]= 0;
// Now walk down the old string and expand tabs. Tabs are usually place
// every 8 characters.
pos = 0;
c = s;
while (*c) {
if (*c == '\n') {
pos = -1;
}
if (*c == '\t') {
// Expand the character
for (i = 0; i < (8 - (pos % 8)); i++) {
this->add(' ');
}
pos+=(8-(pos % 8));
} else {
this->add(*c);
pos++;
}
c++;
}
// Blow away the old string
put_pool(s,oldmaxsize);
}
// -----------------------------------------------------------------
// void String::replace(const char *token, const char *rep)
//
// Search for tokens in a string and replace them with rep.
// This probably isn't the fastest implementation, but fortunately
// SWIG rarely calls this function.
// -----------------------------------------------------------------
void String::replace(const char *token, const char *rep) {
char *s, *c, *t;
int oldmaxsize = maxsize;
// Copy the current string representation
s = str;
// Now walk down the old string and search for tokens
c = s;
t = strstr(c,token);
if (t) {
len = 0;
str = get_pool(maxsize,maxsize);
while (t) {
// Found a token in string s
// Dump characters into our string
char temp;
temp = *t;
*t = 0;
this->add(c);
c = t;
*t = temp;
// Now dump the replacement string into place
this->add(rep);
// Jump over the token
c+=strlen(token);
t = strstr(c,token);
}
// Attach rest of the string
if (*c)
this->add(c);
put_pool(s,oldmaxsize);
}
}
// -----------------------------------------------------------------
// void String::replaceid(char *token, char *rep)
//
// Searches for valid identifiers matching token and replaces
// them with rep. Unlike replace() tokens must be a valid C
// identifier (surrounded by whitespace).
// -----------------------------------------------------------------
void String::replaceid(const char *token, const char *rep) {
char *s, *c, *t;
int whitespace, tokenlen;
int oldmaxsize = maxsize;
// Copy the current string representation
s = str;
// Reset the internal state of this string
tokenlen = strlen(token);
// Now walk down the old string and search for tokens
c = s;
t = strstr(c,token);
if (t) {
len = 0;
str = get_pool(maxsize,maxsize);
while (t) {
// Found a token in string s
// Dump characters into our string
whitespace = 1;
while (c != t) {
this->add(*c);
if (!(isalpha(*c) || (*c == '_') || (*c == '$'))) whitespace = 1;
else whitespace = 0;
c++;
}
if (whitespace) {
// Check to see if there is whitespace afterwards
if ((!c[tokenlen]) || (!(isalnum(c[tokenlen]) || (c[tokenlen] == '_') || (c[tokenlen] == '$')))) {
this->add(rep);
} else {
this->add(token);
}
c+=tokenlen;
} else {
this->add(*c);
c++;
}
t = strstr(c,token);
}
// Attach rest of the string
if (*c)
this->add(c);
// Delete the old string
put_pool(s,oldmaxsize);
}
}
// -----------------------------------------------------------------
// void String::strip()
//
// Intelligently strips whitespace from a string. Will not strip
// whitespace if it is between two characters that are part of a
// legal C identifier. For example 'unsigned int'.
// -----------------------------------------------------------------
void String::strip() {
char *s = str; // Old pointer value
char *c, lastchar = 0;
int whitespace = 0;
int oldmaxsize = maxsize;
str = get_pool(maxsize,maxsize); // Get a new string.
len = 0;
c = s;
while(*c) {
if (!isspace(*c)) {
// See if this character doesn't violate our whitespace rules
if (whitespace) {
if (isalnum(lastchar) || (lastchar == '_') || (lastchar == '$')) {
if (isalnum(*c) || (*c == '_') || (*c == '$'))
this->add(' ');
}
}
this->add(*c);
lastchar = *c;
whitespace = 0;
} else {
whitespace = 1;
}
c++;
}
put_pool(s,oldmaxsize);
}

View File

@@ -0,0 +1,196 @@
/*******************************************************************************
* 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.
*******************************************************************************/
#include "internal.h"
/*******************************************************************************
* $Header$
*
* File : symbol.cxx
*
* Symbol table management.
*
*******************************************************************************/
// -----------------------------------------------------------------------------
// Symbol object
// -----------------------------------------------------------------------------
struct Symbol {
~Symbol() {
if (name) delete name;
if (type) delete type;
if (value) delete value;
}
char *name;
DataType *type; // Optional datatype
char *value; // Optional value (for constant expressions)
};
static Hash SymHash; // SWIG Symbol table
// -----------------------------------------------------------------------------
// int add_symbol(char *name, DataType *type, char *value)
//
// Adds a symbol to the symbol table. Returns -1 if symbol is already in the
// table.
//
// Inputs :
// name = Symbol name
// type = Datatype (for constants). Optional.
// value = Value string. Optional.
//
// Output : 0 on success, -1 if symbol already exists.
//
// Side Effects : None
// -----------------------------------------------------------------------------
int add_symbol(char *name, DataType *type, char *value) {
Symbol *s;
int ret;
s = new Symbol;
s->name = copy_string(name);
if (type)
s->type = new DataType(type);
else s->type = (DataType *) 0;
if (value)
s->value = copy_string(value);
else s->value = (char *) 0;
// Add this to the symbol table
ret = SymHash.add(s->name, s);
if (ret == -1) {
delete s;
}
return ret;
}
// -----------------------------------------------------------------------------
// int lookup_symbol(char *name)
//
// Checks to see if a symbol is in the symbol table.
//
// Inputs : name = Symbol name
//
// Output : 0 if not found, 1 if found.
//
// Side Effects : None
// -----------------------------------------------------------------------------
int lookup_symbol(char *name) {
Symbol *s;
s = (Symbol *) SymHash.lookup(name);
if (s) return 1;
else return 0;
}
// -----------------------------------------------------------------------------
// DataType *lookup_symtype(char *name)
//
// Returns the datatype of a symbol or NULL if not found.
//
// Inputs : name = Symbol name
//
// Output : Datatype of symbol, NULL if not found.
//
// Side Effects : None
// -----------------------------------------------------------------------------
DataType *lookup_symtype(char *name) {
Symbol *s;
s = (Symbol *) SymHash.lookup(name);
if (s) return s->type;
else return (DataType *) 0;
}
// -----------------------------------------------------------------------------
// char *lookup_symvalue(char *name)
//
// Returns the value associate with a symbol.
//
// Inputs : name = Symbol name
//
// Output : Symbol value (or NULL if not present).
//
// Side Effects : None
// -----------------------------------------------------------------------------
char *lookup_symvalue(char *name) {
Symbol *s;
s = (Symbol *) SymHash.lookup(name);
if (s) return s->value;
else return (char *) 0;
}
// -----------------------------------------------------------------------------
// int update_symbol(char *name, DataType *type, char *value)
//
// Updates a symbol (or create it) in the hash table.
//
// Inputs :
// name = Name of symbol
// type = Datatype of symbol (optional)
// value = Symbol value (optional)
//
// Output : 0
//
// Side Effects : None
// -----------------------------------------------------------------------------
int update_symbol(char *name, DataType *type, char *value) {
Symbol *s;
s = (Symbol *) SymHash.lookup(name);
if (s) {
if (s->type) delete s->type;
if (s->value) delete s->value;
if (type)
s->type = new DataType(type);
else
s->type = (DataType *) 0;
if (value)
s->value = copy_string(value);
else
s->value = (char *) 0;
return 0;
} else {
return add_symbol(name, type, value);
}
}
// -----------------------------------------------------------------------------
// void remove_symbol(char *name)
//
// Removes a symbol from the symbol table.
//
// Inputs : name = Symbol name.
//
// Output : None
//
// Side Effects : None
// -----------------------------------------------------------------------------
void remove_symbol(char *name) {
SymHash.remove(name);
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,164 @@
/*******************************************************************************
* 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.
*******************************************************************************/
// ------------------------------------------------------------------
// wrapfunc.cxx
//
// Created : June 22, 1996
// Dave Beazley
//
// This file defines a class for writing wrappers. Instead of worrying
// about I/O problems, this wrapper class can be used to write functions
// out of order.
//
// Defines 3 string objects.
// def - Wrapper function definition (function name and arguments)
// locals - Local variable definitions
// code - The actual wrapper function code
//
//-------------------------------------------------------------------
#include "internal.h"
#include <ctype.h>
// -------------------------------------------------------------------
// Print out a wrapper function.
//
// -------------------------------------------------------------------
void WrapperFunction::print(FILE *f) {
fprintf(f,"%s\n",def.get());
fprintf(f,"%s\n",locals.get());
fprintf(f,"%s\n",code.get());
}
// -------------------------------------------------------------------
// Print out a wrapper function.
//
// -------------------------------------------------------------------
void WrapperFunction::print(String &f) {
f << def << "\n"
<< locals << "\n"
<< code << "\n";
}
// -------------------------------------------------------------------
// Safely add a local variable.
//
// Maintains a hash table to prevent double adding.
// -------------------------------------------------------------------
void WrapperFunction::add_local(char *type, char *name, char *defarg) {
char *stored_type;
char *new_type;
char temp[256],*c,*t;
new_type = new char[strlen(type)+1];
strcpy(new_type,type);
// Figure out what the name of this variable is
c = name;
t = temp;
while ((isalnum(*c) || (*c == '_') || (*c == '$')) && (*c)) {
*(t++) = *c;
c++;
}
*t = 0;
if (h.add(temp,new_type,WrapperFunction::del_type) == -1) {
// Check to see if a type mismatch has occurred
stored_type = (char *) h.lookup(temp);
if (strcmp(type,stored_type) != 0)
fprintf(stderr,"Error. Type %s conflicts with previously declared type of %s\n",
type, stored_type);
return;
}
// Successful, write some wrapper code
if (!defarg)
locals << tab4 << type << " " << name << ";\n";
else
locals << tab4 << type << " " << name << " = " << defarg << ";\n";
}
// -------------------------------------------------------------------
// char *WrapperFunction::new_local(char *type, char *name, char *defarg) {
//
// A safe way to add a new local variable. type and name are used as
// a starting point, but a new local variable will be created if these
// are already in use.
// -------------------------------------------------------------------
char *WrapperFunction::new_local(char *type, char *name, char *defarg) {
char *new_type;
static String new_name;
char *c;
new_type = new char[strlen(type)+1];
strcpy(new_type,type);
new_name = "";
c = name;
for (c = name; ((isalnum(*c) || (*c == '_') || (*c == '$')) && (*c)); c++)
new_name << *c;
// Try to add a new local variable
if (h.add(new_name,new_type,WrapperFunction::del_type) == -1) {
// Local variable already exists, try to generate a new name
int i = 0;
new_name = "";
// This is a little funky. We copy characters until we reach a nonvalid
// identifier symbol, add a number, then append the rest. This is
// needed to properly handle arrays.
c = name;
for (c = name; ((isalnum(*c) || (*c == '_') || (*c == '$')) && (*c)); c++)
new_name << *c;
new_name << i;
while (h.add(new_name,new_type,WrapperFunction::del_type) == -1) {
i++;
c = name;
new_name = "";
for (c = name; ((isalnum(*c) || (*c == '_') || (*c == '$')) && (*c)); c++)
new_name << *c;
new_name << i;
}
}
new_name << c;
// Successful, write some wrapper code
if (!defarg)
locals << tab4 << type << " " << new_name << ";\n";
else
locals << tab4 << type << " " << new_name << " = " << defarg << ";\n";
// Need to strip off the array symbols now
c = new_name.get();
while ((isalnum(*c) || (*c == '_') || (*c == '$')) && (*c))
c++;
*c = 0;
return new_name;
}
// ------------------------------------------------------------------
// static WrapperFunction::del_type(void *obj)
//
// Callback function used when cleaning up the hash table.
// ------------------------------------------------------------------
void WrapperFunction::del_type(void *obj) {
delete (char *) obj;
}

View File

@@ -0,0 +1,445 @@
dnl Process this file with autoconf to produce a configure script.
AC_INIT(Include/swig.h)
AC_PREREQ(2.0)
# Set name for machine-dependent library files
AC_SUBST(MACHDEP)
AC_MSG_CHECKING(MACHDEP)
if test -z "$MACHDEP"
then
if test -f /usr/lib/NextStep/software_version; then
set X `hostinfo | grep 'NeXT Mach.*:' | \
sed -e 's/://' -e 's/\./_/'` && \
ac_sys_system=next && ac_sys_release=$4
MACHDEP="$ac_sys_system$ac_sys_release$ac_sys_cpu"
else
ac_sys_system=`uname -s`
if test "$ac_sys_system" = "AIX" ; then
ac_sys_release=`uname -v`
else
ac_sys_release=`uname -r`
fi
ac_md_system=`echo $ac_sys_system |
tr -d '[/ ]' | tr '[[A-Z]]' '[[a-z]]'`
ac_md_release=`echo $ac_sys_release |
tr -d '[/ ]' | sed 's/\..*//'`
MACHDEP="$ac_md_system$ac_md_release"
fi
case MACHDEP in
'') MACHDEP=unknown;;
esac
fi
AC_MSG_RESULT($MACHDEP)
AC_LANG_CPLUSPLUS
dnl Checks for programs.
AC_PROG_CXX
AC_PROG_CC
AC_PROG_RANLIB
AC_SUBST(AR)
AC_CHECK_PROGS(AR, ar aal, ar)
dnl Checks for header files.
AC_HEADER_STDC
dnl Checks for library functions.
AC_FUNC_ALLOCA
AC_ARG_WITH(lang,[ --with-lang=LANG Set SWIG target language (TCL,TCL8,PYTHON,PERL5,PERL4,GUILE)],[
AC_DEFINE_UNQUOTED(SWIG_LANG,$withval)], [AC_DEFINE(SWIG_LANG,TCL)])
AC_ARG_WITH(doc,[ --with-doc=DOC Set SWIG target documentation method (ASCII,LATEX,HTML,NODOC)], [
AC_DEFINE_UNQUOTED(SWIG_DOC,$withval)], [AC_DEFINE(SWIG_DOC,ASCII)])
AC_ARG_WITH(yacc,[ --without-yacc Try to compile without yacc/bison], [
YACC="cp parser.cxx.no y.tab.c; cp parser.h.no y.tab.h"
AC_SUBST(YACC)
YACCFLAGS=""
AC_SUBST(YACCFLAGS)
], [ AC_PROG_YACC
YACCFLAGS="-d parser.y"
AC_SUBST(YACCFLAGS) ])
# This borrowed from the Python configuration file
# Set info about shared libraries.
AC_SUBST(SO)
AC_SUBST(LDSHARED)
AC_SUBST(CCSHARED)
AC_SUBST(LINKFORSHARED)
# SO is the extension of shared libraries `(including the dot!)
# -- usually .so, .sl on HP-UX
AC_MSG_CHECKING(SO)
if test -z "$SO"
then
case $ac_sys_system in
hp*|HP*) SO=.sl;;
NeXT|next) SO=.a;; # no shared libs on NeXT 3.3 and less
*) SO=.so;;
esac
fi
AC_MSG_RESULT($SO)
# LDSHARED is the ld *command* used to create shared library
# -- "ld" on SunOS 4.x.x, "ld -G" on SunOS 5.x, "ld -shared" on IRIX 5
AC_MSG_CHECKING(LDSHARED)
if test -z "$LDSHARED"
then
case $ac_sys_system/$ac_sys_release in
AIX*) LDSHARED="ld_so_aix";;
IRIX*) LDSHARED="ld -shared";;
SunOS/4*) LDSHARED="ld";;
SunOS/5*) LDSHARED="ld -G";;
hp*|HP*) LDSHARED="ld -b";;
OSF*) LDSHARED="ld -shared -expect_unresolved \"*\"";;
DYNIX/ptx*) LDSHARED="ld -G";;
Linux*) LDSHARED="gcc -shared";;
FreeBSD*) LDSHARED="ld -Bshareable";;
NeXT|next/3*) LDSHARED="ld -u libsys_s";;
*) LDSHARED="ld";;
esac
fi
AC_MSG_RESULT($LDSHARED)
# CCSHARED are the C *flags* used to create objects to go into a shared
# library -- this is only needed for a few systems
AC_MSG_CHECKING(CCSHARED)
if test -z "$CCSHARED"
then
case $ac_sys_system in
hp*|HP*) if test "$GCC" = yes;
then CCSHARED="-fpic";
else CCSHARED="+z";
fi;;
Linux*) CCSHARED="-fpic";;
FreeBSD*) CCSHARED="-fpic";;
esac
fi
AC_MSG_RESULT($CCSHARED)
# LINKFORSHARED are the flags passed to the $(CC) command that links
# the a few executables -- this is only needed for a few systems
AC_MSG_CHECKING(LINKFORSHARED)
if test -z "$LINKFORSHARED"
then
case $ac_sys_system/$ac_sys_release in
AIX*) LINKFORSHARED='-Wl,-bE:$(srcdir)/python.exp -lld';;
hp*|HP*)
LINKFORSHARED="-Wl,-E -Wl,+s -Wl,+b\$(BINLIBDEST)/lib-dynload";;
Linux*) LINKFORSHARED="-Xlinker -export-dynamic";;
next/*) LINKFORSHARED="-u libsys_s";;
SCO_SV*) LINKFORSHARED="-Bdynamic -dy -Wl,-Bexport";;
IRIX*/6*) LINKFORSHARED="-all";;
esac
fi
AC_MSG_RESULT($LINKFORSHARED)
echo ""
echo "Checking for installed packages."
echo "Note : None of the following packages are required to compile SWIG"
echo ""
# Check for specific libraries. Used for SWIG examples
AC_CHECK_LIB(dl, dlopen) # Dynamic linking for SunOS/Solaris and SYSV
AC_CHECK_LIB(dld, shl_load) # Dynamic linking for HP-UX
# The following three (nsl,inet,socket) are needed on Sequent;
# the order of checking must be this. Most SVR4 platforms will
# need -lsocket and -lnsl. However on SGI IRIX 5, these exist but
# broken. I see no elegant solution (probably CHECK_LIB should be
# fixed to only add the library if the given entry point is not
# satisfied without it).
if test "`uname -s`" != IRIX
then
AC_CHECK_LIB(nsl, t_open, [LIBS="-lnsl $LIBS"]) # SVR4
AC_CHECK_LIB(inet, gethostbyname, [LIBS="-linet $LIBS"], [], -lnsl) # Sequent
AC_CHECK_LIB(socket, socket, [LIBS="-lsocket $LIBS"], [], $LIBS) # SVR4 sockets
fi
# check for --with-libm=...
AC_SUBST(LIBM)
LIBM=-lm
AC_ARG_WITH(libm, [ --with-libm=STRING math library], [
if test "$withval" != yes
then LIBM=$withval
else AC_ERROR(proper usage is --with-libm=STRING)
fi])
AC_CHECK_LIB(ieee, main, [LIBM="-lieee $LIBM"])
AC_CHECK_LIB(crypt,crypt, [LIBCRYPT="-lcrypt"])
AC_SUBST(LIBCRYPT)
# check for --with-libc=...
AC_SUBST(LIBC)
AC_ARG_WITH(libc, [ --with-libc=STRING C library], [
if test "$withval" != yes
then LIBC=$withval
else AC_ERROR(proper usage is --with-libc=STRING)
fi])
#--------------------------------------------------------------------
# Locate the X11 header files and the X11 library archive. Try
# the ac_path_x macro first, but if it doesn't find the X stuff
# (e.g. because there's no xmkmf program) then check through
# a list of possible directories. Under some conditions the
# autoconf macro will return an include directory that contains
# no include files, so double-check its result just to be safe.
#--------------------------------------------------------------------
AC_PATH_X
not_really_there=""
if test "$no_x" = ""; then
if test "$x_includes" = ""; then
AC_TRY_CPP([#include <X11/XIntrinsic.h>], , not_really_there="yes")
else
if test ! -r $x_includes/X11/Intrinsic.h; then
not_really_there="yes"
fi
fi
fi
if test "$no_x" = "yes" -o "$not_really_there" = "yes"; then
AC_MSG_CHECKING(for X11 header files)
XINCLUDES="# no special path needed"
AC_TRY_CPP([#include <X11/Intrinsic.h>], , XINCLUDES="nope")
if test "$XINCLUDES" = nope; then
dirs="/usr/unsupported/include /usr/local/include /usr/X386/include /usr/include/X11R4 /usr/X11R5/include /usr/include/X11R5 /usr/openwin/include /usr/X11/include /usr/sww/include /usr/X11R6/include /usr/include/X11R6"
for i in $dirs ; do
if test -r $i/X11/Intrinsic.h; then
AC_MSG_RESULT($i)
XINCLUDES=" -I$i"
break
fi
done
fi
else
if test "$x_includes" != ""; then
XINCLUDES=-I$x_includes
else
XINCLUDES="# no special path needed"
fi
fi
if test "$XINCLUDES" = nope; then
AC_MSG_RESULT(couldn't find any!)
XINCLUDES="# no include files found"
fi
if test "$no_x" = yes; then
AC_MSG_CHECKING(for X11 libraries)
XLIBSW=nope
dirs="/usr/unsupported/lib /usr/local/lib /usr/X386/lib /usr/lib/X11R4 /usr/X11R5/lib /usr/lib/X11R5 /usr/X11R6/lib /usr/lib/X11R6 /usr/openwin/lib /usr/X11/lib /usr/sww/X11/lib"
for i in $dirs ; do
if test -r $i/libX11.a -o -r $i/libX11.so -o -r $i/libX11.sl; then
AC_MSG_RESULT($i)
XLIBSW="-L$i -lX11"
break
fi
done
else
if test "$x_libraries" = ""; then
XLIBSW=-lX11
else
XLIBSW="-L$x_libraries -lX11"
fi
fi
if test "$XLIBSW" = nope ; then
AC_CHECK_LIB(Xwindow, XCreateWindow, XLIBSW=-lXwindow)
fi
if test "$XLIBSW" = nope ; then
AC_MSG_RESULT(couldn't find any! Using -lX11.)
XLIBSW=-lX11
fi
AC_SUBST(XINCLUDES)
AC_SUBST(XLIBSW)
#--------------------------------------------------------------------
# Try to locate the Tcl package
#--------------------------------------------------------------------
TCLINCLUDE=nope
TCLLIB=nope
TCLPACKAGE=nope
AC_ARG_WITH(tcl,[ --with-tcl=path Set location of Tcl package],[
TCLPACKAGE="$withval"], [TCLPACKAGE=nope])
AC_ARG_WITH(tclincl,[ --with-tclincl=path Set location of Tcl include directory],[
TCLINCLUDE="-I$withval"], [TCLINCLUDE=nope])
AC_ARG_WITH(tcllib,[ --with-tcllib=path Set location of Tcl library directory],[
TCLLIB="-L$withval"], [TCLLIB=nope])
if test "$TCLINCLUDE" = nope; then
if test "$TCLPACKAGE" != nope; then
TCLINCLUDE="-I$TCLPACKAGE/include"
fi
fi
if test "$TCLLIB" = nope; then
if test "$TCLPACKAGE" != nope; then
TCLLIB="-L$TCLPACKAGE/lib"
fi
fi
AC_MSG_CHECKING(for Tcl header files)
if test "$TCLINCLUDE" = nope; then
AC_TRY_CPP([#include <tcl.h>], , TCLINCLUDE="nope")
if test "$TCLINCLUDE" = nope; then
dirs="$prefix/include /usr/local/include /usr/include /opt/local/include /home/sci/local/include"
for i in $dirs ; do
if test -r $i/tcl.h; then
AC_MSG_RESULT($i)
TCLINCLUDE="-I$i"
break
fi
done
fi
if test "$TCLINCLUDE" = nope; then
TCLINCLUDE="-I/usr/local/include"
AC_MSG_RESULT(not found)
fi
else
AC_MSG_RESULT($TCLINCLUDE)
fi
AC_MSG_CHECKING(for Tcl library)
if test "$TCLLIB" = nope; then
dirs="$prefix/lib /usr/local/lib /usr/lib /opt/local/lib /home/sci/local/lib"
for i in $dirs ; do
if test -r $i/libtcl.a; then
AC_MSG_RESULT($i)
TCLLIB="-L$i"
break
fi
done
if test "$TCLLIB" = nope; then
AC_MSG_RESULT(not found)
TCLLIB="-L/usr/local/lib"
fi
else
AC_MSG_RESULT($TCLLIB)
fi
AC_SUBST(TCLINCLUDE)
AC_SUBST(TCLLIB)
#----------------------------------------------------------------
# Look for Python
#----------------------------------------------------------------
PYINCLUDE=nope
PYLIB=nope
PYPACKAGE=nope
PYLINK="-lModules -lPython -lObjects -lParser"
AC_ARG_WITH(py,[ --with-py=path Set location of Python],[
PYPACKAGE="$withval"], [PYPACKAGE=nope])
AC_ARG_WITH(pyincl,[ --with-pyincl=path Set location of Python include directory],[
PYINCLUDE="$withval"], [PYINCLUDE=nope])
AC_ARG_WITH(pylib,[ --with-pylib=path Set location of Python library directory],[
PYLIB="$withval"], [PYLIB=nope])
if test "$PYINCLUDE" = nope; then
if test "$PYPACKAGE" != nope; then
PYINCLUDE="$PYPACKAGE/include"
fi
fi
if test "$PYLIB" = nope; then
if test "$PYPACKAGE" != nope; then
PYLIB="$PYPACKAGE/lib"
fi
fi
AC_MSG_CHECKING(for Python header files)
dirs="$PYINCLUDE $PYINCLUDE/python1.5 $PYINCLUDE/python1.4 $PYINCLUDE/Py $prefix/include/python1.5 $prefix/include/python1.4 /usr/local/include/python1.5 /usr/include/python1.5 /usr/local/include/python1.4 /usr/include/python1.4 $prefix/include/Py /usr/local/include/Py /usr/include/Py"
for i in $dirs ; do
if test -r $i/Python.h; then
AC_MSG_RESULT($i)
PYINCLUDE="-I$i"
break
fi
done
if test "$PYINCLUDE" = nope; then
PYINCLUDE="-I/usr/local/include/Py"
AC_MSG_RESULT(not found)
fi
AC_MSG_CHECKING(for Python library)
dirs="$PYLIB $PYLIB/config $PYLIB/lib $PYLIB/python1.5/config $PYLIB/python1.4/config $PYLIB/python/lib $prefix/lib/python1.5/config $prefix/lib/python1.4/config /usr/local/lib/python1.5/config /usr/lib/python1.5 /usr/local/lib/python1.4/config /usr/lib/python1.4 $prefix/lib/python/lib /usr/local/lib/python/lib /usr/lib/python/lib /home/sci/local/lib/python"
for i in $dirs ; do
if test -r $i/libpython1.5.a; then
AC_MSG_RESULT($i)
PYLIB="$i"
PYINCLUDE="$PYINCLUDE -I$i"
PYLINK="-lpython1.5"
break
fi
if test -r $i/libPython.a; then
AC_MSG_RESULT($i)
PYLIB="$i"
PYINCLUDE="$PYINCLUDE -I$i"
break
fi
done
if test "$PYLIB" = nope; then
AC_MSG_RESULT(not found)
PYLIB="/usr/local/lib/python/lib"
PYINCLUDE="$PYINCLUDE -I$PYLIB"
fi
AC_SUBST(PYINCLUDE)
AC_SUBST(PYLIB)
AC_SUBST(PYLINK)
#----------------------------------------------------------------
# Look for Perl5
#----------------------------------------------------------------
PERLBIN=nope
AC_ARG_WITH(perl5,[ --with-perl5=path Set location of Perl5 executable],[
PERLBIN="$withval"], [PERLBIN=nope])
# First figure out what the name of Perl5 is
if test "$PERLBIN" = nope; then
AC_CHECK_PROGS(PERL, perl5.004 perl5.003 perl5.002 perl5.001 perl5 perl,nope)
else
PERL="$PERLBIN"
fi
AC_MSG_CHECKING(for Perl5 header files)
if test "$PERL" != nope; then
PERL5DIR=`($PERL -e 'use Config; print $Config{archlib};') 2>/dev/null`
if test "$PERL5DIR" != ""; then
dirs="$PERL5DIR $PERL5DIR/CORE"
PERL5EXT=none
for i in $dirs; do
if test -r $i/perl.h; then
AC_MSG_RESULT($i)
PERL5EXT="$i"
break;
fi
done
if test "$PERL5EXT" = none; then
PERL5EXT="$PERL5DIR/CORE"
AC_MSG_RESULT(could not locate perl.h...using $PERL5EXT)
fi
else
AC_MSG_RESULT(unable to determine perl5 configuration)
PERL5EXT=$PERL5DIR
fi
else
AC_MSG_RESULT(could not figure out how to run perl5)
PERL5EXT="/usr/local/lib/perl/archname/5.003/CORE"
fi
AC_SUBST(PERL5EXT)
AC_OUTPUT(Makefile SWIG/Makefile Modules/Makefile Runtime/Makefile swig_lib/tcl/Makefile swig_lib/python/Makefile swig_lib/perl5/Makefile Makefile.template)

View File

@@ -0,0 +1,70 @@
#######################################################################
# $Header$
# Simplified Wrapper and Interface Generator (SWIG)
#
# Windows NT/95 Makefile for version 1.1
# Kevin Butler & Dave Beazley
# March 12, 1997
#
# This file contains default values and various parameters for
# building SWIG with MS Visual C++.
#
#######################################################################
# ---------------------------------------------------------------------
# Set your compiler location here
# MS Visual C++ defaults to the listed locations
# (Set compiler, linker/lib manager, and location of standard includes
# ---------------------------------------------------------------------
CC = cl.exe
LD = lib.exe
##CCHOME = c:\Tools\VisStudio\vc98
##STD_INC = "$(CCHOME)/include"
#
# Set the prefix below to indicate where you want SWIG to install its
# files. Normally this is c:\swig
#
# 'prefix' is used as a symbol for SWIG itself.
# 'dprefix' is the DOS prefix with the backwards slash.
##prefix = c:/tools/swig1.1-883
##dprefix = c:\tools\swig1.1-883
# Location and filename of the SWIG executable. Feel free to put this
# wherever you'd like in your PATH, or leave it in c:\swig\swig.exe
##dSWIG_EXE = $(dprefix)\swig.exe
# Location of the SWIG library. Is normally placed in c:\swig\swig_lib
# on NT/Win95. The SWIG library contains configuration files and library modules
# so you should install it someplace where it can be easily accessed.
##SWIG_LIB = $(prefix)/swig_lib
##dSWIG_LIB = $(dprefix)\swig_lib
#
# SWIG_OPTS controls swig defaults.
# You may want to change SWIG_LANG or SWIG_DOC.
#
# SWIG_LANG may be one of : TCL,TCL8,PERL5,PERL4,PYTHON, or GUILE
# SWIG_DOC may be one of : ASCII, LATEX, HTML, NONE
#
SWIG_OPTS = -DSWIG_LANG=PYTHON -DSWIG_DOC=ASCII
MAKE = nmake /f makefile.vc
## -DSWIG_LIB="\"$(SWIG_LIB)\""
DEBUG = -Zi
CFLAGS = $(DEBUG) -nologo -DSWIG_CC="\"$(CC)\"" -DMSDOS -DSTDC_HEADERS=1 -DHAVE_LIBDL=1 $(SWIG_OPTS)
INCFLAGS= -I$(rootdir)/Include -I$(rootdir)/SWIG -I$(rootdir)/Modules
LD_FLAGS= -VERBOSE

155
wxPython/wxSWIG/makefile.vc Normal file
View File

@@ -0,0 +1,155 @@
#######################################################################
# $Header$
# Simplified Wrapper and Interface Generator (SWIG)
#
# Makefile for version 1.1
# Dave Beazley
# March 12, 1997
#
# Modified for Visual C++
# Kevin Butler
# 1/10/97
#
# $Log$
# Revision 1.1 2002/04/29 19:56:47 RD
# Since I have made several changes to SWIG over the years to accomodate
# special cases and other things in wxPython, and since I plan on making
# several more, I've decided to put the SWIG sources in wxPython's CVS
# instead of relying on maintaining patches. This effectivly becomes a
# fork of an obsolete version of SWIG, :-( but since SWIG 1.3 still
# doesn't have some things I rely on in 1.1, not to mention that my
# custom patches would all have to be redone, I felt that this is the
# easier road to take.
#
# Revision 1.3 1999/11/01 15:24:53 beazley
# Removed perl4
#
# Revision 1.2 1999/08/10 16:50:30 beazley
# Windows Runtime
#
# Revision 1.1.1.1 1999/02/28 02:00:53 beazley
# Swig1.1
#
# Revision 1.1 1996/08/12 01:55:02 dmb
# Initial revision
#
#######################################################################
!include <make_win.in>
srcdir = .
all: wxswig
wxswig: wxswig.exe
wxswig.exe:
@echo "Making the SWIG Parser..."
cd SWIG
$(MAKE)
@echo "Make Modules..."
cd ..\Modules
$(MAKE)
cd ..
clean:
del *.lib
del *.obj
del swig.exe
@cd SWIG
@$(MAKE) clean
@cd ..\Modules
@$(MAKE) clean
@cd ..
doc: swig
@echo "Building Documentation for SWIG library..."
.\swig -Iswig_lib -d Doc/swiglib -I./swig_lib ./swig_lib/autodoc.i
runtime: swig
@cd Runtime
$(MAKE)
## # Install the SWIG program
##
## INSTALL = copy
##
## install: install-main install-lib install-runtime
## @echo "Installation complete"
##
## install-runtime:
## @cd ..\..\Runtime
## $(MAKE) install
##
## install95: install-main95 install-lib95 install-runtime95
## @echo "Installation complete"
##
## install-runtime95:
## @ ..\..\Runtime
## $(MAKE) install95
##
## smallinstall: install-main
##
## install-main: swig
## @if not exist $(dprefix) mkdir $(dprefix)
## @echo "Installing $(dSWIG_EXE)"
## @copy ..\swig.exe $(dSWIG_EXE)
## install-lib:
## @if not exist $(dSWIG_LIB) mkdir $(dSWIG_LIB)
## @echo "$(dSWIG_LIB)"
## @echo "Installing the SWIG library"
## @cd ..\swig_lib
## @xcopy *.i $(dSWIG_LIB)
## @xcopy *.swg $(dSWIG_LIB)
## @if not exist $(dSWIG_LIB)\tcl mkdir $(dSWIG_LIB)\tcl
## @cd tcl
## @xcopy *.i $(dSWIG_LIB)\tcl
## @xcopy *.swg $(dSWIG_LIB)\tcl
## @if not exist $(dSWIG_LIB)\perl5 mkdir $(dSWIG_LIB)\perl5
## @cd ..\perl5
## @xcopy *.i $(dSWIG_LIB)\perl5
## @xcopy *.swg $(dSWIG_LIB)\perl5
## @if not exist $(dSWIG_LIB)\python mkdir $(dSWIG_LIB)\python
## @cd ..\python
## @xcopy *.i $(dSWIG_LIB)\python
## @xcopy *.swg $(dSWIG_LIB)\python
## @if not exist $(dSWIG_LIB)\guile mkdir $(dSWIG_LIB)\guile
## @cd ..\guile
## @xcopy *.i $(dSWIG_LIB)\guile
## @xcopy *.swg $(dSWIG_LIB)\guile
##
## install-main95: swig
## @if not exist $(dprefix) mkdir $(dprefix)
## @echo "Installing $(dSWIG_EXE)"
## @copy ..\swig.exe $(dSWIG_EXE) /Y
## install-lib95:
## @if not exist $(dSWIG_LIB) mkdir $(dSWIG_LIB)
## @echo "$(dSWIG_LIB)"
## @echo "Installing the SWIG library"
## @cd ..\swig_lib
## @xcopy *.i $(dSWIG_LIB) /Y
## @xcopy *.swg $(dSWIG_LIB) /Y
## @mkdir $(dSWIG_LIB)\tcl
## @cd tcl
## @xcopy *.i $(dSWIG_LIB)\tcl /Y
## @xcopy *.swg $(dSWIG_LIB)\tcl /Y
## @mkdir $(dSWIG_LIB)\perl5
## @cd ..\perl5
## @xcopy *.i $(dSWIG_LIB)\perl5 /Y
## @xcopy *.swg $(dSWIG_LIB)\perl5 /Y
## @mkdir $(dSWIG_LIB)\python
## @cd ..\python
## @xcopy *.i $(dSWIG_LIB)\python /Y
## @xcopy *.swg $(dSWIG_LIB)\python /Y
## @mkdir $(dSWIG_LIB)\guile
## @cd ..\guile
## @xcopy *.i $(dSWIG_LIB)\guile /Y
## @xcopy *.swg $(dSWIG_LIB)\guile /Y
#Makefile.template has not been ported to NT
# @echo "Installing Makefile"
# $(INSTALL_DATA) Makefile.template $(dSWIG_LIB)/Makefile

View File

@@ -0,0 +1,401 @@
//
// array.i
// Dave Beazley
// November 30, 1996
//
// This SWIG library file provides access to C arrays.
%module carray
%section "SWIG C Array Module",info,after,pre,nosort,skip=1,chop_left=3,chop_right=0,chop_top=0,chop_bottom=0
%text %{
%include array.i
This module provides scripting language access to various kinds of C/C++
arrays. For each datatype, a collection of four functions are created :
<type>_array(size) : Create a new array of given size
<type>_get(array, index) : Get an element from the array
<type>_set(array, index, value) : Set an element in the array
<type>_destroy(array) : Destroy an array
The functions in this library are only low-level accessor functions
designed to directly access C arrays. Like C, no bounds checking is
performed so use at your own peril.
%}
// Grab the SWIG exception library
#ifndef AUTODOC
%include exception.i
#endif
// A Typemap used to check input arguments.
%typemap(check) int *, double *, float *, char **, short *, long * {
if (!$target) {
SWIG_exception(SWIG_ValueError,"Received a NULL Pointer");
}
}
%typemap(ret) int *, double *, float *, char **, short *, long * {
if (!$source) {
SWIG_exception(SWIG_MemoryError,"Out of memory.");
}
}
// -----------------------------------------------------------------------
// Integer array support
// -----------------------------------------------------------------------
%subsection "Integer Arrays"
%text %{
The following functions provide access to integer arrays (mapped
onto the C 'int' datatype.
%}
%{
#include <limits.h>
/* Create a new integer array */
static int *int_array(int size) {
#ifdef __cplusplus
return new int[size];
#else
return (int *) malloc(size*sizeof(int));
#endif
}
/* Destroy an integer array */
static void int_destroy(int *array) {
if (array) {
#ifdef __cplusplus
delete array;
#else
free(array);
#endif
}
}
/* Return an element */
static int int_get(int *array, int index) {
if (array) {
return array[index];
} else {
return INT_MIN;
}
}
/* Set an element */
static int int_set(int *array, int index, int value) {
if (array) {
return (array[index] = value);
} else {
return INT_MIN;
}
}
%}
int *int_array(int nitems);
/* Creates a new array of integers. nitems specifies the number of elements.
The array is created using malloc() in C and new() in C++. */
void int_destroy(int *array);
/* Destroys the given array. */
int int_get(int *array, int index);
/* Returns the value of array[index]. */
int int_set(int *array, int index, int value);
/* Sets array[index] = value. Returns value. */
// -----------------------------------------------------------------------
// Floating point
// -----------------------------------------------------------------------
%subsection "Floating Point Arrays"
/* The following functions provide access to arrays of floats and doubles. */
%{
#include <float.h>
/* Create a new float array */
static float *float_array(int size) {
#ifdef __cplusplus
return new float[size];
#else
return (float *) malloc(size*sizeof(float));
#endif
}
/* Destroy an array */
static void float_destroy(float *array) {
if (array) {
#ifdef __cplusplus
delete array;
#else
free(array);
#endif
}
}
/* Return an element */
static float float_get(float *array, int index) {
if (array) {
return array[index];
} else {
return FLT_MIN;
}
}
/* Set an element */
static float float_set(float *array, int index, float value) {
if (array) {
return (array[index] = value);
} else {
return FLT_MIN;
}
}
/* Create a new double array */
static double *double_array(int size) {
#ifdef __cplusplus
return new double[size];
#else
return (double *) malloc(size*sizeof(double));
#endif
}
/* Destroy an array */
static void double_destroy(double *array) {
if (array) {
#ifdef __cplusplus
delete array;
#else
free(array);
#endif
}
}
/* Return an element */
static double double_get(double *array, int index) {
if (array) {
return array[index];
} else {
return FLT_MIN;
}
}
/* Set an element */
static double double_set(double *array, int index, double value) {
if (array) {
return (array[index] = value);
} else {
return FLT_MIN;
}
}
%}
double *double_array(int nitems);
/* Creates a new array of doubles. nitems specifies the number of elements.
The array is created using malloc() in C and new() in C++. */
void double_destroy(double *array);
/* Destroys the given array. */
double double_get(double *array, int index);
/* Returns the value of array[index]. */
double double_set(double *array, int index, double value);
/* Sets array[index] = value. Returns value. */
float *float_array(int nitems);
/* Creates a new array of floats. nitems specifies the number of elements.
The array is created using malloc() in C and new() in C++. */
void float_destroy(float *array);
/* Destroys the given array. */
float float_get(float *array, int index);
/* Returns the value of array[index]. */
float float_set(float *array, int index, float value);
/* Sets array[index] = value. Returns value. */
// -----------------------------------------------------------------------
// Character strings
// -----------------------------------------------------------------------
%subsection "String Arrays"
%text %{
The following functions provide support for the 'char **' datatype. This
is primarily used to handle argument lists and other similar structures that
need to be passed to a C/C++ function.
%}
#if defined(SWIGTCL)
%text %{
To convert from a Tcl list into a 'char **', the following code can be used :
# $list is a list
set args [string_array expr {[llength $list] + 1}]
set i 0
foreach a $list {
string_set $args $i $a
incr i 1
}
string_set $i ""
# $args is now a char ** type
%}
#elif defined(SWIGPERL)
%text %{
To convert from a Perl list into a 'char **', code similar to the following
can be used :
# @list is a list
my $l = scalar(@list);
my $args = string_array($l+1);
my $i = 0;
foreach $arg (@list) {
string_set($args,$i,$arg);
$i++;
}
string_set($args,$i,"");
(of course, there is always more than one way to do it)
%}
#elif defined(SWIGPYTHON)
%text %{
To convert from a Python list to a 'char **', code similar to the following
can be used :
# 'list' is a list
args = string_array(len(list)+1)
for i in range(0,len(list)):
string_set(args,i,list[i])
string_set(args,len(list),"")
%}
#endif
%{
/* Create character string arrays */
static char **string_array(int size) {
char **a;
int i;
#ifdef __cplusplus
a = new char *[size];
#else
a = (char **) malloc(size*sizeof(char *));
#endif
for (i = 0; i < size; i++)
a[i] = 0;
return a;
}
/* Destroy a string array */
static void string_destroy(char **array) {
int i = 0;
if (array) {
while (array[i]) {
#ifdef __cplusplus
delete array[i];
#else
free(array[i]);
#endif
i++;
}
#ifdef __cplusplus
delete array;
#else
free(array);
#endif
}
}
/* Get an element */
static char *string_get(char **array_string, int index) {
if (array_string)
if (array_string[index]) return (array_string[index]);
else return "";
else
return "";
}
/* Set an element */
static char *string_set(char **array_string, int index, char * val) {
if (array_string) {
if (array_string[index]) {
#ifdef __cplusplus
delete array_string[index];
#else
free(array_string[index]);
#endif
}
if (strlen(val) > 0) {
#ifdef __cplusplus
array_string[index] = new char[strlen(val)+1];
#else
array_string[index] = (char *) malloc(strlen(val)+1);
#endif
strcpy(array_string[index],val);
return array_string[index];
} else {
array_string[index] = 0;
return val;
}
} else return val;
}
%}
char **string_array(int nitems);
/* Creates a new array of strings. nitems specifies the number of elements.
The array is created using malloc() in C and new() in C++. Each element
of the array is set to NULL upon initialization. */
void string_destroy(char **array);
/* Destroys the given array. Each element of the array is assumed to be
a NULL-terminated string allocated with malloc() or new(). All of
these strings will be destroyed as well. (It is probably only safe to
use this function on an array created by string_array) */
char *string_get(char **array, int index);
/* Returns the value of array[index]. Returns a string of zero length
if the corresponding element is NULL. */
char *string_set(char **array, int index, char *value);
/* Sets array[index] = value. value is assumed to be a NULL-terminated
string. A string of zero length is mapped into a NULL value. When
setting the value, the value will be copied into a new string allocated
with malloc() or new(). Any previous value in the array will be
destroyed. */
%typemap(check) int *, double *, float *, char **, short *, long * = PREVIOUS;
%typemap(out) int *, double *, float *, char **, short *, long * = PREVIOUS;

View File

@@ -0,0 +1,109 @@
// This file automatically generates the SWIG library documentation
%doconly
%style latex_section="\\newpage \\section{:}"
%title "SWIG Library Reference",pre,sort,chop_left = 0,noinfo
/*
Version 1.1p4
January, 1998
Copyright (C) 1996-1998
Dave Beazley
(This file was automatically generated by SWIG)
*/
%style html_contents="<hr><h2>:</h2>"
%module swig_lib
%section " Introduction"
%text %{
This file describes all of the functions in the generic SWIG library.
The SWIG library is a collection of generally useful functions that
can be used to supplement an interface file. These include functions
to manipulate arrays, functions from the C library, and interesting
modules.
This document is automatically generated by SWIG from the file
"swig_lib/autodoc.i". Some modules may supply additional documentation
for a particular target language. To recreate the documentation for
a particular target language, simply run SWIG on the file 'autodoc.i'
with the appropriate target language option.
%}
#if defined(SWIGTCL)
%text %{
This document has been generated for Tcl.
%}
#elif defined(SWIGPERL)
%text %{
This document has been generated for Perl.
%}
#elif defined(SWIGPYTHON)
%text %{
This document has been generated for Python.
%}
#endif
%subsection "Call for contributions"
%text %{
My long-term goal is for the SWIG library to be a collection of useful
modules that can be used to quickly put together interesting programs.
To contribute new modules send e-mail to beazley@cs.utah.edu and I
will include them here.
%}
#define AUTODOC
%include array.i
%include math.i
%include timers.i
%include malloc.i
%include memory.i
%include exception.i
%include pointer.i
%include constraints.i
%include typemaps.i
#ifdef SWIGTCL
%section "Tcl Library Files",nosort
%text %{
The following library modules are available when using the Tcl
language module.
%}
%include "tcl/consthash.i"
%include "tcl/constarray.i"
%include "tcl/tclsh.i"
%include "tcl/wish.i"
%include "tcl/expect.i"
%include "tcl/expectk.i"
%include "tcl/blt.i"
%include "tcl/tix.i"
%include "tcl/ish.i"
%include "tcl/itclsh.i"
%include "tcl/iwish.i"
%include "tcl/itkwish.i"
#endif
#ifdef SWIGPYTHON
%section "Python Library Files",nosort
%text %{
The following modules are available when using the Python language
module.
%}
%include "python/embed.i"
%include "python/embed14.i"
%include "python/embed13.i"
#endif
#ifdef SWIGPERL
%section "Perl Library Files",nosort
%text %{
The following modules are available when using the Perl5 language
module.
%}
%include "perl5/perlmain.i"
#endif

View File

@@ -0,0 +1,182 @@
//
// $Header$
// carray.i
// Dave Beazley
// March 24, 1996
//
// This SWIG library file supports C arrays of various datatypes.
// These arrays are probably *not* compatible with scripting languages
// but they are compatible with C functions.
//
/* Revision History
* -- $Log$
* -- Revision 1.1 2002/04/29 19:56:49 RD
* -- Since I have made several changes to SWIG over the years to accomodate
* -- special cases and other things in wxPython, and since I plan on making
* -- several more, I've decided to put the SWIG sources in wxPython's CVS
* -- instead of relying on maintaining patches. This effectivly becomes a
* -- fork of an obsolete version of SWIG, :-( but since SWIG 1.3 still
* -- doesn't have some things I rely on in 1.1, not to mention that my
* -- custom patches would all have to be redone, I felt that this is the
* -- easier road to take.
* --
* -- Revision 1.1.1.1 1999/02/28 02:00:53 beazley
* -- Swig1.1
* --
* -- Revision 1.1 1996/05/22 17:23:48 beazley
* -- Initial revision
* --
*/
%module carray
%{
#include <string.h>
/* Create an integer array of given size */
static int *array_int(int size) {
return (int *) malloc(size*sizeof(int));
}
static int get_int(int *array_int, int index) {
if (array_int)
return (array_int[index]);
else
return 0;
}
static int set_int(int *array_int, int index, int val) {
if (array_int)
return (array_int[index] = val);
else
return 0;
}
/* Create double precision arrays */
static double *array_double(int size) {
return (double *) malloc(size*sizeof(double));
}
static double get_double(double *array_double, int index) {
if (array_double)
return (array_double[index]);
else
return 0;
}
static double set_double(double *array_double, int index, double val) {
if (array_double)
return (array_double[index] = val);
else
return 0;
}
/* Create byte arrays */
typedef unsigned char byte;
static byte *array_byte(int size) {
return (byte *) malloc(size*sizeof(byte));
}
static byte get_byte(byte *array_byte, int index) {
if (array_byte)
return (array_byte[index]);
else
return 0;
}
static byte set_byte(byte *array_byte, int index, byte val) {
if (array_byte)
return (array_byte[index] = val);
else
return 0;
}
/* Create character string arrays */
static char **array_string(int size) {
char **a;
int i;
a = (char **) malloc(size*sizeof(char *));
for (i = 0; i < size; i++)
a[i] = 0;
return a;
}
static char *get_string(char **array_string, int index) {
if (array_string)
return (array_string[index]);
else
return "";
}
static char *set_string(char **array_string, int index, char * val) {
if (array_string) {
if (array_string[index]) free(array_string[index]);
if (strlen(val) > 0) {
array_string[index] = (char *) malloc(strlen(val)+1);
strcpy(array_string[index],val);
return array_string[index];
} else {
array_string[index] = 0;
return val;
}
}
else
return val;
}
%}
%section "Array Operations"
int *array_int(int size);
/* Creates an integer array of size elements. Integers are the same
size as the C int type. */
int get_int(int *array_int, int index) ;
/* Return the integer in array_int[index] */
int set_int(int *array_int, int index, int ival);
/* Sets array_int[index] = ival. Returns it's value so you
can use this function in an expression. */
/* Create double precision arrays */
double *array_double(int size);
/* Creates an array of double precision floats. */
double get_double(double *array_double, int index);
/* Return the double in array_double[index] */
double set_double(double *array_double, int index, double dval);
/* Sets array_double[index] = dval. Returns it's value */
typedef unsigned char byte;
byte *array_byte(int nbytes);
/* Creates a byte array. A byte is defined as an unsigned char. */
byte get_byte(byte *array_byte, int index);
/* Returns array_byte[index] */
byte set_byte(byte *array_byte, int index, byte val);
/* Sets array_byte[index] = val. Returns it's new value */
char **array_string(int size);
/* Creates a string array. A string is array is the same as char ** in C */
char *get_string(char **array_string, int index);
/* Returns character string in array_string[index]. If that entry is
NULL, returns an empty string */
char *set_string(char **array_string, int index, char * string);
/* Sets array_string[index] = string. string must be a 0-terminated
ASCII string. If string is "" then this will create a NULL pointer. */

View File

@@ -0,0 +1,172 @@
/* swigptr.cfg
* $Header$
*
* This file contains two functions :
*
* void _swig_make_hex(char *_c, void *_ptr, char *type)
* char *_swig_get_hex(char *_c, void **ptr, char *type)
*
* These are used to convert pointers to and from pointer strings
* and to perform type checking.
*
* You can remap these functions by making a file called "swigptr.cfg" in
* your the same directory as the interface file you are wrapping.
*
* IMPORTANT !!! the function _swig_get_hex returns a non-null char pointer
* in the event of a type error (this is used to generate an error message).
* If a type is successfully parsed, a NULL pointer is returned.
*
* $Log$
* Revision 1.1 2002/04/29 19:56:50 RD
* Since I have made several changes to SWIG over the years to accomodate
* special cases and other things in wxPython, and since I plan on making
* several more, I've decided to put the SWIG sources in wxPython's CVS
* instead of relying on maintaining patches. This effectivly becomes a
* fork of an obsolete version of SWIG, :-( but since SWIG 1.3 still
* doesn't have some things I rely on in 1.1, not to mention that my
* custom patches would all have to be redone, I felt that this is the
* easier road to take.
*
* Revision 1.1.1.1 1999/02/28 02:00:53 beazley
* Swig1.1
*
* Revision 1.5 1996/08/01 16:28:56 dmb
* Took out unused "dt" variable.
*
* Revision 1.4 1996/07/23 14:38:42 dmb
* Minor change to handling of NULL pointers.
*
* Revision 1.3 1996/07/17 15:26:08 dmb
* Made a minor bug fix so pointers of form _0_Type could be used
* (as described in the manual). Disable by compiling with -DNO_ZERO.
*
* Revision 1.2 1996/06/10 23:42:10 beazley
* Added const qualifier.
*
# Revision 1.1 1996/05/22 17:17:47 beazley
# Initial revision
#
*/
static void
_swig_make_hex (char *_c, const void *_ptr, char *type)
{
static char _hex[16] =
{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f'};
unsigned long _p, _s;
char _result[128], *_r;
_r = _result;
_p = (unsigned long) _ptr;
if (_p > 0)
{
while (_p > 0)
{
_s = _p & 0xf;
*(_r++) = _hex[_s];
_p = _p >> 4;
}
*_r = '_';
while (_r >= _result)
*(_c++) = *(_r--);
}
else
{
strcpy (_c, "NULL");
}
if (_ptr)
strcpy (_c, type);
}
/* A forward reference; */
static char ***swig_ptr_derived = 0;
static char *
_swig_get_hex (char *_c, void **ptr, char *_t)
{
unsigned long _p;
char temp_type[256];
char *_tt;
char **eq;
int i, j, n;
_p = 0;
if (*_c == '_')
{
_c++;
while (*_c)
{
if ((*_c >= '0') && (*_c <= '9'))
_p = (_p << 4) + (*_c - '0');
else if ((*_c >= 'a') && (*_c <= 'f'))
_p = (_p << 4) + ((*_c - 'a') + 10);
else
break;
_c++;
}
#ifdef NO_ZERO
if (_p == 0)
{
return (char *) _c;
}
#endif
_tt = _c;
if (_t)
{
if (strcmp (_c, _t))
{
/* Have a type mismatch, we're going to have to do some
searching here */
i = 0;
if (swig_ptr_derived)
{
while (swig_ptr_derived[i])
{
eq = swig_ptr_derived[i];
/* Check type */
if (strncmp (_t, eq[0], strlen (eq[0])) == 0)
{
/* Found derived type list for this. */
n = strlen (eq[0]);
j = 1;
while (eq[j])
{
sprintf (temp_type, "%s%s", eq[j], _t + n);
if (strcmp (_c, temp_type) == 0)
{
*ptr = (void *) _p;
return (char *) 0;
}
j++;
}
}
i++;
}
}
*ptr = (void *) _p;
return _tt;
}
else
{
*ptr = (void *) _p;
return (char *) 0;
}
}
else
{
*ptr = (void *) _p;
return (char *) 0;
}
}
else {
#ifdef ALLOW_NULL
if (strcmp (_c, "NULL") == 0)
{
*ptr = (void *) 0;
return (char *) 0;
}
#endif
*ptr = (void *) 0;
return _c;
}
}

View File

@@ -0,0 +1,208 @@
//
// SWIG constraint library
// Dave Beazley
// May 4, 1997
//
// This library file contains typemaps for implementing various kinds of
// constraints. Depends upon the SWIG exception library for generating
// errors in a language-independent manner.
#ifdef AUTODOC
%section "Constraint Library",info,after,pre,nosort,skip=1,chop_left=3,chop_right=0,chop_top=0,chop_bottom=0
%text %{
%include constraints.i
This library provides support for applying constraints to function
arguments. Using a constraint, you can restrict arguments to be
positive numbers, non-NULL pointers, and so on. The following
constraints are available :
Number POSITIVE - Positive number (not zero)
Number NEGATIVE - Negative number (not zero)
Number NONZERO - Nonzero number
Number NONNEGATIVE - Positive number (including zero)
Number NONPOSITIVE - Negative number (including zero)
Pointer NONNULL - Non-NULL pointer
Pointer ALIGN8 - 8-byte aligned pointer
Pointer ALIGN4 - 4-byte aligned pointer
Pointer ALIGN2 - 2-byte aligned pointer
To use the constraints, you need to "apply" them to specific
function arguments in your code. This is done using the %apply
directive. For example :
%apply Number NONNEGATIVE { double nonneg };
double sqrt(double nonneg); // Name of argument must match
%apply Pointer NONNULL { void *ptr };
void *malloc(int POSITIVE); // May return a NULL pointer
void free(void *ptr); // May not accept a NULL pointer
Any function argument of the type you specify with the %apply directive
will be checked with the appropriate constraint. Multiple types may
be specified as follows :
%apply Pointer NONNULL { void *, Vector *, List *, double *};
In this case, all of the types listed would be checked for non-NULL
pointers.
The common datatypes of int, short, long, unsigned int, unsigned long,
unsigned short, unsigned char, signed char, float, and double can be
checked without using the %apply directive by simply using the
constraint name as the parameter name. For example :
double sqrt(double NONNEGATIVE);
double log(double POSITIVE);
If you have used typedef to change type-names, you can also do this :
%apply double { Real }; // Make everything defined for doubles
// work for Reals.
Real sqrt(Real NONNEGATIVE);
Real log(Real POSITIVE);
%}
#endif
%include exception.i
// Positive numbers
%typemap(check) int POSITIVE,
short POSITIVE,
long POSITIVE,
unsigned int POSITIVE,
unsigned short POSITIVE,
unsigned long POSITIVE,
signed char POSITIVE,
unsigned char POSITIVE,
float POSITIVE,
double POSITIVE,
Number POSITIVE
{
if ($target <= 0) {
SWIG_exception(SWIG_ValueError,"Expected a positive value.");
}
}
// Negative numbers
%typemap(check) int NEGATIVE,
short NEGATIVE,
long NEGATIVE,
unsigned int NEGATIVE,
unsigned short NEGATIVE,
unsigned long NEGATIVE,
signed char NEGATIVE,
unsigned char NEGATIVE,
float NEGATIVE,
double NEGATIVE,
Number NEGATIVE
{
if ($target >= 0) {
SWIG_exception(SWIG_ValueError,"Expected a negative value.");
}
}
// Nonzero numbers
%typemap(check) int NONZERO,
short NONZERO,
long NONZERO,
unsigned int NONZERO,
unsigned short NONZERO,
unsigned long NONZERO,
signed char NONZERO,
unsigned char NONZERO,
float NONZERO,
double NONZERO,
Number NONZERO
{
if ($target == 0) {
SWIG_exception(SWIG_ValueError,"Expected a nonzero value.");
}
}
// Nonnegative numbers
%typemap(check) int NONNEGATIVE,
short NONNEGATIVE,
long NONNEGATIVE,
unsigned int NONNEGATIVE,
unsigned short NONNEGATIVE,
unsigned long NONNEGATIVE,
signed char NONNEGATIVE,
unsigned char NONNEGATIVE,
float NONNEGATIVE,
double NONNEGATIVE,
Number NONNEGATIVE
{
if ($target < 0) {
SWIG_exception(SWIG_ValueError,"Expected a non-negative value.");
}
}
// Nonpositive numbers
%typemap(check) int NONPOSITIVE,
short NONPOSITIVE,
long NONPOSITIVE,
unsigned int NONPOSITIVE,
unsigned short NONPOSITIVE,
unsigned long NONPOSITIVE,
signed char NONPOSITIVE,
unsigned char NONPOSITIVE,
float NONPOSITIVE,
double NONPOSITIVE,
Number NONPOSITIVE
{
if ($target < 0) {
SWIG_exception(SWIG_ValueError,"Expected a non-positive value.");
}
}
// Non-NULL pointer
%typemap(check) void * NONNULL,
Pointer NONNULL
{
if (!$target) {
SWIG_exception(SWIG_ValueError,"Received a NULL pointer.");
}
}
// Aligned pointers
%typemap(check) void * ALIGN8,
Pointer ALIGN8
{
long tmp;
tmp = (long) $target;
if (tmp & 7) {
SWIG_exception(SWIG_ValueError,"Pointer must be 8-byte aligned.");
}
}
%typemap(check) void * ALIGN4,
Pointer ALIGN4
{
long tmp;
tmp = (long) $target;
if (tmp & 3) {
SWIG_exception(SWIG_ValueError,"Pointer must be 4-byte aligned.");
}
}
%typemap(check) void * ALIGN2,
Pointer ALIGN2
{
long tmp;
tmp = (long) $target;
if (tmp & 1) {
SWIG_exception(SWIG_ValueError,"Pointer must be 2-byte aligned.");
}
}

View File

@@ -0,0 +1,64 @@
//
// ctype.i
// Dave Beazley
// November 30, 1996
// SWIG file for character tests
//
%module ctype
%{
#include <ctype.h>
%}
%section "Character Class Testing Module",after,info,nosort,pre,chop_left=3,chop_bottom=0,chop_top=0,chop_right=0,skip=1
%text %{
%include ctype.i
This module provides access to a number of functions for testing
characters. These functions are in the C <ctype.h> library.
Most scripting languages already provide much of this functionality,
but just in case you want to use one of the built-in C functions,
you can use this module.
%}
int isalnum(char c);
/* Returns 1 if isalpha(c) or isdigit(c) is true. */
int isalpha(char c);
/* Returns 1 if isupper(c) or islower(c) is true. */
int iscntrl(char c);
/* Returns 1 if c is a control character. */
int isdigit(char c);
/* Returns 1 if c is a decimal digit. */
int isgraph(char c);
/* Returns 1 if c is a printing character except space. */
int islower(char c);
/* Returns 1 if c is a lower-case letter. */
int isprint(char c);
/* Returns 1 if c is a printing character including space. */
int ispunct(char c);
/* Returns 1 if c is a printing character except space or letter
or digit. */
int isspace(char c);
/* Returns 1 if c is a space, formfeed, newline, carriage return,
tab, or vertical tab. */
int isupper(char c);
/* Returns 1 if c is an upper case letter. */
int isxdigit(char c);
/* Returns 1 if c is a hexadecimal digit. */
char tolower(char c);
/* Converts c to lower case */
char toupper(char c);
/* Converts c to upper case */

View File

@@ -0,0 +1,146 @@
//
// except.i
// Dave Beazley
// April 14, 1997
//
// This SWIG library file provides language independent exception handling
#ifdef AUTODOC
%section "Exception Handling Library",info,after,pre,nosort,skip=1,chop_left=3,chop_right=0,chop_top=0,chop_bottom=0
%text %{
%include exception.i
This library provides language independent support for raising scripting
language exceptions in SWIG generated wrapper code. Normally, this is
used in conjunction with the %except directive.
To raise an exception, use the following function call :
SWIG_exception(int exctype, char *msg);
'exctype' is an exception type code and may be one of the following :
SWIG_MemoryError
SWIG_IOError
SWIG_RuntimeError
SWIG_IndexError
SWIG_TypeError
SWIG_DivisionByZero
SWIG_OverflowError
SWIG_SyntaxError
SWIG_ValueError
SWIG_SystemError
SWIG_UnknownError
'msg' is an error string that should be reported to the user.
The library is normally used in conjunction with the %except directive
as follows :
%except {
try {
$function
} catch RangeError {
SWIG_exception(SWIG_IndexError,"Array index out of bounds");
} catch(...) {
SWIG_exception(SWIG_UnknownError,"Uncaught exception");
}
}
It is important to note that the SWIG_exception() function is only available
to the C code generated by SWIG. It is not available in the scripting language
interface itself.
%}
#endif
%{
#define SWIG_MemoryError 1
#define SWIG_IOError 2
#define SWIG_RuntimeError 3
#define SWIG_IndexError 4
#define SWIG_TypeError 5
#define SWIG_DivisionByZero 6
#define SWIG_OverflowError 7
#define SWIG_SyntaxError 8
#define SWIG_ValueError 9
#define SWIG_SystemError 10
#define SWIG_UnknownError 99
%}
#ifdef SWIGTCL8
%{
#define SWIG_exception(a,b) Tcl_SetStringObj(tcl_result,b,-1); return TCL_ERROR
%}
#else
#ifdef SWIGTCL
%{
#define SWIG_exception(a,b) Tcl_SetResult(interp,b,TCL_VOLATILE); return TCL_ERROR
%}
#endif
#endif
#ifdef SWIGPERL5
%{
#define SWIG_exception(a,b) croak(b)
%}
#endif
#ifdef SWIGPERL4
%{
#define SWIG_exception(a,b) fatal(b)
%}
#endif
#ifdef SWIGPYTHON
%{
static void _SWIG_exception(int code, char *msg) {
switch(code) {
case SWIG_MemoryError:
PyErr_SetString(PyExc_MemoryError,msg);
break;
case SWIG_IOError:
PyErr_SetString(PyExc_IOError,msg);
break;
case SWIG_RuntimeError:
PyErr_SetString(PyExc_RuntimeError,msg);
break;
case SWIG_IndexError:
PyErr_SetString(PyExc_IndexError,msg);
break;
case SWIG_TypeError:
PyErr_SetString(PyExc_TypeError,msg);
break;
case SWIG_DivisionByZero:
PyErr_SetString(PyExc_ZeroDivisionError,msg);
break;
case SWIG_OverflowError:
PyErr_SetString(PyExc_OverflowError,msg);
break;
case SWIG_SyntaxError:
PyErr_SetString(PyExc_SyntaxError,msg);
break;
case SWIG_ValueError:
PyErr_SetString(PyExc_ValueError,msg);
break;
case SWIG_SystemError:
PyErr_SetString(PyExc_SystemError,msg);
break;
default:
PyErr_SetString(PyExc_RuntimeError,msg);
break;
}
}
#define SWIG_exception(a,b) _SWIG_exception(a,b); return NULL
%}
#endif
#ifdef SWIGGUILE
%echo %{
exception.i : Guile not currently supported.
%}
#endif

View File

@@ -0,0 +1,4 @@
co::
co RCS/*.i* RCS/*.swg*

View File

@@ -0,0 +1,15 @@
/* -----------------------------------------------------------------------
* swig_lib/guile/guile.swg
*
* Guile configuration file. This file assumes FSF Guile 1.0. It may not
* work with other versions
* ----------------------------------------------------------------------- */
#include "guile/gh.h"
/* Since GUILE seems to be somewhat incomplete, these bindings
are used in the SWIG generated code. To change the Guile
interface, simply change this file */
#define GH_NOT_PASSED SCM_UNDEFINED

View File

@@ -0,0 +1,21 @@
%{
void guile_main(void *closure, int argc, char **argv) {
char buffer[1024];
void SWIG_init();
SWIG_init();
printf("starting Guile...\n");
printf("guile >");
while (fgets(buffer,1024,stdin)) {
gh_eval_str(buffer);
printf("guile >");
}
}
void main(int argc, char **argv) {
gh_enter(argc,argv, guile_main);
}
%}

View File

@@ -0,0 +1,78 @@
//
// $Header$
//
// SWIG file for a simple Guile interpreter
//
/* Revision History
* $Log$
* Revision 1.1 2002/04/29 19:56:52 RD
* Since I have made several changes to SWIG over the years to accomodate
* special cases and other things in wxPython, and since I plan on making
* several more, I've decided to put the SWIG sources in wxPython's CVS
* instead of relying on maintaining patches. This effectivly becomes a
* fork of an obsolete version of SWIG, :-( but since SWIG 1.3 still
* doesn't have some things I rely on in 1.1, not to mention that my
* custom patches would all have to be redone, I felt that this is the
* easier road to take.
*
* Revision 1.1.1.1 1999/02/28 02:00:54 beazley
* Swig1.1
*
* Revision 1.1 1996/05/22 20:02:10 beazley
* Initial revision
*
*/
%{
#include <stdio.h>
GSCM_status guile_init();
int main(int argc, char **argv) {
GSCM_status status;
GSCM_top_level toplev;
char *eval_answer;
char input_str[16384];
int done;
/* start a scheme interpreter */
status = gscm_run_scm(argc, argv, 0, stdout, stderr, guile_init, 0, "#t");
if (status != GSCM_OK) {
fputs(gscm_error_msg(status), stderr);
fputc('\n', stderr);
printf("Error in startup.\n");
exit(1);
}
/* create the top level environment */
status = gscm_create_top_level(&toplev);
if (status != GSCM_OK) {
fputs(gscm_error_msg(status), stderr);
fputc('\n', stderr);
exit(1);
}
/* now sit in a scheme eval loop: I input the expressions, have guile
* evaluate them, and then get another expression.
*/
done = 0;
fprintf(stdout,"Guile > ");
while (!done) {
if (fgets(input_str,16384,stdin) == NULL) {
exit(1);
} else {
if (strncmp(input_str,"quit",4) == 0) exit(1);
status = gscm_eval_str(&eval_answer, toplev, input_str);
fprintf(stdout,"%s\n", eval_answer);
fprintf(stdout,"Guile > ");
}
}
/* now clean up and quit */
gscm_destroy_top_level(toplev);
}
%}

View File

@@ -0,0 +1,64 @@
//
// $Header$
//
// malloc.i
// Dave Beazley
// March 24, 1996
// SWIG file for memory management functions
// (also contained in stdlib.i)
//
/* Revision History
* $Log$
* Revision 1.1 2002/04/29 19:56:49 RD
* Since I have made several changes to SWIG over the years to accomodate
* special cases and other things in wxPython, and since I plan on making
* several more, I've decided to put the SWIG sources in wxPython's CVS
* instead of relying on maintaining patches. This effectivly becomes a
* fork of an obsolete version of SWIG, :-( but since SWIG 1.3 still
* doesn't have some things I rely on in 1.1, not to mention that my
* custom patches would all have to be redone, I felt that this is the
* easier road to take.
*
* Revision 1.1.1.1 1999/02/28 02:00:53 beazley
* Swig1.1
*
* Revision 1.1 1996/05/22 17:27:01 beazley
* Initial revision
*
*/
%module malloc
%{
#include <stdlib.h>
%}
%section "Memory Allocation Module",
pre,info,after,nosort,chop_left=3,chop_right=0,chop_top=0,chop_bottom=0,skip=1
%text %{
%include malloc.i
This module provides access to a few basic C memory management functions.
All functions return void pointers, but realloc() and free() will operate
on any sort of pointer. Sizes should be specified in bytes.
%}
void *calloc(unsigned nobj, unsigned size);
/* Returns a pointer to a space for an array of nobj objects, each with
size bytes. Returns NULL if the request can't be satisfied.
Initializes the space to zero bytes. */
void *malloc(unsigned size);
/* Returns a pointer to space for an object of size bytes. Returns NULL
upon failure. */
void *realloc(void *ptr, unsigned size);
/* Changes the size of the object pointed to by ptr to size bytes.
The contents will be unchanged up the minimum of the old and new
sizes. Returns a pointer to the new space of NULL upon failure,
in which case *ptr is unchanged. */
void free(void *ptr);
/* Deallocates the space pointed to by ptr. Does nothing if ptr is NULL.
ptr must be a space previously allocated by calloc, malloc, or realloc. */

View File

@@ -0,0 +1,120 @@
//
// $Header$
//
// math.i
// Dave Beazley
// March 24, 1996
// SWIG file for floating point operations
//
/* Revision history
* $Log$
* Revision 1.1 2002/04/29 19:56:49 RD
* Since I have made several changes to SWIG over the years to accomodate
* special cases and other things in wxPython, and since I plan on making
* several more, I've decided to put the SWIG sources in wxPython's CVS
* instead of relying on maintaining patches. This effectivly becomes a
* fork of an obsolete version of SWIG, :-( but since SWIG 1.3 still
* doesn't have some things I rely on in 1.1, not to mention that my
* custom patches would all have to be redone, I felt that this is the
* easier road to take.
*
* Revision 1.1.1.1 1999/02/28 02:00:53 beazley
* Swig1.1
*
* Revision 1.1 1996/05/22 17:27:01 beazley
* Initial revision
*
*/
%module math
%{
#include <math.h>
%}
%section "SWIG Math Module",after,info,nosort,pre,chop_left=3,chop_bottom=0,chop_top=0,chop_right=0,skip=1
%text %{
%include math.i
This module provides access to the C math library and contains most
of the functions in <math.h>. Most scripting languages already provide
math support, but in certain cases, this module can provide more
direct access.
%}
%subsection "Functions"
extern double cos(double x);
/* Cosine of x */
extern double sin(double x);
/* Sine of x */
extern double tan(double x);
/* Tangent of x */
extern double acos(double x);
/* Inverse cosine in range [-PI/2,PI/2], x in [-1,1]. */
extern double asin(double x);
/* Inverse sine in range [0,PI], x in [-1,1]. */
extern double atan(double x);
/* Inverse tangent in range [-PI/2,PI/2]. */
extern double atan2(double y, double x);
/* Inverse tangent of y/x in range [-PI,PI]. */
extern double cosh(double x);
/* Hyperbolic cosine of x */
extern double sinh(double x);
/* Hyperbolic sine of x */
extern double tanh(double x);
/* Hyperbolic tangent of x */
extern double exp(double x);
/* Natural exponential function e^x */
extern double log(double x);
/* Natural logarithm ln(x), x > 0 */
extern double log10(double x);
/* Base 10 logarithm, x > 0 */
extern double pow(double x, double y);
/* Power function x^y. */
extern double sqrt(double x);
/* Square root. x >= 0 */
extern double fabs(double x);
/* Absolute value of x */
extern double ceil(double x);
/* Smallest integer not less than x, as a double */
extern double floor(double x);
/* Largest integer not greater than x, as a double */
extern double fmod(double x, double y);
/* Floating-point remainder of x/y, with the same sign as x. */
%subsection "Mathematical constants",noinfo
#define M_E 2.7182818284590452354
#define M_LOG2E 1.4426950408889634074
#define M_LOG10E 0.43429448190325182765
#define M_LN2 0.69314718055994530942
#define M_LN10 2.30258509299404568402
#define M_PI 3.14159265358979323846
#define M_PI_2 1.57079632679489661923
#define M_PI_4 0.78539816339744830962
#define M_1_PI 0.31830988618379067154
#define M_2_PI 0.63661977236758134308
#define M_2_SQRTPI 1.12837916709551257390
#define M_SQRT2 1.41421356237309504880
#define M_SQRT1_2 0.70710678118654752440

View File

@@ -0,0 +1,39 @@
//
// memory.i
// Dave Beazley
// November 30, 1996
// SWIG file for memory operations
//
%module memory
%{
#include <string.h>
%}
%section "Memory Manipulation Module",after,info,nosort,pre,chop_left=3,chop_bottom=0,chop_top=0,chop_right=0,skip=1
%text %{
%include memory.i
This module provides support for a few memory operations from the C
<string.h> library. These functions can be used to manipulate binary
data. s and t are of type void *, cs and ct are both of type const void *.
%}
void *memcpy(void *s, const void *ct, int n);
/* Copy n characters from ct to s, and return s */
void *memmove(void *s, const void *ct, int n);
/* Same as memcpy except that it works even if the objects overlap. */
int memcmp(const void *cs, const void *ct, int n);
/* Compare the first n characters of cs with ct. Returns 0 if
they are equal, <0 if cs < ct, and >0 if cs > ct. */
void *memchr(const void *cs, char c, int n);
/* Returns pointer to the first occurrence of character c in cs. */
void *memset(void *s, char c, int n);
/* Place character c into first n characters of s, return s */

View File

@@ -0,0 +1,56 @@
// SWIG Objective-C configuration file
// Dave Beazley
// Copyright (C) 1997
// This file provides support to Objective-C parsing and
// should be included with just about any Objective-C module
// Base Object class
@interface Object { }
-(char *) name; // Get object name
@end
typedef Object *id; // Make 'id' behave like any other "Object"
// Typemaps to make *id work like kind of like a void pointer
%typemap(python,in) id {
char *temp;
if (!PyString_Check($source)) {
PyErr_SetString(PyExc_TypeError,"Expecting an 'id' in argument $argnum of $name");
return NULL;
}
temp = PyString_AsString($source);
if (SWIG_GetPtr(temp, (void **) &$target, 0)) {
PyErr_SetString(PyExc_TypeError,"Expecting an 'id' in argument $argnum of $name");
return NULL;
}
}
%typemap(tcl,in) id {
if (SWIG_GetPtr($source,(void **) &$target, 0)) {
Tcl_SetResult(interp,"Expecting an 'id' in argument $argnum of $name",TCL_STATIC);
return TCL_ERROR;
}
}
%typemap(tcl8,in) id {
if (SWIG_GetPointerObj(interp, $source, (void **) &$target, 0)) {
Tcl_SetStringObj(result_obj, "Expecting an 'id' in argument $argnum of $name");
}
}
%typemap(perl5,in) id {
if (SWIG_GetPtr($source, (void **) &$target, 0)) {
croak("Expecting an 'id' in argument $argnum of $name");
}
}

View File

@@ -0,0 +1,140 @@
# Generated automatically from Makefile.in by configure.
# ---------------------------------------------------------------
# $Header$
# SWIG Perl5 Makefile
#
# This file can be used to build various Perl5 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
#
# Many portions of this file were created by the SWIG configure
# script and should already reflect your machine.
#----------------------------------------------------------------
SRCS =
CXXSRCS =
OBJCSRCS =
OBJS =
INTERFACE =
WRAPFILE = $(INTERFACE:.i=_wrap.c)
WRAPOBJ = $(INTERFACE:.i=_wrap.o)
TARGET = module.so # Use this kind of target for dynamic loading
#TARGET = myperl # Use this target for static linking
prefix = /usr/local
exec_prefix = ${prefix}
CC = cc
CXX = CC
OBJC = cc -Wno-import # -Wno-import needed for gcc
CFLAGS =
INCLUDE =
LIBS =
# 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 = -perl5
SWIGCC = $(CC)
# SWIG Library files. Uncomment this to staticly rebuild Perl
#SWIGLIB = -static -lperlmain.i
# Rules for creating .o files from source.
COBJS = $(SRCS:.c=.o)
CXXOBJS = $(CXXSRCS:.cxx=.o)
OBJCOBJS = $(OBJCSRCS:.m=.o)
ALLOBJS = $(COBJS) $(CXXOBJS) $(OBJCOBJS) $(OBJS)
# Command that will be used to build the final extension.
BUILD = $(SWIGCC)
# Uncomment the following if you are using dynamic loading
CCSHARED =
BUILD = ld -G
# Uncomment the following if you are using dynamic loading with C++ and
# need to provide additional link libraries (this is not always required).
#DLL_LIBS = -L/usr/local/lib/gcc-lib/sparc-sun-solaris2.5.1/2.7.2 \
-L/usr/local/lib -lg++ -lstdc++ -lgcc
# X11 installation (possibly needed if using Perl-Tk)
XLIB = -L/usr/openwin/lib -lX11
XINCLUDE = -I/usr/openwin/include
# Perl installation
PERL_INCLUDE = -I/usr/local/lib/perl5/5.00503/sun4-solaris/CORE
PERL_LIB = -L/usr/local/lib/perl5/5.00503/sun4-solaris/CORE -lperl
PERL_FLAGS = -Dbool=char -Dexplicit=
# Tcl installation. If using Tk you might need this
TCL_INCLUDE = -I/usr/local/include
TCL_LIB = -L/usr/local/lib
# Build libraries (needed for static builds)
LIBM = -lm
LIBC =
SYSLIBS = $(LIBM) $(LIBC) -lsocket -lnsl -ldl
# Build options (uncomment only one these)
#TK_LIB = $(TCL_LIB) -ltcl -ltk $(XLIB)
BUILD_LIBS = $(LIBS) # Dynamic loading
#BUILD_LIBS = $(PERL_LIB) $(TK_LIB) $(LIBS) $(SYSLIBS) # Static linking
# Compilation rules for non-SWIG components
.SUFFIXES: .c .cxx .m
.c.o:
$(CC) $(CCSHARED) $(CFLAGS) $(INCLUDE) -c $<
.cxx.o:
$(CXX) $(CCSHARED) $(CXXFLAGS) $(INCLUDE) -c $<
.m.o:
$(OBJC) $(CCSHARED) $(CFLAGS) $(INCLUDE) -c $<
# ----------------------------------------------------------------------
# Rules for building the extension
# ----------------------------------------------------------------------
all: $(TARGET)
# Convert the wrapper file into an object file
$(WRAPOBJ) : $(WRAPFILE)
$(SWIGCC) -c $(CCSHARED) $(CFLAGS) $(INCLUDE) $(PERL_INCLUDE) $(PERL_FLAGS) $(WRAPFILE)
$(WRAPFILE) : $(INTERFACE)
$(SWIG) $(SWIGOPT) -o $(WRAPFILE) $(SWIGLIB) $(INTERFACE)
$(TARGET): $(WRAPOBJ) $(ALLOBJS)
$(BUILD) $(WRAPOBJ) $(ALLOBJS) $(BUILD_LIBS) -o $(TARGET)
clean:
rm -f $(COBJS) $(CXXOBJS) $(OBJCOBJS) $(WRAPOBJ) $(WRAPFILE) $(TARGET)

View File

@@ -0,0 +1,139 @@
# ---------------------------------------------------------------
# $Header$
# SWIG Perl5 Makefile
#
# This file can be used to build various Perl5 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
#
# Many portions of this file were created by the SWIG configure
# script and should already reflect your machine.
#----------------------------------------------------------------
SRCS =
CXXSRCS =
OBJCSRCS =
OBJS =
INTERFACE =
WRAPFILE = $(INTERFACE:.i=_wrap.c)
WRAPOBJ = $(INTERFACE:.i=_wrap.o)
TARGET = module@SO@ # Use this kind of target for dynamic loading
#TARGET = myperl # Use this target for static linking
prefix = @prefix@
exec_prefix = @exec_prefix@
CC = @CC@
CXX = @CXX@
OBJC = @CC@ -Wno-import # -Wno-import needed for gcc
CFLAGS =
INCLUDE =
LIBS =
# 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 = -perl5
SWIGCC = $(CC)
# SWIG Library files. Uncomment this to staticly rebuild Perl
#SWIGLIB = -static -lperlmain.i
# Rules for creating .o files from source.
COBJS = $(SRCS:.c=.o)
CXXOBJS = $(CXXSRCS:.cxx=.o)
OBJCOBJS = $(OBJCSRCS:.m=.o)
ALLOBJS = $(COBJS) $(CXXOBJS) $(OBJCOBJS) $(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@
# Uncomment the following if you are using dynamic loading with C++ and
# need to provide additional link libraries (this is not always required).
#DLL_LIBS = -L/usr/local/lib/gcc-lib/sparc-sun-solaris2.5.1/2.7.2 \
-L/usr/local/lib -lg++ -lstdc++ -lgcc
# X11 installation (possibly needed if using Perl-Tk)
XLIB = @XLIBSW@
XINCLUDE = @XINCLUDES@
# Perl installation
PERL_INCLUDE = -I@PERL5EXT@
PERL_LIB = -L@PERL5EXT@ -lperl
PERL_FLAGS = -Dbool=char -Dexplicit=
# Tcl installation. If using Tk you might need this
TCL_INCLUDE = @TCLINCLUDE@
TCL_LIB = @TCLLIB@
# Build libraries (needed for static builds)
LIBM = @LIBM@
LIBC = @LIBC@
SYSLIBS = $(LIBM) $(LIBC) @LIBS@
# Build options (uncomment only one these)
#TK_LIB = $(TCL_LIB) -ltcl -ltk $(XLIB)
BUILD_LIBS = $(LIBS) # Dynamic loading
#BUILD_LIBS = $(PERL_LIB) $(TK_LIB) $(LIBS) $(SYSLIBS) # Static linking
# Compilation rules for non-SWIG components
.SUFFIXES: .c .cxx .m
.c.o:
$(CC) $(CCSHARED) $(CFLAGS) $(INCLUDE) -c $<
.cxx.o:
$(CXX) $(CCSHARED) $(CXXFLAGS) $(INCLUDE) -c $<
.m.o:
$(OBJC) $(CCSHARED) $(CFLAGS) $(INCLUDE) -c $<
# ----------------------------------------------------------------------
# Rules for building the extension
# ----------------------------------------------------------------------
all: $(TARGET)
# Convert the wrapper file into an object file
$(WRAPOBJ) : $(WRAPFILE)
$(SWIGCC) -c $(CCSHARED) $(CFLAGS) $(INCLUDE) $(PERL_INCLUDE) $(PERL_FLAGS) $(WRAPFILE)
$(WRAPFILE) : $(INTERFACE)
$(SWIG) $(SWIGOPT) -o $(WRAPFILE) $(SWIGLIB) $(INTERFACE)
$(TARGET): $(WRAPOBJ) $(ALLOBJS)
$(BUILD) $(WRAPOBJ) $(ALLOBJS) $(BUILD_LIBS) -o $(TARGET)
clean:
rm -f $(COBJS) $(CXXOBJS) $(OBJCOBJS) $(WRAPOBJ) $(WRAPFILE) $(TARGET)

View File

@@ -0,0 +1,21 @@
# File : Makefile.pl
# MakeMaker file for a SWIG module. Use this file if you are
# producing a module for general use or distribution.
#
# 1. Modify the file as appropriate. Replace $module with the
# real name of your module and wrapper file.
# 2. Run perl as 'perl Makefile.pl'
# 3. Type 'make' to build your module
# 4. Type 'make install' to install your module.
#
# See "Programming Perl", 2nd. Ed, for more gory details than
# you ever wanted to know.
use ExtUtils::MakeMaker;
WriteMakefile(
'NAME' => '$module', # Name of your module
'LIBS' => [''], # Custom libraries (if any)
'OBJECT' => '$module_wrap.o' # Object files
);

View File

@@ -0,0 +1,24 @@
/* $Header$ */
/* Implementation : PERL 5 */
#define SWIGPERL
#define SWIGPERL5
#ifdef __cplusplus
/* Needed on some windows machines---since MS plays funny
games with the header files under C++ */
#include <math.h>
#include <stdlib.h>
extern "C" {
#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
/* Get rid of free and malloc defined by perl */
#undef free
#undef malloc
#include <string.h>
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,361 @@
/* Definitions for compiling Perl extensions on a variety of machines */
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
# if defined(_MSC_VER)
# define SWIGEXPORT(a) __declspec(dllexport) a
# else
# if defined(__BORLANDC__)
# define SWIGEXPORT(a) a _export
# else
# define SWIGEXPORT(a) a
# endif
# endif
#else
# define SWIGEXPORT(a) a
#endif
#ifdef PERL_OBJECT
#define MAGIC_PPERL CPerlObj *pPerl = (CPerlObj *) this;
#define MAGIC_CAST (int (CPerlObj::*)(SV *, MAGIC *))
#define SWIGCLASS_STATIC
#else
#define MAGIC_PPERL
#define MAGIC_CAST
#define SWIGCLASS_STATIC static
#endif
#if defined(WIN32) && defined(PERL_OBJECT) && !defined(PerlIO_exportFILE)
#define PerlIO_exportFILE(fh,fl) (FILE*)(fh)
#endif
/* Modifications for newer Perl 5.005 releases */
#if !defined(PERL_REVISION) || ((PERL_REVISION >= 5) && ((PERL_VERSION < 5) || ((PERL_VERSION == 5) && (PERL_SUBVERSION < 50))))
#ifndef PL_sv_yes
#define PL_sv_yes sv_yes
#endif
#ifndef PL_sv_undef
#define PL_sv_undef sv_undef
#endif
#ifndef PL_na
#define PL_na na
#endif
#endif
/******************************************************************************
* Pointer type-checking code
*****************************************************************************/
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef SWIG_NOINCLUDE
extern void SWIG_MakePtr(char *, void *, char *);
#ifndef PERL_OBJECT
extern void SWIG_RegisterMapping(char *, char *, void *(*)(void *));
#else
#define SWIG_RegisterMapping(a,b,c) _SWIG_RegisterMapping(pPerl,a,b,c);
extern void _SWIG_RegisterMapping(CPerlObj *,char *, char *, void *(*)(void *),int);
#endif
#ifndef PERL_OBJECT
extern char *SWIG_GetPtr(SV *, void **, char *);
#else
extern char *_SWIG_GetPtr(CPerlObj *, SV *, void **, char *);
#define SWIG_GetPtr(a,b,c) _SWIG_GetPtr(pPerl,a,b,c)
#endif
#else
#ifdef SWIG_GLOBAL
#define SWIGSTATICRUNTIME(a) SWIGEXPORT(a)
#else
#define SWIGSTATICRUNTIME(a) static a
#endif
/* These are internal variables. Should be static */
typedef struct SwigPtrType {
char *name;
int len;
void *(*cast)(void *);
struct SwigPtrType *next;
} SwigPtrType;
/* Pointer cache structure */
typedef struct {
int stat; /* Status (valid) bit */
SwigPtrType *tp; /* Pointer to type structure */
char name[256]; /* Given datatype name */
char mapped[256]; /* Equivalent name */
} SwigCacheType;
static int SwigPtrMax = 64; /* Max entries that can be currently held */
static int SwigPtrN = 0; /* Current number of entries */
static int SwigPtrSort = 0; /* Status flag indicating sort */
static SwigPtrType *SwigPtrTable = 0; /* Table containing pointer equivalences */
static int SwigStart[256]; /* Table containing starting positions */
/* Cached values */
#define SWIG_CACHESIZE 8
#define SWIG_CACHEMASK 0x7
static SwigCacheType SwigCache[SWIG_CACHESIZE];
static int SwigCacheIndex = 0;
static int SwigLastCache = 0;
/* Sort comparison function */
static int swigsort(const void *data1, const void *data2) {
SwigPtrType *d1 = (SwigPtrType *) data1;
SwigPtrType *d2 = (SwigPtrType *) data2;
return strcmp(d1->name,d2->name);
}
/* Binary Search function */
static int swigcmp(const void *key, const void *data) {
char *k = (char *) key;
SwigPtrType *d = (SwigPtrType *) data;
return strncmp(k,d->name,d->len);
}
/* Register a new datatype with the type-checker */
#ifndef PERL_OBJECT
SWIGSTATICRUNTIME(void)
SWIG_RegisterMapping(char *origtype, char *newtype, void *(*cast)(void *)) {
#else
#define SWIG_RegisterMapping(a,b,c) _SWIG_RegisterMapping(pPerl, a,b,c)
SWIGSTATICRUNTIME(void)
_SWIG_RegisterMapping(CPerlObj *pPerl, char *origtype, char *newtype, void *(*cast)(void *)) {
#endif
int i;
SwigPtrType *t = 0, *t1;
if (!SwigPtrTable) {
SwigPtrTable = (SwigPtrType *) malloc(SwigPtrMax*sizeof(SwigPtrType));
SwigPtrN = 0;
}
if (SwigPtrN >= SwigPtrMax) {
SwigPtrMax = 2*SwigPtrMax;
SwigPtrTable = (SwigPtrType *) realloc(SwigPtrTable,SwigPtrMax*sizeof(SwigPtrType));
}
for (i = 0; i < SwigPtrN; i++)
if (strcmp(SwigPtrTable[i].name,origtype) == 0) {
t = &SwigPtrTable[i];
break;
}
if (!t) {
t = &SwigPtrTable[SwigPtrN];
t->name = origtype;
t->len = strlen(t->name);
t->cast = 0;
t->next = 0;
SwigPtrN++;
}
while (t->next) {
if (strcmp(t->name,newtype) == 0) {
if (cast) t->cast = cast;
return;
}
t = t->next;
}
t1 = (SwigPtrType *) malloc(sizeof(SwigPtrType));
t1->name = newtype;
t1->len = strlen(t1->name);
t1->cast = cast;
t1->next = 0;
t->next = t1;
SwigPtrSort = 0;
}
/* Make a pointer value string */
SWIGSTATICRUNTIME(void)
SWIG_MakePtr(char *_c, const void *_ptr, char *type) {
static char _hex[16] =
{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f'};
unsigned long _p, _s;
char _result[20], *_r; /* Note : a 64-bit hex number = 16 digits */
_r = _result;
_p = (unsigned long) _ptr;
if (_p > 0) {
while (_p > 0) {
_s = _p & 0xf;
*(_r++) = _hex[_s];
_p = _p >> 4;
}
*_r = '_';
while (_r >= _result)
*(_c++) = *(_r--);
} else {
strcpy (_c, "NULL");
}
if (_ptr)
strcpy (_c, type);
}
/* Function for getting a pointer value */
#ifndef PERL_OBJECT
SWIGSTATICRUNTIME(char *)
SWIG_GetPtr(SV *sv, void **ptr, char *_t)
#else
#define SWIG_GetPtr(a,b,c) _SWIG_GetPtr(pPerl,a,b,c)
SWIGSTATICRUNTIME(char *)
_SWIG_GetPtr(CPerlObj *pPerl, SV *sv, void **ptr, char *_t)
#endif
{
char temp_type[256];
char *name,*_c;
int len,i,start,end;
IV tmp;
SwigPtrType *sp,*tp;
SwigCacheType *cache;
/* If magical, apply more magic */
if (SvGMAGICAL(sv))
mg_get(sv);
/* Check to see if this is an object */
if (sv_isobject(sv)) {
SV *tsv = (SV*) SvRV(sv);
if ((SvTYPE(tsv) == SVt_PVHV)) {
MAGIC *mg;
if (SvMAGICAL(tsv)) {
mg = mg_find(tsv,'P');
if (mg) {
SV *rsv = mg->mg_obj;
if (sv_isobject(rsv)) {
tmp = SvIV((SV*)SvRV(rsv));
}
}
} else {
return "Not a valid pointer value";
}
} else {
tmp = SvIV((SV*)SvRV(sv));
}
if (!_t) {
*(ptr) = (void *) tmp;
return (char *) 0;
}
} else if (! SvOK(sv)) { /* Check for undef */
*(ptr) = (void *) 0;
return (char *) 0;
} else if (SvTYPE(sv) == SVt_RV) { /* Check for NULL pointer */
*(ptr) = (void *) 0;
if (!SvROK(sv))
return (char *) 0;
else
return "Not a valid pointer value";
} else { /* Don't know what it is */
*(ptr) = (void *) 0;
return "Not a valid pointer value";
}
if (_t) {
/* Now see if the types match */
if (!sv_isa(sv,_t)) {
_c = HvNAME(SvSTASH(SvRV(sv)));
if (!SwigPtrSort) {
qsort((void *) SwigPtrTable, SwigPtrN, sizeof(SwigPtrType), swigsort);
for (i = 0; i < 256; i++) {
SwigStart[i] = SwigPtrN;
}
for (i = SwigPtrN-1; i >= 0; i--) {
SwigStart[SwigPtrTable[i].name[0]] = i;
}
for (i = 255; i >= 1; i--) {
if (SwigStart[i-1] > SwigStart[i])
SwigStart[i-1] = SwigStart[i];
}
SwigPtrSort = 1;
for (i = 0; i < SWIG_CACHESIZE; i++)
SwigCache[i].stat = 0;
}
/* First check cache for matches. Uses last cache value as starting point */
cache = &SwigCache[SwigLastCache];
for (i = 0; i < SWIG_CACHESIZE; i++) {
if (cache->stat) {
if (strcmp(_t,cache->name) == 0) {
if (strcmp(_c,cache->mapped) == 0) {
cache->stat++;
*ptr = (void *) tmp;
if (cache->tp->cast) *ptr = (*(cache->tp->cast))(*ptr);
return (char *) 0;
}
}
}
SwigLastCache = (SwigLastCache+1) & SWIG_CACHEMASK;
if (!SwigLastCache) cache = SwigCache;
else cache++;
}
start = SwigStart[_t[0]];
end = SwigStart[_t[0]+1];
sp = &SwigPtrTable[start];
while (start < end) {
if (swigcmp(_t,sp) == 0) break;
sp++;
start++;
}
if (start > end) sp = 0;
while (start <= end) {
if (swigcmp(_t,sp) == 0) {
name = sp->name;
len = sp->len;
tp = sp->next;
while(tp) {
if (tp->len >= 255) {
return _c;
}
strcpy(temp_type,tp->name);
strncat(temp_type,_t+len,255-tp->len);
if (sv_isa(sv,temp_type)) {
/* Get pointer value */
*ptr = (void *) tmp;
if (tp->cast) *ptr = (*(tp->cast))(*ptr);
strcpy(SwigCache[SwigCacheIndex].mapped,_c);
strcpy(SwigCache[SwigCacheIndex].name,_t);
SwigCache[SwigCacheIndex].stat = 1;
SwigCache[SwigCacheIndex].tp = tp;
SwigCacheIndex = SwigCacheIndex & SWIG_CACHEMASK;
return (char *) 0;
}
tp = tp->next;
}
}
sp++;
start++;
}
/* Didn't find any sort of match for this data.
Get the pointer value and return the received type */
*ptr = (void *) tmp;
return _c;
} else {
/* Found a match on the first try. Return pointer value */
*ptr = (void *) tmp;
return (char *) 0;
}
}
*ptr = (void *) tmp;
return (char *) 0;
}
#endif
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,19 @@
/* Magic variable code */
#ifndef PERL_OBJECT
#define swig_create_magic(s,a,b,c) _swig_create_magic(s,a,b,c)
static void _swig_create_magic(SV *sv, char *name, int (*set)(SV *, MAGIC *), int (*get)(SV *,MAGIC *)) {
#else
#define swig_create_magic(s,a,b,c) _swig_create_magic(pPerl,s,a,b,c)
static void _swig_create_magic(CPerlObj *pPerl, SV *sv, char *name, int (CPerlObj::*set)(SV *, MAGIC *), int (CPerlObj::*get)(SV *, MAGIC *)) {
#endif
MAGIC *mg;
sv_magic(sv,sv,'U',name,strlen(name));
mg = mg_find(sv,'U');
mg->mg_virtual = (MGVTBL *) malloc(sizeof(MGVTBL));
mg->mg_virtual->svt_get = get;
mg->mg_virtual->svt_set = set;
mg->mg_virtual->svt_len = 0;
mg->mg_virtual->svt_clear = 0;
mg->mg_virtual->svt_free = 0;
}

View File

@@ -0,0 +1,80 @@
// $Header$
// Code to statically rebuild perl5.
//
#ifdef AUTODOC
%subsection "perlmain.i"
%text %{
This module provides support for building a new version of the
Perl executable. This will be necessary on systems that do
not support shared libraries and may be necessary with C++
extensions.
This module may only build a stripped down version of the
Perl executable. Thus, it may be necessary (or desirable)
to hand-edit this file for your particular application. To
do this, simply copy this file from swig_lib/perl5/perlmain.i
to your working directory and make the appropriate modifications.
This library file works with Perl 5.003. It may work with earlier
versions, but it hasn't been tested. As far as I know, this
library is C++ safe.
%}
#endif
%{
static void xs_init _((void));
static PerlInterpreter *my_perl;
int perl_eval(char *string) {
char *argv[2];
argv[0] = string;
argv[1] = (char *) 0;
return perl_call_argv("eval",0,argv);
}
int
main(int argc, char **argv, char **env)
{
int exitstatus;
my_perl = perl_alloc();
if (!my_perl)
exit(1);
perl_construct( my_perl );
exitstatus = perl_parse( my_perl, xs_init, argc, argv, (char **) NULL );
if (exitstatus)
exit( exitstatus );
/* Initialize all of the module variables */
exitstatus = perl_run( my_perl );
perl_destruct( my_perl );
perl_free( my_perl );
exit( exitstatus );
}
/* Register any extra external extensions */
/* Do not delete this line--writemain depends on it */
/* EXTERN_C void boot_DynaLoader _((CV* cv)); */
static void
xs_init()
{
/* dXSUB_SYS; */
char *file = __FILE__;
{
/* newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file); */
newXS(SWIG_name, SWIG_init, file);
#ifdef SWIGMODINIT
SWIGMODINIT
#endif
}
}
%}

View File

@@ -0,0 +1,650 @@
//
// SWIG pointer conversion and utility library
//
// Dave Beazley
// April 19, 1997
//
// Perl5 specific implementation. This file is included
// by the file ../pointer.i
%{
#ifdef WIN32
#undef isspace
#define isspace(c) (c == ' ')
#endif
/*------------------------------------------------------------------
ptrcast(value,type)
Constructs a new pointer value. Value may either be a string
or an integer. Type is a string corresponding to either the
C datatype or mangled datatype.
ptrcast(0,"Vector *")
or
ptrcast(0,"Vector_p")
------------------------------------------------------------------ */
#ifdef PERL_OBJECT
static SV *_ptrcast(CPerlObj *pPerl, SV *_PTRVALUE, char *type) {
#define ptrcast(a,b) _ptrcast(pPerl,a,b)
#else
static SV *_ptrcast(SV *_PTRVALUE, char *type) {
#define ptrcast(a,b) _ptrcast(a,b)
#endif
char *r,*s;
void *ptr;
SV *obj;
char *typestr,*c;
/* Produce a "mangled" version of the type string. */
typestr = (char *) malloc(strlen(type)+20);
/* Go through and munge the typestring */
r = typestr;
c = type;
while (*c) {
if (!isspace(*c)) {
if ((*c == '*') || (*c == '&')) {
strcpy(r,"Ptr");
r+=3;
} else *(r++) = *c;
}
c++;
}
*(r++) = 0;
/* Check to see if the input value is an integer */
if (SvIOK(_PTRVALUE)) {
ptr = (void *) SvIV(_PTRVALUE);
/* Received a numerical value. Make a pointer out of it */
obj = sv_newmortal();
sv_setref_pv(obj,typestr,ptr);
} else if (sv_isobject(_PTRVALUE)) {
/* Have a real pointer value now. Try to strip out the pointer value */
/* Now extract the pointer value */
if (!SWIG_GetPtr(_PTRVALUE,&ptr,0)) {
obj = sv_newmortal();
sv_setref_pv(obj,typestr,ptr);
}
} else {
croak("ptrcast(). Not a reference.");
}
free(typestr);
return obj;
}
/*------------------------------------------------------------------
ptrvalue(ptr,type = 0)
Attempts to dereference a pointer value. If type is given, it
will try to use that type. Otherwise, this function will attempt
to "guess" the proper datatype by checking against all of the
builtin C datatypes.
------------------------------------------------------------------ */
#ifdef PERL_OBJECT
static SV *_ptrvalue(CPerlObj *pPerl,SV *_PTRVALUE, int index, char *type) {
#define ptrvalue(a,b,c) _ptrvalue(pPerl,a,b,c)
#else
static SV *_ptrvalue(SV *_PTRVALUE, int index, char *type) {
#define ptrvalue(a,b,c) _ptrvalue(a,b,c)
#endif
void *ptr;
SV *obj = 0;
if (SWIG_GetPtr(_PTRVALUE,&ptr,0)) {
croak("Type error it ptrvalue. Argument is not a valid pointer value.");
} else {
/* If no datatype was passed, try a few common datatypes first */
if (!type) {
/* No datatype was passed. Type to figure out if it's a common one */
if (!SWIG_GetPtr(_PTRVALUE,&ptr,"intPtr")) {
type = "int";
} else if (!SWIG_GetPtr(_PTRVALUE,&ptr,"doublePtr")) {
type = "double";
} else if (!SWIG_GetPtr(_PTRVALUE,&ptr,"shortPtr")) {
type = "short";
} else if (!SWIG_GetPtr(_PTRVALUE,&ptr,"longPtr")) {
type = "long";
} else if (!SWIG_GetPtr(_PTRVALUE,&ptr,"floatPtr")) {
type = "float";
} else if (!SWIG_GetPtr(_PTRVALUE,&ptr,"charPtr")) {
type = "char";
} else if (!SWIG_GetPtr(_PTRVALUE,&ptr,"charPtrPtr")) {
type = "char *";
} else {
type = "unknown";
}
}
if (!ptr) {
croak("Unable to dereference NULL pointer.");
return 0;
}
/* Now we have a datatype. Try to figure out what to do about it */
if (strcmp(type,"int") == 0) {
obj = sv_newmortal();
sv_setiv(obj,(IV) *(((int *) ptr) + index));
} else if (strcmp(type,"double") == 0) {
obj = sv_newmortal();
sv_setnv(obj,(double) *(((double *) ptr)+index));
} else if (strcmp(type,"short") == 0) {
obj = sv_newmortal();
sv_setiv(obj,(IV) *(((short *) ptr) + index));
} else if (strcmp(type,"long") == 0) {
obj = sv_newmortal();
sv_setiv(obj,(IV) *(((long *) ptr) + index));
} else if (strcmp(type,"float") == 0) {
obj = sv_newmortal();
sv_setnv(obj,(double) *(((float *) ptr)+index));
} else if (strcmp(type,"char") == 0) {
obj = sv_newmortal();
sv_setpv(obj,((char *) ptr)+index);
} else if (strcmp(type,"char *") == 0) {
char *c = *(((char **) ptr)+index);
obj = sv_newmortal();
if (c)
sv_setpv(obj,c);
else
sv_setpv(obj,"NULL");
} else {
croak("Unable to dereference unsupported datatype.");
obj = 0;
}
}
return obj;
}
/*------------------------------------------------------------------
ptrcreate(type,value = 0,numelements = 1)
Attempts to create a new object of given type. Type must be
a basic C datatype. Will not create complex objects.
------------------------------------------------------------------ */
#ifdef PERL_OBJECT
static SV *_ptrcreate(CPerlObj *pPerl, char *type, SV *value, int numelements) {
#define ptrcreate(a,b,c) _ptrcreate(pPerl,a,b,c)
#else
static SV *_ptrcreate(char *type, SV *value, int numelements) {
#define ptrcreate(a,b,c) _ptrcreate(a,b,c)
#endif
void *ptr;
SV *obj;
int sz;
char *cast;
char temp[40];
/* Check the type string against a variety of possibilities */
if (strcmp(type,"int") == 0) {
sz = sizeof(int)*numelements;
cast = "intPtr";
} else if (strcmp(type,"short") == 0) {
sz = sizeof(short)*numelements;
cast = "shortPtr";
} else if (strcmp(type,"long") == 0) {
sz = sizeof(long)*numelements;
cast = "longPtr";
} else if (strcmp(type,"double") == 0) {
sz = sizeof(double)*numelements;
cast = "doublePtr";
} else if (strcmp(type,"float") == 0) {
sz = sizeof(float)*numelements;
cast = "floatPtr";
} else if (strcmp(type,"char") == 0) {
sz = sizeof(char)*numelements;
cast = "charPtr";
} else if (strcmp(type,"char *") == 0) {
sz = sizeof(char *)*(numelements+1);
cast = "charPtrPtr";
} else if (strcmp(type,"void") == 0) {
sz = numelements;
cast = "voidPtr";
} else {
croak("Unable to create unknown datatype.");
return 0;
}
/* Create the new object */
ptr = (void *) malloc(sz);
if (!ptr) {
croak("Out of memory in ptrcreate.");
return 0;
}
/* Now try to set its default value */
if (value) {
if (strcmp(type,"int") == 0) {
int *ip,i,ivalue;
ivalue = (int) SvIV(value);
ip = (int *) ptr;
for (i = 0; i < numelements; i++)
ip[i] = ivalue;
} else if (strcmp(type,"short") == 0) {
short *ip,ivalue;
int i;
ivalue = (short) SvIV(value);
ip = (short *) ptr;
for (i = 0; i < numelements; i++)
ip[i] = ivalue;
} else if (strcmp(type,"long") == 0) {
long *ip,ivalue;
int i;
ivalue = (long) SvIV(value);
ip = (long *) ptr;
for (i = 0; i < numelements; i++)
ip[i] = ivalue;
} else if (strcmp(type,"double") == 0) {
double *ip,ivalue;
int i;
ivalue = (double) SvNV(value);
ip = (double *) ptr;
for (i = 0; i < numelements; i++)
ip[i] = ivalue;
} else if (strcmp(type,"float") == 0) {
float *ip,ivalue;
int i;
ivalue = (float) SvNV(value);
ip = (float *) ptr;
for (i = 0; i < numelements; i++)
ip[i] = ivalue;
} else if (strcmp(type,"char") == 0) {
char *ip,*ivalue;
ivalue = (char *) SvPV(value,PL_na);
ip = (char *) ptr;
strncpy(ip,ivalue,numelements-1);
} else if (strcmp(type,"char *") == 0) {
char **ip, *ivalue;
int i;
ivalue = (char *) SvPV(value,PL_na);
ip = (char **) ptr;
for (i = 0; i < numelements; i++) {
if (ivalue) {
ip[i] = (char *) malloc(strlen(ivalue)+1);
strcpy(ip[i],ivalue);
} else {
ip[i] = 0;
}
}
ip[numelements] = 0;
}
}
/* Create the pointer value */
SWIG_MakePtr(temp,ptr,cast);
obj = sv_newmortal();
sv_setref_pv(obj,cast,ptr);
return obj;
}
/*------------------------------------------------------------------
ptrset(ptr,value,index = 0,type = 0)
Attempts to set the value of a pointer variable. If type is
given, we will use that type. Otherwise, we'll guess the datatype.
------------------------------------------------------------------ */
#ifdef PERL_OBJECT
static void _ptrset(CPerlObj *pPerl,SV *_PTRVALUE, SV *value, int index, char *type) {
#define ptrset(a,b,c,d) _ptrset(pPerl,a,b,c,d)
#else
static void _ptrset(SV *_PTRVALUE, SV *value, int index, char *type) {
#define ptrset(a,b,c,d) _ptrset(a,b,c,d)
#endif
void *ptr;
SV *obj;
if (SWIG_GetPtr(_PTRVALUE,&ptr,0)) {
croak("Type error in ptrset. Argument is not a valid pointer value.");
return;
}
/* If no datatype was passed, try a few common datatypes first */
if (!type) {
/* No datatype was passed. Type to figure out if it's a common one */
if (!SWIG_GetPtr(_PTRVALUE,&ptr,"intPtr")) {
type = "int";
} else if (!SWIG_GetPtr(_PTRVALUE,&ptr,"doublePtr")) {
type = "double";
} else if (!SWIG_GetPtr(_PTRVALUE,&ptr,"shortPtr")) {
type = "short";
} else if (!SWIG_GetPtr(_PTRVALUE,&ptr,"longPtr")) {
type = "long";
} else if (!SWIG_GetPtr(_PTRVALUE,&ptr,"floatPtr")) {
type = "float";
} else if (!SWIG_GetPtr(_PTRVALUE,&ptr,"charPtr")) {
type = "char";
} else if (!SWIG_GetPtr(_PTRVALUE,&ptr,"charPtrPtr")) {
type = "char *";
} else {
type = "unknown";
}
}
if (!ptr) {
croak("Unable to set NULL pointer.");
return;
}
/* Now we have a datatype. Try to figure out what to do about it */
if (strcmp(type,"int") == 0) {
*(((int *) ptr)+index) = (int) SvIV(value);
} else if (strcmp(type,"double") == 0) {
*(((double *) ptr)+index) = (double) SvNV(value);
} else if (strcmp(type,"short") == 0) {
*(((short *) ptr)+index) = (short) SvIV(value);
} else if (strcmp(type,"long") == 0) {
*(((long *) ptr)+index) = (long) SvIV(value);
} else if (strcmp(type,"float") == 0) {
*(((float *) ptr)+index) = (float) SvNV(value);
} else if (strcmp(type,"char") == 0) {
char *c = SvPV(value,PL_na);
strcpy(((char *) ptr)+index, c);
} else if (strcmp(type,"char *") == 0) {
char *c = SvPV(value,PL_na);
char **ca = (char **) ptr;
if (ca[index]) free(ca[index]);
if (strcmp(c,"NULL") == 0) {
ca[index] = 0;
} else {
ca[index] = (char *) malloc(strlen(c)+1);
strcpy(ca[index],c);
}
} else {
croak("Unable to set unsupported datatype.");
return;
}
}
/*------------------------------------------------------------------
ptradd(ptr,offset)
Adds a value to an existing pointer value. Will do a type-dependent
add for basic datatypes. For other datatypes, will do a byte-add.
------------------------------------------------------------------ */
#ifdef PERL_OBJECT
static SV *_ptradd(CPerlObj *pPerl, SV *_PTRVALUE, int offset) {
#define ptradd(a,b) _ptradd(pPerl,a,b)
#else
static SV *_ptradd(SV *_PTRVALUE, int offset) {
#define ptradd(a,b) _ptradd(a,b)
#endif
void *ptr,*junk;
SV *obj;
char *type;
/* Try to handle a few common datatypes first */
if (!SWIG_GetPtr(_PTRVALUE,&ptr,"intPtr")) {
ptr = (void *) (((int *) ptr) + offset);
} else if (!SWIG_GetPtr(_PTRVALUE,&ptr,"doublePtr")) {
ptr = (void *) (((double *) ptr) + offset);
} else if (!SWIG_GetPtr(_PTRVALUE,&ptr,"shortPtr")) {
ptr = (void *) (((short *) ptr) + offset);
} else if (!SWIG_GetPtr(_PTRVALUE,&ptr,"longPtr")) {
ptr = (void *) (((long *) ptr) + offset);
} else if (!SWIG_GetPtr(_PTRVALUE,&ptr,"floatPtr")) {
ptr = (void *) (((float *) ptr) + offset);
} else if (!SWIG_GetPtr(_PTRVALUE,&ptr,"charPtr")) {
ptr = (void *) (((char *) ptr) + offset);
} else if (!SWIG_GetPtr(_PTRVALUE,&ptr,0)) {
ptr = (void *) (((char *) ptr) + offset);
} else {
croak("Type error in ptradd. Argument is not a valid pointer value.");
return 0;
}
type = SWIG_GetPtr(_PTRVALUE,&junk,"INVALID POINTER");
obj = sv_newmortal();
sv_setref_pv(obj,type,ptr);
return obj;
}
/*------------------------------------------------------------------
ptrmap(type1,type2)
Allows a mapping between type1 and type2. (Like a typedef)
------------------------------------------------------------------ */
#ifdef PERL_OBJECT
static void _ptrmap(CPerlObj *pPerl,char *type1, char *type2) {
#define ptrmap(a,b) _ptrmap(pPerl,a,b)
#else
static void _ptrmap(char *type1, char *type2) {
#define ptrmap(a,b) _ptrmap(a,b)
#endif
char *typestr1,*typestr2,*c,*r;
/* Produce a "mangled" version of the type string. */
typestr1 = (char *) malloc(strlen(type1)+20);
/* Go through and munge the typestring */
r = typestr1;
*(r++) = '_';
c = type1;
while (*c) {
if (!isspace(*c)) {
if ((*c == '*') || (*c == '&')) {
strcpy(r,"Ptr");
r+=3;
}
else *(r++) = *c;
}
c++;
}
*(r++) = 0;
typestr2 = (char *) malloc(strlen(type2)+20);
/* Go through and munge the typestring */
r = typestr2;
*(r++) = '_';
c = type2;
while (*c) {
if (!isspace(*c)) {
if ((*c == '*') || (*c == '&')) {
strcpy(r,"Ptr");
r+=3;
}
else *(r++) = *c;
}
c++;
}
*(r++) = 0;
SWIG_RegisterMapping(typestr1,typestr2,0);
SWIG_RegisterMapping(typestr2,typestr1,0);
}
/*------------------------------------------------------------------
ptrfree(ptr)
Destroys a pointer value
------------------------------------------------------------------ */
#ifdef PERL_OBJECT
void _ptrfree(CPerlObj *pPerl, SV *_PTRVALUE) {
#define ptrfree(a) _ptrfree(pPerl, a)
#else
void _ptrfree(SV *_PTRVALUE) {
#define ptrfree(a) _ptrfree(a)
#endif
void *ptr, *junk;
if (SWIG_GetPtr(_PTRVALUE,&ptr,0)) {
croak("Type error in ptrfree. Argument is not a valid pointer value.");
return;
}
/* Check to see if this pointer is a char ** */
if (!SWIG_GetPtr(_PTRVALUE,&junk,"charPtrPtr")) {
char **c = (char **) ptr;
if (c) {
int i = 0;
while (c[i]) {
free(c[i]);
i++;
}
}
}
if (ptr)
free((char *) ptr);
}
%}
%typemap(perl5,in) SV *ptr, SV *value {
$target = $source;
}
%typemap(perl5,out) SV *ptrcast,
SV *ptrvalue,
SV *ptrcreate,
SV *ptradd
{
$target = $source;
argvi++;
}
%typemap(perl5,ret) int ptrset {
if ($source == -1) return NULL;
}
SV *ptrcast(SV *ptr, char *type);
// Casts a pointer ptr to a new datatype given by the string type.
// type may be either the SWIG generated representation of a datatype
// or the C representation. For example :
//
// ptrcast($ptr,"doublePtr"); # Perl5 representation
// ptrcast($ptr,"double *"); # C representation
//
// A new pointer value is returned. ptr may also be an integer
// value in which case the value will be used to set the pointer
// value. For example :
//
// $a = ptrcast(0,"VectorPtr");
//
// Will create a NULL pointer of type "VectorPtr"
//
// The casting operation is sensitive to formatting. As a result,
// "double *" is different than "double*". As a result of thumb,
// there should always be exactly one space between the C datatype
// and any pointer specifiers (*).
SV *ptrvalue(SV *ptr, int index = 0, char *type = 0);
// Returns the value that a pointer is pointing to (ie. dereferencing).
// The type is automatically inferred by the pointer type--thus, an
// integer pointer will return an integer, a double will return a double,
// and so on. The index and type fields are optional parameters. When
// an index is specified, this function returns the value of ptr[index].
// This allows array access. When a type is specified, it overrides
// the given pointer type. Examples :
//
// ptrvalue($a) # Returns the value *a
// ptrvalue($a,10) # Returns the value a[10]
// ptrvalue($a,10,"double") # Returns a[10] assuming a is a double *
void ptrset(SV *ptr, SV *value, int index = 0, char *type = 0);
// Sets the value pointed to by a pointer. The type is automatically
// inferred from the pointer type so this function will work for
// integers, floats, doubles, etc... The index and type fields are
// optional. When an index is given, it provides array access. When
// type is specified, it overrides the given pointer type. Examples :
//
// ptrset($a,3) # Sets the value *a = 3
// ptrset($a,3,10) # Sets a[10] = 3
// ptrset($a,3,10,"int") # Sets a[10] = 3 assuming a is a int *
SV *ptrcreate(char *type, SV *value = 0, int nitems = 1);
// Creates a new object and returns a pointer to it. This function
// can be used to create various kinds of objects for use in C functions.
// type specifies the basic C datatype to create and value is an
// optional parameter that can be used to set the initial value of the
// object. nitems is an optional parameter that can be used to create
// an array. This function results in a memory allocation using
// malloc(). Examples :
//
// $a = ptrcreate("double") # Create a new double, return pointer
// $a = ptrcreate("int",7) # Create an integer, set value to 7
// $a = ptrcreate("int",0,1000) # Create an integer array with initial
// # values all set to zero
//
// This function only recognizes a few common C datatypes as listed below :
//
// int, short, long, float, double, char, char *, void
//
// All other datatypes will result in an error. However, other
// datatypes can be created by using the ptrcast function. For
// example:
//
// $a = ptrcast(ptrcreate("int",0,100),"unsigned int *")
void ptrfree(SV *ptr);
// Destroys the memory pointed to by ptr. This function calls free()
// and should only be used with objects created by ptrcreate(). Since
// this function calls free, it may work with other objects, but this
// is generally discouraged unless you absolutely know what you're
// doing.
SV *ptradd(SV *ptr, int offset);
// Adds a value to the current pointer value. For the C datatypes of
// int, short, long, float, double, and char, the offset value is the
// number of objects and works in exactly the same manner as in C. For
// example, the following code steps through the elements of an array
//
// $a = ptrcreate("double",0,100); # Create an array double a[100]
// $b = $a;
// for ($i = 0; $i < 100; $i++) {
// ptrset($b,0.0025*$i); # set *b = 0.0025*i
// $b = ptradd($b,1); # b++ (go to next double)
// }
//
// In this case, adding one to b goes to the next double.
//
// For all other datatypes (including all complex datatypes), the
// offset corresponds to bytes. This function does not perform any
// bounds checking and negative offsets are perfectly legal.
void ptrmap(char *type1, char *type2);
// This is a rarely used function that performs essentially the same
// operation as a C typedef. To manage datatypes at run-time, SWIG
// modules manage an internal symbol table of type mappings. This
// table keeps track of which types are equivalent to each other. The
// ptrmap() function provides a mechanism for scripts to add symbols
// to this table. For example :
//
// ptrmap("doublePtr","RealPtr");
//
// would make the types "doublePtr" and "RealPtr" equivalent to each
// other. Pointers of either type could now be used interchangably.
//
// Normally this function is not needed, but it can be used to
// circumvent SWIG's normal type-checking behavior or to work around
// weird type-handling problems.

View File

@@ -0,0 +1,475 @@
//
// SWIG Typemap library
// Dave Beazley
// May 5, 1997
//
// Perl5 implementation
//
// This library provides standard typemaps for modifying SWIG's behavior.
// With enough entries in this file, I hope that very few people actually
// ever need to write a typemap.
//
#ifdef AUTODOC
%section "Typemap Library (Perl 5)",info,after,pre,nosort,skip=1,chop_left=3,chop_right=0,chop_top=0,chop_bottom=0
%text %{
%include typemaps.i
The SWIG typemap library provides a language independent mechanism for
supporting output arguments, input values, and other C function
calling mechanisms. The primary use of the library is to provide a
better interface to certain C function--especially those involving
pointers.
%}
#endif
// ------------------------------------------------------------------------
// Pointer handling
//
// These mappings provide support for input/output arguments and common
// uses for C/C++ pointers.
// ------------------------------------------------------------------------
// INPUT typemaps.
// These remap a C pointer to be an "INPUT" value which is passed by value
// instead of reference.
#ifdef AUTODOC
%subsection "Input Methods"
%text %{
The following methods can be applied to turn a pointer into a simple
"input" value. That is, instead of passing a pointer to an object,
you would use a real value instead.
int *INPUT
short *INPUT
long *INPUT
unsigned int *INPUT
unsigned short *INPUT
unsigned long *INPUT
unsigned char *INPUT
float *INPUT
double *INPUT
To use these, suppose you had a C function like this :
double fadd(double *a, double *b) {
return *a+*b;
}
You could wrap it with SWIG as follows :
%include typemaps.i
double fadd(double *INPUT, double *INPUT);
or you can use the %apply directive :
%include typemaps.i
%apply double *INPUT { double *a, double *b };
double fadd(double *a, double *b);
%}
#endif
%typemap(perl5,in) double *INPUT(double temp)
{
temp = (double) SvNV($source);
$target = &temp;
}
%typemap(perl5,in) float *INPUT(float temp)
{
temp = (float) SvNV($source);
$target = &temp;
}
%typemap(perl5,in) int *INPUT(int temp)
{
temp = (int) SvIV($source);
$target = &temp;
}
%typemap(perl5,in) short *INPUT(short temp)
{
temp = (short) SvIV($source);
$target = &temp;
}
%typemap(perl5,in) long *INPUT(long temp)
{
temp = (long) SvIV($source);
$target = &temp;
}
%typemap(perl5,in) unsigned int *INPUT(unsigned int temp)
{
temp = (unsigned int) SvIV($source);
$target = &temp;
}
%typemap(perl5,in) unsigned short *INPUT(unsigned short temp)
{
temp = (unsigned short) SvIV($source);
$target = &temp;
}
%typemap(perl5,in) unsigned long *INPUT(unsigned long temp)
{
temp = (unsigned long) SvIV($source);
$target = &temp;
}
%typemap(perl5,in) unsigned char *INPUT(unsigned char temp)
{
temp = (unsigned char) SvIV($source);
$target = &temp;
}
// OUTPUT typemaps. These typemaps are used for parameters that
// are output only. The output value is appended to the result as
// a list element.
#ifdef AUTODOC
%subsection "Output Methods"
%text %{
The following methods can be applied to turn a pointer into an "output"
value. When calling a function, no input value would be given for
a parameter, but an output value would be returned. In the case of
multiple output values, functions will return a Perl array.
int *OUTPUT
short *OUTPUT
long *OUTPUT
unsigned int *OUTPUT
unsigned short *OUTPUT
unsigned long *OUTPUT
unsigned char *OUTPUT
float *OUTPUT
double *OUTPUT
For example, suppose you were trying to wrap the modf() function in the
C math library which splits x into integral and fractional parts (and
returns the integer part in one of its parameters).K:
double modf(double x, double *ip);
You could wrap it with SWIG as follows :
%include typemaps.i
double modf(double x, double *OUTPUT);
or you can use the %apply directive :
%include typemaps.i
%apply double *OUTPUT { double *ip };
double modf(double x, double *ip);
The Perl output of the function would be an array containing both
output values.
%}
#endif
// Force the argument to be ignored.
%typemap(perl5,ignore) int *OUTPUT(int temp),
short *OUTPUT(short temp),
long *OUTPUT(long temp),
unsigned int *OUTPUT(unsigned int temp),
unsigned short *OUTPUT(unsigned short temp),
unsigned long *OUTPUT(unsigned long temp),
unsigned char *OUTPUT(unsigned char temp),
float *OUTPUT(float temp),
double *OUTPUT(double temp)
{
$target = &temp;
}
%typemap(perl5,argout) int *OUTPUT,
short *OUTPUT,
long *OUTPUT,
unsigned int *OUTPUT,
unsigned short *OUTPUT,
unsigned long *OUTPUT,
unsigned char *OUTPUT
{
if (argvi >= items) {
EXTEND(sp,1);
}
$target = sv_newmortal();
sv_setiv($target,(IV) *($source));
argvi++;
}
%typemap(perl5,argout) float *OUTPUT,
double *OUTPUT
{
if (argvi >= items) {
EXTEND(sp,1);
}
$target = sv_newmortal();
sv_setnv($target,(double) *($source));
argvi++;
}
// BOTH
// Mappings for an argument that is both an input and output
// parameter
#ifdef AUTODOC
%subsection "Input/Output Methods"
%text %{
The following methods can be applied to make a function parameter both
an input and output value. This combines the behavior of both the
"INPUT" and "OUTPUT" methods described earlier. Output values are
returned in the form of a Tcl list.
int *BOTH
short *BOTH
long *BOTH
unsigned int *BOTH
unsigned short *BOTH
unsigned long *BOTH
unsigned char *BOTH
float *BOTH
double *BOTH
For example, suppose you were trying to wrap the following function :
void neg(double *x) {
*x = -(*x);
}
You could wrap it with SWIG as follows :
%include typemaps.i
void neg(double *BOTH);
or you can use the %apply directive :
%include typemaps.i
%apply double *BOTH { double *x };
void neg(double *x);
Unlike C, this mapping does not directly modify the input value.
Rather, the modified input value shows up as the return value of the
function. Thus, to apply this function to a Perl variable you might
do this :
$x = neg($x);
%}
#endif
%typemap(perl5,in) int *BOTH = int *INPUT;
%typemap(perl5,in) short *BOTH = short *INPUT;
%typemap(perl5,in) long *BOTH = long *INPUT;
%typemap(perl5,in) unsigned *BOTH = unsigned *INPUT;
%typemap(perl5,in) unsigned short *BOTH = unsigned short *INPUT;
%typemap(perl5,in) unsigned long *BOTH = unsigned long *INPUT;
%typemap(perl5,in) unsigned char *BOTH = unsigned char *INPUT;
%typemap(perl5,in) float *BOTH = float *INPUT;
%typemap(perl5,in) double *BOTH = double *INPUT;
%typemap(perl5,argout) int *BOTH = int *OUTPUT;
%typemap(perl5,argout) short *BOTH = short *OUTPUT;
%typemap(perl5,argout) long *BOTH = long *OUTPUT;
%typemap(perl5,argout) unsigned *BOTH = unsigned *OUTPUT;
%typemap(perl5,argout) unsigned short *BOTH = unsigned short *OUTPUT;
%typemap(perl5,argout) unsigned long *BOTH = unsigned long *OUTPUT;
%typemap(perl5,argout) unsigned char *BOTH = unsigned char *OUTPUT;
%typemap(perl5,argout) float *BOTH = float *OUTPUT;
%typemap(perl5,argout) double *BOTH = double *OUTPUT;
// REFERENCE
// Accept Perl references as pointers
#ifdef AUTODOC
%subsection "Reference Methods"
%text %{
The following methods make Perl references work like simple C
pointers. References can only be used for simple input/output
values, not C arrays however. It should also be noted that
REFERENCES are specific to Perl and not supported in other
scripting languages at this time.
int *REFERENCE
short *REFERENCE
long *REFERENCE
unsigned int *REFERENCE
unsigned short *REFERENCE
unsigned long *REFERENCE
unsigned char *REFERENCE
float *REFERENCE
double *REFERENCE
For example, suppose you were trying to wrap the following function :
void neg(double *x) {
*x = -(*x);
}
You could wrap it with SWIG as follows :
%include typemaps.i
void neg(double *REFERENCE);
or you can use the %apply directive :
%include typemaps.i
%apply double *REFERENCE { double *x };
void neg(double *x);
Unlike the BOTH mapping described previous, this approach directly
modifies the value of a Perl reference. Thus, you could use it
as follows :
$x = 3;
neg(\$x);
print "$x\n"; # Should print out -3.
%}
#endif
%typemap(perl5,in) double *REFERENCE (double dvalue)
{
SV *tempsv;
if (!SvROK($source)) {
croak("expected a reference");
}
tempsv = SvRV($source);
if ((!SvNOK(tempsv)) && (!SvIOK(tempsv))) {
printf("Received %d\n", SvTYPE(tempsv));
croak("Expected a double reference.");
}
dvalue = SvNV(tempsv);
$target = &dvalue;
}
%typemap(perl5,in) float *REFERENCE (float dvalue)
{
SV *tempsv;
if (!SvROK($source)) {
croak("expected a reference");
}
tempsv = SvRV($source);
if ((!SvNOK(tempsv)) && (!SvIOK(tempsv))) {
croak("expected a double reference");
}
dvalue = (float) SvNV(tempsv);
$target = &dvalue;
}
%typemap(perl5,in) int *REFERENCE (int dvalue)
{
SV *tempsv;
if (!SvROK($source)) {
croak("expected a reference");
}
tempsv = SvRV($source);
if (!SvIOK(tempsv)) {
croak("expected a integer reference");
}
dvalue = SvIV(tempsv);
$target = &dvalue;
}
%typemap(perl5,in) short *REFERENCE (short dvalue)
{
SV *tempsv;
if (!SvROK($source)) {
croak("expected a reference");
}
tempsv = SvRV($source);
if (!SvIOK(tempsv)) {
croak("expected a integer reference");
}
dvalue = (short) SvIV(tempsv);
$target = &dvalue;
}
%typemap(perl5,in) long *REFERENCE (long dvalue)
{
SV *tempsv;
if (!SvROK($source)) {
croak("expected a reference");
}
tempsv = SvRV($source);
if (!SvIOK(tempsv)) {
croak("expected a integer reference");
}
dvalue = (long) SvIV(tempsv);
$target = &dvalue;
}
%typemap(perl5,in) unsigned int *REFERENCE (unsigned int dvalue)
{
SV *tempsv;
if (!SvROK($source)) {
croak("expected a reference");
}
tempsv = SvRV($source);
if (!SvIOK(tempsv)) {
croak("expected a integer reference");
}
dvalue = (unsigned int) SvIV(tempsv);
$target = &dvalue;
}
%typemap(perl5,in) unsigned short *REFERENCE (unsigned short dvalue)
{
SV *tempsv;
if (!SvROK($source)) {
croak("expected a reference");
}
tempsv = SvRV($source);
if (!SvIOK(tempsv)) {
croak("expected a integer reference");
}
dvalue = (unsigned short) SvIV(tempsv);
$target = &dvalue;
}
%typemap(perl5,in) unsigned long *REFERENCE (unsigned long dvalue)
{
SV *tempsv;
if (!SvROK($source)) {
croak("expected a reference");
}
tempsv = SvRV($source);
if (!SvIOK(tempsv)) {
croak("expected a integer reference");
}
dvalue = (unsigned long) SvIV(tempsv);
$target = &dvalue;
}
%typemap(perl5,argout) double *REFERENCE,
float *REFERENCE
{
SV *tempsv;
tempsv = SvRV($arg);
sv_setnv(tempsv, (double) *$source);
}
%typemap(perl5,argout) int *REFERENCE,
short *REFERENCE,
long *REFERENCE,
unsigned int *REFERENCE,
unsigned short *REFERENCE,
unsigned long *REFERENCE
{
SV *tempsv;
tempsv = SvRV($arg);
sv_setiv(tempsv, (int) *$source);
}
// --------------------------------------------------------------------
// Special types
//
// --------------------------------------------------------------------

View File

@@ -0,0 +1,58 @@
//
// SWIG Pointer manipulation library
//
// This library can be used to manipulate C pointers.
%title "SWIG Pointer Library"
%module pointer
%section "Pointer Handling Library",noinfo,after,pre,nosort,skip=1,chop_left=3,chop_right=0,chop_top=0,chop_bottom=0
%text %{
%include pointer.i
The pointer.i library provides run-time support for managing and
manipulating a variety of C/C++ pointer values. In particular,
you can create various kinds of objects and dereference common
pointer types. This is done through a common set of functions:
ptrcast - Casts a pointer to a new type
ptrvalue - Dereferences a pointer
ptrset - Set the value of an object referenced by
a pointer.
ptrcreate - Create a new object and return a pointer.
ptrfree - Free the memory allocated by ptrcreate.
ptradd - Increment/decrement a pointer value.
ptrmap - Make two datatypes equivalent to each other.
(Is a runtime equivalent of typedef).
When creating, dereferencing, or setting the value of pointer
variable, only the common C datatypes of int, short, long, float,
double, char, and char * are currently supported. Other
datatypes may generate an error.
One of the more interesting aspects of this library is that
it operates with a wide range of datatypes. For example,
the "ptrvalue" function can dereference "double *", "int *",
"long *", "char *", and other datatypes. Since SWIG encodes
pointers with type information, this can be done transparently
and in most cases, you can dereference a pointer without
ever knowing what type it actually is.
This library is primarily designed for utility, not high
performance (the dynamic determination of pointer types takes
more work than most normal wrapper functions). As a result,
you may achieve better performance by writing customized
"helper" functions if you're making lots of calls to these
functions in inner loops or other intensive operations.
%}
// This library is a pretty hideous mess of language dependent code.
// Grab the implementation from the appropriate libray
%include ptrlang.i

View File

@@ -0,0 +1,137 @@
# Generated automatically from Makefile.in by configure.
# ---------------------------------------------------------------
# $Header$
# SWIG Python 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
#
# Many portions of this file were created by the SWIG configure
# script and should already reflect your machine.
#----------------------------------------------------------------
SRCS =
CXXSRCS =
OBJCSRCS =
OBJS =
INTERFACE =
WRAPFILE = $(INTERFACE:.i=_wrap.c)
WRAPOBJ = $(INTERFACE:.i=_wrap.o)
TARGET = module.so # Use this kind of target for dynamic loading
#TARGET = mypython # Use this target for static linking
prefix = /usr/local
exec_prefix = ${prefix}
CC = cc
CXX = CC
OBJC = cc -Wno-import # -Wno-import needed for gcc
CFLAGS =
INCLUDE =
LIBS =
# 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
SWIGCC = $(CC)
# SWIG Library files. Uncomment if rebuilding the Python interpreter
#SWIGLIB = -lembed.i
# Rules for creating .o files from source.
COBJS = $(SRCS:.c=.o)
CXXOBJS = $(CXXSRCS:.cxx=.o)
OBJCOBJS = $(OBJCSRCS:.m=.o)
ALLOBJS = $(COBJS) $(CXXOBJS) $(OBJCOBJS) $(OBJS)
# Command that will be used to build the final extension.
BUILD = $(SWIGCC)
# Uncomment the following if you are using dynamic loading
CCSHARED =
BUILD = ld -G
# Uncomment the following if you are using dynamic loading with C++ and
# need to provide additional link libraries (this is not always required).
#DLL_LIBS = -L/usr/local/lib/gcc-lib/sparc-sun-solaris2.5.1/2.7.2 \
-L/usr/local/lib -lg++ -lstdc++ -lgcc
# X11 installation (needed if rebuilding Python + tkinter)
XLIB = -L/usr/openwin/lib -lX11
XINCLUDE = -I/usr/openwin/include
# Python installation
PY_INCLUDE = -DHAVE_CONFIG_H -I/usr/local/include/python1.5 -I/usr/local/lib/python1.5/config
PY_LIB = /usr/local/lib/python1.5/config
# Tcl installation. Needed if rebuilding Python with tkinter.
TCL_INCLUDE = -I/usr/local/include
TCL_LIB = -L/usr/local/lib
# Build libraries (needed for static builds)
LIBM = -lm
LIBC =
SYSLIBS = $(LIBM) $(LIBC) -lsocket -lnsl -ldl
# Build options (uncomment only one these)
#TKINTER = $(TCL_LIB) -ltk -ltcl $(XLIB)
BUILD_LIBS = $(LIBS) # Dynamic loading
#BUILD_LIBS = $(PY_LIB) -lpython1.5 $(TKINTER) $(LIBS) $(SYSLIBS)
# Compilation rules for non-SWIG components
.SUFFIXES: .c .cxx .m
.c.o:
$(CC) $(CCSHARED) $(CFLAGS) $(INCLUDE) -c $<
.cxx.o:
$(CXX) $(CCSHARED) $(CXXFLAGS) $(INCLUDE) -c $<
.m.o:
$(OBJC) $(CCSHARED) $(CFLAGS) $(INCLUDE) -c $<
# ----------------------------------------------------------------------
# Rules for building the extension
# ----------------------------------------------------------------------
all: $(TARGET)
# Convert the wrapper file into an object file
$(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)
clean:
rm -f $(COBJS) $(CXXOBJS) $(OBJCOBJS) $(WRAPOBJ) $(WRAPFILE) $(TARGET)

View File

@@ -0,0 +1,136 @@
# ---------------------------------------------------------------
# $Header$
# SWIG Python 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
#
# Many portions of this file were created by the SWIG configure
# script and should already reflect your machine.
#----------------------------------------------------------------
SRCS =
CXXSRCS =
OBJCSRCS =
OBJS =
INTERFACE =
WRAPFILE = $(INTERFACE:.i=_wrap.c)
WRAPOBJ = $(INTERFACE:.i=_wrap.o)
TARGET = module@SO@ # Use this kind of target for dynamic loading
#TARGET = mypython # Use this target for static linking
prefix = @prefix@
exec_prefix = @exec_prefix@
CC = @CC@
CXX = @CXX@
OBJC = @CC@ -Wno-import # -Wno-import needed for gcc
CFLAGS =
INCLUDE =
LIBS =
# 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
SWIGCC = $(CC)
# SWIG Library files. Uncomment if rebuilding the Python interpreter
#SWIGLIB = -lembed.i
# Rules for creating .o files from source.
COBJS = $(SRCS:.c=.o)
CXXOBJS = $(CXXSRCS:.cxx=.o)
OBJCOBJS = $(OBJCSRCS:.m=.o)
ALLOBJS = $(COBJS) $(CXXOBJS) $(OBJCOBJS) $(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@
# Uncomment the following if you are using dynamic loading with C++ and
# need to provide additional link libraries (this is not always required).
#DLL_LIBS = -L/usr/local/lib/gcc-lib/sparc-sun-solaris2.5.1/2.7.2 \
-L/usr/local/lib -lg++ -lstdc++ -lgcc
# X11 installation (needed if rebuilding Python + tkinter)
XLIB = @XLIBSW@
XINCLUDE = @XINCLUDES@
# Python installation
PY_INCLUDE = -DHAVE_CONFIG_H @PYINCLUDE@
PY_LIB = @PYLIB@
# Tcl installation. Needed if rebuilding Python with tkinter.
TCL_INCLUDE = @TCLINCLUDE@
TCL_LIB = @TCLLIB@
# Build libraries (needed for static builds)
LIBM = @LIBM@
LIBC = @LIBC@
SYSLIBS = $(LIBM) $(LIBC) @LIBS@
# Build options (uncomment only one these)
#TKINTER = $(TCL_LIB) -ltk -ltcl $(XLIB)
BUILD_LIBS = $(LIBS) # Dynamic loading
#BUILD_LIBS = $(PY_LIB) @PYLINK@ $(TKINTER) $(LIBS) $(SYSLIBS)
# Compilation rules for non-SWIG components
.SUFFIXES: .c .cxx .m
.c.o:
$(CC) $(CCSHARED) $(CFLAGS) $(INCLUDE) -c $<
.cxx.o:
$(CXX) $(CCSHARED) $(CXXFLAGS) $(INCLUDE) -c $<
.m.o:
$(OBJC) $(CCSHARED) $(CFLAGS) $(INCLUDE) -c $<
# ----------------------------------------------------------------------
# Rules for building the extension
# ----------------------------------------------------------------------
all: $(TARGET)
# Convert the wrapper file into an object file
$(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)
clean:
rm -f $(COBJS) $(CXXOBJS) $(OBJCOBJS) $(WRAPOBJ) $(WRAPFILE) $(TARGET)

View File

@@ -0,0 +1,36 @@
/* This file defines an internal function for processing default arguments
with shadow classes.
There seems to be no straightforward way to write a shadow functions
involving default arguments. For example :
def foo(arg1,arg2,*args):
shadowc.foo(arg1,arg2,args)
This fails because args is now a tuple and SWIG doesn't know what to
do with it.
This file allows a different approach :
def foo(arg1,arg2,*args):
shadowc.__call_defarg(shadowc.foo,(arg1,arg2,)+args)
Basically, we form a new tuple from the object, call this special
__call_defarg method and it passes control to the real wrapper function.
An ugly hack, but it works.
*/
static PyObject *swig_call_defargs(PyObject *self, PyObject *args) {
PyObject *func;
PyObject *parms;
if (!PyArg_ParseTuple(args,"OO",&func,&parms))
return NULL;
if (!PyCallable_Check(func)) {
PyErr_SetString(PyExc_TypeError, "__call_defarg : Need a callable object!");
return NULL;
}
return PyEval_CallObject(func,parms);
}

View File

@@ -0,0 +1,115 @@
//
// embed15.i
// SWIG file embedding the Python interpreter in something else.
// This file is based on Python-1.5. It will not work with
// earlier versions.
//
// This file makes it possible to extend Python and all of its
// built-in functions without having to hack it's setup script.
//
#ifdef AUTODOC
%subsection "embed.i"
%text %{
This module provides support for building a new version of the
Python executable. This will be necessary on systems that do
not support shared libraries and may be necessary with C++
extensions. This file contains everything you need to build
a new version of Python from include files and libraries normally
installed with the Python language.
This module will automatically grab all of the Python modules
present in your current Python executable (including any special
purpose modules you have enabled such as Tkinter). Thus, you
may need to provide additional link libraries when compiling.
This library file only works with Python 1.5. A version
compatible with Python 1.4 is available as embed14.i and
a Python1.3 version is available as embed13.i. As far as
I know, this module is C++ safe.
%}
#else
%echo "embed.i : Using Python 1.5"
#endif
%wrapper %{
#include <Python.h>
#ifdef __cplusplus
extern "C"
#endif
void SWIG_init(); /* Forward reference */
#define _PyImport_Inittab swig_inittab
/* Grab Python's inittab[] structure */
#ifdef __cplusplus
extern "C" {
#endif
#include <config.c>
#undef _PyImport_Inittab
/* Now define our own version of it.
Hopefully someone does not have more than 1000 built-in modules */
struct _inittab _SwigImport_Inittab[1000];
static int swig_num_modules = 0;
/* Function for adding modules to Python */
static void swig_add_module(char *name, void (*initfunc)()) {
_SwigImport_Inittab[swig_num_modules].name = name;
_SwigImport_Inittab[swig_num_modules].initfunc = initfunc;
swig_num_modules++;
_SwigImport_Inittab[swig_num_modules].name = (char *) 0;
_SwigImport_Inittab[swig_num_modules].initfunc = 0;
}
/* Function to add all of Python's build in modules to our interpreter */
static void swig_add_builtin() {
int i = 0;
while (swig_inittab[i].name) {
swig_add_module(swig_inittab[i].name, swig_inittab[i].initfunc);
i++;
}
#ifdef SWIGMODINIT
SWIGMODINIT
#endif
/* Add SWIG builtin function */
swig_add_module(SWIG_name, SWIG_init);
}
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
extern "C" {
#endif
extern int Py_Main(int, char **);
#ifdef __cplusplus
}
#endif
extern struct _inittab *PyImport_Inittab;
int
main(int argc, char **argv) {
swig_add_builtin();
PyImport_Inittab = _SwigImport_Inittab;
return Py_Main(argc,argv);
}
%}

View File

@@ -0,0 +1,342 @@
//
// embed.i
// SWIG file embedding the Python interpreter in something else.
// This file is based on Python-1.3, but it might work with
// later versions.
//
// This file makes it possible to extend Python and all of its
// built-in functions without having to hack it's setup script.
//
#ifdef AUTODOC
%subsection "embed13.i"
%text %{
This module provides support for building a new version of the
Python 1.3 executable. This will be necessary on systems that do
not support shared libraries and may be necessary with C++
extensions. This file contains everything you need to build
a new version of Python from include files and libraries normally
installed with the Python language.
This module is functionally equivalent to the embed.i library,
but has a number of changes needed to work with older versions
of Python.
%}
#else
%echo "embed.i : Using Python 1.3"
#endif
%wrapper %{
#ifndef NEED_GETOPT
#include <unistd.h>
#endif
#include <pythonrun.h>
typedef struct SWIGPyTab {
char *name;
void (*initfunc)();
} SWIGPyTab;
#ifdef __cplusplus
extern "C"
#endif
void SWIG_init(void); /* Forward reference */
#define inittab python_inittab
/* Grab Python's inittab[] structure */
#ifdef __cplusplus
extern "C" {
#endif
#include <config.c>
#undef inittab
/* Now define our own version of it.
God forbid someone have more than 1000 built-in modules! */
SWIGPyTab inittab[1000];
static int swig_num_modules = 0;
/* Function for adding modules to Python */
static void swig_add_module(char *name, void (*initfunc)()) {
inittab[swig_num_modules].name = name;
inittab[swig_num_modules].initfunc = initfunc;
swig_num_modules++;
inittab[swig_num_modules].name = (char *) 0;
inittab[swig_num_modules].initfunc = (void (*)()) 0;
}
/* Function to add all of Python's build in modules to our interpreter */
static void swig_add_builtin() {
int i = 0;
while (python_inittab[i].name) {
swig_add_module(python_inittab[i].name, python_inittab[i].initfunc);
i++;
}
/* Add SWIG builtin function */
swig_add_module(SWIG_name, SWIG_init);
#ifdef SWIGMODINIT
SWIGMODINIT
#endif
}
#ifdef __cplusplus
}
#endif
/* Interface to getopt(): */
extern int optind;
extern char *optarg;
#ifdef NEED_GETOPT
#ifdef __cplusplus
extern "C" int getopt(int, char **, char *);
#else
extern int getopt(); /* PROTO((int, char **, char *)); -- not standardized */
#endif
#endif
extern int Py_DebugFlag; /* For parser.c, declared in pythonrun.c */
extern int Py_VerboseFlag; /* For import.c, declared in pythonrun.c */
extern int Py_SuppressPrintingFlag; /* For ceval.c, declared in pythonrun.c */
/* Subroutines that live in their own file */
#ifdef __cplusplus
extern "C" {
extern int isatty(int fd);
extern int PySys_SetArgv(int, char **);
#endif
extern char *getversion();
extern char *getcopyright();
#ifdef __cplusplus
}
#endif
/* For getprogramname(); set by main() */
static char *argv0;
/* For getargcargv(); set by main() */
static char **orig_argv;
static int orig_argc;
/* Short usage message (with %s for argv0) */
static char *usage_line =
"usage: %s [-d] [-i] [-s] [-u ] [-v] [-c cmd | file | -] [arg] ...\n";
/* Long usage message, split into parts < 512 bytes */
static char *usage_top = "\n\
Options and arguments (and corresponding environment variables):\n\
-d : debug output from parser (also PYTHONDEBUG=x)\n\
-i : inspect interactively after running script (also PYTHONINSPECT=x)\n\
-s : suppress printing of top level expressions (also PYTHONSUPPRESS=x)\n\
-u : unbuffered stdout and stderr (also PYTHONUNBUFFERED=x)\n\
-v : verbose (trace import statements) (also PYTHONVERBOSE=x)\n\
-c cmd : program passed in as string (terminates option list)\n\
";
static char *usage_bot = "\
file : program read from script file\n\
- : program read from stdin (default; interactive mode if a tty)\n\
arg ...: arguments passed to program in sys.argv[1:]\n\
\n\
Other environment variables:\n\
PYTHONSTARTUP: file executed on interactive startup (no default)\n\
PYTHONPATH : colon-separated list of directories prefixed to the\n\
default module search path. The result is sys.path.\n\
";
/* Main program */
int
main(int argc, char **argv) {
int c;
int sts;
char *command = NULL;
char *filename = NULL;
FILE *fp = stdin;
char *p;
int inspect = 0;
int unbuffered = 0;
swig_add_builtin(); /* Add SWIG built-in modules */
orig_argc = argc; /* For getargcargv() */
orig_argv = argv;
argv0 = argv[0]; /* For getprogramname() */
if ((p = getenv("PYTHONDEBUG")) && *p != '\0')
Py_DebugFlag = 1;
if ((p = getenv("PYTHONSUPPRESS")) && *p != '\0')
Py_SuppressPrintingFlag = 1;
if ((p = getenv("PYTHONVERBOSE")) && *p != '\0')
Py_VerboseFlag = 1;
if ((p = getenv("PYTHONINSPECT")) && *p != '\0')
inspect = 1;
if ((p = getenv("PYTHONUNBUFFERED")) && *p != '\0')
unbuffered = 1;
while ((c = getopt(argc, argv, "c:disuv")) != EOF) {
if (c == 'c') {
/* -c is the last option; following arguments
that look like options are left for the
the command to interpret. */
command = (char *) malloc(strlen(optarg) + 2);
if (command == NULL)
Py_FatalError(
"not enough memory to copy -c argument");
strcpy(command, optarg);
strcat(command, "\n");
break;
}
switch (c) {
case 'd':
Py_DebugFlag++;
break;
case 'i':
inspect++;
break;
case 's':
Py_SuppressPrintingFlag++;
break;
case 'u':
unbuffered++;
break;
case 'v':
Py_VerboseFlag++;
break;
/* This space reserved for other options */
default:
fprintf(stderr, usage_line, argv[0]);
fprintf(stderr, usage_top);
fprintf(stderr, usage_bot);
exit(2);
/*NOTREACHED*/
}
}
if (unbuffered) {
#ifndef MPW
setbuf(stdout, (char *)NULL);
setbuf(stderr, (char *)NULL);
#else
/* On MPW (3.2) unbuffered seems to hang */
setvbuf(stdout, (char *)NULL, _IOLBF, BUFSIZ);
setvbuf(stderr, (char *)NULL, _IOLBF, BUFSIZ);
#endif
}
if (command == NULL && optind < argc &&
strcmp(argv[optind], "-") != 0)
filename = argv[optind];
if (Py_VerboseFlag ||
command == NULL && filename == NULL && isatty((int)fileno(fp)))
fprintf(stderr, "Python %s\n%s\n",
getversion(), getcopyright());
if (filename != NULL) {
if ((fp = fopen(filename, "r")) == NULL) {
fprintf(stderr, "%s: can't open file '%s'\n",
argv[0], filename);
exit(2);
}
}
Py_Initialize();
if (command != NULL) {
/* Backup optind and force sys.argv[0] = '-c' */
optind--;
argv[optind] = "-c";
}
PySys_SetArgv(argc-optind, argv+optind);
if (command) {
sts = PyRun_SimpleString(command) != 0;
}
else {
if (filename == NULL && isatty((int)fileno(fp))) {
char *startup = getenv("PYTHONSTARTUP");
if (startup != NULL && startup[0] != '\0') {
FILE *fp = fopen(startup, "r");
if (fp != NULL) {
(void) PyRun_SimpleFile(fp, startup);
PyErr_Clear();
fclose(fp);
}
}
}
sts = PyRun_AnyFile(
fp, filename == NULL ? "<stdin>" : filename) != 0;
if (filename != NULL)
fclose(fp);
}
if (inspect && isatty((int)fileno(stdin)) &&
(filename != NULL || command != NULL))
sts = PyRun_AnyFile(stdin, "<stdin>") != 0;
Py_Exit(sts);
/*NOTREACHED*/
}
/* Return the program name -- some code out there needs this. */
#ifdef __cplusplus
extern "C"
#endif
char *
getprogramname()
{
return argv0;
}
/* Make the *original* argc/argv available to other modules.
This is rare, but it is needed by the secureware extension. */
#ifdef __cplusplus
extern "C"
#endif
void
getargcargv(int *argc,char ***argv)
{
*argc = orig_argc;
*argv = orig_argv;
}
/* Total Hack to get getpath.c to compile under C++ */
#ifdef __cplusplus
#define malloc (char *) malloc
extern "C" {
#endif
#include <getpath.c>
#ifdef __cplusplus
}
#undef malloc
#endif
%}

View File

@@ -0,0 +1,340 @@
//
// embed.i
// SWIG file embedding the Python interpreter in something else.
// This file is based on Python-1.4.
//
// This file makes it possible to extend Python and all of its
// built-in functions without having to hack it's setup script.
//
#ifdef AUTODOC
%subsection "embed.i"
%text %{
This module provides support for building a new version of the
Python executable. This will be necessary on systems that do
not support shared libraries and may be necessary with C++
extensions. This file contains everything you need to build
a new version of Python from include files and libraries normally
installed with the Python language.
This module will automatically grab all of the Python modules
present in your current Python executable (including any special
purpose modules you have enabled such as tkinter). Thus, you
may need to provide additional link libraries when compiling.
This library file only works with Python 1.4. A version compatible
with Python 1.3 is available as embed13.i. A Python 1.5 version is
available as embed15.i As far as I know, this module is C++ safe
(well, it works for me).
%}
#else
%echo "embed.i : Using Python 1.4"
#endif
%wrapper %{
#ifndef NEED_GETOPT
#include <unistd.h>
#endif
#include <pythonrun.h>
#ifdef __cplusplus
extern "C"
#endif
void SWIG_init(); /* Forward reference */
#define inittab python_inittab
/* Grab Python's inittab[] structure */
#ifdef __cplusplus
extern "C" {
#endif
#include <config.c>
#undef inittab
/* Now define our own version of it.
Hopefully someone does not have more than 1000 built-in modules */
struct _inittab inittab[1000];
static int swig_num_modules = 0;
/* Function for adding modules to Python */
static void swig_add_module(char *name, void (*initfunc)()) {
inittab[swig_num_modules].name = name;
inittab[swig_num_modules].initfunc = initfunc;
swig_num_modules++;
inittab[swig_num_modules].name = (char *) 0;
inittab[swig_num_modules].initfunc = 0;
}
/* Function to add all of Python's build in modules to our interpreter */
static void swig_add_builtin() {
int i = 0;
while (python_inittab[i].name) {
swig_add_module(python_inittab[i].name, python_inittab[i].initfunc);
i++;
}
#ifdef SWIGMODINIT
SWIGMODINIT
#endif
/* Add SWIG builtin function */
swig_add_module(SWIG_name, SWIG_init);
}
#ifdef __cplusplus
}
#endif
/* Interface to getopt(): */
extern int optind;
extern char *optarg;
#ifdef NEED_GETOPT
#ifdef __cplusplus
extern "C" int getopt(int, char **, char *);
#else
extern int getopt(); /* PROTO((int, char **, char *)); -- not standardized */
#endif
#endif
extern int Py_DebugFlag; /* For parser.c, declared in pythonrun.c */
extern int Py_VerboseFlag; /* For import.c, declared in pythonrun.c */
extern int Py_SuppressPrintingFlag; /* For ceval.c, declared in pythonrun.c */
/* Subroutines that live in their own file */
#ifdef __cplusplus
extern "C" {
extern int isatty(int fd);
extern void PySys_SetArgv(int, char **);
#endif
extern char *Py_GetVersion();
extern char *Py_GetCopyright();
#ifdef __cplusplus
}
#endif
/* For getprogramname(); set by main() */
static char *argv0;
/* For getargcargv(); set by main() */
static char **orig_argv;
static int orig_argc;
/* Short usage message (with %s for argv0) */
static char *usage_line =
"usage: %s [-d] [-i] [-s] [-u ] [-v] [-c cmd | file | -] [arg] ...\n";
/* Long usage message, split into parts < 512 bytes */
static char *usage_top = "\n\
Options and arguments (and corresponding environment variables):\n\
-d : debug output from parser (also PYTHONDEBUG=x)\n\
-i : inspect interactively after running script (also PYTHONINSPECT=x)\n\
-s : suppress printing of top level expressions (also PYTHONSUPPRESS=x)\n\
-u : unbuffered stdout and stderr (also PYTHONUNBUFFERED=x)\n\
-v : verbose (trace import statements) (also PYTHONVERBOSE=x)\n\
-c cmd : program passed in as string (terminates option list)\n\
";
static char *usage_bot = "\
file : program read from script file\n\
- : program read from stdin (default; interactive mode if a tty)\n\
arg ...: arguments passed to program in sys.argv[1:]\n\
\n\
Other environment variables:\n\
PYTHONSTARTUP: file executed on interactive startup (no default)\n\
PYTHONPATH : colon-separated list of directories prefixed to the\n\
default module search path. The result is sys.path.\n\
";
/* Main program */
int
main(int argc, char **argv) {
int c;
int sts;
char *command = NULL;
char *filename = NULL;
FILE *fp = stdin;
char *p;
int inspect = 0;
int unbuffered = 0;
swig_add_builtin(); /* Add SWIG built-in modules */
orig_argc = argc; /* For getargcargv() */
orig_argv = argv;
argv0 = argv[0]; /* For getprogramname() */
if ((p = getenv("PYTHONDEBUG")) && *p != '\0')
Py_DebugFlag = 1;
if ((p = getenv("PYTHONSUPPRESS")) && *p != '\0')
Py_SuppressPrintingFlag = 1;
if ((p = getenv("PYTHONVERBOSE")) && *p != '\0')
Py_VerboseFlag = 1;
if ((p = getenv("PYTHONINSPECT")) && *p != '\0')
inspect = 1;
if ((p = getenv("PYTHONUNBUFFERED")) && *p != '\0')
unbuffered = 1;
while ((c = getopt(argc, argv, "c:disuv")) != EOF) {
if (c == 'c') {
/* -c is the last option; following arguments
that look like options are left for the
the command to interpret. */
command = (char *) malloc(strlen(optarg) + 2);
if (command == NULL)
Py_FatalError(
"not enough memory to copy -c argument");
strcpy(command, optarg);
strcat(command, "\n");
break;
}
switch (c) {
case 'd':
Py_DebugFlag++;
break;
case 'i':
inspect++;
break;
case 's':
Py_SuppressPrintingFlag++;
break;
case 'u':
unbuffered++;
break;
case 'v':
Py_VerboseFlag++;
break;
/* This space reserved for other options */
default:
fprintf(stderr, usage_line, argv[0]);
fprintf(stderr, usage_top);
fprintf(stderr, usage_bot);
exit(2);
/*NOTREACHED*/
}
}
if (unbuffered) {
#ifndef MPW
setbuf(stdout, (char *)NULL);
setbuf(stderr, (char *)NULL);
#else
/* On MPW (3.2) unbuffered seems to hang */
setvbuf(stdout, (char *)NULL, _IOLBF, BUFSIZ);
setvbuf(stderr, (char *)NULL, _IOLBF, BUFSIZ);
#endif
}
if (command == NULL && optind < argc &&
strcmp(argv[optind], "-") != 0)
filename = argv[optind];
if (Py_VerboseFlag ||
command == NULL && filename == NULL && isatty((int)fileno(fp)))
fprintf(stderr, "Python %s\n%s\n",
Py_GetVersion(), Py_GetCopyright());
if (filename != NULL) {
if ((fp = fopen(filename, "r")) == NULL) {
fprintf(stderr, "%s: can't open file '%s'\n",
argv[0], filename);
exit(2);
}
}
Py_Initialize();
if (command != NULL) {
/* Backup optind and force sys.argv[0] = '-c' */
optind--;
argv[optind] = "-c";
}
PySys_SetArgv(argc-optind, argv+optind);
if (command) {
sts = PyRun_SimpleString(command) != 0;
}
else {
if (filename == NULL && isatty((int)fileno(fp))) {
char *startup = getenv("PYTHONSTARTUP");
if (startup != NULL && startup[0] != '\0') {
FILE *fp = fopen(startup, "r");
if (fp != NULL) {
(void) PyRun_SimpleFile(fp, startup);
PyErr_Clear();
fclose(fp);
}
}
}
sts = PyRun_AnyFile(
fp, filename == NULL ? "<stdin>" : filename) != 0;
if (filename != NULL)
fclose(fp);
}
if (inspect && isatty((int)fileno(stdin)) &&
(filename != NULL || command != NULL))
sts = PyRun_AnyFile(stdin, "<stdin>") != 0;
Py_Exit(sts);
/*NOTREACHED*/
}
/* Return the program name -- some code out there needs this. */
#ifdef __cplusplus
extern "C"
#endif
char *
Py_GetProgramName()
{
return argv0;
}
/* Make the *original* argc/argv available to other modules.
This is rare, but it is needed by the secureware extension. */
#ifdef __cplusplus
extern "C"
#endif
void
getargcargv(int *argc,char ***argv)
{
*argc = orig_argc;
*argv = orig_argv;
}
/* Total Hack to get getpath.c to compile under C++ */
#ifdef __cplusplus
#define malloc (char *) malloc
extern "C" {
#endif
#include <getpath.c>
#ifdef __cplusplus
}
#undef malloc
#endif
%}

Some files were not shown because too many files have changed in this diff Show More