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"
27 main(int argc
, char *argv
[])
30 * Make inverted file indexes. Reads a stream from mkey which
31 * gives record pointer items and keys. Generates set of files
32 * a. NHASH pointers to file b.
33 * b. lists of record numbers.
34 * c. record pointer items.
36 * these files are named xxx.ia, xxx.ib, xxx.ic;
37 * where xxx is taken from arg1.
38 * If the files exist they are updated.
41 FILE *fa
, *fb
, *fc
, *fta
, *ftb
, *ftc
;
45 int keepkey
= 0, pipein
= 0;
46 char nma
[100], nmb
[100], nmc
[100], com
[100], nmd
[100];
47 char tmpa
[20], tmpb
[20], tmpc
[20];
49 int chatty
= 0, docs
, hashes
, fp
[2], fr
, fw
, pfork
, pwait
, status
;
55 (void) setlocale(LC_ALL
, "");
57 #if !defined(TEXT_DOMAIN)
58 #define TEXT_DOMAIN "SYS_TEST"
60 (void) textdomain(TEXT_DOMAIN
);
62 sortdir
= (access("/crp/tmp", 06) == 0) ? "/crp/tmp" : "/usr/tmp";
63 while (argc
> 1 && argv
[1][0] == '-') {
65 case 'h': /* size of hash table */
66 nhash
= atoi(argv
[1]+2);
68 case 'n': /* new, don't append */
71 case 'a': /* append to old file */
74 case 'v': /* verbose output */
77 case 'd': /* keep keys on file .id for check on searching */
80 case 'p': /* pipe into sort (saves space, costs time) */
83 case 'i': /* input is on file, not stdin */
85 if (open(argv
[2], 0) != 0)
86 err(gettext("Can't read input %s"), argv
[2]);
87 if (argv
[1][2] == 'u') /* unlink */
96 strcpy(nma
, argc
>= 2 ? argv
[1] : "Index");
105 sprintf(tmpa
, "junk%di", getpid());
107 sprintf(com
, "/usr/bin/sort -T %s -o %s", sortdir
, tmpa
);
108 fta
= popen(com
, "w");
109 } else { /* use tmp file */
110 fta
= fopen(tmpa
, "w");
115 if (fb
= fopen(nmb
, "r")) {
116 sprintf(tmpb
, "junk%dj", getpid());
117 ftb
= fopen(tmpb
, "w");
119 err(gettext("Can't get scratch file %s"), tmpb
);
120 nhash
= recopy(ftb
, fb
, fopen(nma
, "r"));
125 fc
= fopen(nmc
, appflg
? "a" : "w");
127 fd
= keepkey
? fopen(nmd
, "w") : 0;
128 docs
= newkeys(fta
, stdin
, fc
, nhash
, fd
, &iflong
);
138 sprintf(com
, "sort -T %s %s -o %s", sortdir
, tmpa
, tmpa
);
142 sprintf(tmpc
, "junk%dk", getpid());
143 sprintf(com
, "mv %s %s", tmpa
, tmpc
);
145 sprintf(com
, "sort -T %s -m %s %s -o %s", sortdir
,
149 fta
= fopen(tmpa
, "r");
150 fa
= fopen(nma
, "w");
151 fb
= fopen(nmb
, "w");
152 whash(fta
, fa
, fb
, nhash
, iflong
, &keys
, &hashes
);
162 printf(gettext("%ld key occurrences, %d hashes, %d docs\n"),