diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2009-08-18 20:56:02 +0000 |
---|---|---|
committer | Lorry <lorry@roadtrain.codethink.co.uk> | 2012-09-25 16:59:08 +0000 |
commit | 9f8a09ed743cedd9547bf0661d518647966ab114 (patch) | |
tree | 9c7803d3b27a8ec22e91792ac7f7932efa128b20 /Lib/tcl | |
download | swig-tarball-9f8a09ed743cedd9547bf0661d518647966ab114.tar.gz |
Imported from /srv/lorry/lorry-area/swig-tarball/swig-1.3.40.tar.gz.HEADswig-1.3.40master
Diffstat (limited to 'Lib/tcl')
43 files changed, 3523 insertions, 0 deletions
diff --git a/Lib/tcl/Makefile.in b/Lib/tcl/Makefile.in new file mode 100644 index 0000000..523349b --- /dev/null +++ b/Lib/tcl/Makefile.in @@ -0,0 +1,133 @@ +# --------------------------------------------------------------- +# SWIG Tcl/Tk Makefile +# +# This file can be used to build various Tcl 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. However, you +# may need to modify the Makefile to reflect your specific +# application. +#---------------------------------------------------------------- + +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 = my_tclsh # 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 = +INCLUDES = +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 = -tcl # use -tcl8 for Tcl 8.0 +SWIGCC = $(CC) + +# SWIG Library files. Uncomment one of these for rebuilding tclsh or wish +#SWIGLIB = -ltclsh.i +#SWIGLIB = -lwish.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 to rebuild Tk extensions) + +XLIB = @XLIBSW@ +XINCLUDE = @XINCLUDES@ + +# Tcl installation (where is Tcl/Tk located) + +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) + +BUILD_LIBS = $(LIBS) # Dynamic loading +#BUILD_LIBS = $(TCL_LIB) -ltcl $(LIBS) $(SYSLIBS) # tclsh +#BUILD_LIBS = $(TCL_LIB) -ltk -ltcl $(XLIB) $(LIBS) $(SYSLIBS) # wish + +# Compilation rules for non-SWIG components + +.SUFFIXES: .c .cxx .m + +.c.o: + $(CC) $(CCSHARED) $(CFLAGS) $(INCLUDES) -c $< + +.cxx.o: + $(CXX) $(CCSHARED) $(CXXFLAGS) $(INCLUDES) -c $< + +.m.o: + $(OBJC) $(CCSHARED) $(CFLAGS) $(INCLUDES) -c $< + + +# ---------------------------------------------------------------------- +# Rules for building the extension +# ---------------------------------------------------------------------- + +all: $(TARGET) + +# Convert the wrapper file into an object file + +$(WRAPOBJ) : $(WRAPFILE) + $(SWIGCC) -c $(CCSHARED) $(CFLAGS) $(WRAPFILE) $(INCLUDES) $(TCL_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) + + + + diff --git a/Lib/tcl/attribute.i b/Lib/tcl/attribute.i new file mode 100644 index 0000000..779716c --- /dev/null +++ b/Lib/tcl/attribute.i @@ -0,0 +1 @@ +%include <typemaps/attribute.swg> diff --git a/Lib/tcl/carrays.i b/Lib/tcl/carrays.i new file mode 100644 index 0000000..0236672 --- /dev/null +++ b/Lib/tcl/carrays.i @@ -0,0 +1,4 @@ +%include <typemaps/carrays.swg> + + + diff --git a/Lib/tcl/cdata.i b/Lib/tcl/cdata.i new file mode 100644 index 0000000..3679659 --- /dev/null +++ b/Lib/tcl/cdata.i @@ -0,0 +1 @@ +%include <typemaps/cdata.swg> diff --git a/Lib/tcl/cmalloc.i b/Lib/tcl/cmalloc.i new file mode 100644 index 0000000..248f06b --- /dev/null +++ b/Lib/tcl/cmalloc.i @@ -0,0 +1 @@ +%include <typemaps/cmalloc.swg> diff --git a/Lib/tcl/cni.i b/Lib/tcl/cni.i new file mode 100644 index 0000000..10a1403 --- /dev/null +++ b/Lib/tcl/cni.i @@ -0,0 +1,2 @@ +%include <gcj/cni.i> +%include <jstring.i> diff --git a/Lib/tcl/cpointer.i b/Lib/tcl/cpointer.i new file mode 100644 index 0000000..d824792 --- /dev/null +++ b/Lib/tcl/cpointer.i @@ -0,0 +1 @@ +%include <typemaps/cpointer.swg> diff --git a/Lib/tcl/cstring.i b/Lib/tcl/cstring.i new file mode 100644 index 0000000..ede9c59 --- /dev/null +++ b/Lib/tcl/cstring.i @@ -0,0 +1 @@ +%include <typemaps/cstring.swg> diff --git a/Lib/tcl/cwstring.i b/Lib/tcl/cwstring.i new file mode 100644 index 0000000..b17ca76 --- /dev/null +++ b/Lib/tcl/cwstring.i @@ -0,0 +1,2 @@ +%include <tclwstrings.swg> +%include <typemaps/cwstring.swg> diff --git a/Lib/tcl/exception.i b/Lib/tcl/exception.i new file mode 100644 index 0000000..4d22797 --- /dev/null +++ b/Lib/tcl/exception.i @@ -0,0 +1,6 @@ +%include <typemaps/exception.swg> + + +%insert("runtime") { + %define_as(SWIG_exception(code, msg), %block(%error(code, msg); return TCL_ERROR;)) +} diff --git a/Lib/tcl/factory.i b/Lib/tcl/factory.i new file mode 100644 index 0000000..46a0a87 --- /dev/null +++ b/Lib/tcl/factory.i @@ -0,0 +1 @@ +%include <typemaps/factory.swg> diff --git a/Lib/tcl/jstring.i b/Lib/tcl/jstring.i new file mode 100644 index 0000000..7fb7b89 --- /dev/null +++ b/Lib/tcl/jstring.i @@ -0,0 +1,42 @@ +%include <typemaps/valtypes.swg> + +%fragment(SWIG_AsVal_frag(jstring),"header") { +SWIGINTERN int +SWIG_AsVal_dec(jstring)(Tcl_Obj * obj, jstring *val) +{ + int len = 0; + const char *cstr = Tcl_GetStringFromObj(obj, &len); + if (!cstr || (strcmp(cstr,"NULL") == 0)) { + if (val) *val = 0; + return SWIG_OK; + } else { + int len = 0; + const Tcl_UniChar *ucstr = Tcl_GetUnicodeFromObj(obj,&len); + if (val) { + *val = JvNewString((const jchar*)ucstr, len); + } + } + + return SWIG_NEWOBJ; +} +} + +%fragment(SWIG_From_frag(jstring),"header") { +SWIGINTERNINLINE Tcl_Obj * +SWIG_From_dec(jstring)(jstring val) +{ + if (!val) { + return Tcl_NewStringObj("NULL",-1); + } else { + return Tcl_NewUnicodeObj((Tcl_UniChar *)JvGetStringChars(val),JvGetStringUTFLength(val)); + } +} +} + +%typemaps_asvalfrom(%checkcode(STRING), + %arg(SWIG_AsVal(jstring)), + %arg(SWIG_From(jstring)), + %arg(SWIG_AsVal_frag(jstring)), + %arg(SWIG_From_frag(jstring)), + java::lang::String *); + diff --git a/Lib/tcl/mactclinit.c b/Lib/tcl/mactclinit.c new file mode 100644 index 0000000..5dcf8e7 --- /dev/null +++ b/Lib/tcl/mactclinit.c @@ -0,0 +1,93 @@ +/* ----------------------------------------------------------------------------- + * See the LICENSE file for information on copyright, usage and redistribution + * of SWIG, and the README file for authors - http://www.swig.org/release.html. + * + * mactclinit.c + * ----------------------------------------------------------------------------- */ + +/* + * tclMacAppInit.c -- + * + * Provides a version of the Tcl_AppInit procedure for the example shell. + * + * Copyright (c) 1993-1994 Lockheed Missle & Space Company, AI Center + * Copyright (c) 1995-1997 Sun Microsystems, Inc. + * + * See the file "license.terms" for information on usage and redistribution + * of this file, and for a DISCLAIMER OF ALL WARRANTIES. + * + * SCCS: @(#) tclMacAppInit.c 1.17 97/01/21 18:13:34 + */ + +#include "tcl.h" +#include "tclInt.h" +#include "tclMacInt.h" + +#if defined(THINK_C) +# include <console.h> +#elif defined(__MWERKS__) +# include <SIOUX.h> +short InstallConsole _ANSI_ARGS_((short fd)); +#endif + + + +/* + *---------------------------------------------------------------------- + * + * MacintoshInit -- + * + * This procedure calls initalization routines to set up a simple + * console on a Macintosh. This is necessary as the Mac doesn't + * have a stdout & stderr by default. + * + * Results: + * Returns TCL_OK if everything went fine. If it didn't the + * application should probably fail. + * + * Side effects: + * Inits the appropiate console package. + * + *---------------------------------------------------------------------- + */ + +#ifdef __cplusplus +extern "C" +#endif +extern int +MacintoshInit() +{ +#if defined(THINK_C) + + /* Set options for Think C console package */ + /* The console package calls the Mac init calls */ + console_options.pause_atexit = 0; + console_options.title = "\pTcl Interpreter"; + +#elif defined(__MWERKS__) + + /* Set options for CodeWarrior SIOUX package */ + SIOUXSettings.autocloseonquit = true; + SIOUXSettings.showstatusline = true; + SIOUXSettings.asktosaveonclose = false; + InstallConsole(0); + SIOUXSetTitle("\pTcl Interpreter"); + +#elif defined(applec) + + /* Init packages used by MPW SIOW package */ + InitGraf((Ptr)&qd.thePort); + InitFonts(); + InitWindows(); + InitMenus(); + TEInit(); + InitDialogs(nil); + InitCursor(); + +#endif + + TclMacSetEventProc((TclMacConvertEventPtr) SIOUXHandleOneEvent); + + /* No problems with initialization */ + return TCL_OK; +} diff --git a/Lib/tcl/mactkinit.c b/Lib/tcl/mactkinit.c new file mode 100644 index 0000000..bfe7402 --- /dev/null +++ b/Lib/tcl/mactkinit.c @@ -0,0 +1,236 @@ +/* ----------------------------------------------------------------------------- + * See the LICENSE file for information on copyright, usage and redistribution + * of SWIG, and the README file for authors - http://www.swig.org/release.html. + * + * mactkinit.c + * + * This is a support file needed to build a new version of Wish. + * Normally, this capability is found in TkAppInit.c, but this creates + * tons of namespace problems for many applications. + * ----------------------------------------------------------------------------- */ + +#include <Gestalt.h> +#include <ToolUtils.h> +#include <Fonts.h> +#include <Dialogs.h> +#include <SegLoad.h> +#include <Traps.h> + +#include "tk.h" +#include "tkInt.h" +#include "tkMacInt.h" + +typedef int (*TclMacConvertEventPtr) _ANSI_ARGS_((EventRecord *eventPtr)); +Tcl_Interp *gStdoutInterp = NULL; + +void TclMacSetEventProc _ANSI_ARGS_((TclMacConvertEventPtr procPtr)); +int TkMacConvertEvent _ANSI_ARGS_((EventRecord *eventPtr)); + +/* + * Prototypes for functions the ANSI library needs to link against. + */ +short InstallConsole _ANSI_ARGS_((short fd)); +void RemoveConsole _ANSI_ARGS_((void)); +long WriteCharsToConsole _ANSI_ARGS_((char *buff, long n)); +long ReadCharsFromConsole _ANSI_ARGS_((char *buff, long n)); +char * __ttyname _ANSI_ARGS_((long fildes)); +short SIOUXHandleOneEvent _ANSI_ARGS_((EventRecord *event)); + +/* + * Forward declarations for procedures defined later in this file: + */ + +/* + *---------------------------------------------------------------------- + * + * MacintoshInit -- + * + * This procedure calls Mac specific initilization calls. Most of + * these calls must be made as soon as possible in the startup + * process. + * + * Results: + * Returns TCL_OK if everything went fine. If it didn't the + * application should probably fail. + * + * Side effects: + * Inits the application. + * + *---------------------------------------------------------------------- + */ + +int +MacintoshInit() +{ + int i; + long result, mask = 0x0700; /* mask = system 7.x */ + + /* + * Tk needs us to set the qd pointer it uses. This is needed + * so Tk doesn't have to assume the availablity of the qd global + * variable. Which in turn allows Tk to be used in code resources. + */ + tcl_macQdPtr = &qd; + + InitGraf(&tcl_macQdPtr->thePort); + InitFonts(); + InitWindows(); + InitMenus(); + InitDialogs((long) NULL); + InitCursor(); + + /* + * Make sure we are running on system 7 or higher + */ + + if ((NGetTrapAddress(_Gestalt, ToolTrap) == + NGetTrapAddress(_Unimplemented, ToolTrap)) + || (((Gestalt(gestaltSystemVersion, &result) != noErr) + || (mask != (result & mask))))) { + panic("Tcl/Tk requires System 7 or higher."); + } + + /* + * Make sure we have color quick draw + * (this means we can't run on 68000 macs) + */ + + if (((Gestalt(gestaltQuickdrawVersion, &result) != noErr) + || (result < gestalt32BitQD13))) { + panic("Tk requires Color QuickDraw."); + } + + + FlushEvents(everyEvent, 0); + SetEventMask(everyEvent); + + /* + * Set up stack & heap sizes + */ + /* TODO: stack size + size = StackSpace(); + SetAppLimit(GetAppLimit() - 8192); + */ + MaxApplZone(); + for (i = 0; i < 4; i++) { + (void) MoreMasters(); + } + + TclMacSetEventProc(TkMacConvertEvent); + TkConsoleCreate(); + + return TCL_OK; +} + +/* + *---------------------------------------------------------------------- + * + * SetupMainInterp -- + * + * This procedure calls initalization routines require a Tcl + * interp as an argument. This call effectively makes the passed + * iterpreter the "main" interpreter for the application. + * + * Results: + * Returns TCL_OK if everything went fine. If it didn't the + * application should probably fail. + * + * Side effects: + * More initilization. + * + *---------------------------------------------------------------------- + */ + +int +SetupMainInterp( + Tcl_Interp *interp) +{ + /* + * Initialize the console only if we are running as an interactive + * application. + */ + + TkMacInitAppleEvents(interp); + TkMacInitMenus(interp); + + if (strcmp(Tcl_GetVar(interp, "tcl_interactive", TCL_GLOBAL_ONLY), "1") + == 0) { + if (TkConsoleInit(interp) == TCL_ERROR) { + goto error; + } + } + + /* + * Attach the global interpreter to tk's expected global console + */ + + gStdoutInterp = interp; + + return TCL_OK; + +error: + panic(interp->result); + return TCL_ERROR; +} + +/* + *---------------------------------------------------------------------- + * + * InstallConsole, RemoveConsole, etc. -- + * + * The following functions provide the UI for the console package. + * Users wishing to replace SIOUX with their own console package + * need only provide the four functions below in a library. + * + * Results: + * See SIOUX documentation for details. + * + * Side effects: + * See SIOUX documentation for details. + * + *---------------------------------------------------------------------- + */ + +short +InstallConsole(short fd) +{ +#pragma unused (fd) + + return 0; +} + +void +RemoveConsole(void) +{ +} + +long +WriteCharsToConsole(char *buffer, long n) +{ + TkConsolePrint(gStdoutInterp, TCL_STDOUT, buffer, n); + return n; +} + +long +ReadCharsFromConsole(char *buffer, long n) +{ + return 0; +} + +extern char * +__ttyname(long fildes) +{ + static char *devicename = "null device"; + + if (fildes >= 0 && fildes <= 2) { + return (devicename); + } + + return (0L); +} + +short +SIOUXHandleOneEvent(EventRecord *event) +{ + return 0; +} diff --git a/Lib/tcl/std_common.i b/Lib/tcl/std_common.i new file mode 100644 index 0000000..3a6f470 --- /dev/null +++ b/Lib/tcl/std_common.i @@ -0,0 +1,20 @@ +/* ----------------------------------------------------------------------------- + * See the LICENSE file for information on copyright, usage and redistribution + * of SWIG, and the README file for authors - http://www.swig.org/release.html. + * + * std_common.i + * + * SWIG typemaps for STL - common utilities + * ----------------------------------------------------------------------------- */ + +%include <std/std_except.i> + +%types(std::size_t); +%apply size_t { std::size_t }; +%apply const unsigned long& { const std::size_t& }; + +%types(std::ptrdiff_t); +%apply long { std::ptrdiff_t }; +%apply const long& { const std::ptrdiff_t& }; + + diff --git a/Lib/tcl/std_deque.i b/Lib/tcl/std_deque.i new file mode 100644 index 0000000..cb98f6c --- /dev/null +++ b/Lib/tcl/std_deque.i @@ -0,0 +1 @@ +%include <std/_std_deque.i> diff --git a/Lib/tcl/std_except.i b/Lib/tcl/std_except.i new file mode 100644 index 0000000..af98428 --- /dev/null +++ b/Lib/tcl/std_except.i @@ -0,0 +1 @@ +%include <typemaps/std_except.swg> diff --git a/Lib/tcl/std_map.i b/Lib/tcl/std_map.i new file mode 100644 index 0000000..006a62e --- /dev/null +++ b/Lib/tcl/std_map.i @@ -0,0 +1,173 @@ +// +// SWIG typemaps for std::map +// Luigi Ballabio +// Jan. 2003 +// +// Common implementation + +%include <std_common.i> + +// ------------------------------------------------------------------------ +// std::map +// ------------------------------------------------------------------------ + +%{ +#include <map> +#include <algorithm> +#include <stdexcept> +%} + +// exported class + +namespace std { + + template<class K, class T> class map { + // add typemaps here + public: + map(); + map(const map<K,T> &); + + unsigned int size() const; + bool empty() const; + void clear(); + %extend { + T& get(const K& key) throw (std::out_of_range) { + std::map<K,T >::iterator i = self->find(key); + if (i != self->end()) + return i->second; + else + throw std::out_of_range("key not found"); + } + void set(const K& key, const T& x) { + (*self)[key] = x; + } + void del(const K& key) throw (std::out_of_range) { + std::map<K,T >::iterator i = self->find(key); + if (i != self->end()) + self->erase(i); + else + throw std::out_of_range("key not found"); + } + bool has_key(const K& key) { + std::map<K,T >::iterator i = self->find(key); + return i != self->end(); + } + } + }; + + + // specializations for built-ins + + %define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO) + + template<class T> class map<K,T> { + // add typemaps here + public: + map(); + map(const map<K,T> &); + + unsigned int size() const; + bool empty() const; + void clear(); + %extend { + T& get(K key) throw (std::out_of_range) { + std::map<K,T >::iterator i = self->find(key); + if (i != self->end()) + return i->second; + else + throw std::out_of_range("key not found"); + } + void set(K key, const T& x) { + (*self)[key] = x; + } + void del(K key) throw (std::out_of_range) { + std::map<K,T >::iterator i = self->find(key); + if (i != self->end()) + self->erase(i); + else + throw std::out_of_range("key not found"); + } + bool has_key(K key) { + std::map<K,T >::iterator i = self->find(key); + return i != self->end(); + } + } + }; + %enddef + + %define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO) + template<class K> class map<K,T> { + // add typemaps here + public: + map(); + map(const map<K,T> &); + + unsigned int size() const; + bool empty() const; + void clear(); + %extend { + T get(const K& key) throw (std::out_of_range) { + std::map<K,T >::iterator i = self->find(key); + if (i != self->end()) + return i->second; + else + throw std::out_of_range("key not found"); + } + void set(const K& key, T x) { + (*self)[key] = x; + } + void del(const K& key) throw (std::out_of_range) { + std::map<K,T >::iterator i = self->find(key); + if (i != self->end()) + self->erase(i); + else + throw std::out_of_range("key not found"); + } + bool has_key(const K& key) { + std::map<K,T >::iterator i = self->find(key); + return i != self->end(); + } + } + }; + %enddef + + %define specialize_std_map_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO, + T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO) + template<> class map<K,T> { + // add typemaps here + public: + map(); + map(const map<K,T> &); + + unsigned int size() const; + bool empty() const; + void clear(); + %extend { + T get(K key) throw (std::out_of_range) { + std::map<K,T >::iterator i = self->find(key); + if (i != self->end()) + return i->second; + else + throw std::out_of_range("key not found"); + } + void set(K key, T x) { + (*self)[key] = x; + } + void del(K key) throw (std::out_of_range) { + std::map<K,T >::iterator i = self->find(key); + if (i != self->end()) + self->erase(i); + else + throw std::out_of_range("key not found"); + } + bool has_key(K key) { + std::map<K,T >::iterator i = self->find(key); + return i != self->end(); + } + } + }; + %enddef + + // add specializations here + +} diff --git a/Lib/tcl/std_pair.i b/Lib/tcl/std_pair.i new file mode 100644 index 0000000..52e9667 --- /dev/null +++ b/Lib/tcl/std_pair.i @@ -0,0 +1,37 @@ +/* ----------------------------------------------------------------------------- + * See the LICENSE file for information on copyright, usage and redistribution + * of SWIG, and the README file for authors - http://www.swig.org/release.html. + * + * std_pair.i + * + * Typemaps for std::pair + * ----------------------------------------------------------------------------- */ + +%include <std_common.i> +%include <exception.i> + +// ------------------------------------------------------------------------ +// std::pair +// ------------------------------------------------------------------------ + +%{ +#include <utility> +%} + +namespace std { + + template<class T, class U> struct pair { + + pair(); + pair(T first, U second); + pair(const pair& p); + + template <class U1, class U2> pair(const pair<U1, U2> &p); + + T first; + U second; + }; + + // add specializations here + +} diff --git a/Lib/tcl/std_string.i b/Lib/tcl/std_string.i new file mode 100644 index 0000000..5b31b28 --- /dev/null +++ b/Lib/tcl/std_string.i @@ -0,0 +1,2 @@ +%include <typemaps/std_string.swg> + diff --git a/Lib/tcl/std_vector.i b/Lib/tcl/std_vector.i new file mode 100644 index 0000000..2732142 --- /dev/null +++ b/Lib/tcl/std_vector.i @@ -0,0 +1,422 @@ +/* ----------------------------------------------------------------------------- + * See the LICENSE file for information on copyright, usage and redistribution + * of SWIG, and the README file for authors - http://www.swig.org/release.html. + * + * std_vector.i + * ----------------------------------------------------------------------------- */ + +%include <std_common.i> + +// ------------------------------------------------------------------------ +// std::vector +// +// The aim of all that follows would be to integrate std::vector with +// Tcl as much as possible, namely, to allow the user to pass and +// be returned Tcl lists. +// const declarations are used to guess the intent of the function being +// exported; therefore, the following rationale is applied: +// +// -- f(std::vector< T >), f(const std::vector< T >&), f(const std::vector< T >*): +// the parameter being read-only, either a Tcl list or a +// previously wrapped std::vector< T > can be passed. +// -- f(std::vector< T >&), f(std::vector< T >*): +// the parameter must be modified; therefore, only a wrapped std::vector +// can be passed. +// -- std::vector< T > f(): +// the vector is returned by copy; therefore, a Tcl list of T:s +// is returned which is most easily used in other Tcl functions procs +// -- std::vector< T >& f(), std::vector< T >* f(), const std::vector< T >& f(), +// const std::vector< T >* f(): +// the vector is returned by reference; therefore, a wrapped std::vector +// is returned +// ------------------------------------------------------------------------ + +%{ +#include <vector> +#include <algorithm> +#include <stdexcept> +#include <string> + +Tcl_Obj* SwigString_FromString(const std::string &s) { + return Tcl_NewStringObj(s.data(), (int)s.length()); +} + +int Tcl_GetBoolFromObj(Tcl_Interp *interp, Tcl_Obj *o, bool *val) { + int v; + int res = Tcl_GetBooleanFromObj(interp, o, &v); + if (res == TCL_OK) { + *val = v ? true : false; + } + return res; +} + +int SwigString_AsString(Tcl_Interp *interp, Tcl_Obj *o, std::string *val) { + int len; + const char* temp = Tcl_GetStringFromObj(o, &len); + if (temp == NULL) + return TCL_ERROR; + val->assign(temp, len); + return TCL_OK; +} + +// behaviour of this is such as the real Tcl_GetIntFromObj +template <typename Type> +int SwigInt_As(Tcl_Interp *interp, Tcl_Obj *o, Type *val) { + int temp_val, return_val; + return_val = Tcl_GetIntFromObj(interp, o, &temp_val); + *val = (Type) temp_val; + return return_val; +} + +// behaviour of this is such as the real Tcl_GetDoubleFromObj +template <typename Type> +int SwigDouble_As(Tcl_Interp *interp, Tcl_Obj *o, Type *val) { + int return_val; + double temp_val; + return_val = Tcl_GetDoubleFromObj(interp, o, &temp_val); + *val = (Type) temp_val; + return return_val; +} + +%} + +// exported class + +namespace std { + + template<class T> class vector { + %typemap(in) vector< T > (std::vector< T > *v) { + Tcl_Obj **listobjv; + int nitems; + int i; + T* temp; + + if (SWIG_ConvertPtr($input, (void **) &v, \ + $&1_descriptor, 0) == 0){ + $1 = *v; + } else { + // It isn't a vector< T > so it should be a list of T's + if(Tcl_ListObjGetElements(interp, $input, \ + &nitems, &listobjv) == TCL_ERROR) + return TCL_ERROR; + $1 = std::vector< T >(); + for (i = 0; i < nitems; i++) { + if ((SWIG_ConvertPtr(listobjv[i],(void **) &temp, + $descriptor(T *),0)) != 0) { + char message[] = + "list of " #T " expected"; + Tcl_SetResult(interp, message, TCL_VOLATILE); + return TCL_ERROR; + } + $1.push_back(*temp); + } + } + } + + %typemap(in) const vector< T >* (std::vector< T > *v, std::vector< T > w), + const vector< T >& (std::vector< T > *v, std::vector< T > w) { + Tcl_Obj **listobjv; + int nitems; + int i; + T* temp; + + if(SWIG_ConvertPtr($input, (void **) &v, \ + $&1_descriptor, 0) == 0) { + $1 = v; + } else { + // It isn't a vector< T > so it should be a list of T's + if(Tcl_ListObjGetElements(interp, $input, + &nitems, &listobjv) == TCL_ERROR) + return TCL_ERROR; + w = std::vector< T >(); + for (i = 0; i < nitems; i++) { + if ((SWIG_ConvertPtr(listobjv[i],(void **) &temp, + $descriptor(T *),0)) != 0) { + char message[] = + "list of " #T " expected"; + Tcl_SetResult(interp, message, TCL_VOLATILE); + return TCL_ERROR; + } + w.push_back(*temp); + } + $1 = &w; + } + } + + %typemap(out) vector< T > { + for (unsigned int i=0; i<$1.size(); i++) { + T* ptr = new T((($1_type &)$1)[i]); + Tcl_ListObjAppendElement(interp, $result, \ + SWIG_NewInstanceObj(ptr, + $descriptor(T *), + 0)); + } + } + + %typecheck(SWIG_TYPECHECK_VECTOR) vector< T > { + Tcl_Obj **listobjv; + int nitems; + T* temp; + std::vector< T > *v; + + if(SWIG_ConvertPtr($input, (void **) &v, \ + $&1_descriptor, 0) == 0) { + /* wrapped vector */ + $1 = 1; + } else { + // It isn't a vector< T > so it should be a list of T's + if(Tcl_ListObjGetElements(interp, $input, + &nitems, &listobjv) == TCL_ERROR) + $1 = 0; + else + if (nitems == 0) + $1 = 1; + //check the first value to see if it is of correct type + else if ((SWIG_ConvertPtr(listobjv[0], + (void **) &temp, + $descriptor(T *),0)) != 0) + $1 = 0; + else + $1 = 1; + } + } + + %typecheck(SWIG_TYPECHECK_VECTOR) const vector< T >&, + const vector< T >* { + Tcl_Obj **listobjv; + int nitems; + T* temp; + std::vector< T > *v; + + if(SWIG_ConvertPtr($input, (void **) &v, \ + $1_descriptor, 0) == 0){ + /* wrapped vector */ + $1 = 1; + } else { + // It isn't a vector< T > so it should be a list of T's + if(Tcl_ListObjGetElements(interp, $input, + &nitems, &listobjv) == TCL_ERROR) + $1 = 0; + else + if (nitems == 0) + $1 = 1; + //check the first value to see if it is of correct type + else if ((SWIG_ConvertPtr(listobjv[0], + (void **) &temp, + $descriptor(T *),0)) != 0) + $1 = 0; + else + $1 = 1; + } + } + + public: + vector(unsigned int size = 0); + vector(unsigned int size, const T& value); + vector(const vector< T > &); + + unsigned int size() const; + bool empty() const; + void clear(); + %rename(push) push_back; + void push_back(const T& x); + %extend { + T pop() throw (std::out_of_range) { + if (self->size() == 0) + throw std::out_of_range("pop from empty vector"); + T x = self->back(); + self->pop_back(); + return x; + } + T& get(int i) throw (std::out_of_range) { + int size = int(self->size()); + if (i<0) i += size; + if (i>=0 && i<size) + return (*self)[i]; + else + throw std::out_of_range("vector index out of range"); + } + void set(int i, const T& x) throw (std::out_of_range) { + int size = int(self->size()); + if (i<0) i+= size; + if (i>=0 && i<size) + (*self)[i] = x; + else + throw std::out_of_range("vector index out of range"); + } + } + }; + + + // specializations for built-ins + + %define specialize_std_vector(T, CONVERT_FROM, CONVERT_TO) + template<> class vector< T > { + + %typemap(in) vector< T > (std::vector< T > *v){ + Tcl_Obj **listobjv; + int nitems; + int i; + T temp; + + if(SWIG_ConvertPtr($input, (void **) &v, \ + $&1_descriptor, 0) == 0) { + $1 = *v; + } else { + // It isn't a vector< T > so it should be a list of T's + if(Tcl_ListObjGetElements(interp, $input, + &nitems, &listobjv) == TCL_ERROR) + return TCL_ERROR; + $1 = std::vector< T >(); + for (i = 0; i < nitems; i++) { + if (CONVERT_FROM(interp, listobjv[i], &temp) == TCL_ERROR) + return TCL_ERROR; + $1.push_back(temp); + } + } + } + + %typemap(in) const vector< T >& (std::vector< T > *v,std::vector< T > w), + const vector< T >* (std::vector< T > *v,std::vector< T > w) { + Tcl_Obj **listobjv; + int nitems; + int i; + T temp; + + if(SWIG_ConvertPtr($input, (void **) &v, \ + $1_descriptor, 0) == 0) { + $1 = v; + } else { + // It isn't a vector< T > so it should be a list of T's + if(Tcl_ListObjGetElements(interp, $input, + &nitems, &listobjv) == TCL_ERROR) + return TCL_ERROR; + w = std::vector< T >(); + for (i = 0; i < nitems; i++) { + if (CONVERT_FROM(interp, listobjv[i], &temp) == TCL_ERROR) + return TCL_ERROR; + w.push_back(temp); + } + $1 = &w; + } + } + + %typemap(out) vector< T > { + for (unsigned int i=0; i<$1.size(); i++) { + Tcl_ListObjAppendElement(interp, $result, \ + CONVERT_TO((($1_type &)$1)[i])); + } + } + + %typecheck(SWIG_TYPECHECK_VECTOR) vector< T > { + Tcl_Obj **listobjv; + int nitems; + T temp; + std::vector< T > *v; + + if(SWIG_ConvertPtr($input, (void **) &v, \ + $&1_descriptor, 0) == 0){ + /* wrapped vector */ + $1 = 1; + } else { + // It isn't a vector< T > so it should be a list of T's + if(Tcl_ListObjGetElements(interp, $input, + &nitems, &listobjv) == TCL_ERROR) + $1 = 0; + else + if (nitems == 0) + $1 = 1; + //check the first value to see if it is of correct type + if (CONVERT_FROM(interp, listobjv[0], &temp) == TCL_ERROR) + $1 = 0; + else + $1 = 1; + } + } + + %typecheck(SWIG_TYPECHECK_VECTOR) const vector< T >&, + const vector< T >*{ + Tcl_Obj **listobjv; + int nitems; + T temp; + std::vector< T > *v; + + if(SWIG_ConvertPtr($input, (void **) &v, \ + $1_descriptor, 0) == 0){ + /* wrapped vector */ + $1 = 1; + } else { + // It isn't a vector< T > so it should be a list of T's + if(Tcl_ListObjGetElements(interp, $input, + &nitems, &listobjv) == TCL_ERROR) + $1 = 0; + else + if (nitems == 0) + $1 = 1; + //check the first value to see if it is of correct type + if (CONVERT_FROM(interp, listobjv[0], &temp) == TCL_ERROR) + $1 = 0; + else + $1 = 1; + } + } + + public: + vector(unsigned int size = 0); + vector(unsigned int size, const T& value); + vector(const vector< T > &); + + unsigned int size() const; + bool empty() const; + void clear(); + %rename(push) push_back; + void push_back(T x); + %extend { + T pop() throw (std::out_of_range) { + if (self->size() == 0) + throw std::out_of_range("pop from empty vector"); + T x = self->back(); + self->pop_back(); + return x; + } + T get(int i) throw (std::out_of_range) { + int size = int(self->size()); + if (i<0) i += size; + if (i>=0 && i<size) + return (*self)[i]; + else + throw std::out_of_range("vector index out of range"); + } + void set(int i, T x) throw (std::out_of_range) { + int size = int(self->size()); + if (i<0) i+= size; + if (i>=0 && i<size) + (*self)[i] = x; + else + throw std::out_of_range("vector index out of range"); + } + } + }; + %enddef + + specialize_std_vector(bool, Tcl_GetBoolFromObj, Tcl_NewBooleanObj); + specialize_std_vector(char, SwigInt_As<char>,Tcl_NewIntObj); + specialize_std_vector(int, Tcl_GetIntFromObj,Tcl_NewIntObj); + specialize_std_vector(short, SwigInt_As<short>, Tcl_NewIntObj); + specialize_std_vector(long, SwigInt_As<long>, Tcl_NewIntObj); + specialize_std_vector(unsigned char, + SwigInt_As<unsigned char>, Tcl_NewIntObj); + specialize_std_vector(unsigned int, + SwigInt_As<unsigned int>, Tcl_NewIntObj); + specialize_std_vector(unsigned short, + SwigInt_As<unsigned short>, Tcl_NewIntObj); + specialize_std_vector(unsigned long, + SwigInt_As<unsigned long>, Tcl_NewIntObj); + specialize_std_vector(double, Tcl_GetDoubleFromObj, Tcl_NewDoubleObj); + specialize_std_vector(float, SwigDouble_As<float>, Tcl_NewDoubleObj); + specialize_std_vector(std::string, + SwigString_AsString, SwigString_FromString); + +} + + diff --git a/Lib/tcl/std_wstring.i b/Lib/tcl/std_wstring.i new file mode 100644 index 0000000..f132614 --- /dev/null +++ b/Lib/tcl/std_wstring.i @@ -0,0 +1,2 @@ +%include <tclwstrings.swg> +%include <typemaps/std_wstring.swg> diff --git a/Lib/tcl/stl.i b/Lib/tcl/stl.i new file mode 100644 index 0000000..afd1213 --- /dev/null +++ b/Lib/tcl/stl.i @@ -0,0 +1,14 @@ +/* ----------------------------------------------------------------------------- + * See the LICENSE file for information on copyright, usage and redistribution + * of SWIG, and the README file for authors - http://www.swig.org/release.html. + * + * stl.i + * ----------------------------------------------------------------------------- */ + +/* initial STL definition. extended as needed in each language */ +%include <std_common.i> +%include <std_string.i> +%include <std_vector.i> +%include <std_map.i> +%include <std_pair.i> + diff --git a/Lib/tcl/tcl8.swg b/Lib/tcl/tcl8.swg new file mode 100644 index 0000000..c33cc76 --- /dev/null +++ b/Lib/tcl/tcl8.swg @@ -0,0 +1,45 @@ +/* ----------------------------------------------------------------------------- + * See the LICENSE file for information on copyright, usage and redistribution + * of SWIG, and the README file for authors - http://www.swig.org/release.html. + * + * tcl8.swg + * + * Tcl configuration module. + * ----------------------------------------------------------------------------- */ + +/* ------------------------------------------------------------ + * Inner macros + * ------------------------------------------------------------ */ +%include <tclmacros.swg> + +/* ------------------------------------------------------------ + * The runtime part + * ------------------------------------------------------------ */ +%include <tclruntime.swg> + +/* ------------------------------------------------------------ + * Special user directives + * ------------------------------------------------------------ */ +%include <tcluserdir.swg> + +/* ------------------------------------------------------------ + * Typemap specializations + * ------------------------------------------------------------ */ +%include <tcltypemaps.swg> + +/* ------------------------------------------------------------ + * Overloaded operator support + * ------------------------------------------------------------ */ +%include <tclopers.swg> + +/* ------------------------------------------------------------ + * Warnings for Tcl keywords + * ------------------------------------------------------------ */ +%include <tclkw.swg> + +/* ------------------------------------------------------------ + * The Tcl initialization function + * ------------------------------------------------------------ */ +%include <tclinit.swg> + + diff --git a/Lib/tcl/tclapi.swg b/Lib/tcl/tclapi.swg new file mode 100644 index 0000000..6b67327 --- /dev/null +++ b/Lib/tcl/tclapi.swg @@ -0,0 +1,107 @@ +/* ----------------------------------------------------------------------------- + * SWIG API. Portion that goes into the runtime + * ----------------------------------------------------------------------------- */ +#ifdef __cplusplus +extern "C" { +#endif + +/* ----------------------------------------------------------------------------- + * Constant declarations + * ----------------------------------------------------------------------------- */ + +/* Constant Types */ +#define SWIG_TCL_POINTER 4 +#define SWIG_TCL_BINARY 5 + +/* Constant information structure */ +typedef struct swig_const_info { + int type; + char *name; + long lvalue; + double dvalue; + void *pvalue; + swig_type_info **ptype; +} swig_const_info; + +typedef int (*swig_wrapper)(ClientData, Tcl_Interp *, int, Tcl_Obj *CONST []); +typedef int (*swig_wrapper_func)(ClientData, Tcl_Interp *, int, Tcl_Obj *CONST []); +typedef char *(*swig_variable_func)(ClientData, Tcl_Interp *, char *, char *, int); +typedef void (*swig_delete_func)(ClientData); + +typedef struct swig_method { + const char *name; + swig_wrapper method; +} swig_method; + +typedef struct swig_attribute { + const char *name; + swig_wrapper getmethod; + swig_wrapper setmethod; +} swig_attribute; + +typedef struct swig_class { + const char *name; + swig_type_info **type; + swig_wrapper constructor; + void (*destructor)(void *); + swig_method *methods; + swig_attribute *attributes; + struct swig_class **bases; + const char **base_names; + swig_module_info *module; +} swig_class; + +typedef struct swig_instance { + Tcl_Obj *thisptr; + void *thisvalue; + swig_class *classptr; + int destroy; + Tcl_Command cmdtok; +} swig_instance; + +/* Structure for command table */ +typedef struct { + const char *name; + int (*wrapper)(ClientData, Tcl_Interp *, int, Tcl_Obj *CONST []); + ClientData clientdata; +} swig_command_info; + +/* Structure for variable linking table */ +typedef struct { + const char *name; + void *addr; + char * (*get)(ClientData, Tcl_Interp *, char *, char *, int); + char * (*set)(ClientData, Tcl_Interp *, char *, char *, int); +} swig_var_info; + + +/* -----------------------------------------------------------------------------* + * Install a constant object + * -----------------------------------------------------------------------------*/ + +static Tcl_HashTable swigconstTable; +static int swigconstTableinit = 0; + +SWIGINTERN void +SWIG_Tcl_SetConstantObj(Tcl_Interp *interp, const char* name, Tcl_Obj *obj) { + int newobj; + Tcl_ObjSetVar2(interp,Tcl_NewStringObj(name,-1), NULL, obj, TCL_GLOBAL_ONLY); + Tcl_SetHashValue(Tcl_CreateHashEntry(&swigconstTable, name, &newobj), (ClientData) obj); +} + +SWIGINTERN Tcl_Obj * +SWIG_Tcl_GetConstantObj(const char *key) { + Tcl_HashEntry *entryPtr; + if (!swigconstTableinit) return 0; + entryPtr = Tcl_FindHashEntry(&swigconstTable, key); + if (entryPtr) { + return (Tcl_Obj *) Tcl_GetHashValue(entryPtr); + } + return 0; +} + +#ifdef __cplusplus +} +#endif + + diff --git a/Lib/tcl/tclerrors.swg b/Lib/tcl/tclerrors.swg new file mode 100644 index 0000000..889d3ad --- /dev/null +++ b/Lib/tcl/tclerrors.swg @@ -0,0 +1,76 @@ +/* ----------------------------------------------------------------------------- + * error manipulation + * ----------------------------------------------------------------------------- */ + +SWIGINTERN const char* +SWIG_Tcl_ErrorType(int code) { + const char* type = 0; + switch(code) { + case SWIG_MemoryError: + type = "MemoryError"; + break; + case SWIG_IOError: + type = "IOError"; + break; + case SWIG_RuntimeError: + type = "RuntimeError"; + break; + case SWIG_IndexError: + type = "IndexError"; + break; + case SWIG_TypeError: + type = "TypeError"; + break; + case SWIG_DivisionByZero: + type = "ZeroDivisionError"; + break; + case SWIG_OverflowError: + type = "OverflowError"; + break; + case SWIG_SyntaxError: + type = "SyntaxError"; + break; + case SWIG_ValueError: + type = "ValueError"; + break; + case SWIG_SystemError: + type = "SystemError"; + break; + case SWIG_AttributeError: + type = "AttributeError"; + break; + default: + type = "RuntimeError"; + } + return type; +} + + +SWIGINTERN void +SWIG_Tcl_SetErrorObj(Tcl_Interp *interp, const char *ctype, Tcl_Obj *obj) +{ + Tcl_ResetResult(interp); + Tcl_SetObjResult(interp, obj); + Tcl_SetErrorCode(interp, "SWIG", ctype, NULL); +} + +SWIGINTERN void +SWIG_Tcl_SetErrorMsg(Tcl_Interp *interp, const char *ctype, const char *mesg) +{ + Tcl_ResetResult(interp); + Tcl_SetErrorCode(interp, "SWIG", ctype, NULL); + Tcl_AppendResult(interp, ctype, " ", mesg, NULL); + /* + Tcl_AddErrorInfo(interp, ctype); + Tcl_AddErrorInfo(interp, " "); + Tcl_AddErrorInfo(interp, mesg); + */ +} + +SWIGINTERNINLINE void +SWIG_Tcl_AddErrorMsg(Tcl_Interp *interp, const char* mesg) +{ + Tcl_AddErrorInfo(interp, mesg); +} + + diff --git a/Lib/tcl/tclfragments.swg b/Lib/tcl/tclfragments.swg new file mode 100644 index 0000000..ba6398c --- /dev/null +++ b/Lib/tcl/tclfragments.swg @@ -0,0 +1,22 @@ +/* + + Create a file with this name, 'tclfragments.swg', in your working + directory and add all the %fragments you want to take precedence + over the ones defined by default by swig. + + For example, if you add: + + %fragment(SWIG_AsVal_frag(int),"header") { + SWIGINTERNINLINE int + SWIG_AsVal_dec(int)(TclObject *obj, int *val) + { + <your code here>; + } + } + + this will replace the code used to retrieve an integer value for all + the typemaps that need it, including: + + int, std::vector<int>, std::list<std::pair<int,int> >, etc. + +*/ diff --git a/Lib/tcl/tclinit.swg b/Lib/tcl/tclinit.swg new file mode 100644 index 0000000..6910d3c --- /dev/null +++ b/Lib/tcl/tclinit.swg @@ -0,0 +1,119 @@ +/* ------------------------------------------------------------ + * The start of the Tcl initialization function + * ------------------------------------------------------------ */ + +%insert(init) "swiginit.swg" + +/* This initialization code exports the module initialization function */ + +%header %{ + +#ifdef __cplusplus +extern "C" { +#endif +#ifdef MAC_TCL +#pragma export on +#endif +SWIGEXPORT int SWIG_init(Tcl_Interp *); +#ifdef MAC_TCL +#pragma export off +#endif +#ifdef __cplusplus +} +#endif + +/* Compatibility version for TCL stubs */ +#ifndef SWIG_TCL_STUBS_VERSION +#define SWIG_TCL_STUBS_VERSION "8.1" +#endif + +%} + +%init %{ +#ifdef __cplusplus +extern "C" { +#endif + +/* ----------------------------------------------------------------------------- + * constants/methods manipulation + * ----------------------------------------------------------------------------- */ + +/* Install Constants */ + +SWIGINTERN void +SWIG_Tcl_InstallConstants(Tcl_Interp *interp, swig_const_info constants[]) { + int i; + Tcl_Obj *obj; + + if (!swigconstTableinit) { + Tcl_InitHashTable(&swigconstTable, TCL_STRING_KEYS); + swigconstTableinit = 1; + } + for (i = 0; constants[i].type; i++) { + switch(constants[i].type) { + case SWIG_TCL_POINTER: + obj = SWIG_NewPointerObj(constants[i].pvalue, *(constants[i]).ptype,0); + break; + case SWIG_TCL_BINARY: + obj = SWIG_NewPackedObj(constants[i].pvalue, constants[i].lvalue, *(constants[i].ptype)); + break; + default: + obj = 0; + break; + } + if (obj) { + SWIG_Tcl_SetConstantObj(interp, constants[i].name, obj); + } + } +} + +#ifdef __cplusplus +} +#endif + +/* -----------------------------------------------------------------------------* + * Partial Init method + * -----------------------------------------------------------------------------*/ + +SWIGEXPORT int SWIG_init(Tcl_Interp *interp) { + int i; + if (interp == 0) return TCL_ERROR; +#ifdef USE_TCL_STUBS + /* (char*) cast is required to avoid compiler warning/error for Tcl < 8.4. */ + if (Tcl_InitStubs(interp, (char*)SWIG_TCL_STUBS_VERSION, 0) == NULL) { + return TCL_ERROR; + } +#endif +#ifdef USE_TK_STUBS + /* (char*) cast is required to avoid compiler warning/error. */ + if (Tk_InitStubs(interp, (char*)SWIG_TCL_STUBS_VERSION, 0) == NULL) { + return TCL_ERROR; + } +#endif + + Tcl_PkgProvide(interp, (char*)SWIG_name, (char*)SWIG_version); + +#ifdef SWIG_namespace + Tcl_Eval(interp, "namespace eval " SWIG_namespace " { }"); +#endif + + SWIG_InitializeModule((void *) interp); + SWIG_PropagateClientData(); + + for (i = 0; swig_commands[i].name; i++) { + Tcl_CreateObjCommand(interp, (char *) swig_commands[i].name, (swig_wrapper_func) swig_commands[i].wrapper, + swig_commands[i].clientdata, NULL); + } + for (i = 0; swig_variables[i].name; i++) { + Tcl_SetVar(interp, (char *) swig_variables[i].name, (char *) "", TCL_GLOBAL_ONLY); + Tcl_TraceVar(interp, (char *) swig_variables[i].name, TCL_TRACE_READS | TCL_GLOBAL_ONLY, + (Tcl_VarTraceProc *) swig_variables[i].get, (ClientData) swig_variables[i].addr); + Tcl_TraceVar(interp, (char *) swig_variables[i].name, TCL_TRACE_WRITES | TCL_GLOBAL_ONLY, + (Tcl_VarTraceProc *) swig_variables[i].set, (ClientData) swig_variables[i].addr); + } + + SWIG_Tcl_InstallConstants(interp, swig_constants); + +%} + +/* Note: the initialization function is closed after all code is generated */ diff --git a/Lib/tcl/tclinterp.i b/Lib/tcl/tclinterp.i new file mode 100644 index 0000000..48cdb60 --- /dev/null +++ b/Lib/tcl/tclinterp.i @@ -0,0 +1,20 @@ +/* ----------------------------------------------------------------------------- + * See the LICENSE file for information on copyright, usage and redistribution + * of SWIG, and the README file for authors - http://www.swig.org/release.html. + * + * tclinterp.i + * + * Tcl_Interp *interp + * + * Passes the current Tcl_Interp value directly to a C function. + * This can be used to work with existing wrapper functions or + * if you just need the interp value for some reason. When used, + * the 'interp' parameter becomes hidden in the Tcl interface--that + * is, you don't specify it explicitly. SWIG fills in its value + * automatically. + * ----------------------------------------------------------------------------- */ + +%typemap(in,numinputs=0) Tcl_Interp *interp { + $1 = interp; +} + diff --git a/Lib/tcl/tclkw.swg b/Lib/tcl/tclkw.swg new file mode 100644 index 0000000..e96e885 --- /dev/null +++ b/Lib/tcl/tclkw.swg @@ -0,0 +1,10 @@ +#ifndef TCL_TCLKW_SWG_ +#define TCL_TCLKW_SWG_ + +// Some special reserved words in classes + +%keywordwarn("cget is a tcl reserved method name") *::cget; +%keywordwarn("configure is a tcl reserved method name") *::configure; + + +#endif //_TCL_TCLKW_SWG_ diff --git a/Lib/tcl/tclmacros.swg b/Lib/tcl/tclmacros.swg new file mode 100644 index 0000000..ab7bace --- /dev/null +++ b/Lib/tcl/tclmacros.swg @@ -0,0 +1,4 @@ +%include <typemaps/swigmacros.swg> + + + diff --git a/Lib/tcl/tclopers.swg b/Lib/tcl/tclopers.swg new file mode 100644 index 0000000..26b7420 --- /dev/null +++ b/Lib/tcl/tclopers.swg @@ -0,0 +1,46 @@ +/* ----------------------------------------------------------------------------- + * See the LICENSE file for information on copyright, usage and redistribution + * of SWIG, and the README file for authors - http://www.swig.org/release.html. + * + * tclopers.swg + * + * C++ overloaded operators. + * + * These declarations define how SWIG is going to rename C++ + * overloaded operators in Tcl. Since Tcl allows identifiers + * to be essentially any valid string, we'll just use the + * normal operator names. + * ----------------------------------------------------------------------------- */ + + +#ifdef __cplusplus +%rename("+") *::operator+; +//%rename("u+") *::operator+(); // Unary + +//%rename("u+") *::operator+() const; // Unary + +%rename("-") *::operator-; +//%rename("u-") *::operator-(); // Unary - +//%rename("u-") *::operator-() const; // Unary - +%rename("*") *::operator*; +%rename("/") *::operator/; +%rename("<<") *::operator<<; +%rename(">>") *::operator>>; +%rename("&") *::operator&; +%rename("|") *::operator|; +%rename("^") *::operator^; +%rename("%") *::operator%; +%rename("=") *::operator=; + +/* Ignored operators */ +%ignoreoperator(NOTEQUAL) operator!=; +%ignoreoperator(PLUSEQ) operator+=; +%ignoreoperator(MINUSEQ) operator-=; +%ignoreoperator(MULEQ) operator*=; +%ignoreoperator(DIVEQ) operator/=; +%ignoreoperator(MODEQ) operator%=; +%ignoreoperator(LSHIFTEQ) operator<<=; +%ignoreoperator(RSHIFTEQ) operator>>=; +%ignoreoperator(ANDEQ) operator&=; +%ignoreoperator(OREQ) operator|=; +%ignoreoperator(XOREQ) operator^=; + +#endif diff --git a/Lib/tcl/tclprimtypes.swg b/Lib/tcl/tclprimtypes.swg new file mode 100644 index 0000000..e781798 --- /dev/null +++ b/Lib/tcl/tclprimtypes.swg @@ -0,0 +1,239 @@ +/* ------------------------------------------------------------ + * Primitive Types + * ------------------------------------------------------------ */ + +/* boolean */ + +%fragment(SWIG_From_frag(bool),"header") { + %define_as(SWIG_From_dec(bool), Tcl_NewBooleanObj) +} + +%fragment(SWIG_AsVal_frag(bool),"header") { +SWIGINTERN int +SWIG_AsVal_dec(bool)(Tcl_Obj *obj, bool *val) +{ + int v; + if (Tcl_GetBooleanFromObj(0, obj, &v) == TCL_OK) { + if (val) *val = v ? true : false; + return SWIG_OK; + } + return SWIG_TypeError; +} +} + +/* long */ + +%fragment(SWIG_From_frag(long),"header", + fragment="<limits.h>") { +SWIGINTERNINLINE Tcl_Obj* +SWIG_From_dec(long)(long value) +{ + if (((long) INT_MIN <= value) && (value <= (long) INT_MAX)) { + return Tcl_NewIntObj(%numeric_cast(value,int)); + } else { + return Tcl_NewLongObj(value); + } +} +} + +%fragment(SWIG_AsVal_frag(long),"header") { +SWIGINTERN int +SWIG_AsVal_dec(long)(Tcl_Obj *obj, long* val) +{ + long v; + if (Tcl_GetLongFromObj(0,obj, &v) == TCL_OK) { + if (val) *val = (long) v; + return SWIG_OK; + } + return SWIG_TypeError; +} +} + +/* unsigned long */ + +%fragment(SWIG_From_frag(unsigned long),"header", + fragment=SWIG_From_frag(long), + fragment="<stdio.h>") { +SWIGINTERNINLINE Tcl_Obj* +SWIG_From_dec(unsigned long)(unsigned long value) +{ + if (value < (unsigned long) LONG_MAX) { + return SWIG_From(long)(%numeric_cast(value, long)); + } else { + char temp[256]; + sprintf(temp, "%lu", value); + return Tcl_NewStringObj(temp,-1); + } +} +} + +%fragment(SWIG_AsVal_frag(unsigned long),"header", + fragment="<limits.h>") { +SWIGINTERN int +SWIG_AsVal_dec(unsigned long)(Tcl_Obj *obj, unsigned long *val) { + long v; + if (Tcl_GetLongFromObj(0,obj, &v) == TCL_OK) { + if (v >= 0) { + if (val) *val = (unsigned long) v; + return SWIG_OK; + } + /* If v is negative, then this could be a negative number, or an + unsigned value which doesn't fit in a signed long, so try to + get it as a string so we can distinguish these cases. */ + } + { + int len = 0; + const char *nptr = Tcl_GetStringFromObj(obj, &len); + if (nptr && len > 0) { + char *endptr; + unsigned long v; + if (*nptr == '-') return SWIG_OverflowError; + errno = 0; + v = strtoul(nptr, &endptr,0); + if (nptr[0] == '\0' || *endptr != '\0') + return SWIG_TypeError; + if (v == ULONG_MAX && errno == ERANGE) { + errno = 0; + return SWIG_OverflowError; + } else { + if (*endptr == '\0') { + if (val) *val = v; + return SWIG_OK; + } + } + } + } + + return SWIG_TypeError; +} +} + +/* long long */ + +%fragment(SWIG_From_frag(long long),"header", + fragment=SWIG_From_frag(long), + fragment="<limits.h>", + fragment="<stdio.h>") { +SWIGINTERNINLINE Tcl_Obj* +SWIG_From_dec(long long)(long long value) +{ + if (((long long) LONG_MIN <= value) && (value <= (long long) LONG_MAX)) { + return SWIG_From(long)(%numeric_cast(value,long)); + } else { + char temp[256]; + sprintf(temp, "%lld", value); + return Tcl_NewStringObj(temp,-1); + } +} +} + +%fragment(SWIG_AsVal_frag(long long),"header", + fragment="<limits.h>", + fragment="<stdlib.h>") { +SWIGINTERN int +SWIG_AsVal_dec(long long)(Tcl_Obj *obj, long long *val) +{ + long v; + if (Tcl_GetLongFromObj(0,obj, &v) == TCL_OK) { + if (val) *val = v; + return SWIG_OK; + } else { + int len = 0; + const char *nptr = Tcl_GetStringFromObj(obj, &len); + if (nptr && len > 0) { + char *endptr; + long long v; + errno = 0; + v = strtoll(nptr, &endptr,0); + if (nptr[0] == '\0' || *endptr != '\0') + return SWIG_TypeError; + if ((v == LLONG_MAX || v == LLONG_MIN) && errno == ERANGE) { + errno = 0; + return SWIG_OverflowError; + } else { + if (*endptr == '\0') { + if (val) *val = v; + return SWIG_OK; + } + } + } + } + return SWIG_TypeError; +} +} + +/* unsigned long long */ + +%fragment(SWIG_From_frag(unsigned long long),"header", + fragment=SWIG_From_frag(long long), + fragment="<limits.h>", + fragment="<stdio.h>") { +SWIGINTERNINLINE Tcl_Obj* +SWIG_From_dec(unsigned long long)(unsigned long long value) +{ + if (value < (unsigned long long) LONG_MAX) { + return SWIG_From(long long)(%numeric_cast(value, long long)); + } else { + char temp[256]; + sprintf(temp, "%llu", value); + return Tcl_NewStringObj(temp,-1); + } +} +} + +%fragment(SWIG_AsVal_frag(unsigned long long),"header", + fragment=SWIG_AsVal_frag(unsigned long), + fragment="<limits.h>", + fragment="<stdlib.h>") { +SWIGINTERN int +SWIG_AsVal_dec(unsigned long long)(Tcl_Obj *obj, unsigned long long *val) +{ + long v; + if (Tcl_GetLongFromObj(0,obj, &v) == TCL_OK) { + if (val) *val = (unsigned long) v; + return SWIG_OK; + } else { + int len = 0; + const char *nptr = Tcl_GetStringFromObj(obj, &len); + if (nptr && len > 0) { + char *endptr; + unsigned long long v; + if (*nptr == '-') return SWIG_OverflowError; + errno = 0; + v = strtoull(nptr, &endptr,0); + if (nptr[0] == '\0' || *endptr != '\0') + return SWIG_TypeError; + if (v == ULLONG_MAX && errno == ERANGE) { + errno = 0; + return SWIG_OverflowError; + } else { + if (*endptr == '\0') { + if (val) *val = v; + return SWIG_OK; + } + } + } + } + return SWIG_TypeError; +} +} + +/* double */ + +%fragment(SWIG_From_frag(double),"header") { + %define_as(SWIG_From(double), Tcl_NewDoubleObj) +} + +%fragment(SWIG_AsVal_frag(double),"header") { +SWIGINTERN int +SWIG_AsVal_dec(double)(Tcl_Obj *obj, double *val) +{ + double v; + if (Tcl_GetDoubleFromObj(0, obj, &v) == TCL_OK) { + if (val) *val = v; + return SWIG_OK; + } + return SWIG_TypeError; +} +} + diff --git a/Lib/tcl/tclresult.i b/Lib/tcl/tclresult.i new file mode 100644 index 0000000..ca01064 --- /dev/null +++ b/Lib/tcl/tclresult.i @@ -0,0 +1,30 @@ +/* ----------------------------------------------------------------------------- + * See the LICENSE file for information on copyright, usage and redistribution + * of SWIG, and the README file for authors - http://www.swig.org/release.html. + * + * tclresult.i + * ----------------------------------------------------------------------------- */ + +/* +int Tcl_Result + + Makes the integer return code of a function the return value + of a SWIG generated wrapper function. For example : + + int foo() { + ... do stuff ... + return TCL_OK; + } + + could be wrapped as follows : + + %include typemaps.i + %apply int Tcl_Result { int foo }; + int foo(); +*/ + +// If return code is a Tcl_Result, simply pass it on + +%typemap(out) int Tcl_Result { + return $1; +} diff --git a/Lib/tcl/tclrun.swg b/Lib/tcl/tclrun.swg new file mode 100644 index 0000000..6387fb0 --- /dev/null +++ b/Lib/tcl/tclrun.swg @@ -0,0 +1,695 @@ +/* ----------------------------------------------------------------------------- + * See the LICENSE file for information on copyright, usage and redistribution + * of SWIG, and the README file for authors - http://www.swig.org/release.html. + * + * tclrun.swg + * + * This file contains the runtime support for Tcl modules and includes + * code for managing global variables and pointer type checking. + * ----------------------------------------------------------------------------- */ + +/* Common SWIG API */ + +/* for raw pointers */ +#define SWIG_ConvertPtr(oc, ptr, ty, flags) SWIG_Tcl_ConvertPtr(interp, oc, ptr, ty, flags) +#define SWIG_NewPointerObj(ptr, type, flags) SWIG_Tcl_NewPointerObj(ptr, type, flags) + +/* for raw packed data */ +#define SWIG_ConvertPacked(obj, ptr, sz, ty) SWIG_Tcl_ConvertPacked(interp, obj, ptr, sz, ty) +#define SWIG_NewPackedObj(ptr, sz, type) SWIG_Tcl_NewPackedObj(ptr, sz, type) + +/* for class or struct pointers */ +#define SWIG_ConvertInstance(obj, pptr, type, flags) SWIG_Tcl_ConvertPtr(interp, obj, pptr, type, flags) +#define SWIG_NewInstanceObj(thisvalue, type, flags) SWIG_Tcl_NewInstanceObj(interp, thisvalue, type, flags) + +/* for C or C++ function pointers */ +#define SWIG_ConvertFunctionPtr(obj, pptr, type) SWIG_Tcl_ConvertPtr(interp, obj, pptr, type, 0) +#define SWIG_NewFunctionPtrObj(ptr, type) SWIG_Tcl_NewPointerObj(ptr, type, 0) + +/* for C++ member pointers, ie, member methods */ +#define SWIG_ConvertMember(obj, ptr, sz, ty) SWIG_Tcl_ConvertPacked(interp,obj, ptr, sz, ty) +#define SWIG_NewMemberObj(ptr, sz, type) SWIG_Tcl_NewPackedObj(ptr, sz, type) + + +/* Runtime API */ + +#define SWIG_GetModule(clientdata) SWIG_Tcl_GetModule((Tcl_Interp *) (clientdata)) +#define SWIG_SetModule(clientdata, pointer) SWIG_Tcl_SetModule((Tcl_Interp *) (clientdata), pointer) + + +/* Error manipulation */ + +#define SWIG_ErrorType(code) SWIG_Tcl_ErrorType(code) +#define SWIG_Error(code, msg) SWIG_Tcl_SetErrorMsg(interp, SWIG_Tcl_ErrorType(code), msg) +#define SWIG_fail goto fail + + +/* Tcl-specific SWIG API */ + +#define SWIG_Acquire(ptr) SWIG_Tcl_Acquire(ptr) +#define SWIG_MethodCommand SWIG_Tcl_MethodCommand +#define SWIG_Disown(ptr) SWIG_Tcl_Disown(ptr) +#define SWIG_ConvertPtrFromString(c, ptr, ty, flags) SWIG_Tcl_ConvertPtrFromString(interp, c, ptr, ty, flags) +#define SWIG_MakePtr(c, ptr, ty, flags) SWIG_Tcl_MakePtr(c, ptr, ty, flags) +#define SWIG_PointerTypeFromString(c) SWIG_Tcl_PointerTypeFromString(c) +#define SWIG_GetArgs SWIG_Tcl_GetArgs +#define SWIG_GetConstantObj(key) SWIG_Tcl_GetConstantObj(key) +#define SWIG_ObjectConstructor SWIG_Tcl_ObjectConstructor +#define SWIG_Thisown(ptr) SWIG_Tcl_Thisown(ptr) +#define SWIG_ObjectDelete SWIG_Tcl_ObjectDelete + + +#define SWIG_TCL_DECL_ARGS_2(arg1, arg2) (Tcl_Interp *interp SWIGUNUSED, arg1, arg2) +#define SWIG_TCL_CALL_ARGS_2(arg1, arg2) (interp, arg1, arg2) +/* ----------------------------------------------------------------------------- + * pointers/data manipulation + * ----------------------------------------------------------------------------- */ + +/* For backward compatibility only */ +#define SWIG_POINTER_EXCEPTION 0 +#define SWIG_GetConstant SWIG_GetConstantObj +#define SWIG_Tcl_GetConstant SWIG_Tcl_GetConstantObj + +#include "assert.h" + +#ifdef __cplusplus +extern "C" { +#if 0 +} /* cc-mode */ +#endif +#endif + +/* Object support */ + +SWIGRUNTIME Tcl_HashTable* +SWIG_Tcl_ObjectTable(void) { + static Tcl_HashTable swigobjectTable; + static int swigobjectTableinit = 0; + if (!swigobjectTableinit) { + Tcl_InitHashTable(&swigobjectTable, TCL_ONE_WORD_KEYS); + swigobjectTableinit = 1; + } + return &swigobjectTable; +} + +/* Acquire ownership of a pointer */ +SWIGRUNTIME void +SWIG_Tcl_Acquire(void *ptr) { + int newobj; + Tcl_CreateHashEntry(SWIG_Tcl_ObjectTable(), (char *) ptr, &newobj); +} + +SWIGRUNTIME int +SWIG_Tcl_Thisown(void *ptr) { + if (Tcl_FindHashEntry(SWIG_Tcl_ObjectTable(), (char *) ptr)) { + return 1; + } + return 0; +} + +/* Disown a pointer. Returns 1 if we owned it to begin with */ +SWIGRUNTIME int +SWIG_Tcl_Disown(void *ptr) { + Tcl_HashEntry *entryPtr = Tcl_FindHashEntry(SWIG_Tcl_ObjectTable(), (char *) ptr); + if (entryPtr) { + Tcl_DeleteHashEntry(entryPtr); + return 1; + } + return 0; +} + +/* Convert a pointer value */ +SWIGRUNTIME int +SWIG_Tcl_ConvertPtrFromString(Tcl_Interp *interp, const char *c, void **ptr, swig_type_info *ty, int flags) { + swig_cast_info *tc; + /* Pointer values must start with leading underscore */ + while (*c != '_') { + *ptr = (void *) 0; + if (strcmp(c,"NULL") == 0) return SWIG_OK; + + /* Empty string: not a pointer */ + if (*c == 0) return SWIG_ERROR; + + /* Hmmm. It could be an object name. */ + + /* Check if this is a command at all. Prevents <c> cget -this */ + /* from being called when c is not a command, firing the unknown proc */ + if (Tcl_VarEval(interp,"info commands ", c, (char *) NULL) == TCL_OK) { + Tcl_Obj *result = Tcl_GetObjResult(interp); + if (*(Tcl_GetStringFromObj(result, NULL)) == 0) { + /* It's not a command, so it can't be a pointer */ + Tcl_ResetResult(interp); + return SWIG_ERROR; + } + } else { + /* This will only fail if the argument is multiple words. */ + /* Multiple words are also not commands. */ + Tcl_ResetResult(interp); + return SWIG_ERROR; + } + + /* Check if this is really a SWIG pointer */ + if (Tcl_VarEval(interp,c," cget -this", (char *) NULL) != TCL_OK) { + Tcl_ResetResult(interp); + return SWIG_ERROR; + } + + c = Tcl_GetStringFromObj(Tcl_GetObjResult(interp), NULL); + } + + c++; + c = SWIG_UnpackData(c,ptr,sizeof(void *)); + if (ty) { + tc = c ? SWIG_TypeCheck(c,ty) : 0; + if (!tc) { + return SWIG_ERROR; + } + if (flags & SWIG_POINTER_DISOWN) { + SWIG_Disown((void *) *ptr); + } + { + int newmemory = 0; + *ptr = SWIG_TypeCast(tc,(void *) *ptr,&newmemory); + assert(!newmemory); /* newmemory handling not yet implemented */ + } + } + return SWIG_OK; +} + +/* Convert a pointer value */ +SWIGRUNTIMEINLINE int +SWIG_Tcl_ConvertPtr(Tcl_Interp *interp, Tcl_Obj *oc, void **ptr, swig_type_info *ty, int flags) { + return SWIG_Tcl_ConvertPtrFromString(interp, Tcl_GetStringFromObj(oc,NULL), ptr, ty, flags); +} + +/* Convert a pointer value */ +SWIGRUNTIME char * +SWIG_Tcl_PointerTypeFromString(char *c) { + char d; + /* Pointer values must start with leading underscore. NULL has no type */ + if (*c != '_') { + return 0; + } + c++; + /* Extract hex value from pointer */ + while ((d = *c)) { + if (!(((d >= '0') && (d <= '9')) || ((d >= 'a') && (d <= 'f')))) break; + c++; + } + return c; +} + +/* Convert a packed value value */ +SWIGRUNTIME int +SWIG_Tcl_ConvertPacked(Tcl_Interp *SWIGUNUSEDPARM(interp) , Tcl_Obj *obj, void *ptr, int sz, swig_type_info *ty) { + swig_cast_info *tc; + const char *c; + + if (!obj) goto type_error; + c = Tcl_GetStringFromObj(obj,NULL); + /* Pointer values must start with leading underscore */ + if (*c != '_') goto type_error; + c++; + c = SWIG_UnpackData(c,ptr,sz); + if (ty) { + tc = SWIG_TypeCheck(c,ty); + if (!tc) goto type_error; + } + return SWIG_OK; + + type_error: + + return SWIG_ERROR; +} + + +/* Take a pointer and convert it to a string */ +SWIGRUNTIME void +SWIG_Tcl_MakePtr(char *c, void *ptr, swig_type_info *ty, int flags) { + if (ptr) { + *(c++) = '_'; + c = SWIG_PackData(c,&ptr,sizeof(void *)); + strcpy(c,ty->name); + } else { + strcpy(c,(char *)"NULL"); + } + flags = 0; +} + +/* Create a new pointer object */ +SWIGRUNTIMEINLINE Tcl_Obj * +SWIG_Tcl_NewPointerObj(void *ptr, swig_type_info *type, int flags) { + Tcl_Obj *robj; + char result[SWIG_BUFFER_SIZE]; + SWIG_MakePtr(result,ptr,type,flags); + robj = Tcl_NewStringObj(result,-1); + return robj; +} + +SWIGRUNTIME Tcl_Obj * +SWIG_Tcl_NewPackedObj(void *ptr, int sz, swig_type_info *type) { + char result[1024]; + char *r = result; + if ((2*sz + 1 + strlen(type->name)) > 1000) return 0; + *(r++) = '_'; + r = SWIG_PackData(r,ptr,sz); + strcpy(r,type->name); + return Tcl_NewStringObj(result,-1); +} + +/* -----------------------------------------------------------------------------* + * Get type list + * -----------------------------------------------------------------------------*/ + +SWIGRUNTIME swig_module_info * +SWIG_Tcl_GetModule(Tcl_Interp *interp) { + const char *data; + swig_module_info *ret = 0; + + /* first check if pointer already created */ + data = Tcl_GetVar(interp, (char *)"swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, TCL_GLOBAL_ONLY); + if (data) { + SWIG_UnpackData(data, &ret, sizeof(swig_type_info **)); + } + + return ret; +} + +SWIGRUNTIME void +SWIG_Tcl_SetModule(Tcl_Interp *interp, swig_module_info *module) { + char buf[SWIG_BUFFER_SIZE]; + char *data; + + /* create a new pointer */ + data = SWIG_PackData(buf, &module, sizeof(swig_type_info **)); + *data = 0; + Tcl_SetVar(interp, (char *)"swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, buf, 0); +} + +/* -----------------------------------------------------------------------------* + * Object auxiliars + * -----------------------------------------------------------------------------*/ + + +SWIGRUNTIME void +SWIG_Tcl_ObjectDelete(ClientData clientData) { + swig_instance *si = (swig_instance *) clientData; + if ((si) && (si->destroy) && (SWIG_Disown(si->thisvalue))) { + if (si->classptr->destructor) { + (si->classptr->destructor)(si->thisvalue); + } + } + Tcl_DecrRefCount(si->thisptr); + free(si); +} + +/* Function to invoke object methods given an instance */ +SWIGRUNTIME int +SWIG_Tcl_MethodCommand(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST _objv[]) { + char *method, *attrname; + swig_instance *inst = (swig_instance *) clientData; + swig_method *meth; + swig_attribute *attr; + Tcl_Obj *oldarg; + Tcl_Obj **objv; + int rcode; + swig_class *cls; + swig_class *cls_stack[64]; + int cls_stack_bi[64]; + int cls_stack_top = 0; + int numconf = 2; + int bi; + + objv = (Tcl_Obj **) _objv; + if (objc < 2) { + Tcl_SetResult(interp, (char *) "wrong # args.", TCL_STATIC); + return TCL_ERROR; + } + method = Tcl_GetStringFromObj(objv[1],NULL); + if (strcmp(method,"-acquire") == 0) { + inst->destroy = 1; + SWIG_Acquire(inst->thisvalue); + return TCL_OK; + } + if (strcmp(method,"-disown") == 0) { + if (inst->destroy) { + SWIG_Disown(inst->thisvalue); + } + inst->destroy = 0; + return TCL_OK; + } + if (strcmp(method,"-delete") == 0) { + Tcl_DeleteCommandFromToken(interp,inst->cmdtok); + return TCL_OK; + } + cls_stack[cls_stack_top] = inst->classptr; + cls_stack_bi[cls_stack_top] = -1; + cls = inst->classptr; + while (1) { + bi = cls_stack_bi[cls_stack_top]; + cls = cls_stack[cls_stack_top]; + if (bi != -1) { + if (!cls->bases[bi] && cls->base_names[bi]) { + /* lookup and cache the base class */ + swig_type_info *info = SWIG_TypeQueryModule(cls->module, cls->module, cls->base_names[bi]); + if (info) cls->bases[bi] = (swig_class *) info->clientdata; + } + cls = cls->bases[bi]; + if (cls) { + cls_stack_bi[cls_stack_top]++; + cls_stack_top++; + cls_stack[cls_stack_top] = cls; + cls_stack_bi[cls_stack_top] = -1; + continue; + } + } + if (!cls) { + cls_stack_top--; + if (cls_stack_top < 0) break; + else continue; + } + cls_stack_bi[cls_stack_top]++; + + meth = cls->methods; + /* Check for methods */ + while (meth && meth->name) { + if (strcmp(meth->name,method) == 0) { + oldarg = objv[1]; + objv[1] = inst->thisptr; + Tcl_IncrRefCount(inst->thisptr); + rcode = (*meth->method)(clientData,interp,objc,objv); + objv[1] = oldarg; + Tcl_DecrRefCount(inst->thisptr); + return rcode; + } + meth++; + } + /* Check class methods for a match */ + if (strcmp(method,"cget") == 0) { + if (objc < 3) { + Tcl_SetResult(interp, (char *) "wrong # args.", TCL_STATIC); + return TCL_ERROR; + } + attrname = Tcl_GetStringFromObj(objv[2],NULL); + attr = cls->attributes; + while (attr && attr->name) { + if ((strcmp(attr->name, attrname) == 0) && (attr->getmethod)) { + oldarg = objv[1]; + objv[1] = inst->thisptr; + Tcl_IncrRefCount(inst->thisptr); + rcode = (*attr->getmethod)(clientData,interp,2, objv); + objv[1] = oldarg; + Tcl_DecrRefCount(inst->thisptr); + return rcode; + } + attr++; + } + if (strcmp(attrname, "-this") == 0) { + Tcl_SetObjResult(interp, Tcl_DuplicateObj(inst->thisptr)); + return TCL_OK; + } + if (strcmp(attrname, "-thisown") == 0) { + if (SWIG_Thisown(inst->thisvalue)) { + Tcl_SetResult(interp,(char*)"1",TCL_STATIC); + } else { + Tcl_SetResult(interp,(char*)"0",TCL_STATIC); + } + return TCL_OK; + } + } else if (strcmp(method, "configure") == 0) { + int i; + if (objc < 4) { + Tcl_SetResult(interp, (char *) "wrong # args.", TCL_STATIC); + return TCL_ERROR; + } + i = 2; + while (i < objc) { + attrname = Tcl_GetStringFromObj(objv[i],NULL); + attr = cls->attributes; + while (attr && attr->name) { + if ((strcmp(attr->name, attrname) == 0) && (attr->setmethod)) { + oldarg = objv[i]; + objv[i] = inst->thisptr; + Tcl_IncrRefCount(inst->thisptr); + rcode = (*attr->setmethod)(clientData,interp,3, &objv[i-1]); + objv[i] = oldarg; + Tcl_DecrRefCount(inst->thisptr); + if (rcode != TCL_OK) return rcode; + numconf += 2; + } + attr++; + } + i+=2; + } + } + } + if (strcmp(method,"configure") == 0) { + if (numconf >= objc) { + return TCL_OK; + } else { + Tcl_SetResult(interp,(char *) "Invalid attribute name.", TCL_STATIC); + return TCL_ERROR; + } + } + if (strcmp(method,"cget") == 0) { + Tcl_SetResult(interp,(char *) "Invalid attribute name.", TCL_STATIC); + return TCL_ERROR; + } + Tcl_SetResult(interp, (char *) "Invalid method. Must be one of: configure cget -acquire -disown -delete", TCL_STATIC); + cls = inst->classptr; + bi = 0; + while (cls) { + meth = cls->methods; + while (meth && meth->name) { + char *cr = (char *) Tcl_GetStringResult(interp); + size_t meth_len = strlen(meth->name); + char* where = strchr(cr,':'); + while(where) { + where = strstr(where, meth->name); + if(where) { + if(where[-1] == ' ' && (where[meth_len] == ' ' || where[meth_len]==0)) { + break; + } else { + where++; + } + } + } + + if (!where) + Tcl_AppendElement(interp, (char *) meth->name); + meth++; + } + cls = inst->classptr->bases[bi++]; + } + return TCL_ERROR; +} + +/* This function takes the current result and turns it into an object command */ +SWIGRUNTIME Tcl_Obj * +SWIG_Tcl_NewInstanceObj(Tcl_Interp *interp, void *thisvalue, swig_type_info *type, int flags) { + Tcl_Obj *robj = SWIG_NewPointerObj(thisvalue, type,0); + /* Check to see if this pointer belongs to a class or not */ + if ((type->clientdata) && (interp)) { + Tcl_CmdInfo ci; + char *name; + name = Tcl_GetStringFromObj(robj,NULL); + if (!Tcl_GetCommandInfo(interp,name, &ci) || (flags)) { + swig_instance *newinst = (swig_instance *) malloc(sizeof(swig_instance)); + newinst->thisptr = Tcl_DuplicateObj(robj); + Tcl_IncrRefCount(newinst->thisptr); + newinst->thisvalue = thisvalue; + newinst->classptr = (swig_class *) type->clientdata; + newinst->destroy = flags; + newinst->cmdtok = Tcl_CreateObjCommand(interp, Tcl_GetStringFromObj(robj,NULL), (swig_wrapper_func) SWIG_MethodCommand, (ClientData) newinst, (swig_delete_func) SWIG_ObjectDelete); + if (flags) { + SWIG_Acquire(thisvalue); + } + } + } + return robj; +} + +/* Function to create objects */ +SWIGRUNTIME int +SWIG_Tcl_ObjectConstructor(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { + Tcl_Obj *newObj = 0; + void *thisvalue = 0; + swig_instance *newinst = 0; + swig_class *classptr = (swig_class *) clientData; + swig_wrapper cons = 0; + char *name = 0; + int firstarg = 0; + int thisarg = 0; + int destroy = 1; + + if (!classptr) { + Tcl_SetResult(interp, (char *) "swig: internal runtime error. No class object defined.", TCL_STATIC); + return TCL_ERROR; + } + cons = classptr->constructor; + if (objc > 1) { + char *s = Tcl_GetStringFromObj(objv[1],NULL); + if (strcmp(s,"-this") == 0) { + thisarg = 2; + cons = 0; + } else if (strcmp(s,"-args") == 0) { + firstarg = 1; + } else if (objc == 2) { + firstarg = 1; + name = s; + } else if (objc >= 3) { + char *s1; + name = s; + s1 = Tcl_GetStringFromObj(objv[2],NULL); + if (strcmp(s1,"-this") == 0) { + thisarg = 3; + cons = 0; + } else { + firstarg = 1; + } + } + } + if (cons) { + int result; + result = (*cons)(0, interp, objc-firstarg, &objv[firstarg]); + if (result != TCL_OK) { + return result; + } + newObj = Tcl_DuplicateObj(Tcl_GetObjResult(interp)); + if (!name) name = Tcl_GetStringFromObj(newObj,NULL); + } else if (thisarg > 0) { + if (thisarg < objc) { + destroy = 0; + newObj = Tcl_DuplicateObj(objv[thisarg]); + if (!name) name = Tcl_GetStringFromObj(newObj,NULL); + } else { + Tcl_SetResult(interp, (char *) "wrong # args.", TCL_STATIC); + return TCL_ERROR; + } + } else { + Tcl_SetResult(interp, (char *) "No constructor available.", TCL_STATIC); + return TCL_ERROR; + } + if (SWIG_Tcl_ConvertPtr(interp,newObj, (void **) &thisvalue, *(classptr->type), 0) != SWIG_OK) { + Tcl_DecrRefCount(newObj); + return TCL_ERROR; + } + newinst = (swig_instance *) malloc(sizeof(swig_instance)); + newinst->thisptr = newObj; + Tcl_IncrRefCount(newObj); + newinst->thisvalue = thisvalue; + newinst->classptr = classptr; + newinst->destroy = destroy; + if (destroy) { + SWIG_Acquire(thisvalue); + } + newinst->cmdtok = Tcl_CreateObjCommand(interp,name, (swig_wrapper) SWIG_MethodCommand, (ClientData) newinst, (swig_delete_func) SWIG_ObjectDelete); + return TCL_OK; +} + +/* -----------------------------------------------------------------------------* + * Get arguments + * -----------------------------------------------------------------------------*/ +SWIGRUNTIME int +SWIG_Tcl_GetArgs(Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], const char *fmt, ...) { + int argno = 0, opt = 0; + long tempi; + double tempd; + const char *c; + va_list ap; + void *vptr; + Tcl_Obj *obj = 0; + swig_type_info *ty; + + va_start(ap,fmt); + for (c = fmt; (*c && (*c != ':') && (*c != ';')); c++,argno++) { + if (*c == '|') { + opt = 1; + c++; + } + if (argno >= (objc-1)) { + if (!opt) { + Tcl_SetResult(interp, (char *) "Wrong number of arguments ", TCL_STATIC); + goto argerror; + } else { + va_end(ap); + return TCL_OK; + } + } + + vptr = va_arg(ap,void *); + if (vptr) { + if (isupper(*c)) { + obj = SWIG_Tcl_GetConstantObj(Tcl_GetStringFromObj(objv[argno+1],0)); + if (!obj) obj = objv[argno+1]; + } else { + obj = objv[argno+1]; + } + switch(*c) { + case 'i': case 'I': + case 'l': case 'L': + case 'h': case 'H': + case 'b': case 'B': + if (Tcl_GetLongFromObj(interp,obj,&tempi) != TCL_OK) goto argerror; + if ((*c == 'i') || (*c == 'I')) *((int *)vptr) = (int)tempi; + else if ((*c == 'l') || (*c == 'L')) *((long *)vptr) = (long)tempi; + else if ((*c == 'h') || (*c == 'H')) *((short*)vptr) = (short)tempi; + else if ((*c == 'b') || (*c == 'B')) *((unsigned char *)vptr) = (unsigned char)tempi; + break; + case 'f': case 'F': + case 'd': case 'D': + if (Tcl_GetDoubleFromObj(interp,obj,&tempd) != TCL_OK) goto argerror; + if ((*c == 'f') || (*c == 'F')) *((float *) vptr) = (float)tempd; + else if ((*c == 'd') || (*c == 'D')) *((double*) vptr) = tempd; + break; + case 's': case 'S': + if (*(c+1) == '#') { + int *vlptr = (int *) va_arg(ap, void *); + *((char **) vptr) = Tcl_GetStringFromObj(obj, vlptr); + c++; + } else { + *((char **)vptr) = Tcl_GetStringFromObj(obj,NULL); + } + break; + case 'c': case 'C': + *((char *)vptr) = *(Tcl_GetStringFromObj(obj,NULL)); + break; + case 'p': case 'P': + ty = (swig_type_info *) va_arg(ap, void *); + if (SWIG_Tcl_ConvertPtr(interp, obj, (void **) vptr, ty, 0) != SWIG_OK) goto argerror; + break; + case 'o': case 'O': + *((Tcl_Obj **)vptr) = objv[argno+1]; + break; + default: + break; + } + } + } + + if ((*c != ';') && ((objc-1) > argno)) { + Tcl_SetResult(interp, (char *) "Wrong # args.", TCL_STATIC); + goto argerror; + } + va_end(ap); + return TCL_OK; + + argerror: + { + char temp[32]; + sprintf(temp,"%d", argno+1); + c = strchr(fmt,':'); + if (!c) c = strchr(fmt,';'); + if (!c) c = (char *)""; + Tcl_AppendResult(interp,c," argument ", temp, NULL); + va_end(ap); + return TCL_ERROR; + } +} + +#ifdef __cplusplus +#if 0 +{ /* cc-mode */ +#endif +} +#endif diff --git a/Lib/tcl/tclruntime.swg b/Lib/tcl/tclruntime.swg new file mode 100644 index 0000000..bb4edd7 --- /dev/null +++ b/Lib/tcl/tclruntime.swg @@ -0,0 +1,15 @@ +/* tcl.h has to appear first */ +%insert(runtime) %{ +#include <stdio.h> +#include <tcl.h> +#include <errno.h> +#include <stdlib.h> +#include <stdarg.h> +#include <ctype.h> +%} + +%insert(runtime) "swigrun.swg"; /* Common C API type-checking code */ +%insert(runtime) "swigerrors.swg" /* SWIG errors */ +%insert(runtime) "tclerrors.swg"; /* Tcl Errors */ +%insert(runtime) "tclapi.swg"; /* Tcl API */ +%insert(runtime) "tclrun.swg"; /* Tcl run-time code */ diff --git a/Lib/tcl/tclsh.i b/Lib/tcl/tclsh.i new file mode 100644 index 0000000..2e8ed33 --- /dev/null +++ b/Lib/tcl/tclsh.i @@ -0,0 +1,88 @@ +/* ----------------------------------------------------------------------------- + * See the LICENSE file for information on copyright, usage and redistribution + * of SWIG, and the README file for authors - http://www.swig.org/release.html. + * + * tclsh.i + * + * SWIG File for building new tclsh program + * ----------------------------------------------------------------------------- */ + +#ifdef AUTODOC +%subsection "tclsh.i" +%text %{ +This module provides the Tcl_AppInit() function needed to build a +new version of the tclsh executable. This file should not be used +when using dynamic loading. To make an interface file work with +both static and dynamic loading, put something like this in your +interface file : + + #ifdef STATIC + %include <tclsh.i> + #endif +%} +#endif + +%{ + +/* A TCL_AppInit() function that lets you build a new copy + * of tclsh. + * + * The macro SWIG_init contains the name of the initialization + * function in the wrapper file. + */ + +#ifndef SWIG_RcFileName +char *SWIG_RcFileName = "~/.myapprc"; +#endif + + +#ifdef MAC_TCL +extern int MacintoshInit _ANSI_ARGS_((void)); +#endif + +int Tcl_AppInit(Tcl_Interp *interp){ + + if (Tcl_Init(interp) == TCL_ERROR) + return TCL_ERROR; + + /* Now initialize our functions */ + + if (SWIG_init(interp) == TCL_ERROR) + return TCL_ERROR; +#if TCL_MAJOR_VERSION > 7 || TCL_MAJOR_VERSION == 7 && TCL_MINOR_VERSION >= 5 + Tcl_SetVar(interp, (char *) "tcl_rcFileName",SWIG_RcFileName,TCL_GLOBAL_ONLY); +#else + tcl_RcFileName = SWIG_RcFileName; +#endif +#ifdef SWIG_RcRsrcName + Tcl_SetVar(interp, (char *) "tcl_rcRsrcName",SWIG_RcRsrcName,TCL_GLOBAL); +#endif + + return TCL_OK; +} + +#if TCL_MAJOR_VERSION > 7 || TCL_MAJOR_VERSION == 7 && TCL_MINOR_VERSION >= 4 +int main(int argc, char **argv) { +#ifdef MAC_TCL + char *newArgv[2]; + + if (MacintoshInit() != TCL_OK) { + Tcl_Exit(1); + } + + argc = 1; + newArgv[0] = "tclsh"; + newArgv[1] = NULL; + argv = newArgv; +#endif + + Tcl_Main(argc, argv, Tcl_AppInit); + return(0); + +} +#else +extern int main(); +#endif + +%} + diff --git a/Lib/tcl/tclstrings.swg b/Lib/tcl/tclstrings.swg new file mode 100644 index 0000000..540d627 --- /dev/null +++ b/Lib/tcl/tclstrings.swg @@ -0,0 +1,31 @@ +/* ------------------------------------------------------------ + * utility methods for char strings + * ------------------------------------------------------------ */ + +%fragment("SWIG_AsCharPtrAndSize","header") { +SWIGINTERN int +SWIG_AsCharPtrAndSize(Tcl_Obj *obj, char** cptr, size_t* psize, int *alloc) +{ + int len = 0; + char *cstr = Tcl_GetStringFromObj(obj, &len); + if (cstr) { + if (cptr) *cptr = cstr; + if (psize) *psize = len + 1; + if (alloc) *alloc = SWIG_OLDOBJ; + return SWIG_OK; + } + return SWIG_TypeError; +} +} + + +%fragment("SWIG_FromCharPtrAndSize","header", + fragment="<limits.h>") { +SWIGINTERNINLINE Tcl_Obj * +SWIG_FromCharPtrAndSize(const char* carray, size_t size) +{ + return (size < INT_MAX) ? Tcl_NewStringObj(carray, %numeric_cast(size,int)) : NULL; +} +} + + diff --git a/Lib/tcl/tcltypemaps.swg b/Lib/tcl/tcltypemaps.swg new file mode 100644 index 0000000..7199e67 --- /dev/null +++ b/Lib/tcl/tcltypemaps.swg @@ -0,0 +1,89 @@ +/* ------------------------------------------------------------ + * Typemap specializations for Tcl + * ------------------------------------------------------------ */ + +/* ------------------------------------------------------------ + * Fragment section + * ------------------------------------------------------------ */ + +/* + in Tcl we need to pass the interp value, so, we define the decl/call + macros as needed. +*/ + +#define SWIG_AS_DECL_ARGS SWIG_TCL_DECL_ARGS_2 +#define SWIG_AS_CALL_ARGS SWIG_TCL_CALL_ARGS_2 + + +/* Include fundamental fragemt definitions */ +%include <typemaps/fragments.swg> + +/* Look for user fragments file. */ +%include <tclfragments.swg> + +/* Tcl fragments for primitve types */ +%include <tclprimtypes.swg> + +/* Tcl fragments for char* strings */ +%include <tclstrings.swg> + + +/* ------------------------------------------------------------ + * Unified typemap section + * ------------------------------------------------------------ */ + +/* No director supported in Tcl */ +#ifdef SWIG_DIRECTOR_TYPEMAPS +#undef SWIG_DIRECTOR_TYPEMAPS +#endif + + +/* Tcl types */ +#define SWIG_Object Tcl_Obj * + +/* Overload of the output/constant/exception handling */ + +/* output */ +#define %set_output(obj) Tcl_SetObjResult(interp,obj) + +/* append output */ +#define %append_output(obj) Tcl_ListObjAppendElement(interp,Tcl_GetObjResult(interp),obj) + +/* set constant */ +#define SWIG_SetConstant(name, obj) SWIG_Tcl_SetConstantObj(interp, name, obj) + +/* raise */ +#define SWIG_Raise(obj,type,desc) SWIG_Tcl_SetErrorObj(interp,type,obj) + + +/* Include the unified typemap library */ +%include <typemaps/swigtypemaps.swg> + + +/* ------------------------------------------------------------ + * Tcl extra typemaps + * ------------------------------------------------------------ */ + +#if 1 +// Old 1.3.25 typemaps needed to avoid premature object deletion +%typemap(out,noblock=1) SWIGTYPE *INSTANCE, SWIGTYPE &INSTANCE, SWIGTYPE INSTANCE[] { + Tcl_SetObjResult(interp, SWIG_NewInstanceObj( %as_voidptr($1), $1_descriptor,0)); +} + +%typemap(out) SWIGTYPE *DYNAMIC, SWIGTYPE &DYNAMIC { + swig_type_info *ty = SWIG_TypeDynamicCast($1_descriptor,%as_voidptrptr(&$1)); + Tcl_SetObjResult(interp,SWIG_NewInstanceObj(%as_voidptr($1), ty,0)); +} + +#endif + +%typemap(throws,noblock=1) SWIGTYPE CLASS { + SWIG_set_result(SWIG_NewInstanceObj(%as_voidptr(SWIG_new_copy($1, $1_ltype)), $&1_descriptor, 1)); + SWIG_fail; +} + +%typemap(out) SWIGTYPE = SWIGTYPE INSTANCE; +%typemap(out) SWIGTYPE * = SWIGTYPE *INSTANCE; +%typemap(out) SWIGTYPE & = SWIGTYPE &INSTANCE; +%typemap(out) SWIGTYPE [] = SWIGTYPE INSTANCE[]; +%typemap(varout) SWIGTYPE = SWIGTYPE INSTANCE; diff --git a/Lib/tcl/tcluserdir.swg b/Lib/tcl/tcluserdir.swg new file mode 100644 index 0000000..d5b41fb --- /dev/null +++ b/Lib/tcl/tcluserdir.swg @@ -0,0 +1,5 @@ +/* ----------------------------------------------------------------------------- + * Special user directives + * ----------------------------------------------------------------------------- */ + + diff --git a/Lib/tcl/tclwstrings.swg b/Lib/tcl/tclwstrings.swg new file mode 100644 index 0000000..2d344c2 --- /dev/null +++ b/Lib/tcl/tclwstrings.swg @@ -0,0 +1,70 @@ +/* ----------------------------------------------------------------------------- + * See the LICENSE file for information on copyright, usage and redistribution + * of SWIG, and the README file for authors - http://www.swig.org/release.html. + * + * tclwstrings.wg + * + * Utility methods for wchar strings + * ----------------------------------------------------------------------------- */ + +%{ +#include <wchar.h> +%} + +%fragment("SWIG_AsWCharPtrAndSize","header") { +SWIGINTERN int +SWIG_AsWCharPtrAndSize(Tcl_Obj *obj, wchar_t** cptr, size_t* psize, int *alloc) +{ + int len = 0; + Tcl_UniChar *ustr = Tcl_GetUnicodeFromObj(obj, &len); + if (ustr) { + if (cptr) { + Tcl_Encoding encoding = NULL; + char *src = (char *) ustr; + int srcLen = (len)*sizeof(Tcl_UniChar); + int dstLen = sizeof(wchar_t)*(len + 1); + char *dst = %new_array(dstLen, char); + int flags = 0; + Tcl_EncodingState *statePtr = 0; + int srcRead = 0; + int dstWrote = 0; + int dstChars = 0; + Tcl_UtfToExternal(0, encoding, src, srcLen, flags, statePtr, dst, + dstLen, &srcRead, &dstWrote, &dstChars); + + if (alloc) *alloc = SWIG_NEWOBJ; + } + if (psize) *psize = len + 1; + return SWIG_OK; + } + return SWIG_TypeError; +} +} + +%fragment("SWIG_FromWCharPtrAndSize","header") { +SWIGINTERNINLINE Tcl_Obj * +SWIG_FromWCharPtrAndSize(const wchar_t* carray, size_t size) +{ + Tcl_Obj *res = NULL; + if (size < INT_MAX) { + Tcl_Encoding encoding = NULL; + char *src = (char *) carray; + int srcLen = (int)(size*sizeof(wchar_t)); + int dstLen = (int)(size*sizeof(Tcl_UniChar)); + char *dst = %new_array(dstLen, char); + int flags = 0; + Tcl_EncodingState *statePtr = 0; + int srcRead = 0; + int dstWrote = 0; + int dstChars = 0; + + Tcl_ExternalToUtf(0, encoding, src, srcLen, flags, statePtr, dst, + dstLen, &srcRead, &dstWrote, &dstChars); + + res = Tcl_NewUnicodeObj((Tcl_UniChar*)dst, (int)size); + %delete_array(dst); + } + return res; +} +} + diff --git a/Lib/tcl/typemaps.i b/Lib/tcl/typemaps.i new file mode 100644 index 0000000..7c9e04a --- /dev/null +++ b/Lib/tcl/typemaps.i @@ -0,0 +1,467 @@ +/* ----------------------------------------------------------------------------- + * See the LICENSE file for information on copyright, usage and redistribution + * of SWIG, and the README file for authors - http://www.swig.org/release.html. + * + * typemaps.i + * + * Swig typemap library for Tcl8. This file contains various sorts + * of typemaps for modifying Swig's code generation. + * ----------------------------------------------------------------------------- */ + +#if !defined(SWIG_USE_OLD_TYPEMAPS) +%include <typemaps/typemaps.swg> +#else + +/* +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. +*/ + +// INPUT typemaps. +// These remap a C pointer to be an "INPUT" value which is passed by value +// instead of reference. + +/* +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 + long long *INPUT + unsigned int *INPUT + unsigned short *INPUT + unsigned long *INPUT + unsigned long long *INPUT + unsigned char *INPUT + bool *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); + +*/ + +%typemap(in) double *INPUT(double temp), double &INPUT(double temp) +{ + if (Tcl_GetDoubleFromObj(interp,$input,&temp) == TCL_ERROR) { + SWIG_fail; + } + $1 = &temp; +} + +%typemap(in) float *INPUT(double dvalue, float temp), float &INPUT(double dvalue, float temp) +{ + if (Tcl_GetDoubleFromObj(interp,$input,&dvalue) == TCL_ERROR) { + SWIG_fail; + } + temp = (float) dvalue; + $1 = &temp; +} + +%typemap(in) int *INPUT(int temp), int &INPUT(int temp) +{ + if (Tcl_GetIntFromObj(interp,$input,&temp) == TCL_ERROR) { + SWIG_fail; + } + $1 = &temp; +} + +%typemap(in) short *INPUT(int ivalue, short temp), short &INPUT(int ivalue, short temp) +{ + if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) { + SWIG_fail; + } + temp = (short) ivalue; + $1 = &temp; +} + +%typemap(in) long *INPUT(int ivalue, long temp), long &INPUT(int ivalue, long temp) +{ + if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) { + SWIG_fail; + } + temp = (long) ivalue; + $1 = &temp; +} + +%typemap(in) unsigned int *INPUT(int ivalue, unsigned int temp), + unsigned int &INPUT(int ivalue, unsigned int temp) +{ + if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) { + SWIG_fail; + } + temp = (unsigned int) ivalue; + $1 = &temp; +} + +%typemap(in) unsigned short *INPUT(int ivalue, unsigned short temp), + unsigned short &INPUT(int ivalue, unsigned short temp) +{ + if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) { + SWIG_fail; + } + temp = (unsigned short) ivalue; + $1 = &temp; +} + +%typemap(in) unsigned long *INPUT(int ivalue, unsigned long temp), + unsigned long &INPUT(int ivalue, unsigned long temp) +{ + if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) { + SWIG_fail; + } + temp = (unsigned long) ivalue; + $1 = &temp; +} + +%typemap(in) unsigned char *INPUT(int ivalue, unsigned char temp), + unsigned char &INPUT(int ivalue, unsigned char temp) +{ + if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) { + SWIG_fail; + } + temp = (unsigned char) ivalue; + $1 = &temp; +} + +%typemap(in) signed char *INPUT(int ivalue, signed char temp), + signed char &INPUT(int ivalue, signed char temp) +{ + if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) { + SWIG_fail; + } + temp = (signed char) ivalue; + $1 = &temp; +} + +%typemap(in) bool *INPUT(int ivalue, bool temp), + bool &INPUT(int ivalue, bool temp) +{ + if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) { + SWIG_fail; + } + temp = ivalue ? true : false; + $1 = &temp; +} + +%typemap(in) long long *INPUT($*1_ltype temp), + long long &INPUT($*1_ltype temp) +{ + temp = ($*1_ltype) strtoll(Tcl_GetStringFromObj($input,NULL),0,0); + $1 = &temp; +} + +%typemap(in) unsigned long long *INPUT($*1_ltype temp), + unsigned long long &INPUT($*1_ltype temp) +{ + temp = ($*1_ltype) strtoull(Tcl_GetStringFromObj($input,NULL),0,0); + $1 = &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. + +/* +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, they are returned in the form of a Tcl list. + + int *OUTPUT + short *OUTPUT + long *OUTPUT + long long *OUTPUT + unsigned int *OUTPUT + unsigned short *OUTPUT + unsigned long *OUTPUT + unsigned long long *OUTPUT + unsigned char *OUTPUT + bool *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 Tcl output of the function would be a list containing both +output values. + +*/ + +%typemap(in,numinputs=0) 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), + signed char *OUTPUT(signed char temp), + bool *OUTPUT(bool temp), + float *OUTPUT(float temp), + double *OUTPUT(double temp), + long long *OUTPUT($*1_ltype temp), + unsigned long long *OUTPUT($*1_ltype temp), + 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), + signed char &OUTPUT(signed char temp), + bool &OUTPUT(bool temp), + unsigned char &OUTPUT(unsigned char temp), + float &OUTPUT(float temp), + double &OUTPUT(double temp), + long long &OUTPUT($*1_ltype temp), + unsigned long long &OUTPUT($*1_ltype temp) +"$1 = &temp;"; + +%typemap(argout) int *OUTPUT, int &OUTPUT, + short *OUTPUT, short &OUTPUT, + long *OUTPUT, long &OUTPUT, + unsigned int *OUTPUT, unsigned int &OUTPUT, + unsigned short *OUTPUT, unsigned short &OUTPUT, + unsigned long *OUTPUT, unsigned long &OUTPUT, + unsigned char *OUTPUT, unsigned char &OUTPUT, + signed char *OUTPUT, signed char &OUTPUT, + bool *OUTPUT, bool &OUTPUT +{ + Tcl_Obj *o; + o = Tcl_NewIntObj((int) *($1)); + Tcl_ListObjAppendElement(interp,Tcl_GetObjResult(interp),o); +} + +%typemap(argout) float *OUTPUT, float &OUTPUT, + double *OUTPUT, double &OUTPUT +{ + Tcl_Obj *o; + o = Tcl_NewDoubleObj((double) *($1)); + Tcl_ListObjAppendElement(interp,Tcl_GetObjResult(interp),o); +} + +%typemap(argout) long long *OUTPUT, long long &OUTPUT +{ + char temp[256]; + Tcl_Obj *o; + sprintf(temp,"%lld",(long long)*($1)); + o = Tcl_NewStringObj(temp,-1); + Tcl_ListObjAppendElement(interp,Tcl_GetObjResult(interp),o); +} + +%typemap(argout) unsigned long long *OUTPUT, unsigned long long &OUTPUT +{ + char temp[256]; + Tcl_Obj *o; + sprintf(temp,"%llu",(unsigned long long)*($1)); + o = Tcl_NewStringObj(temp,-1); + Tcl_ListObjAppendElement(interp,Tcl_GetObjResult(interp),o); +} + +// INOUT +// Mappings for an argument that is both an input and output +// parameter + +/* +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 *INOUT + short *INOUT + long *INOUT + long long *INOUT + unsigned int *INOUT + unsigned short *INOUT + unsigned long *INOUT + unsigned long long *INOUT + unsigned char *INOUT + bool *INOUT + float *INOUT + double *INOUT + +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 *INOUT); + +or you can use the %apply directive : + + %include typemaps.i + %apply double *INOUT { double *x }; + void neg(double *x); + +Unlike C, this mapping does not directly modify the input value (since +this makes no sense in Tcl). Rather, the modified input value shows +up as the return value of the function. Thus, to apply this function +to a Tcl variable you might do this : + + set x [neg $x] + +*/ + + +%typemap(in) int *INOUT = int *INPUT; +%typemap(in) short *INOUT = short *INPUT; +%typemap(in) long *INOUT = long *INPUT; +%typemap(in) unsigned int *INOUT = unsigned int *INPUT; +%typemap(in) unsigned short *INOUT = unsigned short *INPUT; +%typemap(in) unsigned long *INOUT = unsigned long *INPUT; +%typemap(in) unsigned char *INOUT = unsigned char *INPUT; +%typemap(in) signed char *INOUT = signed char *INPUT; +%typemap(in) bool *INOUT = bool *INPUT; +%typemap(in) float *INOUT = float *INPUT; +%typemap(in) double *INOUT = double *INPUT; +%typemap(in) long long *INOUT = long long *INPUT; +%typemap(in) unsigned long long *INOUT = unsigned long long *INPUT; + +%typemap(in) int &INOUT = int &INPUT; +%typemap(in) short &INOUT = short &INPUT; +%typemap(in) long &INOUT = long &INPUT; +%typemap(in) unsigned int &INOUT = unsigned int &INPUT; +%typemap(in) unsigned short &INOUT = unsigned short &INPUT; +%typemap(in) unsigned long &INOUT = unsigned long &INPUT; +%typemap(in) unsigned char &INOUT = unsigned char &INPUT; +%typemap(in) signed char &INOUT = signed char &INPUT; +%typemap(in) bool &INOUT = bool &INPUT; +%typemap(in) float &INOUT = float &INPUT; +%typemap(in) double &INOUT = double &INPUT; +%typemap(in) long long &INOUT = long long &INPUT; +%typemap(in) unsigned long long &INOUT = unsigned long long &INPUT; + +%typemap(argout) int *INOUT = int *OUTPUT; +%typemap(argout) short *INOUT = short *OUTPUT; +%typemap(argout) long *INOUT = long *OUTPUT; +%typemap(argout) unsigned int *INOUT = unsigned int *OUTPUT; +%typemap(argout) unsigned short *INOUT = unsigned short *OUTPUT; +%typemap(argout) unsigned long *INOUT = unsigned long *OUTPUT; +%typemap(argout) unsigned char *INOUT = unsigned char *OUTPUT; +%typemap(argout) signed char *INOUT = signed char *OUTPUT; +%typemap(argout) bool *INOUT = bool *OUTPUT; +%typemap(argout) float *INOUT = float *OUTPUT; +%typemap(argout) double *INOUT = double *OUTPUT; +%typemap(argout) long long *INOUT = long long *OUTPUT; +%typemap(argout) unsigned long long *INOUT = unsigned long long *OUTPUT; + +%typemap(argout) int &INOUT = int &OUTPUT; +%typemap(argout) short &INOUT = short &OUTPUT; +%typemap(argout) long &INOUT = long &OUTPUT; +%typemap(argout) unsigned int &INOUT = unsigned int &OUTPUT; +%typemap(argout) unsigned short &INOUT = unsigned short &OUTPUT; +%typemap(argout) unsigned long &INOUT = unsigned long &OUTPUT; +%typemap(argout) unsigned char &INOUT = unsigned char &OUTPUT; +%typemap(argout) signed char &INOUT = signed char &OUTPUT; +%typemap(argout) bool &INOUT = bool &OUTPUT; +%typemap(argout) float &INOUT = float &OUTPUT; +%typemap(argout) double &INOUT = double &OUTPUT; +%typemap(argout) long long &INOUT = long long &OUTPUT; +%typemap(argout) unsigned long long &INOUT = unsigned long long &OUTPUT; + + +/* Overloading information */ + +%typemap(typecheck) double *INPUT = double; +%typemap(typecheck) bool *INPUT = bool; +%typemap(typecheck) signed char *INPUT = signed char; +%typemap(typecheck) unsigned char *INPUT = unsigned char; +%typemap(typecheck) unsigned long *INPUT = unsigned long; +%typemap(typecheck) unsigned short *INPUT = unsigned short; +%typemap(typecheck) unsigned int *INPUT = unsigned int; +%typemap(typecheck) long *INPUT = long; +%typemap(typecheck) short *INPUT = short; +%typemap(typecheck) int *INPUT = int; +%typemap(typecheck) float *INPUT = float; +%typemap(typecheck) long long *INPUT = long long; +%typemap(typecheck) unsigned long long *INPUT = unsigned long long; + +%typemap(typecheck) double &INPUT = double; +%typemap(typecheck) bool &INPUT = bool; +%typemap(typecheck) signed char &INPUT = signed char; +%typemap(typecheck) unsigned char &INPUT = unsigned char; +%typemap(typecheck) unsigned long &INPUT = unsigned long; +%typemap(typecheck) unsigned short &INPUT = unsigned short; +%typemap(typecheck) unsigned int &INPUT = unsigned int; +%typemap(typecheck) long &INPUT = long; +%typemap(typecheck) short &INPUT = short; +%typemap(typecheck) int &INPUT = int; +%typemap(typecheck) float &INPUT = float; +%typemap(typecheck) long long &INPUT = long long; +%typemap(typecheck) unsigned long long &INPUT = unsigned long long; + +%typemap(typecheck) double *INOUT = double; +%typemap(typecheck) bool *INOUT = bool; +%typemap(typecheck) signed char *INOUT = signed char; +%typemap(typecheck) unsigned char *INOUT = unsigned char; +%typemap(typecheck) unsigned long *INOUT = unsigned long; +%typemap(typecheck) unsigned short *INOUT = unsigned short; +%typemap(typecheck) unsigned int *INOUT = unsigned int; +%typemap(typecheck) long *INOUT = long; +%typemap(typecheck) short *INOUT = short; +%typemap(typecheck) int *INOUT = int; +%typemap(typecheck) float *INOUT = float; +%typemap(typecheck) long long *INOUT = long long; +%typemap(typecheck) unsigned long long *INOUT = unsigned long long; + +%typemap(typecheck) double &INOUT = double; +%typemap(typecheck) bool &INOUT = bool; +%typemap(typecheck) signed char &INOUT = signed char; +%typemap(typecheck) unsigned char &INOUT = unsigned char; +%typemap(typecheck) unsigned long &INOUT = unsigned long; +%typemap(typecheck) unsigned short &INOUT = unsigned short; +%typemap(typecheck) unsigned int &INOUT = unsigned int; +%typemap(typecheck) long &INOUT = long; +%typemap(typecheck) short &INOUT = short; +%typemap(typecheck) int &INOUT = int; +%typemap(typecheck) float &INOUT = float; +%typemap(typecheck) long long &INOUT = long long; +%typemap(typecheck) unsigned long long &INOUT = unsigned long long; + +#endif + +// -------------------------------------------------------------------- +// Special types +// -------------------------------------------------------------------- + +%include <tclinterp.i> +%include <tclresult.i> diff --git a/Lib/tcl/wish.i b/Lib/tcl/wish.i new file mode 100644 index 0000000..077ded6 --- /dev/null +++ b/Lib/tcl/wish.i @@ -0,0 +1,149 @@ +/* ----------------------------------------------------------------------------- + * See the LICENSE file for information on copyright, usage and redistribution + * of SWIG, and the README file for authors - http://www.swig.org/release.html. + * + * wish.i + * + * SWIG File for making wish + * ----------------------------------------------------------------------------- */ + +#ifdef AUTODOC +%subsection "wish.i" +%text %{ +This module provides the Tk_AppInit() function needed to build a +new version of the wish executable. Like tclsh.i, this file should +not be used with dynamic loading. To make an interface file work with +both static and dynamic loading, put something like this in your +interface file : + + #ifdef STATIC + %include <wish.i> + #endif + +A startup file may be specified by defining the symbol SWIG_RcFileName +as follows (this should be included in a code-block) : + + #define SWIG_RcFileName "~/.mywishrc" +%} +#endif + +%{ + + +/* Initialization code for wish */ + +#include <tk.h> + +#ifndef SWIG_RcFileName +char *SWIG_RcFileName = "~/.wishrc"; +#endif + +#ifdef MAC_TCL +extern int MacintoshInit _ANSI_ARGS_((void)); +extern int SetupMainInterp _ANSI_ARGS_((Tcl_Interp *interp)); +#endif + +/* + *---------------------------------------------------------------------- + * + * Tcl_AppInit -- + * + * This procedure performs application-specific initialization. + * Most applications, especially those that incorporate additional + * packages, will have their own version of this procedure. + * + * Results: + * Returns a standard Tcl completion code, and leaves an error + * message in interp->result if an error occurs. + * + * Side effects: + * Depends on the startup script. + * + *---------------------------------------------------------------------- + */ + +int Tcl_AppInit(Tcl_Interp *interp) +{ +#ifndef MAC_TCL + Tk_Window main; + main = Tk_MainWindow(interp); +#endif + /* + * Call the init procedures for included packages. Each call should + * look like this: + * + * if (Mod_Init(interp) == TCL_ERROR) { + * return TCL_ERROR; + * } + * + * where "Mod" is the name of the module. + */ + + if (Tcl_Init(interp) == TCL_ERROR) { + return TCL_ERROR; + } + + if (Tk_Init(interp) == TCL_ERROR) { + return TCL_ERROR; + } + + /* + * Call Tcl_CreateCommand for application-specific commands, if + * they weren't already created by the init procedures called above. + */ + + if (SWIG_init(interp) == TCL_ERROR) { + return TCL_ERROR; + } + +#ifdef MAC_TCL + SetupMainInterp(interp); +#endif + + /* + * Specify a user-specific startup file to invoke if the application + * is run interactively. Typically the startup file is "~/.apprc" + * where "app" is the name of the application. If this line is deleted + * then no user-specific startup file will be run under any conditions. + */ + +#if TCL_MAJOR_VERSION >= 8 || TCL_MAJOR_VERSION == 7 && TCL_MINOR_VERSION >= 5 + Tcl_SetVar(interp, (char *) "tcl_rcFileName",SWIG_RcFileName,TCL_GLOBAL_ONLY); +#else + tcl_RcFileName = SWIG_RcFileName; +#endif + +/* For Macintosh might also want this */ + +#ifdef MAC_TCL +#ifdef SWIG_RcRsrcName + Tcl_SetVar(interp, (char *) "tcl_rcRsrcName",SWIG_RcRsrcName,TCL_GLOBAL_ONLY); +#endif +#endif + return TCL_OK; +} + +#if TK_MAJOR_VERSION >= 4 +int main(int argc, char **argv) { + +#ifdef MAC_TCL + char *newArgv[2]; + if (MacintoshInit() != TCL_OK) { + Tcl_Exit(1); + } + argc = 1; + newArgv[0] = "Wish"; + newArgv[1] = NULL; + argv = newArgv; +#endif + Tk_Main(argc, argv, Tcl_AppInit); + return(0); +} +#else +extern int main(); +#endif + +%} + + + |