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 #include <memory.h>
00077 #include "udanax.h"
00078
00079
00080 static void hgetwiddsp(typecuc * ptr, char **loafptrptr);
00081 static void varunpackloaf(int insidediskblocknumber, typediskloaf *uloafptr, typecuc *father);
00082
00090
00091 void
00092 initkluge(
00093 typecuc **granfptr,
00094 typecuc **spanfptr)
00095 {
00096 typecbc *tempcbc;
00097
00098
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 ;
00103 inorgl(tempcbc);
00104
00105 tempcbc->cinfo.granstuff.orglstuff.orglptr->leftbroorfather = NULL;
00106 *granfptr = tempcbc->cinfo.granstuff.orglstuff.orglptr;
00107 (*granfptr)->numberofsons = 0;
00108
00109
00110 tempcbc->cinfo.granstuff.orglstuff.diskorglptr.diskblocknumber = SPANFDISKLOCATION;
00111 tempcbc->cinfo.granstuff.orglstuff.diskorglptr.insidediskblocknumber = 0 ;
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
00153
00161 static void
00162 hgetinfo(
00163 typecbc *ptr,
00164 char **loafptrptr)
00165 {
00166 unsigned int temp;
00167
00168 if (!is2dcrum((typecorecrum *) ptr)) {
00169 hgetfromloaf(&ptr->cinfo.infotype, *loafptrptr);
00170
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
00181
00182
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
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);
00227
00228 xloafptr = lookinsideloaffor(insidediskblocknumber, uloafptr);
00229 loafp = (char *)xloafptr;
00230
00231 hgetfromloaf(&size, loafp);
00232 hgetfromloaf(&isapex, loafp);
00233
00234 if (isapex ) {
00235 #ifndef DISTRIBUTION
00236 dumphexstuff((char *) uloafptr);
00237 dumphexstuff((char *) xloafptr);
00238 assert(0);
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);
00252 #else
00253 assert(0);
00254 #endif
00255 }
00256 #ifdef glurg
00257 father->modified = false;
00258 #endif
00259 hgetfromloaf(&enftype, loafp);
00260
00261 if (enftype != father->cenftype)
00262 assert(0);
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);
00282 #else
00283 assert(0);
00284 #endif
00285 }
00286 if (ptr->sonorigin.diskblocknumber == DISKPTRNULL) {
00287 #ifndef DISTRIBUTION
00288 dump((typecorecrum *) ptr);
00289 assert(0);
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);
00316
00317 if (father->leftson)
00318 assert(0);
00319
00320 typediskloaf loaf;
00321 readloaf(&loaf, father->sonorigin);
00322 unpackloaf(father->sonorigin.insidediskblocknumber, &loaf, father);
00323
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);
00348 hgetfromloaf((int *) &temp, loafp);
00349 hgetfromloaf((int *) &temp2, loafp);
00350
00351 typecuc *ptr;
00352 if ( crumptr) {
00353 ptr = (typecuc *) crumptr;
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
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);
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);
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
00400
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 }