libsrc/edit.cxx

Go to the documentation of this file.
00001 /**********************************************************************
00002  * Copyright 2002 Jeff Rush <jrush@taupro.com>
00003  * Original Copyright 1979-2002 Udanax.com
00004  *
00005  * This file is part of the Udanax xanalogical storage system.
00006  *
00007  * Udanax is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * Udanax is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with Udanax; if not, write to the Free Software Foundation,
00019  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  **********************************************************************/
00021 
00030 /* Modification History:
00031  * $Log: edit.cxx,v $
00032  * Revision 1.11  2004/09/11 13:59:21  jrush
00033  * Changed all fprintf's to stderr to use the Nana library L() macro.  Also
00034  * removed a 2-3 minor compiler warnings.
00035  *
00036  * Revision 1.10  2004/09/04 16:02:17  jrush
00037  * Added Doxygen headers before each and every function definition.
00038  *
00039  * Revision 1.9  2002/07/26 04:30:29  jrush
00040  * Replaced gerror() with assert()
00041  *
00042  * Revision 1.8  2002/05/28 04:22:29  jrush
00043  * Adjusted source files to comply with GPL licensing.
00044  *
00045  * Revision 1.7  2002/05/28 02:49:42  jrush
00046  * Made static any functions and global variables private to this source file
00047  * and commented out any unused functions.
00048  *
00049  * Revision 1.6  2002/04/12 11:56:43  jrush
00050  * Reorganized include file layout, renamed xanadu.h to udanax.h and
00051  * typecontext/typecrumcontext to C++ class Context/CrumContext.
00052  *
00053  * Revision 1.5  2002/04/09 21:45:46  jrush
00054  * Renamed class 'tumbler' to 'Tumbler', for consistency with Python sources,
00055  * and changed typeisa from typedef to a subclass, in preparation for cleaning
00056  * up the type/class tree.
00057  *
00058  * Revision 1.4  2002/04/06 19:51:30  jrush
00059  * Renamed TRUE/FALSE constant use to the C++ standard of true/false.
00060  *
00061  * Revision 1.3  2002/04/06 15:01:17  jrush
00062  * Changed INT to just 'int'.
00063  *
00064  * Revision 1.2  2002/02/14 09:27:43  jrush
00065  * Cleaned up source:
00066  *
00067  * 1. ran thru the indent tool to achieve a standard look,
00068  * 2. added structured comments at top for use with DOxygen reporting
00069  *    as well as CVS keywords,
00070  * 3. fixed compiler warnings re ambiguous assign/compares,
00071  *    needed casts and unused/uninitialized variables,
00072  * 4. fixed funcs that didn't specify a return type,
00073  * 5. centralized prototypes in protos.h, removing incomplete ones,
00074  * 6. cleaned up use of bool/BOOLEAN type to suit C++ type,
00075  * 7. fixed initializer nesting in tumbler constants,
00076  * 8. renamed vars that conflict with C++ keywords (new, this),
00077  * 9. fixed global/extern confusion re some global vars.
00078  *
00079  */
00080 
00081 #include <string.h>
00082 #include "udanax.h"
00083 
00091     static int
00092 deletecutsectionnd(
00093     typecorecrum *ptr,
00094     typewid      *offset,
00095     typeknives   *knives)
00096 {
00097     int i, cmp;
00098 
00099     for (i = knives->nblades - 1; i >= 0; --i) {        /* unique to delete */
00100         cmp = whereoncrum(ptr, offset, &knives->blades[i], knives->dimension);
00101         if (cmp == THRUME) {
00102             return (-1);
00103         } else if (cmp <= ONMYLEFTBORDER) {     /* compare last to first */
00104             return (i + 1);
00105         }
00106     }
00107     return (0);
00108 }
00109 
00117 /* use with SPAN and POOM */
00118     void
00119 deletend(
00120     typecuc *fullcrumptr,
00121     Tumbler *origin,
00122     Tumbler *width,
00123     int      index)
00124 {
00125     typeknives knives;
00126     typewid offset, grasp, reach;
00127     typecuc *father, *ptr, *next;
00128     typewid foffset, fgrasp;
00129 
00130     clear(&offset, sizeof(offset));    /* fullcrum alway has zero offset */
00131     prologuend((typecorecrum *) fullcrumptr, &offset, &grasp, &reach);
00132     movetumbler(origin, &knives.blades[0]);
00133     tumbleradd(origin, width, &knives.blades[1]);
00134     knives.nblades = 2;
00135     knives.dimension = index;
00136     makecutsnd(fullcrumptr, &knives);
00137     newfindintersectionnd(fullcrumptr, &knives, &father, &foffset);
00138     prologuend((typecorecrum *) father, &foffset, &fgrasp, (typedsp *) NULL);
00139     for (ptr = (typecuc *) findleftson(father); ptr; ptr = next) {
00140         next = (typecuc *) findrightbro((typecorecrum *) ptr);
00141         switch (deletecutsectionnd((typecorecrum *) ptr, &fgrasp, &knives)) {
00142         case -1:
00143             assert(0); // deletend can't classify crum
00144         case 0:
00145             break;
00146         case 1:
00147             disown((typecorecrum *) ptr);
00148             subtreefree((typecorecrum *) ptr);
00149             break;
00150         case 2:
00151             tumblersub(&ptr->cdsp.dsas[index], width, &ptr->cdsp.dsas[index]);
00152 /* This will get set to modified in setwisp */
00153             break;
00154         default:
00155             assert(0); // unexpected cutsection
00156         }
00157     }
00158     setwispupwards(father, 1);
00159     recombine(father);
00160 }
00161 
00169 /* Prepares offsets for both 3 and 4 cut rearranges */
00170 
00171     static void
00172 makeoffsetsfor3or4cuts(
00173     typeknives *knives,
00174     Tumbler     diff[])
00175 {
00176     Tumbler a, b;
00177 
00178 /* diff[0] is simply ignored */
00179     if (knives->nblades == 4) {
00180         tumblersub(&knives->blades[2], &knives->blades[0], &(diff[1]));
00181         tumblersub(&knives->blades[1], &knives->blades[0], &a);
00182         tumblersub(&knives->blades[3], &knives->blades[2], &b);
00183         tumblersub(&b, &a, &(diff[2]));
00184 /* tumblersub (&knives->blades[0], &knives->blades[2], &(diff[3])); *//* should be <0 */
00185         movetumbler(&diff[1], &diff[3]);
00186         diff[3].sign = !diff[1].sign;
00187     } else if (knives->nblades == 3) {
00188         tumblersub(&knives->blades[2], &knives->blades[1], &diff[1]);
00189         tumblersub(&knives->blades[1], &knives->blades[0], &diff[2]);   /* should be negative */
00190         diff[2].sign = !diff[2].sign;
00191         tumblerclear(&(diff[3]));
00192     } else
00193         assert(0); // Wrong number of cuts
00194 }
00195 
00203 /* Returns which between-cut slice the crum is in. Does this ** by finding the first cut to the right of the crum **
00204  * Each editting routine requires a slightly different version of ** this function. */
00205     static int
00206 rearrangecutsectionnd(
00207     typecorecrum *ptr,
00208     typewid      *offset,
00209     typeknives   *knives)
00210 {
00211     int i, cmp;
00212 
00213     for (i = knives->nblades - 1; i >= 0; --i) {
00214         cmp = whereoncrum(ptr, offset, &knives->blades[i], knives->dimension);
00215         if (cmp == THRUME) {
00216             return -1;
00217         } else if (cmp <= ONMYLEFTBORDER) {
00218             return i + 1;
00219         }
00220     }
00221     return 0;
00222 }
00223 
00231     static void
00232 sortknives(
00233     typeknives *knifeptr)
00234 {
00235     Tumbler temp;
00236     int i;
00237 
00238     for (i = 0; i < knifeptr->nblades - 1; ++i) {
00239         if (tumblercmp(&knifeptr->blades[i], &knifeptr->blades[i + 1]) == GREATER) {
00240             movetumbler(&knifeptr->blades[i + 1], &temp);
00241             movetumbler(&knifeptr->blades[i], &knifeptr->blades[i + 1]);
00242             movetumbler(&temp, &knifeptr->blades[i]);
00243             --i;
00244         }
00245     }
00246 }
00247 
00255     void
00256 rearrangend(
00257     typecuc    *fullcrumptr,
00258     typecutseq *cutseqptr,
00259     int         index)
00260 {
00261     typecuc *father, *ptr;
00262     typewid foffset, fgrasp;
00263     typeknives knives;
00264     Tumbler diff[4];
00265     int i;
00266 
00267 #ifdef UNdeFined
00268     L("entering rearrangend\n");
00269       fixincoresubtreewids(fullcrumptr);    /* 1999 // a temp kluge zzz till we find where setwisp * isnt called// 
00270  *//* this is a brute  force kluge, if this fixes anything it means that the wids aren't being set properly somplace else probably near here */
00271     L("in rearrangend \n");
00272     switch (fullcrumptr->cenftype) {
00273     case POOM:
00274         L("in rearrangend  dumppoomwisps\n");
00275         dumppoomwisps(fullcrumptr);
00276         break;
00277     case SPAN:
00278         L("in rearrangend  showspanf\n");
00279         showspanf(fullcrumptr);
00280         break;
00281     }
00282 #endif
00283 /* displaycutspm(cutseqptr); */
00284     knives.dimension = index;
00285     knives.nblades = cutseqptr->numberofcuts;
00286     for (i = 0; i < knives.nblades; i++) {
00287         movetumbler(&cutseqptr->cutsarray[i], &knives.blades[i]);
00288     }
00289     sortknives(&knives);
00290     makeoffsetsfor3or4cuts(&knives, diff);
00291 /* for(i=1;i<=knives.nblades;i++){L("\noffset for cut %d = ",i);dumptumbler(&diff[i]);} */
00292     makecutsnd(fullcrumptr, &knives);
00293     newfindintersectionnd(fullcrumptr, &knives, &father, &foffset);
00294     prologuend((typecorecrum *) father, &foffset, &fgrasp, (typedsp *) NULL);
00295     for (ptr = (typecuc *) findleftson(father); ptr; ptr = (typecuc *) findrightbro((typecorecrum *) ptr)) {
00296         i = rearrangecutsectionnd((typecorecrum *) ptr, &fgrasp, &knives);
00297         switch (i) {
00298         case -1:
00299             assert(0); // rearrangend can't classify crum
00300         case 0:
00301         case 4:                       /* these never move */
00302             break;
00303         case 1:
00304         case 2:
00305         case 3:                       /* 3 only moves in 4 cuts */
00306             tumbleradd(&ptr->cdsp.dsas[index], &diff[i], &ptr->cdsp.dsas[index]);
00307 /* L("\nptr = %x i = %d ",ptr,i); dump(ptr); */
00308             ivemodified((typecorecrum *) ptr);
00309             break;
00310         default:
00311             assert(0); // unexpected cutsection
00312         }
00313     }
00314     setwispupwards(father, 1);         /* should do nothing, */
00315 /* but, just on general principles.. */
00316     recombine(fullcrumptr);
00317 
00318     (void)splitcrumupwards(fullcrumptr);        /* can we move this before recombine ? */
00319 #ifdef UnDEfINed
00320     L("leaving rearrangend\n");
00321 
00322       fixincoresubtreewids(fullcrumptr);    /* 1999 // a temp kluge zzz till we find where setwisp * isnt called// 
00323  *//* this is a brute  force kluge, if this fixes anything it means that the wids aren't being set properly somplace else probably near here */
00324     L("in rearrangend \n");
00325     switch (fullcrumptr->cenftype) {
00326     case POOM:
00327         L("in rearrangend  dumppoomwisps\n");
00328         dumppoomwisps(fullcrumptr);
00329         break;
00330     case SPAN:
00331         L("in rearrangend  showspanf\n");
00332         showspanf(fullcrumptr);
00333         break;
00334     }
00335 #endif
00336 
00337 }
00338 
00346     int
00347 insertcutsectionnd(
00348     typecorecrum *ptr,
00349     typewid      *offset,
00350     typeknives   *knives)
00351 {
00352     int i, cmp; /* hacked from delete */
00353 
00354 /* for (i = knives->nblades-1; i >= 0; --i){ */
00355     if (knives->nblades == 2) {
00356         i = 1;
00357         cmp = whereoncrum(ptr, offset, &knives->blades[i], knives->dimension);
00358         if ( /* false&& */ cmp == THRUME) {
00359             dumpwid((typewid *) &ptr->cwid.dsas[i], ptr->cenftype);
00360             return -1;
00361         } else if (cmp <= ONMYLEFTBORDER) {     /* compare last to first */
00362             return 2;
00363         }
00364     }
00365 
00366     i = 0;
00367 
00368     cmp = whereoncrum(ptr, offset, &knives->blades[i], knives->dimension);
00369     if (cmp == THRUME) {
00370         dumpwid((typewid *) &ptr->cwid.dsas[i], ptr->cenftype);
00371         return -1;
00372     } else if (cmp <= ONMYLEFTBORDER) { /* compare last to first */
00373         return 1;
00374     }
00375 
00376 /* } */
00377     return 0;
00378 }

Generated on Sun Aug 21 04:18:14 2005 for Udanax-Green by doxygen1.3.4