| 1 | /* ------------------------------ decs9a.c ----------------------------- */ |
|---|
| 2 | |
|---|
| 3 | /* ======================================================================== |
|---|
| 4 | Link file generation for the MeSH Headings field |
|---|
| 5 | |
|---|
| 6 | Author: decs8b.c/AOT, Oct 23 1990 |
|---|
| 7 | ======================================================================== */ |
|---|
| 8 | |
|---|
| 9 | #include <stdio.h> |
|---|
| 10 | #include <string.h> |
|---|
| 11 | |
|---|
| 12 | #include "cisis.h" /* CISIS Interface */ |
|---|
| 13 | #include "cirun.h" /* runtime area and defines by AOT */ |
|---|
| 14 | |
|---|
| 15 | #define TRACE 0 |
|---|
| 16 | #define TRACEUC 0 |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | /* DECS */ |
|---|
| 20 | |
|---|
| 21 | FILE *fplst; |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | char *dbnp; |
|---|
| 25 | char *uctp,*decs,*l1Sp,*l2Sp,*l1Np,*l2Np; |
|---|
| 26 | int parmmyb=0; |
|---|
| 27 | int vfd[2][2]; |
|---|
| 28 | LONGX vc[2][2] = { 0,0,0,0 }; |
|---|
| 29 | char line[BUFSIZ],key1[BUFSIZ],key2[BUFSIZ]; |
|---|
| 30 | char key0[BUFSIZ]; |
|---|
| 31 | char vetflag[BUFSIZ]; |
|---|
| 32 | #define NOTFLAGGED 0 |
|---|
| 33 | LONGX countx=0; |
|---|
| 34 | LONGX itrmw = MAXNTRM-3; |
|---|
| 35 | |
|---|
| 36 | #if MPE |
|---|
| 37 | int vlrecl[2]; |
|---|
| 38 | char dcb[32]; |
|---|
| 39 | #endif |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | /* prototypes */ |
|---|
| 43 | #if ANSI |
|---|
| 44 | int outlink(LONGX mfn, int tag, int occ, int cnt, char *kp, int klen, int sn); |
|---|
| 45 | int genlk1(int occ, int tag, RECSTRU *recp, int xdir); |
|---|
| 46 | int genlk2(int occ, int tag, RECSTRU *recp, int xdir); |
|---|
| 47 | #else |
|---|
| 48 | int outlink(); |
|---|
| 49 | int genlk1(); |
|---|
| 50 | int genlk2(); |
|---|
| 51 | #endif |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | /* main */ |
|---|
| 55 | #if ANSI |
|---|
| 56 | void main (int argc, char *argv[]) |
|---|
| 57 | #else |
|---|
| 58 | main(argc,argv) |
|---|
| 59 | int argc; |
|---|
| 60 | char *argv[]; |
|---|
| 61 | #endif |
|---|
| 62 | { |
|---|
| 63 | RECSTRU *recp; /* mandatory for defines REC RDB MF0 MFR DIR, FIELDP */ |
|---|
| 64 | LONGX irec; /* indice registro de entrada */ |
|---|
| 65 | LONGX mfn; |
|---|
| 66 | |
|---|
| 67 | int xdir,occ,dirloop; |
|---|
| 68 | |
|---|
| 69 | LONGX count,xtell; |
|---|
| 70 | int loop,n; |
|---|
| 71 | unsigned char *p; |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | if (argc < 7 || argc > 8) { |
|---|
| 75 | printf("%s",cicopyr("Utility MDL/DECS9A")); |
|---|
| 76 | printf("\n"); |
|---|
| 77 | printf("decs9a <dbB> <decs> <lkfil1> <lkfil2> <lkfil1> <lkfil2> [+myb] \n"); |
|---|
| 78 | printf("\n"); |
|---|
| 79 | printf("generate link files for mesh headings/qualifiers \n"); |
|---|
| 80 | printf("from mdlmf <dbB>, according to decs <decs> \n"); |
|---|
| 81 | printf("\n"); |
|---|
| 82 | printf("\n"); |
|---|
| 83 | exit(1); |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | /* get parms */ |
|---|
| 87 | dbnp=argv[1]; |
|---|
| 88 | decs=argv[2]; |
|---|
| 89 | l1Sp=argv[3]; |
|---|
| 90 | l2Sp=argv[4]; |
|---|
| 91 | l1Np=argv[5]; |
|---|
| 92 | l2Np=argv[6]; |
|---|
| 93 | if (argc > 7) if (strcmp(argv[7],"+myb")) fatal(argv[7]); else parmmyb=1; |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | /* |
|---|
| 97 | ve entrada |
|---|
| 98 | */ |
|---|
| 99 | RECORD((irec=nrecs),dbnp,0L); |
|---|
| 100 | if ((xtell=MF0nxtmfn/10) < 1) xtell=1; |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | /* open link files */ |
|---|
| 105 | #if MPE |
|---|
| 106 | vlrecl[0]=25+LE1; |
|---|
| 107 | vlrecl[1]=25+LE2; |
|---|
| 108 | #endif |
|---|
| 109 | #if PC || UNIX |
|---|
| 110 | vfd[0][0]=creat(l1Sp,0644); |
|---|
| 111 | vfd[1][0]=creat(l2Sp,0644); |
|---|
| 112 | vfd[0][1]=creat(l1Np,0644); |
|---|
| 113 | vfd[1][1]=creat(l2Np,0644); |
|---|
| 114 | #endif |
|---|
| 115 | #if MPE |
|---|
| 116 | sprintf(dcb,"R%d Bl%d",vlrecl[0],8192/vlrecl[0]); |
|---|
| 117 | vfd[0][0]=open(l1Sp,O_WRONLY|O_CREAT|O_TRUNC|O_MPEOPTS,0644,dcb); |
|---|
| 118 | sprintf(dcb,"R%d Bl%d",vlrecl[1],8192/vlrecl[1]); |
|---|
| 119 | vfd[1][0]=open(l2Sp,O_WRONLY|O_CREAT|O_TRUNC|O_MPEOPTS,0644,dcb); |
|---|
| 120 | sprintf(dcb,"R%d Bl%d",vlrecl[0],8192/vlrecl[0]); |
|---|
| 121 | vfd[0][1]=open(l1Np,O_WRONLY|O_CREAT|O_TRUNC|O_MPEOPTS,0644,dcb); |
|---|
| 122 | sprintf(dcb,"R%d Bl%d",vlrecl[1],8192/vlrecl[1]); |
|---|
| 123 | vfd[1][1]=open(l2Np,O_WRONLY|O_CREAT|O_TRUNC|O_MPEOPTS,0644,dcb); |
|---|
| 124 | #endif |
|---|
| 125 | if (vfd[0][0] == EOF) |
|---|
| 126 | fatal(l1Sp); |
|---|
| 127 | if (vfd[1][0] == EOF) |
|---|
| 128 | fatal(l2Sp); |
|---|
| 129 | if (vfd[0][1] == EOF) |
|---|
| 130 | fatal(l1Np); |
|---|
| 131 | if (vfd[1][1] == EOF) |
|---|
| 132 | fatal(l2Np); |
|---|
| 133 | |
|---|
| 134 | /* open log */ |
|---|
| 135 | if ((fplst=fopen("decs9a.lst","w")) == NULL) |
|---|
| 136 | fatal("decs9a.lst"); |
|---|
| 137 | |
|---|
| 138 | count=0; |
|---|
| 139 | |
|---|
| 140 | /* |
|---|
| 141 | processing loop |
|---|
| 142 | */ |
|---|
| 143 | |
|---|
| 144 | for (mfn=1; (RECORD(irec,dbnp,mfn))->recrc != RCEOF; mfn++) { |
|---|
| 145 | |
|---|
| 146 | if (RECrc != RCNORMAL) |
|---|
| 147 | continue; |
|---|
| 148 | |
|---|
| 149 | for (xdir=0; xdir < MFRnvf; xdir++) |
|---|
| 150 | if (DIRtag(xdir) == 870 || DIRtag(xdir) == 880) |
|---|
| 151 | for (p=FIELDP(xdir), loop=DIRlen(xdir); loop--; ) |
|---|
| 152 | *p++ = isisuctab[*p]; |
|---|
| 153 | |
|---|
| 154 | for (xdir=0; xdir < MFRnvf; xdir++) vetflag[xdir]=NOTFLAGGED; |
|---|
| 155 | for (occ=0, xdir=0, dirloop=MFRnvf; dirloop--; xdir++) |
|---|
| 156 | if (DIRtag(xdir) == 870 || DIRtag(xdir) == 880) { |
|---|
| 157 | if (vetflag[xdir] == NOTFLAGGED) |
|---|
| 158 | genlk1(occ+1,DIRtag(xdir),recp,xdir); |
|---|
| 159 | occ++; |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | for (xdir=0; xdir < MFRnvf; xdir++) vetflag[xdir]=NOTFLAGGED; |
|---|
| 163 | for (occ=0, xdir=0, dirloop=MFRnvf; dirloop--; xdir++) |
|---|
| 164 | if (DIRtag(xdir) == 870 || DIRtag(xdir) == 880) { |
|---|
| 165 | if (vetflag[xdir] == NOTFLAGGED) |
|---|
| 166 | genlk2(occ+1,DIRtag(xdir),recp,xdir); |
|---|
| 167 | occ++; |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | if ((++count % xtell) == 0) |
|---|
| 171 | printf( |
|---|
| 172 | "+++ mfn / recs / links: %"_LD_" / %"_LD_" / S=%"_LD_"+%"_LD_" N=%"_LD_"+%"_LD_" (%"_LD_") \n", |
|---|
| 173 | mfn,count,vc[0][0],vc[0][1],vc[1][0],vc[1][1],countx); |
|---|
| 174 | } |
|---|
| 175 | |
|---|
| 176 | printf("+++ recs / links: %"_LD_"/%"_LD_" / S=%"_LD_"+%"_LD_" N=%"_LD_"+%"_LD_" (%"_LD_") \n", |
|---|
| 177 | mfn,count,vc[0][0],vc[0][1],vc[1][0],vc[1][1],countx); |
|---|
| 178 | |
|---|
| 179 | exit(0); |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | |
|---|
| 183 | |
|---|
| 184 | |
|---|
| 185 | #if ANSI |
|---|
| 186 | int outlink(LONGX mfn, int tag, int occ, int cnt, char *keyp, int keylen, |
|---|
| 187 | int sn) |
|---|
| 188 | #else |
|---|
| 189 | int outlink(mfn,tag,occ,cnt,keyp,keylen,sn) |
|---|
| 190 | LONGX mfn; |
|---|
| 191 | int tag; |
|---|
| 192 | int occ; |
|---|
| 193 | int cnt; |
|---|
| 194 | char *keyp; |
|---|
| 195 | int keylen; |
|---|
| 196 | int sn; |
|---|
| 197 | #endif |
|---|
| 198 | { |
|---|
| 199 | unsigned char *p,*q; |
|---|
| 200 | int loop,rc,lrecl; |
|---|
| 201 | |
|---|
| 202 | #if TRACE |
|---|
| 203 | printf("+++ outlink - %8"_LD_"/%5d/%4d/%4d/%d ",mfn,tag,occ,cnt,sn); |
|---|
| 204 | for (q=keyp, loop=keylen; loop--; q++) printf("%c",*q); |
|---|
| 205 | printf("\n"); |
|---|
| 206 | #endif |
|---|
| 207 | |
|---|
| 208 | /* setup link record */ |
|---|
| 209 | lrecl=0; |
|---|
| 210 | if (keylen > LE2) keylen=LE2; |
|---|
| 211 | rc = (keylen <= LE1) ? 0 : 1; |
|---|
| 212 | |
|---|
| 213 | #if UNIX |
|---|
| 214 | /* |
|---|
| 215 | 1234567890123456 1234567 12345 1234 1234 |
|---|
| 216 | IS 0262-0898 1 300 1 1 |
|---|
| 217 | JC DFC 1 300 1 3 |
|---|
| 218 | IS 0262-0898 2 300 1 1 |
|---|
| 219 | */ |
|---|
| 220 | for (p=&line[lrecl], q=keyp, loop=keylen; loop--; ) *p++ = *q++; |
|---|
| 221 | lrecl+=keylen; |
|---|
| 222 | loop=(rc)?LE2-keylen:LE1-keylen; |
|---|
| 223 | memset(p,' ',loop); p+=loop; lrecl+=loop; |
|---|
| 224 | sprintf(&line[lrecl]," %8"_LD_" %5d %4d %4d",mfn,tag,occ,cnt); |
|---|
| 225 | p+=25; lrecl+=25; |
|---|
| 226 | *p='\n'; |
|---|
| 227 | lrecl++; |
|---|
| 228 | #endif /* UNIX */ |
|---|
| 229 | |
|---|
| 230 | #if MPE || PC |
|---|
| 231 | #if MPE |
|---|
| 232 | line[lrecl++]='\0'; |
|---|
| 233 | sprintf(&line[lrecl],"%8"_LD_" %5d %4d %4d ",mfn,tag,occ,cnt); |
|---|
| 234 | lrecl+=25; |
|---|
| 235 | #endif |
|---|
| 236 | #if PC |
|---|
| 237 | sprintf(&line[lrecl],"%1"_LD_" %1d %1d %1d ",mfn,tag,occ,cnt); |
|---|
| 238 | lrecl+=strlen(&line[lrecl]); |
|---|
| 239 | #endif |
|---|
| 240 | for (p=&line[lrecl], q=keyp, loop=keylen; loop--; ) *p++ = *q++; |
|---|
| 241 | lrecl+=keylen; |
|---|
| 242 | #if MPE |
|---|
| 243 | for (loop=vlrecl[rc]-lrecl; loop--; ) { |
|---|
| 244 | *p++ = ' '; |
|---|
| 245 | lrecl++; |
|---|
| 246 | } |
|---|
| 247 | *p='\n'; |
|---|
| 248 | lrecl++; |
|---|
| 249 | #endif |
|---|
| 250 | #endif /* MPE || PC */ |
|---|
| 251 | |
|---|
| 252 | /* write it */ |
|---|
| 253 | if (write(vfd[rc][sn],line,lrecl) != lrecl) { |
|---|
| 254 | printf("mfn/tag/occ/cnt: %"_LD_"/%d/%d/%d \n",mfn,tag,occ,cnt); |
|---|
| 255 | fatal((rc)?l2Sp:l1Sp); |
|---|
| 256 | } |
|---|
| 257 | |
|---|
| 258 | vc[rc][sn]++; |
|---|
| 259 | |
|---|
| 260 | return(rc); |
|---|
| 261 | } |
|---|
| 262 | |
|---|
| 263 | |
|---|
| 264 | |
|---|
| 265 | |
|---|
| 266 | #if ANSI |
|---|
| 267 | int genlk1(int occ, int tag, RECSTRU *recp, int xdir) |
|---|
| 268 | #else |
|---|
| 269 | int genlk1(occ,tag,recp,xdir) |
|---|
| 270 | int occ; |
|---|
| 271 | int tag; |
|---|
| 272 | RECSTRU *recp; |
|---|
| 273 | int xdir; |
|---|
| 274 | #endif |
|---|
| 275 | { |
|---|
| 276 | unsigned char *fldp; |
|---|
| 277 | FFI len,xlen; |
|---|
| 278 | int hn,qn,xloop,xn,cnt,n,sn,cn,chktag,n2,prim870; |
|---|
| 279 | unsigned char *hp,*qp,*xp,*p,*cp; |
|---|
| 280 | TRMSTRU *trmp; |
|---|
| 281 | |
|---|
| 282 | |
|---|
| 283 | fldp=FIELDP(xdir); cnt=1; |
|---|
| 284 | |
|---|
| 285 | len=DIRlen(xdir); |
|---|
| 286 | hp=subfldp(fldp,'h',&len); |
|---|
| 287 | hn=(hp)?subfldn(hp,len):0; |
|---|
| 288 | |
|---|
| 289 | len=DIRlen(xdir); |
|---|
| 290 | cp=subfldp(fldp,'c',&len); |
|---|
| 291 | cn=(cp)?subfldn(cp,len):0; |
|---|
| 292 | |
|---|
| 293 | len=DIRlen(xdir); |
|---|
| 294 | qp=subfldp(fldp,'q',&len); |
|---|
| 295 | qn=(qp)?subfldn(qp,len):0; |
|---|
| 296 | |
|---|
| 297 | if (hn == 0) { |
|---|
| 298 | fprintf(stderr,"mfn/tag: %"_LD_"/%d\n",MFRmfn,tag); |
|---|
| 299 | if (parmmyb) return(occ); /* myb */ |
|---|
| 300 | fatal("^h missing"); |
|---|
| 301 | } |
|---|
| 302 | if (cn != 0 && cn != 1) { |
|---|
| 303 | fprintf(stderr,"mfn/tag: %"_LD_"/%d\n",MFRmfn,tag); |
|---|
| 304 | if (parmmyb) return(occ); /* myb - 28.04.92 */ |
|---|
| 305 | fatal("^c invalid"); |
|---|
| 306 | } |
|---|
| 307 | if (qn != 0 && qn != 2) { |
|---|
| 308 | fprintf(stderr,"mfn/tag: %"_LD_"/%d\n",MFRmfn,tag); |
|---|
| 309 | if (parmmyb) return(occ); /* myb - 28.04.92 */ |
|---|
| 310 | fatal("^q invalid"); |
|---|
| 311 | } |
|---|
| 312 | |
|---|
| 313 | if (*hp <= ' ') { |
|---|
| 314 | printf("+++ Adjusting key %"_LD_"/%d/%d/%d \n",MFRmfn,tag,occ,cnt); |
|---|
| 315 | while (*hp <= ' ') |
|---|
| 316 | if (hn > 1) { |
|---|
| 317 | hp++; hn--; |
|---|
| 318 | } |
|---|
| 319 | else { |
|---|
| 320 | printf("*** Rejected key - mfn/tag/occ/cnt: %"_LD_"/%d/%d/%d \n", |
|---|
| 321 | MFRmfn,tag,occ,cnt); |
|---|
| 322 | return(occ); |
|---|
| 323 | } |
|---|
| 324 | } |
|---|
| 325 | if (qn > 0 && *qp <= ' ') { |
|---|
| 326 | printf("+++ Adjusting sub: %"_LD_"/%d/%d/%d \n",MFRmfn,tag,occ,cnt); |
|---|
| 327 | while (*qp <= ' ') |
|---|
| 328 | if (qn > 1) { |
|---|
| 329 | qp++; qn--; |
|---|
| 330 | } |
|---|
| 331 | else break; |
|---|
| 332 | } |
|---|
| 333 | |
|---|
| 334 | |
|---|
| 335 | if (cn == 1 && (*cp == '3' || *cp == '2')) { |
|---|
| 336 | memcpy(key1,"CT?",3); |
|---|
| 337 | memcpy(key1+3,hp,hn); |
|---|
| 338 | p=key1; n=hn+3; |
|---|
| 339 | chktag=1; |
|---|
| 340 | } |
|---|
| 341 | else { |
|---|
| 342 | p=hp; n=hn; |
|---|
| 343 | chktag=0; |
|---|
| 344 | } |
|---|
| 345 | if (chktag) |
|---|
| 346 | return(occ); /* NLM checks duplication */ |
|---|
| 347 | |
|---|
| 348 | sn = 0; |
|---|
| 349 | memcpy(line,p,n); line[n]='\0'; |
|---|
| 350 | if ((TERM(itrmw,decs,line))->trmrc != RCNORMAL) { |
|---|
| 351 | printf("+++ mfn=%"_LD_" tag=%d key=%s -> Not found\n", |
|---|
| 352 | MFRmfn,DIRtag(xdir),line); |
|---|
| 353 | fprintf(fplst,"mfn=%06"_LD_" tag=%03d key=%s -> Not found\n", |
|---|
| 354 | MFRmfn,DIRtag(xdir),line); |
|---|
| 355 | } |
|---|
| 356 | |
|---|
| 357 | if (n > LE2-1-(1+2)) { |
|---|
| 358 | printf("+++ mfn=%"_LD_" tag=%d key=%s -> %d chars\n", |
|---|
| 359 | MFRmfn,DIRtag(xdir),line,n); |
|---|
| 360 | fprintf(fplst,"mfn=%06"_LD_" tag=%03d key=%s -> %d chars\n", |
|---|
| 361 | MFRmfn,DIRtag(xdir),line,n); |
|---|
| 362 | n = LE2-1-(1+2); |
|---|
| 363 | } |
|---|
| 364 | |
|---|
| 365 | |
|---|
| 366 | outlink(MFRmfn,0,occ,cnt,p,n,sn); |
|---|
| 367 | prim870=0; |
|---|
| 368 | |
|---|
| 369 | if (DIRtag(xdir) == 870) { |
|---|
| 370 | memcpy(key2,".",1); n2=1; |
|---|
| 371 | memcpy(key2+1,p,n); n2+=n; |
|---|
| 372 | outlink(MFRmfn,1,occ,cnt,key2,n2,sn); |
|---|
| 373 | prim870=1; |
|---|
| 374 | } |
|---|
| 375 | else |
|---|
| 376 | memcpy(key2,p,n2=n); |
|---|
| 377 | |
|---|
| 378 | memcpy(key2+n2,"/",1); |
|---|
| 379 | if (qn) |
|---|
| 380 | memcpy(key2+n2+1,qp,qn); |
|---|
| 381 | if (DIRtag(xdir) == 870) |
|---|
| 382 | outlink(MFRmfn,20,occ,cnt,key2+1,n2+1+qn-1,sn); |
|---|
| 383 | outlink(MFRmfn,21,occ,cnt,key2,n2+1+qn,sn); |
|---|
| 384 | |
|---|
| 385 | |
|---|
| 386 | for (xloop=xdir+1; xloop < MFRnvf; xloop++) { |
|---|
| 387 | |
|---|
| 388 | occ++; |
|---|
| 389 | if (DIRtag(xloop) != 870 && DIRtag(xloop) != 880) |
|---|
| 390 | continue; |
|---|
| 391 | |
|---|
| 392 | if (vetflag[xloop] == NOTFLAGGED) { /* if not yet flagged */ |
|---|
| 393 | |
|---|
| 394 | fldp=FIELDP(xloop); |
|---|
| 395 | xlen=DIRlen(xloop); |
|---|
| 396 | xp=subfldp(fldp,'h',&xlen); |
|---|
| 397 | xn=(xp)?subfldn(xp,xlen):0; |
|---|
| 398 | if (xn == 0) { |
|---|
| 399 | fprintf(stderr,"mfn/tag: %"_LD_"/%d\n",MFRmfn,tag); |
|---|
| 400 | if (parmmyb) return(occ); /* myb */ |
|---|
| 401 | fatal("^h missing"); |
|---|
| 402 | } |
|---|
| 403 | |
|---|
| 404 | if (*xp <= ' ') { |
|---|
| 405 | printf("+++ Adjusting key %"_LD_"/%d/%d/%d (compare) \n", |
|---|
| 406 | MFRmfn,tag,occ,cnt); |
|---|
| 407 | while (*xp <= ' ') |
|---|
| 408 | if (xn > 1) { |
|---|
| 409 | xp++; xn--; |
|---|
| 410 | } |
|---|
| 411 | else break; |
|---|
| 412 | } |
|---|
| 413 | if (xn != hn) |
|---|
| 414 | continue; |
|---|
| 415 | if (memcmp(hp,xp,xn) != 0) |
|---|
| 416 | continue; |
|---|
| 417 | |
|---|
| 418 | xlen=DIRlen(xloop); |
|---|
| 419 | qp=subfldp(fldp,'q',&xlen); |
|---|
| 420 | qn=(qp)?subfldn(qp,xlen):0; |
|---|
| 421 | if (qn != 0 && qn != 2) { |
|---|
| 422 | fprintf(stderr,"mfn/tag: %"_LD_"/%d\n",MFRmfn,tag); |
|---|
| 423 | if (parmmyb) return(occ); /* myb */ |
|---|
| 424 | fatal("^q invalid"); |
|---|
| 425 | } |
|---|
| 426 | |
|---|
| 427 | if (qn > 0 && *qp <= ' ') { |
|---|
| 428 | printf("+++ Adjusting sub: %"_LD_"/%d/%d/%d \n", |
|---|
| 429 | MFRmfn,tag,occ,cnt); |
|---|
| 430 | while (*qp <= ' ') |
|---|
| 431 | if (qn > 1) { |
|---|
| 432 | qp++; qn--; |
|---|
| 433 | } |
|---|
| 434 | else break; |
|---|
| 435 | } |
|---|
| 436 | |
|---|
| 437 | if (DIRtag(xloop) == 870) { |
|---|
| 438 | memcpy(key2,".",1); n2=1; |
|---|
| 439 | memcpy(key2+1,p,n); n2+=n; |
|---|
| 440 | if (!prim870) { |
|---|
| 441 | outlink(MFRmfn,1,occ,cnt,key2,n2,sn); |
|---|
| 442 | prim870=1; |
|---|
| 443 | } |
|---|
| 444 | } |
|---|
| 445 | else |
|---|
| 446 | memcpy(key2,p,n2=n); |
|---|
| 447 | |
|---|
| 448 | memcpy(key2+n2,"/",1); |
|---|
| 449 | if (qn) |
|---|
| 450 | memcpy(key2+n2+1,qp,qn); |
|---|
| 451 | if (DIRtag(xloop) == 870) |
|---|
| 452 | outlink(MFRmfn,20,occ,cnt,key2+1,n2+1+qn-1,sn); |
|---|
| 453 | outlink(MFRmfn,21,occ,cnt,key2,n2+1+qn,sn); |
|---|
| 454 | |
|---|
| 455 | |
|---|
| 456 | #if 0 |
|---|
| 457 | memcpy(key2+n2,"/",1); |
|---|
| 458 | if (qn) |
|---|
| 459 | memcpy(key2+n2+1,qp,qn); |
|---|
| 460 | outlink(MFRmfn,20,occ,cnt,key2+1,n2+1+qn-1,sn); |
|---|
| 461 | if (DIRtag(xloop) == 870) |
|---|
| 462 | outlink(MFRmfn,21,occ,cnt,key2,n2+1+qn,sn); |
|---|
| 463 | #endif |
|---|
| 464 | vetflag[xloop] = !NOTFLAGGED; /* flag it */ |
|---|
| 465 | |
|---|
| 466 | } |
|---|
| 467 | } |
|---|
| 468 | |
|---|
| 469 | return(occ); |
|---|
| 470 | } |
|---|
| 471 | |
|---|
| 472 | |
|---|
| 473 | #if ANSI |
|---|
| 474 | int genlk2(int occ, int tag, RECSTRU *recp, int xdir) |
|---|
| 475 | #else |
|---|
| 476 | int genlk2(occ,tag,recp,xdir) |
|---|
| 477 | int occ; |
|---|
| 478 | int tag; |
|---|
| 479 | RECSTRU *recp; |
|---|
| 480 | int xdir; |
|---|
| 481 | #endif |
|---|
| 482 | { |
|---|
| 483 | unsigned char *fldp; |
|---|
| 484 | FFI len,xlen; |
|---|
| 485 | int hn,qn,xloop,xn,cnt,sn,cn,n2,primok; |
|---|
| 486 | unsigned char *hp,*qp,*xp,*cp; |
|---|
| 487 | |
|---|
| 488 | |
|---|
| 489 | fldp=FIELDP(xdir); cnt=1; |
|---|
| 490 | |
|---|
| 491 | len=DIRlen(xdir); |
|---|
| 492 | hp=subfldp(fldp,'h',&len); |
|---|
| 493 | hn=(hp)?subfldn(hp,len):0; |
|---|
| 494 | |
|---|
| 495 | len=DIRlen(xdir); |
|---|
| 496 | cp=subfldp(fldp,'c',&len); |
|---|
| 497 | cn=(cp)?subfldn(cp,len):0; |
|---|
| 498 | |
|---|
| 499 | len=DIRlen(xdir); |
|---|
| 500 | qp=subfldp(fldp,'q',&len); |
|---|
| 501 | qn=(qp)?subfldn(qp,len):0; |
|---|
| 502 | |
|---|
| 503 | if (hn == 0) { |
|---|
| 504 | fprintf(stderr,"mfn/tag: %"_LD_"/%d\n",MFRmfn,tag); |
|---|
| 505 | if (parmmyb) return(occ); /* myb */ |
|---|
| 506 | fatal("^h missing"); |
|---|
| 507 | } |
|---|
| 508 | if (cn != 0 && cn != 1) { |
|---|
| 509 | fprintf(stderr,"mfn/tag: %"_LD_"/%d\n",MFRmfn,tag); |
|---|
| 510 | if (parmmyb) return(occ); /* myb */ |
|---|
| 511 | fatal("^c invalid"); |
|---|
| 512 | } |
|---|
| 513 | if (qn != 0 && qn != 2) { |
|---|
| 514 | fprintf(stderr,"mfn/tag: %"_LD_"/%d\n",MFRmfn,tag); |
|---|
| 515 | if (parmmyb) return(occ); /* myb */ |
|---|
| 516 | fatal("^q invalid"); |
|---|
| 517 | } |
|---|
| 518 | |
|---|
| 519 | if (*hp <= ' ') { |
|---|
| 520 | printf("+++ Adjusting2 key %"_LD_"/%d/%d/%d \n",MFRmfn,tag,occ,cnt); |
|---|
| 521 | while (*hp <= ' ') |
|---|
| 522 | if (hn > 1) { |
|---|
| 523 | hp++; hn--; |
|---|
| 524 | } |
|---|
| 525 | else { |
|---|
| 526 | printf("*** Rejected key - mfn/tag/occ/cnt: %"_LD_"/%d/%d/%d \n", |
|---|
| 527 | MFRmfn,tag,occ,cnt); |
|---|
| 528 | return(occ); |
|---|
| 529 | } |
|---|
| 530 | } |
|---|
| 531 | if (qn > 0 && *qp <= ' ') { |
|---|
| 532 | printf("+++ Adjusting2 sub: %"_LD_"/%d/%d/%d \n",MFRmfn,tag,occ,cnt); |
|---|
| 533 | while (*qp <= ' ') |
|---|
| 534 | if (qn > 1) { |
|---|
| 535 | qp++; qn--; |
|---|
| 536 | } |
|---|
| 537 | else break; |
|---|
| 538 | } |
|---|
| 539 | |
|---|
| 540 | |
|---|
| 541 | if (cn == 1 && (*cp == '3' || *cp == '2')) |
|---|
| 542 | return(occ); /* NLM checks duplication */ |
|---|
| 543 | |
|---|
| 544 | |
|---|
| 545 | if (qn == 0) |
|---|
| 546 | return(occ); |
|---|
| 547 | |
|---|
| 548 | sn=1; |
|---|
| 549 | |
|---|
| 550 | primok=0; n2=0; |
|---|
| 551 | if (DIRtag(xdir) == 870) { |
|---|
| 552 | memcpy(key2,".",n2=1); |
|---|
| 553 | primok=1; |
|---|
| 554 | } |
|---|
| 555 | |
|---|
| 556 | memcpy(key2+n2,"/",1); |
|---|
| 557 | if (qn) |
|---|
| 558 | memcpy(key2+n2+1,qp,qn); |
|---|
| 559 | if (DIRtag(xdir) == 870) |
|---|
| 560 | outlink(MFRmfn,30,occ,cnt,key2+1,n2+1+qn-1,sn); |
|---|
| 561 | outlink(MFRmfn,31,occ,cnt,key2,n2+1+qn,sn); |
|---|
| 562 | |
|---|
| 563 | |
|---|
| 564 | for (xloop=xdir+1; xloop < MFRnvf; xloop++) { |
|---|
| 565 | |
|---|
| 566 | occ++; |
|---|
| 567 | if (DIRtag(xloop) != 870 && DIRtag(xloop) != 880) |
|---|
| 568 | continue; |
|---|
| 569 | |
|---|
| 570 | if (vetflag[xloop] == NOTFLAGGED) { /* if not yet flagged */ |
|---|
| 571 | |
|---|
| 572 | fldp=FIELDP(xloop); |
|---|
| 573 | |
|---|
| 574 | xlen=DIRlen(xloop); |
|---|
| 575 | xp=subfldp(fldp,'q',&xlen); |
|---|
| 576 | xn=(xp)?subfldn(xp,xlen):0; |
|---|
| 577 | if (xn != 0 && xn != 2) { |
|---|
| 578 | fprintf(stderr,"mfn/tag: %"_LD_"/%d\n",MFRmfn,tag); |
|---|
| 579 | if (parmmyb) return(occ); /* myb */ |
|---|
| 580 | fatal("^q invalid"); |
|---|
| 581 | } |
|---|
| 582 | |
|---|
| 583 | if (xn > 0 && *xp <= ' ') { |
|---|
| 584 | printf("+++ Adjusting2 sub: %"_LD_"/%d/%d/%d \n", |
|---|
| 585 | MFRmfn,tag,occ,cnt); |
|---|
| 586 | while (*xp <= ' ') |
|---|
| 587 | if (xn > 1) { |
|---|
| 588 | xp++; xn--; |
|---|
| 589 | } |
|---|
| 590 | else break; |
|---|
| 591 | } |
|---|
| 592 | if (xn != qn) |
|---|
| 593 | continue; |
|---|
| 594 | if (memcmp(qp,xp,xn) != 0) |
|---|
| 595 | continue; |
|---|
| 596 | |
|---|
| 597 | |
|---|
| 598 | if (DIRtag(xloop) == 870) |
|---|
| 599 | if (!primok) { |
|---|
| 600 | memcpy(key1,".",1); |
|---|
| 601 | memcpy(key1+1,key2,n2+1+qn); |
|---|
| 602 | outlink(MFRmfn,31,occ,cnt,key1,n2+1+qn+1,sn); |
|---|
| 603 | primok=1; |
|---|
| 604 | } |
|---|
| 605 | |
|---|
| 606 | vetflag[xloop] = !NOTFLAGGED; /* flag it */ |
|---|
| 607 | |
|---|
| 608 | } |
|---|
| 609 | } |
|---|
| 610 | |
|---|
| 611 | return(occ); |
|---|
| 612 | } |
|---|