| 1 | /* mdl2i.c - NLM Medlars II Unit-Records to CDS/ISIS |
|---|
| 2 | |
|---|
| 3 | uso: mdl2i <filin> <lrecl>/<filvb0> [create=]<dbnout> [CAN/QAL] |
|---|
| 4 | [skip=[b=]n] [count=n] [tell=n] [test=1] [REPLACE] [+DP] |
|---|
| 5 | |
|---|
| 6 | <filin>: arquivo de entrada |
|---|
| 7 | |
|---|
| 8 | <lrecl>: tamanho do registro fisico de <filin> |
|---|
| 9 | <filvb0>: arquivo .vb0 |
|---|
| 10 | |
|---|
| 11 | <dbnout>: database de saida |
|---|
| 12 | |
|---|
| 13 | CAN: rec_id = CAN |
|---|
| 14 | QAL: rec_id = QAL |
|---|
| 15 | |
|---|
| 16 | [skip=n]: Para saltar n registros antes do processamento |
|---|
| 17 | ou, se skip=b=n, para saltar n bytes |
|---|
| 18 | |
|---|
| 19 | [count=n]: Para processar no maximo n registros |
|---|
| 20 | |
|---|
| 21 | [tell=n]: Para avisar a cada n registros logicos processados |
|---|
| 22 | |
|---|
| 23 | [REPLACE]: Para ler fitas Maint SOF |
|---|
| 24 | |
|---|
| 25 | [+DP]: Para gravar <filin>|anoP|dpurecs|urecs|count em mdl2i.log |
|---|
| 26 | |
|---|
| 27 | [force]: Para nao dar fatal("mdl2i/invalid MDL data"); |
|---|
| 28 | |
|---|
| 29 | Autor: ccmdl0/AOT |
|---|
| 30 | BRM, 07/06/89 |
|---|
| 31 | Alter: MYB/AOT, 16/05/91 |
|---|
| 32 | 1. Parametro REPLACE |
|---|
| 33 | AOT, 23/02/94 |
|---|
| 34 | 1. Parametro +DP |
|---|
| 35 | Alter: MMB/AOT, 15/10/99 (P-day) |
|---|
| 36 | 1. Parametro force |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | ----------------------------------------------------------- */ |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | #include <stdio.h> |
|---|
| 43 | #include <string.h> |
|---|
| 44 | |
|---|
| 45 | #include "cisis.h" /* CISIS Interface */ |
|---|
| 46 | #include "cirun.h" /* runtime area and defines by AOT */ |
|---|
| 47 | |
|---|
| 48 | #define TRACE 0 |
|---|
| 49 | #define TRACEA 0 |
|---|
| 50 | #define TRACEL 01 |
|---|
| 51 | #define TRACVB0 0 |
|---|
| 52 | #define TRACER 0 |
|---|
| 53 | |
|---|
| 54 | #if PC |
|---|
| 55 | #define MBUFSIZ 8192 |
|---|
| 56 | #else |
|---|
| 57 | #define MBUFSIZ 32768 |
|---|
| 58 | #endif |
|---|
| 59 | |
|---|
| 60 | int fx; |
|---|
| 61 | int nxleft,ixleft; |
|---|
| 62 | unsigned char buffin[MBUFSIZ]; /* readvbf/readvb0 */ |
|---|
| 63 | int lastleft = 0; |
|---|
| 64 | |
|---|
| 65 | LONGX lastbyt=0,nextbyt=0; |
|---|
| 66 | LONGX lastvbx=0; |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | typedef struct vbcntl { |
|---|
| 70 | short buflen; |
|---|
| 71 | short bufzer; |
|---|
| 72 | } VBCNTL; |
|---|
| 73 | |
|---|
| 74 | typedef struct vrcntl { |
|---|
| 75 | short reclen; |
|---|
| 76 | short reczer; |
|---|
| 77 | } VRCNTL; |
|---|
| 78 | |
|---|
| 79 | #define VBCSIZ sizeof(VBCNTL) |
|---|
| 80 | #define VRCSIZ sizeof(VRCNTL) |
|---|
| 81 | |
|---|
| 82 | VBCNTL vbp; |
|---|
| 83 | VRCNTL vrp; |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | unsigned char buffgo[MBUFSIZ]; /* readvbf/readvb0 */ |
|---|
| 87 | unsigned char *ibuf = buffgo; |
|---|
| 88 | |
|---|
| 89 | char *parmvb0 = NULL; /* readvb0 */ |
|---|
| 90 | FILE *fpvb0; |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | unsigned char buffup[MBUFSIZ]; /* fldupdat */ |
|---|
| 94 | |
|---|
| 95 | LONGX count=0; |
|---|
| 96 | LONGX urecs=0; |
|---|
| 97 | LONGX marcfirst=1; |
|---|
| 98 | LONGX marclast=0; |
|---|
| 99 | |
|---|
| 100 | typedef struct urstru { |
|---|
| 101 | unsigned char rec_id[3]; |
|---|
| 102 | unsigned char recfm; |
|---|
| 103 | unsigned char status[2]; |
|---|
| 104 | short reclen; |
|---|
| 105 | LONGX seq_no; |
|---|
| 106 | unsigned char data[1]; |
|---|
| 107 | } URECORD; |
|---|
| 108 | |
|---|
| 109 | typedef struct datdir { |
|---|
| 110 | short noc; |
|---|
| 111 | short data_ptr; |
|---|
| 112 | short len_oc[1]; |
|---|
| 113 | } DATDIR; |
|---|
| 114 | |
|---|
| 115 | typedef struct eltdir { |
|---|
| 116 | short eltype; |
|---|
| 117 | short occur_ptr; |
|---|
| 118 | } ELTDIR; |
|---|
| 119 | |
|---|
| 120 | typedef struct trailer { |
|---|
| 121 | short anoc; |
|---|
| 122 | short anel; |
|---|
| 123 | } TRAILER; |
|---|
| 124 | |
|---|
| 125 | |
|---|
| 126 | #define TRAILSIZE sizeof(TRAILER) |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | #define URIDC 0xc3 /* EBCDIC Up 'C' */ |
|---|
| 130 | #define URIDI 0xc9 /* EBCDIC Up 'I' */ |
|---|
| 131 | #define URIDT 0xe3 /* EBCDIC Up 'T' */ |
|---|
| 132 | |
|---|
| 133 | #define URIDA 0xc1 /* EBCDIC Up 'A' */ |
|---|
| 134 | #define URIDN 0xd5 /* EBCDIC Up 'N' */ |
|---|
| 135 | |
|---|
| 136 | #define URIDQ 0xd8 /* EBCDIC Up 'Q' */ |
|---|
| 137 | #define URIDL 0xd3 /* EBCDIC Up 'L' */ |
|---|
| 138 | |
|---|
| 139 | unsigned char uridc = URIDC; |
|---|
| 140 | unsigned char uridi = URIDI; |
|---|
| 141 | unsigned char uridt = URIDT; |
|---|
| 142 | int badurids = 0; |
|---|
| 143 | |
|---|
| 144 | #define URTYPE 0xe4 /* EBCDIC Up 'U' */ |
|---|
| 145 | |
|---|
| 146 | URECORD *urp; |
|---|
| 147 | DATDIR *datdirp; |
|---|
| 148 | ELTDIR *eltdirp; |
|---|
| 149 | TRAILER *trailerp; |
|---|
| 150 | |
|---|
| 151 | short anelleft; |
|---|
| 152 | short occurleft; |
|---|
| 153 | short ioc; |
|---|
| 154 | unsigned char *fldp; |
|---|
| 155 | |
|---|
| 156 | int replace; /* REPLACE switch */ |
|---|
| 157 | |
|---|
| 158 | #define REPLOFF 60 /* REPLACE offset */ |
|---|
| 159 | #define REPLTAGUI 18 /* first UI field */ |
|---|
| 160 | #define REPLTAGST 56 /* status field */ |
|---|
| 161 | |
|---|
| 162 | FILE *fout=NULL; /* arquivo a mais */ |
|---|
| 163 | FILE *fplog=NULL; /* +DP */ |
|---|
| 164 | LONGX dpurecs=0L; |
|---|
| 165 | int dpareal=0; |
|---|
| 166 | int dpxdir=EOF; |
|---|
| 167 | char dparea[BUFSIZ]; |
|---|
| 168 | |
|---|
| 169 | #define NLMTAGDP 354 /* A640 [aaaammdd: A650=650] */ |
|---|
| 170 | |
|---|
| 171 | /* prototypes */ |
|---|
| 172 | #if ANSI |
|---|
| 173 | int readmdl(char *ibuf); |
|---|
| 174 | int readxaot(char *xbuf, int xbufsize); |
|---|
| 175 | int readvb0(void); |
|---|
| 176 | #else |
|---|
| 177 | int readmdl(); |
|---|
| 178 | int readxaot(); |
|---|
| 179 | int readvb0(); |
|---|
| 180 | #endif |
|---|
| 181 | |
|---|
| 182 | void main(argc,argv) |
|---|
| 183 | |
|---|
| 184 | int argc; |
|---|
| 185 | char *argv[]; |
|---|
| 186 | |
|---|
| 187 | { |
|---|
| 188 | RECSTRU *recp; /* mandatory for defines REC RDB MF0 MFR DIR, FIELDP */ |
|---|
| 189 | |
|---|
| 190 | LONGX crec,irec,nxtmfn; |
|---|
| 191 | char *dbnp,*batchp; |
|---|
| 192 | int rc; |
|---|
| 193 | |
|---|
| 194 | int n1; |
|---|
| 195 | int ibufsize; |
|---|
| 196 | LONGX parmskip,parmskpb,parmcount,parmtell; |
|---|
| 197 | int parmtest; |
|---|
| 198 | int parmforce=0; |
|---|
| 199 | |
|---|
| 200 | unsigned char *p,*q; |
|---|
| 201 | |
|---|
| 202 | int i,n,loop; |
|---|
| 203 | |
|---|
| 204 | |
|---|
| 205 | if (argc < 4) { |
|---|
| 206 | printf("%s",cicopyr("Utility MDL/MDL2I")); |
|---|
| 207 | printf("\n"); |
|---|
| 208 | printf("mdl2i <filin> {<lrecl>/<filvb0>} [create=]<dbnout>"); |
|---|
| 209 | printf(" [CAN/QAL]\n"); |
|---|
| 210 | printf(" [skip=[b=]n] [count=n] [tell=n] [test=1] [REPLACE]"); |
|---|
| 211 | printf(" [+DP] [force]\n"); |
|---|
| 212 | exit(1); |
|---|
| 213 | } |
|---|
| 214 | |
|---|
| 215 | if ((fx=open(argv[1],O_RDONLY|O_BINARY)) == -1) fatal(argv[1]); |
|---|
| 216 | |
|---|
| 217 | if ((n=strlen(argv[2])) >= 3 && strcmp(argv[2]+n-3,"vb0") == 0) { |
|---|
| 218 | parmvb0=argv[2]; |
|---|
| 219 | if ((fpvb0=fopen(parmvb0,"r")) == NULL) fatal(parmvb0); |
|---|
| 220 | } |
|---|
| 221 | else { |
|---|
| 222 | if ((sscanf(argv[2],"%d",&ibufsize)) != 1) fatal(argv[2]); |
|---|
| 223 | if (ibufsize > MBUFSIZ) fatal(argv[2]); |
|---|
| 224 | } |
|---|
| 225 | |
|---|
| 226 | dbnp=argv[3]; |
|---|
| 227 | |
|---|
| 228 | |
|---|
| 229 | |
|---|
| 230 | parmskip=0; parmskpb=0; parmcount=999999999L; |
|---|
| 231 | parmtell=0; parmtest=0; replace=0; |
|---|
| 232 | |
|---|
| 233 | for (i=4; i<argc; i++) { |
|---|
| 234 | |
|---|
| 235 | if (!strncmp(argv[i],"skip=",5)) { |
|---|
| 236 | p=argv[i]+5; q=p; |
|---|
| 237 | if (*q == 'b' && *(q+1) == '=') { |
|---|
| 238 | if ((sscanf(q+2,"%"_LD_,&parmskpb)) != 1) fatal(argv[i]); |
|---|
| 239 | } |
|---|
| 240 | else if ((sscanf(p,"%"_LD_,&parmskip)) != 1) fatal(argv[i]); |
|---|
| 241 | if (parmskip) |
|---|
| 242 | printf("+++ skip=%"_LD_" recs de %d bytes\n",parmskip,ibufsize); |
|---|
| 243 | if (parmskpb) |
|---|
| 244 | printf("+++ skip=%"_LD_" bytes\n",parmskpb); |
|---|
| 245 | } |
|---|
| 246 | else |
|---|
| 247 | if (!strncmp(argv[i],"count=",6)) { |
|---|
| 248 | p=argv[i]+6; |
|---|
| 249 | if ((sscanf(p,"%"_LD_,&parmcount)) != 1) fatal(argv[i]); |
|---|
| 250 | printf("+++ count=%"_LD_" lrecs\n",parmcount); |
|---|
| 251 | } |
|---|
| 252 | else |
|---|
| 253 | if (!strncmp(argv[i],"tell=",5)) { |
|---|
| 254 | p=argv[i]+5; |
|---|
| 255 | if ((sscanf(p,"%"_LD_,&parmtell)) != 1) fatal(argv[i]); |
|---|
| 256 | } |
|---|
| 257 | else |
|---|
| 258 | if (!strncmp(argv[i],"test=",5)) { |
|---|
| 259 | p=argv[i]+5; |
|---|
| 260 | if ((sscanf(p,"%d",&parmtest)) != 1) fatal(argv[i]); |
|---|
| 261 | } |
|---|
| 262 | else |
|---|
| 263 | if (!strcmp(argv[i],"CAN")) { |
|---|
| 264 | uridc = URIDC; |
|---|
| 265 | uridi = URIDA; |
|---|
| 266 | uridt = URIDN; |
|---|
| 267 | printf("+++ mdl2i for CANCERLIT\n"); |
|---|
| 268 | } |
|---|
| 269 | else |
|---|
| 270 | if (!strcmp(argv[i],"QAL")) { |
|---|
| 271 | uridc = URIDQ; |
|---|
| 272 | uridi = URIDA; |
|---|
| 273 | uridt = URIDL; |
|---|
| 274 | printf("+++ mdl2i for VOCABULARY\n"); |
|---|
| 275 | } |
|---|
| 276 | else |
|---|
| 277 | if (!strcmp(argv[i],"REPLACE")) { |
|---|
| 278 | replace = 1; |
|---|
| 279 | printf("+++ mdl2i for Maint SOF\n"); |
|---|
| 280 | } |
|---|
| 281 | else |
|---|
| 282 | if (!strcmp(argv[i],"+DP")) { |
|---|
| 283 | if ((fplog=fopen("mdl2i.log","w")) == NULL) fatal("mdl2i.log"); |
|---|
| 284 | printf("+++ mdl2i.log\n"); |
|---|
| 285 | memset(dparea,'0',dpareal=4); dparea[dpareal]='\0'; |
|---|
| 286 | } |
|---|
| 287 | else |
|---|
| 288 | if (!strcmp(argv[i],"force")) { |
|---|
| 289 | parmforce=1; |
|---|
| 290 | printf("+++ mdl2i forcing bad records!!!\007\007\007\n"); |
|---|
| 291 | } |
|---|
| 292 | else |
|---|
| 293 | fatal(argv[i]); |
|---|
| 294 | } |
|---|
| 295 | |
|---|
| 296 | /* |
|---|
| 297 | processa parametros |
|---|
| 298 | */ |
|---|
| 299 | LSEEK64(fx,parmskpb+parmskip*(LONGX)ibufsize,0); |
|---|
| 300 | |
|---|
| 301 | /* |
|---|
| 302 | inicializa readmdl e faz primeira leitura |
|---|
| 303 | */ |
|---|
| 304 | nxleft=0; |
|---|
| 305 | #if 0 |
|---|
| 306 | n1=(ibufsize) ? readvbf() : readvb0(); |
|---|
| 307 | #endif |
|---|
| 308 | n1=readmdl(ibuf); |
|---|
| 309 | |
|---|
| 310 | if (n1 == EOF) fatal(argv[1]); |
|---|
| 311 | count++; |
|---|
| 312 | |
|---|
| 313 | |
|---|
| 314 | /* |
|---|
| 315 | inicializa bases de dados |
|---|
| 316 | */ |
|---|
| 317 | if (strncmp(dbnp,"create=",7) == 0) { |
|---|
| 318 | rc=recisis0((dbnp+=7)); |
|---|
| 319 | /* printf("+++ recisis0=%d\n",rc); */ |
|---|
| 320 | } |
|---|
| 321 | |
|---|
| 322 | RECORD((crec=0L),dbnp,0L); |
|---|
| 323 | nxtmfn=MF0nxtmfn; |
|---|
| 324 | RECORD((irec=crec+1),dbnp,nxtmfn); |
|---|
| 325 | |
|---|
| 326 | |
|---|
| 327 | /* |
|---|
| 328 | loop principal |
|---|
| 329 | */ |
|---|
| 330 | while (n1 != EOF && count <= parmcount) { |
|---|
| 331 | |
|---|
| 332 | #if ONLYSEERECLEN |
|---|
| 333 | printf("+++ %6"_LD_" - buflen=%d reclen=%d \n", |
|---|
| 334 | count,vbp.buflen,vrp.reclen); |
|---|
| 335 | count++; |
|---|
| 336 | n1 = readmdl(ibuf); |
|---|
| 337 | continue; |
|---|
| 338 | #endif |
|---|
| 339 | |
|---|
| 340 | |
|---|
| 341 | |
|---|
| 342 | urp = (replace) ? (URECORD *)(ibuf+REPLOFF) : (URECORD *)ibuf; |
|---|
| 343 | batchp=buffup; |
|---|
| 344 | #if BEFORE20000330 |
|---|
| 345 | #else |
|---|
| 346 | *batchp='\0'; |
|---|
| 347 | #endif |
|---|
| 348 | |
|---|
| 349 | #if TRACE |
|---|
| 350 | printf("ibuf=%p urp=%p",ibuf,urp); |
|---|
| 351 | getchar(); |
|---|
| 352 | #endif |
|---|
| 353 | |
|---|
| 354 | #if SWAPPED /* PC */ |
|---|
| 355 | p=(unsigned char *)(&urp->reclen); |
|---|
| 356 | urp->reclen=((*p)<<8)+(*(p+1)); |
|---|
| 357 | #endif |
|---|
| 358 | |
|---|
| 359 | /* if (urp->rec_id[0] != uridc || |
|---|
| 360 | urp->rec_id[1] != uridi || |
|---|
| 361 | urp->rec_id[2] != uridt || |
|---|
| 362 | */ |
|---|
| 363 | if (urp->recfm != URTYPE || TRACE) { |
|---|
| 364 | fprintf(stderr,"+++ %"_LD_"/%"_LD_" recs [#%"_LD_":%d +%"_LD_"+%d] \n", |
|---|
| 365 | urecs,count, |
|---|
| 366 | lastvbx,vbp.buflen+VBCSIZ,lastbyt,vrp.reclen+VRCSIZ); |
|---|
| 367 | printf("+++ id=%02x%02x%02x fm=%02x st=%02x%02x len=%d\n", |
|---|
| 368 | urp->rec_id[0],urp->rec_id[1],urp->rec_id[2], |
|---|
| 369 | urp->recfm, |
|---|
| 370 | urp->status[0],urp->status[1], |
|---|
| 371 | urp->reclen); |
|---|
| 372 | if (urp->recfm != URTYPE) |
|---|
| 373 | if (++badurids > 50) |
|---|
| 374 | fatal("badurids"); |
|---|
| 375 | goto NEWREC_LAB; |
|---|
| 376 | } |
|---|
| 377 | |
|---|
| 378 | badurids=0; |
|---|
| 379 | urecs++; |
|---|
| 380 | if (parmtest) { |
|---|
| 381 | sprintf(batchp, |
|---|
| 382 | "A1#%02x%02x%02x#A2#%02x#A3#%02x%02x#A4#%5d#", |
|---|
| 383 | urp->rec_id[0],urp->rec_id[1],urp->rec_id[2], |
|---|
| 384 | urp->recfm, |
|---|
| 385 | urp->status[0],urp->status[1], |
|---|
| 386 | urp->reclen); |
|---|
| 387 | batchp+=strlen(batchp); |
|---|
| 388 | } |
|---|
| 389 | |
|---|
| 390 | if (replace) { |
|---|
| 391 | sprintf(batchp, |
|---|
| 392 | "A%d#%.8s#A%d#%.2s#", |
|---|
| 393 | REPLTAGUI,ibuf, |
|---|
| 394 | REPLTAGST,urp->status); |
|---|
| 395 | batchp+=strlen(batchp); |
|---|
| 396 | } |
|---|
| 397 | |
|---|
| 398 | trailerp=(TRAILER *)(&urp->rec_id[0] + urp->reclen - TRAILSIZE); |
|---|
| 399 | |
|---|
| 400 | #if SWAPPED /* PC */ |
|---|
| 401 | p=(unsigned char *)(&trailerp->anoc); |
|---|
| 402 | trailerp->anoc=((*p)<<8)+(*(p+1)); |
|---|
| 403 | p=(unsigned char *)(&trailerp->anel); |
|---|
| 404 | trailerp->anel=((*p)<<8)+(*(p+1)); |
|---|
| 405 | #endif |
|---|
| 406 | |
|---|
| 407 | if (trailerp->anoc < trailerp->anel || TRACE) { |
|---|
| 408 | printf("*** count=%"_LD_" anoc=%d anel=%d\n", |
|---|
| 409 | count, |
|---|
| 410 | trailerp->anoc, |
|---|
| 411 | trailerp->anel); |
|---|
| 412 | if (trailerp->anoc < trailerp->anel) |
|---|
| 413 | goto NEWREC_LAB; |
|---|
| 414 | } |
|---|
| 415 | |
|---|
| 416 | |
|---|
| 417 | eltdirp=(ELTDIR *)(trailerp); eltdirp-=(anelleft=trailerp->anel); |
|---|
| 418 | |
|---|
| 419 | for (; anelleft; eltdirp++, anelleft--) { |
|---|
| 420 | |
|---|
| 421 | #if SWAPPED /* PC */ |
|---|
| 422 | p=(unsigned char *)(&eltdirp->eltype); |
|---|
| 423 | eltdirp->eltype=((*p)<<8)+(*(p+1)); |
|---|
| 424 | p=(unsigned char *)(&eltdirp->occur_ptr); |
|---|
| 425 | eltdirp->occur_ptr=((*p)<<8)+(*(p+1)); |
|---|
| 426 | #endif |
|---|
| 427 | |
|---|
| 428 | datdirp=(DATDIR *)(&urp->rec_id[0] + eltdirp->occur_ptr); |
|---|
| 429 | |
|---|
| 430 | #if SWAPPED /* PC */ |
|---|
| 431 | p=(unsigned char *)(&datdirp->noc); |
|---|
| 432 | datdirp->noc=((*p)<<8)+(*(p+1)); |
|---|
| 433 | p=(unsigned char *)(&datdirp->data_ptr); |
|---|
| 434 | datdirp->data_ptr=((*p)<<8)+(*(p+1)); |
|---|
| 435 | #endif |
|---|
| 436 | occurleft=datdirp->noc; |
|---|
| 437 | |
|---|
| 438 | |
|---|
| 439 | fldp=(unsigned char *)(&urp->rec_id[0] + datdirp->data_ptr); |
|---|
| 440 | |
|---|
| 441 | for (ioc=0; occurleft; ioc++, occurleft--) { |
|---|
| 442 | #if SWAPPED /* PC */ |
|---|
| 443 | p=(unsigned char *)(&datdirp->len_oc[ioc]); |
|---|
| 444 | datdirp->len_oc[ioc]=((*p)<<8)+(*(p+1)); |
|---|
| 445 | #endif |
|---|
| 446 | sprintf(batchp,"A%d%c",eltdirp->eltype,0x01); |
|---|
| 447 | batchp+=strlen(batchp); |
|---|
| 448 | |
|---|
| 449 | for (p=fldp, loop=datdirp->len_oc[ioc]; loop--; p++) { |
|---|
| 450 | #if TRACEA |
|---|
| 451 | putchar(*p); |
|---|
| 452 | #endif |
|---|
| 453 | if (*p < 0x40) { /* ebcdic space */ |
|---|
| 454 | printf("*** count=%"_LD_" tag=%d occ=%d chr#%d/%d=%02x\n", |
|---|
| 455 | count,eltdirp->eltype,ioc+1, |
|---|
| 456 | datdirp->len_oc[ioc], |
|---|
| 457 | datdirp->len_oc[ioc]-loop, |
|---|
| 458 | *p); |
|---|
| 459 | if (loop < 0) { |
|---|
| 460 | if (parmforce) { |
|---|
| 461 | printf("*** invalid MDL data!!!\007\007\007\n"); |
|---|
| 462 | break; |
|---|
| 463 | } |
|---|
| 464 | fatal("mdl2i/invalid MDL data"); |
|---|
| 465 | } |
|---|
| 466 | *batchp++ = 0x40; |
|---|
| 467 | } |
|---|
| 468 | else |
|---|
| 469 | *batchp++ = *p; |
|---|
| 470 | } |
|---|
| 471 | *batchp++ = 0x01; |
|---|
| 472 | #if TRACEA |
|---|
| 473 | putchar('\n'); |
|---|
| 474 | #endif |
|---|
| 475 | fldp+=datdirp->len_oc[ioc]; |
|---|
| 476 | } |
|---|
| 477 | } |
|---|
| 478 | |
|---|
| 479 | |
|---|
| 480 | #if BEFORE2000330 |
|---|
| 481 | *batchp=NULL; |
|---|
| 482 | #else |
|---|
| 483 | *batchp='\0'; |
|---|
| 484 | #endif |
|---|
| 485 | |
|---|
| 486 | MFRmfn=nxtmfn++; |
|---|
| 487 | MFRmfrl=LEADER; |
|---|
| 488 | MFRmfbwb=0; MFRmfbwp=0; |
|---|
| 489 | MFRbase=LEADER; |
|---|
| 490 | MFRnvf=0; |
|---|
| 491 | MFRstatus=ACTIVE; |
|---|
| 492 | |
|---|
| 493 | RECtype=TYPEMFR; |
|---|
| 494 | RECrc=RCNORMAL; |
|---|
| 495 | |
|---|
| 496 | p=fldupdat(irec,buffup); |
|---|
| 497 | if (p) { |
|---|
| 498 | printf("*** count=%"_LD_"\n",count); |
|---|
| 499 | printf("+++ fldupdat='%s'\n",p); |
|---|
| 500 | #if BEFORE2000330 |
|---|
| 501 | #else |
|---|
| 502 | printf("+++ buffup="); |
|---|
| 503 | for (p=buffup; *p; p++) printf("%c=%02x ",*p,*p); |
|---|
| 504 | #endif |
|---|
| 505 | fatal("fldupdat"); |
|---|
| 506 | } |
|---|
| 507 | #if TRACEL |
|---|
| 508 | printf("Leader - %"_LD_",%d,%"_LD_",%d,%d,%d,%d\n", |
|---|
| 509 | MFRmfn,MFRmfrl,MFRmfbwb,MFRmfbwp,MFRbase, |
|---|
| 510 | MFRnvf,MFRstatus); |
|---|
| 511 | #endif |
|---|
| 512 | |
|---|
| 513 | rc=recupdat(crec,irec); |
|---|
| 514 | if (rc) { |
|---|
| 515 | printf("*** count=%"_LD_"\n",count); |
|---|
| 516 | printf("+++ recupdat=%d\n",rc); |
|---|
| 517 | fatal("recupdat"); |
|---|
| 518 | } |
|---|
| 519 | |
|---|
| 520 | dpurecs++; |
|---|
| 521 | if (fplog) { |
|---|
| 522 | dpxdir=fieldx(irec,NLMTAGDP,1); |
|---|
| 523 | if (dpxdir < 0) { |
|---|
| 524 | sprintf(buffup,"A%d#0000#",NLMTAGDP); |
|---|
| 525 | if (fldupdat(irec,buffup)) fatal(buffup); |
|---|
| 526 | dpxdir=fieldx(irec,NLMTAGDP,1); |
|---|
| 527 | } |
|---|
| 528 | else { |
|---|
| 529 | for (p=FIELDP(dpxdir), loop=DIRlen(dpxdir); loop--; p++) |
|---|
| 530 | *p = (char )((int)*p - 0xF0 + (int)'0'); /* EBCDIC '0' */ |
|---|
| 531 | } |
|---|
| 532 | if (urecs == 1) { |
|---|
| 533 | dpareal=DIRlen(dpxdir); if (dpareal > 4) dpareal=4; |
|---|
| 534 | memcpy(dparea,FIELDP(dpxdir),dpareal); dparea[dpareal]='\0'; |
|---|
| 535 | } |
|---|
| 536 | } |
|---|
| 537 | |
|---|
| 538 | |
|---|
| 539 | |
|---|
| 540 | NEWREC_LAB: |
|---|
| 541 | #if 0 |
|---|
| 542 | n1 = (ibufsize) ? readvbf() : readvb0(); |
|---|
| 543 | #endif |
|---|
| 544 | n1 = readmdl(ibuf); |
|---|
| 545 | |
|---|
| 546 | if (fplog && (dpxdir >= 0 || n1 == EOF)) { |
|---|
| 547 | if (n1 == EOF) n=1; |
|---|
| 548 | else |
|---|
| 549 | if (DIRlen(dpxdir) < 4) n=1; |
|---|
| 550 | else n=memcmp(FIELDP(dpxdir),dparea,4); |
|---|
| 551 | if (n) { |
|---|
| 552 | #if 0 |
|---|
| 553 | fprintf(fplog,"%s|",argv[1]); |
|---|
| 554 | fprintf(fplog,"%s|",argv[3]+7); |
|---|
| 555 | #else |
|---|
| 556 | fprintf(fplog,"%s|",dbnp); |
|---|
| 557 | #endif |
|---|
| 558 | for (p=dparea, loop=dpareal; loop--; p++) |
|---|
| 559 | fprintf(fplog,"%c",*p); |
|---|
| 560 | marclast=count - 1; |
|---|
| 561 | if (n1 == EOF) marclast++; |
|---|
| 562 | fprintf(fplog,"|%"_LD_"|ur=%"_LD_"|lr=%"_LD_"\n",dpurecs,marcfirst,marclast); |
|---|
| 563 | dpareal=DIRlen(dpxdir); if (dpareal > 4) dpareal=4; |
|---|
| 564 | memcpy(dparea,FIELDP(dpxdir),dpareal); dparea[dpareal]='\0'; |
|---|
| 565 | dpurecs=0L; |
|---|
| 566 | marcfirst=marclast + 1; |
|---|
| 567 | |
|---|
| 568 | |
|---|
| 569 | } |
|---|
| 570 | } |
|---|
| 571 | dpxdir=EOF; |
|---|
| 572 | |
|---|
| 573 | if (n1 > 0) { |
|---|
| 574 | count++; |
|---|
| 575 | if (parmtell) |
|---|
| 576 | if (!(count % parmtell)) |
|---|
| 577 | fprintf(stderr,"+++ %"_LD_"/%"_LD_" recs [#%"_LD_":%d +%"_LD_"+%d] \n", |
|---|
| 578 | urecs,count, |
|---|
| 579 | lastvbx,vbp.buflen+VBCSIZ,lastbyt,vrp.reclen+VRCSIZ); |
|---|
| 580 | } |
|---|
| 581 | |
|---|
| 582 | } |
|---|
| 583 | |
|---|
| 584 | if (count > parmcount) |
|---|
| 585 | count--; |
|---|
| 586 | |
|---|
| 587 | |
|---|
| 588 | printf("mdl2i: %"_LD_" unit records \n",urecs); |
|---|
| 589 | printf(" %"_LD_" logical records\n",count); |
|---|
| 590 | |
|---|
| 591 | exit(0); |
|---|
| 592 | } |
|---|
| 593 | |
|---|
| 594 | |
|---|
| 595 | int readvb0() /* |
|---|
| 596 | --- --------- */ |
|---|
| 597 | |
|---|
| 598 | { |
|---|
| 599 | int i,n1; |
|---|
| 600 | |
|---|
| 601 | off_t vboffset; |
|---|
| 602 | int vblength; |
|---|
| 603 | |
|---|
| 604 | |
|---|
| 605 | #if PC |
|---|
| 606 | i=fscanf(fpvb0,"%"_LD_"|%d" ,&vboffset,&vblength); |
|---|
| 607 | #else |
|---|
| 608 | i=fscanf(fpvb0,"%"_LD_"|%d\n",&vboffset,&vblength); |
|---|
| 609 | #endif |
|---|
| 610 | |
|---|
| 611 | if (i != 2) |
|---|
| 612 | return(EOF); |
|---|
| 613 | |
|---|
| 614 | #if TRACVB0 |
|---|
| 615 | printf("vb0: offset=%"_LD_" length=%d\n",vboffset,vblength); |
|---|
| 616 | #endif |
|---|
| 617 | |
|---|
| 618 | if (vblength > MBUFSIZ) { |
|---|
| 619 | fprintf(stderr,"count: %"_LD_"\n",count); |
|---|
| 620 | fprintf(stderr,"vblength: %d\n",vblength); |
|---|
| 621 | fprintf(stderr,"MBUFSIZ: %d\n",MBUFSIZ); |
|---|
| 622 | fatal("readvb0/MBUFSIZ"); |
|---|
| 623 | } |
|---|
| 624 | |
|---|
| 625 | LSEEK64(fx,vboffset,SEEK_SET); |
|---|
| 626 | n1=read(fx,buffin,vblength); |
|---|
| 627 | |
|---|
| 628 | if (n1 == 0) |
|---|
| 629 | return(EOF); |
|---|
| 630 | |
|---|
| 631 | if (n1 != vblength) { |
|---|
| 632 | fprintf(stderr,"count: %"_LD_"\n",count); |
|---|
| 633 | fprintf(stderr,"n1: %d\n",n1); |
|---|
| 634 | fprintf(stderr,"vblength: %d\n",vblength); |
|---|
| 635 | fatal("readvb0/vblength"); |
|---|
| 636 | } |
|---|
| 637 | |
|---|
| 638 | return(n1); |
|---|
| 639 | } |
|---|
| 640 | |
|---|
| 641 | |
|---|
| 642 | |
|---|
| 643 | int readmdl(ibuf) |
|---|
| 644 | char *ibuf; |
|---|
| 645 | { |
|---|
| 646 | int n1; |
|---|
| 647 | #if SWAPPED /* PC */ |
|---|
| 648 | unsigned char *p; |
|---|
| 649 | #endif |
|---|
| 650 | #if TRACER |
|---|
| 651 | printf("+++ readmdl \n"); |
|---|
| 652 | #endif |
|---|
| 653 | |
|---|
| 654 | if (lastvbx) lastbyt=nextbyt; |
|---|
| 655 | |
|---|
| 656 | if (!lastleft) { |
|---|
| 657 | n1=readxaot((char *)&vbp,VBCSIZ); |
|---|
| 658 | if (n1 == EOF) return(n1); |
|---|
| 659 | if (n1 < VBCSIZ) { |
|---|
| 660 | fprintf(stderr,"count: %"_LD_"\n",count); |
|---|
| 661 | fprintf(stderr,"n1: %d\n",n1); |
|---|
| 662 | fprintf(stderr,"lastc: %"_LD_"\n",lastvbx); |
|---|
| 663 | fprintf(stderr,"lastb: %"_LD_"\n",lastbyt); |
|---|
| 664 | fatal("readmdl/read/block length"); |
|---|
| 665 | } |
|---|
| 666 | |
|---|
| 667 | #if SWAPPED /* PC */ |
|---|
| 668 | p=(unsigned char *)(&vbp.buflen); |
|---|
| 669 | vbp.buflen=((*p)<<8)+(*(p+1)); |
|---|
| 670 | #endif |
|---|
| 671 | vbp.buflen-=VBCSIZ; |
|---|
| 672 | lastleft=vbp.buflen; |
|---|
| 673 | #if TRACER |
|---|
| 674 | printf("+++ readmdl - buflen/lastleft=%d/%d \n",vbp.buflen,lastleft); |
|---|
| 675 | #endif |
|---|
| 676 | lastvbx++; |
|---|
| 677 | if (vbp.buflen < VBCSIZ || vbp.buflen > MBUFSIZ) { |
|---|
| 678 | fprintf(stderr,"count: %"_LD_"\n",count); |
|---|
| 679 | fprintf(stderr,"buflen: %d\n",vbp.buflen); |
|---|
| 680 | fprintf(stderr,"lastc: %"_LD_"\n",lastvbx); |
|---|
| 681 | fprintf(stderr,"lastb: %"_LD_"\n",lastbyt); |
|---|
| 682 | fatal("readmdl/block length"); |
|---|
| 683 | } |
|---|
| 684 | } |
|---|
| 685 | |
|---|
| 686 | n1=readxaot((char *)&vrp,VRCSIZ); |
|---|
| 687 | if (n1 < VRCSIZ) { |
|---|
| 688 | fprintf(stderr,"count: %"_LD_"\n",count); |
|---|
| 689 | fprintf(stderr,"n1: %d\n",n1); |
|---|
| 690 | fprintf(stderr,"lastc: %"_LD_"\n",lastvbx); |
|---|
| 691 | fprintf(stderr,"lastb: %"_LD_"\n",lastbyt); |
|---|
| 692 | fatal("readmdl/read/record length"); |
|---|
| 693 | } |
|---|
| 694 | |
|---|
| 695 | #if SWAPPED /* PC */ |
|---|
| 696 | p=(unsigned char *)(&vrp.reclen); |
|---|
| 697 | vrp.reclen=((*p)<<8)+(*(p+1)); |
|---|
| 698 | #endif |
|---|
| 699 | if (vrp.reclen < VRCSIZ || vrp.reclen > MBUFSIZ) { |
|---|
| 700 | fprintf(stderr,"count: %"_LD_"\n",count); |
|---|
| 701 | fprintf(stderr,"reclen: %d\n",vrp.reclen); |
|---|
| 702 | fprintf(stderr,"lastc: %"_LD_"\n",lastvbx); |
|---|
| 703 | fprintf(stderr,"lastb: %"_LD_"\n",lastbyt); |
|---|
| 704 | fatal("readmdl/record length"); |
|---|
| 705 | } |
|---|
| 706 | lastleft-=VRCSIZ; |
|---|
| 707 | |
|---|
| 708 | vrp.reclen-=VRCSIZ; |
|---|
| 709 | n1=readxaot(ibuf,vrp.reclen); |
|---|
| 710 | if (n1 < vrp.reclen) { |
|---|
| 711 | fprintf(stderr,"count: %"_LD_"\n",count); |
|---|
| 712 | fprintf(stderr,"reclen: %d\n",vrp.reclen); |
|---|
| 713 | fatal("readmdl/read/record"); |
|---|
| 714 | } |
|---|
| 715 | lastleft-=vrp.reclen; |
|---|
| 716 | |
|---|
| 717 | #if TRACER |
|---|
| 718 | printf("+++ readmdl - buflen/lastleft=%d/%d reclen=%d \n", |
|---|
| 719 | vbp.buflen,lastleft,vrp.reclen); |
|---|
| 720 | #endif |
|---|
| 721 | |
|---|
| 722 | if (lastleft < 0) fatal("readmdl/lastleft"); |
|---|
| 723 | |
|---|
| 724 | n1=vrp.reclen; |
|---|
| 725 | |
|---|
| 726 | nextbyt=vbp.buflen+VBCSIZ-lastleft; |
|---|
| 727 | |
|---|
| 728 | return(n1); |
|---|
| 729 | } |
|---|
| 730 | |
|---|
| 731 | |
|---|
| 732 | int readxaot(xbuf,xbufsize) |
|---|
| 733 | char *xbuf; |
|---|
| 734 | int xbufsize; |
|---|
| 735 | { |
|---|
| 736 | int nx,n; |
|---|
| 737 | |
|---|
| 738 | if (nxleft >= xbufsize) { |
|---|
| 739 | nx=xbufsize; |
|---|
| 740 | memcpy(xbuf,&buffin[ixleft],xbufsize); |
|---|
| 741 | nxleft-=xbufsize; |
|---|
| 742 | ixleft+=xbufsize; |
|---|
| 743 | } |
|---|
| 744 | else { |
|---|
| 745 | nx=nxleft; |
|---|
| 746 | memcpy(xbuf,&buffin[ixleft],nx); |
|---|
| 747 | nxleft=read(fx,buffin,MBUFSIZ); |
|---|
| 748 | ixleft=0; |
|---|
| 749 | if (nx+nxleft) { |
|---|
| 750 | n=xbufsize-nx; |
|---|
| 751 | if (nxleft < n) { |
|---|
| 752 | fprintf(stderr,"count: %"_LD_"\n",count); |
|---|
| 753 | fprintf(stderr,"xbufsize: %d\n",xbufsize); |
|---|
| 754 | fprintf(stderr,"nx: %d\n",nx); |
|---|
| 755 | fatal("readxaot/more bytes expected"); |
|---|
| 756 | } |
|---|
| 757 | memcpy(&xbuf[nx],buffin,n); |
|---|
| 758 | nx+=n; |
|---|
| 759 | nxleft-=n; |
|---|
| 760 | ixleft+=n; |
|---|
| 761 | } |
|---|
| 762 | else { |
|---|
| 763 | memset(xbuf,0xff,xbufsize); |
|---|
| 764 | nx=EOF; |
|---|
| 765 | } |
|---|
| 766 | } |
|---|
| 767 | |
|---|
| 768 | return(nx); |
|---|
| 769 | } |
|---|