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