1 /*-
2 * %sccs.include.proprietary.c%
3 */
4
5 #ifndef lint
6 static char sccsid[] = "@(#)inv2.c 4.2 (Berkeley) 04/18/91";
7 #endif /* not lint */
8
9 #include <stdio.h>
10 #include <assert.h>
11 #define LINESIZ 1250
12
newkeys(outf,inf,recf,nhash,fd,iflong)13 newkeys (outf, inf, recf, nhash, fd, iflong)
14 FILE *outf, *inf, *recf, *fd;
15 int *iflong;
16 {
17 /* reads key lines from inf; hashes and writes on outf;
18 * writes orig key on recf, records pointer on outf too.
19 * format of outf is : hash code space record pointer
20 */
21
22 long lp, ftell();
23 long ld = 0;
24 int ll = 0, lt = 0;
25 char line[LINESIZ];
26 char key[30], bkeys[40];
27 char *p, *s;
28 char *keyv[500];
29 int i, nk, ndoc = 0, more = 0, c;
30
31 lp = ftell (recf);
32 while (fgets(line, LINESIZ, inf))
33 {
34 p = line;
35 while (*p != '\t') p++;
36 *p++ =0;
37 fputs(line, recf);
38 if (fd)
39 {
40 sprintf(bkeys, ";%ld", ld);
41 ll = strlen(p);
42 lt = strlen(bkeys);
43 fputs(bkeys, recf);
44 sprintf(bkeys, ",%d", ll);
45 lt += strlen(bkeys);
46 fputs(bkeys, recf);
47 ld += ll;
48 fputs(p, fd);
49 }
50 putc('\n',recf);
51 for(s=p; *s; s++);
52 if (*--s == '\n')
53 {
54 more=0;
55 *s=0;
56 }
57 else
58 more=1;
59 _assert (fd==0 || more==0);
60 nk = getargs(p, keyv);
61 if (more)
62 nk--;
63 for(i=0; i<nk; i++)
64 fprintf(outf,"%04d %06ld\n",hash(keyv[i])%nhash, lp);
65 # if D1
66 for(i=0; i<nk; i++)
67 printf("key %s hash %d\n",keyv[i],hash(keyv[i])%nhash);
68 # endif
69 if (more) /* allow more than LINESIZ keys */
70 {
71 strcpy(key, keyv[nk]);
72 for(s=key; *s; s++);
73 while ( (c=getc(inf)) != '\n')
74 {
75 if (c != ' ')
76 {
77 *s++ = c;
78 continue;
79 }
80 *s=0;
81 if (s>key)
82 fprintf(outf, "%04d %06ld\n",hash(key)%nhash, lp);
83 s = key;
84 }
85 }
86 lp += (strlen(line)+lt+1);
87 ndoc++;
88 }
89 *iflong = (lp>=65536L);
90 if (sizeof(int)>2) *iflong=1; /* force long on VAX */
91 fclose(recf);
92 return(ndoc);
93 }
94
trimnl(p)95 trimnl(p)
96 char *p;
97 {
98 while (*p) p++;
99 p--;
100 if (*p == '\n') *p=0;
101 }
102