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 (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 1998 by Sun Microsystems, Inc.
23 * All rights reserved.
24 *
25 * This particular program generates a table that contains the number of
26 * bytes in a UTF-8 character by only examining the leading byte of a UTF-8
27 * character.
28 */
29
30
31
32 #include <stdio.h>
33 #include "../common_defs.h"
34
main()35 main()
36 {
37 int i;
38 int k, l;
39
40 for (i = 0; i <= 0xff; i++) {
41 if (i <= 0x7f)
42 k = 1;
43 else if (i >= 0xc0 && i <= 0xdf)
44 k = 2;
45 else if (i >= 0xe0 && i <= 0xef)
46 k = 3;
47 else if (i >= 0xf0 && i <= 0xf7)
48 k = 4;
49 else if (i >= 0xf8 && i <= 0xfb)
50 k = 5;
51 else if (i >= 0xfc && i <= 0xfd)
52 k = 6;
53 else
54 k = ICV_TYPE_ILLEGAL_CHAR; /* illegal char */
55
56 if (i == 0 || (i % 16 == 0)) {
57 if (i < 0x80)
58 printf("\n\t");
59 else {
60 printf("\n\n /* ");
61 for (l = i; l < (i + 16); l++)
62 printf("%02X ", l);
63 printf("*/\n\t");
64 }
65 }
66 if (k < 0)
67 printf("%d, ", k);
68 else
69 printf(" %d, ", k);
70 }
71
72 printf("\n");
73 }
74