| 1 | /* crunchif - convert SunOS (or MPE?) inverted file to PC format |
|---|
| 2 | AOT, 26/10/93 |
|---|
| 3 | |
|---|
| 4 | Alteracao <target_dbn> |
|---|
| 5 | AOT, 28/11/2001 |
|---|
| 6 | |
|---|
| 7 | */ |
|---|
| 8 | #include <stdio.h> |
|---|
| 9 | #include <string.h> |
|---|
| 10 | #include <ctype.h> |
|---|
| 11 | #include "cisis.h" |
|---|
| 12 | #include "cirun.h" |
|---|
| 13 | |
|---|
| 14 | #define INVTRACE 0 |
|---|
| 15 | #define PCCTRACE 0 |
|---|
| 16 | #define PCNTRACE 0 |
|---|
| 17 | #define PCLTRACE 0 |
|---|
| 18 | |
|---|
| 19 | #define BUFSZX 0x4000 /* 16K */ |
|---|
| 20 | |
|---|
| 21 | #define NOSW_20 0 |
|---|
| 22 | #define NOSW_21 1 |
|---|
| 23 | #define NOSW_40 0 |
|---|
| 24 | #define NOSW_41 1 |
|---|
| 25 | #define NOSW_42 2 |
|---|
| 26 | #define NOSW_43 3 |
|---|
| 27 | |
|---|
| 28 | #define SWAP_20 1 |
|---|
| 29 | #define SWAP_21 0 |
|---|
| 30 | #define SWAP_40 3 |
|---|
| 31 | #define SWAP_41 2 |
|---|
| 32 | #define SWAP_42 1 |
|---|
| 33 | #define SWAP_43 0 |
|---|
| 34 | |
|---|
| 35 | char *movp,*movtmp; |
|---|
| 36 | UWORD moved; |
|---|
| 37 | |
|---|
| 38 | int alignment; |
|---|
| 39 | int mv20,mv21,mv40,mv41,mv42,mv43; |
|---|
| 40 | int xalign; |
|---|
| 41 | |
|---|
| 42 | #define mova(a) \ |
|---|
| 43 | if (a > 1) if ((xalign=moved%a) != 0) while (xalign--) { *movp++ = '\0'; moved++; } |
|---|
| 44 | |
|---|
| 45 | #define mov2(source) \ |
|---|
| 46 | if (alignment >= 2) if ((xalign=moved%2) != 0) while (xalign--) { *movp++ = '\0'; moved++; } \ |
|---|
| 47 | movtmp = (char *)&(source); \ |
|---|
| 48 | *movp++ = movtmp[mv20]; \ |
|---|
| 49 | *movp++ = movtmp[mv21]; \ |
|---|
| 50 | moved+=2; |
|---|
| 51 | #define mov4(source) \ |
|---|
| 52 | if (alignment >= 4) if ((xalign=moved%4) != 0) while (xalign--) { *movp++ = '\0'; moved++; } \ |
|---|
| 53 | movtmp = (char *)&(source); \ |
|---|
| 54 | *movp++ = movtmp[mv40]; \ |
|---|
| 55 | *movp++ = movtmp[mv41]; \ |
|---|
| 56 | *movp++ = movtmp[mv42]; \ |
|---|
| 57 | *movp++ = movtmp[mv43]; \ |
|---|
| 58 | moved+=4; |
|---|
| 59 | #define movx(sourcep,len) \ |
|---|
| 60 | memcpy(movp,sourcep,(size_t)len); \ |
|---|
| 61 | movp+=len; \ |
|---|
| 62 | moved+=len; |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | #if ANSI |
|---|
| 66 | void filcreat(char *gidbnp, char *namp, char *extp, int lrecl); |
|---|
| 67 | void putpcinv(UWORD reclen); |
|---|
| 68 | void endpcinv(void); |
|---|
| 69 | int filopen(char *filename); |
|---|
| 70 | int filclos(int fd); |
|---|
| 71 | #else |
|---|
| 72 | void filcreat(); |
|---|
| 73 | void putpcinv(); |
|---|
| 74 | void endpcinv(); |
|---|
| 75 | int filopen(); |
|---|
| 76 | int filclos(); |
|---|
| 77 | #endif |
|---|
| 78 | |
|---|
| 79 | int inv_fd=0; |
|---|
| 80 | UWORD inv_left=BUFSZX; |
|---|
| 81 | char *inv_buffer,*inv_record; |
|---|
| 82 | char inv_filename[BUFSIZ]; |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | #if !LIND |
|---|
| 86 | #if ANSI |
|---|
| 87 | void cru_ifplist(int parmtrace, TRMSTRU *trmp, INFO info1, INFO info2, int fd); |
|---|
| 88 | void cru_posthdr1(int parmtrace, TRMSTRU *trmp, INFO info1, INFO info2, int fd); |
|---|
| 89 | LONGX cru_posting(int parmtrace, TRMSTRU *trmp, LONGX nord, int fd); |
|---|
| 90 | void cru_postread(int parmtrace, TRMSTRU *trmp, PUNT xblk, int fd); |
|---|
| 91 | void cru_cruifhdr(IFPHEAD *hdrp); |
|---|
| 92 | #else |
|---|
| 93 | void cru_ifplist(); |
|---|
| 94 | void cru_posthdr1(); |
|---|
| 95 | LONGX cru_posting(); |
|---|
| 96 | void cru_postread(); |
|---|
| 97 | void cru_cruifhdr(); |
|---|
| 98 | #endif |
|---|
| 99 | #endif /* !LIND */ |
|---|
| 100 | |
|---|
| 101 | void main(argc,argv) |
|---|
| 102 | int argc; |
|---|
| 103 | char *argv[]; |
|---|
| 104 | { |
|---|
| 105 | char *dbnp,*pcdbnp; |
|---|
| 106 | #if !LIND |
|---|
| 107 | DBXSTRU *dbxp; |
|---|
| 108 | TRMSTRU *trmp; |
|---|
| 109 | char cru_trmarea[sizeof(TRMSTRU)+IFBSIZ]; |
|---|
| 110 | TRMSTRU *cru_trmp=(TRMSTRU *)cru_trmarea; |
|---|
| 111 | #endif |
|---|
| 112 | INVMAP *invp; |
|---|
| 113 | N0STRU *n0p; |
|---|
| 114 | N1IDXE *n1xp; |
|---|
| 115 | N2IDXE *n2xp; |
|---|
| 116 | L0STRU *l0p; |
|---|
| 117 | L1IDXE *l1xp; |
|---|
| 118 | L2IDXE *l2xp; |
|---|
| 119 | UCHR leafarea[sizeof(L2STRU)]; |
|---|
| 120 | int treecase,loop; |
|---|
| 121 | PUNT punt; |
|---|
| 122 | char *p; |
|---|
| 123 | LONGX count1=0,count2=0; |
|---|
| 124 | int argnext=1; |
|---|
| 125 | LONGX parmtell; |
|---|
| 126 | int parmtrace=0; |
|---|
| 127 | #if !LIND |
|---|
| 128 | int parmifpno=0; |
|---|
| 129 | int parmifpif=0; |
|---|
| 130 | #endif |
|---|
| 131 | |
|---|
| 132 | #define TARGET_pc 0 |
|---|
| 133 | #define TARGET_linux 1 |
|---|
| 134 | #define TARGET_hpux 2 |
|---|
| 135 | #define TARGET_sun 3 |
|---|
| 136 | #define TARGET_alpha 4 |
|---|
| 137 | #define TARGET_vax 5 |
|---|
| 138 | #define TARGET_unisys 6 |
|---|
| 139 | #define TARGET_mpe 7 |
|---|
| 140 | #define TARGET_cdc 8 |
|---|
| 141 | /* 0 1 2 3 4 5 6 7 8 */ |
|---|
| 142 | char *target_id[] = {"pc","linux","hpux","sun","alpha","vax","unisys","mpe","cdc",NULL}; |
|---|
| 143 | int target_align[] = { 1, 4, 4, 4, 4, 1, 4, 4, 4, 0 }; |
|---|
| 144 | int target_swapped[]= { 1, 1, 0, 0, 1, 1, 1, 0, 0, 0 }; |
|---|
| 145 | int i; |
|---|
| 146 | |
|---|
| 147 | #if PC |
|---|
| 148 | int xtarget=TARGET_linux; |
|---|
| 149 | #else |
|---|
| 150 | int xtarget=TARGET_pc; |
|---|
| 151 | #endif |
|---|
| 152 | |
|---|
| 153 | int xorigin=TARGET_alpha; |
|---|
| 154 | #if PC |
|---|
| 155 | xorigin=TARGET_pc; |
|---|
| 156 | #endif |
|---|
| 157 | #if UNIX |
|---|
| 158 | #if INTELCPU |
|---|
| 159 | xorigin=TARGET_linux; |
|---|
| 160 | #endif |
|---|
| 161 | #endif |
|---|
| 162 | #if BRME || BRMXCPU |
|---|
| 163 | xorigin=TARGET_hpux; |
|---|
| 164 | #endif |
|---|
| 165 | #if SUN |
|---|
| 166 | xorigin=TARGET_sun; |
|---|
| 167 | #endif |
|---|
| 168 | #if VAX |
|---|
| 169 | xorigin=TARGET_vax; |
|---|
| 170 | #endif |
|---|
| 171 | #if UNISYSCPU |
|---|
| 172 | xorigin=TARGET_unisys; |
|---|
| 173 | #endif |
|---|
| 174 | #if MPE |
|---|
| 175 | xorigin=TARGET_mpe; |
|---|
| 176 | #endif |
|---|
| 177 | #if CDCS4320 |
|---|
| 178 | xorigin=TARGET_cds; |
|---|
| 179 | #endif |
|---|
| 180 | |
|---|
| 181 | |
|---|
| 182 | if (argc == 2 && strcmp(argv[1],"what") == 0) { |
|---|
| 183 | printf("%s",cicopyr("?Utility CRUNCHIF")); |
|---|
| 184 | printf("\n"); |
|---|
| 185 | exit(0); |
|---|
| 186 | } |
|---|
| 187 | if (argc < 3) { |
|---|
| 188 | printf("%s",cicopyr("Utility CRUNCHIF")); |
|---|
| 189 | printf("\n"); |
|---|
| 190 | printf("crunchif <dbn> <target_dbn> [<option> [...]] \n"); |
|---|
| 191 | printf(" \n"); |
|---|
| 192 | printf("options: \n"); |
|---|
| 193 | printf("\n"); |
|---|
| 194 | #if !LIND |
|---|
| 195 | printf(" -ifp -> don't crunch %s file \n",ix1extp); |
|---|
| 196 | printf(" /ifp -> crunch %s file if needed \n",ix1extp); |
|---|
| 197 | #endif |
|---|
| 198 | printf(" tell=<n> -> tell <n> records processed \n"); |
|---|
| 199 | printf(" \n"); |
|---|
| 200 | printf(" target={%s",target_id[xtarget]); |
|---|
| 201 | for (i=0; target_id[i]; i++) |
|---|
| 202 | if (i != xtarget && i != xorigin) printf("|%s",target_id[i]); |
|---|
| 203 | printf("|%s",target_id[xorigin]); |
|---|
| 204 | printf("} default: %s\n",target_id[xtarget]); |
|---|
| 205 | printf(" \n"); |
|---|
| 206 | exit(1); |
|---|
| 207 | } |
|---|
| 208 | |
|---|
| 209 | /* get positional parms */ |
|---|
| 210 | dbnp=argv[argnext++]; |
|---|
| 211 | pcdbnp=argv[argnext++]; |
|---|
| 212 | |
|---|
| 213 | /* get optional parms */ |
|---|
| 214 | parmtell=0; |
|---|
| 215 | for (; argnext < argc; ) { |
|---|
| 216 | p=argv[argnext++]; |
|---|
| 217 | if (strncmp(p,"tell?",5) == 0 || strncmp(p,"tell=",5) == 0) { |
|---|
| 218 | if (sscanf(p+5,"%ld",&parmtell) != 1) fatal(p); |
|---|
| 219 | continue; |
|---|
| 220 | } |
|---|
| 221 | if (strcmp(p,"trace?all") == 0|| strcmp(p,"trace=all") == 0) { |
|---|
| 222 | parmtrace=dbxtrace=trmtrace=1; |
|---|
| 223 | continue; |
|---|
| 224 | } |
|---|
| 225 | if (strcmp(p,"trace") == 0) { |
|---|
| 226 | parmtrace=1; |
|---|
| 227 | continue; |
|---|
| 228 | } |
|---|
| 229 | #if !LIND |
|---|
| 230 | if (strcmp(p,"-ifp") == 0) { |
|---|
| 231 | parmifpno=1; |
|---|
| 232 | continue; |
|---|
| 233 | } |
|---|
| 234 | if (strcmp(p,"/ifp") == 0) { |
|---|
| 235 | parmifpif=1; |
|---|
| 236 | continue; |
|---|
| 237 | } |
|---|
| 238 | #endif |
|---|
| 239 | if (strncmp(p,"target?",7) == 0 || strncmp(p,"target=",7) == 0) { |
|---|
| 240 | int found=0; |
|---|
| 241 | for (xtarget=0; target_id[xtarget]; xtarget++) { |
|---|
| 242 | if (strcmp(p+7,target_id[xtarget])) continue; |
|---|
| 243 | found=1; break; |
|---|
| 244 | } |
|---|
| 245 | if (!found) fatal(p); |
|---|
| 246 | continue; |
|---|
| 247 | } |
|---|
| 248 | fatal(p); |
|---|
| 249 | } |
|---|
| 250 | |
|---|
| 251 | /* setup processing */ |
|---|
| 252 | alignment=target_align[xtarget]; |
|---|
| 253 | |
|---|
| 254 | mv20=NOSW_20; |
|---|
| 255 | mv21=NOSW_21; |
|---|
| 256 | mv40=NOSW_40; |
|---|
| 257 | mv41=NOSW_41; |
|---|
| 258 | mv42=NOSW_42; |
|---|
| 259 | mv43=NOSW_43; |
|---|
| 260 | if (target_swapped[xtarget] != target_swapped[xorigin]) { |
|---|
| 261 | mv20=SWAP_20; |
|---|
| 262 | mv21=SWAP_21; |
|---|
| 263 | mv40=SWAP_40; |
|---|
| 264 | mv41=SWAP_41; |
|---|
| 265 | mv42=SWAP_42; |
|---|
| 266 | mv43=SWAP_43; |
|---|
| 267 | } |
|---|
| 268 | |
|---|
| 269 | /* allocate putpcinv() output buffer */ |
|---|
| 270 | inv_buffer=(char *)ALLOC((ALLOPARM)BUFSZX); |
|---|
| 271 | if (inv_buffer == (char *)ALLONULL) |
|---|
| 272 | fatal("ALLOC/inv_buffer"); |
|---|
| 273 | /* allocate processing buffer */ |
|---|
| 274 | inv_record=(char *)ALLOC((ALLOPARM)BUFSZX); |
|---|
| 275 | if (inv_record == (char *)ALLONULL) |
|---|
| 276 | fatal("ALLOC/inv_record"); |
|---|
| 277 | /* setup inverted file */ |
|---|
| 278 | invsetup(dbnp,0L,0L,0L); |
|---|
| 279 | invp=dbxstorp(dbnp)->dbxifmap; |
|---|
| 280 | /* convert .cnt */ |
|---|
| 281 | filcreat(NULL,pcdbnp,cx1extp,0); |
|---|
| 282 | for (treecase=0; treecase < 2; treecase++) { |
|---|
| 283 | movp=inv_record; moved=0; |
|---|
| 284 | mov2(invp->cn[treecase].idtype); |
|---|
| 285 | mov2(invp->cn[treecase].ordn); |
|---|
| 286 | mov2(invp->cn[treecase].ordf); |
|---|
| 287 | mov2(invp->cn[treecase].n); |
|---|
| 288 | mov2(invp->cn[treecase].k); |
|---|
| 289 | mov2(invp->cn[treecase].liv); |
|---|
| 290 | mov4(invp->cn[treecase].posrx); |
|---|
| 291 | mov4(invp->cn[treecase].nmaxpos); |
|---|
| 292 | mov4(invp->cn[treecase].fmaxpos); |
|---|
| 293 | mov2(invp->cn[treecase].abnormal); |
|---|
| 294 | mova(alignment); |
|---|
| 295 | putpcinv(moved); |
|---|
| 296 | } |
|---|
| 297 | endpcinv(); |
|---|
| 298 | /* convert .n0x */ |
|---|
| 299 | for (treecase=0; treecase < 2; treecase++) { |
|---|
| 300 | filcreat(NULL,pcdbnp,nx12extp[treecase],0); |
|---|
| 301 | for (punt=1L; punt <= invp->cn[treecase].nmaxpos; punt++) { |
|---|
| 302 | n0p=noderead(invp,treecase,0,punt); |
|---|
| 303 | movp=inv_record; moved=0; |
|---|
| 304 | mov4(n0p->pos); |
|---|
| 305 | mov2(n0p->ock); |
|---|
| 306 | mov2(n0p->it); |
|---|
| 307 | loop=TWORDN; |
|---|
| 308 | if (treecase) |
|---|
| 309 | for (n2xp=((N2STRU *)n0p)->idx; loop--; n2xp++) { |
|---|
| 310 | movx(n2xp->key,LE2); |
|---|
| 311 | mov4(n2xp->punt); |
|---|
| 312 | mova(alignment); |
|---|
| 313 | } |
|---|
| 314 | else |
|---|
| 315 | for (n1xp=((N1STRU *)n0p)->idx; loop--; n1xp++) { |
|---|
| 316 | movx(n1xp->key,LE1); |
|---|
| 317 | mov4(n1xp->punt); |
|---|
| 318 | mova(alignment); |
|---|
| 319 | } |
|---|
| 320 | putpcinv(moved); |
|---|
| 321 | } |
|---|
| 322 | endpcinv(); |
|---|
| 323 | } |
|---|
| 324 | /* convert .l0x */ |
|---|
| 325 | for (treecase=0; treecase < 2; treecase++) { |
|---|
| 326 | filcreat(NULL,pcdbnp,lx12extp[treecase],0); |
|---|
| 327 | for (punt=1L; punt <= invp->cn[treecase].fmaxpos; punt++) { |
|---|
| 328 | l0p=leafread(leafarea,invp,treecase,punt,0); |
|---|
| 329 | movp=inv_record; moved=0; |
|---|
| 330 | mov4(l0p->pos); |
|---|
| 331 | mov2(l0p->ock); |
|---|
| 332 | mov2(l0p->it); |
|---|
| 333 | mov4(l0p->ps); |
|---|
| 334 | #if LIND |
|---|
| 335 | mov4(l0p->psb); |
|---|
| 336 | #endif |
|---|
| 337 | loop=TWORDF; |
|---|
| 338 | if (treecase) |
|---|
| 339 | for (l2xp=((L2STRU *)l0p)->idx; loop--; l2xp++) { |
|---|
| 340 | movx(l2xp->key,LE2); |
|---|
| 341 | mov4(l2xp->info1); |
|---|
| 342 | mov4(l2xp->info2); |
|---|
| 343 | #if LIND |
|---|
| 344 | mov4(l2xp->info3info4.info3); |
|---|
| 345 | #endif |
|---|
| 346 | mova(alignment); |
|---|
| 347 | } |
|---|
| 348 | else |
|---|
| 349 | for (l1xp=((L1STRU *)l0p)->idx; loop--; l1xp++) { |
|---|
| 350 | /*mova(0);*/ |
|---|
| 351 | movx(l1xp->key,LE1); |
|---|
| 352 | mov4(l1xp->info1); |
|---|
| 353 | mov4(l1xp->info2); |
|---|
| 354 | #if LIND |
|---|
| 355 | mov4(l1xp->info3info4.info3); |
|---|
| 356 | #endif |
|---|
| 357 | mova(alignment); |
|---|
| 358 | } |
|---|
| 359 | putpcinv(moved); |
|---|
| 360 | } |
|---|
| 361 | endpcinv(); |
|---|
| 362 | } |
|---|
| 363 | |
|---|
| 364 | |
|---|
| 365 | #if !LIND /* ... */ |
|---|
| 366 | |
|---|
| 367 | /* convert .ifp */ |
|---|
| 368 | |
|---|
| 369 | if (!parmifpno) { |
|---|
| 370 | |
|---|
| 371 | int genifp=1; |
|---|
| 372 | if (parmifpif) { |
|---|
| 373 | int ifpshort=4; |
|---|
| 374 | if (ifpshort >= alignment) |
|---|
| 375 | if (target_swapped[xtarget] == target_swapped[xorigin]) |
|---|
| 376 | genifp=0; |
|---|
| 377 | } |
|---|
| 378 | if (genifp) { |
|---|
| 379 | |
|---|
| 380 | /* copy .ifp blocks, converting .ifp block# and ifpctrl */ |
|---|
| 381 | filcreat(NULL,pcdbnp,ix1extp,0); |
|---|
| 382 | TERM(0L,dbnp,"!"); dbxp=TRMdbxp; |
|---|
| 383 | #if CNLI |
|---|
| 384 | if (LSEEK64(DBIifopn,invp->ci_offset,SEEK_SET) != invp->ci_offset) fatal("crunchif/ifp/seek0"); |
|---|
| 385 | #else |
|---|
| 386 | if (LSEEK64(DBIifopn,0L,SEEK_SET) != 0) fatal("crunchif/ifp/seek0"); |
|---|
| 387 | #endif |
|---|
| 388 | while (CIREAD(DBIifopn,TRMifbuf,IFBSIZ) == IFBSIZ) { |
|---|
| 389 | IFPSTRU *ifp=(IFPSTRU *)TRMifbuf; |
|---|
| 390 | movp=inv_record; moved=0; |
|---|
| 391 | if (ifp->ifpblk == 1) { |
|---|
| 392 | IFPCTRL *ifp=(IFPCTRL *)TRMifbuf; |
|---|
| 393 | mov4(ifp->ifpblk); |
|---|
| 394 | mov4(ifp->ifprec1); |
|---|
| 395 | mov4(ifp->ifprec2); |
|---|
| 396 | movx(TRMifbuf+4+4+4,IFBSIZ-4-4-4); |
|---|
| 397 | } |
|---|
| 398 | else { |
|---|
| 399 | mov4(ifp->ifpblk); |
|---|
| 400 | movx(TRMifbuf+4,IFBSIZ-4); |
|---|
| 401 | } |
|---|
| 402 | putpcinv(moved); |
|---|
| 403 | } |
|---|
| 404 | endpcinv(); |
|---|
| 405 | |
|---|
| 406 | /* parse dictionary, converting ifp header and ifp segments */ |
|---|
| 407 | |
|---|
| 408 | memset(cru_trmarea,0x00,sizeof(cru_trmarea)); |
|---|
| 409 | inv_fd=filopen(inv_filename); |
|---|
| 410 | |
|---|
| 411 | for (treecase=0; treecase < 2; treecase++) { |
|---|
| 412 | PUNT punt; |
|---|
| 413 | int level; |
|---|
| 414 | if (parmtrace) printf("+++treecase=%d liv=%ld posrx=%ld\n",treecase,(LONGX)invp->cn[treecase].liv,(LONGX)invp->cn[treecase].posrx); |
|---|
| 415 | if (invp->cn[treecase].liv == NEGLIV) continue; |
|---|
| 416 | |
|---|
| 417 | punt=invp->cn[treecase].posrx; |
|---|
| 418 | for (level=0; punt > 0; level++) { |
|---|
| 419 | N0STRU *n0p; |
|---|
| 420 | if (parmtrace) printf("+++treecase=%d node=%ld",treecase,(LONGX)punt); |
|---|
| 421 | n0p=noderead(invp,treecase,level,punt); |
|---|
| 422 | if (treecase) { |
|---|
| 423 | N2STRU *n2p=(N2STRU *)n0p; punt=n2p->idx[0].punt; |
|---|
| 424 | } |
|---|
| 425 | else { |
|---|
| 426 | N1STRU *n1p=(N1STRU *)n0p; punt=n1p->idx[0].punt; |
|---|
| 427 | } |
|---|
| 428 | if (parmtrace) printf(" punt0=%ld\n",(LONGX)punt); |
|---|
| 429 | } |
|---|
| 430 | punt= -punt; |
|---|
| 431 | |
|---|
| 432 | while (punt > 0) { |
|---|
| 433 | INFO info1; |
|---|
| 434 | INFO info2; |
|---|
| 435 | int i; |
|---|
| 436 | if (parmtrace) printf("+++treecase=%d leaf=%ld",treecase,(LONGX)punt); |
|---|
| 437 | l0p=leafread(leafarea,invp,treecase,punt,0); |
|---|
| 438 | if (parmtrace) printf(" ps=%ld\n",(LONGX)l0p->ps); |
|---|
| 439 | |
|---|
| 440 | loop=l0p->ock; |
|---|
| 441 | for (i=0; i<loop; i++) { |
|---|
| 442 | if (treecase) { |
|---|
| 443 | L2STRU *l2p=(L2STRU *)l0p; |
|---|
| 444 | info1=l2p->idx[i].info1; |
|---|
| 445 | info2=l2p->idx[i].info2; |
|---|
| 446 | if (parmtrace) printf("+++treecase=%d leaf=%ld key=%.30s info=%ld/%ld\n",treecase,(LONGX)punt, |
|---|
| 447 | l2p->idx[i].key,(LONGX)info1,(LONGX)info2); |
|---|
| 448 | } |
|---|
| 449 | else { |
|---|
| 450 | L1STRU *l1p=(L1STRU *)l0p; |
|---|
| 451 | info1=l1p->idx[i].info1; |
|---|
| 452 | info2=l1p->idx[i].info2; |
|---|
| 453 | if (parmtrace) printf("+++treecase=%d leaf=%ld key=%.10s info=%ld/%ld\n",treecase,(LONGX)punt, |
|---|
| 454 | l1p->idx[i].key,(LONGX)info1,(LONGX)info2); |
|---|
| 455 | } |
|---|
| 456 | |
|---|
| 457 | cru_trmp->trmlcase=treecase; |
|---|
| 458 | cru_ifplist(parmtrace,cru_trmp,info1,info2,inv_fd); |
|---|
| 459 | } |
|---|
| 460 | |
|---|
| 461 | punt=l0p->ps; |
|---|
| 462 | |
|---|
| 463 | } |
|---|
| 464 | } |
|---|
| 465 | cru_postread(parmtrace,cru_trmp,0,inv_fd); |
|---|
| 466 | filclos(inv_fd); |
|---|
| 467 | |
|---|
| 468 | } |
|---|
| 469 | else { |
|---|
| 470 | if (parmtrace || parmtell) printf("+++ %s%s not generated! \n",pcdbnp,ix1extp); |
|---|
| 471 | } /* end if (genifp) */ |
|---|
| 472 | |
|---|
| 473 | } /* end if (!parmifpno) */ |
|---|
| 474 | |
|---|
| 475 | #endif /* !LIND */ /* ... */ |
|---|
| 476 | |
|---|
| 477 | if (parmtell) fprintf(stderr,"+++ %ld/%ld \n",count1,count2); |
|---|
| 478 | |
|---|
| 479 | exit(0); |
|---|
| 480 | } |
|---|
| 481 | |
|---|
| 482 | /* ----------------------------- pst.c ------------------------------ */ |
|---|
| 483 | |
|---|
| 484 | #if !LIND |
|---|
| 485 | |
|---|
| 486 | |
|---|
| 487 | void cru_ifplist(parmtrace,trmp,info1,info2,fd) |
|---|
| 488 | int parmtrace; |
|---|
| 489 | TRMSTRU *trmp; |
|---|
| 490 | INFO info1; |
|---|
| 491 | INFO info2; |
|---|
| 492 | int fd; |
|---|
| 493 | { |
|---|
| 494 | |
|---|
| 495 | if (parmtrace) printf("+++cru_posthdr1 - info=%ld/%ld\n",(LONGX)info1,(LONGX)info2); |
|---|
| 496 | |
|---|
| 497 | cru_posthdr1(parmtrace,trmp,info1,info2,fd); |
|---|
| 498 | |
|---|
| 499 | do { |
|---|
| 500 | ; |
|---|
| 501 | } while (cru_posting(parmtrace,trmp,TRMpost+1,fd) > 0); |
|---|
| 502 | |
|---|
| 503 | } |
|---|
| 504 | |
|---|
| 505 | void cru_postread(parmtrace,trmp,xblk,fd) |
|---|
| 506 | int parmtrace; |
|---|
| 507 | TRMSTRU *trmp; |
|---|
| 508 | PUNT xblk; /* registro desejado */ |
|---|
| 509 | int fd; |
|---|
| 510 | { |
|---|
| 511 | IFPSTRU *xp; |
|---|
| 512 | off_t sbyte; |
|---|
| 513 | LONGX cmpblkno; |
|---|
| 514 | |
|---|
| 515 | xp=(IFPSTRU *)TRMifbuf; |
|---|
| 516 | |
|---|
| 517 | if (xp->ifpblk) { |
|---|
| 518 | LONGX blkno; |
|---|
| 519 | movp=(char *)&blkno; mov4(xp->ifpblk); |
|---|
| 520 | sbyte=(blkno-1L)<<IFSHIFT; |
|---|
| 521 | if (LSEEK64(fd,sbyte,SEEK_SET) != sbyte) fatal("cru_postread/lseek/w"); |
|---|
| 522 | if (CIWRITE(fd,TRMifbuf,IFBSIZ) != IFBSIZ) fatal("cru_postread/write"); |
|---|
| 523 | } |
|---|
| 524 | |
|---|
| 525 | if (xblk) { |
|---|
| 526 | sbyte=(xblk-1L)<<IFSHIFT; |
|---|
| 527 | if (parmtrace) printf("+++cru_postread - xblk=%ld sbyte=%"P_OFF_T" \n",(LONGX)xblk,(LONG_LONG)sbyte); |
|---|
| 528 | if (LSEEK64(fd,sbyte,SEEK_SET) != sbyte) fatal("cru_postread/lseek/r"); |
|---|
| 529 | if (CIREAD(fd,TRMifbuf,IFBSIZ) != IFBSIZ) fatal("cru_postread/read"); |
|---|
| 530 | movp=(char *)&cmpblkno; mov4(xblk); |
|---|
| 531 | if (xp->ifpblk != cmpblkno) fatal("cru_postread/check/xblk"); |
|---|
| 532 | } |
|---|
| 533 | } |
|---|
| 534 | |
|---|
| 535 | void cru_posthdr1(parmtrace,trmp,info1,info2,fd) |
|---|
| 536 | int parmtrace; |
|---|
| 537 | TRMSTRU *trmp; /* elemento de vtrmp, apos nx/term(), com IFBSIZ */ |
|---|
| 538 | INFO info1; |
|---|
| 539 | INFO info2; |
|---|
| 540 | int fd; |
|---|
| 541 | { |
|---|
| 542 | UCHR *p,*inp; |
|---|
| 543 | int n; |
|---|
| 544 | INFO *hdrp,*segp,*hp; |
|---|
| 545 | LONGX cmpblkno; |
|---|
| 546 | |
|---|
| 547 | TRMpleft=0; |
|---|
| 548 | TRMpcblk=0; TRMpcpos=IFMAXTIV; |
|---|
| 549 | |
|---|
| 550 | inp=TRMifbuf; |
|---|
| 551 | movp=(char *)&cmpblkno; mov4(info1); |
|---|
| 552 | if (*(INFO *)(inp) != cmpblkno) /* *(INFO *)(inp) != info1 */ |
|---|
| 553 | cru_postread(parmtrace,trmp,info1,fd); |
|---|
| 554 | |
|---|
| 555 | p=inp+INFOSIZE+(info2*INFOSIZE); /* INFOSIZE = ifpblk */ |
|---|
| 556 | hdrp=(INFO *)&TRMifhdr; |
|---|
| 557 | segp=(INFO *)&TRMifseg; |
|---|
| 558 | for (hp=(INFO *)(p), n=IFHDRINFOS; n--; ) *hdrp++= *segp++= *hp++; |
|---|
| 559 | |
|---|
| 560 | TRMpcblk=info1; TRMpcpos=info2+IFHDRINFOS; |
|---|
| 561 | TRMpost=0; TRMpleft=TRMifhdr.ifpsegp; |
|---|
| 562 | if (parmtrace) printf("+++cru_posthdr1 - post=%ld pcblk=%ld pcpos=%ld totp=%ld \n",TRMpost,TRMpcblk,TRMpcpos,TRMpleft); |
|---|
| 563 | |
|---|
| 564 | cru_cruifhdr((IFPHEAD *)p); |
|---|
| 565 | } |
|---|
| 566 | |
|---|
| 567 | void cru_cruifhdr(hdrp) |
|---|
| 568 | IFPHEAD *hdrp; |
|---|
| 569 | { |
|---|
| 570 | char hdrarea[sizeof(IFPHEAD)]; |
|---|
| 571 | |
|---|
| 572 | movp=(char *)hdrarea; |
|---|
| 573 | |
|---|
| 574 | mov4(hdrp->ifpnxtb); /* gdb .ifp ifpnxtb */ |
|---|
| 575 | mov4(hdrp->ifpnxtp); /* gdb .ifp ifpnxtp */ |
|---|
| 576 | mov4(hdrp->ifptotp); /* gdb .ifp ifptotp */ |
|---|
| 577 | mov4(hdrp->ifpsegp); /* gdb .ifp ifpsegp */ |
|---|
| 578 | mov4(hdrp->ifpsegc); /* gdb .ifp ifpsegc */ |
|---|
| 579 | |
|---|
| 580 | memcpy((char *)hdrp,hdrarea,sizeof(IFPHEAD)); |
|---|
| 581 | } |
|---|
| 582 | |
|---|
| 583 | LONGX cru_posting(parmtrace,trmp,nord,fd) |
|---|
| 584 | int parmtrace; |
|---|
| 585 | TRMSTRU *trmp; /* elemento de vtrmp, apos nx/term(), com IFBSIZ */ |
|---|
| 586 | LONGX nord; /* numero de ordem do posting desejado ou 0L */ |
|---|
| 587 | int fd; |
|---|
| 588 | { |
|---|
| 589 | LONGX total; |
|---|
| 590 | INFO info1,info2,*hp,*sp; |
|---|
| 591 | int n; |
|---|
| 592 | UCHR *p,*inp; |
|---|
| 593 | LONGX cmpblkno; |
|---|
| 594 | |
|---|
| 595 | total=TRMifhdr.ifptotp; |
|---|
| 596 | if (nord == 0) return(total); |
|---|
| 597 | if (nord > total) { |
|---|
| 598 | TRMpost=0; |
|---|
| 599 | TRMpleft=0; |
|---|
| 600 | return(-1L); |
|---|
| 601 | } |
|---|
| 602 | |
|---|
| 603 | TRMpost++; |
|---|
| 604 | if (parmtrace) printf("+++cru_posting1 - post=%ld pcblk=%ld pcpos=%ld left=%ld\n",TRMpost,TRMpcblk,TRMpcpos,TRMpleft); |
|---|
| 605 | if (nord != TRMpost) fatal("cru_posting/nord"); |
|---|
| 606 | |
|---|
| 607 | while (!TRMpleft) { |
|---|
| 608 | info1=TRMifseg.ifpnxtb; |
|---|
| 609 | if (!info1) fatal("cru_posting/ifpnxtb"); |
|---|
| 610 | info2=TRMifseg.ifpnxtp; |
|---|
| 611 | inp=TRMifbuf; |
|---|
| 612 | movp=(char *)&cmpblkno; mov4(info1); |
|---|
| 613 | if (*(PUNT *)(inp) != cmpblkno) /* *(PUNT *)(inp) != info1 */ |
|---|
| 614 | cru_postread(parmtrace,trmp,info1,fd); /* v3.3 */ |
|---|
| 615 | p=inp+INFOSIZE+(info2*INFOSIZE); /* INFOSIZE = ifpblk */ |
|---|
| 616 | for (sp=(INFO *)&TRMifseg, hp=(INFO *)p, n=IFHDRINFOS; n--; ) |
|---|
| 617 | *sp++= *hp++; |
|---|
| 618 | |
|---|
| 619 | TRMpleft=TRMifseg.ifpsegp; |
|---|
| 620 | TRMpcblk=info1; |
|---|
| 621 | TRMpcpos=info2+IFHDRINFOS; |
|---|
| 622 | if (parmtrace) printf("+++cru_posting2 - post=%ld pcblk=%ld pcpos=%ld left=%ld \n",TRMpost,TRMpcblk,TRMpcpos,TRMpleft); |
|---|
| 623 | |
|---|
| 624 | cru_cruifhdr((IFPHEAD *)p); |
|---|
| 625 | } |
|---|
| 626 | |
|---|
| 627 | if (TRMpcpos >= (IFMAXTIV-1)) { |
|---|
| 628 | info1=TRMpcblk+1; info2=0; /* 22/02/89 */ |
|---|
| 629 | cru_postread(parmtrace,trmp,info1,fd); /* v3.3 */ |
|---|
| 630 | TRMpcblk=info1; |
|---|
| 631 | TRMpcpos=info2; /* 22/02/89 */ |
|---|
| 632 | if (parmtrace) printf("+++cru_posting3 - post=%ld pcblk=%ld pcpos=%ld \n",TRMpost,TRMpcblk,TRMpcpos); |
|---|
| 633 | } |
|---|
| 634 | |
|---|
| 635 | /* postpost(trmp); */ |
|---|
| 636 | TRMpleft--; |
|---|
| 637 | TRMpcpos+=IFPSTINFOS; |
|---|
| 638 | return(1); /* TRMpmfn */ |
|---|
| 639 | } |
|---|
| 640 | |
|---|
| 641 | #endif /* !LIND */ |
|---|
| 642 | |
|---|
| 643 | |
|---|
| 644 | |
|---|
| 645 | /* ------------------ xxxpcinv() and filxxxx() ----------------------------- */ |
|---|
| 646 | |
|---|
| 647 | void putpcinv(reclen) |
|---|
| 648 | UWORD reclen; |
|---|
| 649 | { |
|---|
| 650 | char *p; |
|---|
| 651 | for (p=inv_record; reclen; ) { |
|---|
| 652 | if (reclen <= inv_left) { |
|---|
| 653 | memcpy(&inv_buffer[BUFSZX-inv_left],p,(size_t)reclen); |
|---|
| 654 | inv_left-=reclen; |
|---|
| 655 | break; |
|---|
| 656 | } |
|---|
| 657 | memcpy(&inv_buffer[BUFSZX-inv_left],p,inv_left); |
|---|
| 658 | if (CIWRITE(inv_fd,inv_buffer,BUFSZX) < BUFSZX) fatal("putpcinv/write"); |
|---|
| 659 | reclen-=inv_left; |
|---|
| 660 | p+=inv_left; |
|---|
| 661 | inv_left=BUFSZX; |
|---|
| 662 | } |
|---|
| 663 | } |
|---|
| 664 | void endpcinv() |
|---|
| 665 | { |
|---|
| 666 | int n; |
|---|
| 667 | if (inv_left < BUFSZX) { |
|---|
| 668 | n=BUFSZX-inv_left; |
|---|
| 669 | if (CIWRITE(inv_fd,inv_buffer,(unsigned)n) < n) fatal("endpcinv/write"); |
|---|
| 670 | } |
|---|
| 671 | inv_left=BUFSZX; |
|---|
| 672 | if (inv_fd) { |
|---|
| 673 | CLOSE(inv_fd); |
|---|
| 674 | inv_fd=0; |
|---|
| 675 | } |
|---|
| 676 | } |
|---|
| 677 | |
|---|
| 678 | void filcreat(gidbnp,namp,extp,lrecl) |
|---|
| 679 | char *gidbnp; |
|---|
| 680 | char *namp; |
|---|
| 681 | char *extp; |
|---|
| 682 | int lrecl; |
|---|
| 683 | { |
|---|
| 684 | #if MPE |
|---|
| 685 | char dcb[80]; |
|---|
| 686 | #endif |
|---|
| 687 | strcpy(inv_filename,namp); |
|---|
| 688 | strcat(inv_filename,extp); |
|---|
| 689 | #if CIPAR |
|---|
| 690 | strcpy(inv_filename,dbxcipar(gidbnp,inv_filename,'=')); |
|---|
| 691 | #endif |
|---|
| 692 | #if MPE |
|---|
| 693 | sprintf(dcb,"b R%d",lrecl); |
|---|
| 694 | inv_fd=OPEN(inv_filename,O_WRONLY|O_CREAT|O_TRUNC|O_MPEOPTS,PERMIS,dcb); |
|---|
| 695 | #else |
|---|
| 696 | inv_fd=CREAT(inv_filename,PERMIS); |
|---|
| 697 | if (lrecl) fatal("filcreat/lrecl"); |
|---|
| 698 | #endif |
|---|
| 699 | if (inv_fd <= 0) fatal(inv_filename); |
|---|
| 700 | } |
|---|
| 701 | |
|---|
| 702 | int filopen(filename) |
|---|
| 703 | char *filename; |
|---|
| 704 | { |
|---|
| 705 | int fd; |
|---|
| 706 | fd=OPEN(filename,O_BINARY|O_RDWR); |
|---|
| 707 | if (fd <= 0) fatal(filename); |
|---|
| 708 | return(fd); |
|---|
| 709 | } |
|---|
| 710 | int filclos(fd) |
|---|
| 711 | int fd; |
|---|
| 712 | { |
|---|
| 713 | if (fd) CLOSE(fd); |
|---|
| 714 | return(0); |
|---|
| 715 | } |
|---|
| 716 | |
|---|