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 #include <memory.h>
00086 #include "udanax.h"
00087
00088 static void makecutsbackuptohere(typecuc *ptr, typewid *offset, typeknives *knives);
00089
00097 static bool
00098 crumiscut(
00099 typecuc *ptr,
00100 typewid *offset,
00101 typeknives *knives)
00102 {
00103 int i;
00104 for (i = 0; i < knives->nblades; ++i) {
00105 if (whereoncrum((typecorecrum *) ptr, offset, &knives->blades[i], knives->dimension) == THRUME)
00106 return true;
00107 }
00108 return false;
00109 }
00110
00118 static bool
00119 sonsarecut(
00120 typecuc *ptr,
00121 typewid *offset,
00122 typeknives *knives)
00123 {
00124 typecuc *son;
00125 typewid grasp;
00126
00127 prologuend((typecorecrum *) ptr, offset, &grasp, (typedsp *) NULL);
00128 for (son = (typecuc *) findleftson(ptr); son; son = (typecuc *) findrightbro((typecorecrum *) son)) {
00129 if (crumiscut(son, &grasp, knives))
00130 return true;
00131 }
00132
00133 return false;
00134 }
00135
00143 static void
00144 makecutsdownnd(
00145 typecuc *fullcrumptr,
00146 typewid *offset,
00147 typeknives *knives)
00148 {
00149 typecuc *ptr;
00150 typecorecrum *sonptr, *son;
00151 int n;
00152
00153 ptr = fullcrumptr;
00154 for (; (knives->nblades > 1) && false && ptr->height;) {
00155 for (n = 0, son = findleftson(ptr); son; son = findrightbro(son)) {
00156 if (crumiscut((typecuc *) son, offset, knives)) {
00157 n++;
00158 sonptr = son;
00159 }
00160 }
00161
00162 if (n == 1) {
00163 prologuend((typecorecrum *) ptr, offset, offset, (typedsp *) NULL);
00164 ptr = (typecuc *) sonptr;
00165 } else
00166 break;
00167 }
00168
00169 makecutsbackuptohere(ptr, offset, knives);
00170 if (toomanysons(ptr)) {
00171
00172 if (isfullcrum((typecorecrum *) ptr)) {
00173
00174
00175
00176 levelpush(ptr);
00177 makecutsnd(fullcrumptr, knives);
00178
00179 } else
00180 makecutsnd(fullcrumptr, knives);
00181 }
00182 }
00183
00191 static void
00192 cutsons(
00193 typecuc *ptr,
00194 typewid *offset,
00195 typeknives *knives)
00196 {
00197 typewid grasp;
00198 typecorecrum *son, *nextson;
00199
00200 while (sonsarecut(ptr, offset, knives)) {
00201 setwispupwards(ptr, 1);
00202 for (son = findleftson(ptr); son; son = nextson) {
00203 nextson = findrightbro(son);
00204 prologuend((typecorecrum *) ptr, offset, &grasp, (typedsp *) NULL);
00205 for (; crumiscut((typecuc *) son, &grasp, knives);
00206 prologuend((typecorecrum *) ptr, offset, &grasp, (typedsp *) NULL)) {
00207 makecutsbackuptohere((typecuc *) son, &grasp, knives);
00208 }
00209 }
00210 }
00211 }
00212
00220 static bool
00221 crumleftofithcut(
00222 typecorecrum *ptr,
00223 typewid *offset,
00224 typeknives *knives,
00225 int i)
00226 {
00227 if (whereoncrum(ptr, offset, &knives->blades[i], knives->dimension) > THRUME)
00228 return false;
00229 else
00230 return true;
00231 }
00232
00240 static void
00241 newpeelcrumoffnd(
00242 typecorecrum *ptr,
00243 typecorecrum *newuncle)
00244 {
00245 typedsp temp;
00246 typecuc *father;
00247 typedsp grasp;
00248 typewid origin;
00249 typedsp offset;
00250
00251 if (!roomformoresons((typecuc *) newuncle))
00252 assert(0);
00253
00254 if (isfullcrum(ptr))
00255 assert(0);
00256
00257 ivemodified(ptr);
00258 father = findfather(ptr);
00259 clear(&offset, sizeof(offset));
00260 dspadd(&father->cdsp, &ptr->cdsp, &origin, (int) father->cenftype);
00261
00262
00263
00264
00265 (void)tumblercheckptr((Tumbler *) & origin, (int *) ptr);
00266
00267 makeroomonleftnd((typecuc *) newuncle, &offset, &origin, &grasp);
00268 disown(ptr);
00269 adopt(ptr, LEFTMOSTSON, newuncle);
00270
00271
00272 dspadd(&father->cdsp, &ptr->cdsp, &temp, (int) ptr->cenftype);
00273
00274
00275
00276 (void)tumblercheckptr((Tumbler *) & temp, (int *) ptr);
00277
00278
00279 dspsub(&temp, &newuncle->cdsp, &ptr->cdsp, (int) ptr->cenftype);
00280
00281
00282
00283
00284 (void)tumblercheckptr((Tumbler *) & ptr->cdsp, (int *) ptr);
00285
00286 ivemodified(ptr);
00287 ivemodified(newuncle);
00288
00289 setwispupwards((typecuc *) ptr, 0);
00290 setwispupwards((typecuc *) newuncle, 0);
00291 setwispupwards(father, 1);
00292
00293 if (toomanysons((typecuc *) newuncle))
00294 assert(0);
00295
00296
00297
00298 }
00299
00307 static void
00308 peelsoncorrectly(
00309 typecorecrum *ptr,
00310 typewid *offset,
00311 typecorecrum *son,
00312 typewid *grasp,
00313 typeknives *knives,
00314 int i)
00315 {
00316 typecuc *uncle;
00317
00318 uncle = (typecuc *) findleftmostbro(ptr);
00319 for (; uncle; uncle = (typecuc *) findrightbro((typecorecrum *) uncle)) {
00320 if (uncle == (typecuc *) ptr) {
00321 continue;
00322 }
00323 if (roomformoresons(uncle)) {
00324 if (crumleftofithcut((typecorecrum *) uncle, offset, knives, i)) {
00325 newpeelcrumoffnd((typecorecrum *) son, (typecorecrum *) uncle);
00326 return;
00327 }
00328 }
00329 }
00330 uncle = (typecuc *) createcrum((int) ptr->height, (int) ptr->cenftype);
00331 adopt((typecorecrum *) uncle, RIGHTBRO, findrightmostbro(ptr));
00332 movewisp(&ptr->cdsp, &uncle->cdsp);
00333 newpeelcrumoffnd((typecorecrum *) son, (typecorecrum *) uncle);
00334 }
00335
00343 static bool
00344 crumiscutbyithknife(
00345 typecuc *ptr,
00346 typewid *offset,
00347 typeknives *knives,
00348 int i)
00349 {
00350 if (whereoncrum((typecorecrum *) ptr, offset, &knives->blades[i], knives->dimension) == THRUME)
00351 return true;
00352
00353 return false;
00354 }
00355
00363 static void
00364 makeithcutonson(
00365 typecorecrum *ptr,
00366 typewid *offset,
00367 typecorecrum *son,
00368 typewid *grasp,
00369 typeknives *knives,
00370 int i)
00371 {
00372 int temp;
00373
00374 if (!crumiscutbyithknife((typecuc *) ptr, offset, knives, i)) {
00375 #ifndef DISTRIBUTION
00376 L("foo return in makeithcutonson\n");
00377 #endif
00378 return;
00379 }
00380 if ((temp = whereoncrum(son, grasp, &knives->blades[i], knives->dimension)) < THRUME) {
00381 peelsoncorrectly(ptr, offset, son, grasp, knives, i);
00382 setwispupwards((typecuc *) ptr, 1);
00383 if (!crumiscutbyithknife((typecuc *) ptr, offset, knives, i)) {
00384 setwispupwards((typecuc *) ptr, 1);
00385
00386
00387 if (((typecuc *) ptr)->numberofsons == 0) {
00388 #ifndef DISTRIBUTION
00389 displaycutspm(knives);
00390 dumpwid(offset, ptr->cenftype);
00391 L("sons went away\n");
00392
00393 check((typecuc *) ptr);
00394 #endif
00395 return;
00396 }
00397 return;
00398 }
00399 (void)findleftson((typecuc *) ptr);
00400 if (((typecuc *) ptr)->numberofsons == 0) {
00401 #ifndef DISTRIBUTION
00402 displaycutspm(knives);
00403 dumpwid(offset, ptr->cenftype);
00404 L("____sons went away\n");
00405 dump(ptr);
00406 check((typecuc *) ptr);
00407 assert(0);
00408 #else
00409 assert(0);
00410 #endif
00411 }
00412 } else if (temp == THRUME)
00413 assert(0);
00414 }
00415
00423 static bool
00424 peeloffcorrectson(
00425 typecorecrum *ptr,
00426 typeknives *knives)
00427 {
00428 typecorecrum *bro, *uncle;
00429
00430 if (toomanysons((typecuc *) ptr)) {
00431 for (bro = findrightbro(ptr); bro; ptr = findrightbro(ptr)) {
00432 if (roomformoresons ((typecuc *) bro)) {
00433 newpeelcrumoffnd(findleftson((typecuc *) ptr), bro);
00434 return true;
00435 }
00436 }
00437 uncle = createcrum((int) ptr->height, (int) ptr->cenftype);
00438 adopt(uncle, RIGHTBRO, ptr);
00439 movewisp(&ptr->cdsp, &uncle->cdsp);
00440 newpeelcrumoffnd(findleftson((typecuc *) ptr), uncle);
00441 }
00442 return true;
00443 }
00444
00452 static void
00453 slicecbcpm(
00454 typecorecrum *ptr,
00455 typewid *offset,
00456 typecorecrum *newcc,
00457 Tumbler *cut,
00458 int index)
00459 {
00460 typedsp grasp ;
00461 Tumbler localcut;
00462 typewid newwid;
00463 int i;
00464
00465
00466 int enftype = ptr->cenftype;
00467
00468 prologuend(ptr, offset, &grasp, (typedsp *) NULL);
00469 if (whereoncrum(ptr, offset, cut, index) != THRUME)
00470 assert(0);
00471
00472 if (!lockis1story(ptr->cwid.dsas, (unsigned)widsize(enftype)))
00473 assert(0);
00474
00475 tumblersub(cut, &grasp.dsas[index], &localcut);
00476
00477 if (localcut.exp != ptr->cwid.dsas[index].exp) {
00478 #ifndef DISTRIBUTION
00479 dump(ptr);
00480 dump(newcc);
00481 dumptumbler(cut);
00482 dumptumbler(&localcut);
00483 dumpwholetree(ptr);
00484 assert(0);
00485 #else
00486 assert(0);
00487 #endif
00488 }
00489 if (!is1story(&localcut)) {
00490 #ifndef DISTRIBUTION
00491 L("\nin slicecbcpm ptr \n");
00492 dump(ptr);
00493 L("\nin slicecbcpm newcc \n");
00494 dump(newcc);
00495 L("\nin slicecbcpm offset \n");
00496 dumpwid(offset, ptr->cenftype);
00497 L("\nin slicecbcpm grasp \n");
00498 dumpwid(&grasp, ptr->cenftype);
00499 L("\nin slicecbcpm cut \n");
00500 dumptumbler(cut);
00501 L("\nin slicecbcpm localcut \n");
00502 dumptumbler(&localcut);
00503 L("\nin slicecbcpm wholedamn tree \n");
00504 dumpwholetree(ptr);
00505 assert(0);
00506 #else
00507 assert(0);
00508 #endif
00509 }
00510
00511 if (tumblerlength(cut) != tumblerlength(&ptr->cwid.dsas[index]))
00512 assert(0);
00513
00514 movewisp(&ptr->cwid, &newwid);
00515 for (i = 0; i < widsize(enftype); i++) {
00516 newwid.dsas[i].mantissa[0] = localcut.mantissa[0];
00517 tumblerjustify(&newwid.dsas[i]);
00518 }
00519
00520
00521 locksubtract((Tumbler *) & ptr->cwid, (Tumbler *) & newwid, (Tumbler *) & newcc->cwid, (unsigned)widsize(enftype));
00522
00523 movewisp(&newwid, &ptr->cwid);
00524 dspadd(&ptr->cdsp, &ptr->cwid, &newcc->cdsp, enftype);
00525 move2dinfo(&((type2dcbc *) ptr)->c2dinfo, &((type2dcbc *) newcc)->c2dinfo);
00526 adopt(newcc, RIGHTBRO, ptr);
00527
00528 }
00529
00537 void
00538 makecutsnd(
00539 typecuc *fullcrumptr,
00540 typeknives *knives)
00541 {
00542 typewid offset;
00543
00544
00545
00546 clear(&offset, sizeof(offset));
00547 makecutsdownnd(fullcrumptr, &offset, knives);
00548 clear(&offset, sizeof(offset));
00549 for (fullcrumptr = findfullcrum((typecorecrum *) fullcrumptr); sonsarecut(fullcrumptr, &offset, knives);
00550 fullcrumptr = findfullcrum((typecorecrum *) fullcrumptr)) {
00551 clear(&offset, sizeof(offset));
00552 makecutsdownnd(fullcrumptr, &offset, knives);
00553 }
00554 #ifndef DISTRIBUTION
00555 asserttreeisok((typecorecrum *) fullcrumptr);
00556 #endif
00557 }
00558
00566 static void
00567 makecutsbackuptohere(
00568 typecuc *ptr,
00569 typewid *offset,
00570 typeknives *knives)
00571 {
00572 typewid grasp;
00573 int i;
00574 typecuc *son, *newcc, *nextson;
00575
00576 if (ptr->height == 0) {
00577 for (i = 0; i < knives->nblades; i++) {
00578 if (whereoncrum((typecorecrum *) ptr, offset, &knives->blades[i], knives->dimension) == THRUME) {
00579 newcc = (typecuc *) createcrum((int) ptr->height, (int) ptr->cenftype);
00580 if (ptr->cenftype == GRAN) {
00581 ((typecbc *) newcc)->cinfo.infotype = ((typecbc *) ptr)->cinfo.infotype;
00582 }
00583 slicecbcpm((typecorecrum *) ptr, offset, (typecorecrum *) newcc, &knives->blades[i], knives->dimension);
00584 ivemodified((typecorecrum *) ptr);
00585 ivemodified((typecorecrum *) newcc);
00586 setwisp((typecorecrum *) ptr);
00587
00588
00589 }
00590 }
00591 return;
00592 } else {
00593 for (i = 0; i < knives->nblades; ++i) {
00594 cutsons(ptr, offset, knives);
00595
00596 if (!isfullcrum((typecorecrum *) ptr)) {
00597 setwispupwards(ptr, 0);
00598 if (crumiscutbyithknife(ptr, offset, knives, i)) {
00599 for (son = (typecuc *) findleftson(ptr); son; son = nextson) {
00600 nextson = (typecuc *) findrightbro((typecorecrum *)
00601 son);
00602 prologuend((typecorecrum *) ptr, offset, &grasp, (typedsp *) NULL);
00603
00604 makeithcutonson((typecorecrum *) ptr, offset, (typecorecrum *) son, &grasp, knives, i);
00605 if (!crumiscutbyithknife(ptr, offset, knives, i)) {
00606 if (ptr->numberofsons == 0) {
00607 return;
00608 }
00609 break;
00610 }
00611 }
00612 }
00613 setwispupwards(ptr, 0);
00614 }
00615
00616 }
00617 }
00618 if (!isfullcrum((typecorecrum *) ptr)) {
00619 if (toomanysons(ptr)) {
00620 while (toomanysons(ptr)) {
00621 #ifndef DISTRIBUTION
00622 L("setwispupwards 4\n" );
00623 #endif
00624 setwispupwards(ptr, 0);
00625
00626 #ifndef DISTRIBUTION
00627 L("toomanysons peel\n");
00628 #endif
00629 peeloffcorrectson((typecorecrum *) ptr, knives);
00630 }
00631 #ifndef DISTRIBUTION
00632 L("calling makecutsbackuptohere\n");
00633 #endif
00634 makecutsbackuptohere(ptr, offset, knives);
00635 }
00636 } else if (toomanysons(ptr)) {
00637 #ifndef DISTRIBUTION
00638 L("________________toomanysons in fullcrum\n");
00639 #endif
00640 }
00641 setwispupwards(ptr, 1);
00642
00643 }