root/tags/5.52/ifupd.c

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

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

Line 
1/* ifupd.c - Update an inverted file
2*/
3
4#include <stdio.h>
5#include <string.h>
6
7#include "cisis.h"
8#include "ciupi.h"
9#include "cirun.h"
10
11char *fstarea=NULL;
12char *stwp=NULL;
13int nstws;
14
15FST_CODE *fstpgmp;
16LONGX maxlk1=1000;
17LONGX maxlk2=500;
18
19
20void main(argc,argv)
21int argc;
22char *argv[];
23
24{
25    char *dbnp,*ifnp;
26    DBXSTRU *dbxp;
27    char *p,*q,qline[CIMPL+1];
28    int argnext=1;
29    int parmtrace=0;
30    LONGX parmfrom,parmto,parmcount,tell,rangtell,mfn;
31    int pstflag=IFUPISIS;
32    int rc=0;
33
34#if LIND
35    LONGX parmxmfn=0L;
36    char *parmlogp=NULL;
37#endif
38
39    if (argc < 2) {
40#if LINDLUX         
41        printf("%s",cicopyr("Utility IFUPD/LINDLUX"));
42#else
43        printf("%s",cicopyr("Utility IFUPD"));
44#endif
45        printf("\n");
46        printf("ifupd ");
47#if MULTI
48        printf("[mono|full] ");
49#endif 
50        printf("[create=]<ifname> [<option> [...]]\n");
51        printf(" \n");
52#if MULTI
53        printf(" [mono|full]              -> single/multi user operation \n");
54#endif 
55        printf(" [create=]                -> to delete+create <ifname> \n");
56        printf(" <ifname>                 -> output inverted file \n");
57        printf(" \n");
58        printf("options: \n");
59        printf("\n");
60        printf(" fst=<fstspec>|@[fstfile] -> field select table \n");
61        printf(" stw=<stwspec>|@[stwfile] -> stop words \n");
62        printf(" -posts                   -> (init and) do not load .ifp \n");
63#if !LIND
64        printf(" master=<name>            -> alternate master file \n");
65#else
66        printf(" maxmfn=<n>               -> max master file number \n");
67        printf(" master=<dbn>             -> master file to get maxmfn \n");
68        printf(" log=<file>               -> log file name \n");
69#endif
70        printf(" actab=<file>             -> alphabetic chars table \n");
71        printf(" uctab=<file>             -> upper case chars table \n");
72        printf(" from=<n>                 -> initial mfn \n");
73        printf(" to=<n>                   -> final mfn \n");
74        printf(" count=<n>                -> max mfns \n");
75        printf(" tell=<n>                 -> tell <n>%% loaded \n");
76        printf(" \n");
77/*
78        printf("FMT=%ld \n",fst_fmtby);
79        printf(" \n");
80*/
81        exit(1);
82    }
83
84    /* get dbn */
85    dbnp=argv[argnext++];
86#if MULTI
87        if (strcmp(dbnp,"mono") == 0) {
88            cipnetws=MONONETS;
89            dbnp=argv[argnext++];
90        } else
91        if (strcmp(dbnp,"mast") == 0) {
92            cipnetws=MASTNETS;
93            dbnp=argv[argnext++];
94        }
95        if (strcmp(dbnp,"full") == 0) {
96            cipnetws=FULLNETS;
97            dbnp=argv[argnext++];
98        }
99#endif
100    if (strncmp(dbnp,"create?",7) == 0 || strncmp(dbnp,"create=",7) == 0) {
101        dbnp+=7;
102        trmisis0(dbnp);
103    }
104    ifnp=dbnp;
105
106    parmfrom=1L; parmto=parmcount=9999999L; tell=0L;
107    for (; argnext < argc; ) {
108
109        p=argv[argnext++];
110
111        if (strncmp(p,"reset?",6) == 0 || strncmp(p,"reset=",6) == 0) {
112            if (sscanf(p+6,"%d",&ifupd_reset) != 1) fatal(p);
113            continue;
114        }
115        if (strncmp(p,"master?",7) == 0 || strncmp(p,"master=",7) == 0) {
116            dbnp=p+7;
117            if (!*dbnp) fatal(p);
118            continue;
119        }
120
121#if LIND
122        if (strncmp(p,"maxmfn?",7) == 0 || strncmp(p,"maxmfn=",7) == 0) {
123            if (sscanf(p+7,"%ld",&parmxmfn) != 1) fatal(p);
124            if (parmxmfn < 1) fatal(p);
125            continue;
126        }
127        if (strncmp(p,"log?",4) == 0 || strncmp(p,"log=",4) == 0) {
128            parmlogp=p+4;
129            if (!*parmlogp) fatal(p);
130            continue;
131        }
132#endif
133        if (strncmp(p,"from?",5) == 0 || strncmp(p,"from=",5) == 0) {
134            if (sscanf(p+5,"%ld",&parmfrom) != 1) fatal(p);
135            continue;
136        }
137        if (strncmp(p,"to?",3) == 0 || strncmp(p,"to=",3) == 0) {
138            if (sscanf(p+3,"%ld",&parmto) != 1) fatal(p);
139            continue;
140        }
141        if (strncmp(p,"count?",6) == 0 || strncmp(p,"count=",6) == 0) {
142            if (sscanf(p+6,"%ld",&parmcount) != 1) fatal(p);
143            continue;
144        }
145        if (strncmp(p,"tell=",5) == 0) {
146            if (sscanf(p+5,"%ld",&tell) != 1) fatal(p);
147            if (tell < 0) fatal(p);
148            continue;
149        }
150        if (strcmp(p,"trace?all") == 0|| strcmp(p,"trace=all") == 0) {
151            dbxtrace=rectrace=parmtrace=fsttrace=multrace=trmtrace=1;
152            continue;
153        }
154        if (strcmp(p,"trace") == 0) {
155            dbxtrace=rectrace=multrace=parmtrace=1;
156            continue;
157        }
158
159        if (strncmp(p,"maxlk1?",7) == 0 || strncmp(p,"maxlk1=",7) == 0) {
160            if (sscanf(p+7,"%ld",&maxlk1) != 1) fatal(p);
161            continue;
162        }
163        if (strncmp(p,"maxlk2?",7) == 0 || strncmp(p,"maxlk2=",7) == 0) {
164            if (sscanf(p+7,"%ld",&maxlk2) != 1) fatal(p);
165            continue;
166        }
167
168        if (strncmp(p,"fst?",4) == 0 || strncmp(p,"fst=",4) == 0) {
169            q=p+4;
170            if (strcmp(q,"@") == 0) sprintf(q=qline,"@%s.fst",ifnp);
171            fstarea=loadfile(ifnp,'@',q,fstarea,0L,'\n');
172            if (!fstarea) fatal(q);
173            if (parmtrace) { showcore("+++ fst"); printf("%s.\n",fstarea); }
174            fst_gener(&fstpgmp,fstarea);
175            if (parmtrace) showcore("+++ fst");
176            if (fst_error) {
177                printf("\n*** FST error#%ld at line %ld\n",fst_error,fst_errl);
178                if (fst_error == FSTERRF)
179                    printf("\n*** FMT error#%ld at offset %ld\n",
180                                                fmt_error,fmt_errof);
181                fatal(fst_errp);
182            }
183            continue;
184        }
185
186        if (strncmp(p,"stw?",4) == 0 || strncmp(p,"stw=",4) == 0) {
187            q=p+4;
188            if (*q++ != '@') fatal(p);
189            if (!*q) sprintf(q=qline,"%s.stw",ifnp);
190            if (parmtrace) showcore("+++ stw");
191            stwp=loadstw(ifnp,q,stwp,0L,&nstws);
192            if (parmtrace) {
193                for (q=stwp; *q; q+=LE1+1) printf("%s/",q);
194                printf("=%d\n",nstws);
195                showcore("+++ stw");
196            }
197            continue;
198        }
199
200        if (strcmp(p,"-posts") == 0) {
201            pstflag=IFUPDICT;
202            continue;
203        }
204
205        if (strncmp(p,"uctab?",6) == 0 || strncmp(p,"uctab=",6) == 0) {
206            if (!loaductb(ifnp,isisuctab,p+6)) fatal(p); /* AOT, 02/04/2001 */
207            continue;
208        }
209        if (strncmp(p,"actab?",6) == 0 || strncmp(p,"actab=",6) == 0) {
210            unsigned char ubuffup[256];
211            memset(isiswctab,0x00,256);
212            if (!loadactb(ifnp,ubuffup,p+6)) fatal(p); /* AOT, 02/04/2001 */
213            for (isiswctot=0; ubuffup[isiswctot]; isiswctot=isiswctot+1)
214                isiswctab[ubuffup[isiswctot]]=1;
215            continue;
216        }
217
218        fatal(p);
219    }
220
221#if LIND
222    /* get maxmfn */
223    if (!parmxmfn) {
224        parmxmfn=VMF0nxtmfn(record(nrecs,dbnp,0L))-1;
225        dbxflush(dbnp);
226    }
227#endif
228
229   dbxp=dbxstorp(ifnp); /* inverted file ! */
230
231   if (parmto == 9999999L) {
232        parmto=VMF0nxtmfn(record(nrecs,dbnp,0L))-1;
233   }
234   if (parmto > parmfrom+parmcount-1) parmto=parmfrom+parmcount-1;
235
236   if (tell) {
237        rangtell=parmto-parmfrom+1;
238        if (rangtell <= 0) rangtell=1;
239        if (tell < 0 || tell > 100) tell=1;
240        tell=rangtell/(100/tell);
241        if (tell <= 0) tell=1;
242   }
243
244
245   if (tell) { DBXitell=tell; DBXirang=rangtell; }
246   if (parmtrace) DBXitrac=parmtrace;
247
248#if LIND
249   invsetup(ifnp,0L,0L,0L);
250#if LINDLUX
251   DBXifmap->ltxthresh=1;               /* noderead()/nodewrit()           */
252   DBXifmap->luxthresh=parmxmfn/8+1;    /* leafread()/leafwrit()/threshold */
253   DBXifmap->lvxiflind=0;               /* ifupdat()                       */
254   DBXifmap->lvxmaxmfn=parmxmfn;        /* ifupdat()                       */
255#endif /* LINDLUX */
256#endif
257
258#if MULTI
259   if (DBXnetws != MONONETS)
260       for (mfn=parmfrom; mfn <= parmto; mfn++) {
261           rc=ifupdat(dbnp,mfn,mfn,
262                        ifnp,fstpgmp,stwp,maxlk1,maxlk2,pstflag,IFUPWRIT);
263           if (rc) break;
264       }
265   else {
266       rc=ifupdat(dbnp,parmfrom,parmto,
267                        ifnp,fstpgmp,stwp,maxlk1,maxlk2,pstflag,IFUPCORE);
268
269       rc+=ifupdat(dbnp,0L,0L,
270                        ifnp,fstpgmp,stwp,maxlk1,maxlk2,pstflag,IFUPWRIT);
271   }
272#else
273   rc=ifupdat(dbnp,parmfrom,parmto,
274                        ifnp,fstpgmp,stwp,maxlk1,maxlk2,pstflag,IFUPCORE);
275
276   rc+=ifupdat(dbnp,0L,0L,
277                        ifnp,fstpgmp,stwp,maxlk1,maxlk2,pstflag,IFUPWRIT);
278#endif
279
280#if !LIND /* v */
281if (tell) {                                             /* 02/06/98 */
282   printf("%ld records updated          \n",DBXirecs);
283   printf("%ld+%ld=%ld postings added   \n",DBXipadd[0],DBXipadd[1],
284                                            DBXipadd[0]+DBXipadd[1]);
285   printf("%ld+%ld=%ld postings deleted \n",DBXipdel[0],DBXipdel[1],
286                                            DBXipdel[0]+DBXipdel[1]);
287}                                           
288#else /* !LIND v */
289   printf("%ld records read             \n",DBXirecs);
290   printf("%ld+%ld records on %s+%s     \n",DBXifmap->cn[0].nmaxpos,
291                                            DBXifmap->cn[1].nmaxpos,
292                                            nx12extp[0],nx12extp[1]);
293   printf("%ld+%ld records on %s+%s     \n",DBXifmap->cn[0].fmaxpos,
294                                            DBXifmap->cn[1].fmaxpos,
295                                            lx12extp[0],lx12extp[1]);
296   printf("%ld+%ld=%ld postings to add  \n",DBXipadd[0],DBXipadd[1],
297                                            DBXipadd[0]+DBXipadd[1]);
298#endif /* !LIND v */
299
300#if LIND
301  if (pstflag != IFUPDICT) {
302#if LINDLUX
303   DBXifmap->ltxthresh=1;               /* noderead()/nodewrit()           */
304   DBXifmap->luxthresh=parmxmfn/8+1;    /* leafread()/leafwrit()/threshold */
305   DBXifmap->lvxiflind=1;               /* svdifupd()                      */
306#endif /* LINDLUX */
307
308   ifupdat(dbnp,parmfrom,parmto,
309                        ifnp,fstpgmp,stwp,maxlk1,maxlk2,pstflag,IFUPCORE);
310
311   ifupdat(dbnp,0L,0L,
312                        ifnp,fstpgmp,stwp,maxlk1,maxlk2,pstflag,IFUPWRIT);
313
314   printf("%ld records read             \n",DBXirecs);
315   printf("%ld+%ld=%ld postings added   \n",DBXipadd[0],DBXipadd[1],
316                                            DBXipadd[0]+DBXipadd[1]);
317  } /* end if pstflag != IFUPDICT */
318#endif
319
320  if (rc) fatal("error while updating the IF");
321 
322  exit(0);
323}
Note: See TracBrowser for help on using the browser.