From 8b65741620bae448b96eb8ce59b85a7b1bb36c44 Mon Sep 17 00:00:00 2001 From: mescalinum Date: Sat, 29 Aug 2009 17:07:13 +0000 Subject: tidy up! svn path=/trunk/externals/tclpd/; revision=12133 --- tcl_setup.cxx | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tcl_setup.cxx (limited to 'tcl_setup.cxx') diff --git a/tcl_setup.cxx b/tcl_setup.cxx new file mode 100644 index 0000000..28d6778 --- /dev/null +++ b/tcl_setup.cxx @@ -0,0 +1,53 @@ +#include "tcl_extras.h" +#include +#include + +Tcl_Interp *tcl_for_pd = NULL; + +extern "C" void tcl_setup(void) { + tclpd_setup(); +} + +void tclpd_setup(void) { + if(tcl_for_pd) { + return; + } + + post("Tcl loader v0.1.1 - 08.2009"); + + tcl_for_pd = Tcl_CreateInterp(); + Tcl_Init(tcl_for_pd); + Tclpd_SafeInit(tcl_for_pd); + + char *dirname = new char[PATH_MAX]; + char *dirresult = new char[PATH_MAX]; + /* nameresult is only a pointer in dirresult space so don't delete[] it. */ + char *nameresult; + if(getcwd(dirname, PATH_MAX) < 0) { + post("Tcl loader: FATAL: cannot get current dir"); + /* exit(69); */ return; + } + + int fd = open_via_path(dirname, "tcl", PDSUF, dirresult, &nameresult, PATH_MAX, 1); + if(fd >= 0) { + close(fd); + } else { + post("Tcl loader: %s was not found via the -path!", "tcl" PDSUF); + } + + Tcl_SetVar(tcl_for_pd, "DIR", dirresult, 0); + Tcl_Eval(tcl_for_pd, "set auto_path [linsert $auto_path $DIR]"); + + if(Tcl_Eval(tcl_for_pd, "source $DIR/tcl.tcl") == TCL_OK) { + post("Tcl loader: loaded %s/tcl.tcl", dirresult); + } + + if(Tcl_Eval(tcl_for_pd,"source $env(HOME)/.pd.tcl") == TCL_OK) { + post("Tcl loader: loaded ~/.pd.tcl"); + } + + delete[] dirresult; + delete[] dirname; + + sys_register_loader(tclpd_do_load_lib); +} -- cgit v1.2.1