| 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 |
#include "bltInt.h" |
| 29 |
#if defined(__STDC__) |
| 30 |
#include <stdarg.h> |
| 31 |
#else |
| 32 |
#include <varargs.h> |
| 33 |
#endif |
| 34 |
|
| 35 |
#include "bltSwitch.h" |
| 36 |
|
| 37 |
static Blt_SwitchSpec * GetCachedSwitchSpecs _ANSI_ARGS_((Tcl_Interp *interp, |
| 38 |
const Blt_SwitchSpec *staticSpecs)); |
| 39 |
static void DeleteSpecCacheTable _ANSI_ARGS_(( |
| 40 |
ClientData clientData, Tcl_Interp *interp)); |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
static Blt_SwitchSpec * |
| 61 |
FindSwitchSpec(interp, specs, name, needFlags, hateFlags, flags) |
| 62 |
Tcl_Interp *interp; |
| 63 |
Blt_SwitchSpec *specs; |
| 64 |
|
| 65 |
char *name; |
| 66 |
|
| 67 |
int needFlags; |
| 68 |
|
| 69 |
int hateFlags; |
| 70 |
|
| 71 |
int flags; |
| 72 |
{ |
| 73 |
register Blt_SwitchSpec *specPtr; |
| 74 |
register char c; |
| 75 |
Blt_SwitchSpec *matchPtr; |
| 76 |
size_t length; |
| 77 |
|
| 78 |
c = name[1]; |
| 79 |
length = strlen(name); |
| 80 |
matchPtr = NULL; |
| 81 |
specs = Blt_GetCachedSwitchSpecs(interp, specs); |
| 82 |
for (specPtr = specs; specPtr->type != BLT_SWITCH_END; specPtr++) { |
| 83 |
if (specPtr->switchName == NULL) { |
| 84 |
continue; |
| 85 |
} |
| 86 |
if ((specPtr->switchName[1] != c) |
| 87 |
|| (strncmp(specPtr->switchName, name, length) != 0)) { |
| 88 |
continue; |
| 89 |
} |
| 90 |
if ((flags&BLT_SWITCH_EXACT) && specPtr->switchName[length] != 0) { |
| 91 |
continue; |
| 92 |
} |
| 93 |
if (((specPtr->flags & needFlags) != needFlags) |
| 94 |
|| (specPtr->flags & hateFlags)) { |
| 95 |
continue; |
| 96 |
} |
| 97 |
if (specPtr->switchName[length] == 0) { |
| 98 |
return specPtr; |
| 99 |
} |
| 100 |
if (matchPtr != NULL) { |
| 101 |
Tcl_AppendResult(interp, "ambiguous option \"", name, "\"", |
| 102 |
(char *) NULL); |
| 103 |
return (Blt_SwitchSpec *) NULL; |
| 104 |
} |
| 105 |
matchPtr = specPtr; |
| 106 |
} |
| 107 |
|
| 108 |
if (matchPtr == NULL) { |
| 109 |
Tcl_AppendResult(interp, "unknown option \"", name, "\" not one of: ", (char *)NULL); |
| 110 |
for (specPtr = specs; specPtr->type != BLT_SWITCH_END; specPtr++) { |
| 111 |
if (specPtr->switchName == NULL) { |
| 112 |
continue; |
| 113 |
} |
| 114 |
if (name[1] != '?' || specPtr->type < 0 || specPtr->type >= BLT_SWITCH_END) { |
| 115 |
Tcl_AppendResult(interp, specPtr->switchName, " ", 0); |
| 116 |
} else { |
| 117 |
static char *typenames[BLT_SWITCH_END+10] = { |
| 118 |
"bool", "int", "posint", "nonneg", "double", "string", |
| 119 |
"list", "flag", "value", "custom", "END" |
| 120 |
}; |
| 121 |
if (typenames[BLT_SWITCH_END] == 0 || |
| 122 |
strcmp(typenames[BLT_SWITCH_END],"END")) { |
| 123 |
fprintf(stderr, "Blt_SwitchTypes changed\n"); |
| 124 |
continue; |
| 125 |
} |
| 126 |
Tcl_AppendResult(interp, "?", specPtr->switchName, 0); |
| 127 |
if (specPtr->type != BLT_SWITCH_FLAG) { |
| 128 |
Tcl_AppendResult(interp, " ", typenames[specPtr->type], 0); |
| 129 |
} |
| 130 |
Tcl_AppendResult(interp, "? ", 0); |
| 131 |
} |
| 132 |
} |
| 133 |
return (Blt_SwitchSpec *) NULL; |
| 134 |
} |
| 135 |
return matchPtr; |
| 136 |
} |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
static int |
| 157 |
DoSwitch(interp, specPtr, string, record, obj) |
| 158 |
Tcl_Interp *interp; |
| 159 |
Blt_SwitchSpec *specPtr; |
| 160 |
char *string; |
| 161 |
ClientData record; |
| 162 |
|
| 163 |
|
| 164 |
Tcl_Obj *obj; |
| 165 |
{ |
| 166 |
char *ptr; |
| 167 |
int isNull; |
| 168 |
int count; |
| 169 |
|
| 170 |
isNull = ((*string == '\0') && (specPtr->flags & BLT_SWITCH_NULL_OK)); |
| 171 |
do { |
| 172 |
ptr = (char *)record + specPtr->offset; |
| 173 |
switch (specPtr->type) { |
| 174 |
case BLT_SWITCH_BOOLEAN: |
| 175 |
if (Tcl_GetBoolean(interp, string, (int *)ptr) != TCL_OK) { |
| 176 |
return TCL_ERROR; |
| 177 |
} |
| 178 |
break; |
| 179 |
|
| 180 |
case BLT_SWITCH_INT: |
| 181 |
if (Tcl_GetInt(interp, string, (int *)ptr) != TCL_OK) { |
| 182 |
return TCL_ERROR; |
| 183 |
} |
| 184 |
break; |
| 185 |
|
| 186 |
case BLT_SWITCH_INT_NONNEGATIVE: |
| 187 |
if (Tcl_GetInt(interp, string, &count) != TCL_OK) { |
| 188 |
return TCL_ERROR; |
| 189 |
} |
| 190 |
if (count < 0) { |
| 191 |
Tcl_AppendResult(interp, "bad value \"", string, "\": ", |
| 192 |
"can't be negative", (char *)NULL); |
| 193 |
return TCL_ERROR; |
| 194 |
} |
| 195 |
*((int *)ptr) = count; |
| 196 |
break; |
| 197 |
|
| 198 |
case BLT_SWITCH_INT_POSITIVE: |
| 199 |
if (Tcl_GetInt(interp, string, &count) != TCL_OK) { |
| 200 |
return TCL_ERROR; |
| 201 |
} |
| 202 |
if (count <= 0) { |
| 203 |
Tcl_AppendResult(interp, "bad value \"", string, "\": ", |
| 204 |
"must be positive", (char *)NULL); |
| 205 |
return TCL_ERROR; |
| 206 |
} |
| 207 |
*((int *)ptr) = count; |
| 208 |
break; |
| 209 |
|
| 210 |
case BLT_SWITCH_DOUBLE: |
| 211 |
if (Tcl_GetDouble(interp, string, (double *)ptr) != TCL_OK) { |
| 212 |
return TCL_ERROR; |
| 213 |
} |
| 214 |
break; |
| 215 |
case BLT_SWITCH_OBJ: |
| 216 |
(*((Tcl_Obj **)ptr)) = obj; |
| 217 |
break; |
| 218 |
|
| 219 |
case BLT_SWITCH_STRING: |
| 220 |
{ |
| 221 |
char *old, *new, **strPtr; |
| 222 |
|
| 223 |
strPtr = (char **)ptr; |
| 224 |
if (isNull) { |
| 225 |
new = NULL; |
| 226 |
} else { |
| 227 |
new = Blt_Strdup(string); |
| 228 |
} |
| 229 |
old = *strPtr; |
| 230 |
if (old != NULL) { |
| 231 |
Blt_Free(old); |
| 232 |
} |
| 233 |
*strPtr = new; |
| 234 |
} |
| 235 |
break; |
| 236 |
|
| 237 |
case BLT_SWITCH_LIST: |
| 238 |
if (Tcl_SplitList(interp, string, &count, (char ***)ptr) |
| 239 |
!= TCL_OK) { |
| 240 |
return TCL_ERROR; |
| 241 |
} |
| 242 |
break; |
| 243 |
|
| 244 |
case BLT_SWITCH_CUSTOM: |
| 245 |
if ((*specPtr->customPtr->parseProc) \ |
| 246 |
(specPtr->customPtr->clientData, interp, specPtr->switchName, |
| 247 |
string, record, specPtr->offset) != TCL_OK) { |
| 248 |
return TCL_ERROR; |
| 249 |
} |
| 250 |
break; |
| 251 |
|
| 252 |
default: |
| 253 |
Tcl_AppendResult(interp, "bad switch table: unknown type \"", |
| 254 |
Blt_Itoa(specPtr->type), "\"", (char *)NULL); |
| 255 |
return TCL_ERROR; |
| 256 |
} |
| 257 |
specPtr++; |
| 258 |
} while ((specPtr->switchName == NULL) && |
| 259 |
(specPtr->type != BLT_SWITCH_END)); |
| 260 |
return TCL_OK; |
| 261 |
} |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
int |
| 286 |
Blt_ProcessSwitches(interp, specs, argc, argv, record, flags) |
| 287 |
Tcl_Interp *interp; |
| 288 |
Blt_SwitchSpec *specs; |
| 289 |
int argc; |
| 290 |
char **argv; |
| 291 |
char *record; |
| 292 |
|
| 293 |
|
| 294 |
int flags; |
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
{ |
| 299 |
register int count; |
| 300 |
char *arg; |
| 301 |
register Blt_SwitchSpec *specPtr; |
| 302 |
int needFlags; |
| 303 |
|
| 304 |
int hateFlags; |
| 305 |
|
| 306 |
|
| 307 |
needFlags = flags & ~(BLT_SWITCH_USER_BIT - 1); |
| 308 |
hateFlags = 0; |
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
specs = Blt_GetCachedSwitchSpecs(interp, specs); |
| 315 |
for (specPtr = specs; specPtr->type != BLT_SWITCH_END; specPtr++) { |
| 316 |
specPtr->flags &= ~BLT_SWITCH_SPECIFIED; |
| 317 |
} |
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
for (count = 0; count < argc; count++) { |
| 323 |
arg = argv[count]; |
| 324 |
if (flags & BLT_SWITCH_OBJV_PARTIAL) { |
| 325 |
if ((arg[0] != '-') || ((arg[1] == '-') && (argv[2] == '\0'))) { |
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
return count; |
| 332 |
} |
| 333 |
} |
| 334 |
specPtr = FindSwitchSpec(interp, specs, arg, needFlags, hateFlags, flags); |
| 335 |
if (specPtr == NULL) { |
| 336 |
return -1; |
| 337 |
} |
| 338 |
if (specPtr->type == BLT_SWITCH_FLAG) { |
| 339 |
char *ptr; |
| 340 |
|
| 341 |
ptr = record + specPtr->offset; |
| 342 |
*((int *)ptr) |= specPtr->value; |
| 343 |
} else if (specPtr->type == BLT_SWITCH_VALUE) { |
| 344 |
char *ptr; |
| 345 |
|
| 346 |
ptr = record + specPtr->offset; |
| 347 |
*((int *)ptr) = specPtr->value; |
| 348 |
} else { |
| 349 |
if ((count + 1) == argc) { |
| 350 |
Tcl_AppendResult(interp, "value for \"", arg, "\" missing", |
| 351 |
(char *) NULL); |
| 352 |
return -1; |
| 353 |
} |
| 354 |
count++; |
| 355 |
if (DoSwitch(interp, specPtr, argv[count], record, NULL) != TCL_OK) { |
| 356 |
char msg[100]; |
| 357 |
|
| 358 |
sprintf(msg, "\n (processing \"%.40s\" option)", |
| 359 |
specPtr->switchName); |
| 360 |
Tcl_AddErrorInfo(interp, msg); |
| 361 |
return -1; |
| 362 |
} |
| 363 |
} |
| 364 |
specPtr->flags |= BLT_SWITCH_SPECIFIED; |
| 365 |
} |
| 366 |
return count; |
| 367 |
} |
| 368 |
|
| 369 |
#if (TCL_VERSION_NUMBER >= _VERSION(8,0,0)) |
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
int |
| 394 |
Blt_ProcessObjSwitches(interp, specs, objc, objv, record, flags) |
| 395 |
Tcl_Interp *interp; |
| 396 |
Blt_SwitchSpec *specs; |
| 397 |
int objc; |
| 398 |
Tcl_Obj *CONST *objv; |
| 399 |
char *record; |
| 400 |
|
| 401 |
|
| 402 |
int flags; |
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
{ |
| 407 |
register Blt_SwitchSpec *specPtr; |
| 408 |
register int count; |
| 409 |
int needFlags; |
| 410 |
|
| 411 |
int hateFlags; |
| 412 |
|
| 413 |
|
| 414 |
needFlags = flags & ~(BLT_SWITCH_USER_BIT - 1); |
| 415 |
hateFlags = 0; |
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
specs = Blt_GetCachedSwitchSpecs(interp, specs); |
| 422 |
for (specPtr = specs; specPtr->type != BLT_SWITCH_END; specPtr++) { |
| 423 |
specPtr->flags &= ~BLT_SWITCH_SPECIFIED; |
| 424 |
} |
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
for (count = 0; count < objc; count++) { |
| 430 |
char *arg; |
| 431 |
|
| 432 |
arg = Tcl_GetString(objv[count]); |
| 433 |
if (flags & BLT_SWITCH_OBJV_PARTIAL) { |
| 434 |
if ((arg[0] != '-') || ((arg[1] == '-') && (arg[2] == '\0'))) { |
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
return count; |
| 441 |
} |
| 442 |
} |
| 443 |
specPtr = FindSwitchSpec(interp, specs, arg, needFlags, hateFlags, flags); |
| 444 |
if (specPtr == NULL) { |
| 445 |
return -1; |
| 446 |
} |
| 447 |
if (specPtr->type == BLT_SWITCH_FLAG) { |
| 448 |
char *ptr; |
| 449 |
|
| 450 |
ptr = record + specPtr->offset; |
| 451 |
*((int *)ptr) |= specPtr->value; |
| 452 |
} else if (specPtr->type == BLT_SWITCH_VALUE) { |
| 453 |
char *ptr; |
| 454 |
|
| 455 |
ptr = record + specPtr->offset; |
| 456 |
*((int *)ptr) = specPtr->value; |
| 457 |
} else { |
| 458 |
count++; |
| 459 |
if (count == objc) { |
| 460 |
Tcl_AppendResult(interp, "value for \"", arg, "\" missing", |
| 461 |
(char *) NULL); |
| 462 |
return -1; |
| 463 |
} |
| 464 |
arg = Tcl_GetString(objv[count]); |
| 465 |
if (DoSwitch(interp, specPtr, arg, record, objv[count]) != TCL_OK) { |
| 466 |
char msg[100]; |
| 467 |
|
| 468 |
sprintf(msg, "\n (processing \"%.40s\" option)", |
| 469 |
specPtr->switchName); |
| 470 |
Tcl_AddErrorInfo(interp, msg); |
| 471 |
return -1; |
| 472 |
} |
| 473 |
} |
| 474 |
specPtr->flags |= BLT_SWITCH_SPECIFIED; |
| 475 |
} |
| 476 |
return count; |
| 477 |
} |
| 478 |
#endif |
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
void |
| 495 |
Blt_FreeSwitches(interp, specs, record, needFlags) |
| 496 |
Tcl_Interp *interp; |
| 497 |
Blt_SwitchSpec *specs; |
| 498 |
char *record; |
| 499 |
|
| 500 |
int needFlags; |
| 501 |
|
| 502 |
|
| 503 |
{ |
| 504 |
register Blt_SwitchSpec *specPtr; |
| 505 |
|
| 506 |
specs = Blt_GetCachedSwitchSpecs(interp, specs); |
| 507 |
for (specPtr = specs; specPtr->type != BLT_SWITCH_END; specPtr++) { |
| 508 |
if ((specPtr->flags & needFlags) == needFlags) { |
| 509 |
char *ptr; |
| 510 |
|
| 511 |
ptr = record + specPtr->offset; |
| 512 |
switch (specPtr->type) { |
| 513 |
case BLT_SWITCH_STRING: |
| 514 |
case BLT_SWITCH_LIST: |
| 515 |
if (*((char **) ptr) != NULL) { |
| 516 |
Blt_Free(*((char **) ptr)); |
| 517 |
*((char **) ptr) = NULL; |
| 518 |
} |
| 519 |
break; |
| 520 |
|
| 521 |
case BLT_SWITCH_CUSTOM: |
| 522 |
if ((*(char **)ptr != NULL) && |
| 523 |
(specPtr->customPtr->freeProc != NULL)) { |
| 524 |
(*specPtr->customPtr->freeProc)(*(char **)ptr); |
| 525 |
*((char **) ptr) = NULL; |
| 526 |
} |
| 527 |
break; |
| 528 |
|
| 529 |
default: |
| 530 |
break; |
| 531 |
} |
| 532 |
} |
| 533 |
} |
| 534 |
} |
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
int Blt_SwitchChanged |
| 552 |
TCL_VARARGS_DEF(Blt_SwitchSpec *, arg1) |
| 553 |
{ |
| 554 |
va_list argList; |
| 555 |
Blt_SwitchSpec *specs; |
| 556 |
register Blt_SwitchSpec *specPtr; |
| 557 |
register char *switchName; |
| 558 |
Tcl_Interp *interp; |
| 559 |
|
| 560 |
specs = TCL_VARARGS_START(Blt_SwitchSpec *, arg1, argList); |
| 561 |
interp = va_arg(argList, Tcl_Interp *); |
| 562 |
specs = Blt_GetCachedSwitchSpecs(interp, specs); |
| 563 |
while ((switchName = va_arg(argList, char *)) != NULL) { |
| 564 |
for (specPtr = specs; specPtr->type != BLT_SWITCH_END; specPtr++) { |
| 565 |
if ((Tcl_StringMatch(specPtr->switchName, switchName)) && |
| 566 |
(specPtr->flags & BLT_SWITCH_SPECIFIED)) { |
| 567 |
va_end(argList); |
| 568 |
return 1; |
| 569 |
} |
| 570 |
} |
| 571 |
} |
| 572 |
va_end(argList); |
| 573 |
return 0; |
| 574 |
} |
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
static void |
| 594 |
DeleteSpecCacheTable(clientData, interp) |
| 595 |
ClientData clientData; |
| 596 |
Tcl_Interp *interp; |
| 597 |
{ |
| 598 |
Tcl_HashTable *tablePtr = (Tcl_HashTable *) clientData; |
| 599 |
Tcl_HashEntry *entryPtr; |
| 600 |
Tcl_HashSearch search; |
| 601 |
|
| 602 |
for (entryPtr = Tcl_FirstHashEntry(tablePtr,&search); entryPtr != NULL; |
| 603 |
entryPtr = Tcl_NextHashEntry(&search)) { |
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
ckfree((char *) Tcl_GetHashValue(entryPtr)); |
| 609 |
} |
| 610 |
Tcl_DeleteHashTable(tablePtr); |
| 611 |
ckfree((char *) tablePtr); |
| 612 |
} |
| 613 |
|
| 614 |
|
| 615 |
Blt_SwitchSpec * |
| 616 |
Blt_GetCachedSwitchSpecs(interp, staticSpecs) |
| 617 |
Tcl_Interp *interp; |
| 618 |
const Blt_SwitchSpec *staticSpecs; |
| 619 |
{ |
| 620 |
return GetCachedSwitchSpecs(interp, staticSpecs); |
| 621 |
} |
| 622 |
|
| 623 |
static Blt_SwitchSpec * |
| 624 |
GetCachedSwitchSpecs(interp, staticSpecs) |
| 625 |
Tcl_Interp *interp; |
| 626 |
const Blt_SwitchSpec *staticSpecs; |
| 627 |
|
| 628 |
|
| 629 |
{ |
| 630 |
Blt_SwitchSpec *cachedSpecs; |
| 631 |
Tcl_HashTable *specCacheTablePtr; |
| 632 |
Tcl_HashEntry *entryPtr; |
| 633 |
int isNew; |
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
specCacheTablePtr = (Tcl_HashTable *) |
| 642 |
Tcl_GetAssocData(interp, "bltSwitchSpec.threadTable", NULL); |
| 643 |
if (specCacheTablePtr == NULL) { |
| 644 |
specCacheTablePtr = (Tcl_HashTable *) ckalloc(sizeof(Tcl_HashTable)); |
| 645 |
Tcl_InitHashTable(specCacheTablePtr, TCL_ONE_WORD_KEYS); |
| 646 |
Tcl_SetAssocData(interp, "bltSwitchSpec.threadTable", |
| 647 |
DeleteSpecCacheTable, (ClientData) specCacheTablePtr); |
| 648 |
} |
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
entryPtr = Tcl_CreateHashEntry(specCacheTablePtr, (char *) staticSpecs, |
| 656 |
&isNew); |
| 657 |
if (isNew) { |
| 658 |
unsigned int entrySpace = sizeof(Blt_SwitchSpec); |
| 659 |
const Blt_SwitchSpec *staticSpecPtr; |
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
for (staticSpecPtr=staticSpecs; staticSpecPtr->type!=BLT_SWITCH_END; |
| 667 |
staticSpecPtr++) { |
| 668 |
entrySpace += sizeof(Blt_SwitchSpec); |
| 669 |
} |
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
cachedSpecs = (Blt_SwitchSpec *) ckalloc(entrySpace); |
| 677 |
memcpy((void *) cachedSpecs, (void *) staticSpecs, entrySpace); |
| 678 |
Tcl_SetHashValue(entryPtr, (ClientData) cachedSpecs); |
| 679 |
|
| 680 |
} else { |
| 681 |
cachedSpecs = (Blt_SwitchSpec *) Tcl_GetHashValue(entryPtr); |
| 682 |
} |
| 683 |
|
| 684 |
return cachedSpecs; |
| 685 |
} |