libsrc/corediskin.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: corediskin.cxx,v $
00032  * Revision 1.10  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.9  2004/09/04 16:02:17  jrush
00037  * Added Doxygen headers before each and every function definition.
00038  *
00039  * Revision 1.8  2002/07/26 04:30:29  jrush
00040  * Replaced gerror() with assert()
00041  *
00042  * Revision 1.7  2002/05/28 04:22:29  jrush
00043  * Adjusted source files to comply with GPL licensing.
00044  *
00045  * Revision 1.6  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.5  2002/04/12 11:56:42  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.4  2002/04/06 19:51:30  jrush
00054  * Renamed TRUE/FALSE constant use to the C++ standard of true/false.
00055  *
00056  * Revision 1.3  2002/04/06 15:01:17  jrush
00057  * Changed INT to just 'int'.
00058  *
00059  * Revision 1.2  2002/02/14 09:27:43  jrush
00060  * Cleaned up source:
00061  *
00062  * 1. ran thru the indent tool to achieve a standard look,
00063  * 2. added structured comments at top for use with DOxygen reporting
00064  *    as well as CVS keywords,
00065  * 3. fixed compiler warnings re ambiguous assign/compares,
00066  *    needed casts and unused/uninitialized variables,
00067  * 4. fixed funcs that didn't specify a return type,
00068  * 5. centralized prototypes in protos.h, removing incomplete ones,
00069  * 6. cleaned up use of bool/BOOLEAN type to suit C++ type,
00070  * 7. fixed initializer nesting in tumbler constants,
00071  * 8. renamed vars that conflict with C++ keywords (new, this),
00072  * 9. fixed global/extern confusion re some global vars.
00073  *
00074  */
00075 
00076 #include <memory.h>
00077 #include "udanax.h"
00078 
00079 //extern bool isxumain;
00080 static void hgetwiddsp(typecuc * ptr, char **loafptrptr);
00081 static void varunpackloaf(int insidediskblocknumber, typediskloaf *uloafptr, typecuc *father);
00082 
00090 /* Initialize thing from old enf.enf */
00091     void
00092 initkluge(
00093     typecuc **granfptr,
00094     typecuc **spanfptr)
00095 {
00096     typecbc *tempcbc;
00097 
00098 /* kluge up a bottum crum, use it to read in granf, similarly for spanf */
00099     tempcbc = (typecbc *) createcrum(0, GRAN);
00100     tempcbc->cinfo.infotype = GRANORGL;
00101     tempcbc->cinfo.granstuff.orglstuff.diskorglptr.diskblocknumber = GRANFDISKLOCATION;
00102     tempcbc->cinfo.granstuff.orglstuff.diskorglptr.insidediskblocknumber = 0 /* 1 */ ;
00103     inorgl(tempcbc);
00104 
00105     tempcbc->cinfo.granstuff.orglstuff.orglptr->leftbroorfather = NULL;
00106     *granfptr = tempcbc->cinfo.granstuff.orglstuff.orglptr;
00107     (*granfptr)->numberofsons = 0;     /* hack to make number of sons in granf be correct */
00108 
00109 /* this is a hack to read in the spanf like an orgl! */
00110     tempcbc->cinfo.granstuff.orglstuff.diskorglptr.diskblocknumber = SPANFDISKLOCATION;
00111     tempcbc->cinfo.granstuff.orglstuff.diskorglptr.insidediskblocknumber = 0 /* 1 */ ;
00112     inorgl(tempcbc);
00113 
00114     tempcbc->cinfo.granstuff.orglstuff.orglptr->leftbroorfather = NULL;
00115     *spanfptr = tempcbc->cinfo.granstuff.orglstuff.orglptr;
00116     (*spanfptr)->numberofsons = 0;
00117 
00118     freecrum((typecorecrum *) tempcbc);
00119 }
00120 
00128     static typediskloaf *
00129 lookinsideloaffor(
00130     int           insidenumber,
00131     typediskloaf *uloafptr)
00132 {
00133     return uloafptr;
00134 }
00135 
00143     static void
00144 unpackloaf(
00145     int           insidediskblocknumber,
00146     typediskloaf *uloafptr,
00147     typecuc      *father)
00148 {
00149     varunpackloaf(insidediskblocknumber, uloafptr, father);
00150 }
00151 
00152 /* #define hgetfromloaf(ip,lp) (*(ip)=intof(lp),L("hgetfromloaf gets %d\n",*(ip)),(lp)=((char*)lp)+lengthof(lp)) */
00153 
00161     static void
00162 hgetinfo(
00163     typecbc  *ptr,
00164     char    **loafptrptr)
00165 {                                      /* this assumes ptr crum is ok except * for info */
00166     unsigned int temp;
00167 
00168     if (!is2dcrum((typecorecrum *) ptr)) {
00169         hgetfromloaf(&ptr->cinfo.infotype, *loafptrptr);
00170 /* dump(ptr); */
00171         if (ptr->cinfo.infotype == GRANTEXT) {
00172             ptr->cinfo.granstuff.textstuff.textlength = intof((humber) * loafptrptr);
00173             (*loafptrptr) += lengthof((humber) * loafptrptr);
00174             movmem((*loafptrptr), ptr->cinfo.granstuff.textstuff.textstring, ptr->cinfo.granstuff.textstuff.textlength);
00175             (*loafptrptr) += ptr->cinfo.granstuff.textstuff.textlength;
00176             return;
00177         } else if (ptr->cinfo.infotype == GRANORGL) {
00178             ptr->cinfo.granstuff.orglstuff.diskorglptr.diskblocknumber = intof((humber) * loafptrptr);
00179 
00180             /* if (temp == 0 || temp == -1) {
00181              *     L("bad diskblocknumber = %d \n", temp);
00182              *     assert(0); // boo in hgetinfo
00183              * }
00184              */
00185 
00186             (*loafptrptr) += lengthof((humber) * loafptrptr);
00187             ptr->cinfo.granstuff.orglstuff.diskorglptr.insidediskblocknumber = intof((humber) * loafptrptr);
00188             (*loafptrptr) += lengthof((humber) * loafptrptr);
00189             return;
00190         } else {
00191             return;
00192         }
00193     } else {
00194         if (ptr->height) {
00195 /* looks like we got this all */
00196         } else {
00197 
00198             temp = tumblerptrtofixed((humber) * loafptrptr, &((type2dcbc *) ptr)->c2dinfo.homedoc);
00199             (*loafptrptr) += temp;
00200         }
00201     }
00202 }
00203 
00211     static void
00212 varunpackloaf(
00213     int           insidediskblocknumber,
00214     typediskloaf *uloafptr,
00215     typecuc      *father)
00216 {
00217     typediskloaf *xloafptr;
00218     typecuc *ptr;
00219     char *loafp;
00220     int numberofsonstoread;
00221     int height, enftype;
00222     int isapex, refcount;
00223     int size;
00224 
00225     if (!uloafptr || !father || father->height <= 0)
00226         assert(0); // bad varunpackloaf call
00227 
00228     xloafptr = lookinsideloaffor(insidediskblocknumber, uloafptr);
00229     loafp = (char *)xloafptr;
00230 /* loafp += 3; */
00231     hgetfromloaf(&size, loafp);
00232     hgetfromloaf(&isapex, loafp);
00233 /* L("isapex = %d\n",isapex); */
00234     if (isapex /*ISAPEX*/) {
00235 #ifndef DISTRIBUTION
00236         dumphexstuff((char *) uloafptr);
00237         dumphexstuff((char *) xloafptr);
00238         assert(0); // attempt to read apex in varumpackloaf
00239 #else
00240         assert(0);
00241 #endif
00242     }
00243     hgetfromloaf(&height, loafp);
00244 
00245     if (height != father->height - 1) {
00246 #ifndef DISTRIBUTION
00247         dump((typecorecrum *) father);
00248         dumphexstuff((char *) uloafptr);
00249         L("next thing = %d\n", intof((humber) loafp));
00250         L("father height = %d %d\n", father->height, height);
00251         assert(0); // height mismatch in varunpackloaf
00252 #else
00253         assert(0);
00254 #endif
00255     }
00256 #ifdef glurg
00257     father->modified = false;
00258 #endif                                 /* glurg */
00259     hgetfromloaf(&enftype, loafp);
00260 
00261     if (enftype != father->cenftype)
00262         assert(0); // enftype mismatch in varunpackloaf
00263 
00264     hgetfromloaf(&numberofsonstoread, loafp);
00265     hgetfromloaf(&refcount, loafp);
00266     father->numberofsons = 0;
00267     while (numberofsonstoread--) {
00268         ptr = (typecuc *) createcrum(height, enftype);
00269         adopt((typecorecrum *) ptr, RIGHTMOSTSON, (typecorecrum *) father);
00270         hgetwiddsp(ptr, &loafp);
00271         if (height != 0) {
00272             ptr->isapex = isapex;
00273             hgetfromloaf(&ptr->sonorigin.diskblocknumber, loafp);
00274             hgetfromloaf(&ptr->sonorigin.insidediskblocknumber, loafp);
00275 
00276             if (ptr->sonorigin.diskblocknumber == 0) {
00277 #ifndef DISTRIBUTION
00278                 dumphexstuff(loafp);
00279                 dump((typecorecrum *) ptr);
00280                 dumphexstuff((char *) uloafptr);
00281                 assert(0); // trying to read 0 block
00282 #else
00283                 assert(0);
00284 #endif
00285             }
00286             if (ptr->sonorigin.diskblocknumber == DISKPTRNULL) {
00287 #ifndef DISTRIBUTION
00288                 dump((typecorecrum *) ptr);
00289                 assert(0); // trying to read DISKPTRNULL block
00290 #else
00291                 assert(0);
00292 #endif
00293             }
00294 
00295         } else {
00296             ptr->isapex = false;
00297             hgetinfo((typecbc *) ptr, &loafp);
00298         }
00299         ptr->modified = false;
00300     }
00301 }
00302 
00310     void
00311 inloaf(
00312     typecuc *father)
00313 {
00314     if (father->height == 0)
00315         assert(0); // inloaf on bottom crum
00316 
00317     if (father->leftson)
00318         assert(0); // Its already got sons, and we aren't going to use pseudo-crums!
00319 
00320     typediskloaf loaf;
00321     readloaf(&loaf, father->sonorigin);
00322     unpackloaf(father->sonorigin.insidediskblocknumber, &loaf, father);
00323 /* nchecknumofsons(father); */
00324 }
00325 
00333     void
00334 inorglinternal(
00335     typecbc             *granorglptr,
00336     typeuberrawdiskloaf *crumptr)
00337 {
00338     unsigned int temp, temp2;
00339 
00340     typediskloaf loaf;
00341     readloaf(&loaf, granorglptr->cinfo.granstuff.orglstuff.diskorglptr);
00342 
00343     char *loafp = (char *)&loaf;
00344 
00345     int size;
00346     hgetfromloaf(&size, loafp);
00347     hgetfromloaf((int *) &temp, loafp);        /* isapex */
00348     hgetfromloaf((int *) &temp, loafp);
00349     hgetfromloaf((int *) &temp2, loafp);
00350 
00351     typecuc *ptr;
00352     if ( /* false&& */ crumptr) {
00353         ptr = (typecuc *) crumptr;     /* ECH I DON'T LIKE THIS!!! */
00354     } else {
00355         ptr = (typecuc *) createcrum((int) temp, (int) temp2);
00356     }
00357 
00358     ptr->cenftype   = temp2;
00359     ptr->isapex     = true;
00360     ptr->isleftmost = true;
00361     hgetfromloaf((int *) &temp, loafp);
00362 
00363     ptr->numberofsons = temp;
00364     hgetfromloaf((int *) &temp, loafp);
00365 /* ptr->refcount = temp; */
00366 
00367     hgetwiddsp(ptr, &loafp);
00368     hgetfromloaf((int *) &temp, loafp);
00369     ptr->sonorigin.diskblocknumber = temp;
00370 
00371     if (ptr->sonorigin.diskblocknumber == 0) {
00372 #ifndef DISTRIBUTION
00373         dump((typecorecrum *) ptr);
00374         assert(0); // trying to write 0 block
00375 #else
00376         assert(0);
00377 #endif
00378     }
00379 
00380     if (ptr->sonorigin.diskblocknumber == DISKPTRNULL) {
00381 #ifndef DISTRIBUTION
00382         dump((typecorecrum *) ptr);
00383         assert(0); // trying to write DSKPTRNULL block
00384 #else
00385         assert(0);
00386 #endif
00387     }
00388 
00389     hgetfromloaf((int *) &temp, loafp);
00390 
00391     ptr->sonorigin.insidediskblocknumber = temp;
00392     ptr->modified                        = false;
00393     ptr->leftbroorfather                 = (typecorecrum *) granorglptr;
00394 
00395     granorglptr->cinfo.granstuff.orglstuff.orglptr    = (typecuc *) ptr;
00396     granorglptr->cinfo.granstuff.orglstuff.orglincore = true;
00397     rejuvinate((typecorecrum *) ptr);
00398 
00399 /* checknumofsons(ptr); */
00400 /* dump(ptr); */
00401 }
00402 
00410     void
00411 inorgl(
00412     typecbc *granorglptr)
00413 {
00414     inorglinternal(granorglptr, (typeuberrawdiskloaf *) NULL);
00415 }
00416 
00424     static void
00425 hgetwiddsp(
00426     typecuc  *ptr,
00427     char    **loafptrptr)
00428 {
00429     unsigned int temp;
00430 
00431     int nstreams = widsize(ptr->cenftype);
00432     typewid *wptr = &ptr->cdsp;
00433 
00434     int i;
00435     for (i = 0; i < nstreams; ++i) {
00436         temp = tumblerptrtofixed((humber) * loafptrptr, &wptr->dsas[i]);
00437         *loafptrptr += temp;
00438     }
00439 
00440     wptr = &ptr->cwid;
00441     for (i = 0; i < nstreams; ++i) {
00442         temp = tumblerptrtofixed((humber) * loafptrptr, &wptr->dsas[i]);
00443         *loafptrptr += temp;
00444     }
00445 }

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