wok-6.x diff tcl2c/stuff/tcl2c.u @ rev 20387
Add tcl2c
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sat Jun 23 11:56:52 2018 +0200 (2018-06-23) |
parents | |
children | 32c2394f606d |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/tcl2c/stuff/tcl2c.u Sat Jun 23 11:56:52 2018 +0200 1.3 @@ -0,0 +1,932 @@ 1.4 +http://web.tiscali.it/pas80/tklauncher.htm 1.5 +http://web.tiscali.it/pas80/tcl2c.tar.gz 1.6 +@@ -1,26 +1,10 @@ 1.7 +-//tcl2c @ 1997-2016 (04/2016) - Under G.P.L. License 1.8 +-//Based on tcl2c.c written by: Jan Nijtmans 1.9 +-//Cyril BARBATO 1.10 +-//tcl2c.sourceforge.net 1.11 +-//cyril.barbato@gmx.com 1.12 ++#include <tcl.h> 1.13 + 1.14 +-#include "tcl.h" 1.15 +-#include <stdio.h> 1.16 +-#include <stdlib.h> 1.17 +- 1.18 +-#ifdef _APPLICATION_IS_ROOT_PATH_ 1.19 +-#include <string.h> 1.20 +-#include <limits.h> 1.21 +-#include <unistd.h> 1.22 +-#endif 1.23 +- 1.24 + #ifdef __cplusplus 1.25 + extern C { 1.26 + #endif 1.27 + 1.28 + extern void exit _ANSI_ARGS_((int status)); 1.29 +-extern int isupper _ANSI_ARGS_((int ch)); 1.30 +-extern int tolower _ANSI_ARGS_((int ch)); 1.31 + 1.32 + #ifdef __cplusplus 1.33 + } 1.34 +@@ -44,55 +28,48 @@ 1.35 + 1.36 + static tableitem table[] = { 1.37 + {"Tcl" ,"-tcl" , 1}, 1.38 +-{"Tk" ,"-tk" , 3}, 1.39 +-{"Tclx" ,"-tclx" , 5}, 1.40 +-{"Itcl" ,"-itcl" , 9}, 1.41 +-{"Otcl" ,"-otcl" , 17}, /* not tested yet */ 1.42 +-{"Pvm" ,"-pvm" , 33}, 1.43 +-{"Tkx" ,"-tkx" , 71}, 1.44 +-{"Itk" ,"-itk" , 139}, 1.45 +-{"Iwidgets" ,"-iwidgets" , 395}, 1.46 +-{"Img" ,"-img" ,515}, 1.47 +-{"Tix" ,"-tix" ,1027}, /* not tested yet */ 1.48 +-{"Blt" ,"-blt" ,2051}, /* not tested yet */ 1.49 +-{"Vtcl" ,"-vtcl" ,4103}, /* not tested yet */ 1.50 ++{"Tclx" ,"-tclx" , 3}, 1.51 ++{"Itcl" ,"-itcl" , 5}, 1.52 ++{"Otcl" ,"-otcl" , 9}, /* not tested yet */ 1.53 ++{"Pvm" ,"-pvm" , 17}, 1.54 ++{"Tk" ,"-tk" , 33}, 1.55 ++{"Tkx" ,"-tkx" , 99}, 1.56 ++{"Itk" ,"-itk" , 165}, 1.57 ++{"Iwidgets" ,"-iwidgets" , 421}, 1.58 ++{"Img" ,"-img" ,545}, 1.59 ++{"Tix" ,"-tix" ,1057}, /* not tested yet */ 1.60 ++{"Blt" ,"-blt" ,2081}, /* not tested yet */ 1.61 ++{"Vtcl" ,"-vtcl" ,4261}, /* not tested yet */ 1.62 + }; 1.63 + 1.64 +-static char verbose[] = "\n\ 1.65 ++static char *verbose = "\n\ 1.66 + *************************** tcl2c ********************************\n\ 1.67 +-Based on tcl2c.c written by: Jan Nijtmans\n\ 1.68 +- CMG (Computer Management Group) Arnhem B.V.\n\ 1.69 +- email: Jan.Nijtmans@wxs.nl (private)\n\ 1.70 +- Jan.Nijtmans@cmg.nl (work)\n\ 1.71 +- url: http://home.wxs.nl/~nijtmans/\n\n\ 1.72 +- new options for gcc by: Cyril Barbato (cyril.barbato@gmx.com)\n\ 1.73 +- -D__MALLOC__ : for using malloc()\n\ 1.74 +- -D__LIBPATH__=\"your lib\" : change tcl lib path\n\ 1.75 +- -D_APPLICATION_IS_ROOT_PATH_ : for application is root path\n\\n\ 1.76 +- -D_CONSOLEWOZHIDE_ : Hide windows console\n\\n\ 1.77 +- new, add 2 tcl commands for windows console :\n\ 1.78 +- _tcl2c_consoleWOZHide for Hide windows console\n\ 1.79 +- _tcl2c_consoleWOZShow for Show windows console\n\\n\ 1.80 +- url : http://tcl2c.sourceforge.net/\n\n\ 1.81 +- usage: tcl2c -o file source1 source2 ... ?options?\n\ 1.82 ++written by: Jan Nijtmans\n\ 1.83 ++ NICI (Nijmegen Institute of Cognition and Information)\n\ 1.84 ++ email: nijtmans@nici.kun.nl\n\ 1.85 ++ url: http://www.cogsci.kun.nl/~nijtmans/\n\n\ 1.86 ++usage: tcl2c -o file source1 source2 ... ?options?\n\ 1.87 + tcl2c -help\n\ 1.88 + "; 1.89 + 1.90 +-static char help[] = "\n\ 1.91 ++static char *help = "\n\ 1.92 + available options:\n\ 1.93 + -a use character array instead of string for script\n\ 1.94 + -n script_name name of script variable\n\ 1.95 + -o filename output file (default is stdout)\n\ 1.96 + -tcl use Tcl\n\ 1.97 + -tclx use Tclx\n\ 1.98 ++ -itcl use Itcl\n\ 1.99 + -otcl use Otcl (not tested yet)\n\ 1.100 + -pvm use tkPvm\n\ 1.101 + -tk use Tk\n\ 1.102 +- -tkx use Tkx (not really useful)\n\ 1.103 +- -img use Img\n\ 1.104 ++ -tkx use Tkx (not really usefull)\n\ 1.105 ++ -itk use Itk\n\ 1.106 ++ -iwidgets use Iwidgets\n\ 1.107 + -tix use Tix (not tested yet)\n\ 1.108 + -blt use Blt (not tested yet)\n\ 1.109 + -vtcl use Vtcl (not tested yet)\n\ 1.110 ++ -index convert tclIndex files\n\n\ 1.111 + Other command line arguments are assumed to be tcl script-files. It is \n\ 1.112 + possible to include C-files (with the extension .c), which are already\n\ 1.113 + converted tcl-scripts. These are included using the \"#include\".\n\n\ 1.114 +@@ -101,7 +78,7 @@ 1.115 + 1.116 + static char *part1 = "\n\ 1.117 + /* This file is created by the \"tcl2c\" utility, which is included in\n\ 1.118 +- * most \"plus\"-patches (e.g. for Tcl8.6). Standalone\n\ 1.119 ++ * most \"plus\"-patches (e.g. for Tcl7.6 and Tcl8.0). Standalone\n\ 1.120 + * executables can be made by providing alternative initialization\n\ 1.121 + * functions which don't read files any more. Sometimes, small\n\ 1.122 + * adaptations to the original libraries are needed to get the\n\ 1.123 +@@ -111,68 +88,29 @@ 1.124 + * easyly extend the \"tcl2c\" utility to your own requirements.\n\ 1.125 + *\n\ 1.126 + * Jan Nijtmans\n\ 1.127 +- * CMG (Computer Management Group) Arnhem B.V.\n\ 1.128 +- * email: Jan.Nijtmans@wxs.nl (private)\n\ 1.129 +- * Jan.Nijtmans@cmg.nl (work)\n\ 1.130 +- * url: http://home.wxs.nl/~nijtmans/\n\ 1.131 +- *\n\ 1.132 +- *new options for gcc by: Cyril Barbato (cyril.barbato@gmx.com)\n\ 1.133 +- * -D__MALLOC__ : for using malloc()\n\ 1.134 +- * -D__LIBPATH__=\"your lib\" : change tcl lib path\n\ 1.135 +- * -D_APPLICATION_IS_ROOT_PATH_ : for application is root path\n\\n\ 1.136 +- -D_CONSOLEWOZHIDE_ : Hide windows console\n\ 1.137 +- *\n\ 1.138 +- new, add 2 tcl commands for windows console :\n\ 1.139 +- _tcl2c_consoleWOZHide for Hide windows console\n\ 1.140 +- _tcl2c_consoleWOZShow for Show windows console\n\\n\ 1.141 +- *\n\ 1.142 +- * url: http://tcl2c.sourceforge.net/\n\ 1.143 +- *\n\ 1.144 +- * usage: tcl2c -o file source1 source2 ... ?options?\n\ 1.145 +- * tcl2c -help\n\ 1.146 ++ * NICI (Nijmegen Institute of Cognition and Information)\n\ 1.147 ++ * email: nijtmans@nici.kun.nl\n\ 1.148 ++ * url: http://www.cogsci.kun.nl/~nijtmans/\n\ 1.149 + */\n\ 1.150 ++#define USE_INTERP_RESULT 1\n\ 1.151 + #include \"tcl.h\"\n\ 1.152 +-#ifdef _MACOSX_APP_\n\ 1.153 +-#import <crt_externs.h>\n\ 1.154 +-#endif\n\ 1.155 +-#ifdef __WIN32__\n\ 1.156 +-#define _WIN32_WINNT 0x0500\n\ 1.157 +-#define WIN32_LEAN_AND_MEAN\n\ 1.158 +-#include <windows.h>\n\ 1.159 +-#undef WIN32_LEAN_AND_MEAN\n\ 1.160 +-#ifndef __MALLOC_H__\n\ 1.161 +-#include <malloc.h>\n\ 1.162 +-#endif\n\ 1.163 +-#include <locale.h>\n\ 1.164 +-#ifndef __LIBPATH__\n\ 1.165 +-#define __LIBPATH__ \"lib\"\n\ 1.166 +-#endif\n\ 1.167 +-#include <unistd.h>\n\ 1.168 +-#ifdef _APPLICATION_IS_ROOT_PATH_\n\ 1.169 +-#include <string.h>\n\ 1.170 +-#include <limits.h>\n\ 1.171 +-#include <unistd.h>\n\ 1.172 +-#endif\n\ 1.173 + \n\ 1.174 +-static int setargv _ANSI_ARGS_((char ***argvPtr));\n\ 1.175 +-static void TclshPanic _ANSI_ARGS_(TCL_VARARGS(char *,format));\n\ 1.176 +-extern void TclWinInit(HINSTANCE instance);\n\ 1.177 +-extern int Registry_Init _ANSI_ARGS_((Tcl_Interp *interp));\n\ 1.178 +-\n\ 1.179 +-#endif\n\ 1.180 +-\n\ 1.181 + /*\n\ 1.182 + * Defines to replace the standard Xxx_Init calls to Xxx_InitStandAlone.\n\ 1.183 + * If you don't have this function, just delete the corresponding\n\ 1.184 + * define such that the normal initialization function is used.\n\ 1.185 +- * If no Xxx_SafeInit function exists, use NULL pointers instead\n\ 1.186 +- * by commenting out the appropriate lines below.\n\ 1.187 ++ * Similar: If SafeInit functions exists, you can use these\n\ 1.188 ++ * by commenting out the corresponding lines below.\n\ 1.189 + */\n\ 1.190 + \n\ 1.191 +-#if defined(TCL_ACTIVE) && !defined(SHARED)\n\ 1.192 ++#ifdef TCL_ACTIVE\n\ 1.193 + "; 1.194 + 1.195 +-static char *part2 = "\n\ 1.196 ++static char *part2 = "#endif\n\ 1.197 ++\n\ 1.198 ++"; 1.199 ++ 1.200 ++static char *part3 = "\n\ 1.201 + /*\n\ 1.202 + * Prototypes of all initialization functions and the free() function.\n\ 1.203 + * So, only \"tcl.h\" needs to be included now.\n\ 1.204 +@@ -182,27 +120,8 @@ 1.205 + extern \"C\" {\n\ 1.206 + #endif\n\ 1.207 + \n\ 1.208 +-#ifndef USE_TCLALLOC\n\ 1.209 +-# define USE_TCLALLOC 0\n\ 1.210 +-#endif\n\ 1.211 +-#if USE_TCLALLOC == 0\n\ 1.212 + extern void free _ANSI_ARGS_((void *));\n\ 1.213 +-extern VOID *malloc _ANSI_ARGS_((int));\n\ 1.214 +-#endif\n\ 1.215 +-extern int Tcl_Init _ANSI_ARGS_((Tcl_Interp *interp));\n\ 1.216 +-\n\ 1.217 + "; 1.218 +- 1.219 +-static char *part3 = "\n\ 1.220 +-extern void Tk_MainLoop _ANSI_ARGS_((void));\n\ 1.221 +-#define HAS_TK\n\ 1.222 +-#ifdef __WIN32__\n\ 1.223 +-extern void TkWinXInit _ANSI_ARGS_((HINSTANCE hinstance));\n\ 1.224 +-extern void TkWinXCleanup _ANSI_ARGS_((HINSTANCE hinstance));\n\ 1.225 +-#endif\n\ 1.226 +-\n\ 1.227 +-"; 1.228 +- 1.229 + static char *part4 = "\n\ 1.230 + #ifdef __cplusplus\n\ 1.231 + }\n\ 1.232 +@@ -213,64 +132,10 @@ 1.233 + * It will be executed in tclAppInit() after the other initializations.\n\ 1.234 + */\n\ 1.235 + \n\ 1.236 +-"; 1.237 +- 1.238 +-static char *part4a = "\ 1.239 +-static char *lineformat = \"%%.0s%%d\";\n\ 1.240 + static int line = (__LINE__ + 1);\n\ 1.241 + "; 1.242 + 1.243 +-static char *part4b = "\ 1.244 +-static char *lineformat = \"%%s_line%%d\";\n\ 1.245 +-static int line = 0;\n\ 1.246 +-"; 1.247 +- 1.248 + static char *part5 = "\ 1.249 +-#ifdef _APPLICATION_IS_ROOT_PATH_\n\ 1.250 +-#define PATH_MAX 1024\n\ 1.251 +-char abs_exe_path[PATH_MAX];\n\ 1.252 +-char *\n\ 1.253 +-#ifdef _USING_PROTOTYPES_\n\ 1.254 +-app_GetPath(\n\ 1.255 +- int argc,\n\ 1.256 +- char *argv[])\n\ 1.257 +-#else\n\ 1.258 +-app_GetPath(argc, argv)\n\ 1.259 +- int argc;\n\ 1.260 +- char *argv[];\n\ 1.261 +-#endif\n\ 1.262 +-{\n\ 1.263 +- char path_save[PATH_MAX];\n\ 1.264 +- char *p;\n\ 1.265 +- if(!(p = strrchr(argv[0], '/')))\n\ 1.266 +- getcwd(abs_exe_path, sizeof(abs_exe_path));\n\ 1.267 +- else\n\ 1.268 +- {\n\ 1.269 +- *p = '\\0';\n\ 1.270 +- getcwd(path_save, sizeof(path_save));\n\ 1.271 +- chdir(argv[0]);\n\ 1.272 +- getcwd(abs_exe_path, sizeof(abs_exe_path));\n\ 1.273 +- chdir(path_save);\n\ 1.274 +- }\n\ 1.275 +- //printf(\"Absolute path to executable is: %s\\n\", abs_exe_path);\n\ 1.276 +- return abs_exe_path;\n\ 1.277 +-};\n\ 1.278 +-#endif\n\ 1.279 +-#ifdef __WIN32__\n\ 1.280 +-HWND hConsoleWnd=NULL;\n\ 1.281 +-int _tcl2c_consoleWOZHideCmd(ClientData clientData, Tcl_Interp *interp, int argc, char **argv) {\n\ 1.282 +- if (hConsoleWnd==NULL) {hConsoleWnd = GetConsoleWindow();};\n\ 1.283 +- if (hConsoleWnd==NULL) {return TCL_OK;};\n\ 1.284 +- SetWindowPos(hConsoleWnd,HWND_NOTOPMOST,0,0,320,240,SWP_HIDEWINDOW);\n\ 1.285 +- return TCL_OK;\n\ 1.286 +-};\n\ 1.287 +-int _tcl2c_consoleWOZShowCmd(ClientData clientData, Tcl_Interp *interp, int argc, char **argv) {\n\ 1.288 +- if (hConsoleWnd==NULL) {hConsoleWnd = GetConsoleWindow();};\n\ 1.289 +- if (hConsoleWnd==NULL) {return TCL_OK;};\n\ 1.290 +- ShowWindow(hConsoleWnd,SW_SHOW);\n\ 1.291 +- return TCL_OK;\n\ 1.292 +-};\n\ 1.293 +-#endif\n\ 1.294 + /*\n\ 1.295 + *----------------------------------------------------------------------\n\ 1.296 + *\n\ 1.297 +@@ -287,18 +152,7 @@ 1.298 + *----------------------------------------------------------------------\n\ 1.299 + */\n\ 1.300 + \n\ 1.301 +-#if defined(__WIN32__) && defined(HAS_TK)\n\ 1.302 +-int APIENTRY\n\ 1.303 +-WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,\n\ 1.304 +- LPSTR lpszCmdLine, int nCmdShow)\n\ 1.305 +-{\n\ 1.306 +- char **argv;\n\ 1.307 +- int argc;\n\ 1.308 +-#else\n\ 1.309 +-"; 1.310 +-//MAIN Tcl App 1.311 +-static char *part5a = "\ 1.312 +-int\n\ 1.313 ++void\n\ 1.314 + #ifdef _USING_PROTOTYPES_\n\ 1.315 + main (int argc, /* Number of command-line arguments. */\n\ 1.316 + char **argv) /* Values of command-line arguments. */\n\ 1.317 +@@ -308,78 +162,12 @@ 1.318 + char **argv; /* Values of command-line arguments. */\n\ 1.319 + #endif\n\ 1.320 + {\n\ 1.321 +-#endif\n\ 1.322 + Tcl_Interp *interp;\n\ 1.323 + char **p = %s;\n\ 1.324 +- char *q, buffer[16];\n\ 1.325 ++ char *q, buffer[10];\n\ 1.326 + Tcl_DString data;\n\ 1.327 + Tcl_Channel inChannel, outChannel, errChannel;\n\ 1.328 + \n\ 1.329 +-#ifdef __LIBPATH__\n\ 1.330 +- ////char _cwd[1024];\n\ 1.331 +- char _libpath[2048];\n\ 1.332 +-#endif\n\ 1.333 +-#ifdef __WIN32__\n\ 1.334 +- char argv0[128];\n\ 1.335 +-#endif\n\ 1.336 +-#ifdef _MACOSX_APP_\n\ 1.337 +-argc = *_NSGetArgc();\n\ 1.338 +-char *progname = *_NSGetProgname();\n\ 1.339 +-char **envp = *_NSGetEnviron();\n\ 1.340 +-argv = *_NSGetArgv();\n\ 1.341 +-#endif\n\ 1.342 +-#ifdef _APPLICATION_IS_ROOT_PATH_\n\ 1.343 +- /* GOTO APPLICATION PATH FOR MAC OS*/\n\ 1.344 +- chdir(app_GetPath(argc, argv));\n\ 1.345 +-#endif\n\ 1.346 +-#ifdef __WIN32__\n\ 1.347 +-#ifdef _CONSOLEWOZHIDE_\n\ 1.348 +-_tcl2c_consoleWOZHideCmd(NULL, NULL, NULL, (char **) NULL);\n\ 1.349 +-#endif\n\ 1.350 +-#if defined(TCL_ACTIVE) && !defined(SHARED) && defined(HAS_TK)\n\ 1.351 +- TclWinInit(hInstance);\n\ 1.352 +- TkWinXInit(hInstance);\n\ 1.353 +- Tcl_CreateExitHandler((Tcl_ExitProc *) TkWinXCleanup, (ClientData) hInstance);\n\ 1.354 +-#endif\n\ 1.355 +-\n\ 1.356 +- Tcl_SetPanicProc(TclshPanic);\n\ 1.357 +-\n"; 1.358 +- 1.359 +-static char *part5b = "\n\ 1.360 +- /*\n\ 1.361 +- * Set up the default locale to be standard \"C\" locale so parsing\n\ 1.362 +- * is performed correctly.\n\ 1.363 +- */\n\ 1.364 +-\n\ 1.365 +- setlocale(LC_ALL, \"C\");\n\ 1.366 +-\n\ 1.367 +- /*\n\ 1.368 +- * Increase the application queue size from default value of 8.\n\ 1.369 +- * At the default value, cross application SendMessage of WM_KILLFOCUS\n\ 1.370 +- * will fail because the handler will not be able to do a PostMessage!\n\ 1.371 +- * This is only needed for Windows 3.x, since NT dynamically expands\n\ 1.372 +- * the queue.\n\ 1.373 +- */\n\ 1.374 +- SetMessageQueue(64);\n\ 1.375 +-\n\ 1.376 +- argc = setargv(&argv);\n\ 1.377 +-\n\ 1.378 +- /*\n\ 1.379 +- * Replace argv[0] with full pathname of executable, and forward\n\ 1.380 +- * slashes substituted for backslashes.\n\ 1.381 +- */\n\ 1.382 +-\n\ 1.383 +-"; 1.384 +-static char *part5c = "\ 1.385 +- GetModuleFileName(NULL, argv0, sizeof(argv0));\n\ 1.386 +- argv[0] = argv0;\n\ 1.387 +- for (q = argv0; *q != '\\0'; q++) {\n\ 1.388 +- if (*q == '\\\\') {\n\ 1.389 +- *q = '/';\n\ 1.390 +- }\n\ 1.391 +- }\n\ 1.392 +-\n\ 1.393 +-#endif\n\ 1.394 + Tcl_FindExecutable(argv[0]);\n\ 1.395 + interp = Tcl_CreateInterp();\n\ 1.396 + \n\ 1.397 +@@ -391,32 +179,8 @@ 1.398 + Tcl_SetVar(interp, \"argv0\", argv[0],TCL_GLOBAL_ONLY);\n\ 1.399 + Tcl_SetVar(interp, \"tcl_interactive\",\"0\", TCL_GLOBAL_ONLY);\n\ 1.400 + \n\ 1.401 +-#ifdef __LIBPATH__\n\ 1.402 +- ////chdir(__LIBPATH__);\n\ 1.403 +- ////getcwd(_cwd,sizeof(_cwd));\n\ 1.404 +- ////printf(\"libpath:%%s\\n\", _cwd);\n\ 1.405 +- sprintf(_libpath, \"set env(PWD) [pwd]\");\n\ 1.406 +- Tcl_Eval(interp, _libpath);\n\ 1.407 +- sprintf(_libpath, \"%%s/%%s/tcl%%s\", Tcl_GetVar2(interp, \"env\", \"PWD\", TCL_GLOBAL_ONLY),__LIBPATH__, Tcl_GetVar(interp,\"tcl_version\", TCL_GLOBAL_ONLY));\n\ 1.408 +- Tcl_SetVar2(interp, \"env\", \"TCL_LIBRARY\", _libpath, TCL_GLOBAL_ONLY);\n\ 1.409 +- Tcl_SetVar2(interp, \"env\", \"TK_LIBRARY\", _libpath, TCL_GLOBAL_ONLY);\n\ 1.410 +- Tcl_SetVar(interp, \"auto_path\", _libpath, TCL_GLOBAL_ONLY);\n\ 1.411 +- Tcl_SetVar(interp, \"tcl_libPath\", _libpath, TCL_GLOBAL_ONLY);\n\ 1.412 +-#endif\n\ 1.413 +-\n\ 1.414 +-if (Tcl_Init(interp) != TCL_OK) {\n\ 1.415 +- goto error;\n\ 1.416 +- }\n\ 1.417 +-\n\ 1.418 +-#ifdef __WIN32__\n\ 1.419 +- Tcl_StaticPackage((Tcl_Interp *) NULL, \"registry\", Registry_Init,\n\ 1.420 +- (Tcl_PackageInitProc *) NULL);\n\n\ 1.421 +- //Create commands _tcl2c_consoleWOZHide and _tcl2c_consoleWOZShow\n\ 1.422 +- Tcl_CreateCommand(interp, \"_tcl2c_consoleWOZHide\", _tcl2c_consoleWOZHideCmd, NULL, NULL);\n\ 1.423 +- Tcl_CreateCommand(interp, \"_tcl2c_consoleWOZShow\", _tcl2c_consoleWOZShowCmd, NULL, NULL);\n\n\ 1.424 +-#endif\n\ 1.425 +-\n\ 1.426 + "; 1.427 ++ 1.428 + static char *part6 = "\n\ 1.429 + /*\n\ 1.430 + * Execute the script that is compiled in.\n\ 1.431 +@@ -436,17 +200,27 @@ 1.432 + }\n\ 1.433 + line++;\n\ 1.434 + }\n\ 1.435 +- sprintf(buffer,lineformat,\"%s\",line);\n\ 1.436 +- printf(\"ERROR : (line %%s) : %%s\\n\", buffer, Tcl_GetVar(interp, \"errorInfo\", TCL_GLOBAL_ONLY));\n\ 1.437 ++ sprintf(buffer,\"%%d\",line);\n\ 1.438 ++ Tcl_AddErrorInfo(interp,\"\\n ( Error in file: \\\"\");\n\ 1.439 ++ Tcl_AddErrorInfo(interp,__FILE__);\n\ 1.440 ++ Tcl_AddErrorInfo(interp,\"\\\", line: \");\n\ 1.441 ++ Tcl_AddErrorInfo(interp,buffer);\n\ 1.442 ++ Tcl_AddErrorInfo(interp,\")\");\n\ 1.443 ++ errChannel = Tcl_GetStdChannel(TCL_STDERR);\n\ 1.444 ++ if (errChannel) {\n\ 1.445 ++ Tcl_Write(errChannel,\n\ 1.446 ++ Tcl_GetVar(interp, \"errorInfo\", TCL_GLOBAL_ONLY), -1);\n\ 1.447 ++ Tcl_Write(errChannel, \"\\n\", 1);\n\ 1.448 ++ }\n\ 1.449 ++ sprintf(buffer, \"exit %%d\", 1);\n\ 1.450 + Tcl_Eval(interp, buffer);\n\ 1.451 +- }};\n\ 1.452 +-"; 1.453 +- 1.454 +-static char *part6a = "\ 1.455 +- Tk_MainLoop();\n\ 1.456 +-"; 1.457 +- 1.458 +-static char *part6b = "\ 1.459 ++ }\n\ 1.460 ++ }\n\ 1.461 ++ Tcl_DStringFree(&data);\n\ 1.462 ++\n\ 1.463 ++ while (Tcl_DoOneEvent(0)) {\n\ 1.464 ++ /* empty loop body */ ;\n\ 1.465 ++ }\n\ 1.466 + sprintf(buffer, \"exit %%d\", 0);\n\ 1.467 + Tcl_Eval(interp, buffer);\n\ 1.468 + \n\ 1.469 +@@ -455,185 +229,20 @@ 1.470 + if (errChannel) {\n\ 1.471 + Tcl_Write(errChannel,\n\ 1.472 + \"application-specific initialization failed: \", -1);\n\ 1.473 +- Tcl_Write(errChannel, Tcl_GetStringResult(interp), -1);\n\ 1.474 ++ Tcl_Write(errChannel, interp->result, -1);\n\ 1.475 + Tcl_Write(errChannel, \"\\n\", 1);\n\ 1.476 + }\n\ 1.477 +-#ifdef __WIN32__\n\ 1.478 +- TclshPanic(Tcl_GetStringResult(interp));\n\ 1.479 +-#endif\n\ 1.480 + sprintf(buffer, \"exit %%d\", 1);\n\ 1.481 + Tcl_Eval(interp, buffer);\n\ 1.482 +- return 0;\n\ 1.483 + }\n\ 1.484 +-\n\ 1.485 +-#ifdef __WIN32__\n\ 1.486 +-/*\n\ 1.487 +- *----------------------------------------------------------------------\n\ 1.488 +- *\n\ 1.489 +- * TclshPanic --\n\ 1.490 +- *\n\ 1.491 +- * Display a message and exit.\n\ 1.492 +- *\n\ 1.493 +- * Results:\n\ 1.494 +- * None.\n\ 1.495 +- *\n\ 1.496 +- * Side effects:\n\ 1.497 +- * Exits the program.\n\ 1.498 +- *\n\ 1.499 +- *----------------------------------------------------------------------\n\ 1.500 +- */\n\ 1.501 +-\n\ 1.502 +-void\n\ 1.503 +-TclshPanic TCL_VARARGS_DEF(char *,arg1)\n\ 1.504 +-{\n\ 1.505 +- va_list argList;\n\ 1.506 +- char buf[1024];\n\ 1.507 +- char *format;\n\ 1.508 +-\n\ 1.509 +- format = TCL_VARARGS_START(char *,arg1,argList);\n\ 1.510 +- vsprintf(buf, format, argList);\n\ 1.511 +-\n\ 1.512 +- MessageBeep(MB_ICONEXCLAMATION);\n\ 1.513 +- MessageBox(NULL, buf, \"Fatal Error in Tclsh\",\n\ 1.514 +- MB_ICONSTOP | MB_OK | MB_TASKMODAL | MB_SETFOREGROUND);\n\ 1.515 +-#ifdef _MSC_VER\n\ 1.516 +- DebugBreak();\n\ 1.517 +-#endif\n\ 1.518 +- ExitProcess(1);\n\ 1.519 +-}\n\ 1.520 + "; 1.521 + 1.522 +-static char *part6c = "\ 1.523 +-\n\ 1.524 +-/*\n\ 1.525 +- *-------------------------------------------------------------------------\n\ 1.526 +- *\n\ 1.527 +- * setargv --\n\ 1.528 +- *\n\ 1.529 +- * Parse the Windows command line string into argc/argv. Done here\n\ 1.530 +- * because we don't trust the builtin argument parser in crt0. \n\ 1.531 +- * Windows applications are responsible for breaking their command\n\ 1.532 +- * line into arguments.\n\ 1.533 +- *\n\ 1.534 +- * 2N backslashes + quote -> N backslashes + begin quoted string\n\ 1.535 +- * 2N + 1 backslashes + quote -> literal\n\ 1.536 +- * N backslashes + non-quote -> literal\n\ 1.537 +- * quote + quote in a quoted string -> single quote\n\ 1.538 +- * quote + quote not in quoted string -> empty string\n\ 1.539 +- * quote -> begin quoted string\n\ 1.540 +- *\n\ 1.541 +- * Results:\n\ 1.542 +- * returns the number of arguments and fill argvPtr with the\n\ 1.543 +- * array of arguments.\n\ 1.544 +- *\n\ 1.545 +- * Side effects:\n\ 1.546 +- * Memory allocated.\n\ 1.547 +- *\n\ 1.548 +- *--------------------------------------------------------------------------\n\ 1.549 +- */\n\ 1.550 +-\n\ 1.551 +-"; 1.552 +- 1.553 +-static char *part6d = "\ 1.554 +-static int\n\ 1.555 +-setargv(argvPtr)\n\ 1.556 +- char ***argvPtr; /* Filled with argument strings (malloc'd). */\n\ 1.557 +-{\n\ 1.558 +- char *cmdLine, *p, *arg, *argSpace;\n\ 1.559 +- char **argv;\n\ 1.560 +- int argc, size, inquote, copy, slashes;\n\ 1.561 +-\n\ 1.562 +- cmdLine = GetCommandLine();\n\ 1.563 +-\n\ 1.564 +- /*\n\ 1.565 +- * Precompute an overly pessimistic guess at the number of arguments\n\ 1.566 +- * in the command line by counting non-space spans.\n\ 1.567 +- */\n\ 1.568 +-\n\ 1.569 +- size = 2;\n\ 1.570 +- for (p = cmdLine; *p != '\\0'; p++) {\n\ 1.571 +- if (isspace(*p)) {\n\ 1.572 +- size++;\n\ 1.573 +- while (isspace(*p)) {\n\ 1.574 +- p++;\n\ 1.575 +- }\n\ 1.576 +- if (*p == '\\0') {\n\ 1.577 +- break;\n\ 1.578 +- }\n\ 1.579 +- }\n\ 1.580 +- }\n\ 1.581 +- argSpace = (char *) ckalloc((unsigned) (size * sizeof(char *)\n\ 1.582 +- + strlen(cmdLine) + 1));\n\ 1.583 +- argv = (char **) argSpace;\n\ 1.584 +- argSpace += size * sizeof(char *);\n\ 1.585 +- size--;\n\ 1.586 +-\n\ 1.587 +- p = cmdLine;\n\ 1.588 +- for (argc = 0; argc < size; argc++) {\n\ 1.589 +- argv[argc] = arg = argSpace;\n\ 1.590 +- while (isspace(*p)) {\n\ 1.591 +- p++;\n\ 1.592 +- }\n\ 1.593 +- if (*p == '\\0') {\n\ 1.594 +- break;\n\ 1.595 +- }\n\ 1.596 +-\n\ 1.597 +-"; 1.598 +- 1.599 +-static char *part6e = "\ 1.600 +- inquote = 0;\n\ 1.601 +- slashes = 0;\n\ 1.602 +- while (1) {\n\ 1.603 +- copy = 1;\n\ 1.604 +- while (*p == '\\\\') {\n\ 1.605 +- slashes++;\n\ 1.606 +- p++;\n\ 1.607 +- }\n\ 1.608 +- if (*p == '\"') {\n\ 1.609 +- if ((slashes & 1) == 0) {\n\ 1.610 +- copy = 0;\n\ 1.611 +- if ((inquote) && (p[1] == '\"')) {\n\ 1.612 +- p++;\n\ 1.613 +- copy = 1;\n\ 1.614 +- } else {\n\ 1.615 +- inquote = !inquote;\n\ 1.616 +- }\n\ 1.617 +- }\n\ 1.618 +- slashes >>= 1;\n\ 1.619 +- }\n\ 1.620 +-\n\ 1.621 +- while (slashes) {\n\ 1.622 +- *arg = '\\\\';\n\ 1.623 +- arg++;\n\ 1.624 +- slashes--;\n\ 1.625 +- }\n\ 1.626 +-\n\ 1.627 +- if ((*p == '\\0') || (!inquote && isspace(*p))) {\n\ 1.628 +- break;\n\ 1.629 +- }\n\ 1.630 +- if (copy != 0) {\n\ 1.631 +- *arg = *p;\n\ 1.632 +- arg++;\n\ 1.633 +- }\n\ 1.634 +- p++;\n\ 1.635 +- }\n\ 1.636 +- *arg = '\\0';\n\ 1.637 +- argSpace = arg + 1;\n\ 1.638 +- }\n\ 1.639 +- argv[argc] = NULL;\n\ 1.640 +-\n\ 1.641 +- *argvPtr = argv;\n\ 1.642 +- return argc;\n\ 1.643 +-}\n\ 1.644 +-#endif /* __WIN32__ */\n\ 1.645 +-"; 1.646 +- 1.647 +-static char *defineproto = "\ 1.648 ++static char *defineproto1 = "\ 1.649 + #define %s_Init %s_InitStandAlone\n\ 1.650 + "; 1.651 + 1.652 + static char *defineproto2 = "\ 1.653 +-/*#define %s_SafeInit ((Tcl_PackageInitProc *) NULL)*/\n\ 1.654 ++#define %s_SafeInit (Tcl_PackageInitProc *) NULL\n\ 1.655 + "; 1.656 + 1.657 + static char *initproto = "\ 1.658 +@@ -653,9 +262,8 @@ 1.659 + }\n\ 1.660 + "; 1.661 + 1.662 +-static char *buffer; 1.663 ++static char buffer[32768]; 1.664 + static unsigned int max_buffer = 0; 1.665 +-static unsigned int buffer_size = MAX_STRING_LEN; 1.666 + static char max_buffer_content[80]; 1.667 + 1.668 + static char array_instead_of_string = 0; 1.669 +@@ -663,23 +271,25 @@ 1.670 + 1.671 + static char script_name[256]; 1.672 + 1.673 +-int printline _ANSI_ARGS_((FILE *f, char *dir, int flags)); 1.674 ++int printline _ANSI_ARGS_((FILE *f, char *buf, char *dir, int flags)); 1.675 + int printfile _ANSI_ARGS_((FILE *fout, char *filename, char *dir, int flags)); 1.676 + 1.677 + int 1.678 + #ifdef _USING_PROTOTYPES_ 1.679 + printline ( 1.680 + FILE *f, 1.681 ++ char *buf, 1.682 + char *dir, 1.683 + int flags) 1.684 + #else 1.685 +-printline(f, dir, flags) 1.686 ++printline(f,buf,dir,flags) 1.687 + FILE *f; 1.688 ++ char *buf; 1.689 + char *dir; 1.690 + int flags; 1.691 + #endif 1.692 + { 1.693 +- char *p, *q, *buf = buffer; 1.694 ++ char *p,*q; 1.695 + char path[128]; 1.696 + unsigned int l; 1.697 + 1.698 +@@ -730,7 +340,7 @@ 1.699 + *q='}'; 1.700 + } 1.701 + } 1.702 +- p = buffer; 1.703 ++ p = buf; 1.704 + while ((p = strstr(p, "[list source [file join $dir")) != NULL) { 1.705 + q = strstr(p,".tcl]]"); 1.706 + if (q != NULL) { 1.707 +@@ -805,14 +415,6 @@ 1.708 + p = q = buffer; 1.709 + while ((c=fgetc(fin))!=EOF) { 1.710 + *p = 0; 1.711 +- if (p + 10 > buffer + buffer_size) { 1.712 +- char *new; 1.713 +- buffer_size += MAX_STRING_LEN; 1.714 +- new = (char *) realloc(buffer, buffer_size); 1.715 +- p = new + (p - buffer); 1.716 +- q = new + (q - buffer); 1.717 +- buffer = new; 1.718 +- } 1.719 + if (c=='\n') { 1.720 + if (!strncmp(buffer,"if {[info exists tk_library] && [string compare $tk_library {}]} {",66)) { 1.721 + int flag = 1; 1.722 +@@ -823,6 +425,7 @@ 1.723 + flag--; 1.724 + } 1.725 + } 1.726 ++ flag=0; 1.727 + p=q=buffer; 1.728 + } else if ((p==buffer)||(*q=='\n')||(*q=='#')) { 1.729 + if ((*q=='#') && (*(p-1)=='\\')) { 1.730 +@@ -833,54 +436,23 @@ 1.731 + } else { 1.732 + *p++ = '\n'; *p=0; 1.733 + if (Tcl_CommandComplete(buffer)) { 1.734 +- p--; *p = 0; printline(fout,dir,flags); 1.735 ++ p--; *p = 0; printline(fout,buffer,dir,flags); 1.736 + p = q = buffer; 1.737 + } else { 1.738 + q=p; 1.739 + } 1.740 + } 1.741 + } else { 1.742 +- *p++ = (char) c; 1.743 ++ *p++ = c; 1.744 + } 1.745 + } 1.746 + if (p!=buffer) { 1.747 +- *p=0; printline(fout, dir, flags); 1.748 ++ *p=0; printline(fout,buffer,dir,flags); 1.749 + } 1.750 + fclose(fin); 1.751 + return 0; /* O.K. */ 1.752 + } 1.753 + 1.754 +-#ifdef _APPLICATION_IS_ROOT_PATH_ 1.755 +-char abs_exe_path[PATH_MAX]; 1.756 +-char * 1.757 +-#ifdef _USING_PROTOTYPES_ 1.758 +-app_GetPath( 1.759 +- int argc, 1.760 +- char *argv[]) 1.761 +-#else 1.762 +-app_GetPath(argc, argv) 1.763 +- int argc; 1.764 +- char *argv[]; 1.765 +-#endif 1.766 +-{ 1.767 +- char path_save[PATH_MAX]; 1.768 +- char *p; 1.769 +- if(!(p = strrchr(argv[0], '/'))) 1.770 +- getcwd(abs_exe_path, sizeof(abs_exe_path)); 1.771 +- else 1.772 +- { 1.773 +- *p = '\0'; 1.774 +- getcwd(path_save, sizeof(path_save)); 1.775 +- chdir(argv[0]); 1.776 +- getcwd(abs_exe_path, sizeof(abs_exe_path)); 1.777 +- chdir(path_save); 1.778 +- } 1.779 +- //printf("Absolute path to executable is: %s\n", abs_exe_path); 1.780 +- return abs_exe_path; 1.781 +-}; 1.782 +-#endif 1.783 +- 1.784 +-/* MAIN */ 1.785 + int 1.786 + #ifdef _USING_PROTOTYPES_ 1.787 + main ( 1.788 +@@ -898,11 +470,6 @@ 1.789 + tableitem *t; 1.790 + int c,i, flags=0; 1.791 + 1.792 +-#ifdef _APPLICATION_IS_ROOT_PATH_ 1.793 +- /* GOTO APPLICATION PATH */ 1.794 +- chdir(app_GetPath(argc, argv)); 1.795 +-#endif 1.796 +- 1.797 + if (argc==1) { 1.798 + printf(verbose); 1.799 + exit(0); 1.800 +@@ -921,6 +488,8 @@ 1.801 + i++; strcpy(script_name,argv[i]); 1.802 + } else if (!strcmp(argv[i],"-o")) { 1.803 + i++; filename = argv[i]; 1.804 ++ } else if (!strcmp(argv[i],"-index")) { 1.805 ++ flags = -1; 1.806 + } else { 1.807 + for (t=table;t<table+(sizeof(table)/sizeof(tableitem));t++) { 1.808 + if (!strcmp(argv[i],t->option)) { 1.809 +@@ -950,61 +519,41 @@ 1.810 + p = q+1; 1.811 + } 1.812 + strcpy(script_name,p); 1.813 +- q = script_name; 1.814 +- while (*q) { 1.815 +- if (*q == '.') { 1.816 +- *q = '_'; 1.817 +- } else if (isupper(*q)) { 1.818 +- *q = tolower(*q); 1.819 +- } 1.820 +- q++; 1.821 +- } 1.822 + while ((q = strchr(script_name,'.')) != NULL) { 1.823 + *q = '_'; 1.824 + } 1.825 + /* create prototypes for all initialization functions that are used */ 1.826 +- if (flags) { 1.827 ++ if (flags && (flags != -1)) { 1.828 + if (script_name[0] == 0) { 1.829 + strcpy(script_name,"script"); 1.830 + } 1.831 + fprintf(fout, part1); 1.832 + for (i=0,c=1;i<(sizeof(table)/sizeof(tableitem));i++,c<<=1) { 1.833 + if (flags & c) { 1.834 +- fprintf(fout,defineproto,table[i].package, 1.835 ++ fprintf(fout,defineproto1,table[i].package, 1.836 + table[i].package); 1.837 + } 1.838 + } 1.839 +- fprintf(fout, "#endif\n\n"); 1.840 +- for (i=1,c=2;i<(sizeof(table)/sizeof(tableitem));i++,c<<=1) { 1.841 ++ fprintf(fout, part2); 1.842 ++ for (i=0,c=1;i<(sizeof(table)/sizeof(tableitem));i++,c<<=1) { 1.843 + if (flags & c) { 1.844 + fprintf(fout,defineproto2,table[i].package); 1.845 + } 1.846 + } 1.847 +- fprintf(fout, part2); 1.848 +- 1.849 +- if (flags & 2) { 1.850 + fprintf(fout, part3); 1.851 +- } 1.852 +- for (i=1,c=2;i<(sizeof(table)/sizeof(tableitem));i++,c<<=1) { 1.853 ++ for (i=0,c=1;i<(sizeof(table)/sizeof(tableitem));i++,c<<=1) { 1.854 + if (flags & c) { 1.855 + fprintf(fout,initproto,table[i].package, 1.856 + table[i].package,table[i].package); 1.857 + } 1.858 + } 1.859 + fprintf(fout, part4, script_name); 1.860 +- if (array_instead_of_string) { 1.861 +- fprintf(fout, part4b); 1.862 +- } else { 1.863 +- fprintf(fout, part4a); 1.864 + } 1.865 +- } 1.866 + if ( !array_instead_of_string && script_name[0]) { 1.867 + fprintf(fout, "static char *%s[] = {\n", script_name); 1.868 + } 1.869 + /* handle all remaining arguments */ 1.870 + if (argc) {argc--; argv++;} 1.871 +- buffer = (char *) malloc(4*MAX_STRING_LEN); 1.872 +- buffer_size = 4*MAX_STRING_LEN; 1.873 + while(argc) { 1.874 + if ((*argv)[0]=='-') { 1.875 + if ((((*argv)[1]=='o')||((*argv)[1]=='n'))&&((*argv)[2]==0)) { 1.876 +@@ -1021,7 +570,6 @@ 1.877 + } 1.878 + argc--; argv++; 1.879 + } 1.880 +- free(buffer); 1.881 + if ( array_instead_of_string ) { 1.882 + fprintf(fout, "static char *%s[] = {\n", script_name); 1.883 + for (i = 0; (unsigned int)i < num_lines;) 1.884 +@@ -1031,39 +579,34 @@ 1.885 + fprintf(fout, "(char *) NULL\n};\n\n"); 1.886 + } 1.887 + /* end of scripts, finally the functions main() and tclAppInit() */ 1.888 +- if (flags) { 1.889 ++ if (flags && (flags != -1)) { 1.890 + fprintf(fout, part5, script_name); 1.891 +- fprintf(fout, part5a, script_name); 1.892 +- fprintf(fout, part5b); 1.893 +- fprintf(fout, part5c); 1.894 +- for (i=1,c=2;i<(sizeof(table)/sizeof(tableitem));i++,c<<=1) { 1.895 +- if (flags & c) { 1.896 +- fprintf(fout,callinit,table[i].package); 1.897 ++ fprintf(fout,callinit,table[0].package); 1.898 ++ if (flags & 0x20) { 1.899 ++ fprintf(fout,callinit,table[5].package); 1.900 ++ } 1.901 ++ for (i=0,c=1;i<(sizeof(table)/sizeof(tableitem));i++,c<<=1) { 1.902 ++ if ((flags & c) && (i!=0)) 1.903 + fprintf(fout,packageproto,table[i].package,table[i].package,table[i].package); 1.904 + } 1.905 ++ for (i=0,c=1;i<(sizeof(table)/sizeof(tableitem));i++,c<<=1) { 1.906 ++ if ((flags & c) && (i!=0) && (i!=5)) 1.907 ++ fprintf(fout,callinit,table[i].package); 1.908 + } 1.909 + p=filename?filename:"app"; 1.910 + if ((q=strrchr(p,'/')) != NULL) p=q+1; 1.911 + if ((q=strchr(p,'.')) != NULL) *q=0; 1.912 + if (!*p) p="app"; 1.913 +- fprintf(fout, part6,script_name,script_name,p,p); 1.914 +- if (flags & 2) { 1.915 +- fprintf(fout, part6a); 1.916 ++ fprintf(fout, part6,script_name,p,p); 1.917 + } 1.918 +- fprintf(fout, part6b); 1.919 +- fprintf(fout, part6c); 1.920 +- fprintf(fout, part6d); 1.921 +- fprintf(fout, part6e); 1.922 +- } 1.923 + /* close output-file, if not stdout */ 1.924 + if (fout!=stdout) { 1.925 + fclose(fout); 1.926 + } 1.927 + if (max_buffer>MAX_STRING_LEN) { 1.928 +- fprintf(stderr,"warning: largest sting in output file is %d bytes\n\ 1.929 ++ fprintf(stderr,"warning: largest string in output file is %d bytes\n\ 1.930 + many compilers can only handle %d characters in a string\n\ 1.931 + first line: %s\n",max_buffer,MAX_STRING_LEN,max_buffer_content); 1.932 + } 1.933 + exit(0); 1.934 +- return 0; 1.935 + }