Debian Codegraph @

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