xref: /illumos-gate/usr/src/cmd/refer/inv5.c (revision ddb365bfc9e868ad24ccdcb0dc91af18b10df082)
1 /*
2  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
7 /*	  All Rights Reserved  	*/
8 
9 /*
10  * Copyright (c) 1980 Regents of the University of California.
11  * All rights reserved. The Berkeley software License Agreement
12  * specifies the terms and conditions for redistribution.
13  */
14 
15 #include <stdio.h>
16 #include <locale.h>
17 
18 extern void err();
19 
20 int
21 recopy(FILE *ft, FILE *fb, FILE *fa, int nhash)
22 {
23 	/* copy fb (old hash items/pointers) to ft (new ones) */
24 	int n, i, iflong;
25 	long getl();
26 	int getw();
27 	int *hpt_s;
28 	int (*getfun)();
29 	long *hpt_l;
30 	long k, lp;
31 	if (fa == NULL) {
32 		err(gettext("No old pointers"), 0);
33 		return (0);
34 	}
35 	fread(&n, sizeof (n), 1, fa);
36 	fread(&iflong, sizeof (iflong), 1, fa);
37 	if (iflong) {
38 		hpt_l = (long *)calloc(sizeof (*hpt_l), n+1);
39 		n = fread(hpt_l, sizeof (*hpt_l), n, fa);
40 	} else {
41 		hpt_s = (int *)calloc(sizeof (*hpt_s), n+1);
42 		n = fread(hpt_s, sizeof (*hpt_s), n, fa);
43 	}
44 	if (n != nhash)
45 		fprintf(stderr, gettext("Changing hash value to old %d\n"), n);
46 	fclose(fa);
47 	if (iflong)
48 		getfun = (int(*)())getl;
49 	else
50 		getfun = getw;
51 	for (i = 0; i < n; i++) {
52 		if (iflong)
53 			lp = hpt_l[i];
54 		else
55 			lp = hpt_s[i];
56 		fseek(fb, lp, 0);
57 		while ((k = (*getfun)(fb)) != -1)
58 			fprintf(ft, "%04d %06ld\n", i, k);
59 	}
60 	fclose(fb);
61 	return (n);
62 }
63