Debian Codegraph @

contrib/cidmap/src/mapjapan1.c

raw symbols SCIP
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include "utype.h"
5
6 static char used[0x110000];
7 static int cid_2_unicode[0x100000];
8 static char *nonuni_names[0x100000];
9 static int cid_2_rotunicode[0x100000];
10 #define MULT_MAX 6
11 static int cid_2_unicodemult[0x100000][MULT_MAX];
12
13 static int hwtable390[] = {
14 646, 1004, 1005, 1002, 1009, 1010, 1008, 936, 938, 940, 942, 944, 946, 948,
15 950, 952, 954, 956, 958, 961, 963, 965, 972, 973, 975, 976, 978, 979, 981,
16 982, 984, 985 };
17 static int hwtable501[] = { 645, 647, 672 };
18 static int hwtable516[] = {
19 923, 842, 844, 846, 848, 850, 908, 910, 912, 876, 843, 845, 847, 849, 851,
20 852, 854, 856, 858, 860, 862, 864, 866, 868, 870, 872, 874, 877, 879, 881,
21 883, 884, 885, 886, 887, 888, 891, 894, 897, 900, 903, 904, 905, 906, 907,
22 909, 911, 913, 914, 915, 916, 917, 918, 920, 924, 921, 922, 919, 853, 855,
23 857, 859, 861, 863, 865, 867, 869, 871, 873, 875, 878, 880, 882, 889, 890,
24 892, 893, 895, 896, 898, 899, 901, 902 };
25
26 #define VERTMARK 0x1000000
27
28 static int ucs2_score(int val) { /* Supplied by KANOU Hiroki */
29 if ( val>=0x2e80 && val<=0x2fff )
30 return( 1 ); /* New CJK Radicals are least important */
31 else if ( val>=VERTMARK )
32 return( 2 ); /* Then vertical guys */
33 else if ( val>=0xf000 && val<=0xffff )
34 return( 3 );
35 /* else if (( val>=0x3400 && val<0x3dff ) || (val>=0x4000 && val<=0x4dff))*/
36 else if ( val>=0x3400 && val<=0x4dff )
37 return( 4 );
38 else
39 return( 5 );
40 }
41
42 static int getnth(char *buffer, int col, int *mults) {
43 int i,j=0, val=0, best;
44 char *end;
45 int vals[10];
46
47 if ( col==1 ) {
48 /* first column is decimal, others are hex */
49 if ( !isdigit(*buffer))
50 return( -1 );
51 while ( isdigit(*buffer))
52 val = 10*val + *buffer++-'0';
53 return( val );
54 }
55 for ( i=1; i<col; ++buffer ) {
56 if ( *buffer=='\t' )
57 ++i;
58 else if ( *buffer=='\0' )
59 return( -1 );
60 }
61 val = strtol(buffer,&end,16);
62 if ( end==buffer )
63 return( -1 );
64 if ( *end=='v' ) {
65 val += VERTMARK;
66 ++end;
67 }
68 if ( *end==',' ) {
69 /* Multiple guess... now we've got to pick one */
70 vals[0] = val;
71 i = 1;
72 while ( *end==',' && i<9 ) {
73 buffer = end+1;
74 vals[i] = strtol(buffer,&end,16);
75 if ( *end=='v' ) {
76 vals[i] += VERTMARK;
77 ++end;
78 }
79 ++i;
80 }
81 vals[i] = 0;
82 best = 0; val = -1;
83 for ( i=0; vals[i]!=0; ++i ) {
84 int score=ucs2_score(vals[i]);
85 if ( score>best || (score==best && vals[i]<val) ) {
86 val = vals[i];
87 best = score;
88 }
89 }
90 if ( mults!=NULL ) for ( i=j=0; vals[i]!=0; ++i ) {
91 if ( vals[i]!=val && !(vals[i]&VERTMARK))
92 mults[j++] = vals[i];
93 }
94 if ( j>MULT_MAX ) {
95 fprintf( stderr, "Too many multiple values for %04x, need %d slots\n", (unsigned int)(val), j );
96 exit(1);
97 }
98 }
99 return( val );
100 }
101
102 int main(int argc, char **argv) {
103 char buffer[600];
104 int cid, uni, max=0, maxcid=0, i,j, fakeuni;
105
106 nonuni_names[0] = ".notdef";
107 for ( cid=0; cid<0x10000; ++cid ) cid_2_unicode[cid] = -1;
108
109 while ( fgets(buffer,sizeof(buffer),stdin)!=NULL ) {
110 if ( *buffer=='#' )
111 continue;
112 cid = getnth(buffer,1,NULL);
113 if ( cid==-1 )
114 continue;
115 uni = getnth(buffer,22,cid_2_unicodemult[cid]);
116 if ( uni==-1 )
117 uni = getnth(buffer,18,cid_2_unicodemult[cid]);
118 if ( uni==-1 )
119 uni = getnth(buffer,19,cid_2_unicodemult[cid]);
120 fakeuni = -1;
121 if ( uni==-1 ) {
122 /* I'm mis-understanding something. Why aren't these guys encoded? */
123 /* Ah, some are halfwidth rather than full... */
124 if ( cid==124 ) fakeuni = 0x2026; /* and this is proportional not full */
125 else if ( cid>=425 && cid<=500 ) fakeuni = 0x2500+cid-425;
126 else if ( cid>=504 && cid<=505 ) fakeuni = 0x3014+cid-504;
127 else if ( cid>=506 && cid<=513 ) fakeuni = 0x3008+cid-506;
128 else if ( cid>=516 && cid<=597 ) {
129 /* These are hiragana, but so disordered (to my eye) that */
130 /* I can't identify them */
131 } else if ( cid==599 ) fakeuni=0xc4;
132 else if ( cid==600 ) fakeuni=0xf9;
133 else if ( cid==601 ) fakeuni=0xe9;
134 else if ( cid==602 ) fakeuni=0xed;
135 else if ( cid==603 ) fakeuni=0xdf;
136 else if ( cid==604 ) fakeuni=0xe7;
137 else if ( cid==605 ) fakeuni=0xc7;
138 else if ( cid==606 ) fakeuni=0xd1;
139 else if ( cid==607 ) fakeuni=0xf1;
140 else if ( cid==608 ) fakeuni=0xa2;
141 else if ( cid==609 ) fakeuni=0xa3;
142 else if ( cid==610 ) fakeuni=0xf3;
143 else if ( cid==611 ) fakeuni=0xfa;
144 else if ( cid==612 ) fakeuni=0xa1;
145 else if ( cid==613 ) fakeuni=0xbf;
146 else if ( cid==614 ) fakeuni=0xbd;
147 else if ( cid==615 ) fakeuni=0xd6;
148 else if ( cid==616 ) fakeuni=0xdc;
149 else if ( cid==617 ) fakeuni=0xe4;
150 else if ( cid==618 ) fakeuni=0xeb;
151 else if ( cid==619 ) fakeuni=0xef;
152 else if ( cid==620 ) fakeuni=0xf6;
153 else if ( cid==621 ) fakeuni=0xfc;
154 else if ( cid==622 ) fakeuni=0xe2;
155 else if ( cid==623 ) fakeuni=0xea;
156 else if ( cid==624 ) fakeuni=0xee;
157 else if ( cid==625 ) fakeuni=0xf4;
158 else if ( cid==626 ) fakeuni=0xfb;
159 else if ( cid==627 ) fakeuni=0xe0;
160 else if ( cid==628 ) fakeuni=0xe8;
161 else if ( cid==630 ) fakeuni=0xe1;
162 else if ( cid==632 ) fakeuni=0xd8;
163 else if ( cid>=8720 && cid<=8814 ) fakeuni=' '+cid-8720;
164 else if ( cid==9435 ) fakeuni = 0x237; /* dotlessj, 0xf6be */
165 else if ( cid==9504 ) fakeuni = 0xa5;
166 else if ( cid>=9444 && cid<=9537 ) fakeuni = ' '+cid-9444;
167 else if ( cid==9540 ) fakeuni = '\\';
168 else if ( cid>=9544 && cid<=9546 ) fakeuni = 0xa1+cid-9544;
169 else if ( cid==9549 ) fakeuni = 0xa7;
170 else if ( cid==9550 ) fakeuni = 0xa4;
171 else if ( cid==9551 ) fakeuni = 0x201c;
172 else if ( cid==9552 ) fakeuni = 0xab;
173 else if ( cid==9553 ) fakeuni = 0x2039;
174 else if ( cid==9554 ) fakeuni = 0x203a;
175 else if ( cid==9555 ) fakeuni = 0xfb01;
176 else if ( cid==9556 ) fakeuni = 0xfb02;
177 else if ( cid==9558 ) fakeuni = 0x2020;
178 else if ( cid==9559 ) fakeuni = 0x2021;
179 else if ( cid==9560 ) fakeuni = 0xb7;
180 else if ( cid==9561 ) fakeuni = 0xb6;
181 else if ( cid==9562 ) fakeuni = 0x2022;
182 else if ( cid==9563 ) fakeuni = 0x201a;
183 else if ( cid==9564 ) fakeuni = 0x201e;
184 else if ( cid==9565 ) fakeuni = 0x201d;
185 else if ( cid==9566 ) fakeuni = 0xbb;
186 else if ( cid==9567 ) fakeuni = 0x2026;
187 else if ( cid==9568 ) fakeuni = 0x2030;
188 else if ( cid==9569 ) fakeuni = 0xbf;
189 else if ( cid==9570 ) fakeuni = 0x2ca;
190 else if ( cid==9571 ) fakeuni = 0x2c6;
191 else if ( cid==9572 ) fakeuni = 0xaf;
192 else if ( cid==9573 ) fakeuni = 0x2d8;
193 else if ( cid==9574 ) fakeuni = 0x2d9;
194 else if ( cid==9575 ) fakeuni = 0xa8;
195 else if ( cid==9576 ) fakeuni = 0x2da;
196 else if ( cid==9577 ) fakeuni = 0xb8;
197 else if ( cid==9578 ) fakeuni = 0x2dd;
198 else if ( cid==9579 ) fakeuni = 0x2db;
199 else if ( cid==9580 ) fakeuni = 0x2c7;
200 else if ( cid==9581 ) fakeuni = 0x2014;
201 else if ( cid==9582 ) fakeuni = 0xc6;
202 else if ( cid==9583 ) fakeuni = 0xaa;
203 else if ( cid==9584 ) fakeuni = 0x141;
204 else if ( cid==9585 ) fakeuni = 0xd8;
205 else if ( cid==9586 ) fakeuni = 0x152;
206 else if ( cid==9587 ) fakeuni = 0xba;
207 else if ( cid==9588 ) fakeuni = 0xe6;
208 else if ( cid==9589 ) fakeuni = 0x131;
209 else if ( cid==9590 ) fakeuni = 0x142;
210 else if ( cid==9591 ) fakeuni = 0xf8;
211 else if ( cid==9592 ) fakeuni = 0x153;
212 else if ( cid==9593 ) fakeuni = 0xdf;
213 else if ( cid==9595 ) fakeuni = 0xa9;
214 else if ( cid==9596 ) fakeuni = 0xac;
215 else if ( cid==9597 ) fakeuni = 0xae;
216 else if ( cid==9598 ) fakeuni = 0xb0;
217 else if ( cid>=9599 && cid<=9601 ) fakeuni = 0xb1+cid-9599;
218 else if ( cid==9602 ) fakeuni = 0xb5;
219 else if ( cid==9603 ) fakeuni = 0xb9;
220 else if ( cid>=9604 && cid<=9606 ) fakeuni = 0xbc+cid-9604;
221 else if ( cid>=9607 && cid<=9612 ) fakeuni = 0xc0+cid-9607;
222 else if ( cid>=9613 && cid<=9629 ) fakeuni = 0xc7+cid-9613;
223 else if ( cid>=9630 && cid<=9641 ) fakeuni = 0xd9+cid-9630;
224 else if ( cid>=9642 && cid<=9658 ) fakeuni = 0xe7+cid-9642;
225 else if ( cid>=9659 && cid<=9665 ) fakeuni = 0xf9+cid-9659;
226 else if ( cid==9666 ) fakeuni = 0x160;
227 else if ( cid==9667 ) fakeuni = 0x178;
228 else if ( cid==9668 ) fakeuni = 0x17d;
229 else if ( cid==9670 ) fakeuni = 0x160;
230 else if ( cid==9671 ) fakeuni = 0x2122;
231 else if ( cid==9672 ) fakeuni = 0x17e;
232 else if ( cid==9673 ) fakeuni = 0xd8;
233 else if ( cid==9674 ) fakeuni = 0x20ac;
234 else if ( cid==9675 ) fakeuni = 0x2126;
235 else if ( cid==9676 ) fakeuni = 0x2032;
236 else if ( cid==9677 ) fakeuni = 0x2033;
237 else if ( cid==9678 ) fakeuni = 0xfb00;
238 else if ( cid==9679 ) fakeuni = 0xfb03;
239 else if ( cid==9680 ) fakeuni = 0xfb04;
240 else if ( cid==9681 ) fakeuni = 0x101;
241 else if ( cid==9682 ) fakeuni = 0x12b;
242 else if ( cid==9683 ) fakeuni = 0x16b;
243 else if ( cid==9684 ) fakeuni = 0x113;
244 else if ( cid==9685 ) fakeuni = 0x14d;
245 else if ( cid==9686 ) fakeuni = 0x100;
246 else if ( cid==9687 ) fakeuni = 0x12a;
247 else if ( cid==9688 ) fakeuni = 0x16a;
248 else if ( cid==9689 ) fakeuni = 0x112;
249 else if ( cid==9690 ) fakeuni = 0x14c;
250 else if ( cid==9691 ) fakeuni = 0x2158;
251 else if ( cid==9692 ) fakeuni = 0x2159;
252 else if ( cid==9693 ) fakeuni = 0x215a;
253 else if ( cid==9694 ) fakeuni = 0x215b;
254 else if ( cid==9695 ) fakeuni = 0x2153;
255 else if ( cid==9696 ) fakeuni = 0x2154;
256 else if ( cid==9697 ) fakeuni = 0x2070;
257 else if ( cid>=9698 && cid<=9703 ) fakeuni = 0x2074+(cid-9698);
258 else if ( cid>=9704 && cid<=9713 ) fakeuni = 0x2080+(cid-9704);
259 else if ( cid==9714 ) fakeuni = 0x1cd;
260 else if ( cid==9715 ) fakeuni = 0x11a;
261 else if ( cid==9717 ) fakeuni = 0x1ebc;
262 else if ( cid==9718 ) fakeuni = 0x1cf;
263 else if ( cid==9721 ) fakeuni = 0x1d1;
264 else if ( cid==9723 ) fakeuni = 0x1d3;
265 else if ( cid==9724 ) fakeuni = 0x16e;
266 else if ( cid==9725 ) fakeuni = 0x168;
267 else if ( cid==9726 ) fakeuni = 0x1ce;
268 else if ( cid==9727 ) fakeuni = 0x11b;
269 else if ( cid==9729 ) fakeuni = 0x1ebd;
270 else if ( cid==9730 ) fakeuni = 0x1d0;
271 else if ( cid==9733 ) fakeuni = 0x1d2;
272 else if ( cid==9735 ) fakeuni = 0x1d4;
273 else if ( cid==9736 ) fakeuni = 0x16f;
274 else if ( cid==9737 ) fakeuni = 0x169;
275 /* duplicate with U+29fd7. JIS X 0213:2004 declares that U+29fce is authentic */
276 else if ( cid==19071 ) fakeuni = 0x29fce;
277 }
278 maxcid = cid;
279 if (( cid>=7887 && cid<=7916 ) || ( cid>=8720 && cid<=9353) ||
280 (cid>=12870 && cid<=13313)) {
281 if ( cid>=7894 && cid<=7898 )
282 sprintf( buffer, "Japan1.%d.vert", cid-7894+665 );
283 else if ( cid>=7899 && cid<=7900 )
284 sprintf( buffer, "Japan1.%d.vert", cid-7899+674 );
285 else if ( cid>=7901 && cid<=7916 )
286 sprintf( buffer, "Japan1.%d.vert", cid-7901+676 );
287 /* Rotated Proportional latin, first 95 are ascii, rest are a mix */
288 else if ( cid>=8720 && cid<=8949 )
289 sprintf( buffer, "Japan1.%d.vert", cid-8720+1 );
290 /* Rotated halfwidth latin, japanese ascii (ie yen for backslash) */
291 /* (don't really need a separate case here, both blocks are consecutive) */
292 else if ( cid>=8950 && cid<=9044 )
293 sprintf( buffer, "Japan1.%d.vert", cid-8950+231 );
294 /* Rotated halfwidth latin, nonascii */
295 else if ( cid>=9045 && cid<=9078 )
296 sprintf( buffer, "Japan1.%d.vert", cid-9045+599 );
297 else if ( cid>=9079 && cid<=9081 )
298 sprintf( buffer, "Japan1.%d.vert", cid-9079+630 );
299 else if ( cid==9083 ) /* halfwidth backslash */
300 strcpy(buffer, "Japan1.8719.vert" );
301 /* Rotated halfwidth katakana */
302 else if ( cid>=9084 && cid<=9147 )
303 sprintf( buffer, "Japan1.%d.vert", cid-9084+326 );
304 /* cid 390 gets used later */
305 else if ( cid>=9148 && cid<=9178 )
306 sprintf( buffer, "Japan1.%d.vert", cid-9148+391 );
307 /* Rotated halfwidth hiragana */
308 else if ( cid>=9179 && cid<=9262 )
309 sprintf( buffer, "Japan1.%d.vert", cid-9179+515 );
310 else if ( cid>=9263 && cid<=9264 )
311 sprintf( buffer, "Japan1.%d.vert", cid-9263+423 );
312 /* Rotated halfwidth brackets */
313 else if ( cid>=9265 && cid<=9276 )
314 sprintf( buffer, "Japan1.%d.vert", cid-9265+504 );
315 /* Rotated halfwidth box builders */
316 else if ( cid>=9277 && cid<=9353 )
317 sprintf( buffer, "Japan1.%d.vert", cid-9277+425 );
318 else if ( cid==9353 )
319 strcpy( buffer, "Japan1.390.vert" );
320 /* More proportional latin */
321 else if ( cid>=12870 && cid<=12959 )
322 sprintf( buffer, "Japan1.%d.vert", cid-12870+9354 );
323 /* proportional italic latin */
324 else if ( cid>=12960 && cid<=13253 )
325 sprintf( buffer, "Japan1.%d.vert", cid-12960+9444 );
326 /* quarter width latin */
327 else if ( cid>=13254 && cid<=13294 )
328 sprintf( buffer, "Japan1.%d.vert", cid-13254+9738 );
329 else if ( uni!=-1 )
330 sprintf( buffer, "uni%04X.vert", (unsigned int)((uni>=VERTMARK?uni-VERTMARK:uni)) );
331 else if ( fakeuni!=-1 )
332 sprintf( buffer, "uni%04X.vert", (unsigned int)((fakeuni>=VERTMARK?fakeuni-VERTMARK:fakeuni)) );
333 else
334 continue;
335 /*sprintf( buffer, "japan1-%d.vert", cid );*/
336 nonuni_names[cid] = strdup(buffer);
337 if ( uni!=-1 && uni<VERTMARK && used[uni] ) ++used[uni];
338 } else if ( uni>VERTMARK ) {
339 /* rotated */
340 cid_2_rotunicode[cid] = uni-VERTMARK;
341 } else if ( uni==-1 && fakeuni==-1 ) {
342 if ( cid>=390 && cid<421 )
343 sprintf( buffer, "Japan1.%d.hw", hwtable390[cid-390] );
344 else if ( cid>=501 && cid<=503 )
345 sprintf( buffer, "Japan1.%d.hw", hwtable501[cid-501] );
346 else if ( cid>=516 && cid<=598 )
347 sprintf( buffer, "Japan1.%d.hw", hwtable516[cid-516] );
348 else if ( cid>=231 && cid<=632 )
349 sprintf( buffer, "Japan1.%d.hw", cid );
350 else
351 continue;
352 /*sprintf( buffer,"Japan1.%d", cid );*/
353 nonuni_names[cid] = strdup(buffer);
354 } else if ((( cid>=231 && cid<=326 ) || ( cid>=390 && cid<=632 ) ||
355 cid==8719) && uni!=0x2002 && fakeuni!=0x2002 ) {
356 /* halfwidth characters that are not specifically entered as such in uni */
357 /*if ( psunicodenames[uni]!=NULL )
358 sprintf( buffer, "%s.hw", psunicodenames[uni]);
359 else*/
360 if ( uni!=-1 )
361 sprintf( buffer, "uni%04X.hw", (unsigned int)(uni) );
362 else
363 sprintf( buffer, "uni%04X.hw", (unsigned int)(fakeuni) );
364 nonuni_names[cid] = strdup(buffer);
365 if ( uni!=-1 && used[uni] ) ++used[uni];
366 else if ( fakeuni!=-1 && used[fakeuni] ) ++used[fakeuni];
367 } else if ( cid>=9444 && cid<=9737 ) {
368 /* italic */
369 /*if ( psunicodenames[uni]!=NULL )
370 sprintf( buffer, "%s.italic", psunicodenames[uni]);
371 else*/
372 sprintf( buffer, "uni%04X.italic", (unsigned int)(fakeuni) );
373 nonuni_names[cid] = strdup(buffer);
374 if ( used[uni] ) ++used[uni];
375 } else if ( uni==-1 ) {
376 if ( fakeuni!=-1 ) {
377 sprintf( buffer, "uni%04X.dup%d", (unsigned int)(fakeuni), ++used[fakeuni] );
378 nonuni_names[cid] = strdup(buffer);
379 }
380 continue;
381 } else if ( !used[uni] ) {
382 used[uni] = 1;
383 cid_2_unicode[cid] = uni;
384 } else {
385 sprintf( buffer, "uni%04X.dup%d", (unsigned int)(uni), ++used[uni] );
386 nonuni_names[cid] = strdup(buffer);
387 }
388 max = cid;
389 }
390 for ( i=0; i<maxcid; ++i ) if ( cid_2_rotunicode[i]!=0 ) {
391 for ( j=0; j<maxcid; ++j )
392 if ( cid_2_unicode[j] == cid_2_rotunicode[i] )
393 break;
394 if ( j==maxcid )
395 sprintf( buffer, "uni%04X.vert", (unsigned int)(cid_2_rotunicode[i]) );
396 else
397 sprintf( buffer, "Japan1.%d.vert", j);
398 nonuni_names[i] = strdup(buffer);
399 }
400
401 printf("%d %d\n",maxcid, max );
402
403 for ( cid=0; cid<=max; ++cid ) {
404 if ( cid_2_unicode[cid]!=-1 && cid_2_unicodemult[cid][0]==0 ) {
405 for ( i=1; cid+i<=max && cid_2_unicode[cid+i]==cid_2_unicode[cid]+i && cid_2_unicodemult[cid+i][0]==0; ++i );
406 --i;
407 if ( i!=0 ) {
408 printf( "%d..%d %04x\n", cid, cid+i, (unsigned int)(cid_2_unicode[cid]) );
409 cid += i;
410 } else
411 printf( "%d %04x\n", cid, (unsigned int)(cid_2_unicode[cid]) );
412 } else if ( cid_2_unicode[cid]!=-1 ) {
413 printf( "%d %04x", cid, (unsigned int)(cid_2_unicode[cid]) );
414 for ( i=0; cid_2_unicodemult[cid][i]!=0; ++i )
415 printf( ",%04x", (unsigned int)(cid_2_unicodemult[cid][i]) );
416 printf( "\n");
417 } else if ( nonuni_names[cid]!=NULL )
418 printf( "%d /%s\n", cid, nonuni_names[cid] );
419 }
420 return( 0 );
421 }