xref: /illumos-gate/usr/src/cmd/refer/inv5.c (revision f012ee0c3db17469b492c2cf757226f3d7b1ebbc)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
16 
17 #include <stdio.h>
18 #include <locale.h>
19 
20 extern void err();
21 
22 int
23 recopy(FILE *ft, FILE *fb, FILE *fa, int nhash)
24 {
25 	/* copy fb (old hash items/pointers) to ft (new ones) */
26 	int n, i, iflong;
27 	long getl();
28 	int getw();
29 	int *hpt_s;
30 	int (*getfun)();
31 	long *hpt_l;
32 	long k, lp;
33 	if (fa == NULL) {
34 		err(gettext("No old pointers"), 0);
35 		return (0);
36 	}
37 	fread(&n, sizeof (n), 1, fa);
38 	fread(&iflong, sizeof (iflong), 1, fa);
39 	if (iflong) {
40 		hpt_l = (long *)calloc(sizeof (*hpt_l), n+1);
41 		n = fread(hpt_l, sizeof (*hpt_l), n, fa);
42 	} else {
43 		hpt_s = (int *)calloc(sizeof (*hpt_s), n+1);
44 		n = fread(hpt_s, sizeof (*hpt_s), n, fa);
45 	}
46 	if (n != nhash)
47 		fprintf(stderr, gettext("Changing hash value to old %d\n"), n);
48 	fclose(fa);
49 	if (iflong)
50 		getfun = (int(*)())getl;
51 	else
52 		getfun = getw;
53 	for (i = 0; i < n; i++) {
54 		if (iflong)
55 			lp = hpt_l[i];
56 		else
57 			lp = hpt_s[i];
58 		fseek(fb, lp, 0);
59 		while ((k = (*getfun)(fb)) != -1)
60 			fprintf(ft, "%04d %06ld\n", i, k);
61 	}
62 	fclose(fb);
63 	return (n);
64 }
65