/* make inverted file indexes. Reads a stream from mkey which
gives record pointer items and keys. Generates a set of files
a. NHASH pointers to file b.
b. lists of record numbers.
these files are named xxx.ia, xxx.ib, xxx.ic;
where xxx is taken from arg1.
If the files exist they are updated.
FILE *fa
, *fb
, *fc
, *fta
, *ftb
, *ftc
, *fd
;
int keepkey
= 0, pipein
= 0;
char nma
[100], nmb
[100], nmc
[100], com
[100], nmd
[100];
char tmpa
[20], tmpb
[20], tmpc
[20];
int chatty
= 0, docs
, hashes
, fp
[2], fr
, fw
, pfork
, pwait
, status
;
sortdir
= (access("/crp/tmp", 06)==0) ? "/crp/tmp" : "/usr/tmp";
while (argv
[1][0] == '-')
case 'h': /* size of hash table */
nhash
= atoi (argv
[1]+2); break;
case 'n': /* new, don't append */
case 'a': /* append to old file */
case 'v': /* verbose output */
case 'd': /* keep keys on file .id for check on searching */
case 'p': /* pipe into sort (saves space, costs time)*/
case 'i': /* input is on file, not stdin */
if (open(argv
[2], 0) != 0)
err("Can't read input %s", argv
[2]);
if (argv
[1][2]=='u') /* unlink */
strcpy (nma
, argc
>= 2 ? argv
[1] : "Index");
sprintf(tmpa
, "junk%di", getpid());
pipe(fp
); fr
=fp
[0]; fw
=fp
[1];
if ( (pfork
=fork()) == 0)
execl("/bin/sort", "sort", "-T", sortdir
, "-o", tmpa
, 0);
execl("/usr/bin/sort", "sort", "-T", sortdir
, "-o", tmpa
, 0);
fta
= fopen("/dev/null", "w");
if (fb
= fopen(nmb
, "r"))
sprintf(tmpb
, "junk%dj", getpid());
err("Can't get scratch file %s",tmpb
);
nhash
= recopy(ftb
, fb
, fopen(nma
, "r"));
fc
= fopen(nmc
, appflg
? "a" : "w");
fd
= keepkey
? fopen(nmd
, "w") : 0;
docs
= newkeys(fta
, stdin
, fc
, nhash
, fd
, &iflong
);
printf("pfork %o pwait %o status %d\n",pfork
,pwait
,status
);
sprintf(com
, "sort -T %s %s -o %s", sortdir
, tmpa
, tmpa
);
sprintf(tmpc
, "junk%dk", getpid());
sprintf(com
, "mv %s %s", tmpa
, tmpc
);
sprintf(com
, "sort -T %s -m %s %s -o %s", sortdir
,
whash(fta
, fa
, fb
, nhash
, iflong
, &keys
, &hashes
);
printf ("%ld key occurrences, %d hashes, %d docs\n",