Debian Codegraph @

contrib/cidmap/src/mapkorean.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[0x10000];
8 static char *nonuni_names[0x10000];
9 static int cid_2_rotunicode[0x10000];
10 #define MULT_MAX 6
11 static int cid_2_unicodemult[0x100000][MULT_MAX];
12
13 #define VERTMARK 0x1000000
14
15 static int ucs2_score(int val) { /* Supplied by KANOU Hiroki */
16 if ( val>=0x2e80 && val<=0x2fff )
17 return( 1 ); /* New CJK Radicals are least important */
18 else if ( val>=VERTMARK )
19 return( 2 ); /* Then vertical guys */
20 else if ( val>=0xf000 && val<=0xffff )
21 return( 3 );
22 /* else if (( val>=0x3400 && val<0x3dff ) || (val>=0x4000 && val<=0x4dff))*/
23 else if ( val>=0x3400 && val<=0x4dff )
24 return( 4 );
25 else
26 return( 5 );
27 }
28
29 #if 0
30 static int allstars(char *buffer) {
31 while ( isdigit(*buffer))
32 ++buffer;
33 while ( *buffer=='\t' || *buffer=='*' )
34 ++buffer;
35 if ( *buffer=='\r' ) ++buffer;
36 if ( *buffer=='\n' ) ++buffer;
37 return( *buffer=='\0' );
38 }
39 #endif
40
41 static int getnth(char *buffer, int col, int *mults) {
42 int i,j=0, val=0, best;
43 char *end;
44 int vals[10];
45
46 if ( col==1 ) {
47 /* first column is decimal, others are hex */
48 if ( !isdigit(*buffer))
49 return( -1 );
50 while ( isdigit(*buffer))
51 val = 10*val + *buffer++-'0';
52 return( val );
53 }
54 for ( i=1; i<col; ++buffer ) {
55 if ( *buffer=='\t' )
56 ++i;
57 else if ( *buffer=='\0' )
58 return( -1 );
59 }
60 val = strtol(buffer,&end,16);
61 if ( end==buffer )
62 return( -1 );
63 if ( *end=='v' ) {
64 val += VERTMARK;
65 ++end;
66 }
67 if ( *end==',' ) {
68 /* Multiple guess... now we've got to pick one */
69 vals[0] = val;
70 i = 1;
71 while ( *end==',' && i<9 ) {
72 buffer = end+1;
73 vals[i] = strtol(buffer,&end,16);
74 if ( *end=='v' ) {
75 vals[i] += VERTMARK;
76 ++end;
77 }
78 ++i;
79 }
80 vals[i] = 0;
81 best = 0; val = -1;
82 for ( i=0; vals[i]!=0; ++i ) {
83 if ( ucs2_score(vals[i])>best ) {
84 val = vals[i];
85 best = ucs2_score(vals[i]);
86 }
87 }
88 if ( mults!=NULL ) for ( i=j=0; vals[i]!=0; ++i ) {
89 if ( vals[i]!=val && !(vals[i]&VERTMARK))
90 mults[j++] = vals[i];
91 }
92 if ( j>MULT_MAX ) {
93 fprintf( stderr, "Too many multiple values for %04x, need %d slots\n", (unsigned int)(val), j );
94 exit(1);
95 }
96 }
97
98 return( val );
99 }
100
101 int main(int argc, char **argv) {
102 char buffer[600];
103 int cid, uni, max=0, maxcid=0, i,j, fakeuni;
104
105 nonuni_names[0] = ".notdef";
106 for ( cid=0; cid<0x10000; ++cid ) cid_2_unicode[cid] = -1;
107
108 while ( fgets(buffer,sizeof(buffer),stdin)!=NULL ) {
109 if ( *buffer=='#' /*|| allstars(buffer)*/)
110 continue;
111 cid = getnth(buffer,1,NULL);
112 if ( cid==-1 )
113 continue;
114 uni = getnth(buffer,11,cid_2_unicodemult[cid]);
115 fakeuni = -1;
116 maxcid = cid;
117 if ( cid>=8094 && cid<=8190 ) {
118 /* halfwidth latin */
119 if ( uni==-1 ) {
120 fakeuni = cid-8094+' ';
121 if ( cid==8154 ) fakeuni = 0x20a9; /* Won sign */
122 else if ( cid==8190 ) fakeuni = 8154-8094+' ';
123 }
124 /*if ( psunicodenames[uni]!=NULL )
125 sprintf( buffer, "%s.hw", psunicodenames[uni]);
126 else*/
127 sprintf( buffer, "uni%04X.hw", (unsigned int)(fakeuni) );
128 nonuni_names[cid] = strdup(buffer);
129 } else if ( cid>=18255 && cid<=18351 ) {
130 /* rotated halfwidth latin */
131 sprintf( buffer, "Korea1.%d.vert", cid-18255+8094 );
132 nonuni_names[cid] = strdup(buffer);
133 } else if ( cid>=18155 && cid<=18254 ) {
134 /* rotated proportional latin */
135 sprintf( buffer, "Korea1.%d.vert", cid-18155+1 );
136 nonuni_names[cid] = strdup(buffer);
137 } else if ( uni>=VERTMARK ) {
138 /* rotated */
139 cid_2_rotunicode[cid] = uni-VERTMARK;
140 } else if ( uni==-1 ) {
141 continue;
142 sprintf( buffer,"Korea1.%d", cid );
143 nonuni_names[cid] = strdup(buffer);
144 } else if ( !used[uni] ) {
145 used[uni] = 1;
146 cid_2_unicode[cid] = uni;
147 } else {
148 sprintf( buffer, "uni%04X.dup%d", (unsigned int)(uni), ++used[uni] );
149 nonuni_names[cid] = strdup(buffer);
150 }
151 max = cid;
152 }
153 for ( i=0; i<maxcid; ++i ) if ( cid_2_rotunicode[i]!=0 ) {
154 for ( j=0; j<maxcid; ++j )
155 if ( cid_2_unicode[j] == cid_2_rotunicode[i] )
156 break;
157 if ( j==maxcid )
158 sprintf( buffer, "uni%04X.vert", (unsigned int)(cid_2_rotunicode[i]) );
159 else
160 sprintf( buffer, "Korea1.%d.vert", j);
161 nonuni_names[i] = strdup(buffer);
162 }
163
164 printf("%d %d\n",maxcid, max );
165
166 for ( cid=0; cid<=max; ++cid ) {
167 if ( cid_2_unicode[cid]!=-1 && cid_2_unicodemult[cid][0]==0 ) {
168 for ( i=1; cid+i<=max && cid_2_unicode[cid+i]==cid_2_unicode[cid]+i && cid_2_unicodemult[cid+i][0]==0; ++i );
169 --i;
170 if ( i!=0 ) {
171 printf( "%d..%d %04x\n", cid, cid+i, (unsigned int)(cid_2_unicode[cid]) );
172 cid += i;
173 } else
174 printf( "%d %04x\n", cid, (unsigned int)(cid_2_unicode[cid]) );
175 } else if ( cid_2_unicode[cid]!=-1 ) {
176 printf( "%d %04x", cid, (unsigned int)(cid_2_unicode[cid]) );
177 for ( i=0; cid_2_unicodemult[cid][i]!=0; ++i )
178 printf( ",%04x", (unsigned int)(cid_2_unicodemult[cid][i]) );
179 printf( "\n");
180 } else if ( nonuni_names[cid]!=NULL )
181 printf( "%d /%s\n", cid, nonuni_names[cid] );
182 }
183 return( 0 );
184 }