xref: /titanic_41/usr/src/cmd/refer/inv5.c (revision 11a8fa6cb17403e630122ac19b39a323c6e64142)
1*11a8fa6cSceastha /*
2*11a8fa6cSceastha  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3*11a8fa6cSceastha  * Use is subject to license terms.
4*11a8fa6cSceastha  */
5*11a8fa6cSceastha 
67c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
77c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
87c478bd9Sstevel@tonic-gate 
97c478bd9Sstevel@tonic-gate /*
107c478bd9Sstevel@tonic-gate  * Copyright (c) 1980 Regents of the University of California.
117c478bd9Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
127c478bd9Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
137c478bd9Sstevel@tonic-gate  */
147c478bd9Sstevel@tonic-gate 
157c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
167c478bd9Sstevel@tonic-gate 
177c478bd9Sstevel@tonic-gate #include <stdio.h>
187c478bd9Sstevel@tonic-gate #include <locale.h>
197c478bd9Sstevel@tonic-gate 
20*11a8fa6cSceastha extern void err();
21*11a8fa6cSceastha 
22*11a8fa6cSceastha int
recopy(FILE * ft,FILE * fb,FILE * fa,int nhash)23*11a8fa6cSceastha recopy(FILE *ft, FILE *fb, FILE *fa, int nhash)
247c478bd9Sstevel@tonic-gate {
257c478bd9Sstevel@tonic-gate 	/* copy fb (old hash items/pointers) to ft (new ones) */
267c478bd9Sstevel@tonic-gate 	int n, i, iflong;
277c478bd9Sstevel@tonic-gate 	long getl();
287c478bd9Sstevel@tonic-gate 	int getw();
297c478bd9Sstevel@tonic-gate 	int *hpt_s;
307c478bd9Sstevel@tonic-gate 	int (*getfun)();
317c478bd9Sstevel@tonic-gate 	long *hpt_l;
327c478bd9Sstevel@tonic-gate 	long k, lp;
33*11a8fa6cSceastha 	if (fa == NULL) {
347c478bd9Sstevel@tonic-gate 		err(gettext("No old pointers"), 0);
35*11a8fa6cSceastha 		return (0);
367c478bd9Sstevel@tonic-gate 	}
377c478bd9Sstevel@tonic-gate 	fread(&n, sizeof (n), 1, fa);
387c478bd9Sstevel@tonic-gate 	fread(&iflong, sizeof (iflong), 1, fa);
39*11a8fa6cSceastha 	if (iflong) {
407c478bd9Sstevel@tonic-gate 		hpt_l = (long *)calloc(sizeof (*hpt_l), n+1);
417c478bd9Sstevel@tonic-gate 		n = fread(hpt_l, sizeof (*hpt_l), n, fa);
42*11a8fa6cSceastha 	} else {
437c478bd9Sstevel@tonic-gate 		hpt_s = (int *)calloc(sizeof (*hpt_s), n+1);
447c478bd9Sstevel@tonic-gate 		n = fread(hpt_s, sizeof (*hpt_s), n, fa);
457c478bd9Sstevel@tonic-gate 	}
467c478bd9Sstevel@tonic-gate 	if (n != nhash)
477c478bd9Sstevel@tonic-gate 		fprintf(stderr, gettext("Changing hash value to old %d\n"), n);
487c478bd9Sstevel@tonic-gate 	fclose(fa);
497c478bd9Sstevel@tonic-gate 	if (iflong)
507c478bd9Sstevel@tonic-gate 		getfun = (int(*)())getl;
517c478bd9Sstevel@tonic-gate 	else
527c478bd9Sstevel@tonic-gate 		getfun = getw;
53*11a8fa6cSceastha 	for (i = 0; i < n; i++) {
547c478bd9Sstevel@tonic-gate 		if (iflong)
557c478bd9Sstevel@tonic-gate 			lp = hpt_l[i];
567c478bd9Sstevel@tonic-gate 		else
577c478bd9Sstevel@tonic-gate 			lp = hpt_s[i];
587c478bd9Sstevel@tonic-gate 		fseek(fb, lp, 0);
597c478bd9Sstevel@tonic-gate 		while ((k = (*getfun)(fb)) != -1)
607c478bd9Sstevel@tonic-gate 			fprintf(ft, "%04d %06ld\n", i, k);
617c478bd9Sstevel@tonic-gate 	}
627c478bd9Sstevel@tonic-gate 	fclose(fb);
637c478bd9Sstevel@tonic-gate 	return (n);
647c478bd9Sstevel@tonic-gate }
65