| 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) { |
| 16 |
if ( val>=0x2e80 && val<=0x2fff ) |
| 17 |
return( 1 ); |
| 18 |
else if ( val>=VERTMARK ) |
| 19 |
return( 2 ); |
| 20 |
else if ( val>=0xf000 && val<=0xffff ) |
| 21 |
return( 3 ); |
| 22 |
|
| 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 |
|
| 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 |
|
| 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; |
| 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=='#' ) |
| 110 |
continue; |
| 111 |
cid = getnth(buffer,1,NULL); |
| 112 |
if ( cid==-1 ) |
| 113 |
continue; |
| 114 |
uni = getnth(buffer,14,cid_2_unicodemult[cid]); |
| 115 |
maxcid = cid; |
| 116 |
if ( ( (cid>=814 && cid<=907) || cid==7716 ) && uni!=-1 ) { |
| 117 |
|
| 118 |
sprintf( buffer,"uni%04X.hw", (unsigned int)(uni) ); |
| 119 |
nonuni_names[cid] = strdup(buffer); |
| 120 |
} else if ( cid>=22226 && cid<=22319 && uni==-1 ) { |
| 121 |
|
| 122 |
sprintf( buffer,"GB1.%d.vert", cid-22226+814 ); |
| 123 |
nonuni_names[cid] = strdup(buffer); |
| 124 |
} else if ( cid>=22127 && cid<=22221 && uni==-1 ) { |
| 125 |
|
| 126 |
sprintf( buffer,"GB1.%d.vert", cid-22127+1 ); |
| 127 |
nonuni_names[cid] = strdup(buffer); |
| 128 |
} else if ( cid>=29059 && cid<=29063 && uni==-1 ) { |
| 129 |
|
| 130 |
sprintf( buffer,"GB1.%d.vert", cid-29059+22353 ); |
| 131 |
nonuni_names[cid] = strdup(buffer); |
| 132 |
} else if ( uni==-1 ) { |
| 133 |
continue; |
| 134 |
sprintf( buffer,"GB1.%d", cid ); |
| 135 |
nonuni_names[cid] = strdup(buffer); |
| 136 |
} else if ( uni>VERTMARK ) { |
| 137 |
|
| 138 |
cid_2_rotunicode[cid] = uni-VERTMARK; |
| 139 |
} else if ( !used[uni] ) { |
| 140 |
used[uni] = 1; |
| 141 |
cid_2_unicode[cid] = uni; |
| 142 |
} else { |
| 143 |
sprintf( buffer, "uni%04X.dup%d", (unsigned int)(uni), ++used[uni] ); |
| 144 |
nonuni_names[cid] = strdup(buffer); |
| 145 |
} |
| 146 |
max = cid; |
| 147 |
} |
| 148 |
for ( i=0; i<maxcid; ++i ) if ( cid_2_rotunicode[i]!=0 ) { |
| 149 |
for ( j=0; j<maxcid; ++j ) |
| 150 |
if ( cid_2_unicode[j] == cid_2_rotunicode[i] ) |
| 151 |
break; |
| 152 |
if ( j==maxcid ) |
| 153 |
sprintf( buffer, "uni%04X.vert", (unsigned int)(cid_2_rotunicode[i]) ); |
| 154 |
else |
| 155 |
sprintf( buffer, "GB1.%d.vert", j); |
| 156 |
nonuni_names[i] = strdup(buffer); |
| 157 |
} |
| 158 |
|
| 159 |
printf("%d %d\n",maxcid, max ); |
| 160 |
|
| 161 |
for ( cid=0; cid<=max; ++cid ) { |
| 162 |
if ( cid_2_unicode[cid]!=-1 && cid_2_unicodemult[cid][0]==0 ) { |
| 163 |
for ( i=1; cid+i<=max && cid_2_unicode[cid+i]==cid_2_unicode[cid]+i && cid_2_unicodemult[cid+i][0]==0; ++i ); |
| 164 |
--i; |
| 165 |
if ( i!=0 ) { |
| 166 |
printf( "%d..%d %04x\n", cid, cid+i, (unsigned int)(cid_2_unicode[cid]) ); |
| 167 |
cid += i; |
| 168 |
} else |
| 169 |
printf( "%d %04x\n", cid, (unsigned int)(cid_2_unicode[cid]) ); |
| 170 |
} else if ( cid_2_unicode[cid]!=-1 ) { |
| 171 |
printf( "%d %04x", cid, (unsigned int)(cid_2_unicode[cid]) ); |
| 172 |
for ( i=0; cid_2_unicodemult[cid][i]!=0; ++i ) |
| 173 |
printf( ",%04x", (unsigned int)(cid_2_unicodemult[cid][i]) ); |
| 174 |
printf( "\n"); |
| 175 |
} else if ( nonuni_names[cid]!=NULL ) |
| 176 |
printf( "%d /%s\n", cid, nonuni_names[cid] ); |
| 177 |
} |
| 178 |
return( 0 ); |
| 179 |
} |