xref: /csrg-svn/old/refer/inv/inv5.c (revision 17679)
112295Stut #ifndef lint
2*17679Sralph static char *sccsid = "@(#)inv5.c	4.2 (Berkeley) 01/09/85";
312295Stut #endif
412295Stut 
512295Stut #include <stdio.h>
612295Stut 
712295Stut recopy (ft, fb, fa, nhash)
812295Stut FILE *ft, *fb, *fa;
912295Stut {
1012295Stut 	/* copy fb (old hash items/pointers) to ft (new ones) */
1112295Stut 	int n, i, iflong;
1212295Stut 	long getl();
1312295Stut 	int getw();
1412295Stut 	int *hpt_s;
1512295Stut 	int (*getfun)();
1612295Stut 	long *hpt_l;
1712295Stut 	long k, lp;
1812295Stut 	if (fa==NULL)
1912295Stut 	{
2012295Stut 		err("No old pointers",0);
2112295Stut 		return;
2212295Stut 	}
2312295Stut 	fread(&n, sizeof(n), 1, fa);
2412295Stut 	fread(&iflong, sizeof(iflong), 1, fa);
2512295Stut 	if (iflong)
2612295Stut 	{
27*17679Sralph 		hpt_l = (long *) calloc(sizeof(*hpt_l), n+1);
2812295Stut 		n =fread(hpt_l, sizeof(*hpt_l), n, fa);
2912295Stut 	}
3012295Stut 	else
3112295Stut 	{
32*17679Sralph 		hpt_s =  (int *) calloc(sizeof(*hpt_s), n+1);
3312295Stut 		n =fread(hpt_s, sizeof(*hpt_s), n, fa);
3412295Stut 	}
3512295Stut 	if (n!= nhash)
3612295Stut 		fprintf(stderr, "Changing hash value to old %d\n",n);
3712295Stut 	fclose(fa);
3812295Stut 	if (iflong)
3912295Stut 		getfun = getl;
4012295Stut 	else
4112295Stut 		getfun = getw;
4212295Stut 	for(i=0; i<n; i++)
4312295Stut 	{
4412295Stut 		if (iflong)
4512295Stut 			lp = hpt_l[i];
4612295Stut 		else
4712295Stut 			lp = hpt_s[i];
4812295Stut 		fseek(fb, lp, 0);
4912295Stut 		while ( (k= (*getfun)(fb) ) != -1)
5012295Stut 			fprintf(ft, "%04d %06ld\n",i,k);
5112295Stut 	}
5212295Stut 	fclose(fb);
5312295Stut 	return(n);
5412295Stut }
55