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