| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#include "tkPort.h" |
| 18 |
#include "tkInt.h" |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
typedef struct Element { |
| 61 |
Tk_Uid nameUid; |
| 62 |
|
| 63 |
union { |
| 64 |
struct ElArray *arrayPtr; |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
Tk_Uid valueUid; |
| 70 |
|
| 71 |
} child; |
| 72 |
int priority; |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
int flags; |
| 79 |
|
| 80 |
} Element; |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
#define TYPE_MASK 0x7 |
| 96 |
|
| 97 |
#define CLASS 0x1 |
| 98 |
#define NODE 0x2 |
| 99 |
#define WILDCARD 0x4 |
| 100 |
|
| 101 |
#define EXACT_LEAF_NAME 0x0 |
| 102 |
#define EXACT_LEAF_CLASS 0x1 |
| 103 |
#define EXACT_NODE_NAME 0x2 |
| 104 |
#define EXACT_NODE_CLASS 0x3 |
| 105 |
#define WILDCARD_LEAF_NAME 0x4 |
| 106 |
#define WILDCARD_LEAF_CLASS 0x5 |
| 107 |
#define WILDCARD_NODE_NAME 0x6 |
| 108 |
#define WILDCARD_NODE_CLASS 0x7 |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
typedef struct ElArray { |
| 118 |
int arraySize; |
| 119 |
|
| 120 |
int numUsed; |
| 121 |
|
| 122 |
Element *nextToUse; |
| 123 |
Element els[1]; |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
} ElArray; |
| 131 |
|
| 132 |
#define EL_ARRAY_SIZE(numEls) ((unsigned) (sizeof(ElArray) \ |
| 133 |
+ ((numEls)-1)*sizeof(Element))) |
| 134 |
#define INITIAL_SIZE 5 |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
#define NUM_STACKS 8 |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
typedef struct StackLevel { |
| 180 |
TkWindow *winPtr; |
| 181 |
|
| 182 |
int bases[NUM_STACKS]; |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
} StackLevel; |
| 187 |
|
| 188 |
typedef struct ThreadSpecificData { |
| 189 |
int initialized; |
| 190 |
|
| 191 |
|
| 192 |
ElArray *stacks[NUM_STACKS]; |
| 193 |
TkWindow *cachedWindow; |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
StackLevel *levels; |
| 206 |
int numLevels; |
| 207 |
int curLevel; |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
int serial; |
| 219 |
Element defaultMatch; |
| 220 |
|
| 221 |
} ThreadSpecificData; |
| 222 |
static Tcl_ThreadDataKey dataKey; |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
static int AddFromString _ANSI_ARGS_((Tcl_Interp *interp, |
| 229 |
Tk_Window tkwin, char *string, int priority)); |
| 230 |
static void ClearOptionTree _ANSI_ARGS_((ElArray *arrayPtr)); |
| 231 |
static ElArray * ExtendArray _ANSI_ARGS_((ElArray *arrayPtr, |
| 232 |
Element *elPtr)); |
| 233 |
static void ExtendStacks _ANSI_ARGS_((ElArray *arrayPtr, |
| 234 |
int leaf)); |
| 235 |
static int GetDefaultOptions _ANSI_ARGS_((Tcl_Interp *interp, |
| 236 |
TkWindow *winPtr)); |
| 237 |
static ElArray * NewArray _ANSI_ARGS_((int numEls)); |
| 238 |
static void OptionThreadExitProc _ANSI_ARGS_(( |
| 239 |
ClientData clientData)); |
| 240 |
static void OptionInit _ANSI_ARGS_((TkMainInfo *mainPtr)); |
| 241 |
static int ParsePriority _ANSI_ARGS_((Tcl_Interp *interp, |
| 242 |
char *string)); |
| 243 |
static int ReadOptionFile _ANSI_ARGS_((Tcl_Interp *interp, |
| 244 |
Tk_Window tkwin, char *fileName, int priority)); |
| 245 |
static void SetupStacks _ANSI_ARGS_((TkWindow *winPtr, int leaf)); |
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
void |
| 264 |
Tk_AddOption(tkwin, name, value, priority) |
| 265 |
Tk_Window tkwin; |
| 266 |
|
| 267 |
CONST char *name; |
| 268 |
CONST char *value; |
| 269 |
int priority; |
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
{ |
| 274 |
TkWindow *winPtr = ((TkWindow *) tkwin)->mainPtr->winPtr; |
| 275 |
register ElArray **arrayPtrPtr; |
| 276 |
register Element *elPtr; |
| 277 |
Element newEl; |
| 278 |
register CONST char *p; |
| 279 |
CONST char *field; |
| 280 |
int count, firstField, length; |
| 281 |
#define TMP_SIZE 100 |
| 282 |
char tmp[TMP_SIZE+1]; |
| 283 |
ThreadSpecificData *tsdPtr = (ThreadSpecificData *) |
| 284 |
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); |
| 285 |
|
| 286 |
if (winPtr->mainPtr->optionRootPtr == NULL) { |
| 287 |
OptionInit(winPtr->mainPtr); |
| 288 |
} |
| 289 |
tsdPtr->cachedWindow = NULL; |
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
if (priority < 0) { |
| 298 |
priority = 0; |
| 299 |
} else if (priority > TK_MAX_PRIO) { |
| 300 |
priority = TK_MAX_PRIO; |
| 301 |
} |
| 302 |
newEl.priority = (priority << 24) + tsdPtr->serial; |
| 303 |
tsdPtr->serial++; |
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
arrayPtrPtr = &(((TkWindow *) tkwin)->mainPtr->optionRootPtr); |
| 310 |
p = name; |
| 311 |
for (firstField = 1; ; firstField = 0) { |
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
if (*p == '*') { |
| 320 |
newEl.flags = WILDCARD; |
| 321 |
p++; |
| 322 |
} else { |
| 323 |
newEl.flags = 0; |
| 324 |
} |
| 325 |
field = p; |
| 326 |
while ((*p != 0) && (*p != '.') && (*p != '*')) { |
| 327 |
p++; |
| 328 |
} |
| 329 |
length = p - field; |
| 330 |
if (length > TMP_SIZE) { |
| 331 |
length = TMP_SIZE; |
| 332 |
} |
| 333 |
strncpy(tmp, field, (size_t) length); |
| 334 |
tmp[length] = 0; |
| 335 |
newEl.nameUid = Tk_GetUid(tmp); |
| 336 |
if (isupper(UCHAR(*field))) { |
| 337 |
newEl.flags |= CLASS; |
| 338 |
} |
| 339 |
|
| 340 |
if (*p != 0) { |
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
newEl.flags |= NODE; |
| 350 |
if (firstField && !(newEl.flags & WILDCARD) |
| 351 |
&& (newEl.nameUid != winPtr->nameUid) |
| 352 |
&& (newEl.nameUid != winPtr->classUid)) { |
| 353 |
return; |
| 354 |
} |
| 355 |
for (elPtr = (*arrayPtrPtr)->els, count = (*arrayPtrPtr)->numUsed; |
| 356 |
; elPtr++, count--) { |
| 357 |
if (count == 0) { |
| 358 |
newEl.child.arrayPtr = NewArray(5); |
| 359 |
*arrayPtrPtr = ExtendArray(*arrayPtrPtr, &newEl); |
| 360 |
arrayPtrPtr = &((*arrayPtrPtr)->nextToUse[-1].child.arrayPtr); |
| 361 |
break; |
| 362 |
} |
| 363 |
if ((elPtr->nameUid == newEl.nameUid) |
| 364 |
&& (elPtr->flags == newEl.flags)) { |
| 365 |
arrayPtrPtr = &(elPtr->child.arrayPtr); |
| 366 |
break; |
| 367 |
} |
| 368 |
} |
| 369 |
if (*p == '.') { |
| 370 |
p++; |
| 371 |
} |
| 372 |
} else { |
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
newEl.child.valueUid = Tk_GetUid(value); |
| 381 |
for (elPtr = (*arrayPtrPtr)->els, count = (*arrayPtrPtr)->numUsed; |
| 382 |
; elPtr++, count--) { |
| 383 |
if (count == 0) { |
| 384 |
*arrayPtrPtr = ExtendArray(*arrayPtrPtr, &newEl); |
| 385 |
return; |
| 386 |
} |
| 387 |
if ((elPtr->nameUid == newEl.nameUid) |
| 388 |
&& (elPtr->flags == newEl.flags)) { |
| 389 |
if (elPtr->priority < newEl.priority) { |
| 390 |
elPtr->priority = newEl.priority; |
| 391 |
elPtr->child.valueUid = newEl.child.valueUid; |
| 392 |
} |
| 393 |
return; |
| 394 |
} |
| 395 |
} |
| 396 |
} |
| 397 |
} |
| 398 |
} |
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
Tk_Uid |
| 422 |
Tk_GetOption(tkwin, name, className) |
| 423 |
Tk_Window tkwin; |
| 424 |
|
| 425 |
CONST char *name; |
| 426 |
CONST char *className; |
| 427 |
|
| 428 |
|
| 429 |
{ |
| 430 |
Tk_Uid nameId, classId = NULL; |
| 431 |
char *masqName; |
| 432 |
register Element *elPtr, *bestPtr; |
| 433 |
register int count; |
| 434 |
StackLevel *levelPtr; |
| 435 |
int stackDepth[NUM_STACKS]; |
| 436 |
ThreadSpecificData *tsdPtr = (ThreadSpecificData *) |
| 437 |
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); |
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
if (tkwin != (Tk_Window) tsdPtr->cachedWindow) { |
| 445 |
SetupStacks((TkWindow *) tkwin, 1); |
| 446 |
} |
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
bestPtr = &tsdPtr->defaultMatch; |
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
masqName = strchr(name, (int)'.'); |
| 470 |
if (masqName != NULL) { |
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
levelPtr = &tsdPtr->levels[tsdPtr->curLevel]; |
| 478 |
nameId = Tk_GetUid(masqName+1); |
| 479 |
for (count = 0; count < NUM_STACKS; count++) { |
| 480 |
stackDepth[count] = levelPtr->bases[count]; |
| 481 |
} |
| 482 |
} else { |
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
nameId = Tk_GetUid(name); |
| 488 |
for (count = 0; count < NUM_STACKS; count++) { |
| 489 |
stackDepth[count] = tsdPtr->stacks[count]->numUsed; |
| 490 |
} |
| 491 |
} |
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
for (elPtr = tsdPtr->stacks[EXACT_LEAF_NAME]->els, |
| 498 |
count = stackDepth[EXACT_LEAF_NAME]; count > 0; |
| 499 |
elPtr++, count--) { |
| 500 |
if ((elPtr->nameUid == nameId) |
| 501 |
&& (elPtr->priority > bestPtr->priority)) { |
| 502 |
bestPtr = elPtr; |
| 503 |
} |
| 504 |
} |
| 505 |
for (elPtr = tsdPtr->stacks[WILDCARD_LEAF_NAME]->els, |
| 506 |
count = stackDepth[WILDCARD_LEAF_NAME]; count > 0; |
| 507 |
elPtr++, count--) { |
| 508 |
if ((elPtr->nameUid == nameId) |
| 509 |
&& (elPtr->priority > bestPtr->priority)) { |
| 510 |
bestPtr = elPtr; |
| 511 |
} |
| 512 |
} |
| 513 |
|
| 514 |
if (className != NULL) { |
| 515 |
classId = Tk_GetUid(className); |
| 516 |
for (elPtr = tsdPtr->stacks[EXACT_LEAF_CLASS]->els, |
| 517 |
count = stackDepth[EXACT_LEAF_CLASS]; count > 0; |
| 518 |
elPtr++, count--) { |
| 519 |
if ((elPtr->nameUid == classId) |
| 520 |
&& (elPtr->priority > bestPtr->priority)) { |
| 521 |
bestPtr = elPtr; |
| 522 |
} |
| 523 |
} |
| 524 |
for (elPtr = tsdPtr->stacks[WILDCARD_LEAF_CLASS]->els, |
| 525 |
count = stackDepth[WILDCARD_LEAF_CLASS]; count > 0; |
| 526 |
elPtr++, count--) { |
| 527 |
if ((elPtr->nameUid == classId) |
| 528 |
&& (elPtr->priority > bestPtr->priority)) { |
| 529 |
bestPtr = elPtr; |
| 530 |
} |
| 531 |
} |
| 532 |
} |
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
if (masqName != NULL) { |
| 542 |
char *masqClass; |
| 543 |
Tk_Uid nodeId, winClassId, winNameId; |
| 544 |
unsigned int classNameLength; |
| 545 |
register Element *nodePtr, *leafPtr; |
| 546 |
static int searchOrder[] = { EXACT_NODE_NAME, |
| 547 |
WILDCARD_NODE_NAME, |
| 548 |
EXACT_NODE_CLASS, |
| 549 |
WILDCARD_NODE_CLASS, |
| 550 |
-1 }; |
| 551 |
int *currentPtr, currentStack, leafCount; |
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
classNameLength = (unsigned int)(masqName - name); |
| 558 |
masqClass = (char *)ckalloc(classNameLength + 1); |
| 559 |
strncpy(masqClass, name, classNameLength); |
| 560 |
masqClass[classNameLength] = '\0'; |
| 561 |
|
| 562 |
winClassId = Tk_GetUid(masqClass); |
| 563 |
ckfree(masqClass); |
| 564 |
winNameId = ((TkWindow *)tkwin)->nameUid; |
| 565 |
|
| 566 |
levelPtr = &tsdPtr->levels[tsdPtr->curLevel]; |
| 567 |
|
| 568 |
for (currentPtr = searchOrder; *currentPtr != -1; currentPtr++) { |
| 569 |
currentStack = *currentPtr; |
| 570 |
nodePtr = tsdPtr->stacks[currentStack]->els; |
| 571 |
count = levelPtr->bases[currentStack]; |
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
if (!(currentStack & WILDCARD)) { |
| 579 |
nodePtr += levelPtr[-1].bases[currentStack]; |
| 580 |
count -= levelPtr[-1].bases[currentStack]; |
| 581 |
} |
| 582 |
|
| 583 |
if (currentStack && CLASS) { |
| 584 |
nodeId = winClassId; |
| 585 |
} else { |
| 586 |
nodeId = winNameId; |
| 587 |
} |
| 588 |
|
| 589 |
for ( ; count > 0; nodePtr++, count--) { |
| 590 |
if (nodePtr->nameUid == nodeId) { |
| 591 |
leafPtr = nodePtr->child.arrayPtr->els; |
| 592 |
leafCount = nodePtr->child.arrayPtr->numUsed; |
| 593 |
for ( ; leafCount > 0; leafPtr++, leafCount--) { |
| 594 |
if (leafPtr->flags & CLASS && className != NULL) { |
| 595 |
if (leafPtr->nameUid == classId && |
| 596 |
leafPtr->priority > bestPtr->priority) { |
| 597 |
bestPtr = leafPtr; |
| 598 |
} |
| 599 |
} else { |
| 600 |
if (leafPtr->nameUid == nameId && |
| 601 |
leafPtr->priority > bestPtr->priority) { |
| 602 |
bestPtr = leafPtr; |
| 603 |
} |
| 604 |
} |
| 605 |
} |
| 606 |
} |
| 607 |
} |
| 608 |
} |
| 609 |
} |
| 610 |
|
| 611 |
return bestPtr->child.valueUid; |
| 612 |
} |
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
int |
| 632 |
Tk_OptionObjCmd(clientData, interp, objc, objv) |
| 633 |
ClientData clientData; |
| 634 |
|
| 635 |
Tcl_Interp *interp; |
| 636 |
int objc; |
| 637 |
Tcl_Obj *CONST objv[]; |
| 638 |
{ |
| 639 |
Tk_Window tkwin = (Tk_Window) clientData; |
| 640 |
int index, result; |
| 641 |
ThreadSpecificData *tsdPtr = (ThreadSpecificData *) |
| 642 |
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); |
| 643 |
|
| 644 |
static CONST char *optionCmds[] = { |
| 645 |
"add", "clear", "get", "readfile", NULL |
| 646 |
}; |
| 647 |
|
| 648 |
enum optionVals { |
| 649 |
OPTION_ADD, OPTION_CLEAR, OPTION_GET, OPTION_READFILE |
| 650 |
}; |
| 651 |
|
| 652 |
if (objc < 2) { |
| 653 |
Tcl_WrongNumArgs(interp, 1, objv, "cmd arg ?arg ...?"); |
| 654 |
return TCL_ERROR; |
| 655 |
} |
| 656 |
|
| 657 |
result = Tcl_GetIndexFromObj(interp, objv[1], optionCmds, "option", 0, |
| 658 |
&index); |
| 659 |
if (result != TCL_OK) { |
| 660 |
return result; |
| 661 |
} |
| 662 |
|
| 663 |
result = TCL_OK; |
| 664 |
switch ((enum optionVals) index) { |
| 665 |
case OPTION_ADD: { |
| 666 |
int priority; |
| 667 |
if ((objc != 4) && (objc != 5)) { |
| 668 |
Tcl_WrongNumArgs(interp, 2, objv, "pattern value ?priority?"); |
| 669 |
return TCL_ERROR; |
| 670 |
} |
| 671 |
|
| 672 |
if (objc == 4) { |
| 673 |
priority = TK_INTERACTIVE_PRIO; |
| 674 |
} else { |
| 675 |
priority = ParsePriority(interp, Tcl_GetString(objv[4])); |
| 676 |
if (priority < 0) { |
| 677 |
return TCL_ERROR; |
| 678 |
} |
| 679 |
} |
| 680 |
Tk_AddOption(tkwin, Tcl_GetString(objv[2]), |
| 681 |
Tcl_GetString(objv[3]), priority); |
| 682 |
break; |
| 683 |
} |
| 684 |
|
| 685 |
case OPTION_CLEAR: { |
| 686 |
TkMainInfo *mainPtr; |
| 687 |
|
| 688 |
if (objc != 2) { |
| 689 |
Tcl_WrongNumArgs(interp, 2, objv, ""); |
| 690 |
return TCL_ERROR; |
| 691 |
} |
| 692 |
mainPtr = ((TkWindow *) tkwin)->mainPtr; |
| 693 |
if (mainPtr->optionRootPtr != NULL) { |
| 694 |
ClearOptionTree(mainPtr->optionRootPtr); |
| 695 |
mainPtr->optionRootPtr = NULL; |
| 696 |
} |
| 697 |
tsdPtr->cachedWindow = NULL; |
| 698 |
break; |
| 699 |
} |
| 700 |
|
| 701 |
case OPTION_GET: { |
| 702 |
Tk_Window window; |
| 703 |
Tk_Uid value; |
| 704 |
|
| 705 |
if (objc != 5) { |
| 706 |
Tcl_WrongNumArgs(interp, 2, objv, "window name class"); |
| 707 |
return TCL_ERROR; |
| 708 |
} |
| 709 |
window = Tk_NameToWindow(interp, Tcl_GetString(objv[2]), tkwin); |
| 710 |
if (window == NULL) { |
| 711 |
return TCL_ERROR; |
| 712 |
} |
| 713 |
value = Tk_GetOption(window, Tcl_GetString(objv[3]), |
| 714 |
Tcl_GetString(objv[4])); |
| 715 |
if (value != NULL) { |
| 716 |
Tcl_SetResult(interp, (char *)value, TCL_STATIC); |
| 717 |
} |
| 718 |
break; |
| 719 |
} |
| 720 |
|
| 721 |
case OPTION_READFILE: { |
| 722 |
int priority; |
| 723 |
|
| 724 |
if ((objc != 3) && (objc != 4)) { |
| 725 |
Tcl_WrongNumArgs(interp, 2, objv, "fileName ?priority?"); |
| 726 |
return TCL_ERROR; |
| 727 |
} |
| 728 |
|
| 729 |
if (objc == 4) { |
| 730 |
priority = ParsePriority(interp, Tcl_GetString(objv[3])); |
| 731 |
if (priority < 0) { |
| 732 |
return TCL_ERROR; |
| 733 |
} |
| 734 |
} else { |
| 735 |
priority = TK_INTERACTIVE_PRIO; |
| 736 |
} |
| 737 |
result = ReadOptionFile(interp, tkwin, Tcl_GetString(objv[2]), |
| 738 |
priority); |
| 739 |
break; |
| 740 |
} |
| 741 |
} |
| 742 |
return result; |
| 743 |
} |
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
void |
| 765 |
TkOptionDeadWindow(winPtr) |
| 766 |
register TkWindow *winPtr; |
| 767 |
{ |
| 768 |
ThreadSpecificData *tsdPtr = (ThreadSpecificData *) |
| 769 |
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); |
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
if (winPtr->optionLevel != -1) { |
| 776 |
int i; |
| 777 |
|
| 778 |
for (i = 1; i <= tsdPtr->curLevel; i++) { |
| 779 |
tsdPtr->levels[i].winPtr->optionLevel = -1; |
| 780 |
} |
| 781 |
tsdPtr->curLevel = -1; |
| 782 |
tsdPtr->cachedWindow = NULL; |
| 783 |
} |
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
if ((winPtr->mainPtr != NULL) && (winPtr->mainPtr->winPtr == winPtr) |
| 791 |
&& (winPtr->mainPtr->optionRootPtr != NULL)) { |
| 792 |
ClearOptionTree(winPtr->mainPtr->optionRootPtr); |
| 793 |
winPtr->mainPtr->optionRootPtr = NULL; |
| 794 |
} |
| 795 |
} |
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
void |
| 817 |
TkOptionClassChanged(winPtr) |
| 818 |
TkWindow *winPtr; |
| 819 |
{ |
| 820 |
int i, j, *basePtr; |
| 821 |
ElArray *arrayPtr; |
| 822 |
ThreadSpecificData *tsdPtr = (ThreadSpecificData *) |
| 823 |
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); |
| 824 |
|
| 825 |
if (winPtr->optionLevel == -1) { |
| 826 |
return; |
| 827 |
} |
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
for (i = 1; i <= tsdPtr->curLevel; i++) { |
| 835 |
if (tsdPtr->levels[i].winPtr == winPtr) { |
| 836 |
for (j = i; j <= tsdPtr->curLevel; j++) { |
| 837 |
tsdPtr->levels[j].winPtr->optionLevel = -1; |
| 838 |
} |
| 839 |
tsdPtr->curLevel = i-1; |
| 840 |
basePtr = tsdPtr->levels[i].bases; |
| 841 |
for (j = 0; j < NUM_STACKS; j++) { |
| 842 |
arrayPtr = tsdPtr->stacks[j]; |
| 843 |
arrayPtr->numUsed = basePtr[j]; |
| 844 |
arrayPtr->nextToUse = &arrayPtr->els[arrayPtr->numUsed]; |
| 845 |
} |
| 846 |
if (tsdPtr->curLevel <= 0) { |
| 847 |
tsdPtr->cachedWindow = NULL; |
| 848 |
} else { |
| 849 |
tsdPtr->cachedWindow = tsdPtr->levels[tsdPtr->curLevel].winPtr; |
| 850 |
} |
| 851 |
break; |
| 852 |
} |
| 853 |
} |
| 854 |
} |
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
static int |
| 875 |
ParsePriority(interp, string) |
| 876 |
Tcl_Interp *interp; |
| 877 |
char *string; |
| 878 |
|
| 879 |
{ |
| 880 |
int priority, c; |
| 881 |
size_t length; |
| 882 |
|
| 883 |
c = string[0]; |
| 884 |
length = strlen(string); |
| 885 |
if ((c == 'w') |
| 886 |
&& (strncmp(string, "widgetDefault", length) == 0)) { |
| 887 |
return TK_WIDGET_DEFAULT_PRIO; |
| 888 |
} else if ((c == 's') |
| 889 |
&& (strncmp(string, "startupFile", length) == 0)) { |
| 890 |
return TK_STARTUP_FILE_PRIO; |
| 891 |
} else if ((c == 'u') |
| 892 |
&& (strncmp(string, "userDefault", length) == 0)) { |
| 893 |
return TK_USER_DEFAULT_PRIO; |
| 894 |
} else if ((c == 'i') |
| 895 |
&& (strncmp(string, "interactive", length) == 0)) { |
| 896 |
return TK_INTERACTIVE_PRIO; |
| 897 |
} else { |
| 898 |
char *end; |
| 899 |
|
| 900 |
priority = strtoul(string, &end, 0); |
| 901 |
if ((end == string) || (*end != 0) || (priority < 0) |
| 902 |
|| (priority > 100)) { |
| 903 |
Tcl_AppendResult(interp, "bad priority level \"", string, |
| 904 |
"\": must be widgetDefault, startupFile, userDefault, ", |
| 905 |
"interactive, or a number between 0 and 100", |
| 906 |
(char *) NULL); |
| 907 |
return -1; |
| 908 |
} |
| 909 |
} |
| 910 |
return priority; |
| 911 |
} |
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
static int |
| 937 |
AddFromString(interp, tkwin, string, priority) |
| 938 |
Tcl_Interp *interp; |
| 939 |
Tk_Window tkwin; |
| 940 |
|
| 941 |
char *string; |
| 942 |
int priority; |
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
{ |
| 947 |
register char *src, *dst; |
| 948 |
char *name, *value; |
| 949 |
int lineNum; |
| 950 |
|
| 951 |
src = string; |
| 952 |
lineNum = 1; |
| 953 |
while (1) { |
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
while ((*src == ' ') || (*src == '\t')) { |
| 961 |
src++; |
| 962 |
} |
| 963 |
if ((*src == '#') || (*src == '!')) { |
| 964 |
do { |
| 965 |
src++; |
| 966 |
if ((src[0] == '\\') && (src[1] == '\n')) { |
| 967 |
src += 2; |
| 968 |
lineNum++; |
| 969 |
} |
| 970 |
} while ((*src != '\n') && (*src != 0)); |
| 971 |
} |
| 972 |
if (*src == '\n') { |
| 973 |
src++; |
| 974 |
lineNum++; |
| 975 |
continue; |
| 976 |
} |
| 977 |
if (*src == '\0') { |
| 978 |
break; |
| 979 |
} |
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
dst = name = src; |
| 987 |
while (*src != ':') { |
| 988 |
if ((*src == '\0') || (*src == '\n')) { |
| 989 |
char buf[32 + TCL_INTEGER_SPACE]; |
| 990 |
|
| 991 |
sprintf(buf, "missing colon on line %d", lineNum); |
| 992 |
Tcl_SetResult(interp, buf, TCL_VOLATILE); |
| 993 |
return TCL_ERROR; |
| 994 |
} |
| 995 |
if ((src[0] == '\\') && (src[1] == '\n')) { |
| 996 |
src += 2; |
| 997 |
lineNum++; |
| 998 |
} else { |
| 999 |
*dst = *src; |
| 1000 |
dst++; |
| 1001 |
src++; |
| 1002 |
} |
| 1003 |
} |
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
while ((dst != name) && ((dst[-1] == ' ') || (dst[-1] == '\t'))) { |
| 1011 |
dst--; |
| 1012 |
} |
| 1013 |
*dst = '\0'; |
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
src++; |
| 1020 |
while ((*src == ' ') || (*src == '\t')) { |
| 1021 |
src++; |
| 1022 |
} |
| 1023 |
if (*src == '\0') { |
| 1024 |
char buf[32 + TCL_INTEGER_SPACE]; |
| 1025 |
|
| 1026 |
sprintf(buf, "missing value on line %d", lineNum); |
| 1027 |
Tcl_SetResult(interp, buf, TCL_VOLATILE); |
| 1028 |
return TCL_ERROR; |
| 1029 |
} |
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
dst = value = src; |
| 1037 |
while (*src != '\n') { |
| 1038 |
if (*src == '\0') { |
| 1039 |
char buf[32 + TCL_INTEGER_SPACE]; |
| 1040 |
|
| 1041 |
sprintf(buf, "missing newline on line %d", lineNum); |
| 1042 |
Tcl_SetResult(interp, buf, TCL_VOLATILE); |
| 1043 |
return TCL_ERROR; |
| 1044 |
} |
| 1045 |
if ((src[0] == '\\') && (src[1] == '\n')) { |
| 1046 |
src += 2; |
| 1047 |
lineNum++; |
| 1048 |
} else { |
| 1049 |
*dst = *src; |
| 1050 |
dst++; |
| 1051 |
src++; |
| 1052 |
} |
| 1053 |
} |
| 1054 |
*dst = 0; |
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
Tk_AddOption(tkwin, name, value, priority); |
| 1061 |
src++; |
| 1062 |
lineNum++; |
| 1063 |
} |
| 1064 |
return TCL_OK; |
| 1065 |
} |
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
static int |
| 1087 |
ReadOptionFile(interp, tkwin, fileName, priority) |
| 1088 |
Tcl_Interp *interp; |
| 1089 |
Tk_Window tkwin; |
| 1090 |
|
| 1091 |
char *fileName; |
| 1092 |
int priority; |
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
{ |
| 1097 |
CONST char *realName; |
| 1098 |
char *buffer; |
| 1099 |
int result, bufferSize; |
| 1100 |
Tcl_Channel chan; |
| 1101 |
Tcl_DString newName; |
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
if (Tcl_IsSafe(interp)) { |
| 1108 |
Tcl_AppendResult(interp, "can't read options from a file in a", |
| 1109 |
" safe interpreter", (char *) NULL); |
| 1110 |
return TCL_ERROR; |
| 1111 |
} |
| 1112 |
|
| 1113 |
realName = Tcl_TranslateFileName(interp, fileName, &newName); |
| 1114 |
if (realName == NULL) { |
| 1115 |
return TCL_ERROR; |
| 1116 |
} |
| 1117 |
chan = Tcl_OpenFileChannel(interp, realName, "r", 0); |
| 1118 |
Tcl_DStringFree(&newName); |
| 1119 |
if (chan == NULL) { |
| 1120 |
Tcl_ResetResult(interp); |
| 1121 |
Tcl_AppendResult(interp, "couldn't open \"", fileName, |
| 1122 |
"\": ", Tcl_PosixError(interp), (char *) NULL); |
| 1123 |
return TCL_ERROR; |
| 1124 |
} |
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
bufferSize = (int) Tcl_Seek(chan, (Tcl_WideInt) 0, SEEK_END); |
| 1132 |
(void) Tcl_Seek(chan, (Tcl_WideInt) 0, SEEK_SET); |
| 1133 |
|
| 1134 |
if (bufferSize < 0) { |
| 1135 |
Tcl_AppendResult(interp, "error seeking to end of file \"", |
| 1136 |
fileName, "\":", Tcl_PosixError(interp), (char *) NULL); |
| 1137 |
Tcl_Close(NULL, chan); |
| 1138 |
return TCL_ERROR; |
| 1139 |
|
| 1140 |
} |
| 1141 |
buffer = (char *) ckalloc((unsigned) bufferSize+1); |
| 1142 |
bufferSize = Tcl_Read(chan, buffer, bufferSize); |
| 1143 |
if (bufferSize < 0) { |
| 1144 |
Tcl_AppendResult(interp, "error reading file \"", fileName, "\":", |
| 1145 |
Tcl_PosixError(interp), (char *) NULL); |
| 1146 |
Tcl_Close(NULL, chan); |
| 1147 |
return TCL_ERROR; |
| 1148 |
} |
| 1149 |
Tcl_Close(NULL, chan); |
| 1150 |
buffer[bufferSize] = 0; |
| 1151 |
result = AddFromString(interp, tkwin, buffer, priority); |
| 1152 |
ckfree(buffer); |
| 1153 |
return result; |
| 1154 |
} |
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
|
| 1159 |
|
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
static ElArray * |
| 1175 |
NewArray(numEls) |
| 1176 |
int numEls; |
| 1177 |
{ |
| 1178 |
register ElArray *arrayPtr; |
| 1179 |
|
| 1180 |
arrayPtr = (ElArray *) ckalloc(EL_ARRAY_SIZE(numEls)); |
| 1181 |
arrayPtr->arraySize = numEls; |
| 1182 |
arrayPtr->numUsed = 0; |
| 1183 |
arrayPtr->nextToUse = arrayPtr->els; |
| 1184 |
return arrayPtr; |
| 1185 |
} |
| 1186 |
|
| 1187 |
|
| 1188 |
|
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
|
| 1204 |
|
| 1205 |
static ElArray * |
| 1206 |
ExtendArray(arrayPtr, elPtr) |
| 1207 |
register ElArray *arrayPtr; |
| 1208 |
register Element *elPtr; |
| 1209 |
{ |
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
if (arrayPtr->numUsed >= arrayPtr->arraySize) { |
| 1215 |
register ElArray *newPtr; |
| 1216 |
|
| 1217 |
newPtr = (ElArray *) ckalloc(EL_ARRAY_SIZE(2*arrayPtr->arraySize)); |
| 1218 |
newPtr->arraySize = 2*arrayPtr->arraySize; |
| 1219 |
newPtr->numUsed = arrayPtr->numUsed; |
| 1220 |
newPtr->nextToUse = &newPtr->els[newPtr->numUsed]; |
| 1221 |
memcpy((VOID *) newPtr->els, (VOID *) arrayPtr->els, |
| 1222 |
(arrayPtr->arraySize*sizeof(Element))); |
| 1223 |
ckfree((char *) arrayPtr); |
| 1224 |
arrayPtr = newPtr; |
| 1225 |
} |
| 1226 |
|
| 1227 |
*arrayPtr->nextToUse = *elPtr; |
| 1228 |
arrayPtr->nextToUse++; |
| 1229 |
arrayPtr->numUsed++; |
| 1230 |
return arrayPtr; |
| 1231 |
} |
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
static void |
| 1252 |
SetupStacks(winPtr, leaf) |
| 1253 |
TkWindow *winPtr; |
| 1254 |
|
| 1255 |
int leaf; |
| 1256 |
|
| 1257 |
|
| 1258 |
{ |
| 1259 |
int level, i, *iPtr; |
| 1260 |
register StackLevel *levelPtr; |
| 1261 |
register ElArray *arrayPtr; |
| 1262 |
ThreadSpecificData *tsdPtr = (ThreadSpecificData *) |
| 1263 |
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); |
| 1264 |
|
| 1265 |
|
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
static int searchOrder[] = {WILDCARD_NODE_CLASS, WILDCARD_NODE_NAME, |
| 1275 |
EXACT_NODE_CLASS, EXACT_NODE_NAME, -1}; |
| 1276 |
|
| 1277 |
if (winPtr->mainPtr->optionRootPtr == NULL) { |
| 1278 |
OptionInit(winPtr->mainPtr); |
| 1279 |
} |
| 1280 |
|
| 1281 |
|
| 1282 |
|
| 1283 |
|
| 1284 |
|
| 1285 |
|
| 1286 |
if (winPtr->parentPtr != NULL) { |
| 1287 |
level = winPtr->parentPtr->optionLevel; |
| 1288 |
if ((level == -1) || (tsdPtr->cachedWindow == NULL)) { |
| 1289 |
SetupStacks(winPtr->parentPtr, 0); |
| 1290 |
level = winPtr->parentPtr->optionLevel; |
| 1291 |
} |
| 1292 |
level++; |
| 1293 |
} else { |
| 1294 |
level = 1; |
| 1295 |
} |
| 1296 |
|
| 1297 |
|
| 1298 |
|
| 1299 |
|
| 1300 |
|
| 1301 |
|
| 1302 |
if (tsdPtr->curLevel >= level) { |
| 1303 |
while (tsdPtr->curLevel >= level) { |
| 1304 |
tsdPtr->levels[tsdPtr->curLevel].winPtr->optionLevel = -1; |
| 1305 |
tsdPtr->curLevel--; |
| 1306 |
} |
| 1307 |
levelPtr = &tsdPtr->levels[level]; |
| 1308 |
for (i = 0; i < NUM_STACKS; i++) { |
| 1309 |
arrayPtr = tsdPtr->stacks[i]; |
| 1310 |
arrayPtr->numUsed = levelPtr->bases[i]; |
| 1311 |
arrayPtr->nextToUse = &arrayPtr->els[arrayPtr->numUsed]; |
| 1312 |
} |
| 1313 |
} |
| 1314 |
tsdPtr->curLevel = winPtr->optionLevel = level; |
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
if ((tsdPtr->curLevel == 1) |
| 1323 |
&& ((tsdPtr->cachedWindow == NULL) |
| 1324 |
|| (tsdPtr->cachedWindow->mainPtr != winPtr->mainPtr))) { |
| 1325 |
for (i = 0; i < NUM_STACKS; i++) { |
| 1326 |
arrayPtr = tsdPtr->stacks[i]; |
| 1327 |
arrayPtr->numUsed = 0; |
| 1328 |
arrayPtr->nextToUse = arrayPtr->els; |
| 1329 |
} |
| 1330 |
ExtendStacks(winPtr->mainPtr->optionRootPtr, 0); |
| 1331 |
} |
| 1332 |
|
| 1333 |
|
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
if (tsdPtr->curLevel >= tsdPtr->numLevels) { |
| 1341 |
StackLevel *newLevels; |
| 1342 |
|
| 1343 |
newLevels = (StackLevel *) ckalloc((unsigned) |
| 1344 |
(tsdPtr->numLevels*2*sizeof(StackLevel))); |
| 1345 |
memcpy((VOID *) newLevels, (VOID *) tsdPtr->levels, |
| 1346 |
(tsdPtr->numLevels*sizeof(StackLevel))); |
| 1347 |
ckfree((char *) tsdPtr->levels); |
| 1348 |
tsdPtr->numLevels *= 2; |
| 1349 |
tsdPtr->levels = newLevels; |
| 1350 |
} |
| 1351 |
levelPtr = &tsdPtr->levels[tsdPtr->curLevel]; |
| 1352 |
levelPtr->winPtr = winPtr; |
| 1353 |
arrayPtr = tsdPtr->stacks[EXACT_LEAF_NAME]; |
| 1354 |
arrayPtr->numUsed = 0; |
| 1355 |
arrayPtr->nextToUse = arrayPtr->els; |
| 1356 |
arrayPtr = tsdPtr->stacks[EXACT_LEAF_CLASS]; |
| 1357 |
arrayPtr->numUsed = 0; |
| 1358 |
arrayPtr->nextToUse = arrayPtr->els; |
| 1359 |
for (i = 0; i < NUM_STACKS; i++) { |
| 1360 |
levelPtr->bases[i] = tsdPtr->stacks[i]->numUsed; |
| 1361 |
} |
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
|
| 1366 |
|
| 1367 |
|
| 1368 |
for (iPtr = searchOrder; *iPtr != -1; iPtr++) { |
| 1369 |
register Element *elPtr; |
| 1370 |
int count; |
| 1371 |
Tk_Uid id; |
| 1372 |
|
| 1373 |
i = *iPtr; |
| 1374 |
if (i & CLASS) { |
| 1375 |
id = winPtr->classUid; |
| 1376 |
} else { |
| 1377 |
id = winPtr->nameUid; |
| 1378 |
} |
| 1379 |
elPtr = tsdPtr->stacks[i]->els; |
| 1380 |
count = levelPtr->bases[i]; |
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
if (!(i & WILDCARD)) { |
| 1388 |
elPtr += levelPtr[-1].bases[i]; |
| 1389 |
count -= levelPtr[-1].bases[i]; |
| 1390 |
} |
| 1391 |
for ( ; count > 0; elPtr++, count--) { |
| 1392 |
if (elPtr->nameUid != id) { |
| 1393 |
continue; |
| 1394 |
} |
| 1395 |
ExtendStacks(elPtr->child.arrayPtr, leaf); |
| 1396 |
} |
| 1397 |
} |
| 1398 |
tsdPtr->cachedWindow = winPtr; |
| 1399 |
} |
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
|
| 1412 |
|
| 1413 |
|
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
|
| 1418 |
|
| 1419 |
static void |
| 1420 |
ExtendStacks(arrayPtr, leaf) |
| 1421 |
ElArray *arrayPtr; |
| 1422 |
int leaf; |
| 1423 |
|
| 1424 |
{ |
| 1425 |
register int count; |
| 1426 |
register Element *elPtr; |
| 1427 |
ThreadSpecificData *tsdPtr = (ThreadSpecificData *) |
| 1428 |
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); |
| 1429 |
|
| 1430 |
for (elPtr = arrayPtr->els, count = arrayPtr->numUsed; |
| 1431 |
count > 0; elPtr++, count--) { |
| 1432 |
if (!(elPtr->flags & (NODE|WILDCARD)) && !leaf) { |
| 1433 |
continue; |
| 1434 |
} |
| 1435 |
tsdPtr->stacks[elPtr->flags] = ExtendArray( |
| 1436 |
tsdPtr->stacks[elPtr->flags], elPtr); |
| 1437 |
} |
| 1438 |
} |
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
|
| 1450 |
|
| 1451 |
|
| 1452 |
|
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
static void |
| 1457 |
OptionThreadExitProc(clientData) |
| 1458 |
ClientData clientData; |
| 1459 |
{ |
| 1460 |
ThreadSpecificData *tsdPtr = (ThreadSpecificData *) |
| 1461 |
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); |
| 1462 |
|
| 1463 |
if (tsdPtr->initialized) { |
| 1464 |
int i; |
| 1465 |
for (i = 0; i < NUM_STACKS; i++) { |
| 1466 |
ckfree((char *) tsdPtr->stacks[i]); |
| 1467 |
} |
| 1468 |
ckfree((char *) tsdPtr->levels); |
| 1469 |
tsdPtr->initialized = 0; |
| 1470 |
} |
| 1471 |
} |
| 1472 |
|
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
|
| 1478 |
|
| 1479 |
|
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
|
| 1484 |
|
| 1485 |
|
| 1486 |
|
| 1487 |
|
| 1488 |
|
| 1489 |
static void |
| 1490 |
OptionInit(mainPtr) |
| 1491 |
register TkMainInfo *mainPtr; |
| 1492 |
|
| 1493 |
|
| 1494 |
{ |
| 1495 |
int i; |
| 1496 |
Tcl_Interp *interp; |
| 1497 |
ThreadSpecificData *tsdPtr = (ThreadSpecificData *) |
| 1498 |
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); |
| 1499 |
Element *defaultMatchPtr = &tsdPtr->defaultMatch; |
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
|
| 1505 |
if (tsdPtr->initialized == 0) { |
| 1506 |
tsdPtr->initialized = 1; |
| 1507 |
tsdPtr->cachedWindow = NULL; |
| 1508 |
tsdPtr->numLevels = 5; |
| 1509 |
tsdPtr->curLevel = -1; |
| 1510 |
tsdPtr->serial = 0; |
| 1511 |
|
| 1512 |
tsdPtr->levels = (StackLevel *) ckalloc((unsigned) |
| 1513 |
(5*sizeof(StackLevel))); |
| 1514 |
for (i = 0; i < NUM_STACKS; i++) { |
| 1515 |
tsdPtr->stacks[i] = NewArray(10); |
| 1516 |
tsdPtr->levels[0].bases[i] = 0; |
| 1517 |
} |
| 1518 |
|
| 1519 |
defaultMatchPtr->nameUid = NULL; |
| 1520 |
defaultMatchPtr->child.valueUid = NULL; |
| 1521 |
defaultMatchPtr->priority = -1; |
| 1522 |
defaultMatchPtr->flags = 0; |
| 1523 |
Tcl_CreateThreadExitHandler(OptionThreadExitProc, NULL); |
| 1524 |
} |
| 1525 |
|
| 1526 |
|
| 1527 |
|
| 1528 |
|
| 1529 |
|
| 1530 |
|
| 1531 |
mainPtr->optionRootPtr = NewArray(20); |
| 1532 |
interp = Tcl_CreateInterp(); |
| 1533 |
(void) GetDefaultOptions(interp, mainPtr->winPtr); |
| 1534 |
Tcl_DeleteInterp(interp); |
| 1535 |
} |
| 1536 |
|
| 1537 |
|
| 1538 |
|
| 1539 |
|
| 1540 |
|
| 1541 |
|
| 1542 |
|
| 1543 |
|
| 1544 |
|
| 1545 |
|
| 1546 |
|
| 1547 |
|
| 1548 |
|
| 1549 |
|
| 1550 |
|
| 1551 |
|
| 1552 |
|
| 1553 |
|
| 1554 |
|
| 1555 |
|
| 1556 |
static void |
| 1557 |
ClearOptionTree(arrayPtr) |
| 1558 |
ElArray *arrayPtr; |
| 1559 |
|
| 1560 |
{ |
| 1561 |
register Element *elPtr; |
| 1562 |
int count; |
| 1563 |
|
| 1564 |
for (count = arrayPtr->numUsed, elPtr = arrayPtr->els; count > 0; |
| 1565 |
count--, elPtr++) { |
| 1566 |
if (elPtr->flags & NODE) { |
| 1567 |
ClearOptionTree(elPtr->child.arrayPtr); |
| 1568 |
} |
| 1569 |
} |
| 1570 |
ckfree((char *) arrayPtr); |
| 1571 |
} |
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
|
| 1576 |
|
| 1577 |
|
| 1578 |
|
| 1579 |
|
| 1580 |
|
| 1581 |
|
| 1582 |
|
| 1583 |
|
| 1584 |
|
| 1585 |
|
| 1586 |
|
| 1587 |
|
| 1588 |
|
| 1589 |
|
| 1590 |
|
| 1591 |
|
| 1592 |
|
| 1593 |
static int |
| 1594 |
GetDefaultOptions(interp, winPtr) |
| 1595 |
Tcl_Interp *interp; |
| 1596 |
TkWindow *winPtr; |
| 1597 |
|
| 1598 |
{ |
| 1599 |
char *regProp; |
| 1600 |
int result, actualFormat; |
| 1601 |
unsigned long numItems, bytesAfter; |
| 1602 |
Atom actualType; |
| 1603 |
|
| 1604 |
|
| 1605 |
|
| 1606 |
|
| 1607 |
|
| 1608 |
regProp = NULL; |
| 1609 |
result = XGetWindowProperty(winPtr->display, |
| 1610 |
RootWindow(winPtr->display, 0), |
| 1611 |
XA_RESOURCE_MANAGER, 0, 100000, |
| 1612 |
False, XA_STRING, &actualType, &actualFormat, |
| 1613 |
&numItems, &bytesAfter, (unsigned char **) ®Prop); |
| 1614 |
|
| 1615 |
if ((result == Success) && (actualType == XA_STRING) |
| 1616 |
&& (actualFormat == 8)) { |
| 1617 |
result = AddFromString(interp, (Tk_Window) winPtr, regProp, |
| 1618 |
TK_USER_DEFAULT_PRIO); |
| 1619 |
XFree(regProp); |
| 1620 |
return result; |
| 1621 |
} |
| 1622 |
|
| 1623 |
|
| 1624 |
|
| 1625 |
|
| 1626 |
|
| 1627 |
|
| 1628 |
if (regProp != NULL) { |
| 1629 |
XFree(regProp); |
| 1630 |
} |
| 1631 |
result = ReadOptionFile(interp, (Tk_Window) winPtr, "~/.Xdefaults", |
| 1632 |
TK_USER_DEFAULT_PRIO); |
| 1633 |
return result; |
| 1634 |
} |