xref: /original-bsd/old/refer/inv/inv5.c (revision f052b07a)
1 #ifndef lint
2 static char *sccsid = "@(#)inv5.c	4.3 (Berkeley) 04/24/88";
3 #endif
4 
5 #include <stdio.h>
6 
7 recopy (ft, fb, fa, nhash)
8 FILE *ft, *fb, *fa;
9 {
10 	/* copy fb (old hash items/pointers) to ft (new ones) */
11 	int n, i, iflong;
12 	long getl();
13 	int getw();
14 	int *hpt_s;
15 	long *hpt_l;
16 	long k, lp;
17 	if (fa==NULL)
18 	{
19 		err("No old pointers",0);
20 		return;
21 	}
22 	fread(&n, sizeof(n), 1, fa);
23 	fread(&iflong, sizeof(iflong), 1, fa);
24 	if (iflong)
25 	{
26 		hpt_l = (long *) calloc(sizeof(*hpt_l), n+1);
27 		n =fread(hpt_l, sizeof(*hpt_l), n, fa);
28 	}
29 	else
30 	{
31 		hpt_s =  (int *) calloc(sizeof(*hpt_s), n+1);
32 		n =fread(hpt_s, sizeof(*hpt_s), n, fa);
33 	}
34 	if (n!= nhash)
35 		fprintf(stderr, "Changing hash value to old %d\n",n);
36 	fclose(fa);
37 	for(i=0; i<n; i++)
38 	{
39 		if (iflong) {
40 			lp = hpt_l[i];
41 			fseek(fb, lp, 0);
42 			while ( (k= getl(fb) ) != -1)
43 				fprintf(ft, "%04d %06ld\n",i,k);
44 		} else {
45 			lp = hpt_s[i];
46 			fseek(fb, lp, 0);
47 			while ( (k= getw(fb) ) != -1)
48 				fprintf(ft, "%04d %06ld\n",i,k);
49 		}
50 	}
51 	fclose(fb);
52 	return(n);
53 }
54