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) 1999 by Sun Microsystems, Inc.
23 * All rights reserved.
24 */
25
26
27
28 #include <libgen.h>
29 #include <stdio.h>
30 #include <ctype.h>
31
32 char * ME;
33 static struct u4_nm {
34 signed int u4;
35 unsigned char nm[256];
36 } u4_nm[0x10000];
37
38
39 static struct to_utf8_table_component2 {
40 unsigned int from;
41 unsigned int u4;
42 unsigned int u8;
43 signed char size;
44 } tbl[0x10000];
45
46 #define INDEX_FOR_BETWEEN_MAX 1000
47
48
49 void
usage(int status)50 usage(int status)
51 {
52 fprintf(stderr, "Usage: %s <mnemonic.txt> < <codeset.txt>\n", ME);
53 exit(status);
54 }
55
56
57 static void mk_u4nm (char *file);
main(int ac,char ** av)58 main(int ac, char **av)
59 {
60 register int i, j;
61 char buf[BUFSIZ], num[100];
62 unsigned int l, k, index_for_between;
63 int mapflag[2];
64 int between[INDEX_FOR_BETWEEN_MAX];
65
66 ME = basename(av[0]);
67 if (ac <= 1) usage(-1);
68 mk_u4nm(av[1]);
69
70 /* if no data, no mapping pair will be created */
71 for (i = 0; i < 0x10000; i++) {
72 tbl[i].size = 0;
73 }
74
75
76 /* for information file, pari data is created */
77 while (fgets(buf, BUFSIZ, stdin)) {
78 i = 0;
79 while (buf[i] && isspace(buf[i]))
80 i++;
81 if (buf[i] == '#' || buf[i] == '\0')
82 continue;
83
84 for (j = 0; !isspace(buf[i]); i++, j++)
85 num[j] = buf[i];
86 num[j] = '\0';
87
88 k = strtol(num, (char **)NULL, 0);
89
90 while (isspace(buf[i]))
91 i++;
92
93 if (buf[i] == '#' || buf[i] == '\0')
94 /* undefined */
95 continue;
96
97 for (j = 0; !isspace(buf[i]); i++, j++)
98 num[j] = buf[i];
99 num[j] = '\0';
100
101 l = strtol(num, (char **)NULL, 0);
102
103 if (tbl[k].size != 0) {
104 /* overwrite */
105 fprintf(stderr, "duplicated mapping for 0x%x\n", k );
106 }
107 tbl[k].u4 = l;
108 tbl[k].from = k;
109
110 if (l < 0x80)
111 tbl[k].size = 1;
112 else if (l < 0x800)
113 tbl[k].size = 2;
114 else if (l < 0x10000)
115 tbl[k].size = 3;
116 else if (l < 0x200000)
117 tbl[k].size = 4;
118 else if (l < 0x4000000)
119 tbl[k].size = 5;
120 else
121 tbl[k].size = 6;
122 }
123 for (i = 0; i < 0x100; i++) {
124 if (tbl[i].size > 0 ) {
125 if (u4_nm[tbl[i].u4].u4 >= 0){
126 printf("0x%0x\t%s\n", i, u4_nm[tbl[i].u4].nm);
127 } else {
128 printf("0x%0x\t ????????\n", i, u4_nm[tbl[i].u4].nm);
129 }
130 } else {
131 printf("0x%0x\t??\n", i);
132 }
133 }
134 return (0);
135 }
136
mk_u4nm(char * file)137 static void mk_u4nm (char *file)
138 {
139 register int i, j;
140 char buf[BUFSIZ], num[100];
141 unsigned int l, k, index_for_between;
142 int mapflag[2];
143 int between[INDEX_FOR_BETWEEN_MAX];
144 int somedatalost = 0;
145 FILE *fd;
146
147
148 for(i = 0; i < 0x1000; i++ ) {
149 u4_nm[k].u4 = -1;
150 }
151
152 if ((fd = fopen(file, "r")) == NULL) {
153 perror("fopen");
154 exit (-1);
155 }
156 while (fgets(buf, BUFSIZ, fd)) {
157 i = 0;
158 while (buf[i] && isspace(buf[i]))
159 i++;
160 if (buf[i] == '#' || buf[i] == '\0')
161 continue;
162
163 for (j = 0; !isspace(buf[i]); i++, j++)
164 num[j] = buf[i];
165 num[j] = '\0';
166
167 k = strtol(num, (char **)NULL, 16);
168
169 while (isspace(buf[i]))
170 i++;
171
172 if (buf[i] == '#' || buf[i] == '\0')
173 /* undefined */
174 continue;
175
176 u4_nm[k].u4 = k;
177 for (j = 0; !isspace(buf[i]); i++, j++)
178 u4_nm[k].nm[j] = buf[i];
179 u4_nm[k].nm[j] = '\0';
180 /* printf("%d(%d): %s\n", k, j, &u4_nm[k].nm[0] ); */
181 }
182 }
183