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