2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
6 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
7 /* All Rights Reserved */
10 * Copyright (c) 1980 Regents of the University of California.
11 * All rights reserved. The Berkeley software License Agreement
12 * specifies the terms and conditions for redistribution.
15 #pragma ident "%Z%%M% %I% %E% SMI"
22 extern char *fgnames
[];
37 static int full
= 1000;
39 char *sinput
, *soutput
, *tagout
;
40 long indexdate
= 0, gdate();
45 extern long findline();
47 extern void grepcall();
48 extern int makefgrep();
53 static int setfrom(char);
56 main(int argc
, char *argv
[])
58 /* read query from stdin, expect name of indexes in argv[1] */
59 static FILE *fa
, *fb
, *fc
;
60 char nma
[100], nmb
[100], nmc
[100], *qitem
[100], *rprog
= NULL
;
61 char nmd
[100], grepquery
[256];
62 static char oldname
[30];
64 /* these pointers are unions of pointer to int and pointer to long */
67 int falseflg
, nhash
, nitem
, nfound
, frtbl
, kk
;
69 /* special wart for refpart: default is tags only */
71 (void) setlocale(LC_ALL
, "");
73 #if !defined(TEXT_DOMAIN)
74 #define TEXT_DOMAIN "SYS_TEST"
76 (void) textdomain(TEXT_DOMAIN
);
80 while (argc
> 1 && argv
[1][0] == '-') {
82 case 'a': /* all output, incl. false drops */
90 case 'F': /* put out full text */
91 full
= setfrom(argv
[1][2]);
93 case 'T': /* put out tags */
94 tags
= setfrom(argv
[1][2]);
96 case 'i': /* input in argument string */
101 case 's': /* text output to string */
106 if ((int)argv
[2] < 16000) {
107 soutlen
= (int)argv
[2];
112 case 't': /* tag output to string */
117 case 'l': /* length of internal lists */
120 lmaster
= atoi(argv
[1]);
122 case 'g': /* suppress fgrep search on old files */
125 case 'C': /* coordination level */
126 colevel
= atoi(argv
[1]+2);
128 fprintf(stderr
, "colevel set to %d\n", colevel
);
131 case 'P': /* print term freqs */
143 strcpy(nma
, todir(argv
[1]));
144 if (was
== 0 || strcmp(oldname
, nma
) != 0) {
145 strcpy(oldname
, nma
);
159 fa
= fopen(nma
, "r");
161 strcpy(*fgnamp
++ = calloc(strlen(oldname
)+2, 1),
166 fb
= fopen(nmb
, "r");
167 fc
= fopen(nmc
, "r");
169 if (fb
== NULL
|| fc
== NULL
) {
170 err(gettext("Index incomplete %s"), nmb
);
173 indexdate
= gdate(fb
);
174 fd
= fopen(nmd
, "r");
177 fread(&nhash
, sizeof (nhash
), 1, fa
);
178 fread(&iflong
, sizeof (iflong
), 1, fa
);
180 master
= (unsigned *)calloc(lmaster
, iflong
?
181 sizeof (long) : sizeof (unsigned));
182 hpt
= (long *)calloc(nhash
, sizeof (*hpt
));
183 kk
= fread(hpt
, sizeof (*hpt
), nhash
, fa
);
185 fprintf(stderr
, "read %d hashes, iflong %d, nhash %d\n",
189 hfreq
= (int *)calloc(nhash
, sizeof (*hfreq
));
190 assert(hfreq
!= NULL
);
191 frtbl
= fread(hfreq
, sizeof (*hfreq
), nhash
, fa
);
192 hfrflg
= (frtbl
== nhash
);
194 fprintf(stderr
, "read freqs %d\n", frtbl
);
201 if (nitem
== 0) continue;
202 if (nitem
< 0) break;
203 if (tagout
) tagout
[0] = 0;
205 nfound
= doquery(hpt
, nhash
, fb
, nitem
, qitem
, master
);
207 fprintf(stderr
, "after doquery nfound %d\n", nfound
);
211 nfound
= baddrop(master
, nfound
, fc
,
212 nitem
, qitem
, rprog
, full
);
214 fprintf(stderr
, "after baddrop nfound %d\n", nfound
);
217 if (fgnamp
> fgnames
) {
218 char **fgp
, tgbuff
[100];
221 fprintf(stderr
, "were %d bad files\n", fgnamp
-fgnames
);
223 (void) memset(tgbuff
, 0, sizeof (tgbuff
));
225 for (k
= 0; k
< nitem
; k
++) {
226 strcat(grepquery
, " ");
227 strcat(grepquery
, qitem
[k
]);
230 fprintf(stderr
, "grepquery %s\n", grepquery
);
232 for (fgp
= fgnames
; fgp
< fgnamp
; fgp
++) {
234 fprintf(stderr
, "Now on %s query /%s/\n",
239 fprintf(stderr
, "grepmade\n");
243 grepcall(grepquery
, tagout
, *fgp
);
245 fprintf(stderr
, "tagout now /%s/\n", tagout
);
260 nout
= findline(oldtagp
, &bout
,
271 result(master
, nfound
> tags
? tags
: nfound
, fc
);
283 while (s
>= t
&& *s
!= '/') s
--;