root/tags/5.52/ifp1.c

Revision 4, 9.1 kB (checked in by heitor.barbieri, 2 years ago)

Versão 5.52 do cisis (28/04/2010)

Line 
1/* ------------------------------ ifp1.c ----------------------------- */
2/* ===========================================================================
3        Link file generation for the MeSH Headings field - STEP c
4        Author: decs9a.c/AOT, Nov 2 1990
5        Alter:  AOT, Oct 08 1991
6                1. Scan the total no of posting, as the last input field
7                2. Scan an additional trailing space
8        Alter:  AOT, Oct 17 1991
9                1. CNLI support
10                2. Key1 = "**DELETE**" (move 0 to the total no of postings)
11=========================================================================== */
12#include <stdio.h>
13#include <string.h>
14#define TRACEMOV 0
15#define TRACEHI  0
16#include "cisis.h"       /* CISIS Interface */
17#include "cirun.h"       /* runtime area and defines by AOT */
18unsigned char keydel[LE2+1] = { "**DELETE**" };
19extern UCHR highv[];
20int parmtrace=0;
21/* prototypes */
22#if ANSI
23int moveinfo(LONGX itrm1, LONGX itrm2);
24int outleaf(int fd, char *buffp, int lbufsiz, PUNT punt, LONGX offset);
25#else
26int moveinfo();
27int outleaf();
28#endif
29/* main */
30#if ANSI
31void main (int argc, char *argv[])
32#else
33main(argc,argv)
34int argc;
35char *argv[];
36#endif
37{
38    unsigned char *ifnautp,*ifnioxp,*listfnp;
39    INVMAP *invp; /* tell */
40    FILE *fplst;
41    FILE *fp;
42    int loop,n;
43#if 0
44    unsigned char listfmt[80];
45#endif
46    unsigned char key1[LE2+1],key2[LE2+1],prefkey[LE2+1],qualkey[LE2+1];
47    LONGX umb;
48    int key1l,key2l,prefl,quall;
49    unsigned char lang,type;
50    TRMSTRU *trmp;
51    LONGX itrmaut,itrmiox;
52    unsigned char keyiox[LE2+1],keyaut[LE2+1];
53    unsigned char *p;
54    LONGX ecount,count,xtell;
55    extern int trmtrace;
56    if (argc < 4) {
57        printf("%s",cicopyr("Utility IFP1"));
58        printf("\n");
59        printf("ifp1 <ifnaut> <ifniox> <crosslst> [<tell> [trace]]\n");
60        printf("\n");
61        printf(" <ifnaut>      -> primary inverted file       \n");
62        printf(" <ifniox>      -> dictionary to be updated    \n");
63        printf(" <crosslst>    -> correspondence table        \n");
64        printf("\n");
65        printf(" trace         -> trace execution \n");
66        printf(" tell=<n>      -> tell <n> keys has been processed \n");
67        printf(" \n");
68        exit(1);
69    }
70
71    /* get parms */
72    xtell=0;
73    ifnautp=argv[1];
74    ifnioxp=argv[2];
75    listfnp=argv[3];
76    if (argc > 4)
77        if (sscanf(argv[4],"%ld",&xtell) != 1) fatal(argv[4]);
78    if (argc > 5) {
79        dbxtrace=trmtrace=parmtrace=1;
80    }
81    /* aloca trm sem area p/ posting - invertido autorizado */
82    trmalloc((itrmaut=ntrms),0L);                               /* tidx #1 */
83    /* aloca trm sem area p/ posting - invertido ifnioxp */
84    trmalloc((itrmiox=ntrms),0L);                               /* tidx #2 */
85    trmp=vtrmp[itrmiox];
86    invsetup(ifnioxp,0L,0L,0L);
87    invp=dbxstorp(ifnioxp)->dbxifmap;
88    /* === open leaf's for CIWRITE */
89    dbxopenw("",ifnioxp,lx12extp[0],&invp->l1opn,&invp->l1opw,"ifp1/l1opn/w");
90    dbxopenw("",ifnioxp,lx12extp[1],&invp->l2opn,&invp->l2opw,"ifp1/l2opn/w");
91    /* === */
92    if (xtell == 0) {
93        xtell=(invp->cn[0].fmaxpos+invp->cn[1].fmaxpos)*TWORDF;
94        xtell/=10;
95        if (xtell < 1)
96            xtell=1;
97    }
98    /* open lst and output files */
99    if ((fplst=fopen(listfnp, "r")) == NULL) fatal(listfnp);
100    ecount=count=0;
101    /* setup keydel */
102    for (p=keydel, n=sizeof(keydel); *p; n--) p++;
103    for (; --n > 0; ) *p++ = ' ';
104    *p = '\0';
105#if 0
106000001|/PD                           |I|a|/PD EXTENSO                   |
107                                                        . |   | 3|11|1|0
1086|LE2|1|1|LE2|2|3|2|2|1|1\n
109%ld|%.30s|%c|%c|%.30s|%.2s|%.3s|%2d|%2d|%d|%d
110/* #endif */
111    sprintf(listfmt,
112        "%%ld|%%.%ds|%%c|%%c|%%.%ds|%%.2s|%%.3s|%%2d|%%2d|%%d|%%d",LE2,LE2);
113    /* loop principal */
114    while (fscanf(fplst,listfmt,&umb,key1,&lang,&type,key2,prefkey,qualkey,
115                                        &key1l,&key2l,&prefl,&quall) == 11) {
116#else
117    while (fscanf(fplst,"%ld|",&umb) == 1) {
118        for (p=key1, n=LE2; n--; ) *p++ = fgetc(fplst); *p='\0'; fgetc(fplst);
119        lang = fgetc(fplst); fgetc(fplst);
120        type = fgetc(fplst); fgetc(fplst);
121        for (p=key2, n=LE2; n--; ) *p++ = fgetc(fplst);  *p='\0'; 
122fgetc(fplst);
123        for (p=prefkey, n=2; n--; ) *p++ = fgetc(fplst); *p='\0'; 
124fgetc(fplst);
125        for (p=qualkey, n=3; n--; ) *p++ = fgetc(fplst); *p='\0'; 
126fgetc(fplst);
127        n=fscanf(fplst,"%2d|%2d|%d|%d",
128                                        &key1l,&key2l,&prefl,&quall);
129        fscanf(fplst,"|%*ld \n");
130        if (n != 4) {
131            printf("n=%d\n%ld|%s|%c|%c|%s|%s|%s|%2d|%2d|%d|%d\n",
132           
133n,umb,key1,lang,type,key2,prefkey,qualkey,key1l,key2l,prefl,quall);
134            fatal("!= 4");
135        }
136        key1[key1l]='\0'; key2[key2l]='\0';
137        prefkey[prefl]='\0'; qualkey[quall]='\0';
138#endif NOW
139        memcpy(keyaut,            prefkey,prefl);
140        memcpy(keyaut+prefl,      key1,key1l);
141        memcpy(keyaut+prefl+key1l,qualkey,quall);
142               keyaut[prefl+key1l+quall]='\0';
143        memcpy(keyiox,            prefkey,prefl);
144        memcpy(keyiox+prefl,      key2,key2l);
145        memcpy(keyiox+prefl+key2l,qualkey,quall);
146               keyiox[prefl+key2l+quall]='\0';
147        if ((++count % xtell) == 0)
148            fprintf(stderr,"+++ %ld %s%s%s %d,%d,%d [%c,%c]\n",
149                count,prefkey,key1,qualkey,prefl,key1l,quall,lang,type);
150        for (p=keyaut; *p; p++) *p=isisuctab[*p];
151        if (memcmp(key1,keydel,key1l) == 0) {
152            printf("+++ %s keyaut=%s (%ld)\n",key1,keyiox,umb);
153            TERM(itrmaut,ifnautp,highv);
154            if (TRMrc != RCEOF) {
155                printf("*** ifnaut=%s keyaut=%s (%ld)\n",ifnautp,keyaut,umb);
156                fatal(keyaut);
157            }
158        }
159        else {
160            TERM(itrmaut,ifnautp,keyaut);
161            if (TRMrc != RCNORMAL) {
162                printf("*** ifnaut=%s keyaut=%s (%ld)\n",ifnautp,keyaut,umb);
163                fatal("TRMrc");
164            }
165        }
166        for (p=keyiox; *p; p++) *p=isisuctab[*p];
167        TERM(itrmiox,ifnioxp,keyiox);
168        if (TRMrc != RCNORMAL) {
169            printf("*** ifniox=%s keyiox=%s (%ld)\n",ifnioxp,keyiox,umb);
170            fatal("TRMrc");
171        }
172        moveinfo(itrmaut,itrmiox);
173    }
174    printf("==> %ld/%ld \n",count,ecount);
175    exit(0);
176}
177
178#if ANSI
179int moveinfo(LONGX itrmaut, LONGX itrmiox)
180#else
181int moveinfo(itrmaut,itrmiox)
182LONGX itrmaut;
183LONGX itrmiox;
184#endif
185{
186    TRMSTRU *trmp;
187    PUNT punt;
188    char *buffp;
189    int lbufsiz,fd;
190    INFO info1,info2;
191#if LIND
192    INFO info3;
193#endif
194    LONGX offset;
195#if TRACEMOV
196    char *p;
197    int n;
198#endif
199    trmp=vtrmp[itrmaut];                                /* ifnaut */
200    if (TRMrc == RCEOF) {                               /* **DELETE** */
201#if LIND
202        info1=0L;       /* MFNSTRING */
203        info2=0L;       /* TRMydocs */
204        info3=0L;       /* info2*PMFNSIZ */
205#else
206        fatal(keydel);  /* Don't know what to do with ifphdr */
207        /* info1=1L; */
208#endif
209        if (parmtrace)
210            printf("+++ moveinfo - TRMrc=%d TRMkey=%s \n",TRMrc,TRMkey);
211    }
212    else {
213       if (TRMlcase) {            /* {} yes */
214            info1=((L2IDXE *)TRMlidxp(1))->info1;
215            info2=((L2IDXE *)TRMlidxp(1))->info2;
216#if LIND
217            info3=((L2IDXE *)TRMlidxp(1))->info3info4.info3;
218#endif
219        }
220        else {
221            info1=((L1IDXE *)TRMlidxp(0))->info1;
222            info2=((L1IDXE *)TRMlidxp(0))->info2;
223#if LIND
224            info3=((L1IDXE *)TRMlidxp(0))->info3info4.info3;
225#endif
226        }
227    }
228#if TRACEMOV
229printf("key=%s (%d) info=%ld/%ld\n",TRMkey,TRMlcase,info1,info2);
230#endif
231    trmp=vtrmp[itrmiox];                                /* ifniox */
232    if (TRMlcase) {
233        ((L2IDXE *)TRMlidxp(1))->info1 = info1;
234        ((L2IDXE *)TRMlidxp(1))->info2 = info2;
235#if LIND
236        ((L2IDXE *)TRMlidxp(1))->info3info4.info3 = info3;
237#endif
238#if TRACEMOV
239        p=TRMlidxp(1); n=LE2;
240#endif
241        punt=TRMl2buf.pos;
242        buffp=(char *)&TRMl2buf;
243        lbufsiz=L2BSIZ;
244        fd=TDBifmap->l2opn;
245    }
246    else {
247        ((L1IDXE *)TRMlidxp(0))->info1 = info1;
248        ((L1IDXE *)TRMlidxp(0))->info2 = info2;
249#if LIND
250        ((L1IDXE *)TRMlidxp(0))->info3info4.info3 = info3;
251#endif
252#if TRACEMOV
253        p=TRMlidxp(0); n=LE1;
254#endif
255        punt=TRMl1buf.pos;
256        buffp=(char *)&TRMl1buf;
257        lbufsiz=L1BSIZ;
258        fd=TDBifmap->l1opn;
259    }
260#if CNLI
261    offset=TDBifmap->cl_offset[TRMlcase];
262    if (parmtrace) {
263        printf("offset=%ld ..",offset);
264        if (getchar() != '\n') exit(1);
265    }
266#else
267    offset=0;
268#endif
269#if TRACEMOV
270printf(" -> '");
271for (; n--; p++) printf("%c",*p);
272printf("' +%ld",offset); getchar();
273#endif
274    if (parmtrace)
275        printf("+++ moveinfo -  %s. %ld/%ld\n",TRMkey,(LONGX)info1,(LONGX)info2);
276    if (outleaf(fd,buffp,lbufsiz,punt,offset)) {
277        printf("*** %s. %ld/%ld\n",TRMkey,(LONGX)info1,(LONGX)info2);
278        fatal("CIWRITE");
279    }
280    return(RCNORMAL);
281}
282
283#if ANSI
284int outleaf(int fd, char *buffp, int lbufsiz, PUNT punt, LONGX offset)
285#else
286int outleaf(fd,buffp,lbufsiz,punt,offset)
287int fd;
288char *buffp;
289int lbufsiz;
290PUNT punt;
291LONGX offset;
292#endif
293{
294    off_t bytes;
295    int n;
296    if (fd <= 0)
297        fatal("fd");
298    if (punt < 1)
299        fatal("punt");
300    bytes=(punt-1L)*lbufsiz+offset;
301    if (LSEEK64(fd,bytes,SEEK_SET) != bytes)
302        fatal("lseek");
303    n=CIWRITE(fd,buffp,lbufsiz) - lbufsiz;
304    ((L0STRU *)buffp)->pos=0;   /*
305                                        This is to force a read on disk:
306                                        TRMl1buf/TRMl2buf->pos in leafread()
307                                        is checked to avoid reading the disk
308                                */
309    return(n);
310}
Note: See TracBrowser for help on using the browser.