| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#include "tkInt.h" |
| 18 |
#include "tkPort.h" |
| 19 |
#include "tkText.h" |
| 20 |
|
| 21 |
#define MIN(a,b) ((a) < (b) ? a : b) |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
typedef struct Summary { |
| 29 |
TkTextTag *tagPtr; |
| 30 |
int toggleCount; |
| 31 |
|
| 32 |
|
| 33 |
struct Summary *nextPtr; |
| 34 |
|
| 35 |
} Summary; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
typedef struct Node { |
| 42 |
struct Node *parentPtr; |
| 43 |
|
| 44 |
struct Node *nextPtr; |
| 45 |
|
| 46 |
|
| 47 |
Summary *summaryPtr; |
| 48 |
|
| 49 |
|
| 50 |
int level; |
| 51 |
|
| 52 |
|
| 53 |
union { |
| 54 |
struct Node *nodePtr; |
| 55 |
TkTextLine *linePtr; |
| 56 |
} children; |
| 57 |
int numChildren; |
| 58 |
int numLines; |
| 59 |
|
| 60 |
} Node; |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
#define MAX_CHILDREN 12 |
| 69 |
#define MIN_CHILDREN 6 |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
typedef struct BTree { |
| 76 |
Node *rootPtr; |
| 77 |
TkText *textPtr; |
| 78 |
|
| 79 |
} BTree; |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
typedef struct TagInfo { |
| 87 |
int numTags; |
| 88 |
|
| 89 |
|
| 90 |
int arraySize; |
| 91 |
|
| 92 |
TkTextTag **tagPtrs; |
| 93 |
|
| 94 |
int *counts; |
| 95 |
|
| 96 |
} TagInfo; |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
int tkBTreeDebug = 0; |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
#define CSEG_SIZE(chars) ((unsigned) (Tk_Offset(TkTextSegment, body) \ |
| 110 |
+ 1 + (chars))) |
| 111 |
#define TSEG_SIZE ((unsigned) (Tk_Offset(TkTextSegment, body) \ |
| 112 |
+ sizeof(TkTextToggle))) |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
static void ChangeNodeToggleCount _ANSI_ARGS_((Node *nodePtr, |
| 119 |
TkTextTag *tagPtr, int delta)); |
| 120 |
static void CharCheckProc _ANSI_ARGS_((TkTextSegment *segPtr, |
| 121 |
TkTextLine *linePtr)); |
| 122 |
static int CharDeleteProc _ANSI_ARGS_((TkTextSegment *segPtr, |
| 123 |
TkTextLine *linePtr, int treeGone)); |
| 124 |
static TkTextSegment * CharCleanupProc _ANSI_ARGS_((TkTextSegment *segPtr, |
| 125 |
TkTextLine *linePtr)); |
| 126 |
static TkTextSegment * CharSplitProc _ANSI_ARGS_((TkTextSegment *segPtr, |
| 127 |
int index)); |
| 128 |
static void CheckNodeConsistency _ANSI_ARGS_((Node *nodePtr)); |
| 129 |
static void CleanupLine _ANSI_ARGS_((TkTextLine *linePtr)); |
| 130 |
static void DeleteSummaries _ANSI_ARGS_((Summary *tagPtr)); |
| 131 |
static void DestroyNode _ANSI_ARGS_((Node *nodePtr)); |
| 132 |
static TkTextSegment * FindTagEnd _ANSI_ARGS_((TkTextBTree tree, |
| 133 |
TkTextTag *tagPtr, TkTextIndex *indexPtr)); |
| 134 |
static void IncCount _ANSI_ARGS_((TkTextTag *tagPtr, int inc, |
| 135 |
TagInfo *tagInfoPtr)); |
| 136 |
static void Rebalance _ANSI_ARGS_((BTree *treePtr, Node *nodePtr)); |
| 137 |
static void RecomputeNodeCounts _ANSI_ARGS_((Node *nodePtr)); |
| 138 |
static TkTextSegment * SplitSeg _ANSI_ARGS_((TkTextIndex *indexPtr)); |
| 139 |
static void ToggleCheckProc _ANSI_ARGS_((TkTextSegment *segPtr, |
| 140 |
TkTextLine *linePtr)); |
| 141 |
static TkTextSegment * ToggleCleanupProc _ANSI_ARGS_((TkTextSegment *segPtr, |
| 142 |
TkTextLine *linePtr)); |
| 143 |
static int ToggleDeleteProc _ANSI_ARGS_((TkTextSegment *segPtr, |
| 144 |
TkTextLine *linePtr, int treeGone)); |
| 145 |
static void ToggleLineChangeProc _ANSI_ARGS_((TkTextSegment *segPtr, |
| 146 |
TkTextLine *linePtr)); |
| 147 |
static TkTextSegment * FindTagStart _ANSI_ARGS_((TkTextBTree tree, |
| 148 |
TkTextTag *tagPtr, TkTextIndex *indexPtr)); |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
Tk_SegType tkTextCharType = { |
| 155 |
"character", |
| 156 |
0, |
| 157 |
CharSplitProc, |
| 158 |
CharDeleteProc, |
| 159 |
CharCleanupProc, |
| 160 |
(Tk_SegLineChangeProc *) NULL, |
| 161 |
TkTextCharLayoutProc, |
| 162 |
CharCheckProc |
| 163 |
}; |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
Tk_SegType tkTextToggleOnType = { |
| 171 |
"toggleOn", |
| 172 |
0, |
| 173 |
(Tk_SegSplitProc *) NULL, |
| 174 |
ToggleDeleteProc, |
| 175 |
ToggleCleanupProc, |
| 176 |
ToggleLineChangeProc, |
| 177 |
(Tk_SegLayoutProc *) NULL, |
| 178 |
ToggleCheckProc |
| 179 |
}; |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
Tk_SegType tkTextToggleOffType = { |
| 187 |
"toggleOff", |
| 188 |
1, |
| 189 |
(Tk_SegSplitProc *) NULL, |
| 190 |
ToggleDeleteProc, |
| 191 |
ToggleCleanupProc, |
| 192 |
ToggleLineChangeProc, |
| 193 |
(Tk_SegLayoutProc *) NULL, |
| 194 |
ToggleCheckProc |
| 195 |
}; |
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
TkTextBTree |
| 215 |
TkBTreeCreate(textPtr) |
| 216 |
TkText *textPtr; |
| 217 |
{ |
| 218 |
register BTree *treePtr; |
| 219 |
register Node *rootPtr; |
| 220 |
register TkTextLine *linePtr, *linePtr2; |
| 221 |
register TkTextSegment *segPtr; |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
rootPtr = (Node *) ckalloc(sizeof(Node)); |
| 231 |
linePtr = (TkTextLine *) ckalloc(sizeof(TkTextLine)); |
| 232 |
linePtr2 = (TkTextLine *) ckalloc(sizeof(TkTextLine)); |
| 233 |
rootPtr->parentPtr = NULL; |
| 234 |
rootPtr->nextPtr = NULL; |
| 235 |
rootPtr->summaryPtr = NULL; |
| 236 |
rootPtr->level = 0; |
| 237 |
rootPtr->children.linePtr = linePtr; |
| 238 |
rootPtr->numChildren = 2; |
| 239 |
rootPtr->numLines = 2; |
| 240 |
|
| 241 |
linePtr->parentPtr = rootPtr; |
| 242 |
linePtr->nextPtr = linePtr2; |
| 243 |
segPtr = (TkTextSegment *) ckalloc(CSEG_SIZE(1)); |
| 244 |
linePtr->segPtr = segPtr; |
| 245 |
segPtr->typePtr = &tkTextCharType; |
| 246 |
segPtr->nextPtr = NULL; |
| 247 |
segPtr->size = 1; |
| 248 |
segPtr->body.chars[0] = '\n'; |
| 249 |
segPtr->body.chars[1] = 0; |
| 250 |
|
| 251 |
linePtr2->parentPtr = rootPtr; |
| 252 |
linePtr2->nextPtr = NULL; |
| 253 |
segPtr = (TkTextSegment *) ckalloc(CSEG_SIZE(1)); |
| 254 |
linePtr2->segPtr = segPtr; |
| 255 |
segPtr->typePtr = &tkTextCharType; |
| 256 |
segPtr->nextPtr = NULL; |
| 257 |
segPtr->size = 1; |
| 258 |
segPtr->body.chars[0] = '\n'; |
| 259 |
segPtr->body.chars[1] = 0; |
| 260 |
|
| 261 |
treePtr = (BTree *) ckalloc(sizeof(BTree)); |
| 262 |
treePtr->rootPtr = rootPtr; |
| 263 |
treePtr->textPtr = textPtr; |
| 264 |
|
| 265 |
return (TkTextBTree) treePtr; |
| 266 |
} |
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
void |
| 286 |
TkBTreeDestroy(tree) |
| 287 |
TkTextBTree tree; |
| 288 |
{ |
| 289 |
BTree *treePtr = (BTree *) tree; |
| 290 |
|
| 291 |
DestroyNode(treePtr->rootPtr); |
| 292 |
ckfree((char *) treePtr); |
| 293 |
} |
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
static void |
| 313 |
DestroyNode(nodePtr) |
| 314 |
register Node *nodePtr; |
| 315 |
{ |
| 316 |
if (nodePtr->level == 0) { |
| 317 |
TkTextLine *linePtr; |
| 318 |
TkTextSegment *segPtr; |
| 319 |
|
| 320 |
while (nodePtr->children.linePtr != NULL) { |
| 321 |
linePtr = nodePtr->children.linePtr; |
| 322 |
nodePtr->children.linePtr = linePtr->nextPtr; |
| 323 |
while (linePtr->segPtr != NULL) { |
| 324 |
segPtr = linePtr->segPtr; |
| 325 |
linePtr->segPtr = segPtr->nextPtr; |
| 326 |
(*segPtr->typePtr->deleteProc)(segPtr, linePtr, 1); |
| 327 |
} |
| 328 |
ckfree((char *) linePtr); |
| 329 |
} |
| 330 |
} else { |
| 331 |
register Node *childPtr; |
| 332 |
|
| 333 |
while (nodePtr->children.nodePtr != NULL) { |
| 334 |
childPtr = nodePtr->children.nodePtr; |
| 335 |
nodePtr->children.nodePtr = childPtr->nextPtr; |
| 336 |
DestroyNode(childPtr); |
| 337 |
} |
| 338 |
} |
| 339 |
DeleteSummaries(nodePtr->summaryPtr); |
| 340 |
ckfree((char *) nodePtr); |
| 341 |
} |
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
static void |
| 361 |
DeleteSummaries(summaryPtr) |
| 362 |
register Summary *summaryPtr; |
| 363 |
|
| 364 |
{ |
| 365 |
register Summary *nextPtr; |
| 366 |
while (summaryPtr != NULL) { |
| 367 |
nextPtr = summaryPtr->nextPtr; |
| 368 |
ckfree((char *) summaryPtr); |
| 369 |
summaryPtr = nextPtr; |
| 370 |
} |
| 371 |
} |
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
void |
| 392 |
TkBTreeInsertChars(indexPtr, string) |
| 393 |
register TkTextIndex *indexPtr; |
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
CONST char *string; |
| 399 |
|
| 400 |
|
| 401 |
{ |
| 402 |
register Node *nodePtr; |
| 403 |
register TkTextSegment *prevPtr; |
| 404 |
|
| 405 |
|
| 406 |
TkTextSegment *curPtr; |
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
TkTextLine *linePtr; |
| 411 |
|
| 412 |
register TkTextSegment *segPtr; |
| 413 |
TkTextLine *newLinePtr; |
| 414 |
int chunkSize; |
| 415 |
register CONST char *eol; |
| 416 |
|
| 417 |
int changeToLineCount; |
| 418 |
|
| 419 |
|
| 420 |
prevPtr = SplitSeg(indexPtr); |
| 421 |
linePtr = indexPtr->linePtr; |
| 422 |
curPtr = prevPtr; |
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
changeToLineCount = 0; |
| 431 |
while (*string != 0) { |
| 432 |
for (eol = string; *eol != 0; eol++) { |
| 433 |
if (*eol == '\n') { |
| 434 |
eol++; |
| 435 |
break; |
| 436 |
} |
| 437 |
} |
| 438 |
chunkSize = eol-string; |
| 439 |
segPtr = (TkTextSegment *) ckalloc(CSEG_SIZE(chunkSize)); |
| 440 |
segPtr->typePtr = &tkTextCharType; |
| 441 |
if (curPtr == NULL) { |
| 442 |
segPtr->nextPtr = linePtr->segPtr; |
| 443 |
linePtr->segPtr = segPtr; |
| 444 |
} else { |
| 445 |
segPtr->nextPtr = curPtr->nextPtr; |
| 446 |
curPtr->nextPtr = segPtr; |
| 447 |
} |
| 448 |
segPtr->size = chunkSize; |
| 449 |
memcpy(segPtr->body.chars, string, MIN(chunkSize, strlen(string) + 1)); |
| 450 |
segPtr->body.chars[chunkSize] = 0; |
| 451 |
|
| 452 |
if (eol[-1] != '\n') { |
| 453 |
break; |
| 454 |
} |
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
newLinePtr = (TkTextLine *) ckalloc(sizeof(TkTextLine)); |
| 462 |
newLinePtr->parentPtr = linePtr->parentPtr; |
| 463 |
newLinePtr->nextPtr = linePtr->nextPtr; |
| 464 |
linePtr->nextPtr = newLinePtr; |
| 465 |
newLinePtr->segPtr = segPtr->nextPtr; |
| 466 |
segPtr->nextPtr = NULL; |
| 467 |
linePtr = newLinePtr; |
| 468 |
curPtr = NULL; |
| 469 |
changeToLineCount++; |
| 470 |
|
| 471 |
string = eol; |
| 472 |
} |
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
CleanupLine(indexPtr->linePtr); |
| 480 |
if (linePtr != indexPtr->linePtr) { |
| 481 |
CleanupLine(linePtr); |
| 482 |
} |
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
for (nodePtr = linePtr->parentPtr ; nodePtr != NULL; |
| 490 |
nodePtr = nodePtr->parentPtr) { |
| 491 |
nodePtr->numLines += changeToLineCount; |
| 492 |
} |
| 493 |
nodePtr = linePtr->parentPtr; |
| 494 |
nodePtr->numChildren += changeToLineCount; |
| 495 |
if (nodePtr->numChildren > MAX_CHILDREN) { |
| 496 |
Rebalance((BTree *) indexPtr->tree, nodePtr); |
| 497 |
} |
| 498 |
|
| 499 |
if (tkBTreeDebug) { |
| 500 |
TkBTreeCheck(indexPtr->tree); |
| 501 |
} |
| 502 |
} |
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
static TkTextSegment * |
| 533 |
SplitSeg(indexPtr) |
| 534 |
TkTextIndex *indexPtr; |
| 535 |
|
| 536 |
{ |
| 537 |
TkTextSegment *prevPtr, *segPtr; |
| 538 |
int count; |
| 539 |
|
| 540 |
for (count = indexPtr->byteIndex, prevPtr = NULL, |
| 541 |
segPtr = indexPtr->linePtr->segPtr; segPtr != NULL; |
| 542 |
count -= segPtr->size, prevPtr = segPtr, segPtr = segPtr->nextPtr) { |
| 543 |
if (segPtr->size > count) { |
| 544 |
if (count == 0) { |
| 545 |
return prevPtr; |
| 546 |
} |
| 547 |
segPtr = (*segPtr->typePtr->splitProc)(segPtr, count); |
| 548 |
if (prevPtr == NULL) { |
| 549 |
indexPtr->linePtr->segPtr = segPtr; |
| 550 |
} else { |
| 551 |
prevPtr->nextPtr = segPtr; |
| 552 |
} |
| 553 |
return segPtr; |
| 554 |
} else if ((segPtr->size == 0) && (count == 0) |
| 555 |
&& !segPtr->typePtr->leftGravity) { |
| 556 |
return prevPtr; |
| 557 |
} |
| 558 |
} |
| 559 |
panic("SplitSeg reached end of line!"); |
| 560 |
return NULL; |
| 561 |
} |
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
static void |
| 584 |
CleanupLine(linePtr) |
| 585 |
TkTextLine *linePtr; |
| 586 |
{ |
| 587 |
TkTextSegment *segPtr, **prevPtrPtr; |
| 588 |
int anyChanges; |
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
while (1) { |
| 601 |
anyChanges = 0; |
| 602 |
for (prevPtrPtr = &linePtr->segPtr, segPtr = *prevPtrPtr; |
| 603 |
segPtr != NULL; |
| 604 |
prevPtrPtr = &(*prevPtrPtr)->nextPtr, segPtr = *prevPtrPtr) { |
| 605 |
if (segPtr->typePtr->cleanupProc != NULL) { |
| 606 |
*prevPtrPtr = (*segPtr->typePtr->cleanupProc)(segPtr, linePtr); |
| 607 |
if (segPtr != *prevPtrPtr) { |
| 608 |
anyChanges = 1; |
| 609 |
} |
| 610 |
} |
| 611 |
} |
| 612 |
if (!anyChanges) { |
| 613 |
break; |
| 614 |
} |
| 615 |
} |
| 616 |
} |
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
void |
| 641 |
TkBTreeDeleteChars(index1Ptr, index2Ptr) |
| 642 |
register TkTextIndex *index1Ptr; |
| 643 |
|
| 644 |
register TkTextIndex *index2Ptr; |
| 645 |
|
| 646 |
{ |
| 647 |
TkTextSegment *prevPtr; |
| 648 |
|
| 649 |
TkTextSegment *lastPtr; |
| 650 |
|
| 651 |
TkTextSegment *segPtr, *nextPtr; |
| 652 |
TkTextLine *curLinePtr; |
| 653 |
Node *curNodePtr, *nodePtr; |
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
lastPtr = SplitSeg(index2Ptr); |
| 661 |
if (lastPtr != NULL) { |
| 662 |
lastPtr = lastPtr->nextPtr; |
| 663 |
} else { |
| 664 |
lastPtr = index2Ptr->linePtr->segPtr; |
| 665 |
} |
| 666 |
prevPtr = SplitSeg(index1Ptr); |
| 667 |
if (prevPtr != NULL) { |
| 668 |
segPtr = prevPtr->nextPtr; |
| 669 |
prevPtr->nextPtr = lastPtr; |
| 670 |
} else { |
| 671 |
segPtr = index1Ptr->linePtr->segPtr; |
| 672 |
index1Ptr->linePtr->segPtr = lastPtr; |
| 673 |
} |
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
curLinePtr = index1Ptr->linePtr; |
| 680 |
curNodePtr = curLinePtr->parentPtr; |
| 681 |
while (segPtr != lastPtr) { |
| 682 |
if (segPtr == NULL) { |
| 683 |
TkTextLine *nextLinePtr; |
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
nextLinePtr = TkBTreeNextLine(curLinePtr); |
| 692 |
if (curLinePtr != index1Ptr->linePtr) { |
| 693 |
if (curNodePtr == index1Ptr->linePtr->parentPtr) { |
| 694 |
index1Ptr->linePtr->nextPtr = curLinePtr->nextPtr; |
| 695 |
} else { |
| 696 |
curNodePtr->children.linePtr = curLinePtr->nextPtr; |
| 697 |
} |
| 698 |
for (nodePtr = curNodePtr; nodePtr != NULL; |
| 699 |
nodePtr = nodePtr->parentPtr) { |
| 700 |
nodePtr->numLines--; |
| 701 |
} |
| 702 |
curNodePtr->numChildren--; |
| 703 |
ckfree((char *) curLinePtr); |
| 704 |
} |
| 705 |
curLinePtr = nextLinePtr; |
| 706 |
segPtr = curLinePtr->segPtr; |
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
while (curNodePtr->numChildren == 0) { |
| 714 |
Node *parentPtr; |
| 715 |
|
| 716 |
parentPtr = curNodePtr->parentPtr; |
| 717 |
if (parentPtr->children.nodePtr == curNodePtr) { |
| 718 |
parentPtr->children.nodePtr = curNodePtr->nextPtr; |
| 719 |
} else { |
| 720 |
Node *prevNodePtr = parentPtr->children.nodePtr; |
| 721 |
while (prevNodePtr->nextPtr != curNodePtr) { |
| 722 |
prevNodePtr = prevNodePtr->nextPtr; |
| 723 |
} |
| 724 |
prevNodePtr->nextPtr = curNodePtr->nextPtr; |
| 725 |
} |
| 726 |
parentPtr->numChildren--; |
| 727 |
ckfree((char *) curNodePtr); |
| 728 |
curNodePtr = parentPtr; |
| 729 |
} |
| 730 |
curNodePtr = curLinePtr->parentPtr; |
| 731 |
continue; |
| 732 |
} |
| 733 |
|
| 734 |
nextPtr = segPtr->nextPtr; |
| 735 |
if ((*segPtr->typePtr->deleteProc)(segPtr, curLinePtr, 0) != 0) { |
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
if (prevPtr == NULL) { |
| 742 |
segPtr->nextPtr = index1Ptr->linePtr->segPtr; |
| 743 |
index1Ptr->linePtr->segPtr = segPtr; |
| 744 |
} else { |
| 745 |
segPtr->nextPtr = prevPtr->nextPtr; |
| 746 |
prevPtr->nextPtr = segPtr; |
| 747 |
} |
| 748 |
if (segPtr->typePtr->leftGravity) { |
| 749 |
prevPtr = segPtr; |
| 750 |
} |
| 751 |
} |
| 752 |
segPtr = nextPtr; |
| 753 |
} |
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
if (index1Ptr->linePtr != index2Ptr->linePtr) { |
| 761 |
TkTextLine *prevLinePtr; |
| 762 |
|
| 763 |
for (segPtr = lastPtr; segPtr != NULL; |
| 764 |
segPtr = segPtr->nextPtr) { |
| 765 |
if (segPtr->typePtr->lineChangeProc != NULL) { |
| 766 |
(*segPtr->typePtr->lineChangeProc)(segPtr, index2Ptr->linePtr); |
| 767 |
} |
| 768 |
} |
| 769 |
curNodePtr = index2Ptr->linePtr->parentPtr; |
| 770 |
for (nodePtr = curNodePtr; nodePtr != NULL; |
| 771 |
nodePtr = nodePtr->parentPtr) { |
| 772 |
nodePtr->numLines--; |
| 773 |
} |
| 774 |
curNodePtr->numChildren--; |
| 775 |
prevLinePtr = curNodePtr->children.linePtr; |
| 776 |
if (prevLinePtr == index2Ptr->linePtr) { |
| 777 |
curNodePtr->children.linePtr = index2Ptr->linePtr->nextPtr; |
| 778 |
} else { |
| 779 |
while (prevLinePtr->nextPtr != index2Ptr->linePtr) { |
| 780 |
prevLinePtr = prevLinePtr->nextPtr; |
| 781 |
} |
| 782 |
prevLinePtr->nextPtr = index2Ptr->linePtr->nextPtr; |
| 783 |
} |
| 784 |
ckfree((char *) index2Ptr->linePtr); |
| 785 |
Rebalance((BTree *) index2Ptr->tree, curNodePtr); |
| 786 |
} |
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
CleanupLine(index1Ptr->linePtr); |
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
Rebalance((BTree *) index1Ptr->tree, index1Ptr->linePtr->parentPtr); |
| 799 |
if (tkBTreeDebug) { |
| 800 |
TkBTreeCheck(index1Ptr->tree); |
| 801 |
} |
| 802 |
} |
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
TkTextLine * |
| 822 |
TkBTreeFindLine(tree, line) |
| 823 |
TkTextBTree tree; |
| 824 |
int line; |
| 825 |
{ |
| 826 |
BTree *treePtr = (BTree *) tree; |
| 827 |
register Node *nodePtr; |
| 828 |
register TkTextLine *linePtr; |
| 829 |
int linesLeft; |
| 830 |
|
| 831 |
nodePtr = treePtr->rootPtr; |
| 832 |
linesLeft = line; |
| 833 |
if ((line < 0) || (line >= nodePtr->numLines)) { |
| 834 |
return NULL; |
| 835 |
} |
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
while (nodePtr->level != 0) { |
| 843 |
for (nodePtr = nodePtr->children.nodePtr; |
| 844 |
nodePtr->numLines <= linesLeft; |
| 845 |
nodePtr = nodePtr->nextPtr) { |
| 846 |
if (nodePtr == NULL) { |
| 847 |
panic("TkBTreeFindLine ran out of nodes"); |
| 848 |
} |
| 849 |
linesLeft -= nodePtr->numLines; |
| 850 |
} |
| 851 |
} |
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
for (linePtr = nodePtr->children.linePtr; linesLeft > 0; |
| 858 |
linePtr = linePtr->nextPtr) { |
| 859 |
if (linePtr == NULL) { |
| 860 |
panic("TkBTreeFindLine ran out of lines"); |
| 861 |
} |
| 862 |
linesLeft -= 1; |
| 863 |
} |
| 864 |
return linePtr; |
| 865 |
} |
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
TkTextLine * |
| 887 |
TkBTreeNextLine(linePtr) |
| 888 |
register TkTextLine *linePtr; |
| 889 |
|
| 890 |
{ |
| 891 |
register Node *nodePtr; |
| 892 |
|
| 893 |
if (linePtr->nextPtr != NULL) { |
| 894 |
return linePtr->nextPtr; |
| 895 |
} |
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
for (nodePtr = linePtr->parentPtr; ; nodePtr = nodePtr->parentPtr) { |
| 904 |
if (nodePtr->nextPtr != NULL) { |
| 905 |
nodePtr = nodePtr->nextPtr; |
| 906 |
break; |
| 907 |
} |
| 908 |
if (nodePtr->parentPtr == NULL) { |
| 909 |
return (TkTextLine *) NULL; |
| 910 |
} |
| 911 |
} |
| 912 |
while (nodePtr->level > 0) { |
| 913 |
nodePtr = nodePtr->children.nodePtr; |
| 914 |
} |
| 915 |
return nodePtr->children.linePtr; |
| 916 |
} |
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
TkTextLine * |
| 938 |
TkBTreePreviousLine(linePtr) |
| 939 |
register TkTextLine *linePtr; |
| 940 |
|
| 941 |
{ |
| 942 |
register Node *nodePtr; |
| 943 |
register Node *node2Ptr; |
| 944 |
register TkTextLine *prevPtr; |
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
prevPtr = linePtr->parentPtr->children.linePtr; |
| 950 |
while (prevPtr != linePtr) { |
| 951 |
if (prevPtr->nextPtr == linePtr) { |
| 952 |
return prevPtr; |
| 953 |
} |
| 954 |
prevPtr = prevPtr->nextPtr; |
| 955 |
if (prevPtr == (TkTextLine *) NULL) { |
| 956 |
panic("TkBTreePreviousLine ran out of lines"); |
| 957 |
} |
| 958 |
} |
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
for (nodePtr = linePtr->parentPtr; ; nodePtr = nodePtr->parentPtr) { |
| 966 |
if (nodePtr == (Node *) NULL || nodePtr->parentPtr == (Node *) NULL) { |
| 967 |
return (TkTextLine *) NULL; |
| 968 |
} |
| 969 |
if (nodePtr != nodePtr->parentPtr->children.nodePtr) { |
| 970 |
break; |
| 971 |
} |
| 972 |
} |
| 973 |
for (node2Ptr = nodePtr->parentPtr->children.nodePtr; ; |
| 974 |
node2Ptr = node2Ptr->children.nodePtr) { |
| 975 |
while (node2Ptr->nextPtr != nodePtr) { |
| 976 |
node2Ptr = node2Ptr->nextPtr; |
| 977 |
} |
| 978 |
if (node2Ptr->level == 0) { |
| 979 |
break; |
| 980 |
} |
| 981 |
nodePtr = (Node *)NULL; |
| 982 |
} |
| 983 |
for (prevPtr = node2Ptr->children.linePtr ; ; prevPtr = prevPtr->nextPtr) { |
| 984 |
if (prevPtr->nextPtr == (TkTextLine *) NULL) { |
| 985 |
return prevPtr; |
| 986 |
} |
| 987 |
} |
| 988 |
} |
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
int |
| 1009 |
TkBTreeLineIndex(linePtr) |
| 1010 |
TkTextLine *linePtr; |
| 1011 |
|
| 1012 |
{ |
| 1013 |
register TkTextLine *linePtr2; |
| 1014 |
register Node *nodePtr, *parentPtr, *nodePtr2; |
| 1015 |
int index; |
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
nodePtr = linePtr->parentPtr; |
| 1023 |
index = 0; |
| 1024 |
for (linePtr2 = nodePtr->children.linePtr; linePtr2 != linePtr; |
| 1025 |
linePtr2 = linePtr2->nextPtr) { |
| 1026 |
if (linePtr2 == NULL) { |
| 1027 |
panic("TkBTreeLineIndex couldn't find line"); |
| 1028 |
} |
| 1029 |
index += 1; |
| 1030 |
} |
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
for (parentPtr = nodePtr->parentPtr ; parentPtr != NULL; |
| 1039 |
nodePtr = parentPtr, parentPtr = parentPtr->parentPtr) { |
| 1040 |
for (nodePtr2 = parentPtr->children.nodePtr; nodePtr2 != nodePtr; |
| 1041 |
nodePtr2 = nodePtr2->nextPtr) { |
| 1042 |
if (nodePtr2 == NULL) { |
| 1043 |
panic("TkBTreeLineIndex couldn't find node"); |
| 1044 |
} |
| 1045 |
index += nodePtr2->numLines; |
| 1046 |
} |
| 1047 |
} |
| 1048 |
return index; |
| 1049 |
} |
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
void |
| 1070 |
TkBTreeLinkSegment(segPtr, indexPtr) |
| 1071 |
TkTextSegment *segPtr; |
| 1072 |
|
| 1073 |
|
| 1074 |
TkTextIndex *indexPtr; |
| 1075 |
|
| 1076 |
|
| 1077 |
{ |
| 1078 |
register TkTextSegment *prevPtr; |
| 1079 |
|
| 1080 |
prevPtr = SplitSeg(indexPtr); |
| 1081 |
if (prevPtr == NULL) { |
| 1082 |
segPtr->nextPtr = indexPtr->linePtr->segPtr; |
| 1083 |
indexPtr->linePtr->segPtr = segPtr; |
| 1084 |
} else { |
| 1085 |
segPtr->nextPtr = prevPtr->nextPtr; |
| 1086 |
prevPtr->nextPtr = segPtr; |
| 1087 |
} |
| 1088 |
CleanupLine(indexPtr->linePtr); |
| 1089 |
if (tkBTreeDebug) { |
| 1090 |
TkBTreeCheck(indexPtr->tree); |
| 1091 |
} |
| 1092 |
} |
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
void |
| 1113 |
TkBTreeUnlinkSegment(tree, segPtr, linePtr) |
| 1114 |
TkTextBTree tree; |
| 1115 |
TkTextSegment *segPtr; |
| 1116 |
TkTextLine *linePtr; |
| 1117 |
|
| 1118 |
{ |
| 1119 |
register TkTextSegment *prevPtr; |
| 1120 |
|
| 1121 |
if (linePtr->segPtr == segPtr) { |
| 1122 |
linePtr->segPtr = segPtr->nextPtr; |
| 1123 |
} else { |
| 1124 |
for (prevPtr = linePtr->segPtr; prevPtr->nextPtr != segPtr; |
| 1125 |
prevPtr = prevPtr->nextPtr) { |
| 1126 |
|
| 1127 |
} |
| 1128 |
prevPtr->nextPtr = segPtr->nextPtr; |
| 1129 |
} |
| 1130 |
CleanupLine(linePtr); |
| 1131 |
} |
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
void |
| 1156 |
TkBTreeTag(index1Ptr, index2Ptr, tagPtr, add) |
| 1157 |
register TkTextIndex *index1Ptr; |
| 1158 |
|
| 1159 |
register TkTextIndex *index2Ptr; |
| 1160 |
|
| 1161 |
TkTextTag *tagPtr; |
| 1162 |
int add; |
| 1163 |
|
| 1164 |
|
| 1165 |
{ |
| 1166 |
TkTextSegment *segPtr, *prevPtr; |
| 1167 |
TkTextSearch search; |
| 1168 |
TkTextLine *cleanupLinePtr; |
| 1169 |
int oldState; |
| 1170 |
int changed; |
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
oldState = TkBTreeCharTagged(index1Ptr, tagPtr); |
| 1179 |
if ((add != 0) ^ oldState) { |
| 1180 |
segPtr = (TkTextSegment *) ckalloc(TSEG_SIZE); |
| 1181 |
segPtr->typePtr = (add) ? &tkTextToggleOnType : &tkTextToggleOffType; |
| 1182 |
prevPtr = SplitSeg(index1Ptr); |
| 1183 |
if (prevPtr == NULL) { |
| 1184 |
segPtr->nextPtr = index1Ptr->linePtr->segPtr; |
| 1185 |
index1Ptr->linePtr->segPtr = segPtr; |
| 1186 |
} else { |
| 1187 |
segPtr->nextPtr = prevPtr->nextPtr; |
| 1188 |
prevPtr->nextPtr = segPtr; |
| 1189 |
} |
| 1190 |
segPtr->size = 0; |
| 1191 |
segPtr->body.toggle.tagPtr = tagPtr; |
| 1192 |
segPtr->body.toggle.inNodeCounts = 0; |
| 1193 |
} |
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
TkBTreeStartSearch(index1Ptr, index2Ptr, tagPtr, &search); |
| 1202 |
cleanupLinePtr = index1Ptr->linePtr; |
| 1203 |
while (TkBTreeNextTag(&search)) { |
| 1204 |
oldState ^= 1; |
| 1205 |
segPtr = search.segPtr; |
| 1206 |
prevPtr = search.curIndex.linePtr->segPtr; |
| 1207 |
if (prevPtr == segPtr) { |
| 1208 |
search.curIndex.linePtr->segPtr = segPtr->nextPtr; |
| 1209 |
} else { |
| 1210 |
while (prevPtr->nextPtr != segPtr) { |
| 1211 |
prevPtr = prevPtr->nextPtr; |
| 1212 |
} |
| 1213 |
prevPtr->nextPtr = segPtr->nextPtr; |
| 1214 |
} |
| 1215 |
if (segPtr->body.toggle.inNodeCounts) { |
| 1216 |
ChangeNodeToggleCount(search.curIndex.linePtr->parentPtr, |
| 1217 |
segPtr->body.toggle.tagPtr, -1); |
| 1218 |
segPtr->body.toggle.inNodeCounts = 0; |
| 1219 |
changed = 1; |
| 1220 |
} else { |
| 1221 |
changed = 0; |
| 1222 |
} |
| 1223 |
ckfree((char *) segPtr); |
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
if (cleanupLinePtr != search.curIndex.linePtr) { |
| 1236 |
CleanupLine(cleanupLinePtr); |
| 1237 |
cleanupLinePtr = search.curIndex.linePtr; |
| 1238 |
} |
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
if (changed) { |
| 1245 |
TkBTreeStartSearch(index1Ptr, index2Ptr, tagPtr, &search); |
| 1246 |
} |
| 1247 |
} |
| 1248 |
if ((add != 0) ^ oldState) { |
| 1249 |
segPtr = (TkTextSegment *) ckalloc(TSEG_SIZE); |
| 1250 |
segPtr->typePtr = (add) ? &tkTextToggleOffType : &tkTextToggleOnType; |
| 1251 |
prevPtr = SplitSeg(index2Ptr); |
| 1252 |
if (prevPtr == NULL) { |
| 1253 |
segPtr->nextPtr = index2Ptr->linePtr->segPtr; |
| 1254 |
index2Ptr->linePtr->segPtr = segPtr; |
| 1255 |
} else { |
| 1256 |
segPtr->nextPtr = prevPtr->nextPtr; |
| 1257 |
prevPtr->nextPtr = segPtr; |
| 1258 |
} |
| 1259 |
segPtr->size = 0; |
| 1260 |
segPtr->body.toggle.tagPtr = tagPtr; |
| 1261 |
segPtr->body.toggle.inNodeCounts = 0; |
| 1262 |
} |
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
CleanupLine(cleanupLinePtr); |
| 1270 |
if (cleanupLinePtr != index2Ptr->linePtr) { |
| 1271 |
CleanupLine(index2Ptr->linePtr); |
| 1272 |
} |
| 1273 |
|
| 1274 |
if (tkBTreeDebug) { |
| 1275 |
TkBTreeCheck(index1Ptr->tree); |
| 1276 |
} |
| 1277 |
} |
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
|
| 1282 |
|
| 1283 |
|
| 1284 |
|
| 1285 |
|
| 1286 |
|
| 1287 |
|
| 1288 |
|
| 1289 |
|
| 1290 |
|
| 1291 |
|
| 1292 |
|
| 1293 |
|
| 1294 |
|
| 1295 |
|
| 1296 |
|
| 1297 |
|
| 1298 |
|
| 1299 |
static void |
| 1300 |
ChangeNodeToggleCount(nodePtr, tagPtr, delta) |
| 1301 |
register Node *nodePtr; |
| 1302 |
|
| 1303 |
TkTextTag *tagPtr; |
| 1304 |
int delta; |
| 1305 |
|
| 1306 |
{ |
| 1307 |
register Summary *summaryPtr, *prevPtr; |
| 1308 |
register Node *node2Ptr; |
| 1309 |
int rootLevel; |
| 1310 |
|
| 1311 |
tagPtr->toggleCount += delta; |
| 1312 |
if (tagPtr->tagRootPtr == (Node *) NULL) { |
| 1313 |
tagPtr->tagRootPtr = nodePtr; |
| 1314 |
return; |
| 1315 |
} |
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
rootLevel = tagPtr->tagRootPtr->level; |
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
for ( ; nodePtr != tagPtr->tagRootPtr; nodePtr = nodePtr->parentPtr) { |
| 1331 |
|
| 1332 |
|
| 1333 |
|
| 1334 |
|
| 1335 |
|
| 1336 |
for (prevPtr = NULL, summaryPtr = nodePtr->summaryPtr; |
| 1337 |
summaryPtr != NULL; |
| 1338 |
prevPtr = summaryPtr, summaryPtr = summaryPtr->nextPtr) { |
| 1339 |
if (summaryPtr->tagPtr == tagPtr) { |
| 1340 |
break; |
| 1341 |
} |
| 1342 |
} |
| 1343 |
if (summaryPtr != NULL) { |
| 1344 |
summaryPtr->toggleCount += delta; |
| 1345 |
if (summaryPtr->toggleCount > 0 && |
| 1346 |
summaryPtr->toggleCount < tagPtr->toggleCount) { |
| 1347 |
continue; |
| 1348 |
} |
| 1349 |
if (summaryPtr->toggleCount != 0) { |
| 1350 |
|
| 1351 |
|
| 1352 |
|
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
panic("ChangeNodeToggleCount: bad toggle count (%d) max (%d)", |
| 1357 |
summaryPtr->toggleCount, tagPtr->toggleCount); |
| 1358 |
} |
| 1359 |
|
| 1360 |
|
| 1361 |
|
| 1362 |
|
| 1363 |
|
| 1364 |
if (prevPtr == NULL) { |
| 1365 |
nodePtr->summaryPtr = summaryPtr->nextPtr; |
| 1366 |
} else { |
| 1367 |
prevPtr->nextPtr = summaryPtr->nextPtr; |
| 1368 |
} |
| 1369 |
ckfree((char *) summaryPtr); |
| 1370 |
} else { |
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
|
| 1375 |
if (rootLevel == nodePtr->level) { |
| 1376 |
|
| 1377 |
|
| 1378 |
|
| 1379 |
|
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
Node *rootNodePtr = tagPtr->tagRootPtr; |
| 1389 |
summaryPtr = (Summary *) ckalloc(sizeof(Summary)); |
| 1390 |
summaryPtr->tagPtr = tagPtr; |
| 1391 |
summaryPtr->toggleCount = tagPtr->toggleCount - delta; |
| 1392 |
summaryPtr->nextPtr = rootNodePtr->summaryPtr; |
| 1393 |
rootNodePtr->summaryPtr = summaryPtr; |
| 1394 |
rootNodePtr = rootNodePtr->parentPtr; |
| 1395 |
rootLevel = rootNodePtr->level; |
| 1396 |
tagPtr->tagRootPtr = rootNodePtr; |
| 1397 |
} |
| 1398 |
summaryPtr = (Summary *) ckalloc(sizeof(Summary)); |
| 1399 |
summaryPtr->tagPtr = tagPtr; |
| 1400 |
summaryPtr->toggleCount = delta; |
| 1401 |
summaryPtr->nextPtr = nodePtr->summaryPtr; |
| 1402 |
nodePtr->summaryPtr = summaryPtr; |
| 1403 |
} |
| 1404 |
} |
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
if (delta >= 0) { |
| 1412 |
return; |
| 1413 |
} |
| 1414 |
if (tagPtr->toggleCount == 0) { |
| 1415 |
tagPtr->tagRootPtr = (Node *) NULL; |
| 1416 |
return; |
| 1417 |
} |
| 1418 |
nodePtr = tagPtr->tagRootPtr; |
| 1419 |
while (nodePtr->level > 0) { |
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
for (node2Ptr = nodePtr->children.nodePtr; |
| 1426 |
node2Ptr != (Node *)NULL ; |
| 1427 |
node2Ptr = node2Ptr->nextPtr) { |
| 1428 |
for (prevPtr = NULL, summaryPtr = node2Ptr->summaryPtr; |
| 1429 |
summaryPtr != NULL; |
| 1430 |
prevPtr = summaryPtr, summaryPtr = summaryPtr->nextPtr) { |
| 1431 |
if (summaryPtr->tagPtr == tagPtr) { |
| 1432 |
break; |
| 1433 |
} |
| 1434 |
} |
| 1435 |
if (summaryPtr == NULL) { |
| 1436 |
continue; |
| 1437 |
} |
| 1438 |
if (summaryPtr->toggleCount != tagPtr->toggleCount) { |
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
return; |
| 1444 |
} |
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
|
| 1450 |
if (prevPtr == NULL) { |
| 1451 |
node2Ptr->summaryPtr = summaryPtr->nextPtr; |
| 1452 |
} else { |
| 1453 |
prevPtr->nextPtr = summaryPtr->nextPtr; |
| 1454 |
} |
| 1455 |
ckfree((char *) summaryPtr); |
| 1456 |
tagPtr->tagRootPtr = node2Ptr; |
| 1457 |
break; |
| 1458 |
} |
| 1459 |
nodePtr = tagPtr->tagRootPtr; |
| 1460 |
} |
| 1461 |
} |
| 1462 |
|
| 1463 |
|
| 1464 |
|
| 1465 |
|
| 1466 |
|
| 1467 |
|
| 1468 |
|
| 1469 |
|
| 1470 |
|
| 1471 |
|
| 1472 |
|
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
|
| 1478 |
|
| 1479 |
|
| 1480 |
|
| 1481 |
|
| 1482 |
static TkTextSegment * |
| 1483 |
FindTagStart(tree, tagPtr, indexPtr) |
| 1484 |
TkTextBTree tree; |
| 1485 |
TkTextTag *tagPtr; |
| 1486 |
TkTextIndex *indexPtr; |
| 1487 |
{ |
| 1488 |
register Node *nodePtr; |
| 1489 |
register TkTextLine *linePtr; |
| 1490 |
register TkTextSegment *segPtr; |
| 1491 |
register Summary *summaryPtr; |
| 1492 |
int offset; |
| 1493 |
|
| 1494 |
nodePtr = tagPtr->tagRootPtr; |
| 1495 |
if (nodePtr == (Node *) NULL) { |
| 1496 |
return NULL; |
| 1497 |
} |
| 1498 |
|
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
while (nodePtr->level > 0) { |
| 1505 |
for (nodePtr = nodePtr->children.nodePtr ; nodePtr != (Node *) NULL; |
| 1506 |
nodePtr = nodePtr->nextPtr) { |
| 1507 |
for (summaryPtr = nodePtr->summaryPtr ; summaryPtr != NULL; |
| 1508 |
summaryPtr = summaryPtr->nextPtr) { |
| 1509 |
if (summaryPtr->tagPtr == tagPtr) { |
| 1510 |
goto gotNodeWithTag; |
| 1511 |
} |
| 1512 |
} |
| 1513 |
} |
| 1514 |
gotNodeWithTag: |
| 1515 |
continue; |
| 1516 |
} |
| 1517 |
|
| 1518 |
|
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
for (linePtr = nodePtr->children.linePtr; linePtr != (TkTextLine *) NULL; |
| 1523 |
linePtr = linePtr->nextPtr) { |
| 1524 |
for (offset = 0, segPtr = linePtr->segPtr ; segPtr != NULL; |
| 1525 |
offset += segPtr->size, segPtr = segPtr->nextPtr) { |
| 1526 |
if (((segPtr->typePtr == &tkTextToggleOnType) |
| 1527 |
|| (segPtr->typePtr == &tkTextToggleOffType)) |
| 1528 |
&& (segPtr->body.toggle.tagPtr == tagPtr)) { |
| 1529 |
|
| 1530 |
|
| 1531 |
|
| 1532 |
|
| 1533 |
indexPtr->tree = tree; |
| 1534 |
indexPtr->linePtr = linePtr; |
| 1535 |
indexPtr->byteIndex = offset; |
| 1536 |
return segPtr; |
| 1537 |
} |
| 1538 |
} |
| 1539 |
} |
| 1540 |
return NULL; |
| 1541 |
} |
| 1542 |
|
| 1543 |
|
| 1544 |
|
| 1545 |
|
| 1546 |
|
| 1547 |
|
| 1548 |
|
| 1549 |
|
| 1550 |
|
| 1551 |
|
| 1552 |
|
| 1553 |
|
| 1554 |
|
| 1555 |
|
| 1556 |
|
| 1557 |
|
| 1558 |
|
| 1559 |
|
| 1560 |
|
| 1561 |
|
| 1562 |
static TkTextSegment * |
| 1563 |
FindTagEnd(tree, tagPtr, indexPtr) |
| 1564 |
TkTextBTree tree; |
| 1565 |
TkTextTag *tagPtr; |
| 1566 |
TkTextIndex *indexPtr; |
| 1567 |
{ |
| 1568 |
register Node *nodePtr, *lastNodePtr; |
| 1569 |
register TkTextLine *linePtr ,*lastLinePtr; |
| 1570 |
register TkTextSegment *segPtr, *lastSegPtr, *last2SegPtr; |
| 1571 |
register Summary *summaryPtr; |
| 1572 |
int lastoffset, lastoffset2, offset; |
| 1573 |
|
| 1574 |
nodePtr = tagPtr->tagRootPtr; |
| 1575 |
if (nodePtr == (Node *) NULL) { |
| 1576 |
return NULL; |
| 1577 |
} |
| 1578 |
|
| 1579 |
|
| 1580 |
|
| 1581 |
|
| 1582 |
|
| 1583 |
|
| 1584 |
while (nodePtr->level > 0) { |
| 1585 |
for (lastNodePtr = NULL, nodePtr = nodePtr->children.nodePtr ; |
| 1586 |
nodePtr != (Node *) NULL; nodePtr = nodePtr->nextPtr) { |
| 1587 |
for (summaryPtr = nodePtr->summaryPtr ; summaryPtr != NULL; |
| 1588 |
summaryPtr = summaryPtr->nextPtr) { |
| 1589 |
if (summaryPtr->tagPtr == tagPtr) { |
| 1590 |
lastNodePtr = nodePtr; |
| 1591 |
break; |
| 1592 |
} |
| 1593 |
} |
| 1594 |
} |
| 1595 |
nodePtr = lastNodePtr; |
| 1596 |
} |
| 1597 |
|
| 1598 |
|
| 1599 |
|
| 1600 |
|
| 1601 |
last2SegPtr = NULL; |
| 1602 |
lastoffset2 = 0; |
| 1603 |
lastoffset = 0; |
| 1604 |
for (lastLinePtr = NULL, linePtr = nodePtr->children.linePtr; |
| 1605 |
linePtr != (TkTextLine *) NULL; linePtr = linePtr->nextPtr) { |
| 1606 |
for (offset = 0, lastSegPtr = NULL, segPtr = linePtr->segPtr ; |
| 1607 |
segPtr != NULL; |
| 1608 |
offset += segPtr->size, segPtr = segPtr->nextPtr) { |
| 1609 |
if (((segPtr->typePtr == &tkTextToggleOnType) |
| 1610 |
|| (segPtr->typePtr == &tkTextToggleOffType)) |
| 1611 |
&& (segPtr->body.toggle.tagPtr == tagPtr)) { |
| 1612 |
lastSegPtr = segPtr; |
| 1613 |
lastoffset = offset; |
| 1614 |
} |
| 1615 |
} |
| 1616 |
if (lastSegPtr != NULL) { |
| 1617 |
lastLinePtr = linePtr; |
| 1618 |
last2SegPtr = lastSegPtr; |
| 1619 |
lastoffset2 = lastoffset; |
| 1620 |
} |
| 1621 |
} |
| 1622 |
indexPtr->tree = tree; |
| 1623 |
indexPtr->linePtr = lastLinePtr; |
| 1624 |
indexPtr->byteIndex = lastoffset2; |
| 1625 |
return last2SegPtr; |
| 1626 |
} |
| 1627 |
|
| 1628 |
|
| 1629 |
|
| 1630 |
|
| 1631 |
|
| 1632 |
|
| 1633 |
|
| 1634 |
|
| 1635 |
|
| 1636 |
|
| 1637 |
|
| 1638 |
|
| 1639 |
|
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
|
| 1644 |
|
| 1645 |
|
| 1646 |
|
| 1647 |
|
| 1648 |
|
| 1649 |
|
| 1650 |
|
| 1651 |
void |
| 1652 |
TkBTreeStartSearch(index1Ptr, index2Ptr, tagPtr, searchPtr) |
| 1653 |
TkTextIndex *index1Ptr; |
| 1654 |
|
| 1655 |
|
| 1656 |
TkTextIndex *index2Ptr; |
| 1657 |
|
| 1658 |
|
| 1659 |
TkTextTag *tagPtr; |
| 1660 |
|
| 1661 |
register TkTextSearch *searchPtr; |
| 1662 |
|
| 1663 |
{ |
| 1664 |
int offset; |
| 1665 |
TkTextIndex index0; |
| 1666 |
TkTextSegment *seg0Ptr; |
| 1667 |
|
| 1668 |
|
| 1669 |
|
| 1670 |
|
| 1671 |
|
| 1672 |
|
| 1673 |
seg0Ptr = FindTagStart(index1Ptr->tree, tagPtr, &index0); |
| 1674 |
if (seg0Ptr == (TkTextSegment *) NULL) { |
| 1675 |
|
| 1676 |
|
| 1677 |
|
| 1678 |
|
| 1679 |
|
| 1680 |
searchPtr->linesLeft = 0; |
| 1681 |
searchPtr->curIndex = *index1Ptr; |
| 1682 |
searchPtr->segPtr = NULL; |
| 1683 |
searchPtr->nextPtr = NULL; |
| 1684 |
return; |
| 1685 |
} |
| 1686 |
if (TkTextIndexCmp(index1Ptr, &index0) < 0) { |
| 1687 |
|
| 1688 |
|
| 1689 |
|
| 1690 |
|
| 1691 |
searchPtr->curIndex = index0; |
| 1692 |
searchPtr->segPtr = NULL; |
| 1693 |
searchPtr->nextPtr = seg0Ptr; |
| 1694 |
index1Ptr = &index0; |
| 1695 |
} else { |
| 1696 |
searchPtr->curIndex = *index1Ptr; |
| 1697 |
searchPtr->segPtr = NULL; |
| 1698 |
searchPtr->nextPtr = TkTextIndexToSeg(index1Ptr, &offset); |
| 1699 |
searchPtr->curIndex.byteIndex -= offset; |
| 1700 |
} |
| 1701 |
searchPtr->lastPtr = TkTextIndexToSeg(index2Ptr, (int *) NULL); |
| 1702 |
searchPtr->tagPtr = tagPtr; |
| 1703 |
searchPtr->linesLeft = TkBTreeLineIndex(index2Ptr->linePtr) + 1 |
| 1704 |
- TkBTreeLineIndex(index1Ptr->linePtr); |
| 1705 |
searchPtr->allTags = (tagPtr == NULL); |
| 1706 |
if (searchPtr->linesLeft == 1) { |
| 1707 |
|
| 1708 |
|
| 1709 |
|
| 1710 |
|
| 1711 |
|
| 1712 |
|
| 1713 |
if (((index1Ptr == &index0) && |
| 1714 |
(index1Ptr->byteIndex > index2Ptr->byteIndex)) || |
| 1715 |
((index1Ptr != &index0) && |
| 1716 |
(index1Ptr->byteIndex >= index2Ptr->byteIndex))) { |
| 1717 |
searchPtr->linesLeft = 0; |
| 1718 |
} |
| 1719 |
} |
| 1720 |
} |
| 1721 |
|
| 1722 |
|
| 1723 |
|
| 1724 |
|
| 1725 |
|
| 1726 |
|
| 1727 |
|
| 1728 |
|
| 1729 |
|
| 1730 |
|
| 1731 |
|
| 1732 |
|
| 1733 |
|
| 1734 |
|
| 1735 |
|
| 1736 |
|
| 1737 |
|
| 1738 |
|
| 1739 |
|
| 1740 |
|
| 1741 |
|
| 1742 |
|
| 1743 |
|
| 1744 |
|
| 1745 |
|
| 1746 |
|
| 1747 |
|
| 1748 |
void |
| 1749 |
TkBTreeStartSearchBack(index1Ptr, index2Ptr, tagPtr, searchPtr) |
| 1750 |
TkTextIndex *index1Ptr; |
| 1751 |
|
| 1752 |
|
| 1753 |
TkTextIndex *index2Ptr; |
| 1754 |
|
| 1755 |
|
| 1756 |
TkTextTag *tagPtr; |
| 1757 |
|
| 1758 |
register TkTextSearch *searchPtr; |
| 1759 |
|
| 1760 |
{ |
| 1761 |
int offset; |
| 1762 |
TkTextIndex index0; |
| 1763 |
TkTextIndex backOne; |
| 1764 |
TkTextSegment *seg0Ptr; |
| 1765 |
|
| 1766 |
|
| 1767 |
|
| 1768 |
|
| 1769 |
|
| 1770 |
|
| 1771 |
seg0Ptr = FindTagEnd(index1Ptr->tree, tagPtr, &index0); |
| 1772 |
if (seg0Ptr == (TkTextSegment *) NULL) { |
| 1773 |
|
| 1774 |
|
| 1775 |
|
| 1776 |
|
| 1777 |
|
| 1778 |
searchPtr->linesLeft = 0; |
| 1779 |
searchPtr->curIndex = *index1Ptr; |
| 1780 |
searchPtr->segPtr = NULL; |
| 1781 |
searchPtr->nextPtr = NULL; |
| 1782 |
return; |
| 1783 |
} |
| 1784 |
|
| 1785 |
|
| 1786 |
|
| 1787 |
|
| 1788 |
|
| 1789 |
|
| 1790 |
if (TkTextIndexCmp(index1Ptr, &index0) > 0) { |
| 1791 |
searchPtr->curIndex = index0; |
| 1792 |
index1Ptr = &index0; |
| 1793 |
} else { |
| 1794 |
TkTextIndexBackChars(index1Ptr, 1, &searchPtr->curIndex); |
| 1795 |
} |
| 1796 |
searchPtr->segPtr = NULL; |
| 1797 |
searchPtr->nextPtr = TkTextIndexToSeg(&searchPtr->curIndex, &offset); |
| 1798 |
searchPtr->curIndex.byteIndex -= offset; |
| 1799 |
|
| 1800 |
|
| 1801 |
|
| 1802 |
|
| 1803 |
|
| 1804 |
|
| 1805 |
if ((TkBTreeLineIndex(index2Ptr->linePtr) == 0) && |
| 1806 |
(index2Ptr->byteIndex == 0)) { |
| 1807 |
backOne = *index2Ptr; |
| 1808 |
searchPtr->lastPtr = NULL; |
| 1809 |
} else { |
| 1810 |
TkTextIndexBackChars(index2Ptr, 1, &backOne); |
| 1811 |
searchPtr->lastPtr = TkTextIndexToSeg(&backOne, (int *) NULL); |
| 1812 |
} |
| 1813 |
searchPtr->tagPtr = tagPtr; |
| 1814 |
searchPtr->linesLeft = TkBTreeLineIndex(index1Ptr->linePtr) + 1 |
| 1815 |
- TkBTreeLineIndex(backOne.linePtr); |
| 1816 |
searchPtr->allTags = (tagPtr == NULL); |
| 1817 |
if (searchPtr->linesLeft == 1) { |
| 1818 |
|
| 1819 |
|
| 1820 |
|
| 1821 |
|
| 1822 |
|
| 1823 |
|
| 1824 |
if (index1Ptr->byteIndex <= backOne.byteIndex) { |
| 1825 |
searchPtr->linesLeft = 0; |
| 1826 |
} |
| 1827 |
} |
| 1828 |
} |
| 1829 |
|
| 1830 |
|
| 1831 |
|
| 1832 |
|
| 1833 |
|
| 1834 |
|
| 1835 |
|
| 1836 |
|
| 1837 |
|
| 1838 |
|
| 1839 |
|
| 1840 |
|
| 1841 |
|
| 1842 |
|
| 1843 |
|
| 1844 |
|
| 1845 |
|
| 1846 |
|
| 1847 |
|
| 1848 |
|
| 1849 |
|
| 1850 |
|
| 1851 |
|
| 1852 |
|
| 1853 |
|
| 1854 |
|
| 1855 |
int |
| 1856 |
TkBTreeNextTag(searchPtr) |
| 1857 |
register TkTextSearch *searchPtr; |
| 1858 |
|
| 1859 |
|
| 1860 |
{ |
| 1861 |
register TkTextSegment *segPtr; |
| 1862 |
register Node *nodePtr; |
| 1863 |
register Summary *summaryPtr; |
| 1864 |
|
| 1865 |
if (searchPtr->linesLeft <= 0) { |
| 1866 |
goto searchOver; |
| 1867 |
} |
| 1868 |
|
| 1869 |
|
| 1870 |
|
| 1871 |
|
| 1872 |
|
| 1873 |
|
| 1874 |
|
| 1875 |
segPtr = searchPtr->nextPtr; |
| 1876 |
while (1) { |
| 1877 |
|
| 1878 |
|
| 1879 |
|
| 1880 |
|
| 1881 |
for ( ; segPtr != NULL; segPtr = segPtr->nextPtr) { |
| 1882 |
if (segPtr == searchPtr->lastPtr) { |
| 1883 |
goto searchOver; |
| 1884 |
} |
| 1885 |
if (((segPtr->typePtr == &tkTextToggleOnType) |
| 1886 |
|| (segPtr->typePtr == &tkTextToggleOffType)) |
| 1887 |
&& (searchPtr->allTags |
| 1888 |
|| (segPtr->body.toggle.tagPtr == searchPtr->tagPtr))) { |
| 1889 |
searchPtr->segPtr = segPtr; |
| 1890 |
searchPtr->nextPtr = segPtr->nextPtr; |
| 1891 |
searchPtr->tagPtr = segPtr->body.toggle.tagPtr; |
| 1892 |
return 1; |
| 1893 |
} |
| 1894 |
searchPtr->curIndex.byteIndex += segPtr->size; |
| 1895 |
} |
| 1896 |
|
| 1897 |
|
| 1898 |
|
| 1899 |
|
| 1900 |
|
| 1901 |
|
| 1902 |
|
| 1903 |
nodePtr = searchPtr->curIndex.linePtr->parentPtr; |
| 1904 |
searchPtr->curIndex.linePtr = searchPtr->curIndex.linePtr->nextPtr; |
| 1905 |
searchPtr->linesLeft--; |
| 1906 |
if (searchPtr->linesLeft <= 0) { |
| 1907 |
goto searchOver; |
| 1908 |
} |
| 1909 |
if (searchPtr->curIndex.linePtr != NULL) { |
| 1910 |
segPtr = searchPtr->curIndex.linePtr->segPtr; |
| 1911 |
searchPtr->curIndex.byteIndex = 0; |
| 1912 |
continue; |
| 1913 |
} |
| 1914 |
if (nodePtr == searchPtr->tagPtr->tagRootPtr) { |
| 1915 |
goto searchOver; |
| 1916 |
} |
| 1917 |
|
| 1918 |
|
| 1919 |
|
| 1920 |
|
| 1921 |
|
| 1922 |
|
| 1923 |
|
| 1924 |
|
| 1925 |
while (1) { |
| 1926 |
while (nodePtr->nextPtr == NULL) { |
| 1927 |
if (nodePtr->parentPtr == NULL || |
| 1928 |
nodePtr->parentPtr == searchPtr->tagPtr->tagRootPtr) { |
| 1929 |
goto searchOver; |
| 1930 |
} |
| 1931 |
nodePtr = nodePtr->parentPtr; |
| 1932 |
} |
| 1933 |
nodePtr = nodePtr->nextPtr; |
| 1934 |
for (summaryPtr = nodePtr->summaryPtr; summaryPtr != NULL; |
| 1935 |
summaryPtr = summaryPtr->nextPtr) { |
| 1936 |
if ((searchPtr->allTags) || |
| 1937 |
(summaryPtr->tagPtr == searchPtr->tagPtr)) { |
| 1938 |
goto gotNodeWithTag; |
| 1939 |
} |
| 1940 |
} |
| 1941 |
searchPtr->linesLeft -= nodePtr->numLines; |
| 1942 |
} |
| 1943 |
|
| 1944 |
|
| 1945 |
|
| 1946 |
|
| 1947 |
|
| 1948 |
|
| 1949 |
|
| 1950 |
gotNodeWithTag: |
| 1951 |
while (nodePtr->level > 0) { |
| 1952 |
for (nodePtr = nodePtr->children.nodePtr; ; |
| 1953 |
nodePtr = nodePtr->nextPtr) { |
| 1954 |
for (summaryPtr = nodePtr->summaryPtr; summaryPtr != NULL; |
| 1955 |
summaryPtr = summaryPtr->nextPtr) { |
| 1956 |
if ((searchPtr->allTags) |
| 1957 |
|| (summaryPtr->tagPtr == searchPtr->tagPtr)) { |
| 1958 |
goto nextChild; |
| 1959 |
} |
| 1960 |
} |
| 1961 |
searchPtr->linesLeft -= nodePtr->numLines; |
| 1962 |
if (nodePtr->nextPtr == NULL) { |
| 1963 |
panic("TkBTreeNextTag found incorrect tag summary info."); |
| 1964 |
} |
| 1965 |
} |
| 1966 |
nextChild: |
| 1967 |
continue; |
| 1968 |
} |
| 1969 |
|
| 1970 |
|
| 1971 |
|
| 1972 |
|
| 1973 |
|
| 1974 |
|
| 1975 |
|
| 1976 |
searchPtr->curIndex.linePtr = nodePtr->children.linePtr; |
| 1977 |
searchPtr->curIndex.byteIndex = 0; |
| 1978 |
segPtr = searchPtr->curIndex.linePtr->segPtr; |
| 1979 |
if (searchPtr->linesLeft <= 0) { |
| 1980 |
goto searchOver; |
| 1981 |
} |
| 1982 |
continue; |
| 1983 |
} |
| 1984 |
|
| 1985 |
searchOver: |
| 1986 |
searchPtr->linesLeft = 0; |
| 1987 |
searchPtr->segPtr = NULL; |
| 1988 |
return 0; |
| 1989 |
} |
| 1990 |
|
| 1991 |
|
| 1992 |
|
| 1993 |
|
| 1994 |
|
| 1995 |
|
| 1996 |
|
| 1997 |
|
| 1998 |
|
| 1999 |
|
| 2000 |
|
| 2001 |
|
| 2002 |
|
| 2003 |
|
| 2004 |
|
| 2005 |
|
| 2006 |
|
| 2007 |
|
| 2008 |
|
| 2009 |
|
| 2010 |
|
| 2011 |
|
| 2012 |
|
| 2013 |
|
| 2014 |
|
| 2015 |
|
| 2016 |
|
| 2017 |
int |
| 2018 |
TkBTreePrevTag(searchPtr) |
| 2019 |
register TkTextSearch *searchPtr; |
| 2020 |
|
| 2021 |
|
| 2022 |
{ |
| 2023 |
register TkTextSegment *segPtr, *prevPtr; |
| 2024 |
register TkTextLine *linePtr, *prevLinePtr; |
| 2025 |
register Node *nodePtr, *node2Ptr, *prevNodePtr; |
| 2026 |
register Summary *summaryPtr; |
| 2027 |
int byteIndex; |
| 2028 |
int pastLast; |
| 2029 |
int linesSkipped; |
| 2030 |
|
| 2031 |
if (searchPtr->linesLeft <= 0) { |
| 2032 |
goto searchOver; |
| 2033 |
} |
| 2034 |
|
| 2035 |
|
| 2036 |
|
| 2037 |
|
| 2038 |
|
| 2039 |
|
| 2040 |
|
| 2041 |
|
| 2042 |
while (1) { |
| 2043 |
|
| 2044 |
|
| 2045 |
|
| 2046 |
byteIndex = 0; |
| 2047 |
if (searchPtr->lastPtr == NULL) { |
| 2048 |
|
| 2049 |
|
| 2050 |
|
| 2051 |
pastLast = 1; |
| 2052 |
} else { |
| 2053 |
pastLast = 0; |
| 2054 |
} |
| 2055 |
for (prevPtr = NULL, segPtr = searchPtr->curIndex.linePtr->segPtr ; |
| 2056 |
segPtr != NULL && segPtr != searchPtr->nextPtr; |
| 2057 |
segPtr = segPtr->nextPtr) { |
| 2058 |
if (((segPtr->typePtr == &tkTextToggleOnType) |
| 2059 |
|| (segPtr->typePtr == &tkTextToggleOffType)) |
| 2060 |
&& (searchPtr->allTags |
| 2061 |
|| (segPtr->body.toggle.tagPtr == searchPtr->tagPtr))) { |
| 2062 |
prevPtr = segPtr; |
| 2063 |
searchPtr->curIndex.byteIndex = byteIndex; |
| 2064 |
} |
| 2065 |
if (segPtr == searchPtr->lastPtr) { |
| 2066 |
prevPtr = NULL; |
| 2067 |
pastLast = 1; |
| 2068 |
} |
| 2069 |
byteIndex += segPtr->size; |
| 2070 |
} |
| 2071 |
if (prevPtr != NULL) { |
| 2072 |
if (searchPtr->linesLeft == 1 && !pastLast) { |
| 2073 |
|
| 2074 |
|
| 2075 |
|
| 2076 |
|
| 2077 |
goto searchOver; |
| 2078 |
} |
| 2079 |
searchPtr->segPtr = prevPtr; |
| 2080 |
searchPtr->nextPtr = prevPtr; |
| 2081 |
searchPtr->tagPtr = prevPtr->body.toggle.tagPtr; |
| 2082 |
return 1; |
| 2083 |
} |
| 2084 |
|
| 2085 |
searchPtr->linesLeft--; |
| 2086 |
if (searchPtr->linesLeft <= 0) { |
| 2087 |
goto searchOver; |
| 2088 |
} |
| 2089 |
|
| 2090 |
|
| 2091 |
|
| 2092 |
|
| 2093 |
|
| 2094 |
|
| 2095 |
|
| 2096 |
nodePtr = searchPtr->curIndex.linePtr->parentPtr; |
| 2097 |
for (prevLinePtr = NULL, linePtr = nodePtr->children.linePtr; |
| 2098 |
linePtr != NULL && linePtr != searchPtr->curIndex.linePtr; |
| 2099 |
prevLinePtr = linePtr, linePtr = linePtr->nextPtr) { |
| 2100 |
; |
| 2101 |
} |
| 2102 |
if (prevLinePtr != NULL) { |
| 2103 |
searchPtr->curIndex.linePtr = prevLinePtr; |
| 2104 |
searchPtr->nextPtr = NULL; |
| 2105 |
continue; |
| 2106 |
} |
| 2107 |
if (nodePtr == searchPtr->tagPtr->tagRootPtr) { |
| 2108 |
goto searchOver; |
| 2109 |
} |
| 2110 |
|
| 2111 |
|
| 2112 |
|
| 2113 |
|
| 2114 |
|
| 2115 |
|
| 2116 |
|
| 2117 |
|
| 2118 |
|
| 2119 |
|
| 2120 |
|
| 2121 |
while (1) { |
| 2122 |
for (prevNodePtr = NULL, linesSkipped = 0, |
| 2123 |
node2Ptr = nodePtr->parentPtr->children.nodePtr ; |
| 2124 |
node2Ptr != nodePtr; node2Ptr = node2Ptr->nextPtr) { |
| 2125 |
for (summaryPtr = node2Ptr->summaryPtr; summaryPtr != NULL; |
| 2126 |
summaryPtr = summaryPtr->nextPtr) { |
| 2127 |
if ((searchPtr->allTags) || |
| 2128 |
(summaryPtr->tagPtr == searchPtr->tagPtr)) { |
| 2129 |
prevNodePtr = node2Ptr; |
| 2130 |
linesSkipped = 0; |
| 2131 |
goto keepLooking; |
| 2132 |
} |
| 2133 |
} |
| 2134 |
linesSkipped += node2Ptr->numLines; |
| 2135 |
|
| 2136 |
keepLooking: |
| 2137 |
continue; |
| 2138 |
} |
| 2139 |
if (prevNodePtr != NULL) { |
| 2140 |
nodePtr = prevNodePtr; |
| 2141 |
searchPtr->linesLeft -= linesSkipped; |
| 2142 |
goto gotNodeWithTag; |
| 2143 |
} |
| 2144 |
nodePtr = nodePtr->parentPtr; |
| 2145 |
if (nodePtr->parentPtr == NULL || |
| 2146 |
nodePtr == searchPtr->tagPtr->tagRootPtr) { |
| 2147 |
goto searchOver; |
| 2148 |
} |
| 2149 |
} |
| 2150 |
|
| 2151 |
|
| 2152 |
|
| 2153 |
|
| 2154 |
|
| 2155 |
|
| 2156 |
|
| 2157 |
gotNodeWithTag: |
| 2158 |
while (nodePtr->level > 0) { |
| 2159 |
for (linesSkipped = 0, prevNodePtr = NULL, |
| 2160 |
nodePtr = nodePtr->children.nodePtr; nodePtr != NULL ; |
| 2161 |
nodePtr = nodePtr->nextPtr) { |
| 2162 |
for (summaryPtr = nodePtr->summaryPtr; summaryPtr != NULL; |
| 2163 |
summaryPtr = summaryPtr->nextPtr) { |
| 2164 |
if ((searchPtr->allTags) |
| 2165 |
|| (summaryPtr->tagPtr == searchPtr->tagPtr)) { |
| 2166 |
prevNodePtr = nodePtr; |
| 2167 |
linesSkipped = 0; |
| 2168 |
goto keepLooking2; |
| 2169 |
} |
| 2170 |
} |
| 2171 |
linesSkipped += nodePtr->numLines; |
| 2172 |
|
| 2173 |
keepLooking2: |
| 2174 |
continue; |
| 2175 |
} |
| 2176 |
if (prevNodePtr == NULL) { |
| 2177 |
panic("TkBTreePrevTag found incorrect tag summary info."); |
| 2178 |
} |
| 2179 |
searchPtr->linesLeft -= linesSkipped; |
| 2180 |
nodePtr = prevNodePtr; |
| 2181 |
} |
| 2182 |
|
| 2183 |
|
| 2184 |
|
| 2185 |
|
| 2186 |
|
| 2187 |
|
| 2188 |
|
| 2189 |
|
| 2190 |
for (prevLinePtr = NULL, linePtr = nodePtr->children.linePtr; |
| 2191 |
linePtr != NULL ; |
| 2192 |
prevLinePtr = linePtr, linePtr = linePtr->nextPtr) { |
| 2193 |
; |
| 2194 |
} |
| 2195 |
searchPtr->curIndex.linePtr = prevLinePtr; |
| 2196 |
searchPtr->curIndex.byteIndex = 0; |
| 2197 |
if (searchPtr->linesLeft <= 0) { |
| 2198 |
goto searchOver; |
| 2199 |
} |
| 2200 |
continue; |
| 2201 |
} |
| 2202 |
|
| 2203 |
searchOver: |
| 2204 |
searchPtr->linesLeft = 0; |
| 2205 |
searchPtr->segPtr = NULL; |
| 2206 |
return 0; |
| 2207 |
} |
| 2208 |
|
| 2209 |
|
| 2210 |
|
| 2211 |
|
| 2212 |
|
| 2213 |
|
| 2214 |
|
| 2215 |
|
| 2216 |
|
| 2217 |
|
| 2218 |
|
| 2219 |
|
| 2220 |
|
| 2221 |
|
| 2222 |
|
| 2223 |
|
| 2224 |
|
| 2225 |
|
| 2226 |
int |
| 2227 |
TkBTreeCharTagged(indexPtr, tagPtr) |
| 2228 |
TkTextIndex *indexPtr; |
| 2229 |
|
| 2230 |
TkTextTag *tagPtr; |
| 2231 |
{ |
| 2232 |
register Node *nodePtr; |
| 2233 |
register TkTextLine *siblingLinePtr; |
| 2234 |
register TkTextSegment *segPtr; |
| 2235 |
TkTextSegment *toggleSegPtr; |
| 2236 |
int toggles, index; |
| 2237 |
|
| 2238 |
|
| 2239 |
|
| 2240 |
|
| 2241 |
|
| 2242 |
|
| 2243 |
|
| 2244 |
toggleSegPtr = NULL; |
| 2245 |
for (index = 0, segPtr = indexPtr->linePtr->segPtr; |
| 2246 |
(index + segPtr->size) <= indexPtr->byteIndex; |
| 2247 |
index += segPtr->size, segPtr = segPtr->nextPtr) { |
| 2248 |
if (((segPtr->typePtr == &tkTextToggleOnType) |
| 2249 |
|| (segPtr->typePtr == &tkTextToggleOffType)) |
| 2250 |
&& (segPtr->body.toggle.tagPtr == tagPtr)) { |
| 2251 |
toggleSegPtr = segPtr; |
| 2252 |
} |
| 2253 |
} |
| 2254 |
if (toggleSegPtr != NULL) { |
| 2255 |
return (toggleSegPtr->typePtr == &tkTextToggleOnType); |
| 2256 |
} |
| 2257 |
|
| 2258 |
|
| 2259 |
|
| 2260 |
|
| 2261 |
|
| 2262 |
|
| 2263 |
|
| 2264 |
for (siblingLinePtr = indexPtr->linePtr->parentPtr->children.linePtr; |
| 2265 |
siblingLinePtr != indexPtr->linePtr; |
| 2266 |
siblingLinePtr = siblingLinePtr->nextPtr) { |
| 2267 |
for (segPtr = siblingLinePtr->segPtr; segPtr != NULL; |
| 2268 |
segPtr = segPtr->nextPtr) { |
| 2269 |
if (((segPtr->typePtr == &tkTextToggleOnType) |
| 2270 |
|| (segPtr->typePtr == &tkTextToggleOffType)) |
| 2271 |
&& (segPtr->body.toggle.tagPtr == tagPtr)) { |
| 2272 |
toggleSegPtr = segPtr; |
| 2273 |
} |
| 2274 |
} |
| 2275 |
} |
| 2276 |
if (toggleSegPtr != NULL) { |
| 2277 |
return (toggleSegPtr->typePtr == &tkTextToggleOnType); |
| 2278 |
} |
| 2279 |
|
| 2280 |
|
| 2281 |
|
| 2282 |
|
| 2283 |
|
| 2284 |
|
| 2285 |
|
| 2286 |
toggles = 0; |
| 2287 |
for (nodePtr = indexPtr->linePtr->parentPtr; nodePtr->parentPtr != NULL; |
| 2288 |
nodePtr = nodePtr->parentPtr) { |
| 2289 |
register Node *siblingPtr; |
| 2290 |
register Summary *summaryPtr; |
| 2291 |
|
| 2292 |
for (siblingPtr = nodePtr->parentPtr->children.nodePtr; |
| 2293 |
siblingPtr != nodePtr; siblingPtr = siblingPtr->nextPtr) { |
| 2294 |
for (summaryPtr = siblingPtr->summaryPtr; summaryPtr != NULL; |
| 2295 |
summaryPtr = summaryPtr->nextPtr) { |
| 2296 |
if (summaryPtr->tagPtr == tagPtr) { |
| 2297 |
toggles += summaryPtr->toggleCount; |
| 2298 |
} |
| 2299 |
} |
| 2300 |
} |
| 2301 |
if (nodePtr == tagPtr->tagRootPtr) { |
| 2302 |
break; |
| 2303 |
} |
| 2304 |
} |
| 2305 |
|
| 2306 |
|
| 2307 |
|
| 2308 |
|
| 2309 |
|
| 2310 |
|
| 2311 |
return toggles & 1; |
| 2312 |
} |
| 2313 |
|
| 2314 |
|
| 2315 |
|
| 2316 |
|
| 2317 |
|
| 2318 |
|
| 2319 |
|
| 2320 |
|
| 2321 |
|
| 2322 |
|
| 2323 |
|
| 2324 |
|
| 2325 |
|
| 2326 |
|
| 2327 |
|
| 2328 |
|
| 2329 |
|
| 2330 |
|
| 2331 |
|
| 2332 |
|
| 2333 |
|
| 2334 |
|
| 2335 |
|
| 2336 |
|
| 2337 |
|
| 2338 |
TkTextTag ** |
| 2339 |
TkBTreeGetTags(indexPtr, numTagsPtr) |
| 2340 |
TkTextIndex *indexPtr; |
| 2341 |
|
| 2342 |
int *numTagsPtr; |
| 2343 |
|
| 2344 |
{ |
| 2345 |
register Node *nodePtr; |
| 2346 |
register TkTextLine *siblingLinePtr; |
| 2347 |
register TkTextSegment *segPtr; |
| 2348 |
int src, dst, index; |
| 2349 |
TagInfo tagInfo; |
| 2350 |
#define NUM_TAG_INFOS 10 |
| 2351 |
|
| 2352 |
tagInfo.numTags = 0; |
| 2353 |
tagInfo.arraySize = NUM_TAG_INFOS; |
| 2354 |
tagInfo.tagPtrs = (TkTextTag **) ckalloc((unsigned) |
| 2355 |
NUM_TAG_INFOS*sizeof(TkTextTag *)); |
| 2356 |
tagInfo.counts = (int *) ckalloc((unsigned) |
| 2357 |
NUM_TAG_INFOS*sizeof(int)); |
| 2358 |
|
| 2359 |
|
| 2360 |
|
| 2361 |
|
| 2362 |
|
| 2363 |
|
| 2364 |
for (index = 0, segPtr = indexPtr->linePtr->segPtr; |
| 2365 |
(index + segPtr->size) <= indexPtr->byteIndex; |
| 2366 |
index += segPtr->size, segPtr = segPtr->nextPtr) { |
| 2367 |
if ((segPtr->typePtr == &tkTextToggleOnType) |
| 2368 |
|| (segPtr->typePtr == &tkTextToggleOffType)) { |
| 2369 |
IncCount(segPtr->body.toggle.tagPtr, 1, &tagInfo); |
| 2370 |
} |
| 2371 |
} |
| 2372 |
|
| 2373 |
|
| 2374 |
|
| 2375 |
|
| 2376 |
|
| 2377 |
|
| 2378 |
for (siblingLinePtr = indexPtr->linePtr->parentPtr->children.linePtr; |
| 2379 |
siblingLinePtr != indexPtr->linePtr; |
| 2380 |
siblingLinePtr = siblingLinePtr->nextPtr) { |
| 2381 |
for (segPtr = siblingLinePtr->segPtr; segPtr != NULL; |
| 2382 |
segPtr = segPtr->nextPtr) { |
| 2383 |
if ((segPtr->typePtr == &tkTextToggleOnType) |
| 2384 |
|| (segPtr->typePtr == &tkTextToggleOffType)) { |
| 2385 |
IncCount(segPtr->body.toggle.tagPtr, 1, &tagInfo); |
| 2386 |
} |
| 2387 |
} |
| 2388 |
} |
| 2389 |
|
| 2390 |
|
| 2391 |
|
| 2392 |
|
| 2393 |
|
| 2394 |
|
| 2395 |
for (nodePtr = indexPtr->linePtr->parentPtr; nodePtr->parentPtr != NULL; |
| 2396 |
nodePtr = nodePtr->parentPtr) { |
| 2397 |
register Node *siblingPtr; |
| 2398 |
register Summary *summaryPtr; |
| 2399 |
|
| 2400 |
for (siblingPtr = nodePtr->parentPtr->children.nodePtr; |
| 2401 |
siblingPtr != nodePtr; siblingPtr = siblingPtr->nextPtr) { |
| 2402 |
for (summaryPtr = siblingPtr->summaryPtr; summaryPtr != NULL; |
| 2403 |
summaryPtr = summaryPtr->nextPtr) { |
| 2404 |
if (summaryPtr->toggleCount & 1) { |
| 2405 |
IncCount(summaryPtr->tagPtr, summaryPtr->toggleCount, |
| 2406 |
&tagInfo); |
| 2407 |
} |
| 2408 |
} |
| 2409 |
} |
| 2410 |
} |
| 2411 |
|
| 2412 |
|
| 2413 |
|
| 2414 |
|
| 2415 |
|
| 2416 |
|
| 2417 |
|
| 2418 |
for (src = 0, dst = 0; src < tagInfo.numTags; src++) { |
| 2419 |
if (tagInfo.counts[src] & 1) { |
| 2420 |
tagInfo.tagPtrs[dst] = tagInfo.tagPtrs[src]; |
| 2421 |
dst++; |
| 2422 |
} |
| 2423 |
} |
| 2424 |
*numTagsPtr = dst; |
| 2425 |
ckfree((char *) tagInfo.counts); |
| 2426 |
if (dst == 0) { |
| 2427 |
ckfree((char *) tagInfo.tagPtrs); |
| 2428 |
return NULL; |
| 2429 |
} |
| 2430 |
return tagInfo.tagPtrs; |
| 2431 |
} |
| 2432 |
|
| 2433 |
|
| 2434 |
|
| 2435 |
|
| 2436 |
|
| 2437 |
|
| 2438 |
|
| 2439 |
|
| 2440 |
|
| 2441 |
|
| 2442 |
|
| 2443 |
|
| 2444 |
|
| 2445 |
|
| 2446 |
|
| 2447 |
|
| 2448 |
|
| 2449 |
|
| 2450 |
|
| 2451 |
|
| 2452 |
|
| 2453 |
|
| 2454 |
int |
| 2455 |
TkTextIsElided(textPtr, indexPtr) |
| 2456 |
TkText *textPtr; |
| 2457 |
TkTextIndex *indexPtr; |
| 2458 |
|
| 2459 |
{ |
| 2460 |
#define LOTSA_TAGS 1000 |
| 2461 |
int elide = 0; |
| 2462 |
|
| 2463 |
int deftagCnts[LOTSA_TAGS]; |
| 2464 |
int *tagCnts = deftagCnts; |
| 2465 |
TkTextTag *deftagPtrs[LOTSA_TAGS]; |
| 2466 |
TkTextTag **tagPtrs = deftagPtrs; |
| 2467 |
int numTags = textPtr->numTags; |
| 2468 |
register Node *nodePtr; |
| 2469 |
register TkTextLine *siblingLinePtr; |
| 2470 |
register TkTextSegment *segPtr; |
| 2471 |
register TkTextTag *tagPtr; |
| 2472 |
register int i, index; |
| 2473 |
|
| 2474 |
|
| 2475 |
if (LOTSA_TAGS < numTags) { |
| 2476 |
tagCnts = (int *)ckalloc((unsigned)sizeof(int) * numTags); |
| 2477 |
tagPtrs = (TkTextTag **)ckalloc((unsigned)sizeof(TkTextTag *) * numTags); |
| 2478 |
} |
| 2479 |
|
| 2480 |
for (i=0; i<numTags; i++) { |
| 2481 |
tagCnts[i] = 0; |
| 2482 |
} |
| 2483 |
|
| 2484 |
|
| 2485 |
|
| 2486 |
|
| 2487 |
|
| 2488 |
|
| 2489 |
for (index = 0, segPtr = indexPtr->linePtr->segPtr; |
| 2490 |
(index + segPtr->size) <= indexPtr->byteIndex; |
| 2491 |
index += segPtr->size, segPtr = segPtr->nextPtr) { |
| 2492 |
if ((segPtr->typePtr == &tkTextToggleOnType) |
| 2493 |
|| (segPtr->typePtr == &tkTextToggleOffType)) { |
| 2494 |
tagPtr = segPtr->body.toggle.tagPtr; |
| 2495 |
if (tagPtr->elideString != NULL) { |
| 2496 |
tagPtrs[tagPtr->priority] = tagPtr; |
| 2497 |
tagCnts[tagPtr->priority]++; |
| 2498 |
} |
| 2499 |
} |
| 2500 |
} |
| 2501 |
|
| 2502 |
|
| 2503 |
|
| 2504 |
|
| 2505 |
|
| 2506 |
|
| 2507 |
for (siblingLinePtr = indexPtr->linePtr->parentPtr->children.linePtr; |
| 2508 |
siblingLinePtr != indexPtr->linePtr; |
| 2509 |
siblingLinePtr = siblingLinePtr->nextPtr) { |
| 2510 |
for (segPtr = siblingLinePtr->segPtr; segPtr != NULL; |
| 2511 |
segPtr = segPtr->nextPtr) { |
| 2512 |
if ((segPtr->typePtr == &tkTextToggleOnType) |
| 2513 |
|| (segPtr->typePtr == &tkTextToggleOffType)) { |
| 2514 |
tagPtr = segPtr->body.toggle.tagPtr; |
| 2515 |
if (tagPtr->elideString != NULL) { |
| 2516 |
tagPtrs[tagPtr->priority] = tagPtr; |
| 2517 |
tagCnts[tagPtr->priority]++; |
| 2518 |
} |
| 2519 |
} |
| 2520 |
} |
| 2521 |
} |
| 2522 |
|
| 2523 |
|
| 2524 |
|
| 2525 |
|
| 2526 |
|
| 2527 |
|
| 2528 |
for (nodePtr = indexPtr->linePtr->parentPtr; nodePtr->parentPtr != NULL; |
| 2529 |
nodePtr = nodePtr->parentPtr) { |
| 2530 |
register Node *siblingPtr; |
| 2531 |
register Summary *summaryPtr; |
| 2532 |
|
| 2533 |
for (siblingPtr = nodePtr->parentPtr->children.nodePtr; |
| 2534 |
siblingPtr != nodePtr; siblingPtr = siblingPtr->nextPtr) { |
| 2535 |
for (summaryPtr = siblingPtr->summaryPtr; summaryPtr != NULL; |
| 2536 |
summaryPtr = summaryPtr->nextPtr) { |
| 2537 |
if (summaryPtr->toggleCount & 1) { |
| 2538 |
tagPtr = summaryPtr->tagPtr; |
| 2539 |
if (tagPtr->elideString != NULL) { |
| 2540 |
tagPtrs[tagPtr->priority] = tagPtr; |
| 2541 |
tagCnts[tagPtr->priority] += summaryPtr->toggleCount; |
| 2542 |
} |
| 2543 |
} |
| 2544 |
} |
| 2545 |
} |
| 2546 |
} |
| 2547 |
|
| 2548 |
|
| 2549 |
|
| 2550 |
|
| 2551 |
|
| 2552 |
|
| 2553 |
for (i = numTags-1; i >=0; i--) { |
| 2554 |
if (tagCnts[i] & 1) { |
| 2555 |
#ifndef ALWAYS_SHOW_SELECTION |
| 2556 |
|
| 2557 |
if ((tagPtr == textPtr->selTagPtr) |
| 2558 |
&& !(textPtr->flags & GOT_FOCUS)) { |
| 2559 |
continue; |
| 2560 |
} |
| 2561 |
#endif |
| 2562 |
elide = tagPtrs[i]->elide; |
| 2563 |
break; |
| 2564 |
} |
| 2565 |
} |
| 2566 |
|
| 2567 |
if (LOTSA_TAGS < numTags) { |
| 2568 |
ckfree((char *) tagCnts); |
| 2569 |
ckfree((char *) tagPtrs); |
| 2570 |
} |
| 2571 |
|
| 2572 |
return elide; |
| 2573 |
} |
| 2574 |
|
| 2575 |
|
| 2576 |
|
| 2577 |
|
| 2578 |
|
| 2579 |
|
| 2580 |
|
| 2581 |
|
| 2582 |
|
| 2583 |
|
| 2584 |
|
| 2585 |
|
| 2586 |
|
| 2587 |
|
| 2588 |
|
| 2589 |
|
| 2590 |
|
| 2591 |
|
| 2592 |
|
| 2593 |
|
| 2594 |
static void |
| 2595 |
IncCount(tagPtr, inc, tagInfoPtr) |
| 2596 |
TkTextTag *tagPtr; |
| 2597 |
int inc; |
| 2598 |
TagInfo *tagInfoPtr; |
| 2599 |
|
| 2600 |
{ |
| 2601 |
register TkTextTag **tagPtrPtr; |
| 2602 |
int count; |
| 2603 |
|
| 2604 |
for (tagPtrPtr = tagInfoPtr->tagPtrs, count = tagInfoPtr->numTags; |
| 2605 |
count > 0; tagPtrPtr++, count--) { |
| 2606 |
if (*tagPtrPtr == tagPtr) { |
| 2607 |
tagInfoPtr->counts[tagInfoPtr->numTags-count] += inc; |
| 2608 |
return; |
| 2609 |
} |
| 2610 |
} |
| 2611 |
|
| 2612 |
|
| 2613 |
|
| 2614 |
|
| 2615 |
|
| 2616 |
|
| 2617 |
|
| 2618 |
if (tagInfoPtr->numTags == tagInfoPtr->arraySize) { |
| 2619 |
TkTextTag **newTags; |
| 2620 |
int *newCounts, newSize; |
| 2621 |
|
| 2622 |
newSize = 2*tagInfoPtr->arraySize; |
| 2623 |
newTags = (TkTextTag **) ckalloc((unsigned) |
| 2624 |
(newSize*sizeof(TkTextTag *))); |
| 2625 |
memcpy((VOID *) newTags, (VOID *) tagInfoPtr->tagPtrs, |
| 2626 |
tagInfoPtr->arraySize * sizeof(TkTextTag *)); |
| 2627 |
ckfree((char *) tagInfoPtr->tagPtrs); |
| 2628 |
tagInfoPtr->tagPtrs = newTags; |
| 2629 |
newCounts = (int *) ckalloc((unsigned) (newSize*sizeof(int))); |
| 2630 |
memcpy((VOID *) newCounts, (VOID *) tagInfoPtr->counts, |
| 2631 |
tagInfoPtr->arraySize * sizeof(int)); |
| 2632 |
ckfree((char *) tagInfoPtr->counts); |
| 2633 |
tagInfoPtr->counts = newCounts; |
| 2634 |
tagInfoPtr->arraySize = newSize; |
| 2635 |
} |
| 2636 |
|
| 2637 |
tagInfoPtr->tagPtrs[tagInfoPtr->numTags] = tagPtr; |
| 2638 |
tagInfoPtr->counts[tagInfoPtr->numTags] = inc; |
| 2639 |
tagInfoPtr->numTags++; |
| 2640 |
} |
| 2641 |
|
| 2642 |
|
| 2643 |
|
| 2644 |
|
| 2645 |
|
| 2646 |
|
| 2647 |
|
| 2648 |
|
| 2649 |
|
| 2650 |
|
| 2651 |
|
| 2652 |
|
| 2653 |
|
| 2654 |
|
| 2655 |
|
| 2656 |
|
| 2657 |
|
| 2658 |
|
| 2659 |
|
| 2660 |
void |
| 2661 |
TkBTreeCheck(tree) |
| 2662 |
TkTextBTree tree; |
| 2663 |
{ |
| 2664 |
BTree *treePtr = (BTree *) tree; |
| 2665 |
register Summary *summaryPtr; |
| 2666 |
register Node *nodePtr; |
| 2667 |
register TkTextLine *linePtr; |
| 2668 |
register TkTextSegment *segPtr; |
| 2669 |
register TkTextTag *tagPtr; |
| 2670 |
Tcl_HashEntry *entryPtr; |
| 2671 |
Tcl_HashSearch search; |
| 2672 |
int count; |
| 2673 |
|
| 2674 |
|
| 2675 |
|
| 2676 |
|
| 2677 |
for (entryPtr = Tcl_FirstHashEntry(&treePtr->textPtr->tagTable, &search); |
| 2678 |
entryPtr != NULL ; entryPtr = Tcl_NextHashEntry(&search)) { |
| 2679 |
tagPtr = (TkTextTag *) Tcl_GetHashValue(entryPtr); |
| 2680 |
nodePtr = tagPtr->tagRootPtr; |
| 2681 |
if (nodePtr == (Node *) NULL) { |
| 2682 |
if (tagPtr->toggleCount != 0) { |
| 2683 |
panic("TkBTreeCheck found \"%s\" with toggles (%d) but no root", |
| 2684 |
tagPtr->name, tagPtr->toggleCount); |
| 2685 |
} |
| 2686 |
continue; |
| 2687 |
} else if (tagPtr->toggleCount == 0) { |
| 2688 |
panic("TkBTreeCheck found root for \"%s\" with no toggles", |
| 2689 |
tagPtr->name); |
| 2690 |
} else if (tagPtr->toggleCount & 1) { |
| 2691 |
panic("TkBTreeCheck found odd toggle count for \"%s\" (%d)", |
| 2692 |
tagPtr->name, tagPtr->toggleCount); |
| 2693 |
} |
| 2694 |
for (summaryPtr = nodePtr->summaryPtr; summaryPtr != NULL; |
| 2695 |
summaryPtr = summaryPtr->nextPtr) { |
| 2696 |
if (summaryPtr->tagPtr == tagPtr) { |
| 2697 |
panic("TkBTreeCheck found root node with summary info"); |
| 2698 |
} |
| 2699 |
} |
| 2700 |
count = 0; |
| 2701 |
if (nodePtr->level > 0) { |
| 2702 |
for (nodePtr = nodePtr->children.nodePtr ; nodePtr != NULL ; |
| 2703 |
nodePtr = nodePtr->nextPtr) { |
| 2704 |
for (summaryPtr = nodePtr->summaryPtr; summaryPtr != NULL; |
| 2705 |
summaryPtr = summaryPtr->nextPtr) { |
| 2706 |
if (summaryPtr->tagPtr == tagPtr) { |
| 2707 |
count += summaryPtr->toggleCount; |
| 2708 |
} |
| 2709 |
} |
| 2710 |
} |
| 2711 |
} else { |
| 2712 |
for (linePtr = nodePtr->children.linePtr ; linePtr != NULL ; |
| 2713 |
linePtr = linePtr->nextPtr) { |
| 2714 |
for (segPtr = linePtr->segPtr; segPtr != NULL; |
| 2715 |
segPtr = segPtr->nextPtr) { |
| 2716 |
if ((segPtr->typePtr == &tkTextToggleOnType || |
| 2717 |
segPtr->typePtr == &tkTextToggleOffType) && |
| 2718 |
segPtr->body.toggle.tagPtr == tagPtr) { |
| 2719 |
count++; |
| 2720 |
} |
| 2721 |
} |
| 2722 |
} |
| 2723 |
} |
| 2724 |
if (count != tagPtr->toggleCount) { |
| 2725 |
panic("TkBTreeCheck toggleCount (%d) wrong for \"%s\" should be (%d)", |
| 2726 |
tagPtr->toggleCount, tagPtr->name, count); |
| 2727 |
} |
| 2728 |
} |
| 2729 |
|
| 2730 |
|
| 2731 |
|
| 2732 |
|
| 2733 |
|
| 2734 |
nodePtr = treePtr->rootPtr; |
| 2735 |
CheckNodeConsistency(treePtr->rootPtr); |
| 2736 |
|
| 2737 |
|
| 2738 |
|
| 2739 |
|
| 2740 |
|
| 2741 |
|
| 2742 |
if (nodePtr->numLines < 2) { |
| 2743 |
panic("TkBTreeCheck: less than 2 lines in tree"); |
| 2744 |
} |
| 2745 |
while (nodePtr->level > 0) { |
| 2746 |
nodePtr = nodePtr->children.nodePtr; |
| 2747 |
while (nodePtr->nextPtr != NULL) { |
| 2748 |
nodePtr = nodePtr->nextPtr; |
| 2749 |
} |
| 2750 |
} |
| 2751 |
linePtr = nodePtr->children.linePtr; |
| 2752 |
while (linePtr->nextPtr != NULL) { |
| 2753 |
linePtr = linePtr->nextPtr; |
| 2754 |
} |
| 2755 |
segPtr = linePtr->segPtr; |
| 2756 |
while ((segPtr->typePtr == &tkTextToggleOffType) |
| 2757 |
|| (segPtr->typePtr == &tkTextRightMarkType) |
| 2758 |
|| (segPtr->typePtr == &tkTextLeftMarkType)) { |
| 2759 |
|
| 2760 |
|
| 2761 |
|
| 2762 |
|
| 2763 |
|
| 2764 |
|
| 2765 |
segPtr = segPtr->nextPtr; |
| 2766 |
} |
| 2767 |
if (segPtr->typePtr != &tkTextCharType) { |
| 2768 |
panic("TkBTreeCheck: last line has bogus segment type"); |
| 2769 |
} |
| 2770 |
if (segPtr->nextPtr != NULL) { |
| 2771 |
panic("TkBTreeCheck: last line has too many segments"); |
| 2772 |
} |
| 2773 |
if (segPtr->size != 1) { |
| 2774 |
panic("TkBTreeCheck: last line has wrong # characters: %d", |
| 2775 |
segPtr->size); |
| 2776 |
} |
| 2777 |
if ((segPtr->body.chars[0] != '\n') || (segPtr->body.chars[1] != 0)) { |
| 2778 |
panic("TkBTreeCheck: last line had bad value: %s", |
| 2779 |
segPtr->body.chars); |
| 2780 |
} |
| 2781 |
} |
| 2782 |
|
| 2783 |
|
| 2784 |
|
| 2785 |
|
| 2786 |
|
| 2787 |
|
| 2788 |
|
| 2789 |
|
| 2790 |
|
| 2791 |
|
| 2792 |
|
| 2793 |
|
| 2794 |
|
| 2795 |
|
| 2796 |
|
| 2797 |
|
| 2798 |
|
| 2799 |
|
| 2800 |
|
| 2801 |
|
| 2802 |
static void |
| 2803 |
CheckNodeConsistency(nodePtr) |
| 2804 |
register Node *nodePtr; |
| 2805 |
|
| 2806 |
{ |
| 2807 |
register Node *childNodePtr; |
| 2808 |
register Summary *summaryPtr, *summaryPtr2; |
| 2809 |
register TkTextLine *linePtr; |
| 2810 |
register TkTextSegment *segPtr; |
| 2811 |
int numChildren, numLines, toggleCount, minChildren; |
| 2812 |
|
| 2813 |
if (nodePtr->parentPtr != NULL) { |
| 2814 |
minChildren = MIN_CHILDREN; |
| 2815 |
} else if (nodePtr->level > 0) { |
| 2816 |
minChildren = 2; |
| 2817 |
} else { |
| 2818 |
minChildren = 1; |
| 2819 |
} |
| 2820 |
if ((nodePtr->numChildren < minChildren) |
| 2821 |
|| (nodePtr->numChildren > MAX_CHILDREN)) { |
| 2822 |
panic("CheckNodeConsistency: bad child count (%d)", |
| 2823 |
nodePtr->numChildren); |
| 2824 |
} |
| 2825 |
|
| 2826 |
numChildren = 0; |
| 2827 |
numLines = 0; |
| 2828 |
if (nodePtr->level == 0) { |
| 2829 |
for (linePtr = nodePtr->children.linePtr; linePtr != NULL; |
| 2830 |
linePtr = linePtr->nextPtr) { |
| 2831 |
if (linePtr->parentPtr != nodePtr) { |
| 2832 |
panic("CheckNodeConsistency: line doesn't point to parent"); |
| 2833 |
} |
| 2834 |
if (linePtr->segPtr == NULL) { |
| 2835 |
panic("CheckNodeConsistency: line has no segments"); |
| 2836 |
} |
| 2837 |
for (segPtr = linePtr->segPtr; segPtr != NULL; |
| 2838 |
segPtr = segPtr->nextPtr) { |
| 2839 |
if (segPtr->typePtr->checkProc != NULL) { |
| 2840 |
(*segPtr->typePtr->checkProc)(segPtr, linePtr); |
| 2841 |
} |
| 2842 |
if ((segPtr->size == 0) && (!segPtr->typePtr->leftGravity) |
| 2843 |
&& (segPtr->nextPtr != NULL) |
| 2844 |
&& (segPtr->nextPtr->size == 0) |
| 2845 |
&& (segPtr->nextPtr->typePtr->leftGravity)) { |
| 2846 |
panic("CheckNodeConsistency: wrong segment order for gravity"); |
| 2847 |
} |
| 2848 |
if ((segPtr->nextPtr == NULL) |
| 2849 |
&& (segPtr->typePtr != &tkTextCharType)) { |
| 2850 |
panic("CheckNodeConsistency: line ended with wrong type"); |
| 2851 |
} |
| 2852 |
} |
| 2853 |
numChildren++; |
| 2854 |
numLines++; |
| 2855 |
} |
| 2856 |
} else { |
| 2857 |
for (childNodePtr = nodePtr->children.nodePtr; childNodePtr != NULL; |
| 2858 |
childNodePtr = childNodePtr->nextPtr) { |
| 2859 |
if (childNodePtr->parentPtr != nodePtr) { |
| 2860 |
panic("CheckNodeConsistency: node doesn't point to parent"); |
| 2861 |
} |
| 2862 |
if (childNodePtr->level != (nodePtr->level-1)) { |
| 2863 |
panic("CheckNodeConsistency: level mismatch (%d %d)", |
| 2864 |
nodePtr->level, childNodePtr->level); |
| 2865 |
} |
| 2866 |
CheckNodeConsistency(childNodePtr); |
| 2867 |
for (summaryPtr = childNodePtr->summaryPtr; summaryPtr != NULL; |
| 2868 |
summaryPtr = summaryPtr->nextPtr) { |
| 2869 |
for (summaryPtr2 = nodePtr->summaryPtr; ; |
| 2870 |
summaryPtr2 = summaryPtr2->nextPtr) { |
| 2871 |
if (summaryPtr2 == NULL) { |
| 2872 |
if (summaryPtr->tagPtr->tagRootPtr == nodePtr) { |
| 2873 |
break; |
| 2874 |
} |
| 2875 |
panic("CheckNodeConsistency: node tag \"%s\" not %s", |
| 2876 |
summaryPtr->tagPtr->name, |
| 2877 |
"present in parent summaries"); |
| 2878 |
} |
| 2879 |
if (summaryPtr->tagPtr == summaryPtr2->tagPtr) { |
| 2880 |
break; |
| 2881 |
} |
| 2882 |
} |
| 2883 |
} |
| 2884 |
numChildren++; |
| 2885 |
numLines += childNodePtr->numLines; |
| 2886 |
} |
| 2887 |
} |
| 2888 |
if (numChildren != nodePtr->numChildren) { |
| 2889 |
panic("CheckNodeConsistency: mismatch in numChildren (%d %d)", |
| 2890 |
numChildren, nodePtr->numChildren); |
| 2891 |
} |
| 2892 |
if (numLines != nodePtr->numLines) { |
| 2893 |
panic("CheckNodeConsistency: mismatch in numLines (%d %d)", |
| 2894 |
numLines, nodePtr->numLines); |
| 2895 |
} |
| 2896 |
|
| 2897 |
for (summaryPtr = nodePtr->summaryPtr; summaryPtr != NULL; |
| 2898 |
summaryPtr = summaryPtr->nextPtr) { |
| 2899 |
if (summaryPtr->tagPtr->toggleCount == summaryPtr->toggleCount) { |
| 2900 |
panic("CheckNodeConsistency: found unpruned root for \"%s\"", |
| 2901 |
summaryPtr->tagPtr->name); |
| 2902 |
} |
| 2903 |
toggleCount = 0; |
| 2904 |
if (nodePtr->level == 0) { |
| 2905 |
for (linePtr = nodePtr->children.linePtr; linePtr != NULL; |
| 2906 |
linePtr = linePtr->nextPtr) { |
| 2907 |
for (segPtr = linePtr->segPtr; segPtr != NULL; |
| 2908 |
segPtr = segPtr->nextPtr) { |
| 2909 |
if ((segPtr->typePtr != &tkTextToggleOnType) |
| 2910 |
&& (segPtr->typePtr != &tkTextToggleOffType)) { |
| 2911 |
continue; |
| 2912 |
} |
| 2913 |
if (segPtr->body.toggle.tagPtr == summaryPtr->tagPtr) { |
| 2914 |
toggleCount ++; |
| 2915 |
} |
| 2916 |
} |
| 2917 |
} |
| 2918 |
} else { |
| 2919 |
for (childNodePtr = nodePtr->children.nodePtr; |
| 2920 |
childNodePtr != NULL; |
| 2921 |
childNodePtr = childNodePtr->nextPtr) { |
| 2922 |
for (summaryPtr2 = childNodePtr->summaryPtr; |
| 2923 |
summaryPtr2 != NULL; |
| 2924 |
summaryPtr2 = summaryPtr2->nextPtr) { |
| 2925 |
if (summaryPtr2->tagPtr == summaryPtr->tagPtr) { |
| 2926 |
toggleCount += summaryPtr2->toggleCount; |
| 2927 |
} |
| 2928 |
} |
| 2929 |
} |
| 2930 |
} |
| 2931 |
if (toggleCount != summaryPtr->toggleCount) { |
| 2932 |
panic("CheckNodeConsistency: mismatch in toggleCount (%d %d)", |
| 2933 |
toggleCount, summaryPtr->toggleCount); |
| 2934 |
} |
| 2935 |
for (summaryPtr2 = summaryPtr->nextPtr; summaryPtr2 != NULL; |
| 2936 |
summaryPtr2 = summaryPtr2->nextPtr) { |
| 2937 |
if (summaryPtr2->tagPtr == summaryPtr->tagPtr) { |
| 2938 |
panic("CheckNodeConsistency: duplicated node tag: %s", |
| 2939 |
summaryPtr->tagPtr->name); |
| 2940 |
} |
| 2941 |
} |
| 2942 |
} |
| 2943 |
} |
| 2944 |
|
| 2945 |
|
| 2946 |
|
| 2947 |
|
| 2948 |
|
| 2949 |
|
| 2950 |
|
| 2951 |
|
| 2952 |
|
| 2953 |
|
| 2954 |
|
| 2955 |
|
| 2956 |
|
| 2957 |
|
| 2958 |
|
| 2959 |
|
| 2960 |
|
| 2961 |
|
| 2962 |
|
| 2963 |
static void |
| 2964 |
Rebalance(treePtr, nodePtr) |
| 2965 |
BTree *treePtr; |
| 2966 |
register Node *nodePtr; |
| 2967 |
{ |
| 2968 |
|
| 2969 |
|
| 2970 |
|
| 2971 |
|
| 2972 |
|
| 2973 |
|
| 2974 |
for ( ; nodePtr != NULL; nodePtr = nodePtr->parentPtr) { |
| 2975 |
register Node *newPtr, *childPtr; |
| 2976 |
register TkTextLine *linePtr; |
| 2977 |
int i; |
| 2978 |
|
| 2979 |
|
| 2980 |
|
| 2981 |
|
| 2982 |
|
| 2983 |
|
| 2984 |
|
| 2985 |
|
| 2986 |
if (nodePtr->numChildren > MAX_CHILDREN) { |
| 2987 |
while (1) { |
| 2988 |
|
| 2989 |
|
| 2990 |
|
| 2991 |
|
| 2992 |
|
| 2993 |
if (nodePtr->parentPtr == NULL) { |
| 2994 |
newPtr = (Node *) ckalloc(sizeof(Node)); |
| 2995 |
newPtr->parentPtr = NULL; |
| 2996 |
newPtr->nextPtr = NULL; |
| 2997 |
newPtr->summaryPtr = NULL; |
| 2998 |
newPtr->level = nodePtr->level + 1; |
| 2999 |
newPtr->children.nodePtr = nodePtr; |
| 3000 |
newPtr->numChildren = 1; |
| 3001 |
newPtr->numLines = nodePtr->numLines; |
| 3002 |
RecomputeNodeCounts(newPtr); |
| 3003 |
treePtr->rootPtr = newPtr; |
| 3004 |
} |
| 3005 |
newPtr = (Node *) ckalloc(sizeof(Node)); |
| 3006 |
newPtr->parentPtr = nodePtr->parentPtr; |
| 3007 |
newPtr->nextPtr = nodePtr->nextPtr; |
| 3008 |
nodePtr->nextPtr = newPtr; |
| 3009 |
newPtr->summaryPtr = NULL; |
| 3010 |
newPtr->level = nodePtr->level; |
| 3011 |
newPtr->numChildren = nodePtr->numChildren - MIN_CHILDREN; |
| 3012 |
if (nodePtr->level == 0) { |
| 3013 |
for (i = MIN_CHILDREN-1, |
| 3014 |
linePtr = nodePtr->children.linePtr; |
| 3015 |
i > 0; i--, linePtr = linePtr->nextPtr) { |
| 3016 |
|
| 3017 |
} |
| 3018 |
newPtr->children.linePtr = linePtr->nextPtr; |
| 3019 |
linePtr->nextPtr = NULL; |
| 3020 |
} else { |
| 3021 |
for (i = MIN_CHILDREN-1, |
| 3022 |
childPtr = nodePtr->children.nodePtr; |
| 3023 |
i > 0; i--, childPtr = childPtr->nextPtr) { |
| 3024 |
|
| 3025 |
} |
| 3026 |
newPtr->children.nodePtr = childPtr->nextPtr; |
| 3027 |
childPtr->nextPtr = NULL; |
| 3028 |
} |
| 3029 |
RecomputeNodeCounts(nodePtr); |
| 3030 |
nodePtr->parentPtr->numChildren++; |
| 3031 |
nodePtr = newPtr; |
| 3032 |
if (nodePtr->numChildren <= MAX_CHILDREN) { |
| 3033 |
RecomputeNodeCounts(nodePtr); |
| 3034 |
break; |
| 3035 |
} |
| 3036 |
} |
| 3037 |
} |
| 3038 |
|
| 3039 |
while (nodePtr->numChildren < MIN_CHILDREN) { |
| 3040 |
register Node *otherPtr; |
| 3041 |
Node *halfwayNodePtr = NULL; |
| 3042 |
TkTextLine *halfwayLinePtr = NULL; |
| 3043 |
int totalChildren, firstChildren, i; |
| 3044 |
|
| 3045 |
|
| 3046 |
|
| 3047 |
|
| 3048 |
|
| 3049 |
|
| 3050 |
|
| 3051 |
|
| 3052 |
|
| 3053 |
if (nodePtr->parentPtr == NULL) { |
| 3054 |
if ((nodePtr->numChildren == 1) && (nodePtr->level > 0)) { |
| 3055 |
treePtr->rootPtr = nodePtr->children.nodePtr; |
| 3056 |
treePtr->rootPtr->parentPtr = NULL; |
| 3057 |
DeleteSummaries(nodePtr->summaryPtr); |
| 3058 |
ckfree((char *) nodePtr); |
| 3059 |
} |
| 3060 |
return; |
| 3061 |
} |
| 3062 |
|
| 3063 |
|
| 3064 |
|
| 3065 |
|
| 3066 |
|
| 3067 |
|
| 3068 |
if (nodePtr->parentPtr->numChildren < 2) { |
| 3069 |
Rebalance(treePtr, nodePtr->parentPtr); |
| 3070 |
continue; |
| 3071 |
} |
| 3072 |
|
| 3073 |
|
| 3074 |
|
| 3075 |
|
| 3076 |
|
| 3077 |
|
| 3078 |
if (nodePtr->nextPtr == NULL) { |
| 3079 |
for (otherPtr = nodePtr->parentPtr->children.nodePtr; |
| 3080 |
otherPtr->nextPtr != nodePtr; |
| 3081 |
otherPtr = otherPtr->nextPtr) { |
| 3082 |
|
| 3083 |
} |
| 3084 |
nodePtr = otherPtr; |
| 3085 |
} |
| 3086 |
otherPtr = nodePtr->nextPtr; |
| 3087 |
|
| 3088 |
|
| 3089 |
|
| 3090 |
|
| 3091 |
|
| 3092 |
|
| 3093 |
|
| 3094 |
|
| 3095 |
|
| 3096 |
totalChildren = nodePtr->numChildren + otherPtr->numChildren; |
| 3097 |
firstChildren = totalChildren/2; |
| 3098 |
if (nodePtr->children.nodePtr == NULL) { |
| 3099 |
nodePtr->children = otherPtr->children; |
| 3100 |
otherPtr->children.nodePtr = NULL; |
| 3101 |
otherPtr->children.linePtr = NULL; |
| 3102 |
} |
| 3103 |
if (nodePtr->level == 0) { |
| 3104 |
register TkTextLine *linePtr; |
| 3105 |
|
| 3106 |
for (linePtr = nodePtr->children.linePtr, i = 1; |
| 3107 |
linePtr->nextPtr != NULL; |
| 3108 |
linePtr = linePtr->nextPtr, i++) { |
| 3109 |
if (i == firstChildren) { |
| 3110 |
halfwayLinePtr = linePtr; |
| 3111 |
} |
| 3112 |
} |
| 3113 |
linePtr->nextPtr = otherPtr->children.linePtr; |
| 3114 |
while (i <= firstChildren) { |
| 3115 |
halfwayLinePtr = linePtr; |
| 3116 |
linePtr = linePtr->nextPtr; |
| 3117 |
i++; |
| 3118 |
} |
| 3119 |
} else { |
| 3120 |
register Node *childPtr; |
| 3121 |
|
| 3122 |
for (childPtr = nodePtr->children.nodePtr, i = 1; |
| 3123 |
childPtr->nextPtr != NULL; |
| 3124 |
childPtr = childPtr->nextPtr, i++) { |
| 3125 |
if (i <= firstChildren) { |
| 3126 |
if (i == firstChildren) { |
| 3127 |
halfwayNodePtr = childPtr; |
| 3128 |
} |
| 3129 |
} |
| 3130 |
} |
| 3131 |
childPtr->nextPtr = otherPtr->children.nodePtr; |
| 3132 |
while (i <= firstChildren) { |
| 3133 |
halfwayNodePtr = childPtr; |
| 3134 |
childPtr = childPtr->nextPtr; |
| 3135 |
i++; |
| 3136 |
} |
| 3137 |
} |
| 3138 |
|
| 3139 |
|
| 3140 |
|
| 3141 |
|
| 3142 |
|
| 3143 |
if (totalChildren <= MAX_CHILDREN) { |
| 3144 |
RecomputeNodeCounts(nodePtr); |
| 3145 |
nodePtr->nextPtr = otherPtr->nextPtr; |
| 3146 |
nodePtr->parentPtr->numChildren--; |
| 3147 |
DeleteSummaries(otherPtr->summaryPtr); |
| 3148 |
ckfree((char *) otherPtr); |
| 3149 |
continue; |
| 3150 |
} |
| 3151 |
|
| 3152 |
|
| 3153 |
|
| 3154 |
|
| 3155 |
|
| 3156 |
|
| 3157 |
if (nodePtr->level == 0) { |
| 3158 |
otherPtr->children.linePtr = halfwayLinePtr->nextPtr; |
| 3159 |
halfwayLinePtr->nextPtr = NULL; |
| 3160 |
} else { |
| 3161 |
otherPtr->children.nodePtr = halfwayNodePtr->nextPtr; |
| 3162 |
halfwayNodePtr->nextPtr = NULL; |
| 3163 |
} |
| 3164 |
RecomputeNodeCounts(nodePtr); |
| 3165 |
RecomputeNodeCounts(otherPtr); |
| 3166 |
} |
| 3167 |
} |
| 3168 |
} |
| 3169 |
|
| 3170 |
|
| 3171 |
|
| 3172 |
|
| 3173 |
|
| 3174 |
|
| 3175 |
|
| 3176 |
|
| 3177 |
|
| 3178 |
|
| 3179 |
|
| 3180 |
|
| 3181 |
|
| 3182 |
|
| 3183 |
|
| 3184 |
|
| 3185 |
|
| 3186 |
|
| 3187 |
|
| 3188 |
|
| 3189 |
|
| 3190 |
|
| 3191 |
|
| 3192 |
static void |
| 3193 |
RecomputeNodeCounts(nodePtr) |
| 3194 |
register Node *nodePtr; |
| 3195 |
|
| 3196 |
{ |
| 3197 |
register Summary *summaryPtr, *summaryPtr2; |
| 3198 |
register Node *childPtr; |
| 3199 |
register TkTextLine *linePtr; |
| 3200 |
register TkTextSegment *segPtr; |
| 3201 |
TkTextTag *tagPtr; |
| 3202 |
|
| 3203 |
|
| 3204 |
|
| 3205 |
|
| 3206 |
|
| 3207 |
|
| 3208 |
for (summaryPtr = nodePtr->summaryPtr; summaryPtr != NULL; |
| 3209 |
summaryPtr = summaryPtr->nextPtr) { |
| 3210 |
summaryPtr->toggleCount = 0; |
| 3211 |
} |
| 3212 |
nodePtr->numChildren = 0; |
| 3213 |
nodePtr->numLines = 0; |
| 3214 |
|
| 3215 |
|
| 3216 |
|
| 3217 |
|
| 3218 |
|
| 3219 |
|
| 3220 |
|
| 3221 |
if (nodePtr->level == 0) { |
| 3222 |
for (linePtr = nodePtr->children.linePtr; linePtr != NULL; |
| 3223 |
linePtr = linePtr->nextPtr) { |
| 3224 |
nodePtr->numChildren++; |
| 3225 |
nodePtr->numLines++; |
| 3226 |
linePtr->parentPtr = nodePtr; |
| 3227 |
for (segPtr = linePtr->segPtr; segPtr != NULL; |
| 3228 |
segPtr = segPtr->nextPtr) { |
| 3229 |
if (((segPtr->typePtr != &tkTextToggleOnType) |
| 3230 |
&& (segPtr->typePtr != &tkTextToggleOffType)) |
| 3231 |
|| !(segPtr->body.toggle.inNodeCounts)) { |
| 3232 |
continue; |
| 3233 |
} |
| 3234 |
tagPtr = segPtr->body.toggle.tagPtr; |
| 3235 |
for (summaryPtr = nodePtr->summaryPtr; ; |
| 3236 |
summaryPtr = summaryPtr->nextPtr) { |
| 3237 |
if (summaryPtr == NULL) { |
| 3238 |
summaryPtr = (Summary *) ckalloc(sizeof(Summary)); |
| 3239 |
summaryPtr->tagPtr = tagPtr; |
| 3240 |
summaryPtr->toggleCount = 1; |
| 3241 |
summaryPtr->nextPtr = nodePtr->summaryPtr; |
| 3242 |
nodePtr->summaryPtr = summaryPtr; |
| 3243 |
break; |
| 3244 |
} |
| 3245 |
if (summaryPtr->tagPtr == tagPtr) { |
| 3246 |
summaryPtr->toggleCount++; |
| 3247 |
break; |
| 3248 |
} |
| 3249 |
} |
| 3250 |
} |
| 3251 |
} |
| 3252 |
} else { |
| 3253 |
for (childPtr = nodePtr->children.nodePtr; childPtr != NULL; |
| 3254 |
childPtr = childPtr->nextPtr) { |
| 3255 |
nodePtr->numChildren++; |
| 3256 |
nodePtr->numLines += childPtr->numLines; |
| 3257 |
childPtr->parentPtr = nodePtr; |
| 3258 |
for (summaryPtr2 = childPtr->summaryPtr; summaryPtr2 != NULL; |
| 3259 |
summaryPtr2 = summaryPtr2->nextPtr) { |
| 3260 |
for (summaryPtr = nodePtr->summaryPtr; ; |
| 3261 |
summaryPtr = summaryPtr->nextPtr) { |
| 3262 |
if (summaryPtr == NULL) { |
| 3263 |
summaryPtr = (Summary *) ckalloc(sizeof(Summary)); |
| 3264 |
summaryPtr->tagPtr = summaryPtr2->tagPtr; |
| 3265 |
summaryPtr->toggleCount = summaryPtr2->toggleCount; |
| 3266 |
summaryPtr->nextPtr = nodePtr->summaryPtr; |
| 3267 |
nodePtr->summaryPtr = summaryPtr; |
| 3268 |
break; |
| 3269 |
} |
| 3270 |
if (summaryPtr->tagPtr == summaryPtr2->tagPtr) { |
| 3271 |
summaryPtr->toggleCount += summaryPtr2->toggleCount; |
| 3272 |
break; |
| 3273 |
} |
| 3274 |
} |
| 3275 |
} |
| 3276 |
} |
| 3277 |
} |
| 3278 |
|
| 3279 |
|
| 3280 |
|
| 3281 |
|
| 3282 |
|
| 3283 |
|
| 3284 |
|
| 3285 |
|
| 3286 |
summaryPtr2 = NULL; |
| 3287 |
for (summaryPtr = nodePtr->summaryPtr; summaryPtr != NULL; ) { |
| 3288 |
if (summaryPtr->toggleCount > 0 && |
| 3289 |
summaryPtr->toggleCount < summaryPtr->tagPtr->toggleCount) { |
| 3290 |
if (nodePtr->level == summaryPtr->tagPtr->tagRootPtr->level) { |
| 3291 |
|
| 3292 |
|
| 3293 |
|
| 3294 |
|
| 3295 |
summaryPtr->tagPtr->tagRootPtr = nodePtr->parentPtr; |
| 3296 |
} |
| 3297 |
summaryPtr2 = summaryPtr; |
| 3298 |
summaryPtr = summaryPtr->nextPtr; |
| 3299 |
continue; |
| 3300 |
} |
| 3301 |
if (summaryPtr->toggleCount == summaryPtr->tagPtr->toggleCount) { |
| 3302 |
|
| 3303 |
|
| 3304 |
|
| 3305 |
|
| 3306 |
summaryPtr->tagPtr->tagRootPtr = nodePtr; |
| 3307 |
} |
| 3308 |
if (summaryPtr2 != NULL) { |
| 3309 |
summaryPtr2->nextPtr = summaryPtr->nextPtr; |
| 3310 |
ckfree((char *) summaryPtr); |
| 3311 |
summaryPtr = summaryPtr2->nextPtr; |
| 3312 |
} else { |
| 3313 |
nodePtr->summaryPtr = summaryPtr->nextPtr; |
| 3314 |
ckfree((char *) summaryPtr); |
| 3315 |
summaryPtr = nodePtr->summaryPtr; |
| 3316 |
} |
| 3317 |
} |
| 3318 |
} |
| 3319 |
|
| 3320 |
|
| 3321 |
|
| 3322 |
|
| 3323 |
|
| 3324 |
|
| 3325 |
|
| 3326 |
|
| 3327 |
|
| 3328 |
|
| 3329 |
|
| 3330 |
|
| 3331 |
|
| 3332 |
|
| 3333 |
|
| 3334 |
|
| 3335 |
|
| 3336 |
|
| 3337 |
|
| 3338 |
|
| 3339 |
int |
| 3340 |
TkBTreeNumLines(tree) |
| 3341 |
TkTextBTree tree; |
| 3342 |
{ |
| 3343 |
BTree *treePtr = (BTree *) tree; |
| 3344 |
return treePtr->rootPtr->numLines - 1; |
| 3345 |
} |
| 3346 |
|
| 3347 |
|
| 3348 |
|
| 3349 |
|
| 3350 |
|
| 3351 |
|
| 3352 |
|
| 3353 |
|
| 3354 |
|
| 3355 |
|
| 3356 |
|
| 3357 |
|
| 3358 |
|
| 3359 |
|
| 3360 |
|
| 3361 |
|
| 3362 |
|
| 3363 |
|
| 3364 |
|
| 3365 |
static TkTextSegment * |
| 3366 |
CharSplitProc(segPtr, index) |
| 3367 |
TkTextSegment *segPtr; |
| 3368 |
int index; |
| 3369 |
|
| 3370 |
{ |
| 3371 |
TkTextSegment *newPtr1, *newPtr2; |
| 3372 |
|
| 3373 |
newPtr1 = (TkTextSegment *) ckalloc(CSEG_SIZE(index)); |
| 3374 |
newPtr2 = (TkTextSegment *) ckalloc( |
| 3375 |
CSEG_SIZE(segPtr->size - index)); |
| 3376 |
newPtr1->typePtr = &tkTextCharType; |
| 3377 |
newPtr1->nextPtr = newPtr2; |
| 3378 |
newPtr1->size = index; |
| 3379 |
memcpy(newPtr1->body.chars, segPtr->body.chars, MIN(index, strlen(segPtr->body.chars) + 1)); |
| 3380 |
newPtr1->body.chars[index] = 0; |
| 3381 |
newPtr2->typePtr = &tkTextCharType; |
| 3382 |
newPtr2->nextPtr = segPtr->nextPtr; |
| 3383 |
newPtr2->size = segPtr->size - index; |
| 3384 |
memcpy(newPtr2->body.chars, segPtr->body.chars + index, strlen(segPtr->body.chars + index) + 1); |
| 3385 |
ckfree((char*) segPtr); |
| 3386 |
return newPtr1; |
| 3387 |
} |
| 3388 |
|
| 3389 |
|
| 3390 |
|
| 3391 |
|
| 3392 |
|
| 3393 |
|
| 3394 |
|
| 3395 |
|
| 3396 |
|
| 3397 |
|
| 3398 |
|
| 3399 |
|
| 3400 |
|
| 3401 |
|
| 3402 |
|
| 3403 |
|
| 3404 |
|
| 3405 |
|
| 3406 |
|
| 3407 |
|
| 3408 |
static TkTextSegment * |
| 3409 |
CharCleanupProc(segPtr, linePtr) |
| 3410 |
TkTextSegment *segPtr; |
| 3411 |
|
| 3412 |
TkTextLine *linePtr; |
| 3413 |
|
| 3414 |
{ |
| 3415 |
TkTextSegment *segPtr2, *newPtr; |
| 3416 |
|
| 3417 |
segPtr2 = segPtr->nextPtr; |
| 3418 |
if ((segPtr2 == NULL) || (segPtr2->typePtr != &tkTextCharType)) { |
| 3419 |
return segPtr; |
| 3420 |
} |
| 3421 |
newPtr = (TkTextSegment *) ckalloc(CSEG_SIZE( |
| 3422 |
segPtr->size + segPtr2->size)); |
| 3423 |
newPtr->typePtr = &tkTextCharType; |
| 3424 |
newPtr->nextPtr = segPtr2->nextPtr; |
| 3425 |
newPtr->size = segPtr->size + segPtr2->size; |
| 3426 |
memcpy(newPtr->body.chars, segPtr->body.chars, strlen(segPtr->body.chars) + 1); |
| 3427 |
memcpy(newPtr->body.chars + segPtr->size, segPtr2->body.chars, strlen(segPtr2->body.chars) + 1); |
| 3428 |
ckfree((char*) segPtr); |
| 3429 |
ckfree((char*) segPtr2); |
| 3430 |
return newPtr; |
| 3431 |
} |
| 3432 |
|
| 3433 |
|
| 3434 |
|
| 3435 |
|
| 3436 |
|
| 3437 |
|
| 3438 |
|
| 3439 |
|
| 3440 |
|
| 3441 |
|
| 3442 |
|
| 3443 |
|
| 3444 |
|
| 3445 |
|
| 3446 |
|
| 3447 |
|
| 3448 |
|
| 3449 |
|
| 3450 |
static int |
| 3451 |
CharDeleteProc(segPtr, linePtr, treeGone) |
| 3452 |
TkTextSegment *segPtr; |
| 3453 |
TkTextLine *linePtr; |
| 3454 |
int treeGone; |
| 3455 |
|
| 3456 |
|
| 3457 |
{ |
| 3458 |
ckfree((char*) segPtr); |
| 3459 |
return 0; |
| 3460 |
} |
| 3461 |
|
| 3462 |
|
| 3463 |
|
| 3464 |
|
| 3465 |
|
| 3466 |
|
| 3467 |
|
| 3468 |
|
| 3469 |
|
| 3470 |
|
| 3471 |
|
| 3472 |
|
| 3473 |
|
| 3474 |
|
| 3475 |
|
| 3476 |
|
| 3477 |
|
| 3478 |
|
| 3479 |
|
| 3480 |
|
| 3481 |
static void |
| 3482 |
CharCheckProc(segPtr, linePtr) |
| 3483 |
TkTextSegment *segPtr; |
| 3484 |
TkTextLine *linePtr; |
| 3485 |
{ |
| 3486 |
|
| 3487 |
|
| 3488 |
|
| 3489 |
|
| 3490 |
|
| 3491 |
|
| 3492 |
|
| 3493 |
|
| 3494 |
if (segPtr->size <= 0) { |
| 3495 |
panic("CharCheckProc: segment has size <= 0"); |
| 3496 |
} |
| 3497 |
if (strlen(segPtr->body.chars) != (size_t) segPtr->size) { |
| 3498 |
panic("CharCheckProc: segment has wrong size"); |
| 3499 |
} |
| 3500 |
if (segPtr->nextPtr == NULL) { |
| 3501 |
if (segPtr->body.chars[segPtr->size-1] != '\n') { |
| 3502 |
panic("CharCheckProc: line doesn't end with newline"); |
| 3503 |
} |
| 3504 |
} else { |
| 3505 |
if (segPtr->nextPtr->typePtr == &tkTextCharType) { |
| 3506 |
panic("CharCheckProc: adjacent character segments weren't merged"); |
| 3507 |
} |
| 3508 |
} |
| 3509 |
} |
| 3510 |
|
| 3511 |
|
| 3512 |
|
| 3513 |
|
| 3514 |
|
| 3515 |
|
| 3516 |
|
| 3517 |
|
| 3518 |
|
| 3519 |
|
| 3520 |
|
| 3521 |
|
| 3522 |
|
| 3523 |
|
| 3524 |
|
| 3525 |
|
| 3526 |
|
| 3527 |
|
| 3528 |
|
| 3529 |
|
| 3530 |
static int |
| 3531 |
ToggleDeleteProc(segPtr, linePtr, treeGone) |
| 3532 |
TkTextSegment *segPtr; |
| 3533 |
TkTextLine *linePtr; |
| 3534 |
int treeGone; |
| 3535 |
|
| 3536 |
|
| 3537 |
{ |
| 3538 |
if (treeGone) { |
| 3539 |
ckfree((char *) segPtr); |
| 3540 |
return 0; |
| 3541 |
} |
| 3542 |
|
| 3543 |
|
| 3544 |
|
| 3545 |
|
| 3546 |
|
| 3547 |
|
| 3548 |
|
| 3549 |
|
| 3550 |
|
| 3551 |
if (segPtr->body.toggle.inNodeCounts) { |
| 3552 |
ChangeNodeToggleCount(linePtr->parentPtr, |
| 3553 |
segPtr->body.toggle.tagPtr, -1); |
| 3554 |
segPtr->body.toggle.inNodeCounts = 0; |
| 3555 |
} |
| 3556 |
return 1; |
| 3557 |
} |
| 3558 |
|
| 3559 |
|
| 3560 |
|
| 3561 |
|
| 3562 |
|
| 3563 |
|
| 3564 |
|
| 3565 |
|
| 3566 |
|
| 3567 |
|
| 3568 |
|
| 3569 |
|
| 3570 |
|
| 3571 |
|
| 3572 |
|
| 3573 |
|
| 3574 |
|
| 3575 |
|
| 3576 |
|
| 3577 |
|
| 3578 |
|
| 3579 |
|
| 3580 |
|
| 3581 |
|
| 3582 |
static TkTextSegment * |
| 3583 |
ToggleCleanupProc(segPtr, linePtr) |
| 3584 |
TkTextSegment *segPtr; |
| 3585 |
TkTextLine *linePtr; |
| 3586 |
{ |
| 3587 |
TkTextSegment *segPtr2, *prevPtr; |
| 3588 |
int counts; |
| 3589 |
|
| 3590 |
|
| 3591 |
|
| 3592 |
|
| 3593 |
|
| 3594 |
|
| 3595 |
|
| 3596 |
|
| 3597 |
if (segPtr->typePtr == &tkTextToggleOffType) { |
| 3598 |
for (prevPtr = segPtr, segPtr2 = prevPtr->nextPtr; |
| 3599 |
(segPtr2 != NULL) && (segPtr2->size == 0); |
| 3600 |
prevPtr = segPtr2, segPtr2 = prevPtr->nextPtr) { |
| 3601 |
if (segPtr2->typePtr != &tkTextToggleOnType) { |
| 3602 |
continue; |
| 3603 |
} |
| 3604 |
if (segPtr2->body.toggle.tagPtr != segPtr->body.toggle.tagPtr) { |
| 3605 |
continue; |
| 3606 |
} |
| 3607 |
counts = segPtr->body.toggle.inNodeCounts |
| 3608 |
+ segPtr2->body.toggle.inNodeCounts; |
| 3609 |
if (counts != 0) { |
| 3610 |
ChangeNodeToggleCount(linePtr->parentPtr, |
| 3611 |
segPtr->body.toggle.tagPtr, -counts); |
| 3612 |
} |
| 3613 |
prevPtr->nextPtr = segPtr2->nextPtr; |
| 3614 |
ckfree((char *) segPtr2); |
| 3615 |
segPtr2 = segPtr->nextPtr; |
| 3616 |
ckfree((char *) segPtr); |
| 3617 |
return segPtr2; |
| 3618 |
} |
| 3619 |
} |
| 3620 |
|
| 3621 |
if (!segPtr->body.toggle.inNodeCounts) { |
| 3622 |
ChangeNodeToggleCount(linePtr->parentPtr, |
| 3623 |
segPtr->body.toggle.tagPtr, 1); |
| 3624 |
segPtr->body.toggle.inNodeCounts = 1; |
| 3625 |
} |
| 3626 |
return segPtr; |
| 3627 |
} |
| 3628 |
|
| 3629 |
|
| 3630 |
|
| 3631 |
|
| 3632 |
|
| 3633 |
|
| 3634 |
|
| 3635 |
|
| 3636 |
|
| 3637 |
|
| 3638 |
|
| 3639 |
|
| 3640 |
|
| 3641 |
|
| 3642 |
|
| 3643 |
|
| 3644 |
|
| 3645 |
|
| 3646 |
static void |
| 3647 |
ToggleLineChangeProc(segPtr, linePtr) |
| 3648 |
TkTextSegment *segPtr; |
| 3649 |
TkTextLine *linePtr; |
| 3650 |
{ |
| 3651 |
if (segPtr->body.toggle.inNodeCounts) { |
| 3652 |
ChangeNodeToggleCount(linePtr->parentPtr, |
| 3653 |
segPtr->body.toggle.tagPtr, -1); |
| 3654 |
segPtr->body.toggle.inNodeCounts = 0; |
| 3655 |
} |
| 3656 |
} |
| 3657 |
|
| 3658 |
|
| 3659 |
|
| 3660 |
|
| 3661 |
|
| 3662 |
|
| 3663 |
|
| 3664 |
|
| 3665 |
|
| 3666 |
|
| 3667 |
|
| 3668 |
|
| 3669 |
|
| 3670 |
|
| 3671 |
|
| 3672 |
|
| 3673 |
|
| 3674 |
|
| 3675 |
static void |
| 3676 |
ToggleCheckProc(segPtr, linePtr) |
| 3677 |
TkTextSegment *segPtr; |
| 3678 |
TkTextLine *linePtr; |
| 3679 |
{ |
| 3680 |
register Summary *summaryPtr; |
| 3681 |
int needSummary; |
| 3682 |
|
| 3683 |
if (segPtr->size != 0) { |
| 3684 |
panic("ToggleCheckProc: segment had non-zero size"); |
| 3685 |
} |
| 3686 |
if (!segPtr->body.toggle.inNodeCounts) { |
| 3687 |
panic("ToggleCheckProc: toggle counts not updated in nodes"); |
| 3688 |
} |
| 3689 |
needSummary = (segPtr->body.toggle.tagPtr->tagRootPtr != linePtr->parentPtr); |
| 3690 |
for (summaryPtr = linePtr->parentPtr->summaryPtr; ; |
| 3691 |
summaryPtr = summaryPtr->nextPtr) { |
| 3692 |
if (summaryPtr == NULL) { |
| 3693 |
if (needSummary) { |
| 3694 |
panic("ToggleCheckProc: tag not present in node"); |
| 3695 |
} else { |
| 3696 |
break; |
| 3697 |
} |
| 3698 |
} |
| 3699 |
if (summaryPtr->tagPtr == segPtr->body.toggle.tagPtr) { |
| 3700 |
if (!needSummary) { |
| 3701 |
panic("ToggleCheckProc: tag present in root node summary"); |
| 3702 |
} |
| 3703 |
break; |
| 3704 |
} |
| 3705 |
} |
| 3706 |
} |
| 3707 |
|
| 3708 |
|
| 3709 |
|
| 3710 |
|
| 3711 |
|
| 3712 |
|
| 3713 |
|
| 3714 |
|
| 3715 |
|
| 3716 |
|
| 3717 |
|
| 3718 |
|
| 3719 |
|
| 3720 |
|
| 3721 |
|
| 3722 |
|
| 3723 |
|
| 3724 |
|
| 3725 |
int |
| 3726 |
TkBTreeCharsInLine(linePtr) |
| 3727 |
TkTextLine *linePtr; |
| 3728 |
|
| 3729 |
{ |
| 3730 |
TkTextSegment *segPtr; |
| 3731 |
int count; |
| 3732 |
|
| 3733 |
count = 0; |
| 3734 |
for (segPtr = linePtr->segPtr; segPtr != NULL; segPtr = segPtr->nextPtr) { |
| 3735 |
if (segPtr->typePtr == &tkTextCharType) { |
| 3736 |
count += Tcl_NumUtfChars(segPtr->body.chars, segPtr->size); |
| 3737 |
} else { |
| 3738 |
count += segPtr->size; |
| 3739 |
} |
| 3740 |
} |
| 3741 |
return count; |
| 3742 |
} |
| 3743 |
|
| 3744 |
int |
| 3745 |
TkBTreeBytesInLine(linePtr) |
| 3746 |
TkTextLine *linePtr; |
| 3747 |
|
| 3748 |
{ |
| 3749 |
TkTextSegment *segPtr; |
| 3750 |
int count; |
| 3751 |
|
| 3752 |
count = 0; |
| 3753 |
for (segPtr = linePtr->segPtr; segPtr != NULL; segPtr = segPtr->nextPtr) { |
| 3754 |
count += segPtr->size; |
| 3755 |
} |
| 3756 |
return count; |
| 3757 |
} |