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 30*0d8b5334Sceastha #pragma ident "%Z%%M% %I% %E% SMI" 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #include <stdlib.h> 337c478bd9Sstevel@tonic-gate #include <unistd.h> 347c478bd9Sstevel@tonic-gate #include <stdio.h> 357c478bd9Sstevel@tonic-gate #include <locale.h> 367c478bd9Sstevel@tonic-gate #include "hash.h" 377c478bd9Sstevel@tonic-gate #include "huff.h" 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate int decode(long, long *); 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate int hindex[NI]; 427c478bd9Sstevel@tonic-gate unsigned *table; 437c478bd9Sstevel@tonic-gate unsigned wp; 447c478bd9Sstevel@tonic-gate int bp; 457c478bd9Sstevel@tonic-gate #define U (BYTE*sizeof (unsigned)) 467c478bd9Sstevel@tonic-gate #define L (BYTE*sizeof (long)) 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate static long 497c478bd9Sstevel@tonic-gate fetch(void) 507c478bd9Sstevel@tonic-gate { 517c478bd9Sstevel@tonic-gate long w1; 527c478bd9Sstevel@tonic-gate long y = 0; 537c478bd9Sstevel@tonic-gate int empty = L; 547c478bd9Sstevel@tonic-gate int i = bp; 557c478bd9Sstevel@tonic-gate int tp = wp; 567c478bd9Sstevel@tonic-gate while (empty >= i) { 577c478bd9Sstevel@tonic-gate empty -= i; 587c478bd9Sstevel@tonic-gate i = U; 597c478bd9Sstevel@tonic-gate y |= (long)table[tp++] << empty; 607c478bd9Sstevel@tonic-gate } 617c478bd9Sstevel@tonic-gate if (empty > 0) 627c478bd9Sstevel@tonic-gate y |= table[tp]>>i-empty; 637c478bd9Sstevel@tonic-gate i = decode((y >> 1) & 647c478bd9Sstevel@tonic-gate (((unsigned long)1 << (BYTE * sizeof (y) - 1)) - 1), &w1); 657c478bd9Sstevel@tonic-gate bp -= i; 667c478bd9Sstevel@tonic-gate while (bp <= 0) { 677c478bd9Sstevel@tonic-gate bp += U; 687c478bd9Sstevel@tonic-gate wp++; 697c478bd9Sstevel@tonic-gate } 707c478bd9Sstevel@tonic-gate return (w1); 717c478bd9Sstevel@tonic-gate } 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate /* ARGSUSED */ 75*0d8b5334Sceastha int 767c478bd9Sstevel@tonic-gate main(int argc, char **argv) 777c478bd9Sstevel@tonic-gate { 787c478bd9Sstevel@tonic-gate int i; 797c478bd9Sstevel@tonic-gate long v; 807c478bd9Sstevel@tonic-gate long a; 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate /* Set locale environment variables local definitions */ 837c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 847c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */ 857c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it wasn't */ 867c478bd9Sstevel@tonic-gate #endif 877c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate (void) rhuff(stdin); 907c478bd9Sstevel@tonic-gate (void) fread((char *)hindex, sizeof (*hindex), NI, stdin); 917c478bd9Sstevel@tonic-gate table = (unsigned *)malloc(hindex[NI-1]*sizeof (*table)); 927c478bd9Sstevel@tonic-gate (void) fread((char *)table, sizeof (*table), hindex[NI-1], stdin); 937c478bd9Sstevel@tonic-gate for (i = 0; i < NI-1; i++) { 947c478bd9Sstevel@tonic-gate bp = U; 957c478bd9Sstevel@tonic-gate v = (long)i<<(HASHWIDTH-INDEXWIDTH); 967c478bd9Sstevel@tonic-gate for (wp = hindex[i]; wp < hindex[i+1]; ) { 977c478bd9Sstevel@tonic-gate if (wp == hindex[i] && bp == U) 987c478bd9Sstevel@tonic-gate a = fetch(); 997c478bd9Sstevel@tonic-gate else { 1007c478bd9Sstevel@tonic-gate a = fetch(); 1017c478bd9Sstevel@tonic-gate if (a == 0) 1027c478bd9Sstevel@tonic-gate break; 1037c478bd9Sstevel@tonic-gate } 1047c478bd9Sstevel@tonic-gate if (wp > hindex[i+1] || 1057c478bd9Sstevel@tonic-gate wp == hindex[i+1] && bp < U) 1067c478bd9Sstevel@tonic-gate break; 1077c478bd9Sstevel@tonic-gate v += a; 1087c478bd9Sstevel@tonic-gate (void) printf("%.9lo\n", v); 1097c478bd9Sstevel@tonic-gate } 1107c478bd9Sstevel@tonic-gate } 111*0d8b5334Sceastha return (0); 1127c478bd9Sstevel@tonic-gate } 113