xref: /illumos-gate/usr/src/cmd/spell/hashcheck.c (revision 2a8bcb4e)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
22*0d8b5334Sceastha /*
23*0d8b5334Sceastha  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*0d8b5334Sceastha  * Use is subject to license terms.
25*0d8b5334Sceastha  */
26*0d8b5334Sceastha 
277c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
287c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #include <stdlib.h>
317c478bd9Sstevel@tonic-gate #include <unistd.h>
327c478bd9Sstevel@tonic-gate #include <stdio.h>
337c478bd9Sstevel@tonic-gate #include <locale.h>
347c478bd9Sstevel@tonic-gate #include "hash.h"
357c478bd9Sstevel@tonic-gate #include "huff.h"
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate int	decode(long, long *);
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate int hindex[NI];
407c478bd9Sstevel@tonic-gate unsigned *table;
417c478bd9Sstevel@tonic-gate unsigned wp;
427c478bd9Sstevel@tonic-gate int bp;
437c478bd9Sstevel@tonic-gate #define	U (BYTE*sizeof (unsigned))
447c478bd9Sstevel@tonic-gate #define	L (BYTE*sizeof (long))
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate static long
fetch(void)477c478bd9Sstevel@tonic-gate fetch(void)
487c478bd9Sstevel@tonic-gate {
497c478bd9Sstevel@tonic-gate 	long w1;
507c478bd9Sstevel@tonic-gate 	long y = 0;
517c478bd9Sstevel@tonic-gate 	int empty = L;
527c478bd9Sstevel@tonic-gate 	int i = bp;
537c478bd9Sstevel@tonic-gate 	int tp = wp;
547c478bd9Sstevel@tonic-gate 	while (empty >= i) {
557c478bd9Sstevel@tonic-gate 		empty -= i;
567c478bd9Sstevel@tonic-gate 		i = U;
577c478bd9Sstevel@tonic-gate 		y |= (long)table[tp++] << empty;
587c478bd9Sstevel@tonic-gate 	}
597c478bd9Sstevel@tonic-gate 	if (empty > 0)
607c478bd9Sstevel@tonic-gate 		y |= table[tp]>>i-empty;
617c478bd9Sstevel@tonic-gate 	i = decode((y >> 1) &
627c478bd9Sstevel@tonic-gate 	    (((unsigned long)1 << (BYTE * sizeof (y) - 1)) - 1), &w1);
637c478bd9Sstevel@tonic-gate 	bp -= i;
647c478bd9Sstevel@tonic-gate 	while (bp <= 0) {
657c478bd9Sstevel@tonic-gate 		bp += U;
667c478bd9Sstevel@tonic-gate 		wp++;
677c478bd9Sstevel@tonic-gate 	}
687c478bd9Sstevel@tonic-gate 	return (w1);
697c478bd9Sstevel@tonic-gate }
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate /* ARGSUSED */
73*0d8b5334Sceastha int
main(int argc,char ** argv)747c478bd9Sstevel@tonic-gate main(int argc, char **argv)
757c478bd9Sstevel@tonic-gate {
767c478bd9Sstevel@tonic-gate 	int i;
777c478bd9Sstevel@tonic-gate 	long v;
787c478bd9Sstevel@tonic-gate 	long a;
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate 	/* Set locale environment variables local definitions */
817c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
827c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)	/* Should be defined by cc -D */
837c478bd9Sstevel@tonic-gate #define	TEXT_DOMAIN "SYS_TEST"	/* Use this only if it wasn't */
847c478bd9Sstevel@tonic-gate #endif
857c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate 	(void) rhuff(stdin);
887c478bd9Sstevel@tonic-gate 	(void) fread((char *)hindex, sizeof (*hindex), NI, stdin);
897c478bd9Sstevel@tonic-gate 	table = (unsigned *)malloc(hindex[NI-1]*sizeof (*table));
907c478bd9Sstevel@tonic-gate 	(void) fread((char *)table, sizeof (*table), hindex[NI-1], stdin);
917c478bd9Sstevel@tonic-gate 	for (i = 0; i < NI-1; i++) {
927c478bd9Sstevel@tonic-gate 		bp = U;
937c478bd9Sstevel@tonic-gate 		v = (long)i<<(HASHWIDTH-INDEXWIDTH);
947c478bd9Sstevel@tonic-gate 		for (wp = hindex[i]; wp < hindex[i+1]; ) {
957c478bd9Sstevel@tonic-gate 			if (wp == hindex[i] && bp == U)
967c478bd9Sstevel@tonic-gate 				a = fetch();
977c478bd9Sstevel@tonic-gate 			else {
987c478bd9Sstevel@tonic-gate 				a = fetch();
997c478bd9Sstevel@tonic-gate 				if (a == 0)
1007c478bd9Sstevel@tonic-gate 					break;
1017c478bd9Sstevel@tonic-gate 			}
1027c478bd9Sstevel@tonic-gate 			if (wp > hindex[i+1] ||
1037c478bd9Sstevel@tonic-gate 				wp == hindex[i+1] && bp < U)
1047c478bd9Sstevel@tonic-gate 				break;
1057c478bd9Sstevel@tonic-gate 			v += a;
1067c478bd9Sstevel@tonic-gate 			(void) printf("%.9lo\n", v);
1077c478bd9Sstevel@tonic-gate 		}
1087c478bd9Sstevel@tonic-gate 	}
109*0d8b5334Sceastha 	return (0);
1107c478bd9Sstevel@tonic-gate }
111