rev |
line source |
pascal@20387
|
1 http://web.tiscali.it/pas80/tklauncher.htm
|
pascal@20387
|
2 http://web.tiscali.it/pas80/tcl2c.tar.gz
|
pascal@20387
|
3 @@ -1,26 +1,10 @@
|
pascal@20387
|
4 -//tcl2c @ 1997-2016 (04/2016) - Under G.P.L. License
|
pascal@20387
|
5 -//Based on tcl2c.c written by: Jan Nijtmans
|
pascal@20387
|
6 -//Cyril BARBATO
|
pascal@20387
|
7 -//tcl2c.sourceforge.net
|
pascal@20387
|
8 -//cyril.barbato@gmx.com
|
pascal@20387
|
9 +#include <tcl.h>
|
pascal@20387
|
10
|
pascal@20387
|
11 -#include "tcl.h"
|
pascal@20387
|
12 -#include <stdio.h>
|
pascal@20387
|
13 -#include <stdlib.h>
|
pascal@20387
|
14 -
|
pascal@20387
|
15 -#ifdef _APPLICATION_IS_ROOT_PATH_
|
pascal@20387
|
16 -#include <string.h>
|
pascal@20387
|
17 -#include <limits.h>
|
pascal@20387
|
18 -#include <unistd.h>
|
pascal@20387
|
19 -#endif
|
pascal@20387
|
20 -
|
pascal@20387
|
21 #ifdef __cplusplus
|
pascal@20387
|
22 extern C {
|
pascal@20387
|
23 #endif
|
pascal@20387
|
24
|
pascal@20387
|
25 extern void exit _ANSI_ARGS_((int status));
|
pascal@20387
|
26 -extern int isupper _ANSI_ARGS_((int ch));
|
pascal@20387
|
27 -extern int tolower _ANSI_ARGS_((int ch));
|
pascal@20387
|
28
|
pascal@20387
|
29 #ifdef __cplusplus
|
pascal@20387
|
30 }
|
pascal@20387
|
31 @@ -44,55 +28,48 @@
|
pascal@20387
|
32
|
pascal@20387
|
33 static tableitem table[] = {
|
pascal@20387
|
34 {"Tcl" ,"-tcl" , 1},
|
pascal@20387
|
35 -{"Tk" ,"-tk" , 3},
|
pascal@20387
|
36 -{"Tclx" ,"-tclx" , 5},
|
pascal@20387
|
37 -{"Itcl" ,"-itcl" , 9},
|
pascal@20387
|
38 -{"Otcl" ,"-otcl" , 17}, /* not tested yet */
|
pascal@20387
|
39 -{"Pvm" ,"-pvm" , 33},
|
pascal@20387
|
40 -{"Tkx" ,"-tkx" , 71},
|
pascal@20387
|
41 -{"Itk" ,"-itk" , 139},
|
pascal@20387
|
42 -{"Iwidgets" ,"-iwidgets" , 395},
|
pascal@20387
|
43 -{"Img" ,"-img" ,515},
|
pascal@20387
|
44 -{"Tix" ,"-tix" ,1027}, /* not tested yet */
|
pascal@20387
|
45 -{"Blt" ,"-blt" ,2051}, /* not tested yet */
|
pascal@20387
|
46 -{"Vtcl" ,"-vtcl" ,4103}, /* not tested yet */
|
pascal@20387
|
47 +{"Tclx" ,"-tclx" , 3},
|
pascal@20387
|
48 +{"Itcl" ,"-itcl" , 5},
|
pascal@20387
|
49 +{"Otcl" ,"-otcl" , 9}, /* not tested yet */
|
pascal@20387
|
50 +{"Pvm" ,"-pvm" , 17},
|
pascal@20387
|
51 +{"Tk" ,"-tk" , 33},
|
pascal@20387
|
52 +{"Tkx" ,"-tkx" , 99},
|
pascal@20387
|
53 +{"Itk" ,"-itk" , 165},
|
pascal@20387
|
54 +{"Iwidgets" ,"-iwidgets" , 421},
|
pascal@20387
|
55 +{"Img" ,"-img" ,545},
|
pascal@20387
|
56 +{"Tix" ,"-tix" ,1057}, /* not tested yet */
|
pascal@20387
|
57 +{"Blt" ,"-blt" ,2081}, /* not tested yet */
|
pascal@20387
|
58 +{"Vtcl" ,"-vtcl" ,4261}, /* not tested yet */
|
pascal@20387
|
59 };
|
pascal@20387
|
60
|
pascal@20387
|
61 -static char verbose[] = "\n\
|
pascal@20387
|
62 +static char *verbose = "\n\
|
pascal@20387
|
63 *************************** tcl2c ********************************\n\
|
pascal@20387
|
64 -Based on tcl2c.c written by: Jan Nijtmans\n\
|
pascal@20387
|
65 - CMG (Computer Management Group) Arnhem B.V.\n\
|
pascal@20387
|
66 - email: Jan.Nijtmans@wxs.nl (private)\n\
|
pascal@20387
|
67 - Jan.Nijtmans@cmg.nl (work)\n\
|
pascal@20387
|
68 - url: http://home.wxs.nl/~nijtmans/\n\n\
|
pascal@20387
|
69 - new options for gcc by: Cyril Barbato (cyril.barbato@gmx.com)\n\
|
pascal@20387
|
70 - -D__MALLOC__ : for using malloc()\n\
|
pascal@20387
|
71 - -D__LIBPATH__=\"your lib\" : change tcl lib path\n\
|
pascal@20387
|
72 - -D_APPLICATION_IS_ROOT_PATH_ : for application is root path\n\\n\
|
pascal@20387
|
73 - -D_CONSOLEWOZHIDE_ : Hide windows console\n\\n\
|
pascal@20387
|
74 - new, add 2 tcl commands for windows console :\n\
|
pascal@20387
|
75 - _tcl2c_consoleWOZHide for Hide windows console\n\
|
pascal@20387
|
76 - _tcl2c_consoleWOZShow for Show windows console\n\\n\
|
pascal@20387
|
77 - url : http://tcl2c.sourceforge.net/\n\n\
|
pascal@20387
|
78 - usage: tcl2c -o file source1 source2 ... ?options?\n\
|
pascal@20387
|
79 +written by: Jan Nijtmans\n\
|
pascal@20387
|
80 + NICI (Nijmegen Institute of Cognition and Information)\n\
|
pascal@20387
|
81 + email: nijtmans@nici.kun.nl\n\
|
pascal@20387
|
82 + url: http://www.cogsci.kun.nl/~nijtmans/\n\n\
|
pascal@20387
|
83 +usage: tcl2c -o file source1 source2 ... ?options?\n\
|
pascal@20387
|
84 tcl2c -help\n\
|
pascal@20387
|
85 ";
|
pascal@20387
|
86
|
pascal@20387
|
87 -static char help[] = "\n\
|
pascal@20387
|
88 +static char *help = "\n\
|
pascal@20387
|
89 available options:\n\
|
pascal@20387
|
90 -a use character array instead of string for script\n\
|
pascal@20387
|
91 -n script_name name of script variable\n\
|
pascal@20387
|
92 -o filename output file (default is stdout)\n\
|
pascal@20387
|
93 -tcl use Tcl\n\
|
pascal@20387
|
94 -tclx use Tclx\n\
|
pascal@20387
|
95 + -itcl use Itcl\n\
|
pascal@20387
|
96 -otcl use Otcl (not tested yet)\n\
|
pascal@20387
|
97 -pvm use tkPvm\n\
|
pascal@20387
|
98 -tk use Tk\n\
|
pascal@20387
|
99 - -tkx use Tkx (not really useful)\n\
|
pascal@20387
|
100 - -img use Img\n\
|
pascal@20387
|
101 + -tkx use Tkx (not really usefull)\n\
|
pascal@20387
|
102 + -itk use Itk\n\
|
pascal@20387
|
103 + -iwidgets use Iwidgets\n\
|
pascal@20387
|
104 -tix use Tix (not tested yet)\n\
|
pascal@20387
|
105 -blt use Blt (not tested yet)\n\
|
pascal@20387
|
106 -vtcl use Vtcl (not tested yet)\n\
|
pascal@20387
|
107 + -index convert tclIndex files\n\n\
|
pascal@20387
|
108 Other command line arguments are assumed to be tcl script-files. It is \n\
|
pascal@20387
|
109 possible to include C-files (with the extension .c), which are already\n\
|
pascal@20387
|
110 converted tcl-scripts. These are included using the \"#include\".\n\n\
|
pascal@20387
|
111 @@ -101,7 +78,7 @@
|
pascal@20387
|
112
|
pascal@20387
|
113 static char *part1 = "\n\
|
pascal@20387
|
114 /* This file is created by the \"tcl2c\" utility, which is included in\n\
|
pascal@20387
|
115 - * most \"plus\"-patches (e.g. for Tcl8.6). Standalone\n\
|
pascal@20387
|
116 + * most \"plus\"-patches (e.g. for Tcl7.6 and Tcl8.0). Standalone\n\
|
pascal@20387
|
117 * executables can be made by providing alternative initialization\n\
|
pascal@20387
|
118 * functions which don't read files any more. Sometimes, small\n\
|
pascal@20387
|
119 * adaptations to the original libraries are needed to get the\n\
|
pascal@20387
|
120 @@ -111,68 +88,29 @@
|
pascal@20387
|
121 * easyly extend the \"tcl2c\" utility to your own requirements.\n\
|
pascal@20387
|
122 *\n\
|
pascal@20387
|
123 * Jan Nijtmans\n\
|
pascal@20387
|
124 - * CMG (Computer Management Group) Arnhem B.V.\n\
|
pascal@20387
|
125 - * email: Jan.Nijtmans@wxs.nl (private)\n\
|
pascal@20387
|
126 - * Jan.Nijtmans@cmg.nl (work)\n\
|
pascal@20387
|
127 - * url: http://home.wxs.nl/~nijtmans/\n\
|
pascal@20387
|
128 - *\n\
|
pascal@20387
|
129 - *new options for gcc by: Cyril Barbato (cyril.barbato@gmx.com)\n\
|
pascal@20387
|
130 - * -D__MALLOC__ : for using malloc()\n\
|
pascal@20387
|
131 - * -D__LIBPATH__=\"your lib\" : change tcl lib path\n\
|
pascal@20387
|
132 - * -D_APPLICATION_IS_ROOT_PATH_ : for application is root path\n\\n\
|
pascal@20387
|
133 - -D_CONSOLEWOZHIDE_ : Hide windows console\n\
|
pascal@20387
|
134 - *\n\
|
pascal@20387
|
135 - new, add 2 tcl commands for windows console :\n\
|
pascal@20387
|
136 - _tcl2c_consoleWOZHide for Hide windows console\n\
|
pascal@20387
|
137 - _tcl2c_consoleWOZShow for Show windows console\n\\n\
|
pascal@20387
|
138 - *\n\
|
pascal@20387
|
139 - * url: http://tcl2c.sourceforge.net/\n\
|
pascal@20387
|
140 - *\n\
|
pascal@20387
|
141 - * usage: tcl2c -o file source1 source2 ... ?options?\n\
|
pascal@20387
|
142 - * tcl2c -help\n\
|
pascal@20387
|
143 + * NICI (Nijmegen Institute of Cognition and Information)\n\
|
pascal@20387
|
144 + * email: nijtmans@nici.kun.nl\n\
|
pascal@20387
|
145 + * url: http://www.cogsci.kun.nl/~nijtmans/\n\
|
pascal@20387
|
146 */\n\
|
pascal@20387
|
147 +#define USE_INTERP_RESULT 1\n\
|
pascal@20387
|
148 #include \"tcl.h\"\n\
|
pascal@20387
|
149 -#ifdef _MACOSX_APP_\n\
|
pascal@20387
|
150 -#import <crt_externs.h>\n\
|
pascal@20387
|
151 -#endif\n\
|
pascal@20387
|
152 -#ifdef __WIN32__\n\
|
pascal@20387
|
153 -#define _WIN32_WINNT 0x0500\n\
|
pascal@20387
|
154 -#define WIN32_LEAN_AND_MEAN\n\
|
pascal@20387
|
155 -#include <windows.h>\n\
|
pascal@20387
|
156 -#undef WIN32_LEAN_AND_MEAN\n\
|
pascal@20387
|
157 -#ifndef __MALLOC_H__\n\
|
pascal@20387
|
158 -#include <malloc.h>\n\
|
pascal@20387
|
159 -#endif\n\
|
pascal@20387
|
160 -#include <locale.h>\n\
|
pascal@20387
|
161 -#ifndef __LIBPATH__\n\
|
pascal@20387
|
162 -#define __LIBPATH__ \"lib\"\n\
|
pascal@20387
|
163 -#endif\n\
|
pascal@20387
|
164 -#include <unistd.h>\n\
|
pascal@20387
|
165 -#ifdef _APPLICATION_IS_ROOT_PATH_\n\
|
pascal@20387
|
166 -#include <string.h>\n\
|
pascal@20387
|
167 -#include <limits.h>\n\
|
pascal@20387
|
168 -#include <unistd.h>\n\
|
pascal@20387
|
169 -#endif\n\
|
pascal@20387
|
170 \n\
|
pascal@20387
|
171 -static int setargv _ANSI_ARGS_((char ***argvPtr));\n\
|
pascal@20387
|
172 -static void TclshPanic _ANSI_ARGS_(TCL_VARARGS(char *,format));\n\
|
pascal@20387
|
173 -extern void TclWinInit(HINSTANCE instance);\n\
|
pascal@20387
|
174 -extern int Registry_Init _ANSI_ARGS_((Tcl_Interp *interp));\n\
|
pascal@20387
|
175 -\n\
|
pascal@20387
|
176 -#endif\n\
|
pascal@20387
|
177 -\n\
|
pascal@20387
|
178 /*\n\
|
pascal@20387
|
179 * Defines to replace the standard Xxx_Init calls to Xxx_InitStandAlone.\n\
|
pascal@20387
|
180 * If you don't have this function, just delete the corresponding\n\
|
pascal@20387
|
181 * define such that the normal initialization function is used.\n\
|
pascal@20387
|
182 - * If no Xxx_SafeInit function exists, use NULL pointers instead\n\
|
pascal@20387
|
183 - * by commenting out the appropriate lines below.\n\
|
pascal@20387
|
184 + * Similar: If SafeInit functions exists, you can use these\n\
|
pascal@20387
|
185 + * by commenting out the corresponding lines below.\n\
|
pascal@20387
|
186 */\n\
|
pascal@20387
|
187 \n\
|
pascal@20387
|
188 -#if defined(TCL_ACTIVE) && !defined(SHARED)\n\
|
pascal@20387
|
189 +#ifdef TCL_ACTIVE\n\
|
pascal@20387
|
190 ";
|
pascal@20387
|
191
|
pascal@20387
|
192 -static char *part2 = "\n\
|
pascal@20387
|
193 +static char *part2 = "#endif\n\
|
pascal@20387
|
194 +\n\
|
pascal@20387
|
195 +";
|
pascal@20387
|
196 +
|
pascal@20387
|
197 +static char *part3 = "\n\
|
pascal@20387
|
198 /*\n\
|
pascal@20387
|
199 * Prototypes of all initialization functions and the free() function.\n\
|
pascal@20387
|
200 * So, only \"tcl.h\" needs to be included now.\n\
|
pascal@20387
|
201 @@ -182,27 +120,8 @@
|
pascal@20387
|
202 extern \"C\" {\n\
|
pascal@20387
|
203 #endif\n\
|
pascal@20387
|
204 \n\
|
pascal@20387
|
205 -#ifndef USE_TCLALLOC\n\
|
pascal@20387
|
206 -# define USE_TCLALLOC 0\n\
|
pascal@20387
|
207 -#endif\n\
|
pascal@20387
|
208 -#if USE_TCLALLOC == 0\n\
|
pascal@20387
|
209 extern void free _ANSI_ARGS_((void *));\n\
|
pascal@20387
|
210 -extern VOID *malloc _ANSI_ARGS_((int));\n\
|
pascal@20387
|
211 -#endif\n\
|
pascal@20387
|
212 -extern int Tcl_Init _ANSI_ARGS_((Tcl_Interp *interp));\n\
|
pascal@20387
|
213 -\n\
|
pascal@20387
|
214 ";
|
pascal@20387
|
215 -
|
pascal@20387
|
216 -static char *part3 = "\n\
|
pascal@20387
|
217 -extern void Tk_MainLoop _ANSI_ARGS_((void));\n\
|
pascal@20387
|
218 -#define HAS_TK\n\
|
pascal@20387
|
219 -#ifdef __WIN32__\n\
|
pascal@20387
|
220 -extern void TkWinXInit _ANSI_ARGS_((HINSTANCE hinstance));\n\
|
pascal@20387
|
221 -extern void TkWinXCleanup _ANSI_ARGS_((HINSTANCE hinstance));\n\
|
pascal@20387
|
222 -#endif\n\
|
pascal@20387
|
223 -\n\
|
pascal@20387
|
224 -";
|
pascal@20387
|
225 -
|
pascal@20387
|
226 static char *part4 = "\n\
|
pascal@20387
|
227 #ifdef __cplusplus\n\
|
pascal@20387
|
228 }\n\
|
pascal@20387
|
229 @@ -213,64 +132,10 @@
|
pascal@20387
|
230 * It will be executed in tclAppInit() after the other initializations.\n\
|
pascal@20387
|
231 */\n\
|
pascal@20387
|
232 \n\
|
pascal@20387
|
233 -";
|
pascal@20387
|
234 -
|
pascal@20387
|
235 -static char *part4a = "\
|
pascal@20387
|
236 -static char *lineformat = \"%%.0s%%d\";\n\
|
pascal@20387
|
237 static int line = (__LINE__ + 1);\n\
|
pascal@20387
|
238 ";
|
pascal@20387
|
239
|
pascal@20387
|
240 -static char *part4b = "\
|
pascal@20387
|
241 -static char *lineformat = \"%%s_line%%d\";\n\
|
pascal@20387
|
242 -static int line = 0;\n\
|
pascal@20387
|
243 -";
|
pascal@20387
|
244 -
|
pascal@20387
|
245 static char *part5 = "\
|
pascal@20387
|
246 -#ifdef _APPLICATION_IS_ROOT_PATH_\n\
|
pascal@20387
|
247 -#define PATH_MAX 1024\n\
|
pascal@20387
|
248 -char abs_exe_path[PATH_MAX];\n\
|
pascal@20387
|
249 -char *\n\
|
pascal@20387
|
250 -#ifdef _USING_PROTOTYPES_\n\
|
pascal@20387
|
251 -app_GetPath(\n\
|
pascal@20387
|
252 - int argc,\n\
|
pascal@20387
|
253 - char *argv[])\n\
|
pascal@20387
|
254 -#else\n\
|
pascal@20387
|
255 -app_GetPath(argc, argv)\n\
|
pascal@20387
|
256 - int argc;\n\
|
pascal@20387
|
257 - char *argv[];\n\
|
pascal@20387
|
258 -#endif\n\
|
pascal@20387
|
259 -{\n\
|
pascal@20387
|
260 - char path_save[PATH_MAX];\n\
|
pascal@20387
|
261 - char *p;\n\
|
pascal@20387
|
262 - if(!(p = strrchr(argv[0], '/')))\n\
|
pascal@20387
|
263 - getcwd(abs_exe_path, sizeof(abs_exe_path));\n\
|
pascal@20387
|
264 - else\n\
|
pascal@20387
|
265 - {\n\
|
pascal@20387
|
266 - *p = '\\0';\n\
|
pascal@20387
|
267 - getcwd(path_save, sizeof(path_save));\n\
|
pascal@20387
|
268 - chdir(argv[0]);\n\
|
pascal@20387
|
269 - getcwd(abs_exe_path, sizeof(abs_exe_path));\n\
|
pascal@20387
|
270 - chdir(path_save);\n\
|
pascal@20387
|
271 - }\n\
|
pascal@20387
|
272 - //printf(\"Absolute path to executable is: %s\\n\", abs_exe_path);\n\
|
pascal@20387
|
273 - return abs_exe_path;\n\
|
pascal@20387
|
274 -};\n\
|
pascal@20387
|
275 -#endif\n\
|
pascal@20387
|
276 -#ifdef __WIN32__\n\
|
pascal@20387
|
277 -HWND hConsoleWnd=NULL;\n\
|
pascal@20387
|
278 -int _tcl2c_consoleWOZHideCmd(ClientData clientData, Tcl_Interp *interp, int argc, char **argv) {\n\
|
pascal@20387
|
279 - if (hConsoleWnd==NULL) {hConsoleWnd = GetConsoleWindow();};\n\
|
pascal@20387
|
280 - if (hConsoleWnd==NULL) {return TCL_OK;};\n\
|
pascal@20387
|
281 - SetWindowPos(hConsoleWnd,HWND_NOTOPMOST,0,0,320,240,SWP_HIDEWINDOW);\n\
|
pascal@20387
|
282 - return TCL_OK;\n\
|
pascal@20387
|
283 -};\n\
|
pascal@20387
|
284 -int _tcl2c_consoleWOZShowCmd(ClientData clientData, Tcl_Interp *interp, int argc, char **argv) {\n\
|
pascal@20387
|
285 - if (hConsoleWnd==NULL) {hConsoleWnd = GetConsoleWindow();};\n\
|
pascal@20387
|
286 - if (hConsoleWnd==NULL) {return TCL_OK;};\n\
|
pascal@20387
|
287 - ShowWindow(hConsoleWnd,SW_SHOW);\n\
|
pascal@20387
|
288 - return TCL_OK;\n\
|
pascal@20387
|
289 -};\n\
|
pascal@20387
|
290 -#endif\n\
|
pascal@20387
|
291 /*\n\
|
pascal@20387
|
292 *----------------------------------------------------------------------\n\
|
pascal@20387
|
293 *\n\
|
pascal@20387
|
294 @@ -287,18 +152,7 @@
|
pascal@20387
|
295 *----------------------------------------------------------------------\n\
|
pascal@20387
|
296 */\n\
|
pascal@20387
|
297 \n\
|
pascal@20387
|
298 -#if defined(__WIN32__) && defined(HAS_TK)\n\
|
pascal@20387
|
299 -int APIENTRY\n\
|
pascal@20387
|
300 -WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,\n\
|
pascal@20387
|
301 - LPSTR lpszCmdLine, int nCmdShow)\n\
|
pascal@20387
|
302 -{\n\
|
pascal@20387
|
303 - char **argv;\n\
|
pascal@20387
|
304 - int argc;\n\
|
pascal@20387
|
305 -#else\n\
|
pascal@20387
|
306 -";
|
pascal@20387
|
307 -//MAIN Tcl App
|
pascal@20387
|
308 -static char *part5a = "\
|
pascal@20387
|
309 -int\n\
|
pascal@20387
|
310 +void\n\
|
pascal@20387
|
311 #ifdef _USING_PROTOTYPES_\n\
|
pascal@20387
|
312 main (int argc, /* Number of command-line arguments. */\n\
|
pascal@20387
|
313 char **argv) /* Values of command-line arguments. */\n\
|
pascal@20387
|
314 @@ -308,78 +162,12 @@
|
pascal@20387
|
315 char **argv; /* Values of command-line arguments. */\n\
|
pascal@20387
|
316 #endif\n\
|
pascal@20387
|
317 {\n\
|
pascal@20387
|
318 -#endif\n\
|
pascal@20387
|
319 Tcl_Interp *interp;\n\
|
pascal@20387
|
320 char **p = %s;\n\
|
pascal@20387
|
321 - char *q, buffer[16];\n\
|
pascal@20387
|
322 + char *q, buffer[10];\n\
|
pascal@20387
|
323 Tcl_DString data;\n\
|
pascal@20387
|
324 Tcl_Channel inChannel, outChannel, errChannel;\n\
|
pascal@20387
|
325 \n\
|
pascal@20387
|
326 -#ifdef __LIBPATH__\n\
|
pascal@20387
|
327 - ////char _cwd[1024];\n\
|
pascal@20387
|
328 - char _libpath[2048];\n\
|
pascal@20387
|
329 -#endif\n\
|
pascal@20387
|
330 -#ifdef __WIN32__\n\
|
pascal@20387
|
331 - char argv0[128];\n\
|
pascal@20387
|
332 -#endif\n\
|
pascal@20387
|
333 -#ifdef _MACOSX_APP_\n\
|
pascal@20387
|
334 -argc = *_NSGetArgc();\n\
|
pascal@20387
|
335 -char *progname = *_NSGetProgname();\n\
|
pascal@20387
|
336 -char **envp = *_NSGetEnviron();\n\
|
pascal@20387
|
337 -argv = *_NSGetArgv();\n\
|
pascal@20387
|
338 -#endif\n\
|
pascal@20387
|
339 -#ifdef _APPLICATION_IS_ROOT_PATH_\n\
|
pascal@20387
|
340 - /* GOTO APPLICATION PATH FOR MAC OS*/\n\
|
pascal@20387
|
341 - chdir(app_GetPath(argc, argv));\n\
|
pascal@20387
|
342 -#endif\n\
|
pascal@20387
|
343 -#ifdef __WIN32__\n\
|
pascal@20387
|
344 -#ifdef _CONSOLEWOZHIDE_\n\
|
pascal@20387
|
345 -_tcl2c_consoleWOZHideCmd(NULL, NULL, NULL, (char **) NULL);\n\
|
pascal@20387
|
346 -#endif\n\
|
pascal@20387
|
347 -#if defined(TCL_ACTIVE) && !defined(SHARED) && defined(HAS_TK)\n\
|
pascal@20387
|
348 - TclWinInit(hInstance);\n\
|
pascal@20387
|
349 - TkWinXInit(hInstance);\n\
|
pascal@20387
|
350 - Tcl_CreateExitHandler((Tcl_ExitProc *) TkWinXCleanup, (ClientData) hInstance);\n\
|
pascal@20387
|
351 -#endif\n\
|
pascal@20387
|
352 -\n\
|
pascal@20387
|
353 - Tcl_SetPanicProc(TclshPanic);\n\
|
pascal@20387
|
354 -\n";
|
pascal@20387
|
355 -
|
pascal@20387
|
356 -static char *part5b = "\n\
|
pascal@20387
|
357 - /*\n\
|
pascal@20387
|
358 - * Set up the default locale to be standard \"C\" locale so parsing\n\
|
pascal@20387
|
359 - * is performed correctly.\n\
|
pascal@20387
|
360 - */\n\
|
pascal@20387
|
361 -\n\
|
pascal@20387
|
362 - setlocale(LC_ALL, \"C\");\n\
|
pascal@20387
|
363 -\n\
|
pascal@20387
|
364 - /*\n\
|
pascal@20387
|
365 - * Increase the application queue size from default value of 8.\n\
|
pascal@20387
|
366 - * At the default value, cross application SendMessage of WM_KILLFOCUS\n\
|
pascal@20387
|
367 - * will fail because the handler will not be able to do a PostMessage!\n\
|
pascal@20387
|
368 - * This is only needed for Windows 3.x, since NT dynamically expands\n\
|
pascal@20387
|
369 - * the queue.\n\
|
pascal@20387
|
370 - */\n\
|
pascal@20387
|
371 - SetMessageQueue(64);\n\
|
pascal@20387
|
372 -\n\
|
pascal@20387
|
373 - argc = setargv(&argv);\n\
|
pascal@20387
|
374 -\n\
|
pascal@20387
|
375 - /*\n\
|
pascal@20387
|
376 - * Replace argv[0] with full pathname of executable, and forward\n\
|
pascal@20387
|
377 - * slashes substituted for backslashes.\n\
|
pascal@20387
|
378 - */\n\
|
pascal@20387
|
379 -\n\
|
pascal@20387
|
380 -";
|
pascal@20387
|
381 -static char *part5c = "\
|
pascal@20387
|
382 - GetModuleFileName(NULL, argv0, sizeof(argv0));\n\
|
pascal@20387
|
383 - argv[0] = argv0;\n\
|
pascal@20387
|
384 - for (q = argv0; *q != '\\0'; q++) {\n\
|
pascal@20387
|
385 - if (*q == '\\\\') {\n\
|
pascal@20387
|
386 - *q = '/';\n\
|
pascal@20387
|
387 - }\n\
|
pascal@20387
|
388 - }\n\
|
pascal@20387
|
389 -\n\
|
pascal@20387
|
390 -#endif\n\
|
pascal@20387
|
391 Tcl_FindExecutable(argv[0]);\n\
|
pascal@20387
|
392 interp = Tcl_CreateInterp();\n\
|
pascal@20387
|
393 \n\
|
pascal@20387
|
394 @@ -391,32 +179,8 @@
|
pascal@20387
|
395 Tcl_SetVar(interp, \"argv0\", argv[0],TCL_GLOBAL_ONLY);\n\
|
pascal@20387
|
396 Tcl_SetVar(interp, \"tcl_interactive\",\"0\", TCL_GLOBAL_ONLY);\n\
|
pascal@20387
|
397 \n\
|
pascal@20387
|
398 -#ifdef __LIBPATH__\n\
|
pascal@20387
|
399 - ////chdir(__LIBPATH__);\n\
|
pascal@20387
|
400 - ////getcwd(_cwd,sizeof(_cwd));\n\
|
pascal@20387
|
401 - ////printf(\"libpath:%%s\\n\", _cwd);\n\
|
pascal@20387
|
402 - sprintf(_libpath, \"set env(PWD) [pwd]\");\n\
|
pascal@20387
|
403 - Tcl_Eval(interp, _libpath);\n\
|
pascal@20387
|
404 - sprintf(_libpath, \"%%s/%%s/tcl%%s\", Tcl_GetVar2(interp, \"env\", \"PWD\", TCL_GLOBAL_ONLY),__LIBPATH__, Tcl_GetVar(interp,\"tcl_version\", TCL_GLOBAL_ONLY));\n\
|
pascal@20387
|
405 - Tcl_SetVar2(interp, \"env\", \"TCL_LIBRARY\", _libpath, TCL_GLOBAL_ONLY);\n\
|
pascal@20387
|
406 - Tcl_SetVar2(interp, \"env\", \"TK_LIBRARY\", _libpath, TCL_GLOBAL_ONLY);\n\
|
pascal@20387
|
407 - Tcl_SetVar(interp, \"auto_path\", _libpath, TCL_GLOBAL_ONLY);\n\
|
pascal@20387
|
408 - Tcl_SetVar(interp, \"tcl_libPath\", _libpath, TCL_GLOBAL_ONLY);\n\
|
pascal@20387
|
409 -#endif\n\
|
pascal@20387
|
410 -\n\
|
pascal@20387
|
411 -if (Tcl_Init(interp) != TCL_OK) {\n\
|
pascal@20387
|
412 - goto error;\n\
|
pascal@20387
|
413 - }\n\
|
pascal@20387
|
414 -\n\
|
pascal@20387
|
415 -#ifdef __WIN32__\n\
|
pascal@20387
|
416 - Tcl_StaticPackage((Tcl_Interp *) NULL, \"registry\", Registry_Init,\n\
|
pascal@20387
|
417 - (Tcl_PackageInitProc *) NULL);\n\n\
|
pascal@20387
|
418 - //Create commands _tcl2c_consoleWOZHide and _tcl2c_consoleWOZShow\n\
|
pascal@20387
|
419 - Tcl_CreateCommand(interp, \"_tcl2c_consoleWOZHide\", _tcl2c_consoleWOZHideCmd, NULL, NULL);\n\
|
pascal@20387
|
420 - Tcl_CreateCommand(interp, \"_tcl2c_consoleWOZShow\", _tcl2c_consoleWOZShowCmd, NULL, NULL);\n\n\
|
pascal@20387
|
421 -#endif\n\
|
pascal@20387
|
422 -\n\
|
pascal@20387
|
423 ";
|
pascal@20387
|
424 +
|
pascal@20387
|
425 static char *part6 = "\n\
|
pascal@20387
|
426 /*\n\
|
pascal@20387
|
427 * Execute the script that is compiled in.\n\
|
pascal@20387
|
428 @@ -436,17 +200,27 @@
|
pascal@20387
|
429 }\n\
|
pascal@20387
|
430 line++;\n\
|
pascal@20387
|
431 }\n\
|
pascal@20387
|
432 - sprintf(buffer,lineformat,\"%s\",line);\n\
|
pascal@20387
|
433 - printf(\"ERROR : (line %%s) : %%s\\n\", buffer, Tcl_GetVar(interp, \"errorInfo\", TCL_GLOBAL_ONLY));\n\
|
pascal@20387
|
434 + sprintf(buffer,\"%%d\",line);\n\
|
pascal@20387
|
435 + Tcl_AddErrorInfo(interp,\"\\n ( Error in file: \\\"\");\n\
|
pascal@20387
|
436 + Tcl_AddErrorInfo(interp,__FILE__);\n\
|
pascal@20387
|
437 + Tcl_AddErrorInfo(interp,\"\\\", line: \");\n\
|
pascal@20387
|
438 + Tcl_AddErrorInfo(interp,buffer);\n\
|
pascal@20387
|
439 + Tcl_AddErrorInfo(interp,\")\");\n\
|
pascal@20387
|
440 + errChannel = Tcl_GetStdChannel(TCL_STDERR);\n\
|
pascal@20387
|
441 + if (errChannel) {\n\
|
pascal@20387
|
442 + Tcl_Write(errChannel,\n\
|
pascal@20387
|
443 + Tcl_GetVar(interp, \"errorInfo\", TCL_GLOBAL_ONLY), -1);\n\
|
pascal@20387
|
444 + Tcl_Write(errChannel, \"\\n\", 1);\n\
|
pascal@20387
|
445 + }\n\
|
pascal@20387
|
446 + sprintf(buffer, \"exit %%d\", 1);\n\
|
pascal@20387
|
447 Tcl_Eval(interp, buffer);\n\
|
pascal@20387
|
448 - }};\n\
|
pascal@20387
|
449 -";
|
pascal@20387
|
450 -
|
pascal@20387
|
451 -static char *part6a = "\
|
pascal@20387
|
452 - Tk_MainLoop();\n\
|
pascal@20387
|
453 -";
|
pascal@20387
|
454 -
|
pascal@20387
|
455 -static char *part6b = "\
|
pascal@20387
|
456 + }\n\
|
pascal@20387
|
457 + }\n\
|
pascal@20387
|
458 + Tcl_DStringFree(&data);\n\
|
pascal@20387
|
459 +\n\
|
pascal@20387
|
460 + while (Tcl_DoOneEvent(0)) {\n\
|
pascal@20387
|
461 + /* empty loop body */ ;\n\
|
pascal@20387
|
462 + }\n\
|
pascal@20387
|
463 sprintf(buffer, \"exit %%d\", 0);\n\
|
pascal@20387
|
464 Tcl_Eval(interp, buffer);\n\
|
pascal@20387
|
465 \n\
|
pascal@20387
|
466 @@ -455,185 +229,20 @@
|
pascal@20387
|
467 if (errChannel) {\n\
|
pascal@20387
|
468 Tcl_Write(errChannel,\n\
|
pascal@20387
|
469 \"application-specific initialization failed: \", -1);\n\
|
pascal@20387
|
470 - Tcl_Write(errChannel, Tcl_GetStringResult(interp), -1);\n\
|
pascal@20387
|
471 + Tcl_Write(errChannel, interp->result, -1);\n\
|
pascal@20387
|
472 Tcl_Write(errChannel, \"\\n\", 1);\n\
|
pascal@20387
|
473 }\n\
|
pascal@20387
|
474 -#ifdef __WIN32__\n\
|
pascal@20387
|
475 - TclshPanic(Tcl_GetStringResult(interp));\n\
|
pascal@20387
|
476 -#endif\n\
|
pascal@20387
|
477 sprintf(buffer, \"exit %%d\", 1);\n\
|
pascal@20387
|
478 Tcl_Eval(interp, buffer);\n\
|
pascal@20387
|
479 - return 0;\n\
|
pascal@20387
|
480 }\n\
|
pascal@20387
|
481 -\n\
|
pascal@20387
|
482 -#ifdef __WIN32__\n\
|
pascal@20387
|
483 -/*\n\
|
pascal@20387
|
484 - *----------------------------------------------------------------------\n\
|
pascal@20387
|
485 - *\n\
|
pascal@20387
|
486 - * TclshPanic --\n\
|
pascal@20387
|
487 - *\n\
|
pascal@20387
|
488 - * Display a message and exit.\n\
|
pascal@20387
|
489 - *\n\
|
pascal@20387
|
490 - * Results:\n\
|
pascal@20387
|
491 - * None.\n\
|
pascal@20387
|
492 - *\n\
|
pascal@20387
|
493 - * Side effects:\n\
|
pascal@20387
|
494 - * Exits the program.\n\
|
pascal@20387
|
495 - *\n\
|
pascal@20387
|
496 - *----------------------------------------------------------------------\n\
|
pascal@20387
|
497 - */\n\
|
pascal@20387
|
498 -\n\
|
pascal@20387
|
499 -void\n\
|
pascal@20387
|
500 -TclshPanic TCL_VARARGS_DEF(char *,arg1)\n\
|
pascal@20387
|
501 -{\n\
|
pascal@20387
|
502 - va_list argList;\n\
|
pascal@20387
|
503 - char buf[1024];\n\
|
pascal@20387
|
504 - char *format;\n\
|
pascal@20387
|
505 -\n\
|
pascal@20387
|
506 - format = TCL_VARARGS_START(char *,arg1,argList);\n\
|
pascal@20387
|
507 - vsprintf(buf, format, argList);\n\
|
pascal@20387
|
508 -\n\
|
pascal@20387
|
509 - MessageBeep(MB_ICONEXCLAMATION);\n\
|
pascal@20387
|
510 - MessageBox(NULL, buf, \"Fatal Error in Tclsh\",\n\
|
pascal@20387
|
511 - MB_ICONSTOP | MB_OK | MB_TASKMODAL | MB_SETFOREGROUND);\n\
|
pascal@20387
|
512 -#ifdef _MSC_VER\n\
|
pascal@20387
|
513 - DebugBreak();\n\
|
pascal@20387
|
514 -#endif\n\
|
pascal@20387
|
515 - ExitProcess(1);\n\
|
pascal@20387
|
516 -}\n\
|
pascal@20387
|
517 ";
|
pascal@20387
|
518
|
pascal@20387
|
519 -static char *part6c = "\
|
pascal@20387
|
520 -\n\
|
pascal@20387
|
521 -/*\n\
|
pascal@20387
|
522 - *-------------------------------------------------------------------------\n\
|
pascal@20387
|
523 - *\n\
|
pascal@20387
|
524 - * setargv --\n\
|
pascal@20387
|
525 - *\n\
|
pascal@20387
|
526 - * Parse the Windows command line string into argc/argv. Done here\n\
|
pascal@20387
|
527 - * because we don't trust the builtin argument parser in crt0. \n\
|
pascal@20387
|
528 - * Windows applications are responsible for breaking their command\n\
|
pascal@20387
|
529 - * line into arguments.\n\
|
pascal@20387
|
530 - *\n\
|
pascal@20387
|
531 - * 2N backslashes + quote -> N backslashes + begin quoted string\n\
|
pascal@20387
|
532 - * 2N + 1 backslashes + quote -> literal\n\
|
pascal@20387
|
533 - * N backslashes + non-quote -> literal\n\
|
pascal@20387
|
534 - * quote + quote in a quoted string -> single quote\n\
|
pascal@20387
|
535 - * quote + quote not in quoted string -> empty string\n\
|
pascal@20387
|
536 - * quote -> begin quoted string\n\
|
pascal@20387
|
537 - *\n\
|
pascal@20387
|
538 - * Results:\n\
|
pascal@20387
|
539 - * returns the number of arguments and fill argvPtr with the\n\
|
pascal@20387
|
540 - * array of arguments.\n\
|
pascal@20387
|
541 - *\n\
|
pascal@20387
|
542 - * Side effects:\n\
|
pascal@20387
|
543 - * Memory allocated.\n\
|
pascal@20387
|
544 - *\n\
|
pascal@20387
|
545 - *--------------------------------------------------------------------------\n\
|
pascal@20387
|
546 - */\n\
|
pascal@20387
|
547 -\n\
|
pascal@20387
|
548 -";
|
pascal@20387
|
549 -
|
pascal@20387
|
550 -static char *part6d = "\
|
pascal@20387
|
551 -static int\n\
|
pascal@20387
|
552 -setargv(argvPtr)\n\
|
pascal@20387
|
553 - char ***argvPtr; /* Filled with argument strings (malloc'd). */\n\
|
pascal@20387
|
554 -{\n\
|
pascal@20387
|
555 - char *cmdLine, *p, *arg, *argSpace;\n\
|
pascal@20387
|
556 - char **argv;\n\
|
pascal@20387
|
557 - int argc, size, inquote, copy, slashes;\n\
|
pascal@20387
|
558 -\n\
|
pascal@20387
|
559 - cmdLine = GetCommandLine();\n\
|
pascal@20387
|
560 -\n\
|
pascal@20387
|
561 - /*\n\
|
pascal@20387
|
562 - * Precompute an overly pessimistic guess at the number of arguments\n\
|
pascal@20387
|
563 - * in the command line by counting non-space spans.\n\
|
pascal@20387
|
564 - */\n\
|
pascal@20387
|
565 -\n\
|
pascal@20387
|
566 - size = 2;\n\
|
pascal@20387
|
567 - for (p = cmdLine; *p != '\\0'; p++) {\n\
|
pascal@20387
|
568 - if (isspace(*p)) {\n\
|
pascal@20387
|
569 - size++;\n\
|
pascal@20387
|
570 - while (isspace(*p)) {\n\
|
pascal@20387
|
571 - p++;\n\
|
pascal@20387
|
572 - }\n\
|
pascal@20387
|
573 - if (*p == '\\0') {\n\
|
pascal@20387
|
574 - break;\n\
|
pascal@20387
|
575 - }\n\
|
pascal@20387
|
576 - }\n\
|
pascal@20387
|
577 - }\n\
|
pascal@20387
|
578 - argSpace = (char *) ckalloc((unsigned) (size * sizeof(char *)\n\
|
pascal@20387
|
579 - + strlen(cmdLine) + 1));\n\
|
pascal@20387
|
580 - argv = (char **) argSpace;\n\
|
pascal@20387
|
581 - argSpace += size * sizeof(char *);\n\
|
pascal@20387
|
582 - size--;\n\
|
pascal@20387
|
583 -\n\
|
pascal@20387
|
584 - p = cmdLine;\n\
|
pascal@20387
|
585 - for (argc = 0; argc < size; argc++) {\n\
|
pascal@20387
|
586 - argv[argc] = arg = argSpace;\n\
|
pascal@20387
|
587 - while (isspace(*p)) {\n\
|
pascal@20387
|
588 - p++;\n\
|
pascal@20387
|
589 - }\n\
|
pascal@20387
|
590 - if (*p == '\\0') {\n\
|
pascal@20387
|
591 - break;\n\
|
pascal@20387
|
592 - }\n\
|
pascal@20387
|
593 -\n\
|
pascal@20387
|
594 -";
|
pascal@20387
|
595 -
|
pascal@20387
|
596 -static char *part6e = "\
|
pascal@20387
|
597 - inquote = 0;\n\
|
pascal@20387
|
598 - slashes = 0;\n\
|
pascal@20387
|
599 - while (1) {\n\
|
pascal@20387
|
600 - copy = 1;\n\
|
pascal@20387
|
601 - while (*p == '\\\\') {\n\
|
pascal@20387
|
602 - slashes++;\n\
|
pascal@20387
|
603 - p++;\n\
|
pascal@20387
|
604 - }\n\
|
pascal@20387
|
605 - if (*p == '\"') {\n\
|
pascal@20387
|
606 - if ((slashes & 1) == 0) {\n\
|
pascal@20387
|
607 - copy = 0;\n\
|
pascal@20387
|
608 - if ((inquote) && (p[1] == '\"')) {\n\
|
pascal@20387
|
609 - p++;\n\
|
pascal@20387
|
610 - copy = 1;\n\
|
pascal@20387
|
611 - } else {\n\
|
pascal@20387
|
612 - inquote = !inquote;\n\
|
pascal@20387
|
613 - }\n\
|
pascal@20387
|
614 - }\n\
|
pascal@20387
|
615 - slashes >>= 1;\n\
|
pascal@20387
|
616 - }\n\
|
pascal@20387
|
617 -\n\
|
pascal@20387
|
618 - while (slashes) {\n\
|
pascal@20387
|
619 - *arg = '\\\\';\n\
|
pascal@20387
|
620 - arg++;\n\
|
pascal@20387
|
621 - slashes--;\n\
|
pascal@20387
|
622 - }\n\
|
pascal@20387
|
623 -\n\
|
pascal@20387
|
624 - if ((*p == '\\0') || (!inquote && isspace(*p))) {\n\
|
pascal@20387
|
625 - break;\n\
|
pascal@20387
|
626 - }\n\
|
pascal@20387
|
627 - if (copy != 0) {\n\
|
pascal@20387
|
628 - *arg = *p;\n\
|
pascal@20387
|
629 - arg++;\n\
|
pascal@20387
|
630 - }\n\
|
pascal@20387
|
631 - p++;\n\
|
pascal@20387
|
632 - }\n\
|
pascal@20387
|
633 - *arg = '\\0';\n\
|
pascal@20387
|
634 - argSpace = arg + 1;\n\
|
pascal@20387
|
635 - }\n\
|
pascal@20387
|
636 - argv[argc] = NULL;\n\
|
pascal@20387
|
637 -\n\
|
pascal@20387
|
638 - *argvPtr = argv;\n\
|
pascal@20387
|
639 - return argc;\n\
|
pascal@20387
|
640 -}\n\
|
pascal@20387
|
641 -#endif /* __WIN32__ */\n\
|
pascal@20387
|
642 -";
|
pascal@20387
|
643 -
|
pascal@20387
|
644 -static char *defineproto = "\
|
pascal@20387
|
645 +static char *defineproto1 = "\
|
pascal@20387
|
646 #define %s_Init %s_InitStandAlone\n\
|
pascal@20387
|
647 ";
|
pascal@20387
|
648
|
pascal@20387
|
649 static char *defineproto2 = "\
|
pascal@20387
|
650 -/*#define %s_SafeInit ((Tcl_PackageInitProc *) NULL)*/\n\
|
pascal@20387
|
651 +#define %s_SafeInit (Tcl_PackageInitProc *) NULL\n\
|
pascal@20387
|
652 ";
|
pascal@20387
|
653
|
pascal@20387
|
654 static char *initproto = "\
|
pascal@20387
|
655 @@ -653,9 +262,8 @@
|
pascal@20387
|
656 }\n\
|
pascal@20387
|
657 ";
|
pascal@20387
|
658
|
pascal@20387
|
659 -static char *buffer;
|
pascal@20387
|
660 +static char buffer[32768];
|
pascal@20387
|
661 static unsigned int max_buffer = 0;
|
pascal@20387
|
662 -static unsigned int buffer_size = MAX_STRING_LEN;
|
pascal@20387
|
663 static char max_buffer_content[80];
|
pascal@20387
|
664
|
pascal@20387
|
665 static char array_instead_of_string = 0;
|
pascal@20387
|
666 @@ -663,23 +271,25 @@
|
pascal@20387
|
667
|
pascal@20387
|
668 static char script_name[256];
|
pascal@20387
|
669
|
pascal@20387
|
670 -int printline _ANSI_ARGS_((FILE *f, char *dir, int flags));
|
pascal@20387
|
671 +int printline _ANSI_ARGS_((FILE *f, char *buf, char *dir, int flags));
|
pascal@20387
|
672 int printfile _ANSI_ARGS_((FILE *fout, char *filename, char *dir, int flags));
|
pascal@20387
|
673
|
pascal@20387
|
674 int
|
pascal@20387
|
675 #ifdef _USING_PROTOTYPES_
|
pascal@20387
|
676 printline (
|
pascal@20387
|
677 FILE *f,
|
pascal@20387
|
678 + char *buf,
|
pascal@20387
|
679 char *dir,
|
pascal@20387
|
680 int flags)
|
pascal@20387
|
681 #else
|
pascal@20387
|
682 -printline(f, dir, flags)
|
pascal@20387
|
683 +printline(f,buf,dir,flags)
|
pascal@20387
|
684 FILE *f;
|
pascal@20387
|
685 + char *buf;
|
pascal@20387
|
686 char *dir;
|
pascal@20387
|
687 int flags;
|
pascal@20387
|
688 #endif
|
pascal@20387
|
689 {
|
pascal@20387
|
690 - char *p, *q, *buf = buffer;
|
pascal@20387
|
691 + char *p,*q;
|
pascal@20387
|
692 char path[128];
|
pascal@20387
|
693 unsigned int l;
|
pascal@20387
|
694
|
pascal@20387
|
695 @@ -730,7 +340,7 @@
|
pascal@20387
|
696 *q='}';
|
pascal@20387
|
697 }
|
pascal@20387
|
698 }
|
pascal@20387
|
699 - p = buffer;
|
pascal@20387
|
700 + p = buf;
|
pascal@20387
|
701 while ((p = strstr(p, "[list source [file join $dir")) != NULL) {
|
pascal@20387
|
702 q = strstr(p,".tcl]]");
|
pascal@20387
|
703 if (q != NULL) {
|
pascal@20387
|
704 @@ -805,14 +415,6 @@
|
pascal@20387
|
705 p = q = buffer;
|
pascal@20387
|
706 while ((c=fgetc(fin))!=EOF) {
|
pascal@20387
|
707 *p = 0;
|
pascal@20387
|
708 - if (p + 10 > buffer + buffer_size) {
|
pascal@20387
|
709 - char *new;
|
pascal@20387
|
710 - buffer_size += MAX_STRING_LEN;
|
pascal@20387
|
711 - new = (char *) realloc(buffer, buffer_size);
|
pascal@20387
|
712 - p = new + (p - buffer);
|
pascal@20387
|
713 - q = new + (q - buffer);
|
pascal@20387
|
714 - buffer = new;
|
pascal@20387
|
715 - }
|
pascal@20387
|
716 if (c=='\n') {
|
pascal@20387
|
717 if (!strncmp(buffer,"if {[info exists tk_library] && [string compare $tk_library {}]} {",66)) {
|
pascal@20387
|
718 int flag = 1;
|
pascal@20387
|
719 @@ -823,6 +425,7 @@
|
pascal@20387
|
720 flag--;
|
pascal@20387
|
721 }
|
pascal@20387
|
722 }
|
pascal@20387
|
723 + flag=0;
|
pascal@20387
|
724 p=q=buffer;
|
pascal@20387
|
725 } else if ((p==buffer)||(*q=='\n')||(*q=='#')) {
|
pascal@20387
|
726 if ((*q=='#') && (*(p-1)=='\\')) {
|
pascal@20387
|
727 @@ -833,54 +436,23 @@
|
pascal@20387
|
728 } else {
|
pascal@20387
|
729 *p++ = '\n'; *p=0;
|
pascal@20387
|
730 if (Tcl_CommandComplete(buffer)) {
|
pascal@20387
|
731 - p--; *p = 0; printline(fout,dir,flags);
|
pascal@20387
|
732 + p--; *p = 0; printline(fout,buffer,dir,flags);
|
pascal@20387
|
733 p = q = buffer;
|
pascal@20387
|
734 } else {
|
pascal@20387
|
735 q=p;
|
pascal@20387
|
736 }
|
pascal@20387
|
737 }
|
pascal@20387
|
738 } else {
|
pascal@20387
|
739 - *p++ = (char) c;
|
pascal@20387
|
740 + *p++ = c;
|
pascal@20387
|
741 }
|
pascal@20387
|
742 }
|
pascal@20387
|
743 if (p!=buffer) {
|
pascal@20387
|
744 - *p=0; printline(fout, dir, flags);
|
pascal@20387
|
745 + *p=0; printline(fout,buffer,dir,flags);
|
pascal@20387
|
746 }
|
pascal@20387
|
747 fclose(fin);
|
pascal@20387
|
748 return 0; /* O.K. */
|
pascal@20387
|
749 }
|
pascal@20387
|
750
|
pascal@20387
|
751 -#ifdef _APPLICATION_IS_ROOT_PATH_
|
pascal@20387
|
752 -char abs_exe_path[PATH_MAX];
|
pascal@20387
|
753 -char *
|
pascal@20387
|
754 -#ifdef _USING_PROTOTYPES_
|
pascal@20387
|
755 -app_GetPath(
|
pascal@20387
|
756 - int argc,
|
pascal@20387
|
757 - char *argv[])
|
pascal@20387
|
758 -#else
|
pascal@20387
|
759 -app_GetPath(argc, argv)
|
pascal@20387
|
760 - int argc;
|
pascal@20387
|
761 - char *argv[];
|
pascal@20387
|
762 -#endif
|
pascal@20387
|
763 -{
|
pascal@20387
|
764 - char path_save[PATH_MAX];
|
pascal@20387
|
765 - char *p;
|
pascal@20387
|
766 - if(!(p = strrchr(argv[0], '/')))
|
pascal@20387
|
767 - getcwd(abs_exe_path, sizeof(abs_exe_path));
|
pascal@20387
|
768 - else
|
pascal@20387
|
769 - {
|
pascal@20387
|
770 - *p = '\0';
|
pascal@20387
|
771 - getcwd(path_save, sizeof(path_save));
|
pascal@20387
|
772 - chdir(argv[0]);
|
pascal@20387
|
773 - getcwd(abs_exe_path, sizeof(abs_exe_path));
|
pascal@20387
|
774 - chdir(path_save);
|
pascal@20387
|
775 - }
|
pascal@20387
|
776 - //printf("Absolute path to executable is: %s\n", abs_exe_path);
|
pascal@20387
|
777 - return abs_exe_path;
|
pascal@20387
|
778 -};
|
pascal@20387
|
779 -#endif
|
pascal@20387
|
780 -
|
pascal@20387
|
781 -/* MAIN */
|
pascal@20387
|
782 int
|
pascal@20387
|
783 #ifdef _USING_PROTOTYPES_
|
pascal@20387
|
784 main (
|
pascal@20387
|
785 @@ -898,11 +470,6 @@
|
pascal@20387
|
786 tableitem *t;
|
pascal@20387
|
787 int c,i, flags=0;
|
pascal@20387
|
788
|
pascal@20387
|
789 -#ifdef _APPLICATION_IS_ROOT_PATH_
|
pascal@20387
|
790 - /* GOTO APPLICATION PATH */
|
pascal@20387
|
791 - chdir(app_GetPath(argc, argv));
|
pascal@20387
|
792 -#endif
|
pascal@20387
|
793 -
|
pascal@20387
|
794 if (argc==1) {
|
pascal@20387
|
795 printf(verbose);
|
pascal@20387
|
796 exit(0);
|
pascal@20387
|
797 @@ -921,6 +488,8 @@
|
pascal@20387
|
798 i++; strcpy(script_name,argv[i]);
|
pascal@20387
|
799 } else if (!strcmp(argv[i],"-o")) {
|
pascal@20387
|
800 i++; filename = argv[i];
|
pascal@20387
|
801 + } else if (!strcmp(argv[i],"-index")) {
|
pascal@20387
|
802 + flags = -1;
|
pascal@20387
|
803 } else {
|
pascal@20387
|
804 for (t=table;t<table+(sizeof(table)/sizeof(tableitem));t++) {
|
pascal@20387
|
805 if (!strcmp(argv[i],t->option)) {
|
pascal@20387
|
806 @@ -950,61 +519,41 @@
|
pascal@20387
|
807 p = q+1;
|
pascal@20387
|
808 }
|
pascal@20387
|
809 strcpy(script_name,p);
|
pascal@20387
|
810 - q = script_name;
|
pascal@20387
|
811 - while (*q) {
|
pascal@20387
|
812 - if (*q == '.') {
|
pascal@20387
|
813 - *q = '_';
|
pascal@20387
|
814 - } else if (isupper(*q)) {
|
pascal@20387
|
815 - *q = tolower(*q);
|
pascal@20387
|
816 - }
|
pascal@20387
|
817 - q++;
|
pascal@20387
|
818 - }
|
pascal@20387
|
819 while ((q = strchr(script_name,'.')) != NULL) {
|
pascal@20387
|
820 *q = '_';
|
pascal@20387
|
821 }
|
pascal@20387
|
822 /* create prototypes for all initialization functions that are used */
|
pascal@20387
|
823 - if (flags) {
|
pascal@20387
|
824 + if (flags && (flags != -1)) {
|
pascal@20387
|
825 if (script_name[0] == 0) {
|
pascal@20387
|
826 strcpy(script_name,"script");
|
pascal@20387
|
827 }
|
pascal@20387
|
828 fprintf(fout, part1);
|
pascal@20387
|
829 for (i=0,c=1;i<(sizeof(table)/sizeof(tableitem));i++,c<<=1) {
|
pascal@20387
|
830 if (flags & c) {
|
pascal@20387
|
831 - fprintf(fout,defineproto,table[i].package,
|
pascal@20387
|
832 + fprintf(fout,defineproto1,table[i].package,
|
pascal@20387
|
833 table[i].package);
|
pascal@20387
|
834 }
|
pascal@20387
|
835 }
|
pascal@20387
|
836 - fprintf(fout, "#endif\n\n");
|
pascal@20387
|
837 - for (i=1,c=2;i<(sizeof(table)/sizeof(tableitem));i++,c<<=1) {
|
pascal@20387
|
838 + fprintf(fout, part2);
|
pascal@20387
|
839 + for (i=0,c=1;i<(sizeof(table)/sizeof(tableitem));i++,c<<=1) {
|
pascal@20387
|
840 if (flags & c) {
|
pascal@20387
|
841 fprintf(fout,defineproto2,table[i].package);
|
pascal@20387
|
842 }
|
pascal@20387
|
843 }
|
pascal@20387
|
844 - fprintf(fout, part2);
|
pascal@20387
|
845 -
|
pascal@20387
|
846 - if (flags & 2) {
|
pascal@20387
|
847 fprintf(fout, part3);
|
pascal@20387
|
848 - }
|
pascal@20387
|
849 - for (i=1,c=2;i<(sizeof(table)/sizeof(tableitem));i++,c<<=1) {
|
pascal@20387
|
850 + for (i=0,c=1;i<(sizeof(table)/sizeof(tableitem));i++,c<<=1) {
|
pascal@20387
|
851 if (flags & c) {
|
pascal@20387
|
852 fprintf(fout,initproto,table[i].package,
|
pascal@20387
|
853 table[i].package,table[i].package);
|
pascal@20387
|
854 }
|
pascal@20387
|
855 }
|
pascal@20387
|
856 fprintf(fout, part4, script_name);
|
pascal@20387
|
857 - if (array_instead_of_string) {
|
pascal@20387
|
858 - fprintf(fout, part4b);
|
pascal@20387
|
859 - } else {
|
pascal@20387
|
860 - fprintf(fout, part4a);
|
pascal@20387
|
861 }
|
pascal@20387
|
862 - }
|
pascal@20387
|
863 if ( !array_instead_of_string && script_name[0]) {
|
pascal@20387
|
864 fprintf(fout, "static char *%s[] = {\n", script_name);
|
pascal@20387
|
865 }
|
pascal@20387
|
866 /* handle all remaining arguments */
|
pascal@20387
|
867 if (argc) {argc--; argv++;}
|
pascal@20387
|
868 - buffer = (char *) malloc(4*MAX_STRING_LEN);
|
pascal@20387
|
869 - buffer_size = 4*MAX_STRING_LEN;
|
pascal@20387
|
870 while(argc) {
|
pascal@20387
|
871 if ((*argv)[0]=='-') {
|
pascal@20387
|
872 if ((((*argv)[1]=='o')||((*argv)[1]=='n'))&&((*argv)[2]==0)) {
|
pascal@20387
|
873 @@ -1021,7 +570,6 @@
|
pascal@20387
|
874 }
|
pascal@20387
|
875 argc--; argv++;
|
pascal@20387
|
876 }
|
pascal@20387
|
877 - free(buffer);
|
pascal@20387
|
878 if ( array_instead_of_string ) {
|
pascal@20387
|
879 fprintf(fout, "static char *%s[] = {\n", script_name);
|
pascal@20387
|
880 for (i = 0; (unsigned int)i < num_lines;)
|
pascal@20387
|
881 @@ -1031,39 +579,34 @@
|
pascal@20387
|
882 fprintf(fout, "(char *) NULL\n};\n\n");
|
pascal@20387
|
883 }
|
pascal@20387
|
884 /* end of scripts, finally the functions main() and tclAppInit() */
|
pascal@20387
|
885 - if (flags) {
|
pascal@20387
|
886 + if (flags && (flags != -1)) {
|
pascal@20387
|
887 fprintf(fout, part5, script_name);
|
pascal@20387
|
888 - fprintf(fout, part5a, script_name);
|
pascal@20387
|
889 - fprintf(fout, part5b);
|
pascal@20387
|
890 - fprintf(fout, part5c);
|
pascal@20387
|
891 - for (i=1,c=2;i<(sizeof(table)/sizeof(tableitem));i++,c<<=1) {
|
pascal@20387
|
892 - if (flags & c) {
|
pascal@20387
|
893 - fprintf(fout,callinit,table[i].package);
|
pascal@20387
|
894 + fprintf(fout,callinit,table[0].package);
|
pascal@20387
|
895 + if (flags & 0x20) {
|
pascal@20387
|
896 + fprintf(fout,callinit,table[5].package);
|
pascal@20387
|
897 + }
|
pascal@20387
|
898 + for (i=0,c=1;i<(sizeof(table)/sizeof(tableitem));i++,c<<=1) {
|
pascal@20387
|
899 + if ((flags & c) && (i!=0))
|
pascal@20387
|
900 fprintf(fout,packageproto,table[i].package,table[i].package,table[i].package);
|
pascal@20387
|
901 }
|
pascal@20387
|
902 + for (i=0,c=1;i<(sizeof(table)/sizeof(tableitem));i++,c<<=1) {
|
pascal@20387
|
903 + if ((flags & c) && (i!=0) && (i!=5))
|
pascal@20387
|
904 + fprintf(fout,callinit,table[i].package);
|
pascal@20387
|
905 }
|
pascal@20387
|
906 p=filename?filename:"app";
|
pascal@20387
|
907 if ((q=strrchr(p,'/')) != NULL) p=q+1;
|
pascal@20387
|
908 if ((q=strchr(p,'.')) != NULL) *q=0;
|
pascal@20387
|
909 if (!*p) p="app";
|
pascal@20387
|
910 - fprintf(fout, part6,script_name,script_name,p,p);
|
pascal@20387
|
911 - if (flags & 2) {
|
pascal@20387
|
912 - fprintf(fout, part6a);
|
pascal@20387
|
913 + fprintf(fout, part6,script_name,p,p);
|
pascal@20387
|
914 }
|
pascal@20387
|
915 - fprintf(fout, part6b);
|
pascal@20387
|
916 - fprintf(fout, part6c);
|
pascal@20387
|
917 - fprintf(fout, part6d);
|
pascal@20387
|
918 - fprintf(fout, part6e);
|
pascal@20387
|
919 - }
|
pascal@20387
|
920 /* close output-file, if not stdout */
|
pascal@20387
|
921 if (fout!=stdout) {
|
pascal@20387
|
922 fclose(fout);
|
pascal@20387
|
923 }
|
pascal@20387
|
924 if (max_buffer>MAX_STRING_LEN) {
|
pascal@20387
|
925 - fprintf(stderr,"warning: largest sting in output file is %d bytes\n\
|
pascal@20387
|
926 + fprintf(stderr,"warning: largest string in output file is %d bytes\n\
|
pascal@20387
|
927 many compilers can only handle %d characters in a string\n\
|
pascal@20387
|
928 first line: %s\n",max_buffer,MAX_STRING_LEN,max_buffer_content);
|
pascal@20387
|
929 }
|
pascal@20387
|
930 exit(0);
|
pascal@20387
|
931 - return 0;
|
pascal@20387
|
932 }
|