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 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 
27 
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <ctype.h>
31 #include <strings.h>
32 #include "../common_defs.h"
33 
34 int
main(int ac,char ** av)35 main(int ac, char **av)
36 {
37 	to_utf8_table_component_t tbl[256];
38 	register int i, j;
39 	char buf[BUFSIZ], num[100];
40 	unsigned int l, k;
41 	char ascii_only = 0;
42 
43 	if (ac > 1 && strcmp(av[1], "-ascii") == 0)
44 		ascii_only = 1;
45 
46 	for (i = 0; i < 256; i++) {
47 		if (i <= 0x1f || i == 0x7f || (ascii_only && i <= 0x7f)) {
48 			tbl[i].size = (signed char)1;
49 			tbl[i].u8 = (unsigned int)i;
50 		} else if (!ascii_only && (i >= 0x80 && i <= 0x9f)) {
51 			tbl[i].size = (signed char)2;
52 			tbl[i].u8 = (unsigned int)i;
53 		} else {
54 			tbl[i].size = (signed char)ICV_TYPE_ILLEGAL_CHAR;
55 			tbl[i].u8 = 0;
56 		}
57 	}
58 
59 
60 	while (fgets(buf, BUFSIZ, stdin)) {
61 		i = 0;
62 		while (buf[i] && isspace(buf[i]))
63 			i++;
64 		if (strncmp(buf + i, "<U", 2) != 0)
65 			continue;
66 
67 		i += 2;
68 		for (j = 0; isxdigit(buf[i]); i++, j++)
69 			num[j] = buf[i];
70 		num[j] = '\0';
71 
72 		l = strtol(num, (char **)NULL, 16);
73 
74 		while (!isxdigit(buf[i]))
75 			i++;
76 
77 		for (j = 0; isxdigit(buf[i]); i++, j++)
78 			num[j] = buf[i];
79 		num[j] = '\0';
80 
81 		k = strtol(num, (char **)NULL, 16);
82 
83 		while (buf[i] == ' ' || buf[i] == '\t')
84 			i++;
85 
86 		if (strncmp(buf + i, "|0", 2) != 0)
87 			continue;
88 
89 		tbl[k].u8 = l;
90 		if (l < 0x80)
91 			tbl[k].size = (signed char)1;
92 		else if (l < 0x800)
93 			tbl[k].size = (signed char)2;
94 		else if (l < 0x10000)
95 			tbl[k].size = (signed char)3;
96 		else if (l < 0x200000)
97 			tbl[k].size = (signed char)4;
98 		else if (l < 0x4000000)
99 			tbl[k].size = (signed char)5;
100 		else
101 			tbl[k].size = (signed char)6;
102 
103 	}
104 
105 	for (i = 0; i < 256; i++) {
106 		l = tbl[i].u8;
107 		if (i > 0x7f && l != 0)
108 			printf("\t{  0x%08X, 0x%02X  },\n", l, i);
109 	}
110 
111 	if (ascii_only)
112 		printf("\t{  0x%08X, 0x%02X  },\n", 0, 0);
113 
114         fprintf(stderr, "%s: make sure you sort the result by using\n\n\
115 \tsort -k 1 -t ',' result_file\n\n\
116 since iconv module that will include the result table uses binary search.\n",
117 av[0]);
118 }
119