#include <stdio.h>#include <stdlib.h>#include <string.h>Include dependency graph for uca-dump.c:

Go to the source code of this file.
Classes | |
| struct | uca_item_st |
Defines | |
| #define | MY_UCA_NPAGES 256 |
| #define | MY_UCA_NCHARS 256 |
| #define | MY_UCA_CMASK 255 |
| #define | MY_UCA_PSHIFT 8 |
Typedefs | |
| typedef unsigned char | uchar |
| typedef unsigned short | uint16 |
Functions | |
| int | main (int ac, char **av) |
Variables | |
| static char * | pname [] = {"", "2", "3"} |
| #define MY_UCA_CMASK 255 |
| #define MY_UCA_NCHARS 256 |
| #define MY_UCA_NPAGES 256 |
| #define MY_UCA_PSHIFT 8 |
| typedef unsigned char uchar |
Definition at line 5 of file uca-dump.c.
| typedef unsigned short uint16 |
Definition at line 6 of file uca-dump.c.
| int main | ( | int | ac, | |
| char ** | av | |||
| ) |
Definition at line 28 of file uca-dump.c.
References bzero, comment, endptr, MY_UCA_CMASK, MY_UCA_NCHARS, MY_UCA_NPAGES, MY_UCA_PSHIFT, NULL, uca_item_st::num, page, pname, strchr(), strtol(), and uca_item_st::weight.
00029 { 00030 char str[256]; 00031 char *weights[64]; 00032 struct uca_item_st uca[64*1024]; 00033 size_t code, w; 00034 int pageloaded[MY_UCA_NPAGES]; 00035 00036 bzero(uca, sizeof(uca)); 00037 bzero(pageloaded, sizeof(pageloaded)); 00038 00039 while (fgets(str,sizeof(str),stdin)) 00040 { 00041 char *comment; 00042 char *weight; 00043 char *s; 00044 size_t codenum; 00045 00046 code= strtol(str,NULL,16); 00047 00048 if (str[0]=='#' || (code > 0xFFFF)) 00049 continue; 00050 if ((comment=strchr(str,'#'))) 00051 { 00052 *comment++= '\0'; 00053 for ( ; *comment==' ' ; comment++); 00054 }else 00055 continue; 00056 00057 if ((weight=strchr(str,';'))) 00058 { 00059 *weight++= '\0'; 00060 for ( ; *weight==' ' ; weight++); 00061 } 00062 else 00063 continue; 00064 00065 codenum= 0; 00066 s= strtok(str, " \t"); 00067 while (s) 00068 { 00069 s= strtok(NULL, " \t"); 00070 codenum++; 00071 } 00072 00073 if (codenum>1) 00074 { 00075 /* Multi-character weight, 00076 i.e. contraction. 00077 Not supported yet. 00078 */ 00079 continue; 00080 } 00081 00082 uca[code].num= 0; 00083 s= strtok(weight, " []"); 00084 while (s) 00085 { 00086 weights[uca[code].num]= s; 00087 s= strtok(NULL, " []"); 00088 uca[code].num++; 00089 } 00090 00091 for (w=0; w < uca[code].num; w++) 00092 { 00093 size_t partnum; 00094 00095 partnum= 0; 00096 s= weights[w]; 00097 while (*s) 00098 { 00099 char *endptr; 00100 size_t part; 00101 part= strtol(s+1,&endptr,16); 00102 uca[code].weight[partnum][w]= part; 00103 s= endptr; 00104 partnum++; 00105 } 00106 } 00107 /* Mark that a character from this page was loaded */ 00108 pageloaded[code >> MY_UCA_PSHIFT]++; 00109 } 00110 00111 00112 00113 /* Now set implicit weights */ 00114 for (code=0; code <= 0xFFFF; code++) 00115 { 00116 size_t base, aaaa, bbbb; 00117 00118 if (uca[code].num) 00119 continue; 00120 00121 /* 00122 3400;<CJK Ideograph Extension A, First> 00123 4DB5;<CJK Ideograph Extension A, Last> 00124 4E00;<CJK Ideograph, First> 00125 9FA5;<CJK Ideograph, Last> 00126 */ 00127 00128 if (code >= 0x3400 && code <= 0x4DB5) 00129 base= 0xFB80; 00130 else if (code >= 0x4E00 && code <= 0x9FA5) 00131 base= 0xFB40; 00132 else 00133 base= 0xFBC0; 00134 00135 aaaa= base + (code >> 15); 00136 bbbb= (code & 0x7FFF) | 0x8000; 00137 uca[code].weight[0][0]= aaaa; 00138 uca[code].weight[0][1]= bbbb; 00139 00140 uca[code].weight[1][0]= 0x0020; 00141 uca[code].weight[1][1]= 0x0000; 00142 00143 uca[code].weight[2][0]= 0x0002; 00144 uca[code].weight[2][1]= 0x0000; 00145 00146 uca[code].weight[3][0]= 0x0001; 00147 uca[code].weight[3][2]= 0x0000; 00148 00149 uca[code].num= 2; 00150 } 00151 00152 printf("#include \"my_uca.h\"\n"); 00153 00154 printf("#define MY_UCA_NPAGES %d\n",MY_UCA_NPAGES); 00155 printf("#define MY_UCA_NCHARS %d\n",MY_UCA_NCHARS); 00156 printf("#define MY_UCA_CMASK %d\n",MY_UCA_CMASK); 00157 printf("#define MY_UCA_PSHIFT %d\n",MY_UCA_PSHIFT); 00158 00159 for (w=0; w<3; w++) 00160 { 00161 size_t page; 00162 int pagemaxlen[MY_UCA_NPAGES]; 00163 00164 for (page=0; page < MY_UCA_NPAGES; page++) 00165 { 00166 size_t offs; 00167 size_t maxnum= 0; 00168 size_t nchars= 0; 00169 size_t mchars; 00170 size_t ndefs= 0; 00171 00172 pagemaxlen[page]= 0; 00173 00174 /* 00175 Skip this page if no weights were loaded 00176 */ 00177 00178 if (!pageloaded[page]) 00179 continue; 00180 00181 /* 00182 Calculate maximum weight 00183 length for this page 00184 */ 00185 00186 for (offs=0; offs < MY_UCA_NCHARS; offs++) 00187 { 00188 size_t i, num; 00189 00190 code= page*MY_UCA_NCHARS+offs; 00191 00192 /* Calculate only non-zero weights */ 00193 for (num=0, i=0; i < uca[code].num; i++) 00194 if (uca[code].weight[w][i]) 00195 num++; 00196 00197 maxnum= maxnum < num ? num : maxnum; 00198 00199 /* Check if default weight */ 00200 if (w == 1 && num == 1) 00201 { 00202 /* 0020 0000 ... */ 00203 if (uca[code].weight[w][0] == 0x0020) 00204 ndefs++; 00205 } 00206 else if (w == 2 && num == 1) 00207 { 00208 /* 0002 0000 ... */ 00209 if (uca[code].weight[w][0] == 0x0002) 00210 ndefs++; 00211 } 00212 } 00213 maxnum++; 00214 00215 /* 00216 If the page have only default weights 00217 then no needs to dump it, skip. 00218 */ 00219 if (ndefs == MY_UCA_NCHARS) 00220 { 00221 continue; 00222 } 00223 switch (maxnum) 00224 { 00225 case 0: mchars= 8; break; 00226 case 1: mchars= 8; break; 00227 case 2: mchars= 8; break; 00228 case 3: mchars= 9; break; 00229 case 4: mchars= 8; break; 00230 default: mchars= uca[code].num; 00231 } 00232 00233 pagemaxlen[page]= maxnum; 00234 00235 00236 /* 00237 Now print this page 00238 */ 00239 00240 00241 printf("uint16 page%03Xdata%s[]= { /* %04X (%d weights per char) */\n", 00242 page, pname[w], page*MY_UCA_NCHARS, maxnum); 00243 00244 for (offs=0; offs < MY_UCA_NCHARS; offs++) 00245 { 00246 uint16 weight[8]; 00247 size_t num, i; 00248 00249 code= page*MY_UCA_NCHARS+offs; 00250 00251 bzero(weight,sizeof(weight)); 00252 00253 /* Copy non-zero weights */ 00254 for (num=0, i=0; i < uca[code].num; i++) 00255 { 00256 if (uca[code].weight[w][i]) 00257 { 00258 weight[num]= uca[code].weight[w][i]; 00259 num++; 00260 } 00261 } 00262 00263 for (i=0; i < maxnum; i++) 00264 { 00265 /* 00266 Invert weights for secondary level to 00267 sort upper case letters before their 00268 lower case counter part. 00269 */ 00270 int tmp= weight[i]; 00271 if (w == 2 && tmp) 00272 tmp= (int)(0x20 - weight[i]); 00273 00274 00275 printf("0x%04X", tmp); 00276 if ((offs+1 != MY_UCA_NCHARS) || (i+1!=maxnum)) 00277 printf(","); 00278 nchars++; 00279 } 00280 if (nchars >=mchars) 00281 { 00282 printf("\n"); 00283 nchars=0; 00284 } 00285 else 00286 { 00287 printf(" "); 00288 } 00289 } 00290 printf("};\n\n"); 00291 } 00292 00293 printf("uchar uca_length%s[%d]={\n", pname[w], MY_UCA_NPAGES); 00294 for (page=0; page < MY_UCA_NPAGES; page++) 00295 { 00296 printf("%d%s%s",pagemaxlen[page],page<MY_UCA_NPAGES-1?",":"",(page+1) % 16 ? "":"\n"); 00297 } 00298 printf("};\n"); 00299 00300 00301 printf("uint16 *uca_weight%s[%d]={\n", pname[w], MY_UCA_NPAGES); 00302 for (page=0; page < MY_UCA_NPAGES; page++) 00303 { 00304 const char *comma= page < MY_UCA_NPAGES-1 ? "," : ""; 00305 const char *nline= (page+1) % 4 ? "" : "\n"; 00306 if (!pagemaxlen[page]) 00307 printf("NULL %s%s%s", w ? " ": "", comma , nline); 00308 else 00309 printf("page%03Xdata%s%s%s", page, pname[w], comma, nline); 00310 } 00311 printf("};\n"); 00312 } 00313 00314 00315 printf("int main(void){ return 0;};\n"); 00316 return 0; 00317 }
Here is the call graph for this function:

char* pname[] = {"", "2", "3"} [static] |
Definition at line 26 of file uca-dump.c.
Referenced by main(), and InitConfigFileParser::storeNameValuePair().
1.4.7

