00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 #include <memory.h>
00104 #include "udanax.h"
00105
00111 static void
00112 findnextaddressinvspace(
00113 typecorecrum *crumptr,
00114 typewid *offsetptr,
00115 Tumbler *nextvspacestartptr,
00116 Tumbler *vsaptr)
00117 {
00118 typecorecrum *ptr;
00119 if (!(ptr = findleftson((typecuc *) crumptr)))
00120 return;
00121
00122 Tumbler maxt;
00123 tumblerclear(&maxt);
00124
00125 for (; ptr; ptr = findrightbro(ptr)) {
00126 typewid reach, grasp;
00127 prologuend(ptr, offsetptr, &grasp, &reach);
00128
00129 if (whereoncrum(ptr, offsetptr, nextvspacestartptr, V) == THRUME) {
00130 findnextaddressinvspace(ptr, &grasp, nextvspacestartptr, vsaptr);
00131 return;
00132
00133 } else if (tumblercmp(&grasp.dsas[V], nextvspacestartptr) != GREATER) {
00134 tumblermax(&reach.dsas[V], &maxt, &maxt);
00135
00136 }
00137 }
00138 movetumbler(&maxt, vsaptr);
00139 }
00140
00149 static void
00150 findvsatoappend(
00151 typecorecrum *ptr,
00152 Tumbler *vsaptr)
00153 {
00154 typewid offset;
00155 clear(&offset, sizeof(offset));
00156
00157 tumblerclear(vsaptr);
00158
00159 Tumbler linkspacevstart;
00160 tumblerclear(&linkspacevstart);
00161 tumblerincrement(&linkspacevstart, 0, 2, &linkspacevstart);
00162
00163 typewid grasp, reach;
00164 prologuend(ptr, &offset, &grasp, &reach);
00165
00166
00167 if (iszerolock((Tumbler *) &ptr->cwid, widsize(POOM)) || (tumblercmp(&grasp.dsas[V], &linkspacevstart) != LESS)) {
00168 tumblerincrement(vsaptr, 0, 1, vsaptr);
00169 tumblerincrement(vsaptr, 1, 1, vsaptr);
00170
00171
00172 } else if (tumblercmp(&reach.dsas[V], &linkspacevstart) == LESS) {
00173 movetumbler(&reach.dsas[V], vsaptr);
00174
00175
00176 } else
00177 findnextaddressinvspace(ptr, &grasp, &linkspacevstart, vsaptr);
00178 }
00179
00187 bool
00188 appendpm(
00189 Session *sess,
00190 IStreamAddr *doc_isa,
00191 typetextset textset)
00192 {
00193
00194
00195
00196 typeorgl orglptr;
00197 if (!findorgl(sess, granf, doc_isa, &orglptr, WRITEBERT))
00198 return false;
00199
00200
00201
00202
00203
00204 Tumbler vsa;
00205 findvsatoappend((typecorecrum *) orglptr, &vsa);
00206
00207 return doinsert(sess, doc_isa, &vsa, textset);
00208 }
00209
00217 bool
00218 insertpm(
00219 Session *sess,
00220 Tumbler *orglisa,
00221 typeorgl orgl,
00222 Tumbler *vsaptr,
00223 typesporglset sporglset)
00224 {
00225 Tumbler lstream, lwidth;
00226 type2dbottomcruminfo linfo;
00227 typewid crumorigin, crumwidth;
00228 Tumbler zero;
00229 int shift, inc;
00230
00231 #ifndef DISTRIBUTION
00232 if (debug) {
00233 L("\nINSERTpm vsa ");
00234 dumptumbler(vsaptr);
00235 L("\n");
00236 dumpitemset((typeitem *) sporglset);
00237 }
00238 #endif
00239
00240 if (iszerotumbler(vsaptr)) {
00241 #ifndef DISTRIBUTION
00242 L("insertpm inserting at 0 ---punt zzzz?");
00243 #endif
00244 return false;
00245 }
00246
00247 tumblerclear(&zero);
00248
00249 if (tumblercmp(vsaptr, &zero) == LESS)
00250 assert(0);
00251
00252 logbertmodified(sess, orglisa);
00253 for (; sporglset; sporglset = (typesporglset) sporglset->xxxxsporgl.next) {
00254 unpacksporgl(sporglset, &lstream, &lwidth, &linfo);
00255
00256 #ifndef DISTRIBUTION
00257 footumbler("lstream = ", &lstream);
00258 #endif
00259 movetumbler(&lstream, &crumorigin.dsas[I]);
00260
00261 #ifndef DISTRIBUTION
00262 footumbler("lwidth = ", &lwidth);
00263 #endif
00264 movetumbler(&lwidth, &crumwidth.dsas[I]);
00265
00266 #ifndef DISTRIBUTION
00267 footumbler("vsaptr = ", vsaptr);
00268 #endif
00269 movetumbler(vsaptr, &crumorigin.dsas[V]);
00270
00271 shift = tumblerlength(vsaptr) - 1;
00272 inc = tumblerintdiff(&lwidth, &zero);
00273 tumblerincrement(&zero, shift, inc, &crumwidth.dsas[V]);
00274
00275 #ifndef DISTRIBUTION
00276 footumbler("crumwidth = ", &crumwidth.dsas[V]);
00277 #endif
00278
00279 if (iszerotumbler(&crumwidth.dsas[V]))
00280 assert(0);
00281
00282 #ifndef DISTRIBUTION
00283 if (debug) {
00284 L(" crumorigin: ");
00285 dumpwid(&crumorigin, POOM);
00286 L(" crumwidth: ");
00287 dumpwid(&crumwidth, POOM);
00288 }
00289 #endif
00290 insertnd(sess, (typecuc *) orgl, &crumorigin, &crumwidth, &linfo, V);
00291 tumbleradd(vsaptr, &crumwidth.dsas[V], vsaptr);
00292 }
00293 return true;
00294 }
00295
00303 bool
00304 rearrangepm(
00305 Session *sess,
00306 Tumbler *docisaptr,
00307 typeorgl docorgl,
00308 typecutseq *cutseqptr)
00309 {
00310 rearrangend((typecuc *) docorgl, cutseqptr, V);
00311 logbertmodified(sess, docisaptr);
00312
00313 return true;
00314 }
00315
00323 bool
00324 deletevspanpm(
00325 Session *sess,
00326 Tumbler *docisaptr,
00327 typeorgl docorgl,
00328 typevspan *vspanptr)
00329 {
00330 if (iszerotumbler(&vspanptr->width))
00331 return false;
00332
00333 deletend((typecuc *) docorgl, &vspanptr->stream, &vspanptr->width, V);
00334 logbertmodified(sess, docisaptr);
00335
00336 return true;
00337 }
00338
00346 bool
00347 retrievedocumentpartofvspanpm(
00348 Session *sess,
00349 typeorgl orgl,
00350 typevspan *vspanptr)
00351 {
00352 vspanptr->next = NULL;
00353 vspanptr->itemid = VSPANID;
00354
00355 movetumbler(&((typecuc *) orgl)->cdsp.dsas[V], &vspanptr->stream);
00356 movetumbler(&((typecuc *) orgl)->cwid.dsas[V], &vspanptr->width);
00357
00358 return true;
00359 }
00360
00368 bool
00369 retrievevspanpm(
00370 Session *sess,
00371 typeorgl orgl,
00372 typevspan *vspanptr)
00373 {
00374 vspanptr->next = NULL;
00375 vspanptr->itemid = VSPANID;
00376
00377 movetumbler(&((typecuc *) orgl)->cdsp.dsas[V], &vspanptr->stream);
00378 movetumbler(&((typecuc *) orgl)->cwid.dsas[V], &vspanptr->width);
00379
00380 return true;
00381 }
00382
00390 static bool
00391 istextcrum(
00392 typecorecrum *crumptr)
00393 {
00394 if (crumptr->cdsp.dsas[V].mantissa[1] == 0 && is1story(&crumptr->cwid.dsas[V])) {
00395 return true;
00396 }
00397 return false;
00398 }
00399
00407 static bool
00408 islinkcrum(
00409 typecorecrum *crumptr)
00410 {
00411 if (crumptr->cdsp.dsas[V].mantissa[0] == 1 && crumptr->cdsp.dsas[V].mantissa[1] != 0) {
00412
00413
00414 return true;
00415 }
00416 return false;
00417 }
00418
00426 static void
00427 maxtextwid(
00428 Session *sess,
00429 typecorecrum *crumptr,
00430 Tumbler *voffset,
00431 Tumbler *maxwid)
00432 {
00433 if (istextcrum(crumptr)) {
00434 Tumbler localvoffset;
00435 tumbleradd(voffset, &crumptr->cwid.dsas[V], &localvoffset);
00436
00437 tumblermax(&localvoffset, maxwid, maxwid);
00438
00439 } else {
00440 Tumbler localvoffset;
00441
00442
00443 tumblercopy(voffset, &localvoffset);
00444
00445 typecorecrum *ptr;
00446 for (ptr = findleftson((typecuc *) crumptr); ptr; ptr = findrightbro(ptr)) {
00447 if (ptr && !islinkcrum(ptr))
00448 maxtextwid(sess, ptr, &localvoffset, maxwid);
00449
00450
00451 }
00452 }
00453 }
00454
00462 static typevspan *
00463 makevspan(
00464 Session *sess,
00465 typevspan *spanptr,
00466 typevspan *nextspan)
00467 {
00468 typevspan *ret = new(sess) typevspan;
00469
00470
00471 movetumbler(&spanptr->stream, &ret->stream);
00472 movetumbler(&spanptr->width, &ret->width);
00473
00474 ret->itemid = VSPANID;
00475 ret->next = nextspan;
00476
00477 return ret;
00478 }
00479
00487 static void
00488 putvspaninlist(
00489 Session *sess,
00490 typevspan *spanptr,
00491 typevspanset *spansetptr)
00492 {
00493 Tumbler newspanend, oldspanend;
00494 int startcmp, endcmp, spancmp;
00495
00496 typevspan *last = NULL;
00497
00498 typevspan *ptr = *spansetptr;
00499 if (!ptr) {
00500 *spansetptr = makevspan(sess, spanptr, (typevspan *) NULL);
00501 return;
00502 }
00503
00504 for (; ptr; last = ptr, ptr = ptr->next) {
00505 tumbleradd(&spanptr->stream, &spanptr->width, &newspanend);
00506 tumbleradd(&ptr->stream, &ptr->width, &oldspanend);
00507
00508 spancmp = tumblercmp(&spanptr->stream, &oldspanend);
00509 if (!spancmp) {
00510 tumbleradd(&ptr->width, &spanptr->width, &ptr->width);
00511 return;
00512 } else if (spancmp == GREATER)
00513 continue;
00514
00515 spancmp = tumblercmp(&ptr->stream, &newspanend);
00516 if (!spancmp) {
00517 movetumbler(&spanptr->stream, &ptr->stream);
00518 tumbleradd(&spanptr->width, &ptr->width, &ptr->width);
00519 return;
00520 } else if (spancmp == GREATER) {
00521 if (ptr != *spansetptr)
00522 last->next = makevspan(sess, spanptr, ptr);
00523 else
00524 *spansetptr = makevspan(sess, spanptr, ptr);
00525 return;
00526 }
00527
00528 startcmp = tumblercmp(&spanptr->stream, &ptr->stream);
00529 endcmp = tumblercmp(&newspanend, &oldspanend);
00530 if (startcmp > LESS && endcmp < GREATER)
00531 return;
00532
00533 switch (startcmp) {
00534 case EQUAL:
00535 if (endcmp == GREATER)
00536 movetumbler(&spanptr->width, &ptr->width);
00537 return;
00538 case LESS:
00539 movetumbler(&spanptr->stream, &ptr->stream);
00540 if (endcmp == GREATER)
00541 movetumbler(&spanptr->width, &ptr->width);
00542 else
00543 tumblersub(&oldspanend, &spanptr->stream, &ptr->width);
00544 break;
00545 case GREATER:
00546 if (endcmp == GREATER) {
00547 tumblersub(&newspanend, &ptr->stream, &ptr->width);
00548 return;
00549 }
00550 }
00551 }
00552 last->next = makevspan(sess, spanptr, (typevspan *) NULL);
00553 }
00554
00562 bool
00563 retrievevspansetpm(
00564 Session *sess,
00565 typeorgl orgl,
00566 typevspanset *vspansetptr)
00567 {
00568 typecorecrum *ccptr = (typecorecrum *) orgl;
00569
00570 *vspansetptr = NULL;
00571 if (is1story(&ccptr->cwid.dsas[V])) {
00572 typevspan vspan;
00573 vspan.next = NULL;
00574 vspan.itemid = VSPANID;
00575
00576 movetumbler(&ccptr->cdsp.dsas[V], &vspan.stream);
00577 movetumbler(&ccptr->cwid.dsas[V], &vspan.width);
00578
00579 putvspaninlist(sess, &vspan, vspansetptr);
00580 return true;
00581
00582 } else {
00583
00584
00585
00586
00587
00588
00589 typevspan bytevspan;
00590 bytevspan.next = NULL;
00591 bytevspan.itemid = VSPANID;
00592
00593 typevspan linkvspan;
00594 linkvspan.next = NULL;
00595 linkvspan.itemid = VSPANID;
00596
00597 movetumbler(&ccptr->cdsp.dsas[V], &bytevspan.stream);
00598
00599 Tumbler voffset;
00600 tumblerclear(&voffset);
00601
00602 Tumbler maxwid;
00603 tumblerclear(&maxwid);
00604 maxtextwid(sess, ccptr, &voffset, &maxwid);
00605
00606 movetumbler(&maxwid, &bytevspan.width);
00607
00608 movetumbler(&ccptr->cdsp.dsas[V], &linkvspan.stream);
00609 linkvspan.stream.mantissa[0] = 2;
00610
00611 movetumbler(&ccptr->cwid.dsas[V], &linkvspan.width);
00612 linkvspan.width.mantissa[0] = 0;
00613 tumblerjustify(&linkvspan.width);
00614
00615 putvspaninlist(sess, &bytevspan, vspansetptr);
00616 putvspaninlist(sess, &linkvspan, vspansetptr);
00617
00618 return true;
00619 }
00620 }
00621
00629 static typespanset *
00630 span2spanset(
00631 Session *sess,
00632 typeorgl orgl,
00633 typespanset restrictionspanptr,
00634 int restrictionindex,
00635 typespanset *targspansetptr,
00636 int targindex)
00637 {
00638 typespan foundspan;
00639 typespan *nextptr = NULL;
00640
00641 #ifndef DISTRIBUTION
00642 foo("entering span2spanset\n");
00643 #endif
00644
00645 Context *context = retrieverestricted((typecuc *) orgl, restrictionspanptr, restrictionindex, (typespan *) NULL, targindex, (IStreamAddr *) NULL);
00646
00647 #ifndef DISTRIBUTION
00648 foocontextlist("in sapan2spanset after retrieverestrictec context =", context);
00649 #endif
00650
00651 Context *c;
00652 for (c = context; c; c = (Context *) c->nextcontext) {
00653
00654 #ifndef DISTRIBUTION
00655 foocontext("in span2spanset loop ", c);
00656 #endif
00657
00658 context2span(c, restrictionspanptr, restrictionindex, &foundspan, targindex);
00659 nextptr = (typespan *) onitemlist(sess, (typeitem *) & foundspan, (typeitemset *) targspansetptr);
00660 }
00661
00662 if (!context) {
00663 return (targspansetptr);
00664 }
00665
00666 #ifndef DISTRIBUTION
00667 foocontext("leaving span2spanset returning context = \n", context);
00668 #endif
00669
00670 contextfree(context);
00671 return &nextptr->next;
00672 }
00673
00681 static typespanset *
00682 permute(
00683 Session *sess,
00684 typeorgl orgl,
00685 typespanset restrictionspanset,
00686 int restrictionindex,
00687 typespanset *targspansetptr,
00688 int targindex)
00689 {
00690 typespanset *save = targspansetptr;
00691
00692 #ifndef DISTRIBUTION
00693 foo("entering permute\n");
00694 foospanset("targspanset ", *targspansetptr);
00695 foospanset("restrictionset is ", restrictionspanset);
00696 #endif
00697
00698
00699
00700 for (; restrictionspanset; restrictionspanset = restrictionspanset->next) {
00701 targspansetptr = span2spanset(sess, orgl, restrictionspanset, restrictionindex, targspansetptr, targindex);
00702 }
00703
00704 #ifndef DISTRIBUTION
00705 foospanset("leaving permute\n", *save);
00706
00707 #endif
00708
00709 return save;
00710 }
00711
00719 typevspanset *
00720 ispan2vspanset(
00721 Session *sess,
00722 typeorgl orgl,
00723 typeispan *ispanptr,
00724 typevspanset *vspansetptr)
00725 {
00726 return permute(sess, orgl, ispanptr, I, vspansetptr, V);
00727 }
00728
00736 typeispanset *
00737 vspanset2ispanset(
00738 Session *sess,
00739 typeorgl orgl,
00740 typevspanset vspanptr,
00741 typeispanset *ispansetptr)
00742 {
00743 return permute(sess, orgl, vspanptr, V, ispansetptr, I);
00744 }
00745
00746
00747
00748
00749
00757 typeitem *
00758 onitemlist(
00759 Session *sess,
00760 typeitem *itemptr,
00761 typeitemset *itemsetptr)
00762 {
00763 typeitem *temp, *newitem = NULL;
00764
00765
00766 #ifndef DISTRIBUTION
00767 if (!itemsetptr)
00768 assert(0);
00769
00770 if (!itemptr)
00771 assert(0);
00772 #else
00773 if (!itemsetptr || !itemptr)
00774 assert(0);
00775 #endif
00776
00777 switch (((typeitemheader *) itemptr)->itemid) {
00778 case TEXTID:
00779 newitem = (typeitem *) new(sess) typetext;
00780
00781 movmem(itemptr, newitem, sizeof(typetext));
00782 break;
00783
00784 case ISPANID:
00785 newitem = (typeitem *) new(sess) typeispan;
00786
00787 movmem(itemptr, newitem, sizeof(typeispan));
00788 break;
00789
00790 case VSPANID:
00791 newitem = (typeitem *) new(sess) typevspan;
00792
00793 movmem(itemptr, newitem, sizeof(typevspan));
00794 break;
00795
00796 case VSPECID:
00797 newitem = (typeitem *) new(sess) typevspec;
00798
00799 movmem(itemptr, newitem, sizeof(typevspec));
00800 break;
00801
00802 case NODEID:
00803 newitem = (typeitem *) new(sess) typeboolsetnode;
00804
00805 movmem(itemptr, newitem, sizeof(typeboolsetnode));
00806 break;
00807
00808 case ADDRESSID:
00809 newitem = (typeitem *) new(sess) typeaddress;
00810
00811 movmem(itemptr, newitem, sizeof(typeaddress));
00812 break;
00813
00814 case SPORGLID:
00815
00816
00817 newitem = (typeitem *) new(sess) typesporglitem;
00818
00819 movmem(itemptr, newitem, sizeof(typesporglitem));
00820 break;
00821
00822 default:
00823 assert(0);
00824 }
00825
00826 ((typeitemheader *) newitem)->next = NULL;
00827 if (*itemsetptr == NULL) {
00828 *itemsetptr = newitem;
00829 } else {
00830
00831
00832 for (temp = *itemsetptr;
00833 #ifndef DISTRIBUTION
00834 checkitem("onitem2.5: ", temp), checkitem("onitem2.75: ", (typeitem *) ((typeitemheader *) temp)->next),
00835 #endif
00836 temp && ((typeitemheader *) temp)->next; temp = (typeitem *) ((typeitemheader *) temp)->next)
00837
00838 #ifndef DISTRIBUTION
00839 if (debug) {
00840 checkitem("onitem3: ", temp);
00841 }
00842 #else
00843 ;
00844 #endif
00845
00846 ((typeitemheader *) temp)->next = (typeitemheader *) newitem;
00847 }
00848
00849 return newitem;
00850 }
00851
00859 bool
00860 isemptyorgl(
00861 typeorgl fullcrumptr)
00862 {
00863 return iszerolock((Tumbler *) & ((typecuc *) fullcrumptr)->cwid, widsize(POOM)) && iszerolock((Tumbler *) & ((typecuc *) fullcrumptr)->cdsp, dspsize(POOM));
00864 }