1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 1999 by Sun Microsystems, Inc.
* All rights reserved.
*/
#include <libgen.h>
#include <stdio.h>
#include <ctype.h>
char * ME;
static struct u4_nm {
signed int u4;
unsigned char nm[256];
} u4_nm[0x10000];
static struct to_utf8_table_component2 {
unsigned int from;
unsigned int u4;
unsigned int u8;
signed char size;
} tbl[0x10000];
#define INDEX_FOR_BETWEEN_MAX 1000
void
usage(int status)
{
fprintf(stderr, "Usage: %s <mnemonic.txt> < <codeset.txt>\n", ME);
exit(status);
}
static void mk_u4nm (char *file);
main(int ac, char **av)
{
register int i, j;
char buf[BUFSIZ], num[100];
unsigned int l, k, index_for_between;
int mapflag[2];
int between[INDEX_FOR_BETWEEN_MAX];
ME = basename(av[0]);
if (ac <= 1) usage(-1);
mk_u4nm(av[1]);
/* if no data, no mapping pair will be created */
for (i = 0; i < 0x10000; i++) {
tbl[i].size = 0;
}
/* for information file, pari data is created */
while (fgets(buf, BUFSIZ, stdin)) {
i = 0;
while (buf[i] && isspace(buf[i]))
i++;
if (buf[i] == '#' || buf[i] == '\0')
continue;
for (j = 0; !isspace(buf[i]); i++, j++)
num[j] = buf[i];
num[j] = '\0';
k = strtol(num, (char **)NULL, 0);
while (isspace(buf[i]))
i++;
if (buf[i] == '#' || buf[i] == '\0')
/* undefined */
continue;
for (j = 0; !isspace(buf[i]); i++, j++)
num[j] = buf[i];
num[j] = '\0';
l = strtol(num, (char **)NULL, 0);
if (tbl[k].size != 0) {
/* overwrite */
fprintf(stderr, "duplicated mapping for 0x%x\n", k );
}
tbl[k].u4 = l;
tbl[k].from = k;
if (l < 0x80)
tbl[k].size = 1;
else if (l < 0x800)
tbl[k].size = 2;
else if (l < 0x10000)
tbl[k].size = 3;
else if (l < 0x200000)
tbl[k].size = 4;
else if (l < 0x4000000)
tbl[k].size = 5;
else
tbl[k].size = 6;
}
for (i = 0; i < 0x100; i++) {
if (tbl[i].size > 0 ) {
if (u4_nm[tbl[i].u4].u4 >= 0){
printf("0x%0x\t%s\n", i, u4_nm[tbl[i].u4].nm);
} else {
printf("0x%0x\t ????????\n", i, u4_nm[tbl[i].u4].nm);
}
} else {
printf("0x%0x\t??\n", i);
}
}
return (0);
}
static void mk_u4nm (char *file)
{
register int i, j;
char buf[BUFSIZ], num[100];
unsigned int l, k, index_for_between;
int mapflag[2];
int between[INDEX_FOR_BETWEEN_MAX];
int somedatalost = 0;
FILE *fd;
for(i = 0; i < 0x1000; i++ ) {
u4_nm[k].u4 = -1;
}
if ((fd = fopen(file, "r")) == NULL) {
perror("fopen");
exit (-1);
}
while (fgets(buf, BUFSIZ, fd)) {
i = 0;
while (buf[i] && isspace(buf[i]))
i++;
if (buf[i] == '#' || buf[i] == '\0')
continue;
for (j = 0; !isspace(buf[i]); i++, j++)
num[j] = buf[i];
num[j] = '\0';
k = strtol(num, (char **)NULL, 16);
while (isspace(buf[i]))
i++;
if (buf[i] == '#' || buf[i] == '\0')
/* undefined */
continue;
u4_nm[k].u4 = k;
for (j = 0; !isspace(buf[i]); i++, j++)
u4_nm[k].nm[j] = buf[i];
u4_nm[k].nm[j] = '\0';
/* printf("%d(%d): %s\n", k, j, &u4_nm[k].nm[0] ); */
}
}
|