xref: /csrg-svn/old/refer/inv/inv6.c (revision 48297)
1*48297Sbostic /*-
2*48297Sbostic  * %sccs.include.proprietary.c%
3*48297Sbostic  */
4*48297Sbostic 
512296Stut #ifndef lint
6*48297Sbostic static char sccsid[] = "@(#)inv6.c	4.3 (Berkeley) 04/18/91";
7*48297Sbostic #endif /* not lint */
812296Stut 
912296Stut #include <stdio.h>
1012296Stut #include <assert.h>
1112296Stut 
whash(ft,fa,fb,nhash,iflong,ptotct,phused)1212296Stut whash(ft, fa, fb, nhash, iflong, ptotct, phused)
1312296Stut FILE *fa, *fb, *ft;
1412296Stut int nhash, *phused;
1512296Stut long *ptotct;
1612296Stut {
1712296Stut 	char line[100];
1812296Stut 	int hash = 0, hused = 0;
1912296Stut 	long totct = 0L;
2012296Stut 	int ct = 0;
2112296Stut 	long point;
2212296Stut 	long opoint = -1;
2312296Stut 	int m;
2412296Stut 	int k;
2512296Stut 	long lp;
2612296Stut 	long *hpt;
2717679Sralph 	int *hfreq;
2812296Stut 
2917679Sralph 	hpt = (long *) calloc (nhash+1, sizeof(*hpt));
3012296Stut 	_assert (hpt != NULL);
3117679Sralph 	hfreq = (int *) calloc (nhash, sizeof(*hfreq));
3217679Sralph 	_assert (hfreq != NULL);
3312296Stut 	hpt[0] = 0;
3412296Stut 	lp= 0;
3512296Stut 	while (fgets(line, 100, ft))
3612296Stut 	{
3712296Stut 		totct++;
3812296Stut 		sscanf(line, "%d %ld", &k, &point);
3912296Stut 		if (hash < k)
4012296Stut 		{
4112296Stut 			hused++;
4212296Stut 			if (iflong) putl(-1L, fb);
4312296Stut 			else putw(-1, fb);
4412296Stut 			hfreq[hash]=ct;
4512296Stut 			while (hash<k)
4612296Stut 			{
4712296Stut 				hpt[++hash] = lp;
4812296Stut 				hfreq[hash] = 0;
4912296Stut 			}
5012296Stut 			hpt[hash] = lp += iflong? sizeof(long) : sizeof(int);
5112296Stut 			opoint= -1;
5212296Stut 			ct=0;
5312296Stut 		}
5412296Stut 		if (point!=opoint)
5512296Stut 		{
5612296Stut 			if (iflong)
5712296Stut 				putl(opoint=point, fb);
5812296Stut 			else
5912296Stut 				putw( (int)(opoint=point), fb);
6012296Stut 			lp += iflong? sizeof(long) : sizeof(int);
6112296Stut 			ct++;
6212296Stut 		}
6312296Stut 	}
6412296Stut 	if (iflong) putl(-1L, fb);
6512296Stut 	else putw(-1,fb);
6612296Stut 	while (hash<nhash)
6712296Stut 		hpt[++hash]=lp;
6812296Stut 	fwrite(&nhash, sizeof(nhash), 1, fa);
6912296Stut 	fwrite(&iflong, sizeof(iflong), 1, fa);
7012296Stut 	fwrite(hpt, sizeof(*hpt), nhash, fa);
7112296Stut 	fwrite (hfreq, sizeof(*hfreq), nhash, fa);
7212296Stut 	*ptotct = totct;
7312296Stut 	*phused = hused;
7412296Stut }
7512296Stut 
putl(ll,f)7612296Stut putl(ll, f)
7712296Stut long ll;
7812296Stut FILE *f;
7912296Stut {
8012296Stut 	putw(ll, f);
8112296Stut }
8212296Stut 
8312296Stut long
getl(f)8412296Stut getl(f)
8512296Stut FILE *f;
8612296Stut {
8712296Stut 	return(getw(f));
8812296Stut }
89