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