xref: /titanic_50/usr/src/cmd/spell/hashcheck.c (revision 554ff184129088135ad2643c1c9832174a17be88)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 #ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.2	*/
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <stdio.h>
30 #include <locale.h>
31 #include "hash.h"
32 #include "huff.h"
33 
34 int	decode(long, long *);
35 
36 int hindex[NI];
37 unsigned *table;
38 unsigned wp;
39 int bp;
40 #define	U (BYTE*sizeof (unsigned))
41 #define	L (BYTE*sizeof (long))
42 
43 static long
44 fetch(void)
45 {
46 	long w1;
47 	long y = 0;
48 	int empty = L;
49 	int i = bp;
50 	int tp = wp;
51 	while (empty >= i) {
52 		empty -= i;
53 		i = U;
54 		y |= (long)table[tp++] << empty;
55 	}
56 	if (empty > 0)
57 		y |= table[tp]>>i-empty;
58 	i = decode((y >> 1) &
59 	    (((unsigned long)1 << (BYTE * sizeof (y) - 1)) - 1), &w1);
60 	bp -= i;
61 	while (bp <= 0) {
62 		bp += U;
63 		wp++;
64 	}
65 	return (w1);
66 }
67 
68 
69 /* ARGSUSED */
70 void
71 main(int argc, char **argv)
72 {
73 	int i;
74 	long v;
75 	long a;
76 
77 	/* Set locale environment variables local definitions */
78 	(void) setlocale(LC_ALL, "");
79 #if !defined(TEXT_DOMAIN)	/* Should be defined by cc -D */
80 #define	TEXT_DOMAIN "SYS_TEST"	/* Use this only if it wasn't */
81 #endif
82 	(void) textdomain(TEXT_DOMAIN);
83 
84 	(void) rhuff(stdin);
85 	(void) fread((char *)hindex, sizeof (*hindex), NI, stdin);
86 	table = (unsigned *)malloc(hindex[NI-1]*sizeof (*table));
87 	(void) fread((char *)table, sizeof (*table), hindex[NI-1], stdin);
88 	for (i = 0; i < NI-1; i++) {
89 		bp = U;
90 		v = (long)i<<(HASHWIDTH-INDEXWIDTH);
91 		for (wp = hindex[i]; wp < hindex[i+1]; ) {
92 			if (wp == hindex[i] && bp == U)
93 				a = fetch();
94 			else {
95 				a = fetch();
96 				if (a == 0)
97 					break;
98 			}
99 			if (wp > hindex[i+1] ||
100 				wp == hindex[i+1] && bp < U)
101 				break;
102 			v += a;
103 			(void) printf("%.9lo\n", v);
104 		}
105 	}
106 	exit(0);
107 }
108