diff options
Diffstat (limited to 'tools/codepages.c')
-rw-r--r-- | tools/codepages.c | 115 |
1 files changed, 83 insertions, 32 deletions
diff --git a/tools/codepages.c b/tools/codepages.c index e19d39c85a..651a99c429 100644 --- a/tools/codepages.c +++ b/tools/codepages.c | |||
@@ -23,6 +23,10 @@ | |||
23 | 23 | ||
24 | #define MAX_TABLE_SIZE 32768 | 24 | #define MAX_TABLE_SIZE 32768 |
25 | 25 | ||
26 | static const int mini_index[5] = { | ||
27 | 0, 1, 3, 6, 7 | ||
28 | }; | ||
29 | |||
26 | static unsigned short iso_table[MAX_TABLE_SIZE]; | 30 | static unsigned short iso_table[MAX_TABLE_SIZE]; |
27 | 31 | ||
28 | unsigned short iso_decode(unsigned char *latin1, int cp, int count) | 32 | unsigned short iso_decode(unsigned char *latin1, int cp, int count) |
@@ -147,53 +151,100 @@ int writeshort(FILE *f, unsigned short s) | |||
147 | return putc(s>>8, f) != EOF; | 151 | return putc(s>>8, f) != EOF; |
148 | } | 152 | } |
149 | 153 | ||
150 | int main(void) | 154 | void print_usage(void) |
151 | { | 155 | { |
156 | printf("Usage: codepages [-m]\n" | ||
157 | "\t-m Create isomini.cp only\n"); | ||
158 | printf("build date: " __DATE__ "\n\n"); | ||
159 | } | ||
152 | 160 | ||
161 | int main(int argc, char **argv) | ||
162 | { | ||
163 | int mini = 0; | ||
153 | int i, j; | 164 | int i, j; |
154 | unsigned char k; | 165 | unsigned char k; |
155 | unsigned short uni; | 166 | unsigned short uni; |
156 | FILE *of; | 167 | FILE *of; |
157 | 168 | ||
169 | for (i = 1;i < argc;i++) | ||
170 | { | ||
171 | if (argv[i][0] == '-') | ||
172 | { | ||
173 | switch (argv[i][1]) | ||
174 | { | ||
175 | case 'm': /* create isomini.cp only */ | ||
176 | mini = 1; | ||
177 | break; | ||
178 | |||
179 | case 'h': /* help */ | ||
180 | case '?': | ||
181 | print_usage(); | ||
182 | exit(1); | ||
183 | break; | ||
184 | |||
185 | default: | ||
186 | print_usage(); | ||
187 | exit(1); | ||
188 | break; | ||
189 | } | ||
190 | } | ||
191 | } | ||
192 | |||
158 | for (i=0; i < MAX_TABLE_SIZE; i++) | 193 | for (i=0; i < MAX_TABLE_SIZE; i++) |
159 | iso_table[i] = 0; | 194 | iso_table[i] = 0; |
160 | 195 | ||
161 | of = fopen("iso.cp", "wb"); | 196 | if (mini) { |
162 | if (!of) return 1; | 197 | of = fopen("isomini.cp", "wb"); |
198 | if (!of) return 1; | ||
163 | 199 | ||
164 | for (i=1; i<8; i++) { | 200 | for (i=1; i<5; i++) { |
165 | 201 | ||
166 | for (j=0; j<128; j++) { | 202 | for (j=0; j<128; j++) { |
167 | k = (unsigned char)j + 128; | 203 | k = (unsigned char)j + 128; |
168 | uni = iso_decode(&k, i, 1); | 204 | uni = iso_decode(&k, mini_index[i], 1); |
169 | writeshort(of, uni); | 205 | writeshort(of, uni); |
206 | } | ||
170 | } | 207 | } |
208 | fclose(of); | ||
171 | } | 209 | } |
172 | fclose(of); | 210 | else { |
211 | of = fopen("iso.cp", "wb"); | ||
212 | if (!of) return 1; | ||
173 | 213 | ||
174 | of = fopen("932.cp", "wb"); | 214 | for (i=1; i<8; i++) { |
175 | if (!of) return 1; | 215 | |
176 | for (i=0; i < MAX_TABLE_SIZE; i++) | 216 | for (j=0; j<128; j++) { |
177 | writeshort(of, cp932_table[i]); | 217 | k = (unsigned char)j + 128; |
178 | fclose(of); | 218 | uni = iso_decode(&k, i, 1); |
179 | 219 | writeshort(of, uni); | |
180 | of = fopen("936.cp", "wb"); | 220 | } |
181 | if (!of) return 1; | 221 | } |
182 | for (i=0; i < MAX_TABLE_SIZE; i++) | 222 | fclose(of); |
183 | writeshort(of, cp936_table[i]); | 223 | |
184 | fclose(of); | 224 | of = fopen("932.cp", "wb"); |
185 | 225 | if (!of) return 1; | |
186 | of = fopen("949.cp", "wb"); | 226 | for (i=0; i < MAX_TABLE_SIZE; i++) |
187 | if (!of) return 1; | 227 | writeshort(of, cp932_table[i]); |
188 | for (i=0; i < MAX_TABLE_SIZE; i++) | 228 | fclose(of); |
189 | writeshort(of, cp949_table[i]); | 229 | |
190 | fclose(of); | 230 | of = fopen("936.cp", "wb"); |
191 | 231 | if (!of) return 1; | |
192 | of = fopen("950.cp", "wb"); | 232 | for (i=0; i < MAX_TABLE_SIZE; i++) |
193 | if (!of) return 1; | 233 | writeshort(of, cp936_table[i]); |
194 | for (i=0; i < MAX_TABLE_SIZE; i++) | 234 | fclose(of); |
195 | writeshort(of, cp950_table[i]); | 235 | |
196 | fclose(of); | 236 | of = fopen("949.cp", "wb"); |
237 | if (!of) return 1; | ||
238 | for (i=0; i < MAX_TABLE_SIZE; i++) | ||
239 | writeshort(of, cp949_table[i]); | ||
240 | fclose(of); | ||
241 | |||
242 | of = fopen("950.cp", "wb"); | ||
243 | if (!of) return 1; | ||
244 | for (i=0; i < MAX_TABLE_SIZE; i++) | ||
245 | writeshort(of, cp950_table[i]); | ||
246 | fclose(of); | ||
247 | } | ||
197 | 248 | ||
198 | return 0; | 249 | return 0; |
199 | } | 250 | } |