| 1 | #include <string.h> |
|---|
| 2 | #if !CICPP |
|---|
| 3 | #include <stdio.h> |
|---|
| 4 | #include <string.h> |
|---|
| 5 | #include <ctype.h> |
|---|
| 6 | |
|---|
| 7 | #include "cisis.h" |
|---|
| 8 | |
|---|
| 9 | #endif /* CICPP */ |
|---|
| 10 | |
|---|
| 11 | /* ----------------------------- giz.c ------------------------------ */ |
|---|
| 12 | |
|---|
| 13 | #if RECGIZM |
|---|
| 14 | |
|---|
| 15 | #define TRACER0 00 |
|---|
| 16 | #define TRACEG1 00 |
|---|
| 17 | #define TRACEG2 00 |
|---|
| 18 | #define TRACEG3 00 |
|---|
| 19 | #define TRACEGT 00 |
|---|
| 20 | #if TRACEGT |
|---|
| 21 | #define GETCHAR printf("\n"); |
|---|
| 22 | #else |
|---|
| 23 | #define GETCHAR getchar() |
|---|
| 24 | #endif |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | /* procedures */ |
|---|
| 28 | |
|---|
| 29 | #if CICPP |
|---|
| 30 | GIZMSTRU *gizmalloc(int n) |
|---|
| 31 | #else /* CICPP */ |
|---|
| 32 | GIZMSTRU *gizmalloc(n) /* |
|---|
| 33 | ------------------- */ |
|---|
| 34 | int n; |
|---|
| 35 | #endif /* CICPP */ |
|---|
| 36 | { |
|---|
| 37 | GIZMSTRU *gizmp; |
|---|
| 38 | |
|---|
| 39 | #if CICPP |
|---|
| 40 | try { gizmp = (GIZMSTRU *)new char [n]; } |
|---|
| 41 | catch (BAD_ALLOC) |
|---|
| 42 | { gizmp = (GIZMSTRU *)ALLONULL; } |
|---|
| 43 | #else /* CICPP */ |
|---|
| 44 | gizmp=(GIZMSTRU *)ALLOC((ALLOPARM)n); |
|---|
| 45 | #endif /* CICPP */ |
|---|
| 46 | |
|---|
| 47 | if (gizmp == (GIZMSTRU *)ALLONULL) |
|---|
| 48 | #if CICPP |
|---|
| 49 | (new CISISX())->xfatal("gizmalloc/ALLOC/GIZMSTRU"); |
|---|
| 50 | #else |
|---|
| 51 | fatal("gizmalloc/ALLOC/GIZMSTRU"); |
|---|
| 52 | #endif |
|---|
| 53 | |
|---|
| 54 | memset((unsigned char *)gizmp,'\0',(int)n); |
|---|
| 55 | |
|---|
| 56 | return(gizmp); |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | #if CICPP |
|---|
| 61 | unsigned char *pattalloc(int n) |
|---|
| 62 | #else /* CICPP */ |
|---|
| 63 | unsigned char *pattalloc(n) /* |
|---|
| 64 | ------------------------ */ |
|---|
| 65 | int n; |
|---|
| 66 | #endif /* CICPP */ |
|---|
| 67 | { |
|---|
| 68 | unsigned char *p; |
|---|
| 69 | |
|---|
| 70 | if (n) { |
|---|
| 71 | #if CICPP |
|---|
| 72 | try { p = new unsigned char [n]; } |
|---|
| 73 | catch (BAD_ALLOC) |
|---|
| 74 | { p = (unsigned char *)ALLONULL; } |
|---|
| 75 | #else /* CICPP */ |
|---|
| 76 | p=(unsigned char *)ALLOC((ALLOPARM)n); |
|---|
| 77 | #endif /* CICPP */ |
|---|
| 78 | |
|---|
| 79 | if (p == (unsigned char *)ALLONULL) |
|---|
| 80 | #if CICPP |
|---|
| 81 | (new CISISX())->xfatal("pattalloc/ALLOC/patt"); |
|---|
| 82 | #else |
|---|
| 83 | fatal("pattalloc/ALLOC/patt"); |
|---|
| 84 | #endif |
|---|
| 85 | } |
|---|
| 86 | else p=NULL; |
|---|
| 87 | |
|---|
| 88 | return(p); |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | |
|---|
| 94 | #if CICPP |
|---|
| 95 | #define CORELEFT() 0 |
|---|
| 96 | #endif /* CICPP */ |
|---|
| 97 | |
|---|
| 98 | #if CICPP |
|---|
| 99 | int gizmread(CISISX * cisisxp, |
|---|
| 100 | char *gizdbnp, |
|---|
| 101 | VGIZPSTRU **vgizmpp) |
|---|
| 102 | #else /* CICPP */ |
|---|
| 103 | int gizmread(gizdbnp, vgizmpp, irec) /* |
|---|
| 104 | ------------ */ |
|---|
| 105 | |
|---|
| 106 | char *gizdbnp; |
|---|
| 107 | VGIZPSTRU **vgizmpp; |
|---|
| 108 | LONGX irec; |
|---|
| 109 | #endif /* CICPP */ |
|---|
| 110 | |
|---|
| 111 | { |
|---|
| 112 | |
|---|
| 113 | unsigned char gfld11[4]; |
|---|
| 114 | unsigned char gfld21[4]; |
|---|
| 115 | |
|---|
| 116 | #if BEFORECD |
|---|
| 117 | LONGX irec; |
|---|
| 118 | #endif |
|---|
| 119 | |
|---|
| 120 | RECSTRU *recp; |
|---|
| 121 | |
|---|
| 122 | #if CICPP |
|---|
| 123 | LONGX irec=-1; |
|---|
| 124 | recp=new RECSTRU(cisisxp); |
|---|
| 125 | #endif /* CICPP */ |
|---|
| 126 | |
|---|
| 127 | VGIZPSTRU *vgizmap; |
|---|
| 128 | GIZMSTRU *gizmhp,*gizmp,*gizmbp,*gizmnp; |
|---|
| 129 | |
|---|
| 130 | short igiz,fld1len,fld2len; |
|---|
| 131 | unsigned char *fld1p,*fld2p,*p,*p2; |
|---|
| 132 | |
|---|
| 133 | int xdir,n,i; |
|---|
| 134 | LONGX nbytes,mfn,ubytes; |
|---|
| 135 | |
|---|
| 136 | unsigned char *q,*cq,c; |
|---|
| 137 | VGIZPSTRU *gmap; |
|---|
| 138 | LONGX xtag1,xtag2; |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | if (rectrace) { |
|---|
| 142 | printf("gizmread - %s=%p [%"_LD_"]\n",gizdbnp,vgizmpp,irec); |
|---|
| 143 | ubytes=CORELEFT(); |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | /* |
|---|
| 147 | aloca e inicializa gizmo |
|---|
| 148 | */ |
|---|
| 149 | nbytes=sizeof(VGIZPSTRU); |
|---|
| 150 | |
|---|
| 151 | #if CICPP |
|---|
| 152 | try { vgizmap = (VGIZPSTRU *) new char[nbytes]; } |
|---|
| 153 | catch (BAD_ALLOC) |
|---|
| 154 | { vgizmap = (VGIZPSTRU *)ALLONULL; } |
|---|
| 155 | #else /* CICPP */ |
|---|
| 156 | vgizmap=(VGIZPSTRU *)ALLOC((ALLOPARM)nbytes); |
|---|
| 157 | #endif /* CICPP */ |
|---|
| 158 | if (vgizmap == (VGIZPSTRU *)ALLONULL) |
|---|
| 159 | fatal("gizmread/ALLOC"); |
|---|
| 160 | memset(vgizmap,0x00,(unsigned)nbytes); |
|---|
| 161 | *vgizmpp=vgizmap; |
|---|
| 162 | for (igiz=0; igiz < 256; igiz++) { |
|---|
| 163 | vgizmap->ghdrp[igiz] = NULL; |
|---|
| 164 | } |
|---|
| 165 | vgizmap->grngs=0; |
|---|
| 166 | vgizmap->gdbnp=pattalloc((n=strlen(gizdbnp))+1); |
|---|
| 167 | memcpy(vgizmap->gdbnp,gizdbnp,n); vgizmap->gdbnp[n]='\0'; |
|---|
| 168 | |
|---|
| 169 | if (rectrace) |
|---|
| 170 | printf("gizmread - %s=%p=%p \n",gizdbnp,*vgizmpp,&vgizmap->nextp); |
|---|
| 171 | |
|---|
| 172 | #if BEFORECD |
|---|
| 173 | /* alocate working record */ |
|---|
| 174 | for (irec=maxnrec-1; irec--; ) { |
|---|
| 175 | if (!vrecp[irec]) |
|---|
| 176 | break; |
|---|
| 177 | } |
|---|
| 178 | if (irec == 0) |
|---|
| 179 | fatal("gizmread/irec"); |
|---|
| 180 | recallok(irec,MAXMFRL); |
|---|
| 181 | #endif |
|---|
| 182 | |
|---|
| 183 | /* setup tag list */ |
|---|
| 184 | if ((cq=(unsigned char *)strchr(gizdbnp+1,c=',')) == NULL) { |
|---|
| 185 | c='\0'; q=(unsigned char *)""; /* no tag list */ |
|---|
| 186 | } |
|---|
| 187 | else { |
|---|
| 188 | *cq='\0'; q=cq+1; /* ends dbn and point to tag list */ |
|---|
| 189 | } |
|---|
| 190 | gmap=vgizmap; |
|---|
| 191 | |
|---|
| 192 | |
|---|
| 193 | /* carrega conteudo, segundo o primeiro char, e ordenado por tamanho */ |
|---|
| 194 | |
|---|
| 195 | #if CICPP |
|---|
| 196 | for (mfn=1L; ; mfn++) { |
|---|
| 197 | recp->xrecord(gizdbnp,mfn); |
|---|
| 198 | if (RECrc == RCEOF) break; |
|---|
| 199 | #else /* CICPP */ |
|---|
| 200 | for (mfn=1L; (RECORD(irec,gizdbnp,mfn))->recrc != RCEOF; mfn++) { |
|---|
| 201 | #endif /* CICPP */ |
|---|
| 202 | |
|---|
| 203 | if (RECrc != RCNORMAL) |
|---|
| 204 | continue; |
|---|
| 205 | if (MFRnvf == 0) |
|---|
| 206 | continue; |
|---|
| 207 | |
|---|
| 208 | #if CICPP |
|---|
| 209 | if ((n=recp->xnocc(GIZMTAG11)) > 0) { |
|---|
| 210 | #else /* CICPP */ |
|---|
| 211 | if ((n=nocc(irec,GIZMTAG11)) > 0) { |
|---|
| 212 | #endif /* CICPP */ |
|---|
| 213 | if (n != 1) { |
|---|
| 214 | if (rectrace) fprintf(stderr,"mfn=%"_LD_"\n",mfn); |
|---|
| 215 | fatal("gizmread/GIZMTAG11/nocc"); |
|---|
| 216 | } |
|---|
| 217 | #if CICPP |
|---|
| 218 | xdir=recp->xfieldx(GIZMTAG11,1); |
|---|
| 219 | #else /* CICPP */ |
|---|
| 220 | xdir=fieldx(irec,GIZMTAG11,1); |
|---|
| 221 | #endif /* CICPP */ |
|---|
| 222 | if (DIRlen(xdir) > 3) { |
|---|
| 223 | if (rectrace) fprintf(stderr,"mfn=%"_LD_"\n",mfn); |
|---|
| 224 | fatal("gizmread/GIZMTAG11/3"); |
|---|
| 225 | } |
|---|
| 226 | |
|---|
| 227 | |
|---|
| 228 | strncpy((char *)gfld11,FIELDP(xdir),DIRlen(xdir)); |
|---|
| 229 | gfld11[DIRlen(xdir)]='\0'; |
|---|
| 230 | if (strcmp((CONST char *)gfld11,"hex") != 0 && strcmp((CONST char *)gfld11,"asc") != 0) { |
|---|
| 231 | if (rectrace) fprintf(stderr,"mfn=%"_LD_"\n",mfn); |
|---|
| 232 | fatal("gizmread/GIZMTAG11/xxx"); |
|---|
| 233 | } |
|---|
| 234 | } |
|---|
| 235 | else |
|---|
| 236 | *gfld11='\0'; |
|---|
| 237 | |
|---|
| 238 | #if CICPP |
|---|
| 239 | if ((n=recp->xnocc(GIZMTAG21)) > 0) { |
|---|
| 240 | #else /* CICPP */ |
|---|
| 241 | if ((n=nocc(irec,GIZMTAG21)) > 0) { |
|---|
| 242 | #endif /* CICPP */ |
|---|
| 243 | if (n != 1) { |
|---|
| 244 | if (rectrace) fprintf(stderr,"mfn=%"_LD_"\n",mfn); |
|---|
| 245 | fatal("gizmread/GIZMTAG21/nocc"); |
|---|
| 246 | } |
|---|
| 247 | #if CICPP |
|---|
| 248 | xdir=recp->xfieldx(GIZMTAG21,1); |
|---|
| 249 | #else /* CICPP */ |
|---|
| 250 | xdir=fieldx(irec,GIZMTAG21,1); |
|---|
| 251 | #endif /* CICPP */ |
|---|
| 252 | if (DIRlen(xdir) > 3) { |
|---|
| 253 | if (rectrace) fprintf(stderr,"mfn=%"_LD_"\n",mfn); |
|---|
| 254 | fatal("gizmread/GIZMTAG21/3"); |
|---|
| 255 | } |
|---|
| 256 | |
|---|
| 257 | strncpy((char *)gfld21,FIELDP(xdir),DIRlen(xdir)); |
|---|
| 258 | gfld21[DIRlen(xdir)]='\0'; |
|---|
| 259 | if (strcmp((CONST char *)gfld21,"hex") != 0 && strcmp((CONST char *)gfld21,"asc") != 0) { |
|---|
| 260 | if (rectrace) fprintf(stderr,"mfn=%"_LD_"\n",mfn); |
|---|
| 261 | fatal("gizmread/GIZMTAG21/xxx"); |
|---|
| 262 | } |
|---|
| 263 | } |
|---|
| 264 | else |
|---|
| 265 | *gfld21='\0'; |
|---|
| 266 | |
|---|
| 267 | #if CICPP |
|---|
| 268 | if (recp->xnocc(GIZMTAG1) != 1) { |
|---|
| 269 | #else /* CICPP */ |
|---|
| 270 | if (nocc(irec,GIZMTAG1) != 1) { |
|---|
| 271 | #endif /* CICPP */ |
|---|
| 272 | if (rectrace) fprintf(stderr,"mfn=%"_LD_"\n",mfn); |
|---|
| 273 | fatal("gizmread/GIZMTAG1/nocc"); |
|---|
| 274 | } |
|---|
| 275 | #if CICPP |
|---|
| 276 | xdir=recp->xfieldx(GIZMTAG1,1); |
|---|
| 277 | #else /* CICPP */ |
|---|
| 278 | xdir=fieldx(irec,GIZMTAG1,1); |
|---|
| 279 | #endif /* CICPP */ |
|---|
| 280 | |
|---|
| 281 | switch (*gfld11) { |
|---|
| 282 | case '\0': |
|---|
| 283 | if ((fld1len=DIRlen(xdir)) < 1) { |
|---|
| 284 | if (rectrace) fprintf(stderr,"mfn=%"_LD_"\n",mfn); |
|---|
| 285 | fatal("gizmread/GIZMTAG1/len"); |
|---|
| 286 | } |
|---|
| 287 | fld1p=(unsigned char *)FIELDP(xdir); |
|---|
| 288 | break; |
|---|
| 289 | case 'h': |
|---|
| 290 | if ((fld1len=DIRlen(xdir)) < 2 || fld1len & 0x01) { |
|---|
| 291 | if (rectrace) fprintf(stderr,"mfn=%"_LD_"\n",mfn); |
|---|
| 292 | fatal("gizmread/GIZMTAG1/hexlen"); |
|---|
| 293 | } |
|---|
| 294 | fld1p=(unsigned char *)FIELDP(xdir); |
|---|
| 295 | for (p=fld1p, p2=p, n=fld1len; n; n-=2, p2+=2) { |
|---|
| 296 | if (sscanf((CONST char *)p2,"%2x",&i) != 1) { |
|---|
| 297 | if (rectrace) fprintf(stderr,"mfn=%"_LD_"\n",mfn); |
|---|
| 298 | fatal("gizmread/GIZMTAG1/hex"); |
|---|
| 299 | } |
|---|
| 300 | *p++ = i; |
|---|
| 301 | } |
|---|
| 302 | fld1len/=2; |
|---|
| 303 | break; |
|---|
| 304 | case 'a': |
|---|
| 305 | if ((fld1len=DIRlen(xdir)) < 3 || (fld1len/3*3 != fld1len)) { |
|---|
| 306 | if (rectrace) fprintf(stderr,"mfn=%"_LD_"\n",mfn); |
|---|
| 307 | fatal("gizmread/GIZMTAG1/asclen"); |
|---|
| 308 | } |
|---|
| 309 | fld1p=(unsigned char *)FIELDP(xdir); |
|---|
| 310 | for (p=fld1p, p2=p, n=fld1len; n; n-=3, p2+=3) { |
|---|
| 311 | if (sscanf((CONST char *)p2,"%3d",&i) != 1) { |
|---|
| 312 | if (rectrace) fprintf(stderr,"mfn=%"_LD_"\n",mfn); |
|---|
| 313 | fatal("gizmread/GIZMTAG1/asc"); |
|---|
| 314 | } |
|---|
| 315 | *p++ = i; |
|---|
| 316 | } |
|---|
| 317 | fld1len/=3; |
|---|
| 318 | break; |
|---|
| 319 | default: fatal("gizmread/GIZMTAG1/switch"); |
|---|
| 320 | } |
|---|
| 321 | |
|---|
| 322 | fld2p=NULL; fld2len=0; |
|---|
| 323 | |
|---|
| 324 | #if CICPP |
|---|
| 325 | if ((n=recp->xnocc(GIZMTAG2)) != 1) |
|---|
| 326 | #else /* CICPP */ |
|---|
| 327 | if ((n=nocc(irec,GIZMTAG2)) != 1) |
|---|
| 328 | #endif /* CICPP */ |
|---|
| 329 | if (n) { |
|---|
| 330 | if (rectrace) fprintf(stderr,"mfn=%"_LD_"\n",mfn); |
|---|
| 331 | fatal("gizmread/GIZMTAG2/nocc"); |
|---|
| 332 | } |
|---|
| 333 | if (n > 0) { |
|---|
| 334 | #if CICPP |
|---|
| 335 | xdir=recp->xfieldx(GIZMTAG2,1); |
|---|
| 336 | #else /* CICPP */ |
|---|
| 337 | xdir=fieldx(irec,GIZMTAG2,1); |
|---|
| 338 | #endif /* CICPP */ |
|---|
| 339 | |
|---|
| 340 | switch (*gfld21) { |
|---|
| 341 | case '\0': |
|---|
| 342 | if ((fld2len=DIRlen(xdir)) < 1) { |
|---|
| 343 | if (rectrace) fprintf(stderr,"mfn=%"_LD_"\n",mfn); |
|---|
| 344 | fatal("gizmread/GIZMTAG2/len"); |
|---|
| 345 | } |
|---|
| 346 | fld2p=(unsigned char *)FIELDP(xdir); |
|---|
| 347 | break; |
|---|
| 348 | case 'h': |
|---|
| 349 | if ((fld2len=DIRlen(xdir)) < 2 || fld2len & 0x01) { |
|---|
| 350 | if (rectrace) fprintf(stderr,"mfn=%"_LD_"\n",mfn); |
|---|
| 351 | fatal("gizmread/GIZMTAG2/hexlen"); |
|---|
| 352 | } |
|---|
| 353 | fld2p=(unsigned char *)FIELDP(xdir); |
|---|
| 354 | for (p=fld2p, p2=p, n=fld2len; n; n-=2, p2+=2) { |
|---|
| 355 | if (sscanf((CONST char *)p2,"%2x",&i) != 1) { |
|---|
| 356 | if (rectrace) fprintf(stderr,"mfn=%"_LD_"\n",mfn); |
|---|
| 357 | fatal("gizmread/GIZMTAG2/hex"); |
|---|
| 358 | } |
|---|
| 359 | *p++ = i; |
|---|
| 360 | } |
|---|
| 361 | fld2len/=2; |
|---|
| 362 | break; |
|---|
| 363 | case 'a': |
|---|
| 364 | if ((fld2len=DIRlen(xdir)) < 3 || (fld2len/3*3 != fld2len)) { |
|---|
| 365 | if (rectrace) fprintf(stderr,"mfn=%"_LD_"\n",mfn); |
|---|
| 366 | fatal("gizmread/GIZMTAG2/asclen"); |
|---|
| 367 | } |
|---|
| 368 | fld2p=(unsigned char *)FIELDP(xdir); |
|---|
| 369 | for (p=fld2p, p2=p, n=fld2len; n; n-=3, p2+=3) { |
|---|
| 370 | if (sscanf((CONST char *)p2,"%3d",&i) != 1) { |
|---|
| 371 | if (rectrace) fprintf(stderr,"mfn=%"_LD_"\n",mfn); |
|---|
| 372 | fatal("gizmread/GIZMTAG2/asc"); |
|---|
| 373 | } |
|---|
| 374 | *p++ = i; |
|---|
| 375 | } |
|---|
| 376 | fld2len/=3; |
|---|
| 377 | break; |
|---|
| 378 | default: fatal("gizmread/GIZMTAG2/switch"); |
|---|
| 379 | } |
|---|
| 380 | } |
|---|
| 381 | |
|---|
| 382 | gizmhp=vgizmap->ghdrp[*fld1p]; gizmnp=gizmhp; |
|---|
| 383 | |
|---|
| 384 | for (gizmbp=NULL; gizmnp; gizmbp=gizmnp, gizmnp=gizmnp->nextp) |
|---|
| 385 | if (fld1len > gizmnp->isize) |
|---|
| 386 | break; |
|---|
| 387 | |
|---|
| 388 | gizmp=gizmalloc(sizeof(GIZMSTRU)); |
|---|
| 389 | gizmp->isize=fld1len; |
|---|
| 390 | gizmp->osize=fld2len; |
|---|
| 391 | gizmp->ipatt=pattalloc(fld1len); memcpy(gizmp->ipatt,fld1p,fld1len); |
|---|
| 392 | gizmp->opatt=pattalloc(fld2len); memcpy(gizmp->opatt,fld2p,fld2len); |
|---|
| 393 | gizmp->nextp=gizmnp; |
|---|
| 394 | |
|---|
| 395 | if (gizmbp) |
|---|
| 396 | gizmbp->nextp=gizmp; |
|---|
| 397 | else |
|---|
| 398 | vgizmap->ghdrp[*fld1p]=gizmp; |
|---|
| 399 | } |
|---|
| 400 | |
|---|
| 401 | |
|---|
| 402 | #if TRACER0 |
|---|
| 403 | for (i=0; i<=255; i++) { |
|---|
| 404 | gizmhp=vgizmap->ghdrp[i]; |
|---|
| 405 | if (!gizmhp) |
|---|
| 406 | continue; |
|---|
| 407 | printf("char1=%c\n",i); |
|---|
| 408 | for (gizmp=gizmhp; gizmp; gizmp=gizmp->nextp) { |
|---|
| 409 | printf("from/%d=",gizmp->isize); |
|---|
| 410 | for (p=gizmp->ipatt, n=gizmp->isize; n--; p++) |
|---|
| 411 | printf("%c(%02x)",*p,*p); |
|---|
| 412 | putchar('\n'); |
|---|
| 413 | printf(" to/%d=",gizmp->osize); |
|---|
| 414 | for (p=gizmp->opatt, n=gizmp->osize; n--; p++) |
|---|
| 415 | printf("%c(%02x)",*p,*p); |
|---|
| 416 | putchar('\n'); |
|---|
| 417 | } |
|---|
| 418 | printf(".."); GETCHAR; |
|---|
| 419 | } |
|---|
| 420 | #endif |
|---|
| 421 | |
|---|
| 422 | |
|---|
| 423 | |
|---|
| 424 | /* close input data base */ |
|---|
| 425 | |
|---|
| 426 | dbxflush(gizdbnp); /* close .mst/.xrf and free input buffers */ |
|---|
| 427 | |
|---|
| 428 | #if CICPP |
|---|
| 429 | delete recp; |
|---|
| 430 | #endif /* CICPP */ |
|---|
| 431 | |
|---|
| 432 | if (rectrace) { |
|---|
| 433 | ubytes-=CORELEFT(); |
|---|
| 434 | printf("gizmread - %s=%"_LD_" bytes\n",(*vgizmpp)->gdbnp,ubytes); |
|---|
| 435 | } |
|---|
| 436 | |
|---|
| 437 | |
|---|
| 438 | /* process tag list */ |
|---|
| 439 | |
|---|
| 440 | while (*q) { |
|---|
| 441 | if (gmap->grngs >= MAXGIZR) fatal((char *)p); |
|---|
| 442 | if (sscanf((CONST char *)q,"%"_LD_"/%"_LD_,&xtag1,&xtag2) == 2) { |
|---|
| 443 | if (xtag1 < 1 || xtag2 > USHRT_MAX) fatal((char *)p); |
|---|
| 444 | if (xtag1 > xtag2) fatal((char *)p); |
|---|
| 445 | while (*q != '/') q++; q++; |
|---|
| 446 | while (isdigit(*q)) q++; |
|---|
| 447 | gmap->grng1[gmap->grngs]=(UWORD)xtag1; |
|---|
| 448 | gmap->grng2[gmap->grngs]=(UWORD)xtag2; |
|---|
| 449 | if (*q == ',') if (*(q+1)) q++; |
|---|
| 450 | gmap->grngs++; |
|---|
| 451 | continue; |
|---|
| 452 | } |
|---|
| 453 | if (sscanf((CONST char *)q,"%"_LD_,&xtag1) == 1) { |
|---|
| 454 | while (isdigit(*q)) q++; |
|---|
| 455 | if (xtag1 > USHRT_MAX) fatal((char *)p); |
|---|
| 456 | gmap->grng1[gmap->grngs]=(UWORD)xtag1; |
|---|
| 457 | gmap->grng2[gmap->grngs]=(UWORD)xtag1; |
|---|
| 458 | if (*q == ',') if (*(q+1)) q++; |
|---|
| 459 | gmap->grngs++; |
|---|
| 460 | continue; |
|---|
| 461 | } |
|---|
| 462 | fatal((char *)p); |
|---|
| 463 | } |
|---|
| 464 | |
|---|
| 465 | if (c) *cq=c; |
|---|
| 466 | |
|---|
| 467 | |
|---|
| 468 | return(0); |
|---|
| 469 | } |
|---|
| 470 | |
|---|
| 471 | |
|---|
| 472 | |
|---|
| 473 | #if CICPP |
|---|
| 474 | LONGX recgizmo(CISISX *cisisxp, |
|---|
| 475 | RECSTRU *recp, |
|---|
| 476 | VGIZPSTRU *vgizmap) |
|---|
| 477 | #else /* CICPP */ |
|---|
| 478 | LONGX recgizmo(irec,vgizmap) /* |
|---|
| 479 | ------------- |
|---|
| 480 | abenda se vrecp nao inicializado; |
|---|
| 481 | abenda se registro irec nao alocado; |
|---|
| 482 | abenda se registro irec invalido; |
|---|
| 483 | processa irec segundo vgizmap; |
|---|
| 484 | retorna o numero de matchs |
|---|
| 485 | */ |
|---|
| 486 | |
|---|
| 487 | LONGX irec; /* indice de vrecp, para info/store */ |
|---|
| 488 | VGIZPSTRU *vgizmap; /* estrutura gizmo a considerar */ |
|---|
| 489 | #endif /* CICPP */ |
|---|
| 490 | |
|---|
| 491 | { |
|---|
| 492 | #if CICPP |
|---|
| 493 | LONGX irec=0; |
|---|
| 494 | #else /* CICPP */ |
|---|
| 495 | RECSTRU *recp; |
|---|
| 496 | #endif /* CICPP */ |
|---|
| 497 | |
|---|
| 498 | GIZMSTRU *gizmhp,*gizmp; |
|---|
| 499 | |
|---|
| 500 | short match; |
|---|
| 501 | unsigned char *p,*p1,*p2; |
|---|
| 502 | unsigned char *buffup,*batchp,*fuplenp; |
|---|
| 503 | LONGX nbytes,nmatchs; |
|---|
| 504 | int xdir,dirloop,fldloop,fuplen,n,irng,rngok; |
|---|
| 505 | UWORD tag; |
|---|
| 506 | |
|---|
| 507 | |
|---|
| 508 | #if !CICPP |
|---|
| 509 | if (rectrace) |
|---|
| 510 | printf("recgizmo - irec=%"_LD_" %s=%p\n",irec,vgizmap->gdbnp,vgizmap); |
|---|
| 511 | |
|---|
| 512 | if (!nrecs) |
|---|
| 513 | fatal("recgizmo/nrecs"); |
|---|
| 514 | |
|---|
| 515 | recp=vrecp[irec]; |
|---|
| 516 | #endif /* CICPP */ |
|---|
| 517 | |
|---|
| 518 | if (!recp) |
|---|
| 519 | fatal("recgizmo/irec"); |
|---|
| 520 | #if 0 |
|---|
| 521 | printf("+++ recgizmo: "); |
|---|
| 522 | prtleader(recp,0L); |
|---|
| 523 | prtfields(recp,0L); |
|---|
| 524 | #endif |
|---|
| 525 | |
|---|
| 526 | if (RECtype != TYPEMFR) { |
|---|
| 527 | if (rectrace) printf("*** irec=%"_LD_" RECtype=%d\n",irec,RECtype); |
|---|
| 528 | fatal("recgizmo/check"); |
|---|
| 529 | } |
|---|
| 530 | |
|---|
| 531 | /* allocate buffer for fldupdat */ |
|---|
| 532 | nbytes=BUFFUPL; |
|---|
| 533 | |
|---|
| 534 | #if CICPP |
|---|
| 535 | try { buffup= new unsigned char [nbytes]; } |
|---|
| 536 | catch (BAD_ALLOC) |
|---|
| 537 | { buffup = (unsigned char *)ALLONULL; } |
|---|
| 538 | #else /* CICPP */ |
|---|
| 539 | buffup=(char *)ALLOC((ALLOPARM)nbytes); |
|---|
| 540 | #endif /* CICPP */ |
|---|
| 541 | if (buffup == (unsigned char *)ALLONULL) |
|---|
| 542 | fatal("recgizmo/ALLOC"); |
|---|
| 543 | |
|---|
| 544 | nmatchs=0; |
|---|
| 545 | if (vgizmap->ghdrp == NULL) fatal("recgizmo/ghdrp"); |
|---|
| 546 | |
|---|
| 547 | for (batchp=buffup, xdir=0, dirloop=MFRnvf; dirloop--; xdir++) { |
|---|
| 548 | tag=DIRtag(xdir); rngok=1; |
|---|
| 549 | #if TRACEG1 |
|---|
| 550 | printf("\\begin tag %d..",tag); GETCHAR; |
|---|
| 551 | #endif |
|---|
| 552 | |
|---|
| 553 | if (vgizmap->grngs) |
|---|
| 554 | for (rngok=0, irng=0; irng < vgizmap->grngs; irng++) { |
|---|
| 555 | if (tag < vgizmap->grng1[irng]) continue; |
|---|
| 556 | if (tag > vgizmap->grng2[irng]) continue; |
|---|
| 557 | rngok=1; break; |
|---|
| 558 | } |
|---|
| 559 | |
|---|
| 560 | if (rngok) { |
|---|
| 561 | sprintf((char *)batchp,"H%u 000000 ",tag); batchp+=strlen((CONST char *)batchp); |
|---|
| 562 | fuplenp=batchp-1-6; fuplen=0; /* fuplenp points to 000000 */ |
|---|
| 563 | #if TRACEG2 |
|---|
| 564 | printf("\\buffup=%s",buffup); GETCHAR; |
|---|
| 565 | #endif |
|---|
| 566 | for (p=(unsigned char *)FIELDP(xdir), fldloop=DIRlen(xdir); fldloop; ) { |
|---|
| 567 | #if TRACEG2 |
|---|
| 568 | printf("\\fldloop=%d *p=%c",fldloop,*p); GETCHAR; |
|---|
| 569 | #endif |
|---|
| 570 | gizmhp=vgizmap->ghdrp[*p]; |
|---|
| 571 | if (gizmhp) { |
|---|
| 572 | for (gizmp=gizmhp; gizmp; ) { |
|---|
| 573 | if ((n=gizmp->isize) > fldloop) { |
|---|
| 574 | #if TRACEG2 |
|---|
| 575 | printf("\\need %d chars - continue",n); GETCHAR; |
|---|
| 576 | #endif |
|---|
| 577 | gizmp=gizmp->nextp; |
|---|
| 578 | match=0; /* for the last cell - next char */ |
|---|
| 579 | continue; |
|---|
| 580 | } |
|---|
| 581 | for (match=1, p1=gizmp->ipatt, p2=p; n--; p1++, p2++) |
|---|
| 582 | if (*p1 != *p2) { |
|---|
| 583 | #if TRACEG2 |
|---|
| 584 | printf("\\%c != %c - no match",*p1,*p2); GETCHAR; |
|---|
| 585 | #endif |
|---|
| 586 | match=0; |
|---|
| 587 | break; |
|---|
| 588 | } |
|---|
| 589 | #if TRACEG2 |
|---|
| 590 | else { |
|---|
| 591 | printf("\\%c == %c - may match",*p1,*p2); GETCHAR; |
|---|
| 592 | } |
|---|
| 593 | #endif |
|---|
| 594 | if (match) { |
|---|
| 595 | #if TRACEG2 |
|---|
| 596 | printf("\\match %d -> %d chars",gizmp->isize,gizmp->osize); GETCHAR; |
|---|
| 597 | #endif |
|---|
| 598 | p1=gizmp->opatt; |
|---|
| 599 | for (n=gizmp->osize; n--; ) |
|---|
| 600 | *batchp++ = *p1++; |
|---|
| 601 | p+=(n=gizmp->isize); |
|---|
| 602 | fldloop-=n; fuplen+=gizmp->osize; |
|---|
| 603 | gizmp->nused++; |
|---|
| 604 | gizmp=NULL; /* break */ |
|---|
| 605 | nmatchs++; |
|---|
| 606 | } |
|---|
| 607 | else { |
|---|
| 608 | gizmp=gizmp->nextp; |
|---|
| 609 | #if TRACEG2 |
|---|
| 610 | printf("\\next"); GETCHAR; |
|---|
| 611 | #endif |
|---|
| 612 | } |
|---|
| 613 | } |
|---|
| 614 | if (!match) { |
|---|
| 615 | #if TRACEG2 |
|---|
| 616 | printf("\\no match - copying %c",*p); GETCHAR; |
|---|
| 617 | #endif |
|---|
| 618 | *batchp++ = *p++; |
|---|
| 619 | fldloop--; fuplen++; |
|---|
| 620 | } |
|---|
| 621 | } |
|---|
| 622 | else { |
|---|
| 623 | #if TRACEG2 |
|---|
| 624 | printf("\\no gizmo - copying %c",*p); GETCHAR; |
|---|
| 625 | #endif |
|---|
| 626 | *batchp++ = *p++; |
|---|
| 627 | fldloop--; fuplen++; |
|---|
| 628 | } |
|---|
| 629 | } /* end field chrs */ |
|---|
| 630 | |
|---|
| 631 | sprintf((char *)fuplenp,"%06d",fuplen); *(fuplenp+6)=' '; |
|---|
| 632 | |
|---|
| 633 | } |
|---|
| 634 | |
|---|
| 635 | else { /* just copy it */ |
|---|
| 636 | sprintf((char *)batchp,"H%u %u ",tag,DIRlen(xdir)); batchp+=strlen((CONST char *)batchp); |
|---|
| 637 | memcpy(batchp,FIELDP(xdir),DIRlen(xdir)); batchp+=DIRlen(xdir); |
|---|
| 638 | } |
|---|
| 639 | |
|---|
| 640 | } /* end dir entries */ |
|---|
| 641 | |
|---|
| 642 | *batchp='\0'; |
|---|
| 643 | |
|---|
| 644 | if (nmatchs) { |
|---|
| 645 | |
|---|
| 646 | MFRmfrl=MFRbase=LEADER; MFRnvf=0; |
|---|
| 647 | |
|---|
| 648 | #if CICPP |
|---|
| 649 | p = (unsigned char *)recp->xfldupdat((char *)buffup); |
|---|
| 650 | #else /* CICPP */ |
|---|
| 651 | p=fldupdat(irec,buffup); |
|---|
| 652 | #endif /* CICPP */ |
|---|
| 653 | |
|---|
| 654 | if (p) { |
|---|
| 655 | if (rectrace) { |
|---|
| 656 | printf("*** buffup='%s'\n",buffup); /* */ |
|---|
| 657 | printf("*** fldupdat='%s'\n",p); /* */ |
|---|
| 658 | for (p=buffup; *p; p++) {printf("p=%02x=%c",*p,*p); if (getchar() != '\n') break;} |
|---|
| 659 | } |
|---|
| 660 | fatal("recgizmo/fldupdat"); |
|---|
| 661 | } |
|---|
| 662 | |
|---|
| 663 | #if TRACEG3 |
|---|
| 664 | /* prtleader(recp,MFRmfn); |
|---|
| 665 | prtfields(recp,MFRmfn); */ |
|---|
| 666 | #endif |
|---|
| 667 | } |
|---|
| 668 | |
|---|
| 669 | /* deallocate working area */ |
|---|
| 670 | #if CICPP |
|---|
| 671 | delete[] buffup; |
|---|
| 672 | #else /* CICPP */ |
|---|
| 673 | FREE(buffup); |
|---|
| 674 | #endif /* CICPP */ |
|---|
| 675 | |
|---|
| 676 | if (rectrace) |
|---|
| 677 | printf("recgizmo - %s %"_LD_" match(s)\n",vgizmap->gdbnp,nmatchs); |
|---|
| 678 | |
|---|
| 679 | return(nmatchs); |
|---|
| 680 | } |
|---|
| 681 | |
|---|
| 682 | |
|---|
| 683 | #undef GETCHAR |
|---|
| 684 | |
|---|
| 685 | #endif /* RECGIZM */ |
|---|
| 686 | |
|---|
| 687 | |
|---|
| 688 | |
|---|
| 689 | #if RECXPND |
|---|
| 690 | |
|---|
| 691 | #define TRACXG1 0 |
|---|
| 692 | #define TRACXG3 0 |
|---|
| 693 | |
|---|
| 694 | #define TRACYG1 0 |
|---|
| 695 | #define TRACYG3 0 |
|---|
| 696 | |
|---|
| 697 | |
|---|
| 698 | #define SIZEOFTAG sizeof(DIRlen(0)) |
|---|
| 699 | |
|---|
| 700 | |
|---|
| 701 | #if CICPP |
|---|
| 702 | LONGX recxpnmo(RECSTRU *recp) |
|---|
| 703 | #else /* CICPP */ |
|---|
| 704 | LONGX recxpnmo(irec) /* |
|---|
| 705 | ------------- |
|---|
| 706 | abenda se vrecp nao inicializado; |
|---|
| 707 | abenda se registro irec nao alocado; |
|---|
| 708 | abenda se registro irec invalido; |
|---|
| 709 | processa irec segundo vxpnmp; |
|---|
| 710 | */ |
|---|
| 711 | |
|---|
| 712 | LONGX irec; /* indice de vrecp, para info/store */ |
|---|
| 713 | #endif /* CICPP */ |
|---|
| 714 | { |
|---|
| 715 | #if !CICPP |
|---|
| 716 | RECSTRU *recp; |
|---|
| 717 | #endif /* CICPP */ |
|---|
| 718 | |
|---|
| 719 | unsigned char *buffup,*batchp,*fuplenp,*p; |
|---|
| 720 | LONGX nmatchs,nbytes; |
|---|
| 721 | int xdir,dirloop,fuplen; |
|---|
| 722 | int minlen,len,tag,loop; |
|---|
| 723 | |
|---|
| 724 | |
|---|
| 725 | if (!nrecs) |
|---|
| 726 | fatal("recxpnmo/nrecs"); |
|---|
| 727 | |
|---|
| 728 | #if !CICPP |
|---|
| 729 | recp=vrecp[irec]; |
|---|
| 730 | #endif /* CICPP */ |
|---|
| 731 | if (!recp) |
|---|
| 732 | fatal("recxpnmo/irec"); |
|---|
| 733 | |
|---|
| 734 | #if TRACXG1 |
|---|
| 735 | printf("recxpnmo - irec: %"_LD_" RDBxpn01,02: %d,%d\n",irec,RDBxpn01,RDBxpn02); |
|---|
| 736 | #endif |
|---|
| 737 | |
|---|
| 738 | if (RECtype != TYPEMFR) { |
|---|
| 739 | if (rectrace) printf("*** irec=%"_LD_" RECtype=%d\n",irec,RECtype); |
|---|
| 740 | fatal("recxpnmo/check"); |
|---|
| 741 | } |
|---|
| 742 | |
|---|
| 743 | /* allocate buffer for fldupdat */ |
|---|
| 744 | nbytes=BUFFUPL; |
|---|
| 745 | #if CICPP |
|---|
| 746 | try { buffup= new char [nbytes]; } |
|---|
| 747 | catch (BAD_ALLOC) |
|---|
| 748 | { buffup = (char *)ALLONULL); } |
|---|
| 749 | #else /* CICPP */ |
|---|
| 750 | buffup=(char *)ALLOC((ALLOPARM)nbytes); |
|---|
| 751 | #endif /* CICPP */ |
|---|
| 752 | if (buffup == (char *)ALLONULL) |
|---|
| 753 | fatal("recxpnmo/ALLOC"); |
|---|
| 754 | |
|---|
| 755 | nmatchs=0; batchp=buffup; minlen=SIZEOFTAG+0+1; |
|---|
| 756 | sprintf(batchp,"D%d",RDBxpn01); batchp+=strlen(batchp); |
|---|
| 757 | for (xdir=0, dirloop=MFRnvf; dirloop--; xdir++) { |
|---|
| 758 | if (DIRtag(xdir) != RDBxpn01) |
|---|
| 759 | continue; |
|---|
| 760 | for (p=FIELDP(xdir), len=DIRlen(xdir); len >= minlen; ) { |
|---|
| 761 | #if SWAPPED |
|---|
| 762 | p+=SIZEOFTAG; |
|---|
| 763 | for (tag= *--p, len--, loop=SIZEOFTAG-1; loop--; ) { /* swapped */ |
|---|
| 764 | tag*=256; tag+=(*--p); len--; |
|---|
| 765 | } |
|---|
| 766 | p+=SIZEOFTAG; |
|---|
| 767 | #else |
|---|
| 768 | for (tag= *p++, len--, loop=SIZEOFTAG-1; loop--; ) { /* normal */ |
|---|
| 769 | tag*=256; tag+=(*p++); len--; |
|---|
| 770 | } |
|---|
| 771 | #endif |
|---|
| 772 | sprintf(batchp,"H%d 000000 ",tag); batchp+=strlen(batchp); |
|---|
| 773 | fuplenp=batchp-1-6; fuplen=0; /* fuplenp points to 000000 */ |
|---|
| 774 | for (; *p != RDBxpn02; len--, fuplen++) { |
|---|
| 775 | if (len <= 0) fatal("recxpnmo/len/move"); |
|---|
| 776 | *batchp++ = *p++; |
|---|
| 777 | } |
|---|
| 778 | sprintf(fuplenp,"%06d",fuplen); *(fuplenp+6)=' '; |
|---|
| 779 | p++; len--; |
|---|
| 780 | #if 0 |
|---|
| 781 | *batchp='\0'; |
|---|
| 782 | printf("len=%d buffup=%s\n",len,buffup); |
|---|
| 783 | #endif |
|---|
| 784 | } |
|---|
| 785 | if (len != 0) fatal("recxpnmo/len/end"); |
|---|
| 786 | } |
|---|
| 787 | *batchp=NULL; |
|---|
| 788 | |
|---|
| 789 | MFRmfrl=MFRbase=LEADER; MFRnvf=0; |
|---|
| 790 | |
|---|
| 791 | #if CICPP |
|---|
| 792 | p= recp->xfldupdat(buffup); |
|---|
| 793 | #else |
|---|
| 794 | p=fldupdat(irec,buffup); |
|---|
| 795 | #endif /* CICPP */ |
|---|
| 796 | |
|---|
| 797 | if (p) { |
|---|
| 798 | /* printf("*** fldupdat='%s'\n",p); */ |
|---|
| 799 | fatal("recxpnmo/fldupdat"); |
|---|
| 800 | } |
|---|
| 801 | |
|---|
| 802 | #if TRACXG3 |
|---|
| 803 | prtleader(recp,MFRmfn); |
|---|
| 804 | prtfields(recp,MFRmfn); |
|---|
| 805 | #endif |
|---|
| 806 | |
|---|
| 807 | /* deallocate working area */ |
|---|
| 808 | #if CICPP |
|---|
| 809 | delete[] buffup; |
|---|
| 810 | #else |
|---|
| 811 | FREE(buffup); |
|---|
| 812 | #endif /* CICPP */ |
|---|
| 813 | |
|---|
| 814 | return(nmatchs); |
|---|
| 815 | } |
|---|
| 816 | |
|---|
| 817 | #if CICPP |
|---|
| 818 | LONGX recxpn00 (RECSTRU *recp, |
|---|
| 819 | int xpn01, |
|---|
| 820 | int xpn02) |
|---|
| 821 | #else /* CICPP */ |
|---|
| 822 | LONGX recxpn00(irec,xpn01,xpn02) /* |
|---|
| 823 | ------------- |
|---|
| 824 | abenda se vrecp nao inicializado; |
|---|
| 825 | abenda se registro irec nao alocado; |
|---|
| 826 | abenda se registro irec invalido; |
|---|
| 827 | processa irec segundo vxpnmp; |
|---|
| 828 | */ |
|---|
| 829 | |
|---|
| 830 | LONGX irec; /* indice de vrecp, para info/store */ |
|---|
| 831 | int xpn01; /* tag */ |
|---|
| 832 | int xpn02; /* delimiter */ |
|---|
| 833 | #endif /* CICPP */ |
|---|
| 834 | { |
|---|
| 835 | |
|---|
| 836 | #if !CICPP |
|---|
| 837 | RECSTRU *recp; |
|---|
| 838 | #endif /* CICPP */ |
|---|
| 839 | |
|---|
| 840 | unsigned char *buffup,*batchp,*fuplenp,*p; |
|---|
| 841 | LONGX nmatchs,nbytes; |
|---|
| 842 | int xdir,dirloop,fuplen; |
|---|
| 843 | |
|---|
| 844 | |
|---|
| 845 | if (!nrecs) |
|---|
| 846 | fatal("recxpn00/nrecs"); |
|---|
| 847 | |
|---|
| 848 | #if !CICPP |
|---|
| 849 | recp=vrecp[irec]; |
|---|
| 850 | #endif /* CICPP */ |
|---|
| 851 | |
|---|
| 852 | if (!recp) |
|---|
| 853 | fatal("recxpn00/irec"); |
|---|
| 854 | |
|---|
| 855 | #if TRACYG1 |
|---|
| 856 | printf("recxpn00 - irec: %"_LD_" xpn01,02: %d,%d SIZEOFTAG=%d\n", |
|---|
| 857 | irec,xpn01,xpn02,SIZEOFTAG); |
|---|
| 858 | #endif |
|---|
| 859 | |
|---|
| 860 | if (RECtype != TYPEMFR) { |
|---|
| 861 | if (rectrace) printf("*** irec=%"_LD_" RECtype=%d\n",irec,RECtype); |
|---|
| 862 | fatal("recxpn00/check"); |
|---|
| 863 | } |
|---|
| 864 | |
|---|
| 865 | /* allocate buffer for fldupdat */ |
|---|
| 866 | nbytes=BUFFUPL; |
|---|
| 867 | |
|---|
| 868 | #if CICPP |
|---|
| 869 | try { buffup = new char [nbytes]; } |
|---|
| 870 | catch (BAD_ALLOC) |
|---|
| 871 | { buffup = (char *)ALLONULL; } |
|---|
| 872 | |
|---|
| 873 | #else /* CICPP */ |
|---|
| 874 | buffup=(char *)ALLOC((ALLOPARM)nbytes); |
|---|
| 875 | #endif /* CICPP */ |
|---|
| 876 | if (buffup = (char *)ALLONULL) |
|---|
| 877 | fatal("recxpn00/ALLOC"); |
|---|
| 878 | |
|---|
| 879 | nmatchs=0; batchp=buffup; |
|---|
| 880 | sprintf(batchp,"H%d 000000 ",xpn01); batchp+=strlen(batchp); |
|---|
| 881 | fuplenp=batchp-1-6; fuplen=0; /* fuplenp points to 000000 */ |
|---|
| 882 | for (xdir=0, dirloop=MFRnvf; dirloop--; xdir++) { |
|---|
| 883 | memcpy(batchp,(char *)&DIRtag(xdir),SIZEOFTAG); |
|---|
| 884 | batchp+=SIZEOFTAG; |
|---|
| 885 | fuplen+=SIZEOFTAG; |
|---|
| 886 | memcpy(batchp,FIELDP(xdir),DIRlen(xdir)); |
|---|
| 887 | batchp+=DIRlen(xdir); |
|---|
| 888 | fuplen+=DIRlen(xdir); |
|---|
| 889 | *batchp++ = xpn02; |
|---|
| 890 | fuplen++; |
|---|
| 891 | } |
|---|
| 892 | *batchp=NULL; |
|---|
| 893 | sprintf(fuplenp,"%06d",fuplen); *(fuplenp+6)=' '; |
|---|
| 894 | |
|---|
| 895 | if (fuplen) { |
|---|
| 896 | MFRmfrl=MFRbase=LEADER; MFRnvf=0; |
|---|
| 897 | |
|---|
| 898 | #if CICPP |
|---|
| 899 | p = recp->xfldupdat(buffup); |
|---|
| 900 | #else |
|---|
| 901 | p=fldupdat(irec,buffup); |
|---|
| 902 | #endif /* CICPP */ |
|---|
| 903 | |
|---|
| 904 | if (p) { |
|---|
| 905 | /* printf("*** fldupdat='%s'\n",p); */ |
|---|
| 906 | fatal("recxpn00/fldupdat"); |
|---|
| 907 | } |
|---|
| 908 | } |
|---|
| 909 | |
|---|
| 910 | #if TRAXYG3 |
|---|
| 911 | prtleader(recp,MFRmfn); |
|---|
| 912 | prtfields(recp,MFRmfn); |
|---|
| 913 | #endif |
|---|
| 914 | |
|---|
| 915 | /* deallocate working area */ |
|---|
| 916 | #if CICPP |
|---|
| 917 | delete[] buffup; |
|---|
| 918 | #else /* CICPP */ |
|---|
| 919 | FREE(buffup); |
|---|
| 920 | #endif /* CICPP */ |
|---|
| 921 | |
|---|
| 922 | return(nmatchs); |
|---|
| 923 | } |
|---|
| 924 | |
|---|
| 925 | |
|---|
| 926 | #undef SIZEOFTAG |
|---|
| 927 | |
|---|
| 928 | #endif /* RECXPND */ |
|---|
| 929 | |
|---|
| 930 | |
|---|
| 931 | |
|---|
| 932 | /* ----------------------------- dec.c ------------------------------ */ |
|---|
| 933 | |
|---|
| 934 | #if RECDECO |
|---|
| 935 | |
|---|
| 936 | /* cidec.h */ |
|---|
| 937 | |
|---|
| 938 | #if CICPP |
|---|
| 939 | #define R2RECORD(r,dbn,mfn) \ |
|---|
| 940 | (R2recp=r)->xrecord(dbn,mfn) |
|---|
| 941 | |
|---|
| 942 | #define R2RECnbytes R2recp->recnbytes |
|---|
| 943 | #define R2RECtype R2recp->rectype |
|---|
| 944 | #define R2RECdbxp R2recp->recdbxp |
|---|
| 945 | #define R2RECrc R2recp->recrc |
|---|
| 946 | |
|---|
| 947 | #define R2MFRmfn R2recp->recmfp->m1.m1mfn |
|---|
| 948 | #define R2MFRmfrl R2recp->recmfp->m1.m1mfrl |
|---|
| 949 | #define R2MFRmfbwb R2recp->recmfp->m1.m1mfbwb |
|---|
| 950 | #define R2MFRmfbwp R2recp->recmfp->m1.m1mfbwp |
|---|
| 951 | #define R2MFRbase R2recp->recmfp->m1.m1base |
|---|
| 952 | #define R2MFRnvf R2recp->recmfp->m1.m1nvf |
|---|
| 953 | #define R2MFRstatus R2recp->recmfp->m1.m1status |
|---|
| 954 | #define R2MFRdir R2recp->recmfp->m1.m1dir |
|---|
| 955 | |
|---|
| 956 | #define R2DIRtag(x) R2recp->recmfp->m1.m1dir[x].tag |
|---|
| 957 | #define R2DIRpos(x) R2recp->recmfp->m1.m1dir[x].pos |
|---|
| 958 | #define R2DIRlen(x) R2recp->recmfp->m1.m1dir[x].len |
|---|
| 959 | |
|---|
| 960 | #define R2FIELDP(x) (R2recp->recmfp->mx)+(R2MFRbase+R2DIRpos(x)) |
|---|
| 961 | |
|---|
| 962 | #define R2RDBname R2RECdbxp->dbxname |
|---|
| 963 | #else /* CICPP */ |
|---|
| 964 | #define R2RECORD(r,dbn,mfn) \ |
|---|
| 965 | R2recp=vrecp[record(((r)?r:(r=nrecs)),dbn,mfn)] |
|---|
| 966 | |
|---|
| 967 | #define R2RECnbytes R2recp->recnbytes |
|---|
| 968 | #define R2RECtype R2recp->rectype |
|---|
| 969 | #define R2RECdbxp R2recp->recdbxp |
|---|
| 970 | #define R2RECrc R2recp->recrc |
|---|
| 971 | |
|---|
| 972 | #define R2MFRmfn R2recp->recmf.m1.m1mfn |
|---|
| 973 | #define R2MFRmfrl R2recp->recmf.m1.m1mfrl |
|---|
| 974 | #define R2MFRmfbwb R2recp->recmf.m1.m1mfbwb |
|---|
| 975 | #define R2MFRmfbwp R2recp->recmf.m1.m1mfbwp |
|---|
| 976 | #define R2MFRbase R2recp->recmf.m1.m1base |
|---|
| 977 | #define R2MFRnvf R2recp->recmf.m1.m1nvf |
|---|
| 978 | #define R2MFRstatus R2recp->recmf.m1.m1status |
|---|
| 979 | #define R2MFRdir R2recp->recmf.m1.m1dir |
|---|
| 980 | |
|---|
| 981 | #define R2DIRtag(x) R2recp->recmf.m1.m1dir[x].tag |
|---|
| 982 | #define R2DIRpos(x) R2recp->recmf.m1.m1dir[x].pos |
|---|
| 983 | #define R2DIRlen(x) R2recp->recmf.m1.m1dir[x].len |
|---|
| 984 | |
|---|
| 985 | #define R2FIELDP(x) VMFX(decridx)+(R2MFRbase+R2DIRpos(x)) /* wall!! */ |
|---|
| 986 | |
|---|
| 987 | #define R2RDBname R2RECdbxp->dbxname |
|---|
| 988 | #endif /* CICPP */ |
|---|
| 989 | /* end cidec.h */ |
|---|
| 990 | |
|---|
| 991 | #define TRACED1 00 |
|---|
| 992 | #define TRACED2 00 |
|---|
| 993 | #define TRACEDx 00 |
|---|
| 994 | #define TRACEDT 00 |
|---|
| 995 | #if TRACEDT |
|---|
| 996 | #define GETCHAR printf("\n"); |
|---|
| 997 | #else |
|---|
| 998 | #define GETX 1 |
|---|
| 999 | int xgetx; |
|---|
| 1000 | #define GETCHAR (xgetx=getchar()) |
|---|
| 1001 | #endif |
|---|
| 1002 | |
|---|
| 1003 | |
|---|
| 1004 | #if CICPP |
|---|
| 1005 | int recdecod(CISISX * cisisxp, |
|---|
| 1006 | RECSTRU *recp, |
|---|
| 1007 | char *decdbnp) |
|---|
| 1008 | #else /* CICPP */ |
|---|
| 1009 | int recdecod(irec,decdbnp,wrec) /* |
|---|
| 1010 | ------------ */ |
|---|
| 1011 | LONGX irec; |
|---|
| 1012 | char *decdbnp; |
|---|
| 1013 | LONGX wrec; |
|---|
| 1014 | #endif /* CICPP */ |
|---|
| 1015 | |
|---|
| 1016 | { |
|---|
| 1017 | VDECPSTRU *dmap,*lastdmap; |
|---|
| 1018 | unsigned char *datp,*p; |
|---|
| 1019 | LONGX xtag1,xtag2; |
|---|
| 1020 | int n,irng; |
|---|
| 1021 | |
|---|
| 1022 | LONGX wmfn; |
|---|
| 1023 | int wdir,wtag,wocc,wox; |
|---|
| 1024 | |
|---|
| 1025 | DBXSTRU *dbxp; |
|---|
| 1026 | |
|---|
| 1027 | #if CICPP |
|---|
| 1028 | RECSTRU *wrecp=new RECSTRU(cisisxp); |
|---|
| 1029 | RECSTRU *keeprecp; |
|---|
| 1030 | #else |
|---|
| 1031 | RECSTRU *recp; |
|---|
| 1032 | recp=vrecp[irec]; |
|---|
| 1033 | #endif /* CICPP */ |
|---|
| 1034 | |
|---|
| 1035 | #if !CICPP |
|---|
| 1036 | recp=vrecp[irec]; |
|---|
| 1037 | #endif /* CICPP */ |
|---|
| 1038 | |
|---|
| 1039 | dbxp=RECdbxp; |
|---|
| 1040 | |
|---|
| 1041 | if (dectrace) |
|---|
| 1042 | printf("recdecod - 1. %s %p +%"_LD_"\n",DBXname,DBXvderp,CORELEFT()); |
|---|
| 1043 | |
|---|
| 1044 | |
|---|
| 1045 | #if CICPP |
|---|
| 1046 | keeprecp=recp; |
|---|
| 1047 | for (wmfn=1; ; wmfn++) { |
|---|
| 1048 | wrecp->xrecord(decdbnp,wmfn); |
|---|
| 1049 | recp=wrecp; /* current */ |
|---|
| 1050 | if (RECrc == RCEOF) break; |
|---|
| 1051 | #else /* CICPP */ |
|---|
| 1052 | for (wmfn=1; (RECORD(wrec,decdbnp,wmfn))->recrc != RCEOF; wmfn++) { |
|---|
| 1053 | #endif /* CICPP */ |
|---|
| 1054 | |
|---|
| 1055 | if (RECrc != RCNORMAL) continue; |
|---|
| 1056 | #if 0 |
|---|
| 1057 | prtfields(recp,MFRmfn); |
|---|
| 1058 | printf("+++\n"); |
|---|
| 1059 | if (getchar() != '\n') break; |
|---|
| 1060 | #endif |
|---|
| 1061 | |
|---|
| 1062 | /* |
|---|
| 1063 | aloca e inicializa decod |
|---|
| 1064 | */ |
|---|
| 1065 | n=sizeof(VDECPSTRU); |
|---|
| 1066 | |
|---|
| 1067 | #if CICPP |
|---|
| 1068 | try { dmap = (VDECPSTRU *) new char [n]; } |
|---|
| 1069 | catch (BAD_ALLOC) |
|---|
| 1070 | { dmap = (VDECPSTRU *)ALLONULL; } |
|---|
| 1071 | #else |
|---|
| 1072 | dmap=(VDECPSTRU *)ALLOC((ALLOPARM)n); |
|---|
| 1073 | #endif /* CICPP */ |
|---|
| 1074 | |
|---|
| 1075 | if (dmap == (VDECPSTRU *)ALLONULL) |
|---|
| 1076 | fatal("recdecod/ALLOC/0"); |
|---|
| 1077 | memset(dmap,0x00,(unsigned)n); |
|---|
| 1078 | |
|---|
| 1079 | if (DBXvderp == NULL) DBXvderp=dmap; |
|---|
| 1080 | else { |
|---|
| 1081 | for (lastdmap=DBXvderp; lastdmap->nextp; ) |
|---|
| 1082 | lastdmap=lastdmap->nextp; |
|---|
| 1083 | lastdmap->nextp=dmap; |
|---|
| 1084 | } |
|---|
| 1085 | |
|---|
| 1086 | /* process data base name */ |
|---|
| 1087 | #if CICPP |
|---|
| 1088 | if ((wdir=wrecp->xfieldx(wtag=DECOTAG1,wocc=1)) < 0) { |
|---|
| 1089 | #else /* CICPP */ |
|---|
| 1090 | if ((wdir=fieldx(wrec,wtag=DECOTAG1,wocc=1)) < 0) { |
|---|
| 1091 | #endif /* CICPP */ |
|---|
| 1092 | if (rectrace) fprintf(stderr,"*** %s/%"_LD_"/%d/%d \n",DBXname,wmfn,wtag,wocc); |
|---|
| 1093 | fatal("recdecod/DECOTAG1"); |
|---|
| 1094 | } |
|---|
| 1095 | n=DIRlen(wdir); |
|---|
| 1096 | |
|---|
| 1097 | #if CICPP |
|---|
| 1098 | try { dmap->ddbnp = new unsigned char [n+1]; } |
|---|
| 1099 | catch (BAD_ALLOC) |
|---|
| 1100 | { dmap->ddbnp = (unsigned char *)ALLONULL; } |
|---|
| 1101 | #else |
|---|
| 1102 | dmap->ddbnp=(unsigned char *)ALLOC((ALLOPARM)n+1); |
|---|
| 1103 | #endif /* CICPP */ |
|---|
| 1104 | |
|---|
| 1105 | if ((dmap->ddbnp == (unsigned char *)ALLONULL)) |
|---|
| 1106 | fatal("recdecod/ALLOC/dmap"); |
|---|
| 1107 | memcpy(dmap->ddbnp,FIELDP(wdir),n); dmap->ddbnp[n]='\0'; |
|---|
| 1108 | |
|---|
| 1109 | if (dectrace) |
|---|
| 1110 | printf("recdecod - 2. %s=%p +%"_LD_"\n",dmap->ddbnp,dmap,CORELEFT()); |
|---|
| 1111 | |
|---|
| 1112 | /* process repeatable subfield delimiter */ |
|---|
| 1113 | #if CICPP |
|---|
| 1114 | if ((wdir=wrecp->xfieldx(wtag=DECOTAG2,wocc=1)) < 0) dmap->drdlm = '\0'; |
|---|
| 1115 | #else /* CICPP */ |
|---|
| 1116 | if ((wdir=fieldx(wrec,wtag=DECOTAG2,wocc=1)) < 0) dmap->drdlm = '\0'; |
|---|
| 1117 | #endif /* CICPP */ |
|---|
| 1118 | |
|---|
| 1119 | else if (DIRlen(wdir) == 0) dmap->drdlm = '\0'; |
|---|
| 1120 | else dmap->drdlm = *(FIELDP(wdir)); |
|---|
| 1121 | |
|---|
| 1122 | /* allocate working area */ |
|---|
| 1123 | #if CICPP |
|---|
| 1124 | try { datp = new unsigned char [MAXMFRL]; } |
|---|
| 1125 | catch (BAD_ALLOC) |
|---|
| 1126 | { datp = (unsigned char *)ALLONULL; } |
|---|
| 1127 | #else /* CICPP */ |
|---|
| 1128 | datp=(char *)ALLOC((ALLOPARM)MAXMFRL); |
|---|
| 1129 | #endif /* CICPP */ |
|---|
| 1130 | if (datp == (unsigned char *)ALLONULL) |
|---|
| 1131 | fatal("recdecod/ALLOC/datp"); |
|---|
| 1132 | |
|---|
| 1133 | /* process tag list */ |
|---|
| 1134 | #if CICPP |
|---|
| 1135 | wtag=DECOTAG3; dmap->drngs=wrecp->xnocc(wtag); |
|---|
| 1136 | #else /* CICPP */ |
|---|
| 1137 | wtag=DECOTAG3; dmap->drngs=nocc(wrec,wtag); |
|---|
| 1138 | #endif /* CICPP */ |
|---|
| 1139 | |
|---|
| 1140 | if ((wocc=dmap->drngs) > MAXDECR) { |
|---|
| 1141 | if (rectrace) fprintf(stderr,"*** %s/%"_LD_"/%d/%d \n",DBXname,wmfn,wtag,wocc); |
|---|
| 1142 | fatal("recdecod/DECOTAG3/nocc"); |
|---|
| 1143 | } |
|---|
| 1144 | for (irng=0, wocc=1; wocc <= dmap->drngs; wocc++, irng++) { |
|---|
| 1145 | if (irng >= MAXDECR) fatal("recdecod/MAXDECR"); |
|---|
| 1146 | |
|---|
| 1147 | #if CICPP |
|---|
| 1148 | wdir=wrecp->xfieldx(wtag=DECOTAG3,wocc); |
|---|
| 1149 | #else /* CICPP */ |
|---|
| 1150 | wdir=fieldx(wrec,wtag=DECOTAG3,wocc); |
|---|
| 1151 | #endif /* CICPP */ |
|---|
| 1152 | |
|---|
| 1153 | if (wdir < 0) fatal("recdecod/internal error"); |
|---|
| 1154 | memcpy(datp,FIELDP(wdir),n=DIRlen(wdir)); datp[n]='\0'; |
|---|
| 1155 | dmap->drng1[irng]=0; |
|---|
| 1156 | if (sscanf((CONST char *)datp,"%"_LD_"/%"_LD_,&xtag1,&xtag2) == 2) |
|---|
| 1157 | if (xtag1 >= 1 && xtag2 <= USHRT_MAX) |
|---|
| 1158 | if (xtag1 <= xtag2) { |
|---|
| 1159 | dmap->drng1[irng]=(UWORD)xtag1; |
|---|
| 1160 | dmap->drng2[irng]=(UWORD)xtag2; |
|---|
| 1161 | } |
|---|
| 1162 | if (sscanf((CONST char *)datp,"%"_LD_,&xtag1) == 1) |
|---|
| 1163 | if (xtag1 <= USHRT_MAX) { |
|---|
| 1164 | dmap->drng1[irng]=(UWORD)xtag1; |
|---|
| 1165 | dmap->drng2[irng]=(UWORD)xtag1; |
|---|
| 1166 | } |
|---|
| 1167 | if (dmap->drng1[irng] == 0) { |
|---|
| 1168 | if (rectrace) fprintf(stderr,"*** %s/%"_LD_"/%d/%d \n",DBXname,wmfn,wtag,wocc); |
|---|
| 1169 | fatal("recdecod/DECOTAG3/tag_or_tag/tag"); |
|---|
| 1170 | } |
|---|
| 1171 | } |
|---|
| 1172 | |
|---|
| 1173 | /* process subfield list */ |
|---|
| 1174 | #if CICPP |
|---|
| 1175 | if ((wocc=dmap->dsflds=wrecp->xnocc(wtag=DECOTAG4)) > MAXDECX) { |
|---|
| 1176 | #else /* CICPP */ |
|---|
| 1177 | if ((wocc=dmap->dsflds=nocc(wrec,wtag=DECOTAG4)) > MAXDECX) { |
|---|
| 1178 | #endif /* CICPP */ |
|---|
| 1179 | if (rectrace) fprintf(stderr,"*** %s/%"_LD_"/%d/%d \n",DBXname,wmfn,wtag,wocc); |
|---|
| 1180 | fatal("recdecod/DECOTAG4/nocc"); |
|---|
| 1181 | } |
|---|
| 1182 | #if TRACEDx |
|---|
| 1183 | printf("+++ 1. dsfld=%s=%d \n",dmap->dsfld,dmap->dsflds); |
|---|
| 1184 | #endif |
|---|
| 1185 | for (wocc=1; wocc <= dmap->dsflds; wocc++) { |
|---|
| 1186 | |
|---|
| 1187 | #if CICPP |
|---|
| 1188 | wdir=wrecp->xfieldx(wtag=DECOTAG4,wocc); wox=wocc-1; |
|---|
| 1189 | #else /* CICPP */ |
|---|
| 1190 | wdir=fieldx(wrec,wtag=DECOTAG4,wocc); wox=wocc-1; |
|---|
| 1191 | #endif /* CICPP */ |
|---|
| 1192 | |
|---|
| 1193 | memcpy(dmap->dsfld,FIELDP(wdir),n=DIRlen(wdir)); |
|---|
| 1194 | dmap->dsfld[n]='\0'; |
|---|
| 1195 | for (p=dmap->dsfld; *p; p++) *p=isisuctab[*p]; |
|---|
| 1196 | if ((p=(unsigned char *)strchr((char *)dmap->dsfld,SFLDCHR)) != NULL) |
|---|
| 1197 | if (*++p) { |
|---|
| 1198 | dmap->dsfldx[wox] = *p; |
|---|
| 1199 | dmap->dsfldv[wox] = atol((CONST char *)(p+1)); |
|---|
| 1200 | } |
|---|
| 1201 | } |
|---|
| 1202 | |
|---|
| 1203 | /* deallocate working area */ |
|---|
| 1204 | #if CICPP |
|---|
| 1205 | delete[] datp; |
|---|
| 1206 | delete wrecp; |
|---|
| 1207 | recp=keeprecp; |
|---|
| 1208 | #else /* CICPP */ |
|---|
| 1209 | FREE(datp); |
|---|
| 1210 | #endif /* CICPP */ |
|---|
| 1211 | |
|---|
| 1212 | #if TRACEDx |
|---|
| 1213 | printf("+++ 2. dsfld=%s=%d \n",dmap->dsfld,dmap->dsflds); |
|---|
| 1214 | #endif |
|---|
| 1215 | } /* end record */ |
|---|
| 1216 | |
|---|
| 1217 | /* flush parameters data base */ |
|---|
| 1218 | dbxflush(decdbnp); |
|---|
| 1219 | |
|---|
| 1220 | if (dectrace) |
|---|
| 1221 | printf("recdecod - 3. %s %p +%"_LD_"\n",DBXname,DBXvderp,CORELEFT()); |
|---|
| 1222 | |
|---|
| 1223 | for (dmap=DBXvderp; dmap; dmap=dmap->nextp) |
|---|
| 1224 | #if CICPP |
|---|
| 1225 | recp->xmstsetup((char *)dmap->ddbnp,0L,0L); |
|---|
| 1226 | #else /* CICPP */ |
|---|
| 1227 | mstsetup(dmap->ddbnp,0L,0L); |
|---|
| 1228 | #endif /* CICPP */ |
|---|
| 1229 | |
|---|
| 1230 | if (dectrace) |
|---|
| 1231 | printf("recdecod - 4. %s %p +%"_LD_"\n",DBXname,DBXvderp,CORELEFT()); |
|---|
| 1232 | |
|---|
| 1233 | return(0); |
|---|
| 1234 | } |
|---|
| 1235 | |
|---|
| 1236 | |
|---|
| 1237 | |
|---|
| 1238 | #if CICPP |
|---|
| 1239 | LONGX recdecex (CISISX * cisisxp, |
|---|
| 1240 | RECSTRU *recp) |
|---|
| 1241 | #else /* CICPP */ |
|---|
| 1242 | LONGX recdecex(irec) /* |
|---|
| 1243 | ------------- |
|---|
| 1244 | abenda se vrecp nao inicializado; |
|---|
| 1245 | abenda se registro irec nao alocado; |
|---|
| 1246 | abenda se registro irec invalido; |
|---|
| 1247 | processa irec segundo vdecop; |
|---|
| 1248 | retorna o numero de matchs |
|---|
| 1249 | */ |
|---|
| 1250 | |
|---|
| 1251 | LONGX irec; /* indice de vrecp, para info/store */ |
|---|
| 1252 | #endif /* CICPP */ |
|---|
| 1253 | { |
|---|
| 1254 | VDECPSTRU *dmap; |
|---|
| 1255 | |
|---|
| 1256 | RECSTRU *R2recp; |
|---|
| 1257 | #if CICPP |
|---|
| 1258 | RECSTRU *decrecp=NULL; |
|---|
| 1259 | LONGX irec=0; |
|---|
| 1260 | #else /* CICPP */ |
|---|
| 1261 | RECSTRU *recp; |
|---|
| 1262 | LONGX decridx=0L; |
|---|
| 1263 | #endif /* CICPP */ |
|---|
| 1264 | |
|---|
| 1265 | short match,check,left; |
|---|
| 1266 | unsigned char *p,*q,c,*leftp; |
|---|
| 1267 | unsigned char *buffup,*batchp,*fuplenp,sfldc,rchar; |
|---|
| 1268 | LONGX nbytes,nmatchs,valmfn; |
|---|
| 1269 | /* ?FFI */ |
|---|
| 1270 | int xdir,dirloop,fldloop,fuplen,n,irng,rngok,sfldn,sfldlen,decxdir,imap,i; |
|---|
| 1271 | UWORD tag; |
|---|
| 1272 | |
|---|
| 1273 | |
|---|
| 1274 | #if !CICPP |
|---|
| 1275 | if (!nrecs) |
|---|
| 1276 | fatal("recdecex/nrecs"); |
|---|
| 1277 | recp=vrecp[irec]; |
|---|
| 1278 | #endif /* CICPP */ |
|---|
| 1279 | |
|---|
| 1280 | if (!recp) |
|---|
| 1281 | fatal("recdecex/irec"); |
|---|
| 1282 | |
|---|
| 1283 | if (RECtype != TYPEMFR) { |
|---|
| 1284 | if (rectrace) printf("*** irec=%"_LD_" RECtype=%d\n",irec,RECtype); |
|---|
| 1285 | fatal("recdecex/check"); |
|---|
| 1286 | } |
|---|
| 1287 | |
|---|
| 1288 | /* set up decod master files */ |
|---|
| 1289 | if (dectrace) |
|---|
| 1290 | printf("recdecex - irec=%"_LD_"=%s/%"_LD_" +%"_LD_"\n", |
|---|
| 1291 | irec,RDBname,MFRmfn,CORELEFT()); |
|---|
| 1292 | |
|---|
| 1293 | /* allocate buffer for fldupdat */ |
|---|
| 1294 | nbytes=BUFFUPL; |
|---|
| 1295 | |
|---|
| 1296 | #if CICPP |
|---|
| 1297 | try { buffup = new unsigned char [nbytes]; } |
|---|
| 1298 | catch (BAD_ALLOC) |
|---|
| 1299 | { buffup = (unsigned char *)ALLONULL; } |
|---|
| 1300 | #else /* CICPP */ |
|---|
| 1301 | buffup=(char *)ALLOC((ALLOPARM)nbytes); |
|---|
| 1302 | #endif /* CICPP */ |
|---|
| 1303 | |
|---|
| 1304 | if (buffup == (unsigned char *)ALLONULL) |
|---|
| 1305 | fatal("recdecex/ALLOC"); |
|---|
| 1306 | buffup[0]='\0'; |
|---|
| 1307 | |
|---|
| 1308 | nmatchs=0; |
|---|
| 1309 | |
|---|
| 1310 | batchp=buffup; |
|---|
| 1311 | |
|---|
| 1312 | for (xdir=0, dirloop=MFRnvf; dirloop--; xdir++) { |
|---|
| 1313 | tag=DIRtag(xdir); |
|---|
| 1314 | |
|---|
| 1315 | #if TRACED1 |
|---|
| 1316 | printf("\\begin tag %d..",tag); GETCHAR; |
|---|
| 1317 | #if GETX |
|---|
| 1318 | if (xgetx != '\n') exit(1); |
|---|
| 1319 | #endif |
|---|
| 1320 | #endif |
|---|
| 1321 | |
|---|
| 1322 | for (imap=0, dmap=RDBvderp; dmap; dmap=dmap->nextp, imap++) { |
|---|
| 1323 | rngok=1; |
|---|
| 1324 | #if TRACEDx |
|---|
| 1325 | printf("+++ 3. dsfld=%s=%d \n",dmap->dsfld,dmap->dsflds); |
|---|
| 1326 | #endif |
|---|
| 1327 | if (dmap->drngs) |
|---|
| 1328 | for (rngok=0, irng=0; irng < dmap->drngs; irng++) { |
|---|
| 1329 | if (tag < dmap->drng1[irng]) continue; |
|---|
| 1330 | if (tag > dmap->drng2[irng]) continue; |
|---|
| 1331 | rngok=1; break; |
|---|
| 1332 | } |
|---|
| 1333 | if (rngok) break; |
|---|
| 1334 | } /* end decod list */ |
|---|
| 1335 | |
|---|
| 1336 | if (rngok) { |
|---|
| 1337 | if (dectrace) { |
|---|
| 1338 | printf("recdecex - irec=%"_LD_"=%s/%"_LD_" %s,%02x=%c,", |
|---|
| 1339 | irec,RDBname,MFRmfn,dmap->ddbnp,dmap->drdlm,dmap->drdlm); |
|---|
| 1340 | printf("%d,",tag); |
|---|
| 1341 | for (i=0; i < dmap->dsflds; i++) { |
|---|
| 1342 | printf("^%c",dmap->dsfld[i]); |
|---|
| 1343 | if (dmap->dsfldx[i]) |
|---|
| 1344 | printf("+%c=%"_LD_,dmap->dsfldx[i],dmap->dsfldv[i]); |
|---|
| 1345 | } |
|---|
| 1346 | printf("\n"); |
|---|
| 1347 | } |
|---|
| 1348 | #if TRACED2 |
|---|
| 1349 | *batchp='\0'; |
|---|
| 1350 | printf("\\buffup=%s",buffup); GETCHAR; |
|---|
| 1351 | #endif |
|---|
| 1352 | sprintf((char *)batchp,"H%u 000000 ",tag); batchp+=strlen((CONST char *)batchp); |
|---|
| 1353 | fuplenp=batchp-1-6; fuplen=0; /* fuplenp points to 000000 */ |
|---|
| 1354 | sfldn=0; sfldc='\0'; |
|---|
| 1355 | for (p=(unsigned char *)FIELDP(xdir), fldloop=DIRlen(xdir); fldloop; sfldn++) { |
|---|
| 1356 | rchar = ~(dmap->drdlm); |
|---|
| 1357 | #if TRACED2 |
|---|
| 1358 | printf("\\fldloop=%d *p=%c",fldloop,*p); GETCHAR; |
|---|
| 1359 | #endif |
|---|
| 1360 | for (sfldlen=1, q=p+1, n=fldloop-1; n--; q++) |
|---|
| 1361 | if (*q == SFLDCHR || (rchar = *q) == dmap->drdlm) break; |
|---|
| 1362 | else sfldlen++; |
|---|
| 1363 | if (sfldlen > 1) |
|---|
| 1364 | if (*p == SFLDCHR) { |
|---|
| 1365 | sfldc = *(p+1); |
|---|
| 1366 | sfldlen-=2; |
|---|
| 1367 | memcpy(batchp,p,2); batchp+=2; p+=2; |
|---|
| 1368 | fldloop-=2; fuplen+=2; |
|---|
| 1369 | } |
|---|
| 1370 | if (sfldlen == 0) continue; |
|---|
| 1371 | |
|---|
| 1372 | if (dmap->dsflds == 0) /* no dsfld */ |
|---|
| 1373 | check=0; |
|---|
| 1374 | else |
|---|
| 1375 | if (sfldn == 0) |
|---|
| 1376 | for (n=0; n < dmap->dsflds; n++) |
|---|
| 1377 | if (dmap->dsfld[n] == '*') { |
|---|
| 1378 | check=0; break; |
|---|
| 1379 | } |
|---|
| 1380 | |
|---|
| 1381 | if (check) { |
|---|
| 1382 | c=isisuctab[(int)sfldc]; |
|---|
| 1383 | for (n=0; n < dmap->dsflds; n++) |
|---|
| 1384 | if (dmap->dsfld[n] == c) { |
|---|
| 1385 | check=0; break; |
|---|
| 1386 | } |
|---|
| 1387 | if (check) { |
|---|
| 1388 | memcpy(batchp,p,n=sfldlen); batchp+=n; p+=n; |
|---|
| 1389 | fldloop-=n; fuplen+=n; |
|---|
| 1390 | continue; |
|---|
| 1391 | } |
|---|
| 1392 | } |
|---|
| 1393 | |
|---|
| 1394 | match=0; |
|---|
| 1395 | for (valmfn=0L, q=p, left=n=sfldlen; n--; q++, left--) |
|---|
| 1396 | if (isdigit(*q)) valmfn=valmfn*10+((int)*q-(int)'0'); |
|---|
| 1397 | else break; |
|---|
| 1398 | leftp=q; |
|---|
| 1399 | |
|---|
| 1400 | if (rchar == dmap->drdlm) sfldlen++; /* skip */ |
|---|
| 1401 | #if TRACED2 |
|---|
| 1402 | printf("\\valmfn=%"_LD_,valmfn); GETCHAR; |
|---|
| 1403 | #endif |
|---|
| 1404 | /* decode */ |
|---|
| 1405 | if (valmfn > 0L) { |
|---|
| 1406 | #if CICPP |
|---|
| 1407 | if (!decrecp) { |
|---|
| 1408 | decrecp=new RECSTRU(cisisxp); |
|---|
| 1409 | } |
|---|
| 1410 | #else /* CICPP */ |
|---|
| 1411 | if (!decridx) { |
|---|
| 1412 | for (decridx=maxnrec; decridx--; ) |
|---|
| 1413 | if (!vrecp[decridx]) break; |
|---|
| 1414 | if (decridx > 0) recallok(decridx,MAXMFRL); |
|---|
| 1415 | else valmfn=0L; /* ok */ |
|---|
| 1416 | } |
|---|
| 1417 | #endif /* CICPP */ |
|---|
| 1418 | } |
|---|
| 1419 | if (valmfn > 0L) { /* ok */ |
|---|
| 1420 | #if CICPP |
|---|
| 1421 | R2RECORD(decrecp,(char *)dmap->ddbnp,valmfn); |
|---|
| 1422 | #else /* CICPP */ |
|---|
| 1423 | R2RECORD(decridx,dmap->ddbnp,valmfn); |
|---|
| 1424 | #endif /* CICPP */ |
|---|
| 1425 | if (R2MFRnvf == 0) R2RECrc=RCLDEL; |
|---|
| 1426 | if (R2RECrc == RCNORMAL) { /* break */ |
|---|
| 1427 | nmatchs++; match=1; |
|---|
| 1428 | #if TRACED2 |
|---|
| 1429 | printf("\\match #%"_LD_,nmatchs); GETCHAR; |
|---|
| 1430 | #endif |
|---|
| 1431 | if (dectrace) |
|---|
| 1432 | printf("recdecex - %s/%"_LD_"/%d[%d] = %s/%"_LD_, |
|---|
| 1433 | RDBname,MFRmfn,DIRtag(xdir),xdir, |
|---|
| 1434 | R2RDBname,R2MFRmfn); |
|---|
| 1435 | decxdir=0; |
|---|
| 1436 | for (; decxdir < R2MFRnvf; decxdir++) { |
|---|
| 1437 | if (dectrace) printf("/%d",R2DIRtag(decxdir)); |
|---|
| 1438 | q=(unsigned char *)R2FIELDP(decxdir); |
|---|
| 1439 | memcpy(batchp,q,n=R2DIRlen(decxdir)); |
|---|
| 1440 | batchp+=n; fuplen+=n; |
|---|
| 1441 | if (left) { |
|---|
| 1442 | memcpy(batchp,leftp,left); |
|---|
| 1443 | batchp+=left; fuplen+=left; |
|---|
| 1444 | } |
|---|
| 1445 | } |
|---|
| 1446 | if (dectrace) printf("\n"); |
|---|
| 1447 | p+=sfldlen; |
|---|
| 1448 | fldloop-=sfldlen; |
|---|
| 1449 | } |
|---|
| 1450 | } |
|---|
| 1451 | |
|---|
| 1452 | if (!match) { |
|---|
| 1453 | #if TRACED2 |
|---|
| 1454 | printf("\\no match"); GETCHAR; |
|---|
| 1455 | #endif |
|---|
| 1456 | |
|---|
| 1457 | if (rchar == dmap->drdlm) { |
|---|
| 1458 | memcpy(batchp,p,n=sfldlen-1); batchp+=n; p+=n+1; |
|---|
| 1459 | fldloop-=n+1; fuplen+=n; |
|---|
| 1460 | } |
|---|
| 1461 | else { |
|---|
| 1462 | memcpy(batchp,p,n=sfldlen); batchp+=n; p+=n; |
|---|
| 1463 | fldloop-=n; fuplen+=n; |
|---|
| 1464 | } |
|---|
| 1465 | } |
|---|
| 1466 | |
|---|
| 1467 | if (rchar == dmap->drdlm) { |
|---|
| 1468 | sprintf((char *)fuplenp,"%06d",fuplen); *(fuplenp+6)=' '; |
|---|
| 1469 | sprintf((char *)batchp,"H%u 000000 ",tag); batchp+=strlen((CONST char *)batchp); |
|---|
| 1470 | fuplenp=batchp-1-6; fuplen=0; /* fuplenp ... 000000 */ |
|---|
| 1471 | sfldn=0; sfldc='\0'; |
|---|
| 1472 | } |
|---|
| 1473 | |
|---|
| 1474 | } /* end field chrs */ |
|---|
| 1475 | |
|---|
| 1476 | sprintf((char *)fuplenp,"%06d",fuplen); *(fuplenp+6)=' '; |
|---|
| 1477 | |
|---|
| 1478 | } /* end rngok */ |
|---|
| 1479 | |
|---|
| 1480 | else { /* just copy it */ |
|---|
| 1481 | sprintf((char *)batchp,"H%u %u ",tag,DIRlen(xdir)); batchp+=strlen((CONST char *)batchp); |
|---|
| 1482 | memcpy(batchp,FIELDP(xdir),DIRlen(xdir)); batchp+=DIRlen(xdir); |
|---|
| 1483 | } |
|---|
| 1484 | |
|---|
| 1485 | } /* end dir entries */ |
|---|
| 1486 | |
|---|
| 1487 | *batchp='\0'; |
|---|
| 1488 | |
|---|
| 1489 | /* deallocate decridx */ |
|---|
| 1490 | #if CICPP |
|---|
| 1491 | if (decrecp) delete decrecp; |
|---|
| 1492 | #else /* CICPP */ |
|---|
| 1493 | if (decridx) { |
|---|
| 1494 | FREE(vrecp[decridx]); vrecp[decridx]=NULL; nrecs--; |
|---|
| 1495 | } |
|---|
| 1496 | #endif /* CICPP */ |
|---|
| 1497 | |
|---|
| 1498 | if (nmatchs) { |
|---|
| 1499 | |
|---|
| 1500 | MFRmfrl=MFRbase=LEADER; MFRnvf=0; |
|---|
| 1501 | |
|---|
| 1502 | #if CICPP |
|---|
| 1503 | p=(unsigned char *)recp->xfldupdat((char *)buffup); |
|---|
| 1504 | #else /* CICPP */ |
|---|
| 1505 | p=fldupdat(irec,buffup); |
|---|
| 1506 | #endif /* CICPP */ |
|---|
| 1507 | |
|---|
| 1508 | if (p) { |
|---|
| 1509 | /* printf("*** fldupdat='%s'\n",p); */ |
|---|
| 1510 | fatal("recdecex/fldupdat"); |
|---|
| 1511 | } |
|---|
| 1512 | } |
|---|
| 1513 | |
|---|
| 1514 | /* deallocate working area */ |
|---|
| 1515 | #if CICPP |
|---|
| 1516 | delete[] buffup; |
|---|
| 1517 | #else /* CICPP */ |
|---|
| 1518 | FREE(buffup); |
|---|
| 1519 | #endif /* CICPP */ |
|---|
| 1520 | |
|---|
| 1521 | if (dectrace) |
|---|
| 1522 | printf("recdecex - irec=%"_LD_"/%"_LD_" matchs=%"_LD_" +%"_LD_"\n", |
|---|
| 1523 | irec,MFRmfn,nmatchs,CORELEFT()); |
|---|
| 1524 | |
|---|
| 1525 | return(nmatchs); |
|---|
| 1526 | } |
|---|
| 1527 | |
|---|
| 1528 | #if CICPP |
|---|
| 1529 | #undef CORELEFT |
|---|
| 1530 | #endif /* CICPP */ |
|---|
| 1531 | |
|---|
| 1532 | #undef GETCHAR |
|---|
| 1533 | |
|---|
| 1534 | #endif /* RECDECO */ |
|---|