1 /*-
2 * %sccs.include.proprietary.c%
3 */
4
5 #ifndef lint
6 static char sccsid[] = "@(#)inv6.c 4.3 (Berkeley) 04/18/91";
7 #endif /* not lint */
8
9 #include <stdio.h>
10 #include <assert.h>
11
whash(ft,fa,fb,nhash,iflong,ptotct,phused)12 whash(ft, fa, fb, nhash, iflong, ptotct, phused)
13 FILE *fa, *fb, *ft;
14 int nhash, *phused;
15 long *ptotct;
16 {
17 char line[100];
18 int hash = 0, hused = 0;
19 long totct = 0L;
20 int ct = 0;
21 long point;
22 long opoint = -1;
23 int m;
24 int k;
25 long lp;
26 long *hpt;
27 int *hfreq;
28
29 hpt = (long *) calloc (nhash+1, sizeof(*hpt));
30 _assert (hpt != NULL);
31 hfreq = (int *) calloc (nhash, sizeof(*hfreq));
32 _assert (hfreq != NULL);
33 hpt[0] = 0;
34 lp= 0;
35 while (fgets(line, 100, ft))
36 {
37 totct++;
38 sscanf(line, "%d %ld", &k, &point);
39 if (hash < k)
40 {
41 hused++;
42 if (iflong) putl(-1L, fb);
43 else putw(-1, fb);
44 hfreq[hash]=ct;
45 while (hash<k)
46 {
47 hpt[++hash] = lp;
48 hfreq[hash] = 0;
49 }
50 hpt[hash] = lp += iflong? sizeof(long) : sizeof(int);
51 opoint= -1;
52 ct=0;
53 }
54 if (point!=opoint)
55 {
56 if (iflong)
57 putl(opoint=point, fb);
58 else
59 putw( (int)(opoint=point), fb);
60 lp += iflong? sizeof(long) : sizeof(int);
61 ct++;
62 }
63 }
64 if (iflong) putl(-1L, fb);
65 else putw(-1,fb);
66 while (hash<nhash)
67 hpt[++hash]=lp;
68 fwrite(&nhash, sizeof(nhash), 1, fa);
69 fwrite(&iflong, sizeof(iflong), 1, fa);
70 fwrite(hpt, sizeof(*hpt), nhash, fa);
71 fwrite (hfreq, sizeof(*hfreq), nhash, fa);
72 *ptotct = totct;
73 *phused = hused;
74 }
75
putl(ll,f)76 putl(ll, f)
77 long ll;
78 FILE *f;
79 {
80 putw(ll, f);
81 }
82
83 long
getl(f)84 getl(f)
85 FILE *f;
86 {
87 return(getw(f));
88 }
89