| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#include <tk.h> |
| 17 |
#include "tixInt.h" |
| 18 |
#define WIN32_LEAN_AND_MEAN |
| 19 |
#include <windows.h> |
| 20 |
#undef WIN32_LEAN_AND_MEAN |
| 21 |
#include <malloc.h> |
| 22 |
#include <locale.h> |
| 23 |
|
| 24 |
#ifdef ITCL_2 |
| 25 |
#include "itcl.h" |
| 26 |
#include "itk.h" |
| 27 |
#endif |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
void TkConsoleCreate _ANSI_ARGS_((void)); |
| 34 |
int TkConsoleInit _ANSI_ARGS_((Tcl_Interp *interp)); |
| 35 |
void TkConsolePrint _ANSI_ARGS_((Tcl_Interp *interp, |
| 36 |
int devId, char *buffer, long size)); |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
static void WishPanic _ANSI_ARGS_(TCL_VARARGS(char *,format)); |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
int APIENTRY |
| 63 |
WinMain(hInstance, hPrevInstance, lpszCmdLine, nCmdShow) |
| 64 |
HINSTANCE hInstance; |
| 65 |
HINSTANCE hPrevInstance; |
| 66 |
LPSTR lpszCmdLine; |
| 67 |
int nCmdShow; |
| 68 |
{ |
| 69 |
char **argv, **argvlist, *p; |
| 70 |
int argc, size, i; |
| 71 |
char buffer[MAX_PATH]; |
| 72 |
|
| 73 |
Tcl_SetPanicProc(WishPanic); |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
SetMessageQueue(64); |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
for (size = 3, p = lpszCmdLine; *p != '\0'; p++) { |
| 92 |
if (isspace(*p)) { |
| 93 |
size++; |
| 94 |
while (isspace(*p)) { |
| 95 |
p++; |
| 96 |
} |
| 97 |
if (*p == '\0') { |
| 98 |
break; |
| 99 |
} |
| 100 |
} |
| 101 |
} |
| 102 |
argvlist = (char **) ckalloc((unsigned) (size * sizeof(char *))); |
| 103 |
argv = argvlist; |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
for (i = 1, p = lpszCmdLine; *p != '\0'; i++) { |
| 113 |
while (isspace(*p)) { |
| 114 |
p++; |
| 115 |
} |
| 116 |
if (*p == '\0') { |
| 117 |
break; |
| 118 |
} |
| 119 |
if (*p == '"') { |
| 120 |
p++; |
| 121 |
argv[i] = p; |
| 122 |
while ((*p != '\0') && (*p != '"')) { |
| 123 |
p++; |
| 124 |
} |
| 125 |
} else { |
| 126 |
argv[i] = p; |
| 127 |
while (*p != '\0' && !isspace(*p)) { |
| 128 |
p++; |
| 129 |
} |
| 130 |
} |
| 131 |
if (*p != '\0') { |
| 132 |
*p = '\0'; |
| 133 |
p++; |
| 134 |
} |
| 135 |
} |
| 136 |
argv[i] = NULL; |
| 137 |
argc = i; |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
GetModuleFileName(NULL, buffer, sizeof(buffer)); |
| 145 |
argv[0] = buffer; |
| 146 |
|
| 147 |
Tk_Main(argc, argv, Tcl_AppInit); |
| 148 |
return 1; |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
int |
| 172 |
Tcl_AppInit(interp) |
| 173 |
Tcl_Interp *interp; |
| 174 |
{ |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
setlocale(LC_ALL, "C"); |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
SetMessageQueue(64); |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
TkConsoleCreate(); |
| 197 |
|
| 198 |
if (Tcl_Init(interp) == TCL_ERROR) { |
| 199 |
if (Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY)) { |
| 200 |
MessageBox(NULL, Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY), |
| 201 |
"Tcl Init Error", MB_OK|MB_ICONSTOP); |
| 202 |
} else { |
| 203 |
MessageBox(NULL, interp->result, "Tcl Init Error", |
| 204 |
MB_OK|MB_ICONSTOP ); |
| 205 |
} |
| 206 |
return TCL_ERROR; |
| 207 |
} |
| 208 |
|
| 209 |
if (Tk_Init(interp) == TCL_ERROR) { |
| 210 |
if (Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY)) { |
| 211 |
MessageBox(NULL, Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY), |
| 212 |
"Tk Init Error", MB_OK|MB_ICONSTOP); |
| 213 |
} else { |
| 214 |
MessageBox(NULL, interp->result, "Tk Init Error", |
| 215 |
MB_OK|MB_ICONSTOP); |
| 216 |
} |
| 217 |
return TCL_ERROR; |
| 218 |
} |
| 219 |
Tcl_StaticPackage(interp, "Tk", Tk_Init, (Tcl_PackageInitProc *) NULL); |
| 220 |
|
| 221 |
#ifdef ITCL_2 |
| 222 |
if (Itcl_Init(interp) == TCL_ERROR) { |
| 223 |
if (Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY)) { |
| 224 |
MessageBox(NULL, Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY), |
| 225 |
"Itcl Init Error", MB_OK|MB_ICONSTOP); |
| 226 |
} else { |
| 227 |
MessageBox(NULL, interp->result, "Itcl Init Error", |
| 228 |
MB_OK|MB_ICONSTOP); |
| 229 |
} |
| 230 |
return TCL_ERROR; |
| 231 |
} |
| 232 |
Tcl_StaticPackage(interp, "Itcl", Itcl_Init, (Tcl_PackageInitProc *) NULL); |
| 233 |
|
| 234 |
if (Itk_Init(interp) == TCL_ERROR) { |
| 235 |
if (Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY)) { |
| 236 |
MessageBox(NULL, Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY), |
| 237 |
"Itk Init Error", MB_OK|MB_ICONSTOP); |
| 238 |
} else { |
| 239 |
MessageBox(NULL, interp->result, "Itk Init Error", |
| 240 |
MB_OK|MB_ICONSTOP); |
| 241 |
} |
| 242 |
return TCL_ERROR; |
| 243 |
} |
| 244 |
Tcl_StaticPackage(interp, "Itk", Itk_Init, (Tcl_PackageInitProc *) NULL); |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
if (Tcl_Import(interp, Tcl_GetGlobalNamespace(interp), |
| 253 |
"::itcl::*", 1) != TCL_OK) { |
| 254 |
return TCL_ERROR; |
| 255 |
} |
| 256 |
|
| 257 |
if (Tcl_Eval(interp, "auto_mkindex_parser::slavehook { _%@namespace import -force ::itcl::* }") != TCL_OK) { |
| 258 |
return TCL_ERROR; |
| 259 |
} |
| 260 |
|
| 261 |
#endif |
| 262 |
|
| 263 |
if (Tix_Init(interp) == TCL_ERROR) { |
| 264 |
if (Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY)) { |
| 265 |
MessageBox(NULL, Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY), |
| 266 |
"Tix Init Error", MB_OK|MB_ICONSTOP); |
| 267 |
} else { |
| 268 |
MessageBox(NULL, interp->result, "Tix Init Error", |
| 269 |
MB_OK|MB_ICONSTOP); |
| 270 |
} |
| 271 |
return TCL_ERROR; |
| 272 |
} |
| 273 |
Tcl_StaticPackage(interp, "Tix", Tix_Init, (Tcl_PackageInitProc *) NULL); |
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
if (strcmp(Tcl_GetVar(interp, "tcl_interactive", TCL_GLOBAL_ONLY), "1") |
| 281 |
== 0) { |
| 282 |
if (TkConsoleInit(interp) == TCL_ERROR) { |
| 283 |
return TCL_ERROR; |
| 284 |
} |
| 285 |
} |
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
return TCL_OK; |
| 290 |
} |
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
void |
| 309 |
WishPanic TCL_VARARGS_DEF(char *,arg1) |
| 310 |
{ |
| 311 |
va_list argList; |
| 312 |
char buf[1024]; |
| 313 |
char *format; |
| 314 |
|
| 315 |
format = TCL_VARARGS_START(char *,arg1,argList); |
| 316 |
vsprintf(buf, format, argList); |
| 317 |
|
| 318 |
MessageBeep(MB_ICONEXCLAMATION); |
| 319 |
MessageBox(NULL, buf, "Fatal Error in Wish", |
| 320 |
MB_ICONSTOP | MB_OK | MB_TASKMODAL | MB_SETFOREGROUND); |
| 321 |
ExitProcess(1); |
| 322 |
} |
| 323 |
|