| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
#include <bltInt.h> |
| 30 |
#include <bltTile.h> |
| 31 |
|
| 32 |
#define EXACT 1 |
| 33 |
|
| 34 |
#ifndef BLT_LIBRARY |
| 35 |
#ifdef WIN32 |
| 36 |
#define BLT_LIBRARY "c:/Program Files/Tcl/lib/blt"##BLT_VERSION |
| 37 |
#else |
| 38 |
#define BLT_LIBRARY "unknown" |
| 39 |
#endif |
| 40 |
#endif |
| 41 |
|
| 42 |
#define BLT_THREAD_KEY "BLT Initialized" |
| 43 |
#define BLT_TCL_CMDS (1<<0) |
| 44 |
#define BLT_TK_CMDS (1<<1) |
| 45 |
|
| 46 |
double bltNaN; |
| 47 |
#if (TCL_MAJOR_VERSION > 7) |
| 48 |
#endif |
| 49 |
|
| 50 |
static Tcl_MathProc MinMathProc, MaxMathProc; |
| 51 |
static char libPath[1024] = |
| 52 |
{ |
| 53 |
BLT_LIBRARY |
| 54 |
}; |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
static char initScript[] = |
| 88 |
{"\n\ |
| 89 |
global blt_library blt_libPath blt_version tcl_library env\n\ |
| 90 |
set blt_library {}\n\ |
| 91 |
set path {}\n\ |
| 92 |
foreach var { env(BLT_LIBRARY) blt_libPath tcl_library env(TCL_LIBRARY) } { \n\ |
| 93 |
if { ![info exists $var] } { \n\ |
| 94 |
continue \n\ |
| 95 |
} \n\ |
| 96 |
set path [set $var] \n\ |
| 97 |
if { [file readable [file join $path bltGraph.pro]] } { \n\ |
| 98 |
set blt_library $path\n\ |
| 99 |
break \n\ |
| 100 |
} \n\ |
| 101 |
set path [file join $path blt$blt_version ] \n\ |
| 102 |
if { [file readable [file join $path bltGraph.pro]] } { \n\ |
| 103 |
set blt_library $path\n\ |
| 104 |
break \n\ |
| 105 |
} \n\ |
| 106 |
set path [file dirname [set $var]] \n\ |
| 107 |
if { [file readable [file join $path bltGraph.pro]] } { \n\ |
| 108 |
set blt_library $path\n\ |
| 109 |
break \n\ |
| 110 |
} \n\ |
| 111 |
set path [file join $path blt$blt_version ] \n\ |
| 112 |
if { [file readable [file join $path bltGraph.pro]] } { \n\ |
| 113 |
set blt_library $path\n\ |
| 114 |
break \n\ |
| 115 |
} \n\ |
| 116 |
} \n\ |
| 117 |
if { $blt_library != \"\" } { \n\ |
| 118 |
global auto_path \n\ |
| 119 |
lappend auto_path $blt_library \n\ |
| 120 |
if { [file exists [file join $blt_library init.tcl]] } {\n\ |
| 121 |
source [file join $blt_library init.tcl]\n\ |
| 122 |
}\n\ |
| 123 |
}\n\ |
| 124 |
unset var path\n\ |
| 125 |
\n" |
| 126 |
}; |
| 127 |
|
| 128 |
|
| 129 |
static Tcl_AppInitProc *tclCmds[] = |
| 130 |
{ |
| 131 |
#ifndef NO_BGEXEC |
| 132 |
Blt_BgexecInit, |
| 133 |
#endif |
| 134 |
#ifndef NO_DEBUG |
| 135 |
Blt_DebugInit, |
| 136 |
#endif |
| 137 |
#ifndef NO_WATCH |
| 138 |
Blt_WatchInit, |
| 139 |
#endif |
| 140 |
#ifndef NO_VECTOR |
| 141 |
Blt_VectorInit, |
| 142 |
#endif |
| 143 |
#ifndef NO_SPLINE |
| 144 |
Blt_SplineInit, |
| 145 |
#endif |
| 146 |
#ifndef NO_TREE |
| 147 |
Blt_TreeInit, |
| 148 |
#endif |
| 149 |
#ifndef NO_DDE |
| 150 |
Blt_DdeInit, |
| 151 |
#endif |
| 152 |
#ifndef NO_CRC32 |
| 153 |
Blt_Crc32Init, |
| 154 |
#endif |
| 155 |
(Tcl_AppInitProc *) NULL |
| 156 |
}; |
| 157 |
|
| 158 |
#ifndef TCL_ONLY |
| 159 |
static Tcl_AppInitProc *tkCmds[] = |
| 160 |
{ |
| 161 |
#ifndef NO_GRAPH |
| 162 |
Blt_GraphInit, |
| 163 |
#endif |
| 164 |
#ifndef NO_TABLE |
| 165 |
Blt_TableInit, |
| 166 |
#endif |
| 167 |
#ifndef NO_HIERBOX |
| 168 |
Blt_HierboxInit, |
| 169 |
#endif |
| 170 |
#ifndef NO_TABSET |
| 171 |
Blt_TabsetInit, |
| 172 |
#endif |
| 173 |
#ifndef NO_TABNOTEBOOK |
| 174 |
Blt_TabnotebookInit, |
| 175 |
#endif |
| 176 |
#ifndef NO_HTEXT |
| 177 |
Blt_HtextInit, |
| 178 |
#endif |
| 179 |
#ifndef NO_BUSY |
| 180 |
Blt_BusyInit, |
| 181 |
#endif |
| 182 |
#ifndef NO_WINOP |
| 183 |
Blt_WinopInit, |
| 184 |
#endif |
| 185 |
#ifndef NO_BITMAP |
| 186 |
Blt_BitmapInit, |
| 187 |
#endif |
| 188 |
#ifndef NO_DRAGDROP |
| 189 |
Blt_DragDropInit, |
| 190 |
#endif |
| 191 |
#ifndef NO_DND |
| 192 |
Blt_DndInit, |
| 193 |
#endif |
| 194 |
#ifndef NO_CONTAINER |
| 195 |
Blt_ContainerInit, |
| 196 |
#endif |
| 197 |
#ifndef NO_BELL |
| 198 |
Blt_BeepInit, |
| 199 |
#endif |
| 200 |
#ifndef NO_CUTBUFFER |
| 201 |
Blt_CutbufferInit, |
| 202 |
#endif |
| 203 |
#ifndef NO_PRINTER |
| 204 |
Blt_PrinterInit, |
| 205 |
#endif |
| 206 |
#ifndef NO_TILEFRAME |
| 207 |
Blt_FrameInit, |
| 208 |
#endif |
| 209 |
#ifndef NO_TILEBUTTON |
| 210 |
Blt_ButtonInit, |
| 211 |
#endif |
| 212 |
#ifndef NO_TILESCROLLBAR |
| 213 |
Blt_ScrollbarInit, |
| 214 |
#endif |
| 215 |
#ifndef NO_TREEVIEW |
| 216 |
Blt_TreeViewInit, |
| 217 |
#endif |
| 218 |
#if (BLT_MAJOR_VERSION == 3) |
| 219 |
#ifndef NO_MOUNTAIN |
| 220 |
Blt_MountainInit, |
| 221 |
#endif |
| 222 |
#endif |
| 223 |
#ifndef NO_TED |
| 224 |
Blt_TedInit, |
| 225 |
#endif |
| 226 |
(Tcl_AppInitProc *) NULL |
| 227 |
}; |
| 228 |
#endif |
| 229 |
|
| 230 |
#ifdef WIN32 |
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
BOOL APIENTRY |
| 248 |
DllMain( |
| 249 |
HINSTANCE hInst, |
| 250 |
DWORD reason, |
| 251 |
LPVOID reserved) |
| 252 |
{ |
| 253 |
return TRUE; |
| 254 |
} |
| 255 |
|
| 256 |
#ifndef STATIC_BUILD |
| 257 |
BOOL APIENTRY |
| 258 |
DllEntryPoint(hInst, reason, reserved) |
| 259 |
HINSTANCE hInst; |
| 260 |
DWORD reason; |
| 261 |
LPVOID reserved; |
| 262 |
{ |
| 263 |
return DllMain(hInst, reason, reserved); |
| 264 |
} |
| 265 |
#endif |
| 266 |
#endif |
| 267 |
|
| 268 |
|
| 269 |
#ifdef __BORLANDC__ |
| 270 |
static double |
| 271 |
MakeNaN(void) |
| 272 |
{ |
| 273 |
union Real { |
| 274 |
struct DoubleWord { |
| 275 |
int lo, hi; |
| 276 |
} doubleWord; |
| 277 |
double number; |
| 278 |
} real; |
| 279 |
|
| 280 |
real.doubleWord.lo = real.doubleWord.hi = 0x7FFFFFFF; |
| 281 |
return real.number; |
| 282 |
} |
| 283 |
#endif |
| 284 |
|
| 285 |
#ifdef _MSC_VER |
| 286 |
static double |
| 287 |
MakeNaN(void) |
| 288 |
{ |
| 289 |
return sqrt(-1.0); |
| 290 |
} |
| 291 |
#endif |
| 292 |
|
| 293 |
#if !defined(__BORLANDC__) && !defined(_MSC_VER) |
| 294 |
static double |
| 295 |
MakeNaN(void) |
| 296 |
{ |
| 297 |
return 0.0 / 0.0; |
| 298 |
} |
| 299 |
#endif |
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
static int |
| 304 |
MinMathProc(clientData, interp, argsPtr, resultPtr) |
| 305 |
ClientData clientData; |
| 306 |
Tcl_Interp *interp; |
| 307 |
Tcl_Value *argsPtr; |
| 308 |
Tcl_Value *resultPtr; |
| 309 |
{ |
| 310 |
Tcl_Value *op1Ptr, *op2Ptr; |
| 311 |
|
| 312 |
op1Ptr = argsPtr, op2Ptr = argsPtr + 1; |
| 313 |
if ((op1Ptr->type == TCL_INT) && (op2Ptr->type == TCL_INT)) { |
| 314 |
resultPtr->intValue = MIN(op1Ptr->intValue, op2Ptr->intValue); |
| 315 |
resultPtr->type = TCL_INT; |
| 316 |
} else { |
| 317 |
double a, b; |
| 318 |
|
| 319 |
a = (op1Ptr->type == TCL_INT) |
| 320 |
? (double)op1Ptr->intValue : op1Ptr->doubleValue; |
| 321 |
b = (op2Ptr->type == TCL_INT) |
| 322 |
? (double)op2Ptr->intValue : op2Ptr->doubleValue; |
| 323 |
resultPtr->doubleValue = MIN(a, b); |
| 324 |
resultPtr->type = TCL_DOUBLE; |
| 325 |
} |
| 326 |
return TCL_OK; |
| 327 |
} |
| 328 |
|
| 329 |
|
| 330 |
static int |
| 331 |
MaxMathProc(clientData, interp, argsPtr, resultPtr) |
| 332 |
ClientData clientData; |
| 333 |
Tcl_Interp *interp; |
| 334 |
Tcl_Value *argsPtr; |
| 335 |
Tcl_Value *resultPtr; |
| 336 |
{ |
| 337 |
Tcl_Value *op1Ptr, *op2Ptr; |
| 338 |
|
| 339 |
op1Ptr = argsPtr, op2Ptr = argsPtr + 1; |
| 340 |
if ((op1Ptr->type == TCL_INT) && (op2Ptr->type == TCL_INT)) { |
| 341 |
resultPtr->intValue = MAX(op1Ptr->intValue, op2Ptr->intValue); |
| 342 |
resultPtr->type = TCL_INT; |
| 343 |
} else { |
| 344 |
double a, b; |
| 345 |
|
| 346 |
a = (op1Ptr->type == TCL_INT) |
| 347 |
? (double)op1Ptr->intValue : op1Ptr->doubleValue; |
| 348 |
b = (op2Ptr->type == TCL_INT) |
| 349 |
? (double)op2Ptr->intValue : op2Ptr->doubleValue; |
| 350 |
resultPtr->doubleValue = MAX(a, b); |
| 351 |
resultPtr->type = TCL_DOUBLE; |
| 352 |
} |
| 353 |
return TCL_OK; |
| 354 |
} |
| 355 |
|
| 356 |
#ifndef TCL_ONLY |
| 357 |
void |
| 358 |
Blt_TileRectangleOrigin( |
| 359 |
Tk_Window tkwin, |
| 360 |
Drawable drawable, |
| 361 |
ClientData tilePtr, |
| 362 |
int x, int y, |
| 363 |
unsigned int width, |
| 364 |
unsigned int height, |
| 365 |
int xofs, int yofs, int flags) |
| 366 |
{ |
| 367 |
|
| 368 |
if (flags&1) { |
| 369 |
Blt_SetTSOrigin(tkwin, tilePtr, xofs, yofs); |
| 370 |
} else if (flags&2) { |
| 371 |
Blt_SetTileOrigin(tkwin, tilePtr, xofs, yofs); |
| 372 |
} else { |
| 373 |
Blt_SetTileOrigin(tkwin, tilePtr, 0, 0); |
| 374 |
} |
| 375 |
Blt_TileRectangle(tkwin, drawable, tilePtr, x, y, width, height); |
| 376 |
} |
| 377 |
|
| 378 |
void |
| 379 |
Blt_TilePolygonOrigin( |
| 380 |
Tk_Window tkwin, Drawable drawable, |
| 381 |
ClientData *clientPtr, XPoint pointArr[], int nPoints, int xofs, int yofs, int flags) |
| 382 |
{ |
| 383 |
Blt_Tile tilePtr = (Blt_Tile)clientPtr; |
| 384 |
if (flags&1) { |
| 385 |
Blt_SetTSOrigin(tkwin, tilePtr, xofs, yofs); |
| 386 |
} else if (flags&2) { |
| 387 |
Blt_SetTileOrigin(tkwin, tilePtr, xofs, yofs); |
| 388 |
} else { |
| 389 |
Blt_SetTileOrigin(tkwin, tilePtr, 0, 0); |
| 390 |
} |
| 391 |
Blt_TilePolygon(tkwin, drawable, tilePtr, pointArr, nPoints); |
| 392 |
} |
| 393 |
|
| 394 |
int Blt_TileFlagsOrigin(ClientData clientPtr) { |
| 395 |
Blt_Tile tilePtr = (Blt_Tile)clientPtr; |
| 396 |
return Blt_TileFlags(tilePtr); |
| 397 |
} |
| 398 |
|
| 399 |
int Blt_TileHasOrigin(ClientData clientPtr) { |
| 400 |
Blt_Tile tilePtr = (Blt_Tile)clientPtr; |
| 401 |
return Blt_HasTile(tilePtr); |
| 402 |
} |
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
static struct TileHandlers { |
| 407 |
int magic; |
| 408 |
int (*Tk_TileHasProcPtr)(ClientData tile); |
| 409 |
int (*Tk_TileFlagsProcPtr)(ClientData tile); |
| 410 |
void (*Tk_TileRectangleProcPtr) (Tk_Window tkwin, Drawable drawable, |
| 411 |
ClientData tile, int x, int y, int width, int height, int xofs, int yofs, int flags); |
| 412 |
void (*Tk_TilePolygonProcPtr)( Tk_Window tkwin, Drawable drawable, |
| 413 |
ClientData *clientPtr, XPoint pointArr[], int nPoints, |
| 414 |
int xofs, int yofs, int flags); |
| 415 |
void (*Tk_FreeTileProcPtr)(ClientData clientData); |
| 416 |
void (*Tk_SetTileChangedProcPtr)( ClientData tile, |
| 417 |
char *procPtr, ClientData clientData); |
| 418 |
Tk_CustomOption *TileOption; |
| 419 |
Tk_ObjCustomOption *CustomTileOption; |
| 420 |
|
| 421 |
} TileHandlerFuncs = { |
| 422 |
0x77711101, |
| 423 |
(void*)Blt_TileHasOrigin, |
| 424 |
(void*)Blt_TileFlagsOrigin, |
| 425 |
(void*)Blt_TileRectangleOrigin, |
| 426 |
(void*)Blt_TilePolygonOrigin, |
| 427 |
(void*)Blt_FreeTile, |
| 428 |
(void*)Blt_SetTileChangedProc, |
| 429 |
NULL, |
| 430 |
NULL |
| 431 |
|
| 432 |
}; |
| 433 |
#endif |
| 434 |
|
| 435 |
static int |
| 436 |
SetLibraryPath(interp) |
| 437 |
Tcl_Interp *interp; |
| 438 |
{ |
| 439 |
Tcl_DString dString; |
| 440 |
CONST char *value; |
| •441 |
#ifndef TCL_ONLY |
| 442 |
static int tkisinit = 0; |
| 443 |
|
| 444 |
if (!tkisinit) { |
| 445 |
struct TileHandlers *thPtr; |
| 446 |
|
| 447 |
tkisinit=1; |
| 448 |
|
| 449 |
thPtr = (struct TileHandlers *)Tcl_GetAssocData(interp, "tkBgTileFuncs", NULL); |
| 450 |
if (thPtr != NULL && thPtr->magic == 0x77711101 && thPtr->TileOption) { |
| 451 |
*(thPtr->TileOption) = bltTileOption; |
| 452 |
*(thPtr->CustomTileOption) = bltCustomTileOption; |
| 453 |
*thPtr = TileHandlerFuncs; |
| 454 |
} |
| 455 |
} |
| 456 |
#endif |
| 457 |
|
| 458 |
Tcl_DStringInit(&dString); |
| 459 |
Tcl_DStringAppend(&dString, libPath, -1); |
| 460 |
#ifdef WIN32 |
| 461 |
{ |
| 462 |
HKEY key; |
| 463 |
DWORD result; |
| 464 |
#ifndef BLT_REGISTRY_KEY |
| 465 |
#define BLT_REGISTRY_KEY "Software\\BLT\\" BLT_VERSION "\\" TCL_VERSION |
| 466 |
#endif |
| 467 |
result = RegOpenKeyEx( |
| 468 |
HKEY_LOCAL_MACHINE, |
| 469 |
BLT_REGISTRY_KEY, |
| 470 |
0, |
| 471 |
KEY_READ, |
| 472 |
&key); |
| 473 |
|
| 474 |
if (result == ERROR_SUCCESS) { |
| 475 |
DWORD size; |
| 476 |
|
| 477 |
|
| 478 |
result = RegQueryValueEx(key, "BLT_LIBRARY", NULL, NULL, NULL, |
| 479 |
&size); |
| 480 |
if (result == ERROR_SUCCESS) { |
| 481 |
Tcl_DStringSetLength(&dString, size); |
| 482 |
|
| 483 |
RegQueryValueEx(key, "BLT_LIBRARY", NULL, NULL, |
| 484 |
(LPBYTE)Tcl_DStringValue(&dString), &size); |
| 485 |
RegCloseKey(key); |
| 486 |
} |
| 487 |
} |
| 488 |
} |
| 489 |
#endif |
| 490 |
value = Tcl_SetVar(interp, "blt_libPath", Tcl_DStringValue(&dString), |
| 491 |
TCL_GLOBAL_ONLY | TCL_LEAVE_ERR_MSG); |
| 492 |
Tcl_DStringFree(&dString); |
| 493 |
if (value == NULL) { |
| 494 |
return TCL_ERROR; |
| 495 |
} |
| 496 |
return TCL_OK; |
| 497 |
} |
| 498 |
|
| 499 |
#if (TCL_MAJOR_VERSION > 7) |
| 500 |
|
| 501 |
#include "bltDecls.h" |
| 502 |
|
| 503 |
#ifdef USE_BLT_STUBS |
| 504 |
extern BltStubs bltStubs; |
| 505 |
#endif |
| 506 |
|
| 507 |
|
| 508 |
EXPORT int |
| 509 |
Blt_Init(interp) |
| 510 |
Tcl_Interp *interp; |
| 511 |
{ |
| 512 |
int flags; |
| •513 |
#ifdef USE_BLT_STUBS |
| 514 |
int dostub = 0; |
| •515 |
#endif |
| 516 |
|
| •517 |
flags = (intptr_t)Tcl_GetAssocData(interp, BLT_THREAD_KEY, NULL); |
| 518 |
if ((flags & BLT_TCL_CMDS) == 0) { |
| 519 |
register Tcl_AppInitProc **p; |
| 520 |
Tcl_Namespace *nsPtr; |
| 521 |
Tcl_ValueType args[2]; |
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
if (Tcl_PkgRequire(interp, "Tcl", TCL_VERSION, 0) == NULL) { |
| 528 |
return TCL_ERROR; |
| 529 |
} |
| 530 |
|
| 531 |
|
| 532 |
if ((Tcl_SetVar(interp, "blt_version", BLT_VERSION, |
| 533 |
TCL_GLOBAL_ONLY) == NULL) || |
| 534 |
(Tcl_SetVar(interp, "blt_patchLevel", BLT_PATCH_LEVEL, |
| 535 |
TCL_GLOBAL_ONLY) == NULL)) { |
| 536 |
return TCL_ERROR; |
| 537 |
} |
| 538 |
if (SetLibraryPath(interp) != TCL_OK) { |
| 539 |
return TCL_ERROR; |
| 540 |
} |
| 541 |
nsPtr = Tcl_CreateNamespace(interp, "blt", NULL, |
| 542 |
(Tcl_NamespaceDeleteProc *) NULL); |
| 543 |
if (nsPtr == NULL) { |
| 544 |
return TCL_ERROR; |
| 545 |
} |
| 546 |
if (Tcl_Eval(interp, initScript) != TCL_OK) { |
| 547 |
return TCL_ERROR; |
| 548 |
} |
| 549 |
#ifdef USE_BLT_STUBS |
| 550 |
if (dostub) { |
| 551 |
Blt_InitStubs(interp, 0, 0); |
| 552 |
} |
| 553 |
#endif |
| 554 |
|
| 555 |
for (p = tclCmds; *p != NULL; p++) { |
| 556 |
if ((**p) (interp) != TCL_OK) { |
| 557 |
Tcl_DeleteNamespace(nsPtr); |
| 558 |
return TCL_ERROR; |
| 559 |
} |
| 560 |
} |
| 561 |
args[0] = args[1] = TCL_EITHER; |
| 562 |
Tcl_CreateMathFunc(interp, "min", 2, args, MinMathProc, (ClientData)0); |
| 563 |
Tcl_CreateMathFunc(interp, "max", 2, args, MaxMathProc, (ClientData)0); |
| 564 |
Blt_RegisterArrayObj(interp); |
| 565 |
bltNaN = MakeNaN(); |
| 566 |
#ifdef USE_BLT_STUBS |
| 567 |
if (Tcl_PkgProvideEx(interp, "BLT", BLT_PATCH_LEVEL, &bltStubs) != TCL_OK) { |
| 568 |
return TCL_ERROR; |
| 569 |
} |
| 570 |
#else |
| 571 |
if (Tcl_PkgProvideEx(interp, "BLT", BLT_PATCH_LEVEL, NULL) != TCL_OK) { |
| 572 |
return TCL_ERROR; |
| 573 |
} |
| 574 |
#endif |
| 575 |
Tcl_SetAssocData(interp, BLT_THREAD_KEY, NULL, |
| •576 |
(ClientData)(intptr_t)(flags | BLT_TCL_CMDS)); |
| 577 |
} |
| 578 |
#ifndef TCL_ONLY |
| 579 |
if ((flags & BLT_TK_CMDS) == 0) { |
| 580 |
register Tcl_AppInitProc **p; |
| 581 |
Tcl_Namespace *nsPtr; |
| 582 |
|
| 583 |
#if ((TCL_VERSION_NUMBER >= _VERSION(8,1,0)) && (TCL_RELEASE_LEVEL == TCL_FINAL_RELEASE)) |
| 584 |
if (Tcl_PkgPresent(interp, "Tk", TK_VERSION, 0) == NULL) { |
| 585 |
return TCL_OK; |
| 586 |
} |
| 587 |
#else |
| 588 |
if (Tcl_PkgRequire(interp, "Tk", TK_VERSION, 0) == NULL) { |
| 589 |
Tcl_ResetResult(interp); |
| 590 |
return TCL_OK; |
| 591 |
} |
| 592 |
#endif |
| 593 |
nsPtr = Tcl_CreateNamespace(interp, "blt::tile", NULL, |
| 594 |
(Tcl_NamespaceDeleteProc *) NULL); |
| 595 |
if (nsPtr == NULL) { |
| 596 |
return TCL_ERROR; |
| 597 |
} |
| 598 |
nsPtr = Tcl_FindNamespace(interp, "blt", (Tcl_Namespace *)NULL, |
| 599 |
TCL_LEAVE_ERR_MSG); |
| 600 |
if (nsPtr == NULL ) { |
| 601 |
return TCL_ERROR; |
| 602 |
} |
| 603 |
|
| 604 |
for (p = tkCmds; *p != NULL; p++) { |
| 605 |
if ((**p) (interp) != TCL_OK) { |
| 606 |
Tcl_DeleteNamespace(nsPtr); |
| 607 |
return TCL_ERROR; |
| 608 |
} |
| 609 |
} |
| 610 |
Blt_InitEpsCanvasItem(interp); |
| 611 |
Tcl_SetAssocData(interp, BLT_THREAD_KEY, NULL, |
| •612 |
(ClientData)(intptr_t)(flags | BLT_TK_CMDS)); |
| 613 |
} |
| 614 |
#endif |
| 615 |
return TCL_OK; |
| 616 |
} |
| 617 |
|
| 618 |
#else |
| 619 |
|
| 620 |
|
| 621 |
EXPORT int |
| 622 |
Blt_Init(interp) |
| 623 |
Tcl_Interp *interp; |
| 624 |
{ |
| 625 |
int flags; |
| 626 |
|
| 627 |
flags = (int)Tcl_GetAssocData(interp, BLT_THREAD_KEY, NULL); |
| 628 |
if ((flags & BLT_TCL_CMDS) == 0) { |
| 629 |
register Tcl_AppInitProc **p; |
| 630 |
Tcl_ValueType args[2]; |
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
if (Tcl_PkgRequire(interp, "Tcl", TCL_VERSION, 0) == NULL) { |
| 637 |
return TCL_ERROR; |
| 638 |
} |
| 639 |
|
| 640 |
|
| 641 |
if ((Tcl_SetVar(interp, "blt_version", BLT_VERSION, |
| 642 |
TCL_GLOBAL_ONLY) == NULL) || |
| 643 |
(Tcl_SetVar(interp, "blt_patchLevel", BLT_PATCH_LEVEL, |
| 644 |
TCL_GLOBAL_ONLY) == NULL)) { |
| 645 |
return TCL_ERROR; |
| 646 |
} |
| 647 |
if (SetLibraryPath(interp) != TCL_OK) { |
| 648 |
return TCL_ERROR; |
| 649 |
} |
| 650 |
if (Tcl_Eval(interp, initScript) != TCL_OK) { |
| 651 |
return TCL_ERROR; |
| 652 |
} |
| 653 |
|
| 654 |
for (p = tclCmds; *p != NULL; p++) { |
| 655 |
if ((**p) (interp) != TCL_OK) { |
| 656 |
return TCL_ERROR; |
| 657 |
} |
| 658 |
} |
| 659 |
args[0] = args[1] = TCL_EITHER; |
| 660 |
Tcl_CreateMathFunc(interp, "min", 2, args, MinMathProc, (ClientData)0); |
| 661 |
Tcl_CreateMathFunc(interp, "max", 2, args, MaxMathProc, (ClientData)0); |
| 662 |
bltNaN = MakeNaN(); |
| 663 |
if (Tcl_PkgProvide(interp, "BLT", BLT_VERSION) != TCL_OK) { |
| 664 |
return TCL_ERROR; |
| 665 |
} |
| 666 |
Tcl_SetAssocData(interp, BLT_THREAD_KEY, NULL, |
| 667 |
(ClientData)(flags | BLT_TCL_CMDS)); |
| 668 |
} |
| 669 |
#ifndef TCL_ONLY |
| 670 |
if ((flags & BLT_TK_CMDS) == 0) { |
| 671 |
register Tcl_AppInitProc **p; |
| 672 |
|
| 673 |
#if (TCL_VERSION_NUMBER >= _VERSION(8,1,0)) |
| 674 |
if (Tcl_PkgPresent(interp, "Tk", TK_VERSION, 0) == NULL) { |
| 675 |
return TCL_OK; |
| 676 |
} |
| 677 |
#else |
| 678 |
if (Tcl_PkgRequire(interp, "Tk", TK_VERSION, 0) == NULL) { |
| 679 |
Tcl_ResetResult(interp); |
| 680 |
return TCL_OK; |
| 681 |
} |
| 682 |
#endif |
| 683 |
|
| 684 |
for (p = tkCmds; *p != NULL; p++) { |
| 685 |
if ((**p) (interp) != TCL_OK) { |
| 686 |
return TCL_ERROR; |
| 687 |
} |
| 688 |
} |
| 689 |
Blt_InitEpsCanvasItem(interp); |
| 690 |
Tcl_SetAssocData(interp, BLT_THREAD_KEY, NULL, |
| 691 |
(ClientData)(flags | BLT_TK_CMDS)); |
| 692 |
} |
| 693 |
#endif |
| 694 |
return TCL_OK; |
| 695 |
} |
| 696 |
|
| 697 |
#endif |
| 698 |
|
| 699 |
|
| 700 |
EXPORT int |
| 701 |
Blt_SafeInit(interp) |
| 702 |
Tcl_Interp *interp; |
| 703 |
{ |
| 704 |
return Blt_Init(interp); |
| 705 |
} |
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
Tcl_Command |
| 730 |
Blt_InitCmd(interp, nsName, specPtr) |
| 731 |
Tcl_Interp *interp; |
| 732 |
char *nsName; |
| 733 |
Blt_CmdSpec *specPtr; |
| 734 |
{ |
| 735 |
char *cmdPath; |
| 736 |
Tcl_DString dString; |
| 737 |
Tcl_Command cmdToken; |
| 738 |
|
| 739 |
Tcl_DStringInit(&dString); |
| 740 |
#if HAVE_NAMESPACES |
| 741 |
if (nsName != NULL) { |
| 742 |
Tcl_DStringAppend(&dString, nsName, -1); |
| 743 |
} |
| 744 |
Tcl_DStringAppend(&dString, "::", -1); |
| 745 |
#endif |
| 746 |
Tcl_DStringAppend(&dString, specPtr->name, -1); |
| 747 |
|
| 748 |
cmdPath = Tcl_DStringValue(&dString); |
| 749 |
cmdToken = Tcl_FindCommand(interp, cmdPath, (Tcl_Namespace *)NULL, 0); |
| 750 |
if (cmdToken != NULL) { |
| 751 |
Tcl_DStringFree(&dString); |
| 752 |
return cmdToken; |
| 753 |
} |
| 754 |
cmdToken = Tcl_CreateCommand(interp, cmdPath, specPtr->cmdProc, |
| 755 |
specPtr->clientData, specPtr->cmdDeleteProc); |
| 756 |
Tcl_DStringFree(&dString); |
| 757 |
|
| 758 |
#if (HAVE_NAMESPACES) && (TCL_MAJOR_VERSION > 7) |
| 759 |
{ |
| 760 |
Tcl_Namespace *nsPtr; |
| 761 |
int dontResetList = 0; |
| 762 |
|
| 763 |
nsPtr = Tcl_FindNamespace(interp, nsName, (Tcl_Namespace *)NULL, |
| 764 |
TCL_LEAVE_ERR_MSG); |
| 765 |
if (nsPtr == NULL) { |
| 766 |
return NULL; |
| 767 |
} |
| 768 |
if (Tcl_Export(interp, nsPtr, specPtr->name, dontResetList) != TCL_OK) { |
| 769 |
return NULL; |
| 770 |
} |
| 771 |
} |
| 772 |
#endif |
| 773 |
return cmdToken; |
| 774 |
} |
| 775 |
|
| 776 |
#if (TCL_MAJOR_VERSION > 7) |
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
Tcl_Command |
| 799 |
Blt_InitObjCmd(interp, nsName, specPtr) |
| 800 |
Tcl_Interp *interp; |
| 801 |
char *nsName; |
| 802 |
Blt_ObjCmdSpec *specPtr; |
| 803 |
{ |
| 804 |
char *cmdPath; |
| 805 |
Tcl_DString dString; |
| 806 |
Tcl_Command cmdToken; |
| 807 |
Tcl_Namespace *nsPtr; |
| 808 |
|
| 809 |
Tcl_DStringInit(&dString); |
| 810 |
if (nsName != NULL) { |
| 811 |
Tcl_DStringAppend(&dString, nsName, -1); |
| 812 |
} |
| 813 |
Tcl_DStringAppend(&dString, "::", -1); |
| 814 |
Tcl_DStringAppend(&dString, specPtr->name, -1); |
| 815 |
|
| 816 |
cmdPath = Tcl_DStringValue(&dString); |
| 817 |
cmdToken = Tcl_FindCommand(interp, cmdPath, (Tcl_Namespace *)NULL, 0); |
| 818 |
if (cmdToken != NULL) { |
| 819 |
Tcl_DStringFree(&dString); |
| 820 |
return cmdToken; |
| 821 |
} |
| 822 |
cmdToken = Tcl_CreateObjCommand(interp, cmdPath, |
| 823 |
(Tcl_ObjCmdProc *)specPtr->cmdProc, |
| 824 |
specPtr->clientData, |
| 825 |
specPtr->cmdDeleteProc); |
| 826 |
Tcl_DStringFree(&dString); |
| 827 |
|
| 828 |
nsPtr = Tcl_FindNamespace(interp, nsName, (Tcl_Namespace *)NULL, |
| 829 |
TCL_LEAVE_ERR_MSG); |
| 830 |
if (nsPtr == NULL) { |
| 831 |
return NULL; |
| 832 |
} |
| 833 |
if (Tcl_Export(interp, nsPtr, specPtr->name, FALSE) != TCL_OK) { |
| 834 |
return NULL; |
| 835 |
} |
| 836 |
return cmdToken; |
| 837 |
} |
| 838 |
|
| 839 |
#endif |
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
int |
| 862 |
Blt_InitCmds(interp, nsName, specPtr, nCmds) |
| 863 |
Tcl_Interp *interp; |
| 864 |
char *nsName; |
| 865 |
Blt_CmdSpec *specPtr; |
| 866 |
int nCmds; |
| 867 |
{ |
| 868 |
Blt_CmdSpec *endPtr; |
| 869 |
|
| 870 |
for (endPtr = specPtr + nCmds; specPtr < endPtr; specPtr++) { |
| 871 |
if (Blt_InitCmd(interp, nsName, specPtr) == NULL) { |
| 872 |
return TCL_ERROR; |
| 873 |
} |
| 874 |
} |
| 875 |
return TCL_OK; |
| 876 |
} |