| 1 | /* ----------------------------- myzcru.c ----------------------------- */ |
|---|
| 2 | |
|---|
| 3 | #include <stdio.h> |
|---|
| 4 | #include <ctype.h> |
|---|
| 5 | #include <string.h> |
|---|
| 6 | |
|---|
| 7 | #include "cisis.h" |
|---|
| 8 | #include "cirun.h" |
|---|
| 9 | |
|---|
| 10 | /* ----------------------------- tlc.h -------------------------------- */ |
|---|
| 11 | |
|---|
| 12 | typedef union { |
|---|
| 13 | L0STRU l0x; |
|---|
| 14 | L1STRU l1x; |
|---|
| 15 | L2STRU l2x; |
|---|
| 16 | } LUSTRU; |
|---|
| 17 | |
|---|
| 18 | LUSTRU tlcleaf; |
|---|
| 19 | LZSTRU lzxleaf; |
|---|
| 20 | |
|---|
| 21 | #define MAXNAPU 256 |
|---|
| 22 | int napus,apun,apuk; |
|---|
| 23 | LONGX *vapup[MAXNAPU]; |
|---|
| 24 | LONGX *apup; |
|---|
| 25 | LONGX divapu; |
|---|
| 26 | |
|---|
| 27 | int parmtrace=0; |
|---|
| 28 | |
|---|
| 29 | #if ANSI |
|---|
| 30 | LONGX leafadda(int treecase,PUNT punt,LONGX addr); |
|---|
| 31 | LONGX leafaddr(int treecase,PUNT pos,int ock,PUNT punt); |
|---|
| 32 | #else |
|---|
| 33 | LONGX leafadda(); |
|---|
| 34 | LONGX leafaddr(); |
|---|
| 35 | #endif |
|---|
| 36 | |
|---|
| 37 | /* ----------------------------- mov.h -------------------------------- */ |
|---|
| 38 | #if INTELCPU /* PC */ /* AOT, 02/04/2002 */ |
|---|
| 39 | #define SWAB 0 |
|---|
| 40 | #define MOV21 0 |
|---|
| 41 | #define MOV20 1 |
|---|
| 42 | #define MOV43 0 |
|---|
| 43 | #define MOV42 1 |
|---|
| 44 | #define MOV41 2 |
|---|
| 45 | #define MOV40 3 |
|---|
| 46 | #else |
|---|
| 47 | #define SWAB 1 |
|---|
| 48 | #define MOV21 1 |
|---|
| 49 | #define MOV20 0 |
|---|
| 50 | #define MOV43 3 |
|---|
| 51 | #define MOV42 2 |
|---|
| 52 | #define MOV41 1 |
|---|
| 53 | #define MOV40 0 |
|---|
| 54 | #endif |
|---|
| 55 | |
|---|
| 56 | char *movp,*movtmp; |
|---|
| 57 | UWORD moved; |
|---|
| 58 | char *mov_record=NULL; |
|---|
| 59 | char *movps_p; |
|---|
| 60 | char *movpsb_p; |
|---|
| 61 | |
|---|
| 62 | #if SWAB |
|---|
| 63 | #define mov2(source) \ |
|---|
| 64 | movtmp = (char *)&(source); \ |
|---|
| 65 | swab(movtmp,movp,2); movp+=2; \ |
|---|
| 66 | moved+=2; |
|---|
| 67 | #else |
|---|
| 68 | #define mov2(source) \ |
|---|
| 69 | movtmp = (char *)&(source); \ |
|---|
| 70 | *movp++ = movtmp[MOV21]; \ |
|---|
| 71 | *movp++ = movtmp[MOV20]; \ |
|---|
| 72 | moved+=2; |
|---|
| 73 | #endif |
|---|
| 74 | |
|---|
| 75 | #define mov4(source) \ |
|---|
| 76 | movtmp = (char *)&(source); \ |
|---|
| 77 | *movp++ = movtmp[MOV43]; \ |
|---|
| 78 | *movp++ = movtmp[MOV42]; \ |
|---|
| 79 | *movp++ = movtmp[MOV41]; \ |
|---|
| 80 | *movp++ = movtmp[MOV40]; \ |
|---|
| 81 | moved+=4; |
|---|
| 82 | |
|---|
| 83 | #define movx(sourcep,len) \ |
|---|
| 84 | memcpy(movp,sourcep,(size_t)len); \ |
|---|
| 85 | movp+=len; \ |
|---|
| 86 | moved+=len; |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | void main(argc,argv) |
|---|
| 90 | int argc; |
|---|
| 91 | char *argv[]; |
|---|
| 92 | { |
|---|
| 93 | extern int trmtrace; |
|---|
| 94 | char *dbnp,*zdbnp; |
|---|
| 95 | int treecase,lex; |
|---|
| 96 | INVMAP *invp; |
|---|
| 97 | |
|---|
| 98 | PUNT punt; |
|---|
| 99 | LONGX punt1,punt2; |
|---|
| 100 | INFO info1,info2; |
|---|
| 101 | #if LIND |
|---|
| 102 | INFO info3; |
|---|
| 103 | LONGX lastaddr,thisaddr; |
|---|
| 104 | #endif |
|---|
| 105 | |
|---|
| 106 | int lzsize,mzxrecl; |
|---|
| 107 | int filler=0; |
|---|
| 108 | LONGX nextaddr; |
|---|
| 109 | |
|---|
| 110 | LONGX tell,countell,rangtell; |
|---|
| 111 | LONGX parmtell=0L; |
|---|
| 112 | LONGX parmtelln=0L; |
|---|
| 113 | int show; |
|---|
| 114 | FILE *fpx; |
|---|
| 115 | |
|---|
| 116 | int origlsiz; |
|---|
| 117 | UWORD x2; |
|---|
| 118 | LONGX origsize,x4; |
|---|
| 119 | |
|---|
| 120 | char *p,*keyp,prevkey[LE2+1]; |
|---|
| 121 | int iarg,n,iock,loop; |
|---|
| 122 | int tree1=1,tree2=2; |
|---|
| 123 | int eq,keylen,ne; |
|---|
| 124 | unsigned char *lzkp; |
|---|
| 125 | |
|---|
| 126 | N0STRU *n0p; |
|---|
| 127 | N1IDXE *n1xp; |
|---|
| 128 | N2IDXE *n2xp; |
|---|
| 129 | int nodesize; |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | if (argc < 3) { |
|---|
| 133 | printf("%s",cicopyr("Utility MYZCRU")); |
|---|
| 134 | printf("\n"); |
|---|
| 135 | printf("myzcru <dbn> <pczdbn> [options..] \n"); |
|---|
| 136 | printf("\n"); |
|---|
| 137 | printf("options: show[=<file>] \n"); |
|---|
| 138 | printf(" {tell|telln}=<times> \n"); |
|---|
| 139 | printf(" {tree1|tree2}=<tree> \n"); |
|---|
| 140 | printf(" \n"); |
|---|
| 141 | exit(1); |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | dbnp=argv[1]; |
|---|
| 145 | dbxopt_ordwr=O_RDONLY; |
|---|
| 146 | invsetup(dbnp,0L,0L,0L); |
|---|
| 147 | |
|---|
| 148 | dbxopt_ordwr=O_RDWR; |
|---|
| 149 | invp=dbxstorp(dbnp)->dbxifmap; |
|---|
| 150 | |
|---|
| 151 | zdbnp=argv[2]; |
|---|
| 152 | |
|---|
| 153 | fpx=stderr; show=0; |
|---|
| 154 | |
|---|
| 155 | for (iarg=3; iarg < argc; iarg++) { |
|---|
| 156 | p=argv[iarg]; |
|---|
| 157 | if (strcmp(p,"show") == 0 || strncmp(p,"show=",5) == 0) { |
|---|
| 158 | if (strncmp(p,"show=",5) == 0) { |
|---|
| 159 | if (!*(p+5)) fatal(p); |
|---|
| 160 | if ((fpx=fopen(p+5,"w")) == NULL) fatal(p+5); |
|---|
| 161 | } |
|---|
| 162 | else fpx=stdout; |
|---|
| 163 | show=1; |
|---|
| 164 | continue; |
|---|
| 165 | } |
|---|
| 166 | if (strcmp(p,"trace") == 0) { |
|---|
| 167 | dbxtrace=trmtrace=parmtrace=1; continue; |
|---|
| 168 | } |
|---|
| 169 | if (strncmp(p,"tell=",5) == 0) { |
|---|
| 170 | if (sscanf(p+5,"%ld",&parmtell) != 1) fatal(p); |
|---|
| 171 | if (parmtell < 0) fatal(p); |
|---|
| 172 | continue; |
|---|
| 173 | } |
|---|
| 174 | if (strncmp(p,"telln=",6) == 0) { |
|---|
| 175 | if (sscanf(p+6,"%ld",&parmtelln) != 1) fatal(p); |
|---|
| 176 | if (parmtelln < 0) fatal(p); |
|---|
| 177 | continue; |
|---|
| 178 | } |
|---|
| 179 | if (strncmp(p,"tree1=",6) == 0) { |
|---|
| 180 | if (sscanf(p+6,"%d",&tree1) != 1) fatal(p); |
|---|
| 181 | if (tree1 < 1 || tree1 > tree2) fatal(p); |
|---|
| 182 | continue; |
|---|
| 183 | } |
|---|
| 184 | if (strncmp(p,"tree2=",6) == 0) { |
|---|
| 185 | if (sscanf(p+6,"%d",&tree2) != 1) fatal(p); |
|---|
| 186 | if (tree2 < tree1 || tree2 > 2) fatal(p); |
|---|
| 187 | continue; |
|---|
| 188 | } |
|---|
| 189 | fatal(p); |
|---|
| 190 | } |
|---|
| 191 | |
|---|
| 192 | tree1--; tree2--; |
|---|
| 193 | |
|---|
| 194 | /* allocate crunching buffer */ |
|---|
| 195 | if (parmtrace) printf("+++ sizeof(LZSTRU)=%d\n",sizeof(LZSTRU)); |
|---|
| 196 | if (parmtrace) printf("+++ 1: coreleft=%ld\n",CORELEFT()); |
|---|
| 197 | mov_record=(char *)ALLOC((ALLOPARM)(sizeof(LZSTRU)+1)); |
|---|
| 198 | if (mov_record == (char *)ALLONULL) fatal("ALLOC/mov_record"); |
|---|
| 199 | if (parmtrace) printf("+++ mov_record: coreleft=%ld\n",CORELEFT()); |
|---|
| 200 | |
|---|
| 201 | /* init leaf addresses */ |
|---|
| 202 | napus=0; divapu=ALLOMAXV/sizeof(LONGX); |
|---|
| 203 | |
|---|
| 204 | /* |
|---|
| 205 | for each tree |
|---|
| 206 | */ |
|---|
| 207 | |
|---|
| 208 | for (treecase=tree1; treecase <= tree2; treecase++) { |
|---|
| 209 | |
|---|
| 210 | punt1=1; punt2=invp->cn[treecase].fmaxpos; |
|---|
| 211 | rangtell=punt2-punt1+1; |
|---|
| 212 | if (rangtell <= 0) rangtell=1; |
|---|
| 213 | if (parmtrace) printf("+++ fmaxpos=%ld \n",punt2); |
|---|
| 214 | if (parmtell) { |
|---|
| 215 | tell=rangtell/parmtell; |
|---|
| 216 | if (tell <= 0) tell=1; |
|---|
| 217 | } |
|---|
| 218 | |
|---|
| 219 | nextaddr=0; |
|---|
| 220 | origlsiz = (treecase) ? L2BSIZ : L1BSIZ; |
|---|
| 221 | origsize=0; |
|---|
| 222 | lex=vlex[treecase]; |
|---|
| 223 | countell=0; |
|---|
| 224 | |
|---|
| 225 | fpccreat("",zdbnp,lx12extp[treecase],0); |
|---|
| 226 | |
|---|
| 227 | /* |
|---|
| 228 | for each leaf |
|---|
| 229 | */ |
|---|
| 230 | for (punt=punt1; punt <= punt2; punt++) { |
|---|
| 231 | |
|---|
| 232 | leafadda(treecase,punt,nextaddr+1); /* punt < 0 */ |
|---|
| 233 | |
|---|
| 234 | /* read */ |
|---|
| 235 | if (leafread((char *)&tlcleaf,invp,treecase,punt,0) != &tlcleaf.l0x) |
|---|
| 236 | fatal("myzcru/bug1"); |
|---|
| 237 | |
|---|
| 238 | /* setup header */ |
|---|
| 239 | lzxleaf.pos = tlcleaf.l0x.pos; |
|---|
| 240 | lzxleaf.ock = tlcleaf.l0x.ock; |
|---|
| 241 | lzxleaf.it = tlcleaf.l0x.it; |
|---|
| 242 | lzxleaf.ps = tlcleaf.l0x.ps; |
|---|
| 243 | if (punt == punt2 && lzxleaf.ps != 0) { |
|---|
| 244 | fatal("lzxleaf.ps/last"); |
|---|
| 245 | } |
|---|
| 246 | if (punt != punt2 && lzxleaf.ps != punt+1) { |
|---|
| 247 | fatal("lzxleaf.ps/next"); |
|---|
| 248 | } |
|---|
| 249 | #if LIND |
|---|
| 250 | lzxleaf.psb = tlcleaf.l0x.psb; |
|---|
| 251 | if (lzxleaf.psb != punt-1) { |
|---|
| 252 | fatal("lzxleaf.psb"); |
|---|
| 253 | } |
|---|
| 254 | #endif |
|---|
| 255 | |
|---|
| 256 | lzsize = 0; /* LZHSIZE; */ |
|---|
| 257 | lzkp = (unsigned char *)lzxleaf.keys; |
|---|
| 258 | |
|---|
| 259 | /* |
|---|
| 260 | for each term |
|---|
| 261 | */ |
|---|
| 262 | for (iock=0; iock < tlcleaf.l0x.ock; iock++) { |
|---|
| 263 | |
|---|
| 264 | if (treecase) { |
|---|
| 265 | keyp = tlcleaf.l2x.idx[iock].key; |
|---|
| 266 | info1 = tlcleaf.l2x.idx[iock].info1; |
|---|
| 267 | info2 = tlcleaf.l2x.idx[iock].info2; |
|---|
| 268 | #if LIND |
|---|
| 269 | info3 = tlcleaf.l2x.idx[iock].info3info4.info3; |
|---|
| 270 | #endif |
|---|
| 271 | } |
|---|
| 272 | else { |
|---|
| 273 | keyp = tlcleaf.l1x.idx[iock].key; |
|---|
| 274 | info1 = tlcleaf.l1x.idx[iock].info1; |
|---|
| 275 | info2 = tlcleaf.l1x.idx[iock].info2; |
|---|
| 276 | #if LIND |
|---|
| 277 | info3 = tlcleaf.l1x.idx[iock].info3info4.info3; |
|---|
| 278 | #endif |
|---|
| 279 | } |
|---|
| 280 | |
|---|
| 281 | /* move existing info */ |
|---|
| 282 | lzxleaf.info1[iock] = info1; /* yaddr */ |
|---|
| 283 | lzxleaf.info2[iock] = info2; |
|---|
| 284 | #if LIND |
|---|
| 285 | lzxleaf.info3[iock] = info3; |
|---|
| 286 | #endif |
|---|
| 287 | |
|---|
| 288 | /* compress existing key */ |
|---|
| 289 | for (keylen=lex, p=keyp+keylen-1; keylen; ) { |
|---|
| 290 | if (*p != ' ') break; |
|---|
| 291 | p--; keylen--; |
|---|
| 292 | } |
|---|
| 293 | if (!keylen) { |
|---|
| 294 | fprintf(stderr,"*** punt=%ld/%d keylen=%d",punt,iock,keylen); |
|---|
| 295 | fatal("keylen"); |
|---|
| 296 | } |
|---|
| 297 | |
|---|
| 298 | if (iock == 0) eq=0; |
|---|
| 299 | else { |
|---|
| 300 | for (eq=0; eq < keylen; eq++) |
|---|
| 301 | if (keyp[eq] != prevkey[eq]) break; |
|---|
| 302 | } |
|---|
| 303 | memcpy(prevkey,keyp,lex); |
|---|
| 304 | |
|---|
| 305 | if (show) { |
|---|
| 306 | fprintf(fpx,"%3d|%3d|",eq,keylen); |
|---|
| 307 | for (p=keyp, n=keylen; n--; p++) fprintf(fpx,"%c",*p); |
|---|
| 308 | fprintf(fpx,"|"); |
|---|
| 309 | for (n=lex-keylen; n--; ) fprintf(fpx," "); |
|---|
| 310 | fprintf(fpx,"|\n"); |
|---|
| 311 | } |
|---|
| 312 | |
|---|
| 313 | *lzkp++ = (unsigned char)eq; |
|---|
| 314 | *lzkp++ = (unsigned char)keylen; |
|---|
| 315 | |
|---|
| 316 | memcpy(lzkp,keyp+eq,ne=keylen-eq); |
|---|
| 317 | lzkp+=ne; |
|---|
| 318 | |
|---|
| 319 | lzsize+=2; /* eq+keylen */ |
|---|
| 320 | lzsize+=ne; |
|---|
| 321 | |
|---|
| 322 | } /* end for each term */ |
|---|
| 323 | |
|---|
| 324 | for (iock=tlcleaf.l0x.ock; iock < TWORDF; iock++) { |
|---|
| 325 | lzxleaf.info1[iock] = 0; |
|---|
| 326 | lzxleaf.info2[iock] = 0; |
|---|
| 327 | #if LIND |
|---|
| 328 | lzxleaf.info3[iock] = 0; |
|---|
| 329 | #endif |
|---|
| 330 | } |
|---|
| 331 | |
|---|
| 332 | /* crunch .lx0 */ |
|---|
| 333 | movp=mov_record; moved=0; |
|---|
| 334 | x4=lzxleaf.pos; mov4(x4); |
|---|
| 335 | x2=lzxleaf.ock; mov2(x2); |
|---|
| 336 | x2=lzxleaf.it; mov2(x2); |
|---|
| 337 | movps_p=movp; x4=lzxleaf.ps; mov4(x4); |
|---|
| 338 | #if LIND |
|---|
| 339 | movpsb_p=movp; x4=lzxleaf.psb; mov4(x4); |
|---|
| 340 | #endif |
|---|
| 341 | for (iock=0; iock < TWORDF; iock++) { |
|---|
| 342 | info1=lzxleaf.info1[iock]; mov4(info1); |
|---|
| 343 | } |
|---|
| 344 | for (iock=0; iock < TWORDF; iock++) { |
|---|
| 345 | info2=lzxleaf.info2[iock]; mov4(info2); |
|---|
| 346 | } |
|---|
| 347 | #if LIND |
|---|
| 348 | for (iock=0; iock < TWORDF; iock++) { |
|---|
| 349 | info3=lzxleaf.info3[iock]; mov4(info3); |
|---|
| 350 | } |
|---|
| 351 | #endif |
|---|
| 352 | mzxrecl=moved+TWORDF*(2+lex); /* n */ |
|---|
| 353 | lzkp=(char *)lzxleaf.keys; movx(lzkp,lzsize); |
|---|
| 354 | |
|---|
| 355 | lzsize=moved; |
|---|
| 356 | |
|---|
| 357 | #if LIND |
|---|
| 358 | thisaddr=nextaddr; |
|---|
| 359 | if (punt == punt1) lastaddr=0; |
|---|
| 360 | #endif |
|---|
| 361 | nextaddr+=lzsize; |
|---|
| 362 | origsize+=/* moved; */ origlsiz; |
|---|
| 363 | |
|---|
| 364 | filler=0; |
|---|
| 365 | if (punt == punt2) { |
|---|
| 366 | filler = mzxrecl-lzsize; nextaddr+=filler; |
|---|
| 367 | if (filler >= sizeof(LZSTRU)) fatal("myzcru/bug2"); |
|---|
| 368 | } |
|---|
| 369 | |
|---|
| 370 | /* fixup ps/psb header */ |
|---|
| 371 | lzxleaf.ps = (punt == punt2) ? 0L : nextaddr+1; /* punt < 0 */ |
|---|
| 372 | movp=movps_p; x4=lzxleaf.ps; mov4(x4); moved-=4; |
|---|
| 373 | #if LIND |
|---|
| 374 | lzxleaf.psb = (punt == punt1) ? 0L : lastaddr+1; /* punt < 0 */ |
|---|
| 375 | movp=movpsb_p; x4=lzxleaf.psb; mov4(x4); moved-=4; |
|---|
| 376 | lastaddr=thisaddr; |
|---|
| 377 | #endif |
|---|
| 378 | |
|---|
| 379 | /* write */ |
|---|
| 380 | fpcwrite(mov_record,moved); |
|---|
| 381 | |
|---|
| 382 | ++countell; |
|---|
| 383 | if (parmtell) |
|---|
| 384 | if (countell % tell == 0 || filler) { |
|---|
| 385 | fprintf(fpx,"%s +%ldp=%3ld%% ",lx12extp[treecase],countell, |
|---|
| 386 | (10 * (countell*100/rangtell) + 5) / 10); |
|---|
| 387 | fprintf(fpx,"i=%3d/%ld ",origlsiz,origsize); |
|---|
| 388 | fprintf(fpx,"o=%3d/%ld ",lzsize,nextaddr); |
|---|
| 389 | fprintf(fpx,"save=%ld=%2d%% ",origsize-nextaddr, |
|---|
| 390 | (10 * ((origsize-nextaddr)*100/origsize) + 5) / 10); |
|---|
| 391 | if (filler) fprintf(fpx,"filler=%d",filler); |
|---|
| 392 | fprintf(fpx,"\n"); |
|---|
| 393 | } |
|---|
| 394 | |
|---|
| 395 | } /* end for punt */ |
|---|
| 396 | |
|---|
| 397 | if (filler) { |
|---|
| 398 | memset(mov_record,0x00,filler); |
|---|
| 399 | fpcwrite(mov_record,filler); |
|---|
| 400 | } |
|---|
| 401 | fpcclose(); |
|---|
| 402 | |
|---|
| 403 | /* |
|---|
| 404 | rewrite .n0x |
|---|
| 405 | (pointing to the absolute leaf address) |
|---|
| 406 | */ |
|---|
| 407 | |
|---|
| 408 | punt1=1; punt2=invp->cn[treecase].nmaxpos; |
|---|
| 409 | rangtell=punt2-punt1+1; |
|---|
| 410 | if (rangtell <= 0) rangtell=1; |
|---|
| 411 | countell=0; |
|---|
| 412 | |
|---|
| 413 | if (parmtrace) printf("+++ nmaxpos=%ld \n",punt2); |
|---|
| 414 | |
|---|
| 415 | if (parmtelln) { |
|---|
| 416 | tell=rangtell/parmtelln; |
|---|
| 417 | if (tell <= 0) tell=1; |
|---|
| 418 | } |
|---|
| 419 | |
|---|
| 420 | fpccreat("",zdbnp,nx12extp[treecase],0); |
|---|
| 421 | nodesize=(treecase)?N2BSIZ:N1BSIZ; |
|---|
| 422 | |
|---|
| 423 | /* for each node */ |
|---|
| 424 | |
|---|
| 425 | for (punt=punt1; punt <= punt2; punt++) { |
|---|
| 426 | |
|---|
| 427 | /* read */ |
|---|
| 428 | n0p=noderead(invp,treecase,0,punt); |
|---|
| 429 | |
|---|
| 430 | /* update leaf punt's */ |
|---|
| 431 | n=n0p->ock; |
|---|
| 432 | if (treecase) |
|---|
| 433 | for (n2xp=((N2STRU *)n0p)->idx; n--; n2xp++) { |
|---|
| 434 | if (n2xp->punt < 0) |
|---|
| 435 | n2xp->punt = -leafaddr(treecase,punt,TWORDN-n,-n2xp->punt); |
|---|
| 436 | } |
|---|
| 437 | else |
|---|
| 438 | for (n1xp=((N1STRU *)n0p)->idx; n--; n1xp++) { |
|---|
| 439 | if (n1xp->punt < 0) |
|---|
| 440 | n1xp->punt = -leafaddr(treecase,punt,TWORDN-n,-n1xp->punt); |
|---|
| 441 | } |
|---|
| 442 | |
|---|
| 443 | /* crunch .n0x */ |
|---|
| 444 | movp=mov_record; moved=0; |
|---|
| 445 | mov4(n0p->pos); |
|---|
| 446 | mov2(n0p->ock); |
|---|
| 447 | mov2(n0p->it); |
|---|
| 448 | loop=TWORDN; |
|---|
| 449 | if (treecase) |
|---|
| 450 | for (n2xp=((N2STRU *)n0p)->idx; loop--; n2xp++) { |
|---|
| 451 | movx(n2xp->key,LE2); |
|---|
| 452 | mov4(n2xp->punt); |
|---|
| 453 | } |
|---|
| 454 | else |
|---|
| 455 | for (n1xp=((N1STRU *)n0p)->idx; loop--; n1xp++) { |
|---|
| 456 | movx(n1xp->key,LE1); |
|---|
| 457 | mov4(n1xp->punt); |
|---|
| 458 | } |
|---|
| 459 | |
|---|
| 460 | /* write */ |
|---|
| 461 | fpcwrite(mov_record,moved); |
|---|
| 462 | |
|---|
| 463 | ++countell; |
|---|
| 464 | if (parmtelln) |
|---|
| 465 | if (countell % tell == 0) { |
|---|
| 466 | fprintf(fpx,"%s +%ldp=%3ld%% ",nx12extp[treecase],countell, |
|---|
| 467 | (10 * (countell*100/rangtell) + 5) / 10); |
|---|
| 468 | fprintf(fpx,"i=%3d/%ld\n",moved,punt*nodesize); |
|---|
| 469 | } |
|---|
| 470 | |
|---|
| 471 | } /* end for punt */ |
|---|
| 472 | |
|---|
| 473 | fpcclose(); |
|---|
| 474 | |
|---|
| 475 | } /* end for treecase */ |
|---|
| 476 | |
|---|
| 477 | |
|---|
| 478 | /* |
|---|
| 479 | rewrite .cnt |
|---|
| 480 | */ |
|---|
| 481 | |
|---|
| 482 | fpccreat("",zdbnp,cx1extp,0); |
|---|
| 483 | invp->cn[0].ordf++; |
|---|
| 484 | for (treecase=0; treecase < 2; treecase++) { |
|---|
| 485 | if (parmtrace) printf("+++ ordf=%d \n",invp->cn[treecase].ordf); |
|---|
| 486 | #if PCCTRACE |
|---|
| 487 | memcpy(mov_record,&(invp->cn[treecase]),moved=CNBSIZ); |
|---|
| 488 | putpcinv(moved); |
|---|
| 489 | #endif |
|---|
| 490 | movp=mov_record; moved=0; |
|---|
| 491 | mov2(invp->cn[treecase].idtype); |
|---|
| 492 | mov2(invp->cn[treecase].ordn); |
|---|
| 493 | mov2(invp->cn[treecase].ordf); |
|---|
| 494 | mov2(invp->cn[treecase].n); |
|---|
| 495 | mov2(invp->cn[treecase].k); |
|---|
| 496 | mov2(invp->cn[treecase].liv); |
|---|
| 497 | mov4(invp->cn[treecase].posrx); |
|---|
| 498 | mov4(invp->cn[treecase].nmaxpos); |
|---|
| 499 | mov4(invp->cn[treecase].fmaxpos); |
|---|
| 500 | mov2(invp->cn[treecase].abnormal); |
|---|
| 501 | fpcwrite(mov_record,moved); |
|---|
| 502 | } |
|---|
| 503 | fpcclose(); |
|---|
| 504 | |
|---|
| 505 | |
|---|
| 506 | exit(0); |
|---|
| 507 | } |
|---|
| 508 | |
|---|
| 509 | |
|---|
| 510 | LONGX leafadda(treecase,punt,addr) |
|---|
| 511 | int treecase; |
|---|
| 512 | PUNT punt; |
|---|
| 513 | LONGX addr; |
|---|
| 514 | { |
|---|
| 515 | if (punt < 1) fatal("leafadda/punt"); |
|---|
| 516 | |
|---|
| 517 | apun=punt/divapu; |
|---|
| 518 | |
|---|
| 519 | if (apun >= napus) { |
|---|
| 520 | if (napus >= MAXNAPU) fatal("MAXNAPU"); |
|---|
| 521 | apup=(LONGX *)ALLOC((ALLOPARM)ALLOMAXV); |
|---|
| 522 | if (apup == (LONGX *)ALLONULL) fatal("ALLOC/vapup"); |
|---|
| 523 | apun=napus; |
|---|
| 524 | vapup[napus++]=apup; |
|---|
| 525 | } |
|---|
| 526 | |
|---|
| 527 | apuk=punt%divapu; |
|---|
| 528 | apup=vapup[apun]; |
|---|
| 529 | |
|---|
| 530 | if (parmtrace) |
|---|
| 531 | printf("+++ leafadda - punt=%d/%ld addr=%ld [%d/%d +%d/%d]\n", |
|---|
| 532 | treecase,punt,addr,apun,napus,apuk,divapu); |
|---|
| 533 | |
|---|
| 534 | apup[apuk]=addr; |
|---|
| 535 | |
|---|
| 536 | return(addr); |
|---|
| 537 | } |
|---|
| 538 | |
|---|
| 539 | |
|---|
| 540 | LONGX leafaddr(treecase,pos,ock,punt) |
|---|
| 541 | int treecase; |
|---|
| 542 | PUNT pos; |
|---|
| 543 | int ock; |
|---|
| 544 | PUNT punt; |
|---|
| 545 | { |
|---|
| 546 | apun=punt/divapu; |
|---|
| 547 | |
|---|
| 548 | if (punt < 1 || apun >= napus) fatal("leafaddr/punt"); |
|---|
| 549 | |
|---|
| 550 | apuk=punt%divapu; |
|---|
| 551 | apup=vapup[apun]; |
|---|
| 552 | |
|---|
| 553 | if (parmtrace) |
|---|
| 554 | printf("+++ leafaddr - punt=%d/%ld node=%ld/%d addr=%ld \n", |
|---|
| 555 | treecase,punt,pos,ock,apup[apuk]); |
|---|
| 556 | |
|---|
| 557 | return(apup[apuk]); |
|---|
| 558 | } |
|---|