libsrc/insert.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: insert.cxx,v $
00032  * Revision 1.9  2004/09/04 16:02:17  jrush
00033  * Added Doxygen headers before each and every function definition.
00034  *
00035  * Revision 1.8  2002/05/28 04:22:29  jrush
00036  * Adjusted source files to comply with GPL licensing.
00037  *
00038  * Revision 1.7  2002/05/28 02:51:11  jrush
00039  * Made static any functions and global variables private to this source file
00040  * and commented out any unused functions.
00041  *
00042  * Revision 1.6  2002/04/12 11:56:43  jrush
00043  * Reorganized include file layout, renamed xanadu.h to udanax.h and
00044  * typecontext/typecrumcontext to C++ class Context/CrumContext.
00045  *
00046  * Revision 1.5  2002/04/09 21:45:46  jrush
00047  * Renamed class 'tumbler' to 'Tumbler', for consistency with Python sources,
00048  * and changed typeisa from typedef to a subclass, in preparation for cleaning
00049  * up the type/class tree.
00050  *
00051  * Revision 1.4  2002/04/06 19:51:30  jrush
00052  * Renamed TRUE/FALSE constant use to the C++ standard of true/false.
00053  *
00054  * Revision 1.3  2002/04/06 15:01:17  jrush
00055  * Changed INT to just 'int'.
00056  *
00057  * Revision 1.2  2002/02/14 09:27:43  jrush
00058  * Cleaned up source:
00059  *
00060  * 1. ran thru the indent tool to achieve a standard look,
00061  * 2. added structured comments at top for use with DOxygen reporting
00062  *    as well as CVS keywords,
00063  * 3. fixed compiler warnings re ambiguous assign/compares,
00064  *    needed casts and unused/uninitialized variables,
00065  * 4. fixed funcs that didn't specify a return type,
00066  * 5. centralized prototypes in protos.h, removing incomplete ones,
00067  * 6. cleaned up use of bool/BOOLEAN type to suit C++ type,
00068  * 7. fixed initializer nesting in tumbler constants,
00069  * 8. renamed vars that conflict with C++ keywords (new, this),
00070  * 9. fixed global/extern confusion re some global vars.
00071  *
00072  */
00073 
00074 #include <memory.h>
00075 #include "udanax.h"
00076 
00077 /* use with GRAN */
00078 
00086     static bool
00087 fillupcbcseq(
00088     typecbc                *ptr,
00089     Tumbler                *crumboundary,
00090     typegranbottomcruminfo *info)
00091 {
00092     char temp[GRANTEXTLENGTH];
00093 
00095 /* do it nicer than this * */
00096 
00097     int crumlength    = ptr->cinfo.granstuff.textstuff.textlength;
00098     int remainingroom = GRANTEXTLENGTH - crumlength;
00099     int textlength    = info->granstuff.textstuff.textlength;
00100 
00101     if (remainingroom > textlength) {
00102         movmem(&info->granstuff.textstuff.textstring, (char *)(&(ptr->cinfo.granstuff.textstuff)) + crumlength, textlength);
00103         ptr->cinfo.granstuff.textstuff.textlength = crumlength + textlength;
00104         tumblerincrement(crumboundary, 0, textlength, crumboundary);
00105         return false;
00106 
00107     } else {
00108         movmem(&info->granstuff.textstuff.textstring, (char *)(&(ptr->cinfo.granstuff.textstuff)) + crumlength,
00109                remainingroom);
00110         ptr->cinfo.granstuff.textstuff.textlength = GRANTEXTLENGTH;
00111         tumblerincrement(crumboundary, 0, remainingroom, crumboundary);
00112     }
00113 
00114 /* then take whats left in info and renormalize it */
00115     info->granstuff.textstuff.textlength -= remainingroom;
00116 
00117     movmem(&info->granstuff.textstuff.textstring[remainingroom], temp, info->granstuff.textstuff.textlength);
00118     clear(info->granstuff.textstuff.textstring, GRANTEXTLENGTH);
00119     movmem(temp, info->granstuff.textstuff.textstring, info->granstuff.textstuff.textlength);
00120 
00121     return true;
00122 }
00123 
00131     void
00132 insertseq(
00133     typecuc                *fullcrumptr,
00134     Tumbler                *address,
00135     typegranbottomcruminfo *info)
00136 {
00137     typedsp reach;
00138 
00139     Tumbler nextaddress;
00140     movetumbler(address, &nextaddress);
00141 
00142     CrumContext *context = retrievecrums(fullcrumptr, address, WIDTH);
00143     typecbc *ptr = context->corecrum;
00144 
00145     typedsp offset;
00146     clear(&offset, sizeof(offset));
00147     movewisp(&context->totaloffset, &offset);
00148 
00149     crumcontextfree(context);
00150 
00151     if (/* crum can be extended */ info->infotype == GRANTEXT && ptr->cinfo.infotype == GRANTEXT && ptr->cinfo.granstuff.textstuff.textlength < GRANTEXTLENGTH) {
00152         if (!fillupcbcseq(ptr, &nextaddress, info)) {
00153             ivemodified((typecorecrum *) ptr);
00154             return;
00155         }
00156     }
00157     reserve((typecorecrum *) ptr);
00158 
00159     typecorecrum *newcc = createcrum(0, (int) ptr->cenftype);
00160     reserve(newcc);
00161 
00162     adopt(newcc, RIGHTBRO, (typecorecrum *) ptr);
00163     ivemodified(newcc);
00164 
00165     bool splitsomething = splitcrumupwards(findfather(newcc));
00166 
00167     if (info->infotype == GRANORGL)
00168         info->granstuff.orglstuff.orglptr->leftbroorfather = newcc;
00169 
00170     moveinfo((typebottomcruminfo *) info, (typebottomcruminfo *) &((typecbc *) newcc)->cinfo);  /* in GRAN */
00171     if (iszerotumbler(&ptr->cwid.dsas[WIDTH])) {        /* last crum in granf */
00172         tumblerclear(&newcc->cwid.dsas[WIDTH]);
00173         tumblersub(&nextaddress, &offset.dsas[WIDTH], &ptr->cwid.dsas[WIDTH]);
00174     } else {
00175         dspadd(&offset, &ptr->cwid, &reach, GRAN);
00176         tumblersub(&reach.dsas[WIDTH], &nextaddress, &newcc->cwid.dsas[WIDTH]);
00177         tumblersub(&nextaddress, &offset.dsas[WIDTH], &ptr->cwid.dsas[WIDTH]);
00178     }
00179 
00180     ivemodified((typecorecrum *) ptr);
00181     setwispupwards(findfather((typecorecrum *) ptr), 0);
00182     setwispupwards(findfather((typecorecrum *) newcc), 1);
00183     splitsomething |= splitcrumupwards(findfather((typecorecrum *) ptr));
00184     rejuvinate((typecorecrum *) ptr);
00185     rejuvinate(newcc);
00186 
00187     if (splitsomething)
00188         recombine(fullcrumptr);
00189 }

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