1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3
* The contents of this file are subject to the Netscape Public License
4
* Version 1.0 (the "NPL"); you may not use this file except in
5
* compliance with the NPL. You may obtain a copy of the NPL at
6
* http://www.mozilla.org/NPL/
8
* Software distributed under the NPL is distributed on an "AS IS" basis,
9
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
10
* for the specific language governing rights and limitations under the
13
* The Initial Developer of this code under the NPL is Netscape
14
* Communications Corporation. Portions created by Netscape are
15
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
20
typedef unsigned short uint16;
22
#define NOMAPPING 0xfffd
25
uint16 srcBegin; /* 2 byte */
26
uint16 srcEnd; /* 2 byte */
27
uint16 destBegin; /* 2 byte */
31
uint16 srcBegin; /* 2 byte */
32
uint16 srcEnd; /* 2 byte */
33
uint16 mappingOffset; /* 2 byte */
37
uint16 srcBegin; /* 2 byte */
38
uint16 srcEnd; /* 2 byte -waste */
39
uint16 destBegin; /* 2 byte */
50
/* =================================================
52
================================================= */
55
uint16 offsetToFormatArray;
56
uint16 offsetToMapCellArray;
57
uint16 offsetToMappingTable;
61
uint16 umap[256][256];
62
int bInitFromOrTo = 0;
63
int bGenerateFromUnicodeTable = 0;
65
#define MAXCELLNUM 1000
67
static int numOfItem = 0;
68
uMapCell cell[MAXCELLNUM];
69
uint16 format[MAXCELLNUM / 4];
70
uint16 mapping[256*256];
71
static int mappinglen = 0;
72
static int formatcount[4] = {0,0,0,0};
74
#define SetFormat(n,f) { format[(n >> 2)] |= ((f) << ((n & 0x0003) << 2)); formatcount[f]++; }
75
#define GetFormat(n) ( format[(n >> 2)] >> ((n & 0x0003) << 2)) &0x00FF)
76
#define MAPVALUE(i) (umap[(i >> 8) & 0xFF][(i) & 0xFF])
78
int FORMAT1CNST = 10 ;
86
umap[i][j]= NOMAPPING;
88
for(i=0;i<MAXCELLNUM / 4;i++)
91
void SetMapValue(short u,short c)
93
if(NOMAPPING == MAPVALUE(u))
94
MAPVALUE(u) = c & 0x0000FFFF;
96
fprintf(stderr, "warning- duplicate mapping %x map to both %x and %x\n", u, MAPVALUE(u), c);
99
void AddFormat2(uint16 srcBegin)
101
uint16 destBegin = MAPVALUE(srcBegin);
102
printf("Begin of Item %04X\n",numOfItem);
103
printf(" Format 2\n");
104
printf(" srcBegin = %04X\n", srcBegin);
105
printf(" destBegin = %04X\n", destBegin );
106
SetFormat(numOfItem,2);
107
cell[numOfItem].fmt.format2.srcBegin = srcBegin;
108
cell[numOfItem].fmt.format2.srcEnd = 0;
109
cell[numOfItem].fmt.format2.destBegin = destBegin;
110
printf("End of Item %04X \n\n",numOfItem);
112
/* Unmark the umap */
113
MAPVALUE(srcBegin) = NOMAPPING;
115
void AddFormat1(uint16 srcBegin, uint16 srcEnd)
118
printf("Begin of Item %04X\n",numOfItem);
119
printf(" Format 1\n");
120
printf(" srcBegin = %04X\n", srcBegin);
121
printf(" srcEnd = %04X\n", srcEnd );
122
printf(" mappingOffset = %04X\n", mappinglen);
123
printf(" Mapping = " );
124
SetFormat(numOfItem,1);
125
cell[numOfItem].fmt.format1.srcBegin = srcBegin;
126
cell[numOfItem].fmt.format1.srcEnd = srcEnd;
127
cell[numOfItem].fmt.format1.mappingOffset = mappinglen;
128
for(i=srcBegin ; i <= srcEnd ; i++,mappinglen++)
130
if( ((i-srcBegin) % 8) == 0)
132
mapping[mappinglen]= MAPVALUE(i);
133
printf("%04X ",(mapping[mappinglen] ));
134
/* Unmark the umap */
135
MAPVALUE(i) = NOMAPPING;
138
printf("End of Item %04X \n\n",numOfItem);
141
void AddFormat0(uint16 srcBegin, uint16 srcEnd)
144
uint16 destBegin = MAPVALUE(srcBegin);
145
printf("Begin of Item %04X\n",numOfItem);
146
printf(" Format 0\n");
147
printf(" srcBegin = %04X\n", srcBegin);
148
printf(" srcEnd = %04X\n", srcEnd );
149
printf(" destBegin = %04X\n", destBegin );
150
SetFormat(numOfItem,0);
151
cell[numOfItem].fmt.format0.srcBegin = srcBegin;
152
cell[numOfItem].fmt.format0.srcEnd = srcEnd;
153
cell[numOfItem].fmt.format0.destBegin = destBegin;
154
for(i=srcBegin ; i <= srcEnd ; i++)
156
/* Unmark the umap */
157
MAPVALUE(i) = NOMAPPING;
159
printf("End of Item %04X \n\n",numOfItem);
165
"/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-\n"
167
"* The contents of this file are subject to the Netscape Public License\n"
168
"* Version 1.0 (the \"NPL\"); you may not use this file except in\n"
169
"* compliance with the NPL. You may obtain a copy of the NPL at\n"
170
"* http://www.mozilla.org/NPL/\n"
172
"* Software distributed under the NPL is distributed on an \"AS IS\" basis, \n"
173
"* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL \n"
174
"* for the specific language governing rights and limitations under the \n"
177
"* The Initial Developer of this code under the NPL is Netscape\n"
178
"* Communications Corporation. Portions created by Netscape are\n"
179
"* Copyright (C) 2001 Netscape Communications Corporation. All Rights\n"
185
/* OK! For now, we just use format 1 for each row */
186
/* We need to chage this to use other format to save the space */
188
uint16 ss,gs,gp,state,gc;
189
uint16 diff, lastdiff;
192
printf("/*========================================================\n");
193
printf(" This is a Generated file. Please don't edit it.\n");
195
printf(" The tool which used to generate this file is called umaptable.\n");
196
printf(" You can find this tool under mozilla/intl/uconv/tools/umaptable.c.\n");
198
printf(" If you have any problem of this file. Please contact \n");
199
printf(" Netscape Client International Team or \n");
200
printf(" ftang@netscape <Frank Tang> \n");
202
printf(" Table in Debug form \n");
204
for(begin = 0; MAPVALUE(begin) ==NOMAPPING; begin++)
206
for(end = 0xFFFF; MAPVALUE(end) ==NOMAPPING; end--)
210
lastdiff = MAPVALUE(begin) - begin;
211
for(gp=begin+1,state = 0 ; gp<=end; gp++)
214
diff = MAPVALUE(gp) - gp;
215
input = (diff == lastdiff);
229
if(gc++ >= FORMAT0CNST)
257
for(;(MAPVALUE(begin) ==NOMAPPING) && (begin <= end); begin++)
261
for(;(MAPVALUE(end)==NOMAPPING) && (end >= begin); end--)
263
for(ss=gp=begin,state = 0 ; gp<=end; gp++)
265
int input = (MAPVALUE(gp) == NOMAPPING);
279
if(gc++ >= FORMAT1CNST)
294
AddFormat1(ss ,gs-1);
304
AddFormat1(ss ,end );
306
printf("========================================================*/\n");
311
uint16 off1,off2,off3;
313
uint16 formatitem = (((numOfItem)>>2) + 1);
315
off2 = off1 + formatitem ;
316
off3 = off2 + numOfItem * sizeof(uMapCell) / sizeof(uint16);
317
/* write itemOfList */
318
printf("/* Offset=0x%04X ItemOfList */\n 0x%04X,\n", cur++, numOfItem);
320
/* write offsetToFormatArray */
321
printf("/*-------------------------------------------------------*/\n");
322
printf("/* Offset=0x%04X offsetToFormatArray */\n 0x%04X,\n", cur++,off1);
324
/* write offsetToMapCellArray */
325
printf("/*-------------------------------------------------------*/\n");
326
printf("/* Offset=0x%04X offsetToMapCellArray */ \n 0x%04X,\n", cur++,off2);
328
/* write offsetToMappingTable */
329
printf("/*-------------------------------------------------------*/\n");
330
printf("/* Offset=0x%04X offsetToMappingTable */ \n 0x%04X,\n", cur++,off3);
332
/* write FormatArray */
333
printf("/*-------------------------------------------------------*/\n");
334
printf("/* Offset=0x%04X Start of Format Array */ \n",cur);
335
printf("/* Total of Format 0 : 0x%04X */\n"
337
printf("/* Total of Format 1 : 0x%04X */\n"
339
printf("/* Total of Format 2 : 0x%04X */\n"
341
printf("/* Total of Format 3 : 0x%04X */\n"
343
for(i=0;i<formatitem;i++,cur++)
347
printf("0x%04X, ",format[i]);
351
/* write MapCellArray */
352
printf("/*-------------------------------------------------------*/\n");
353
printf("/* Offset=0x%04X Start of MapCell Array */ \n",cur);
354
for(i=0;i<numOfItem;i++,cur+=3)
356
printf("/* %04X */ 0x%04X, 0x%04X, 0x%04X, \n",
358
cell[i].fmt.format0.srcBegin,
359
cell[i].fmt.format0.srcEnd,
360
cell[i].fmt.format0.destBegin
364
/* write MappingTable */
365
printf("/*-------------------------------------------------------*/\n");
366
printf("/* Offset=0x%04X Start of MappingTable */ \n",cur);
367
for(i=0;i<mappinglen;i++,cur++)
370
printf("\n/* %04X */ ",i);
371
printf("0x%04X, ",mapping[i] );
374
printf("/* End of table Total Length = 0x%04X * 2 */\n",cur);
379
fprintf(stderr, "please indicate what kind of mapping mapping table you want to generate:\n");
380
fprintf(stderr, "\t-uf : generate *.uf (from unicode) table, or\n");
381
fprintf(stderr, "\t-ut : generate *.ut (to unicode) table\n");
383
parsearg(int argc, char* argv[])
388
if(strncmp("-uf", argv[i],3) == 0) {
389
if(! bInitFromOrTo) {
390
bGenerateFromUnicodeTable = 1;
397
if(strncmp("-ut", argv[i],3) == 0) {
398
if(! bInitFromOrTo) {
399
bGenerateFromUnicodeTable = 0;
406
if((strncmp("-0", argv[i],2) == 0) && ((i+1) < argc))
409
if(sscanf(argv[i+1], "%d", &cnst0) == 1)
418
fprintf(stderr, "argc error !!!!\n");
423
if((strncmp("-1", argv[i],2) == 0) && ((i+1) < argc))
426
if(sscanf(argv[i+1], "%d", &cnst1) == 1)
435
fprintf(stderr, "argc error !!!!\n");
446
fprintf(stderr, "format 0 cnst = %d\n", FORMAT0CNST);
447
fprintf(stderr, "format 1 cnst = %d\n", FORMAT1CNST);
448
fprintf(stderr, "generate u%c table\n",
449
bGenerateFromUnicodeTable ? 'f' : 't');
455
for(;gets(buf)!=NULL;)
457
if(buf[0]=='0' && buf[1] == 'x')
459
sscanf(buf,"%hx %hx",&c,&u);
460
if(bGenerateFromUnicodeTable)
467
main(int argc, char* argv[])
469
parsearg(argc, argv);