root/trunk/decsex.c

Revision 389, 15.9 kB (checked in by heitor.barbieri, 3 weeks ago)

essage first commit

Line 
1/* ------------------------------ decsex.c ----------------------------- */
2
3/* ========================================================================
4        Link file generation for the MeSH Headings explotion
5
6        Assumes DECSEX having 701/702/703 terms and 720 root
7        Assumes DECS inverted as 1 0 mpl,(v720/)
8
9        Author: decs9b.c/AOT, Oct 15 1991 (Prof-day)
10======================================================================== */
11
12#include <stdio.h>
13#include <string.h>
14
15#define TRACE   0
16#define TRACEUC 0
17#define TRACEAC 0
18
19#include "cisis.h"      /* CISIS Interface */
20#include "cirun.h"      /* runtime area and defines by AOT */
21
22
23/*                     DECS & DECSEX                                 */
24
25#define TOFFSET 700
26#define TAGTING (1+TOFFSET)
27#define TAGTESP (2+TOFFSET)
28#define TAGTPOR (3+TOFFSET)
29#define TAGCATN 720
30#define TAGQUAL 14
31
32char wxchr[] = { 'i','e','p' };         /* 1st = Author */
33
34#define wx(tag) (tag-TOFFSET-1)
35
36LONGX totpost;
37
38/*unsigned char isisuctab[256];     agora ja' esta' em cirun.h */
39
40FILE *fplst;
41int fdout[3];
42
43char *dexp,*dbnp;
44char *uctp,*decs,*l1Ip,*l2Ip,*l1Ep,*l2Ep,*l1Pp,*l2Pp;
45
46int vfd[3][2];
47LONGX vc[3][2] = { 0,0,0,0,0,0 };
48
49unsigned char line[BUFSIZ];
50unsigned char explode[LE2+LE2];
51
52int explen;
53int lreclx;
54LONGX count,ecount;
55
56#if MPE
57int vlrecl[2];
58char dcb0[32],dcb1[32],dcbx[32],mpe='"';
59#else
60char mpe=' ';
61#endif
62
63
64LONGX dexirec;       /* indice registro decs */
65LONGX irec;          /* indice registro decs */
66LONGX itrm;          /* indice invertido decs */
67LONGX itrmin;        /* indice invertido entrada */
68
69int parmtrace=1;
70
71#define PARMPFXL        1
72#define PARMSFXL        3
73#define PARMSFXC        '/'
74
75#define PARMNPFX        1
76char parmvpfx[PARMNPFX][LE2+1] = { "." };
77
78#if PC && !DOS32BITS
79#define OPEN30 1
80#endif
81#if OPEN30
82union REGS      d33_regs;
83struct SREGS    d33_sregs;
84unsigned short  d33_newax,d33_n;
85#endif
86
87
88/* prototypes */
89#if ANSI
90void keepinfo(LONGX mfn, int tag, char pfx[], int plen, char sfx[], int slen);
91int outlink(LONGX mfn, int tag, int occ, int cnt, char *kp, int klen, int sn);
92int catlink(char *lnkp,char *pfx,int pl,char *midp,int ml,char *sfx,int sl);
93LONGX copylnks(char pfxcall[]);
94#else
95void keepinfo();
96int outlink();
97int catlink();
98LONGX copylnks();
99#endif
100
101
102/* main */
103#if ANSI
104void main (int argc, char *argv[])
105#else
106main(argc,argv)
107int argc;
108char *argv[];
109#endif
110{
111    RECSTRU *recp;      /* RECORD */
112    TRMSTRU *trmp;      /* TERM/NXTERM */
113    LONGX mfn;
114
115    int occ,ncats,ipfx;
116
117    FILE *fp;
118
119    LONGX xtell;
120    int loop,n,expcatlen,found;
121    unsigned char *p,expcat[LE2+1];
122
123
124#if OPEN30
125        d33_n=32;
126        d33_regs.h.ah = 0x67;   /* Set handle count */
127        d33_regs.x.bx = d33_n;  /* no of handles */
128        d33_newax=intdosx(&d33_regs,&d33_regs,&d33_sregs);
129        if (d33_regs.x.cflag)
130            fprintf(stderr,"AX = %04x [%02d]\n",d33_newax,d33_n);
131#endif
132
133    if (argc < 10) {
134        printf("%s",cicopyr("Utility MDL/DECSEX"));
135        printf("\n");
136        printf("decsex <decsex> <dbB> <decs> <I1> <I2> <E1> <E2> <P1> <P2> \n");
137        printf("\n");
138        printf("generate exploded I/E/P link files for authorized english mesh headings \n");
139        printf("from mdlif <dbB>, according to decs <decs> \n");
140        printf("\n");
141        printf("\n");
142        exit(1);
143    }
144
145    /* get parms */
146    dexp=argv[1];
147    dbnp=argv[2];
148    decs=argv[3];
149    l1Ip=argv[4];
150    l2Ip=argv[5];
151    l1Ep=argv[6];
152    l2Ep=argv[7];
153    l1Pp=argv[8];
154    l2Pp=argv[9];
155
156    /* ve master decsex */
157    RECORD((dexirec=nrecs),dexp,0L);
158
159    /* ve invertido de entrada */
160    TERM((itrmin=ntrms),dbnp,"!");
161
162    xtell=MF0nxtmfn;
163    xtell/=10;
164    if (xtell < 1)
165        xtell=1;
166
167
168    /* ve master decs */
169    RECORD((irec=nrecs),decs,0L);
170
171    /* ve invertido decs */
172    TERM((itrm=ntrms),decs,"!");
173
174    /* open link files */
175#if PC || UNIX
176    vfd[0][0]=creat(l1Ip,0644);
177    vfd[0][1]=creat(l2Ip,0644);
178    vfd[1][0]=creat(l1Ep,0644);
179    vfd[1][1]=creat(l2Ep,0644);
180    vfd[2][0]=creat(l1Pp,0644);
181    vfd[2][1]=creat(l2Pp,0644);
182#endif
183#if MPE
184    vlrecl[0]=25+LE1;
185    vlrecl[1]=25+LE2;
186    sprintf(dcb0,"R%d Bl%d",vlrecl[0],8192/vlrecl[0]);
187    sprintf(dcb1,"R%d Bl%d",vlrecl[1],8192/vlrecl[1]);
188    vfd[0][0]=open(l1Ip,O_WRONLY|O_CREAT|O_TRUNC|O_MPEOPTS,0644,dcb0);
189    vfd[0][1]=open(l2Ip,O_WRONLY|O_CREAT|O_TRUNC|O_MPEOPTS,0644,dcb1);
190    vfd[1][0]=open(l1Ep,O_WRONLY|O_CREAT|O_TRUNC|O_MPEOPTS,0644,dcb0);
191    vfd[1][1]=open(l2Ep,O_WRONLY|O_CREAT|O_TRUNC|O_MPEOPTS,0644,dcb1);
192    vfd[2][0]=open(l1Pp,O_WRONLY|O_CREAT|O_TRUNC|O_MPEOPTS,0644,dcb0);
193    vfd[2][1]=open(l2Pp,O_WRONLY|O_CREAT|O_TRUNC|O_MPEOPTS,0644,dcb1);
194#endif
195    if (vfd[0][0] == EOF) fatal(l1Ip);
196    if (vfd[0][1] == EOF) fatal(l2Ip);
197    if (vfd[1][0] == EOF) fatal(l1Ep);
198    if (vfd[1][1] == EOF) fatal(l2Ep);
199    if (vfd[2][0] == EOF) fatal(l1Pp);
200    if (vfd[2][1] == EOF) fatal(l2Pp);
201
202    /* open lst and output files */
203    if ((fplst   =fopen("decsex.lst", "w")) == NULL) fatal("decsex.lst");
204
205    lreclx = 6+1 + LE2+1 + 1+1+1+1 + LE2+1 + 2+1+3+1 + 2+1+2+1+1+1+1+1 + 9+1;
206
207#if PC || UNIX
208    if ((fdout[0]=creat("decsexI.lst",0644)) == EOF) fatal("decsexI.lst");
209    if ((fdout[1]=creat("decsexE.lst",0644)) == EOF) fatal("decsexE.lst");
210    if ((fdout[2]=creat("decsexP.lst",0644)) == EOF) fatal("decsexP.lst");
211#endif
212#if MPE
213    sprintf(dcbx,"R%d Bl%d",lreclx,8192/lreclx);
214    fdout[0]=open("decsexI.lst",O_WRONLY|O_CREAT|O_TRUNC|O_MPEOPTS,0644,dcbx);
215    fdout[1]=open("decsexE.lst",O_WRONLY|O_CREAT|O_TRUNC|O_MPEOPTS,0644,dcbx);
216    fdout[2]=open("decsexP.lst",O_WRONLY|O_CREAT|O_TRUNC|O_MPEOPTS,0644,dcbx);
217#endif
218    if (fdout[0] == EOF) fatal("decsexI.lst");
219    if (fdout[1] == EOF) fatal("decsexE.lst");
220    if (fdout[2] == EOF) fatal("decsexP.lst");
221
222
223    ecount=count=0;
224
225    /*
226        processing loop
227    */
228
229    RECORD(dexirec,dexp,mfn=1L);
230    for(; RECrc != RCEOF; RECORD(dexirec,dexp,++mfn)) {
231
232        if ((++count % xtell) == 0)
233            fprintf(stderr,"+++ %"_LD_" \n",count);
234
235        if (RECrc != RCNORMAL) continue;
236
237        ncats=nocc(dexirec,TAGCATN);
238        if (ncats <= 0) fatal("CAT not found");
239        if (nocc(dexirec,TAGTING) != 1) fatal("ING invalid");
240        if (nocc(dexirec,TAGTESP) != 1) fatal("ESP invalid");
241        if (nocc(dexirec,TAGTPOR) != 1) fatal("POR invalid");
242
243        recfield(explode,dexirec,TAGTING,1,NULL);
244        explen=strlen(explode);
245        for (p=explode; *p; p++) *p = isisuctab[*p];
246
247        for (occ=1; occ <= ncats; occ++) {
248
249            recfield(expcat,dexirec,TAGCATN,occ,NULL);
250            expcatlen=strlen(expcat);
251            for (p=expcat; *p; p++) *p = isisuctab[*p];
252
253            TERM(itrm,decs,expcat); found=0;
254            while (memcmp(TRMkey,expcat,expcatlen) == 0) {
255                if (TRMxytotp != 1) {
256                    printf("+++ %"_LD_" %s -> %"_LD_" postings !!\n",
257                                        count,TRMkey,TRMxytotp);
258                    fprintf(fplst,
259                           "+++ %"_LD_" %s -> %"_LD_" postings !!\n",
260                                        count,TRMkey,TRMxytotp);
261                    fatal("aborted");
262                }
263
264                RECORD(irec,decs,posting(itrm,1L));
265                if (RECrc != RCNORMAL) fatal("DECS/RECrc");
266
267                copylnks("");
268                for (ipfx=0; ipfx < PARMNPFX; ipfx++)
269                    copylnks(parmvpfx[ipfx]);
270
271                found++;
272                NXTERM(itrm);
273            }
274
275            if (!found) {
276                printf(       "+++ %"_LD_" %s -> Not found\n",count,expcat);
277                fprintf(fplst,"+++ %"_LD_" %s -> Not found\n",count,expcat);
278                fatal("aborted");
279            }
280
281        } /* end occ */
282
283    } /* end main loop */
284
285    printf(
286      "+++ terms=%"_LD_" err=%"_LD_" I=%"_LD_"+%"_LD_" E=%"_LD_"+%"_LD_" P=%"_LD_"+%"_LD_" \n",
287        count,ecount,
288        vc[0][0],vc[0][1],vc[1][0],vc[1][1],vc[2][0],vc[2][1]);
289
290    fprintf(fplst,
291      "+++ terms=%"_LD_" err=%"_LD_" I=%"_LD_"+%"_LD_" E=%"_LD_"+%"_LD_" P=%"_LD_"+%"_LD_" \n",
292        count,ecount,
293        vc[0][0],vc[0][1],vc[1][0],vc[1][1],vc[2][0],vc[2][1]);
294
295    exit(0);
296}
297
298
299
300#if ANSI
301LONGX copylnks(char pfxcall[])
302#else
303LONGX copylnks(pfxcall)
304char pfxcall[];
305#endif
306{
307    int xdir,len,hn,n,x;
308    LONGX nok;
309    unsigned char *hp,*p;
310    RECSTRU *recp;
311    TRMSTRU *trmp;
312
313    int pfxlen,n2,sfxlen;
314    unsigned char inpkey[LE2+LE2],linkkey[LE2+LE2],sfxkey[LE2+LE2];
315
316#if TRACE
317    int tracn;
318    unsigned char *tracp;
319#endif
320
321    char areaqq[LE2+1];
322
323
324    if (nocc(dexirec,TAGTING) != 1) fatal("DECSEX/TAGTING");
325    if (nocc(dexirec,TAGTESP) != 1) fatal("DECSEX/TAGTESP");
326    if (nocc(dexirec,TAGTPOR) != 1) fatal("DECSEX/TAGTPOR");
327
328    if (nocc(irec,TAGTING) != 1) fatal("DECS/TAGTING");
329
330    recp=vrecp[irec];
331
332    if (nocc(irec,TAGQUAL) == 1) {
333        areaqq[0]='/';
334        recfield(areaqq+1,irec,TAGQUAL,1,NULL);
335        hp=areaqq;
336        hn=strlen(hp);
337        if (hn != 3) fatal("DECSEX/TAGQUAL");
338    }
339    else {
340        xdir=fieldx(irec,TAGTING,1);
341        hp=FIELDP(xdir);
342        hn=DIRlen(xdir);
343    }
344
345    if (*hp <= ' ') {
346        printf("+++ Adjusting key %"_LD_" \n",MFRmfn);
347#if TRACE
348for (tracp=hp, tracn=hn; tracn--; tracp++)
349 printf("%c(%02x)",*tracp,*tracp);
350getchar();
351#endif
352        while (*hp <= ' ')
353            if (hn > 1) {
354                hp++; hn--;
355            }
356            else {
357                printf("*** Rejected key -  mfn: %"_LD_" \n",MFRmfn);
358                fatal("aborted");
359           }
360    }
361
362    pfxlen=0;
363    if (*pfxcall) {
364        strcpy(inpkey,pfxcall);
365        pfxlen=strlen(pfxcall);
366    }
367    memcpy(inpkey+pfxlen,hp,hn);
368    inpkey[pfxlen+hn]='\0';
369    for (p=inpkey; *p; p++) *p = isisuctab[*p];
370
371    nok=0;
372    for (TERM(itrmin,dbnp,inpkey); TRMrc != RCEOF; NXTERM(itrmin)) {
373
374        if (memcmp(TRMkey,inpkey,pfxlen+hn)) break;
375
376        totpost=TRMxytotp;
377
378        len=n2=(TRMlcase)?LE2:LE1;
379
380        if (pfxlen) n2-=pfxlen;
381
382        for (p=TRMkey+len; n2; ) if (*--p == ' ') n2--; else break;
383
384        sfxkey[0]='\0'; sfxlen=0;
385        for (n=n2; n > 1; n--, p--) {
386            if (*p == PARMSFXC) {
387                sfxlen = n2 - n + 1;
388                memcpy(sfxkey,p,sfxlen);
389                sfxkey[sfxlen]='\0';
390                n2 = n - 1;
391                break;
392            }
393        }
394
395        if (n2 != hn) continue;
396        nok++;
397
398        if (parmtrace == 1) {
399            printf("+++ %s%s = %s",pfxcall,explode,pfxcall);
400            for (p=TRMkey+pfxlen, n=n2; n--; p++) printf("%c",*p);
401            printf("%s psts=%"_LD_" [%"_LD_"]\n",sfxkey,totpost,nok);
402        }
403
404        if (parmtrace == 2) {
405            printf("+++ pfx=%d=%s trm=%d=",pfxlen,pfxcall,n2);
406            for (p=TRMkey+pfxlen, n=n2; n--; p++) printf("%c",*p);
407            printf(" sfx=%d=%s psts=%"_LD_" [%"_LD_"]\n",sfxlen,sfxkey,totpost,nok);
408        }
409
410        n=0;
411        if (memcmp(TRMkey+pfxlen,hp,hn)) n++;
412
413        if (n && parmtrace != 2) {
414            printf("+++ pfx=%d=%s trm=%d=",pfxlen,pfxcall,n2);
415            for (p=TRMkey+pfxlen, n=n2; n--; p++) printf("%c",*p);
416            printf(" sfx=%d=%s psts=%"_LD_" [%"_LD_"]\n",sfxlen,sfxkey,totpost,nok);
417        }
418        if (n) {
419            printf("+++ key=%d=",hn);
420            for (; hn--; hp++) printf("%c",*hp);
421            printf(" cat=%d=%s \n",explen,explode);
422            fatal("copylnks/bug1");
423        }
424
425        len=catlink(linkkey,pfxcall,pfxlen,explode,explen,sfxkey,sfxlen);
426
427        while (posting(itrmin,TRMpost+1) > 0)
428            outlink(TRMpmfn,TRMptag,TRMpocc,TRMpcnt,linkkey,len,wx(TAGTING));
429
430        recp=vrecp[dexirec];
431
432        x=fieldx(dexirec,TAGTESP,1);
433        len=catlink(linkkey,pfxcall,pfxlen,FIELDP(x),DIRlen(x),sfxkey,sfxlen);
434        for (p=linkkey; *p; p++) *p = isisuctab[*p];
435        outlink(VMFRmfn(dexirec),TAGTESP,1,0,linkkey,len,wx(TAGTESP));
436
437        x=fieldx(dexirec,TAGTPOR,1);
438        len=catlink(linkkey,pfxcall,pfxlen,FIELDP(x),DIRlen(x),sfxkey,sfxlen);
439        for (p=linkkey; *p; p++) *p = isisuctab[*p];
440        outlink(VMFRmfn(dexirec),TAGTPOR,1,0,linkkey,len,wx(TAGTPOR));
441
442        keepinfo(VMFRmfn(dexirec),TAGTESP,pfxcall,pfxlen,sfxkey,sfxlen);
443        keepinfo(VMFRmfn(dexirec),TAGTPOR,pfxcall,pfxlen,sfxkey,sfxlen);
444
445    } /* end NXTERM */
446
447
448    if (!nok) {
449        /* fatal("copylnks/bug2"); */
450        printf(       "+++ %s%s = %s -> Not used\n",pfxcall,explode,inpkey);
451        fprintf(fplst,"+++ %s%s = %s -> Not used\n",pfxcall,explode,inpkey);
452        ecount++;
453    }
454
455    return(nok);
456
457}
458
459
460
461#if ANSI
462int catlink(char *lnkp,char *pfx,int pl,char *midp,int ml,char *sfx,int sl)
463#else
464int catlink(lnkp,pfx,pl,midp,ml,sfx,sl)
465char *lnkp;
466char *pfx;
467int pl;
468char *midp;
469int ml;
470char *sfx;
471int sl;
472#endif
473{
474    char *p;
475    int len;
476
477    p=lnkp;
478    *p='\0';
479
480    if (pl) memcpy(p,pfx,pl);
481    len=pl;
482
483    memcpy(p+len,midp,ml);
484    len+=ml;
485
486    if (sl) memcpy(p+len,sfx,sl);
487    len+=sl;
488
489    lnkp[len]='\0';
490
491    return(len);
492}
493
494
495
496
497#if ANSI
498void keepinfo(LONGX mfn, int tag, char pfx[], int plen, char sfx[], int slen)
499#else
500void keepinfo(mfn,tag,pfx,plen,sfx,slen)
501LONGX mfn;
502int tag;
503char pfx[];
504int plen;
505char sfx[];
506int slen;
507#endif
508{
509    unsigned char *linp,*p;
510    int hn,loop;
511
512    linp=line;
513    sprintf(linp,"%06"_LD_"|",mfn); linp+=strlen(linp);
514
515    if (PARMPFXL+explen+PARMSFXL > LE2) fatal(explode);
516    strcpy(linp,explode); linp+=explen;
517    for (loop=LE2-explen; loop--; ) *linp++ = ' ';
518    *linp++ = '|';
519
520    sprintf(linp,"%c|a|",isisuctab[wxchr[wx(tag)]]);
521    linp+=strlen(linp);
522
523    recfield(linp,dexirec,tag,1,NULL);
524    for (hn=0, p=linp; *p; p++) {
525        *p = isisuctab[*p]; hn++;
526    }
527    if (PARMPFXL+hn+PARMSFXL > LE2) fatal(linp);
528    linp+=hn;
529    for (loop=LE2-hn; loop--; ) *linp++ = ' ';
530    *linp++ = '|';
531
532    if (plen > PARMPFXL) fatal("keepinfo/pfx/length");
533    memcpy(linp,pfx,plen); linp+=plen;
534    for (loop=PARMPFXL-plen+1; loop--; ) *linp++ = ' '; /* one for ifp1 */
535    *linp++ = '|';
536
537    if (slen > PARMSFXL) fatal("keepinfo/sfx/length");
538    memcpy(linp,sfx,slen); linp+=slen;
539    for (loop=PARMSFXL-slen; loop--; ) *linp++ = ' ';
540    *linp++ = '|';
541
542    sprintf(linp,"%2d|%2d|%d|%d|%9"_LD_"\n",explen,hn,plen,slen,totpost);
543#if TRACE
544*linp='\0';
545printf("strlen=%d lreclx=%d\n%s.",strlen(line),lreclx,line);
546#endif
547    if (CIWRITE(fdout[wx(tag)],line,lreclx) != lreclx)
548        fatal("copylnks/write");
549}
550
551
552
553#if ANSI
554int outlink(LONGX mfn, int tag, int occ, int cnt, char *keyp, int keylen,
555                                                                        int sn)
556#else
557int outlink(mfn,tag,occ,cnt,keyp,keylen,sn)
558LONGX mfn;
559int tag;
560int occ;
561int cnt;
562char *keyp;
563int keylen;
564int sn;
565#endif
566{
567    unsigned char *p,*q;
568    int loop,rc,lrecl;
569
570#if TRACE
571    printf("+++ outlink - %8"_LD_"/%5d/%4d/%4d/%d ",mfn,tag,occ,cnt,sn);
572    for (q=keyp, loop=keylen; loop--; q++) printf("%c",*q);
573    printf("\n");
574#endif
575
576    /* setup link record */
577    lrecl=0;
578    if (keylen > LE2) keylen=LE2;
579    rc = (keylen <= LE1) ? 0 : 1;
580
581#if UNIX
582/*
5831234567890123456 1234567 12345 1234 1234
584IS 0262-0898           1   300    1    1
585JC DFC                 1   300    1    3
586IS 0262-0898           2   300    1    1
587*/
588    for (p=&line[lrecl], q=keyp, loop=keylen; loop--; ) *p++ = *q++;
589    lrecl+=keylen;
590    loop=(rc)?LE2-keylen:LE1-keylen;
591    memset(p,' ',loop); p+=loop; lrecl+=loop;
592    sprintf(&line[lrecl]," %8"_LD_" %5d %4d %4d",mfn,tag,occ,cnt);
593    p+=25; lrecl+=25;
594    *p='\n';
595    lrecl++;
596#endif /* UNIX */
597
598#if MPE || PC
599#if MPE
600    line[lrecl++]='\0';
601    sprintf(&line[lrecl],"%8"_LD_" %5d %4d %4d ",mfn,tag,occ,cnt);
602    lrecl+=25;
603#endif
604#if PC
605    sprintf(&line[lrecl],"%1"_LD_" %1d %1d %1d ",mfn,tag,occ,cnt);
606    lrecl+=strlen(&line[lrecl]);
607#endif
608    for (p=&line[lrecl], q=keyp, loop=keylen; loop--; ) *p++ = *q++;
609    lrecl+=keylen;
610#if MPE
611    for (loop=vlrecl[rc]-lrecl; loop--; ) {
612        *p++ = ' ';
613        lrecl++;
614    }
615    *p='\n';
616    lrecl++;
617#endif
618#endif /* MPE || PC */
619
620    /* write it */
621    if (CIWRITE(vfd[sn][rc],line,lrecl) != lrecl) {
622        printf("mfn/tag/occ/cnt: %"_LD_"/%d/%d/%d \n",mfn,tag,occ,cnt);
623        fatal("outlink/write");
624    }
625
626    vc[sn][rc]++;
627
628    return(rc);
629}
Note: See TracBrowser for help on using the browser.