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 /*
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
29
30 #include <stdlib.h>
31 #include <unistd.h>
32 #include <stdio.h>
33 #include <locale.h>
34 #include "hash.h"
35 #include "huff.h"
36
37 int decode(long, long *);
38
39 int hindex[NI];
40 unsigned *table;
41 unsigned wp;
42 int bp;
43 #define U (BYTE*sizeof (unsigned))
44 #define L (BYTE*sizeof (long))
45
46 static long
fetch(void)47 fetch(void)
48 {
49 long w1;
50 long y = 0;
51 int empty = L;
52 int i = bp;
53 int tp = wp;
54 while (empty >= i) {
55 empty -= i;
56 i = U;
57 y |= (long)table[tp++] << empty;
58 }
59 if (empty > 0)
60 y |= table[tp]>>i-empty;
61 i = decode((y >> 1) &
62 (((unsigned long)1 << (BYTE * sizeof (y) - 1)) - 1), &w1);
63 bp -= i;
64 while (bp <= 0) {
65 bp += U;
66 wp++;
67 }
68 return (w1);
69 }
70
71
72 /* ARGSUSED */
73 int
main(int argc,char ** argv)74 main(int argc, char **argv)
75 {
76 int i;
77 long v;
78 long a;
79
80 /* Set locale environment variables local definitions */
81 (void) setlocale(LC_ALL, "");
82 #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
83 #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it wasn't */
84 #endif
85 (void) textdomain(TEXT_DOMAIN);
86
87 (void) rhuff(stdin);
88 (void) fread((char *)hindex, sizeof (*hindex), NI, stdin);
89 table = (unsigned *)malloc(hindex[NI-1]*sizeof (*table));
90 (void) fread((char *)table, sizeof (*table), hindex[NI-1], stdin);
91 for (i = 0; i < NI-1; i++) {
92 bp = U;
93 v = (long)i<<(HASHWIDTH-INDEXWIDTH);
94 for (wp = hindex[i]; wp < hindex[i+1]; ) {
95 if (wp == hindex[i] && bp == U)
96 a = fetch();
97 else {
98 a = fetch();
99 if (a == 0)
100 break;
101 }
102 if (wp > hindex[i+1] ||
103 wp == hindex[i+1] && bp < U)
104 break;
105 v += a;
106 (void) printf("%.9lo\n", v);
107 }
108 }
109 return (0);
110 }
111