root/trunk/decsmesh.c

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

essage first commit

Line 
1/* --------------------------- decsmesh.c ----------------------------- */
2
3/* ========================================================================
4        Field "DESCRIPTOR" DeCS versus MeSH
5
6        Author: decs9a.c/AOT/RSP, April 1, 1991 (MIT B-day)
7       
8        Alter: AOT, 30/06/96
9        1. PC
10        2. Uses std uctab
11        3. CISIS Copyright
12
13======================================================================== */
14
15#include <stdio.h>
16#include <fcntl.h>
17#include <string.h>
18
19#define TRACE1 01
20#define TRACE2 01
21#define TRACE3 0
22#define TRACE4 0
23
24#include "cisis.h"       /* CISIS Interface */
25#include "cirun.h"       /* runtime area and defines by AOT */
26
27#define MAXLIN 100
28#define MAXCOL 60
29
30
31unsigned char buffup[MAXMFRL+MAXMFRL];
32unsigned char key[BUFSIZ];
33unsigned char id[BUFSIZ];
34
35unsigned char cats[2][MAXLIN][MAXCOL+1];
36unsigned char *exclpfxp[MAXLIN];
37int exclpfxl[MAXLIN];
38int nexclpfxs;
39
40#if ANSI
41int getcat(int idx, LONGX irec, int tag);
42int storcats(int idx, int tag);
43#else
44int getcat();
45int storcats();
46#endif
47
48/* main */
49#if ANSI
50void main (int argc, char *argv[])
51#else
52main(argc,argv)
53int argc;
54char *argv[];
55#endif
56{
57    RECSTRU *recp;      /* RECORD */
58    TRMSTRU *trmp;      /* TERM/NXTERM */
59    LONGX irec1,irec2,upcrec,upirec;
60    LONGX itrm2;
61    LONGX mfn1,mfn2;
62
63    char *dbn1,*dbn2,*dbnout;
64
65    int tag1,tag2,tagcat1,tagcat2;
66    int occ1,occ2;
67    LONGX count,errors,empty,xtell;
68    int xdir,loop,n,len,xd,lx;
69    unsigned char *batchp,*p;
70
71    if (argc < 6) {
72        printf("%s",cicopyr("Utility DECSMESH"));
73        printf("\n");
74        printf("decsmesh <db1> <t1,c1> <db2> <t2,c2> <dbout> [<x1>[<x2>]..]\n");
75        printf("\n");
76        printf(" <db1>                  -> decs/mesh master file (*)\n");
77        printf(" <t1,c1>                -> tag_term,tag_cat \n");
78        printf(" <db2>                  -> mesh/decs data base \n");
79        printf(" <t2,c2>                -> tag_term,tag_cat \n");
80        printf(" <db1out>               -> master file for errors \n");
81        printf(" <x1>                   -> exclude cats with prefix <x1> \n");
82        printf(" <x2>                   -> exclude cats with prefix <x2> \n");
83        printf("  .                         \n");
84        printf("  .                         \n");
85        printf(" \n");
86        printf("       (*) if decs \n");
87        printf("              if present 107 \n");
88        printf("                  process term=term+\" (NON MESH)\" \n");
89        printf("              else \n");
90        printf("                  skip term if 106 = p or s \n");
91        printf("           else   \n");
92        printf("              always process term \n");
93        printf(" \n");
94        exit(1);
95    }
96
97    /* get parms */
98    dbn1=argv[1];
99    if (sscanf(argv[2],"%d,%d",&tag1,&tagcat1) != 2) fatal(argv[2]);
100
101    dbn2=argv[3];
102    if (sscanf(argv[4],"%d,%d",&tag2,&tagcat2) != 2) fatal(argv[4]);
103
104    dbnout=argv[5];
105
106    for (nexclpfxs=0, loop=6; loop < argc; loop++) {
107        exclpfxp[nexclpfxs]=argv[loop]; exclpfxl[nexclpfxs]=strlen(argv[loop]);
108        nexclpfxs++;
109    }
110
111    /* ve entrada 1 */
112    RECORD(irec1=nrecs,dbn1,0L);
113
114    xtell=MF0nxtmfn/10;
115    if (xtell < 1)
116        xtell=1;
117
118    /* ve entrada 2 */
119    RECORD(irec2=nrecs,dbn2,0L);
120    TERM(itrm2=ntrms,dbn2,"!");
121
122
123    /* create saida */
124    recisis0(dbnout);
125    record((upcrec=nrecs),dbnout,0L);
126    record((upirec=nrecs),dbnout,1L);
127
128    count=errors=empty=0;
129
130    /*
131        processing loop
132    */
133    for (RECORD(irec1,dbn1,mfn1=1L); ; RECORD(irec1,dbn1,++mfn1)) {
134
135        /* tell */
136        if ((++count % xtell) == 0)
137            printf("+++ %"_LD_" (%"_LD_,%"_LD_")\n",count,errors,empty);
138
139        if (RECrc == RCEOF) break;
140        if (RECrc != RCNORMAL) continue;
141
142        /* get key */
143        if ((xdir=fieldx(irec1,tag1,1)) < 0) {
144            /* printf("*** mfn=%"_LD_" tag=%d -> Absent\n",mfn1,tag1); */
145            /* fatal("Tag1 absent"); */
146            empty++;
147            continue;
148        }
149        len=DIRlen(xdir);
150
151        /* find it */
152        if (strcmp(dbn1,"decs") == 0) {
153
154            if(fieldx(irec1,107,1) >= 0) {
155                 memcpy(key,FIELDP(xdir),len);
156                 key[len]='\0';
157                 strcat(key," (NON MESH)");
158                 for (p=key;*p; p++) *p = isisuctab[*p];
159            }
160            else {
161                  id[0]='\0';
162                  if ((xd=fieldx(irec1,106,1)) >= 0) {
163                     lx=DIRlen(xd);
164                     memcpy(id,FIELDP(xd),lx);
165                     id[lx]='\0';
166                  }
167                  if((strcmp(id,"p")!=0) && (strcmp(id,"s")!=0)) {
168                     memcpy(key,FIELDP(xdir),len);
169                     key[len]='\0';
170                     for (p=key, loop=len; loop--; p++) *p = isisuctab[*p];
171                  } else continue;
172
173            }
174        }
175        else {
176             memcpy(key,FIELDP(xdir),len);
177             key[len]='\0';
178             for (p=key, loop=len; loop--; p++) *p = isisuctab[*p];
179           }
180
181        TERM(itrm2,dbn2,key);
182        mfn2=posting(itrm2,1L);
183
184
185        /* setup output */
186        record(upirec,dbnout,mfn1); /* get a PDEL record */
187        VMFRstatus(upirec)=ACTIVE; /* make it ACTIVE */
188        sprintf(buffup,"H 1 %d ",len); batchp=buffup+strlen(buffup);
189        memcpy(batchp,key,len); batchp+=len;
190        *batchp='\0';
191        if ((p=fldupdat(upirec,buffup)) != NULL) fatal(p);
192
193        if (TRMrc == RCNORMAL && TRMxytotp != 1) {
194            sprintf(buffup,"a2/%s MFN %"_LD_" -> %"_LD_" postings/",
195                                                dbn2,mfn2,TRMxytotp);
196            if (fldupdat(upirec,buffup)) fatal("fldupdat");
197            recupdat(upcrec,upirec); errors++;
198            continue;
199        }
200
201        if (TRMrc != RCNORMAL) {
202            sprintf(buffup,"a2/Not found/");
203            if (fldupdat(upirec,buffup)) fatal("fldupdat");
204            recupdat(upcrec,upirec); errors++;
205            continue;
206        }
207
208        /* get corresponding */
209        RECORD(irec2,dbn2,mfn2);
210
211        if (RECrc != RCNORMAL) {
212            sprintf(buffup,"a2/%s MFN %"_LD_" -> Is deleted /",dbn2,mfn2);
213            if (fldupdat(upirec,buffup)) fatal("fldupdat");
214            recupdat(upcrec,upirec); errors++;
215            continue;
216        }
217
218        /* get sorted tagcat's not on exclude list */
219        occ1=getcat(0,irec1,tagcat1);
220        occ2=getcat(1,irec2,tagcat2);
221
222        if (occ1 != occ2) {
223
224            sprintf(buffup,"a2/%s MFN %"_LD_" TAG %d -> %d occ (%d expected)/",
225                                                dbn2,mfn2,tagcat2,occ2,occ1);
226            storcats(0,3);
227            if (fldupdat(upirec,buffup)) fatal("fldupdat");
228            recupdat(upcrec,upirec); errors++;
229            continue;
230        }
231#if TRACE1
232printf("-- %d\n",mfn1);
233#endif
234
235        for (n=0; n < occ1; n++) {
236
237#if TRACE2
238printf("term: %s %s=%s %s=%s\n",key,dbn1,cats[0][n],dbn2,cats[1][n]);
239#endif
240
241            if (strcmp(cats[0][n],cats[1][n]) == 0) continue;
242
243            sprintf(buffup,"a2/%s MFN %"_LD_" -> Categories/",dbn2,mfn2);
244            storcats(1,4);
245            if (fldupdat(upirec,buffup)) fatal("fldupdat");
246            recupdat(upcrec,upirec); errors++;
247            break;
248        }
249    }
250
251    printf("records=%"_LD_" / errors=%"_LD_" / empty=%"_LD_"\n",
252        count,errors,empty);
253    exit(0);
254}
255
256
257
258int getcat(idx,irec,tag)
259int idx;
260LONGX irec;
261int tag;
262{
263    int ncats,xdir,loop,n,i,found,loop2;
264    RECSTRU *recp;
265    unsigned char temp[MAXCOL+1];
266
267    recp=vrecp[irec]; /* set current */
268    ncats=0;
269
270
271    for (xdir=0, loop=MFRnvf; loop--; xdir++) {
272
273        if (DIRtag(xdir) != tag) continue;
274        for (found=0, n=nexclpfxs, i=0; n--; i++)
275        {
276
277            if (strncmp(FIELDP(xdir),exclpfxp[i],exclpfxl[i]) == 0) {
278                found=1;
279                break;
280            }
281        }
282        if (found) {
283#if TRACE3
284printf("excluindo %s %d\n",exclpfxp[n],xdir);
285#endif
286           continue;
287        }
288        if (DIRlen(xdir) > MAXCOL) fatal("MAXCOL");
289        memcpy(cats[idx][ncats],FIELDP(xdir),DIRlen(xdir));
290        cats[idx][ncats][DIRlen(xdir)] = '\0';
291        ncats++;
292#if TRACE4
293printf("idx=%d ncats=%d '%s'",idx,ncats,cats[idx][ncats-1]);
294if (getchar() != '\n') exit(1);
295#endif
296    }
297
298
299    for (n=ncats-1, loop=0; loop < n; loop++)
300
301        for (loop2=loop+1; loop2 <= n; loop2++)
302
303            if (strcmp(cats[idx][loop],cats[idx][loop2]) > 0) {
304                strcpy(temp,cats[idx][loop]);
305                strcpy(cats[idx][loop],cats[idx][loop2]);
306                strcpy(cats[idx][loop2],temp);
307            }
308
309    cats[idx][ncats][0] = '\0'; /* end */
310
311    return(ncats);
312}
313
314
315int storcats(idx,tag)
316int idx;
317int tag;
318{
319    int icat;
320    char *p;
321
322    for (icat=0; cats[idx][icat][0]; icat++) {
323
324        p=buffup+strlen(buffup);
325
326        sprintf(p,"H %d %d %s",
327                tag,strlen(cats[idx][icat]),cats[idx][icat]);
328
329    }
330
331    return(icat);
332}
Note: See TracBrowser for help on using the browser.