| 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 |
static int puamap[0x2000]; |
| 11 |
#define MULT_MAX 6 |
| 12 |
static int cid_2_unicodemult[0x100000][MULT_MAX]; |
| 13 |
|
| 14 |
#define VERTMARK 0x1000000 |
| 15 |
|
| 16 |
static int ucs2_score(int val) { |
| 17 |
if ( val>=0x2e80 && val<=0x2fff ) |
| 18 |
return( 1 ); |
| 19 |
else if ( val>=VERTMARK ) |
| 20 |
return( 2 ); |
| 21 |
else if ( val>=0xf000 && val<=0xffff ) |
| 22 |
return( 3 ); |
| 23 |
|
| 24 |
else if ( val>=0x3400 && val<=0x4dff ) |
| 25 |
return( 4 ); |
| 26 |
else |
| 27 |
return( 5 ); |
| 28 |
} |
| 29 |
|
| 30 |
#if 0 |
| 31 |
static int allstars(char *buffer) { |
| 32 |
while ( isdigit(*buffer)) |
| 33 |
++buffer; |
| 34 |
while ( *buffer=='\t' || *buffer=='*' ) |
| 35 |
++buffer; |
| 36 |
if ( *buffer=='\r' ) ++buffer; |
| 37 |
if ( *buffer=='\n' ) ++buffer; |
| 38 |
return( *buffer=='\0' ); |
| 39 |
} |
| 40 |
#endif |
| 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 |
int pua, nonbmp; |
| 47 |
|
| 48 |
if ( col==1 ) { |
| 49 |
|
| 50 |
if ( !isdigit(*buffer)) |
| 51 |
return( -1 ); |
| 52 |
while ( isdigit(*buffer)) |
| 53 |
val = 10*val + *buffer++-'0'; |
| 54 |
return( val ); |
| 55 |
} |
| 56 |
for ( i=1; i<col; ++buffer ) { |
| 57 |
if ( *buffer=='\t' ) |
| 58 |
++i; |
| 59 |
else if ( *buffer=='\0' ) |
| 60 |
return( -1 ); |
| 61 |
} |
| 62 |
val = strtol(buffer,&end,16); |
| 63 |
if ( end==buffer ) |
| 64 |
return( -1 ); |
| 65 |
if ( *end=='v' ) { |
| 66 |
val += VERTMARK; |
| 67 |
++end; |
| 68 |
} |
| 69 |
if ( *end==',' ) { |
| 70 |
|
| 71 |
vals[0] = val; |
| 72 |
i = 1; |
| 73 |
while ( *end==',' && i<9 ) { |
| 74 |
buffer = end+1; |
| 75 |
vals[i] = strtol(buffer,&end,16); |
| 76 |
if ( *end=='v' ) { |
| 77 |
vals[i] += VERTMARK; |
| 78 |
++end; |
| 79 |
} |
| 80 |
++i; |
| 81 |
} |
| 82 |
vals[i] = 0; |
| 83 |
best = 0; val = -1; |
| 84 |
pua = nonbmp = 0; |
| 85 |
for ( i=0; vals[i]!=0; ++i ) { |
| 86 |
if ( ucs2_score(vals[i])>best ) { |
| 87 |
val = vals[i]; |
| 88 |
best = ucs2_score(vals[i]); |
| 89 |
} |
| 90 |
if ( vals[i]>=0xe000 && vals[i]<=0xf8ff ) |
| 91 |
pua = vals[i]; |
| 92 |
else if ( vals[i]>0x10000 && vals[i]<VERTMARK ) |
| 93 |
nonbmp = vals[i]; |
| 94 |
} |
| 95 |
if ( pua!=0 && nonbmp!=0 ) |
| 96 |
puamap[pua-0xe000] = nonbmp; |
| 97 |
if ( mults!=NULL ) for ( i=j=0; vals[i]!=0; ++i ) { |
| 98 |
if ( vals[i]!=val && !(vals[i]&VERTMARK)) |
| 99 |
mults[j++] = vals[i]; |
| 100 |
} |
| 101 |
if ( j>MULT_MAX ) { |
| 102 |
fprintf( stderr, "Too many multiple values for %04x, need %d slots\n", (unsigned int)(val), j ); |
| 103 |
exit(1); |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
return( val ); |
| 108 |
} |
| 109 |
|
| 110 |
int main(int argc, char **argv) { |
| 111 |
char buffer[600]; |
| 112 |
int cid, uni, max=0, maxcid=0, i,j; |
| 113 |
FILE *pua; |
| 114 |
|
| 115 |
nonuni_names[0] = ".notdef"; |
| 116 |
for ( cid=0; cid<0x10000; ++cid ) cid_2_unicode[cid] = -1; |
| 117 |
|
| 118 |
while ( fgets(buffer,sizeof(buffer),stdin)!=NULL ) { |
| 119 |
if ( *buffer=='#' ) |
| 120 |
continue; |
| 121 |
cid = getnth(buffer,1,NULL); |
| 122 |
if ( cid==-1 ) |
| 123 |
continue; |
| 124 |
uni = getnth(buffer,12,cid_2_unicodemult[cid]); |
| 125 |
maxcid = cid; |
| 126 |
if ( (cid>=17408 && cid<=17599) || cid==17604 || cid==17605 ) { |
| 127 |
if ( cid>=17408 && cid<=17505 ) |
| 128 |
sprintf( buffer,"CNS1.%d.vert", cid-17408+1 ); |
| 129 |
else if ( cid>=17506 && cid<=17599 ) |
| 130 |
sprintf( buffer,"CNS1.%d.vert", cid-17506+13648 ); |
| 131 |
else if ( cid==17604 ) |
| 132 |
strcpy( buffer, "CNS1.17601.vert" ); |
| 133 |
else if ( cid==17605 ) |
| 134 |
strcpy( buffer, "CNS1.17603.vert" ); |
| 135 |
nonuni_names[cid] = strdup(buffer); |
| 136 |
|
| 137 |
} else if ( (cid>=120 && cid<=127 ) && (cid&1) ) { |
| 138 |
sprintf( buffer,"CNS1.%d.vert", cid-1 ); |
| 139 |
nonuni_names[cid] = strdup(buffer); |
| 140 |
} else if ( (cid>=128 && cid<=159) && (cid&2) ) { |
| 141 |
sprintf( buffer,"CNS1.%d.vert", cid-2 ); |
| 142 |
nonuni_names[cid] = strdup(buffer); |
| 143 |
} else if ( cid>=13648 && cid<=13741 ) { |
| 144 |
sprintf( buffer, "uni%04X.hw", (unsigned int)(cid-13648+' ') ); |
| 145 |
nonuni_names[cid] = strdup(buffer); |
| 146 |
} else if ( cid==13742 ) { |
| 147 |
strcpy( buffer, "uni203E.hw" ); |
| 148 |
} else if ( uni==-1 ) { |
| 149 |
continue; |
| 150 |
sprintf( buffer,"CNS1.%d", cid ); |
| 151 |
nonuni_names[cid] = strdup(buffer); |
| 152 |
} else if ( uni>=VERTMARK ) { |
| 153 |
|
| 154 |
cid_2_rotunicode[cid] = uni-VERTMARK; |
| 155 |
} else if ( !used[uni] ) { |
| 156 |
used[uni] = 1; |
| 157 |
cid_2_unicode[cid] = uni; |
| 158 |
} else { |
| 159 |
sprintf( buffer, "uni%04X.dup%d", (unsigned int)(uni), ++used[uni] ); |
| 160 |
nonuni_names[cid] = strdup(buffer); |
| 161 |
} |
| 162 |
max = cid; |
| 163 |
} |
| 164 |
for ( i=0; i<maxcid; ++i ) if ( cid_2_rotunicode[i]!=0 ) { |
| 165 |
for ( j=0; j<maxcid; ++j ) |
| 166 |
if ( cid_2_unicode[j] == cid_2_rotunicode[i] ) |
| 167 |
break; |
| 168 |
if ( j==maxcid ) |
| 169 |
sprintf( buffer, "uni%04X.vert", (unsigned int)(cid_2_rotunicode[i]) ); |
| 170 |
else |
| 171 |
sprintf( buffer, "CNS1.%d.vert", j); |
| 172 |
nonuni_names[i] = strdup(buffer); |
| 173 |
} |
| 174 |
|
| 175 |
printf("%d %d\n",maxcid, max ); |
| 176 |
|
| 177 |
for ( cid=0; cid<=max; ++cid ) { |
| 178 |
if ( cid_2_unicode[cid]!=-1 && cid_2_unicodemult[cid][0]==0 ) { |
| 179 |
for ( i=1; cid+i<=max && cid_2_unicode[cid+i]==cid_2_unicode[cid]+i && cid_2_unicodemult[cid+i][0]==0; ++i ); |
| 180 |
--i; |
| 181 |
if ( i!=0 ) { |
| 182 |
printf( "%d..%d %04x\n", cid, cid+i, (unsigned int)(cid_2_unicode[cid]) ); |
| 183 |
cid += i; |
| 184 |
} else |
| 185 |
printf( "%d %04x\n", cid, (unsigned int)(cid_2_unicode[cid]) ); |
| 186 |
} else if ( cid_2_unicode[cid]!=-1 ) { |
| 187 |
printf( "%d %04x", cid, (unsigned int)(cid_2_unicode[cid]) ); |
| 188 |
for ( i=0; cid_2_unicodemult[cid][i]!=0; ++i ) |
| 189 |
printf( ",%04x", (unsigned int)(cid_2_unicodemult[cid][i]) ); |
| 190 |
printf( "\n"); |
| 191 |
} else if ( nonuni_names[cid]!=NULL ) |
| 192 |
printf( "%d /%s\n", cid, nonuni_names[cid] ); |
| 193 |
} |
| 194 |
|
| 195 |
pua = fopen("cns14.pua","w"); |
| 196 |
if (pua) { |
| 197 |
for ( i=0; i<0xf8ff-0xe000; i+=8 ) { |
| 198 |
fprintf(pua, "/* %0X */\t", (unsigned int)(i+0xe000) ); |
| 199 |
for ( j=0; j<8; ++j ) { |
| 200 |
if ( puamap[i+j]!=0 ) |
| 201 |
fprintf(pua, "0x%05x,%s", (unsigned int)(puamap[i+j]), j==7 ? "\n" : " " ); |
| 202 |
else |
| 203 |
fprintf(pua, " 0x0,%s", j==7 ? "\n" : " " ); |
| 204 |
} |
| 205 |
} |
| 206 |
fclose(pua); |
| 207 |
} |
| 208 |
|
| 209 |
return( 0 ); |
| 210 |
} |