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
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.
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]
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 #pragma ident "%Z%%M% %I% %E% SMI"
40 int encode(long, long *);
42 #define S (BYTE * sizeof (long))
43 #define B (BYTE * sizeof (unsigned))
46 unsigned wp
; /* word pointer */
47 int bp
= B
; /* bit pointer */
52 append(register unsigned w1
, register int i
)
55 table
[wp
] |= w1
>>(B
-bp
);
71 * where N is number of words in dictionary
72 * and standard input contains sorted, unique
73 * hashed words in octal
77 main(int argc
, char **argv
)
87 /* Set locale environment variables local definitions */
88 (void) setlocale(LC_ALL
, "");
89 #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
90 #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it wasn't */
92 (void) textdomain(TEXT_DOMAIN
);
97 (void) fprintf(stderr
, gettext("%s: arg count\n"), argv
[0]);
100 table
= (unsigned *)malloc(ND
* sizeof (*table
));
102 (void) fprintf(stderr
, gettext("%s: no space for table\n"),
106 if ((atof(argv
[1])) == 0.0) {
107 (void) fprintf(stderr
, gettext("%s: illegal count"), argv
[0]);
111 z
= huff((1L<<HASHWIDTH
)/atof(argv
[1]));
112 (void) fprintf(stderr
, gettext("%s: expected code widths = %f\n"),
114 for (count
= 0; scanf("%lo", (unsigned long *)&h
) == 1; ++count
) {
115 if ((t
= h
>> (HASHWIDTH
- INDEXWIDTH
)) != u
) {
121 k
= (long)t
<<(HASHWIDTH
-INDEXWIDTH
);
126 for (x
= d
; ; x
/= 2) {
132 if (!(append((unsigned)(w1
>>(long) (i
-B
)), B
) &&
133 append((unsigned)(w1
<<(long) (B
+B
-i
)),
137 if (!append((unsigned)(w1
<<(long)(B
-i
)), i
))
151 (void) fwrite((char *)hindex
, sizeof (*hindex
), NI
, stdout
);
152 (void) fwrite((char *)table
, sizeof (*table
), wp
, stdout
);
153 (void) fprintf(stderr
,
154 gettext("%s: %ld items, %d ignored, %d extra, %u words occupied\n"),
155 argv
[0], count
, ignore
, extra
, wp
);
157 (void) fprintf(stderr
, "%s: %f table bits/item, %f table+index bits\n",
158 argv
[0], (((float)BYTE
* wp
) * sizeof (*table
) / count
),
159 (BYTE
* ((float)wp
* sizeof (*table
) + sizeof (hindex
)) / count
));