1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is mozilla.org Code.
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
40 typedef unsigned short uint16
;
42 #define NOMAPPING 0xfffd
45 uint16 srcBegin
; /* 2 byte */
46 uint16 srcEnd
; /* 2 byte */
47 uint16 destBegin
; /* 2 byte */
51 uint16 srcBegin
; /* 2 byte */
52 uint16 srcEnd
; /* 2 byte */
53 uint16 mappingOffset
; /* 2 byte */
57 uint16 srcBegin
; /* 2 byte */
58 uint16 srcEnd
; /* 2 byte -waste */
59 uint16 destBegin
; /* 2 byte */
70 /* =================================================
72 ================================================= */
75 uint16 offsetToFormatArray
;
76 uint16 offsetToMapCellArray
;
77 uint16 offsetToMappingTable
;
81 uint16 umap
[256][256];
82 int bInitFromOrTo
= 0;
83 int bGenerateFromUnicodeTable
= 0;
85 #define MAXCELLNUM 1000
87 static int numOfItem
= 0;
88 uMapCell cell
[MAXCELLNUM
];
89 uint16 format
[MAXCELLNUM
/ 4];
90 uint16 mapping
[256*256];
91 static int mappinglen
= 0;
92 static int formatcount
[4] = {0,0,0,0};
94 #define SetFormat(n,f) { format[(n >> 2)] |= ((f) << ((n & 0x0003) << 2)); formatcount[f]++; }
95 #define GetFormat(n) ( format[(n >> 2)] >> ((n & 0x0003) << 2)) &0x00FF)
96 #define MAPVALUE(i) (umap[(i >> 8) & 0xFF][(i) & 0xFF])
98 int FORMAT1CNST
= 10 ;
106 umap
[i
][j
]= NOMAPPING
;
108 for(i
=0;i
<MAXCELLNUM
/ 4;i
++)
111 void SetMapValue(short u
,short c
)
113 if(NOMAPPING
== MAPVALUE(u
))
114 MAPVALUE(u
) = c
& 0x0000FFFF;
116 fprintf(stderr
, "warning- duplicate mapping %x map to both %x and %x\n", u
, MAPVALUE(u
), c
);
119 void AddFormat2(uint16 srcBegin
)
121 uint16 destBegin
= MAPVALUE(srcBegin
);
122 printf("Begin of Item %04X\n",numOfItem
);
123 printf(" Format 2\n");
124 printf(" srcBegin = %04X\n", srcBegin
);
125 printf(" destBegin = %04X\n", destBegin
);
126 SetFormat(numOfItem
,2);
127 cell
[numOfItem
].fmt
.format2
.srcBegin
= srcBegin
;
128 cell
[numOfItem
].fmt
.format2
.srcEnd
= 0;
129 cell
[numOfItem
].fmt
.format2
.destBegin
= destBegin
;
130 printf("End of Item %04X \n\n",numOfItem
);
132 /* Unmark the umap */
133 MAPVALUE(srcBegin
) = NOMAPPING
;
135 void AddFormat1(uint16 srcBegin
, uint16 srcEnd
)
138 printf("Begin of Item %04X\n",numOfItem
);
139 printf(" Format 1\n");
140 printf(" srcBegin = %04X\n", srcBegin
);
141 printf(" srcEnd = %04X\n", srcEnd
);
142 printf(" mappingOffset = %04X\n", mappinglen
);
143 printf(" Mapping = " );
144 SetFormat(numOfItem
,1);
145 cell
[numOfItem
].fmt
.format1
.srcBegin
= srcBegin
;
146 cell
[numOfItem
].fmt
.format1
.srcEnd
= srcEnd
;
147 cell
[numOfItem
].fmt
.format1
.mappingOffset
= mappinglen
;
148 for(i
=srcBegin
; i
<= srcEnd
; i
++,mappinglen
++)
150 if( ((i
-srcBegin
) % 8) == 0)
152 mapping
[mappinglen
]= MAPVALUE(i
);
153 printf("%04X ",(mapping
[mappinglen
] ));
154 /* Unmark the umap */
155 MAPVALUE(i
) = NOMAPPING
;
158 printf("End of Item %04X \n\n",numOfItem
);
161 void AddFormat0(uint16 srcBegin
, uint16 srcEnd
)
164 uint16 destBegin
= MAPVALUE(srcBegin
);
165 printf("Begin of Item %04X\n",numOfItem
);
166 printf(" Format 0\n");
167 printf(" srcBegin = %04X\n", srcBegin
);
168 printf(" srcEnd = %04X\n", srcEnd
);
169 printf(" destBegin = %04X\n", destBegin
);
170 SetFormat(numOfItem
,0);
171 cell
[numOfItem
].fmt
.format0
.srcBegin
= srcBegin
;
172 cell
[numOfItem
].fmt
.format0
.srcEnd
= srcEnd
;
173 cell
[numOfItem
].fmt
.format0
.destBegin
= destBegin
;
174 for(i
=srcBegin
; i
<= srcEnd
; i
++)
176 /* Unmark the umap */
177 MAPVALUE(i
) = NOMAPPING
;
179 printf("End of Item %04X \n\n",numOfItem
);
185 "/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */\n"
186 "/* ***** BEGIN LICENSE BLOCK *****\n"
187 " * Version: MPL 1.1/GPL 2.0/LGPL 2.1\n"
189 " * The contents of this file are subject to the Mozilla Public License Version\n"
190 " * 1.1 (the \"License\"); you may not use this file except in compliance with\n"
191 " * the License. You may obtain a copy of the License at\n"
192 " * http://www.mozilla.org/MPL/\n"
194 " * Software distributed under the License is distributed on an \"AS IS\" basis,\n"
195 " * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License\n"
196 " * for the specific language governing rights and limitations under the\n"
199 " * The Original Code is mozilla.org code.\n"
201 " * The Initial Developer of the Original Code is\n"
202 " * Netscape Communications Corporation.\n"
203 " * Portions created by the Initial Developer are Copyright (C) 2001\n"
204 " * the Initial Developer. All Rights Reserved.\n"
206 " * Contributor(s):\n"
208 " * Alternatively, the contents of this file may be used under the terms of\n"
209 " * either the GNU General Public License Version 2 or later (the \"GPL\"), or\n"
210 " * the GNU Lesser General Public License Version 2.1 or later (the \"LGPL\"),\n"
211 " * in which case the provisions of the GPL or the LGPL are applicable instead\n"
212 " * of those above. If you wish to allow use of your version of this file only\n"
213 " * under the terms of either the GPL or the LGPL, and not to allow others to\n"
214 " * use your version of this file under the terms of the MPL, indicate your\n"
215 " * decision by deleting the provisions above and replace them with the notice\n"
216 " * and other provisions required by the GPL or the LGPL. If you do not delete\n"
217 " * the provisions above, a recipient may use your version of this file under\n"
218 " * the terms of any one of the MPL, the GPL or the LGPL.\n"
220 " * ***** END LICENSE BLOCK ***** */\n");
224 /* OK! For now, we just use format 1 for each row */
225 /* We need to chage this to use other format to save the space */
227 uint16 ss
,gs
,gp
,state
,gc
;
228 uint16 diff
, lastdiff
;
231 printf("/*========================================================\n");
232 printf(" This is a Generated file. Please don't edit it.\n");
234 printf(" The tool which used to generate this file is called umaptable.\n");
235 printf(" You can find this tool under mozilla/intl/uconv/tools/umaptable.c.\n");
237 printf(" If you have any problem of this file. Please contact \n");
238 printf(" Netscape Client International Team or \n");
239 printf(" ftang@netscape <Frank Tang> \n");
241 printf(" Table in Debug form \n");
243 for(begin
= 0; MAPVALUE(begin
) ==NOMAPPING
; begin
++)
245 for(end
= 0xFFFF; MAPVALUE(end
) ==NOMAPPING
; end
--)
249 lastdiff
= MAPVALUE(begin
) - begin
;
250 for(gp
=begin
+1,state
= 0 ; gp
<=end
; gp
++)
253 diff
= MAPVALUE(gp
) - gp
;
254 input
= (diff
== lastdiff
);
268 if(gc
++ >= FORMAT0CNST
)
296 for(;(MAPVALUE(begin
) ==NOMAPPING
) && (begin
<= end
); begin
++)
300 for(;(MAPVALUE(end
)==NOMAPPING
) && (end
>= begin
); end
--)
302 for(ss
=gp
=begin
,state
= 0 ; gp
<=end
; gp
++)
304 int input
= (MAPVALUE(gp
) == NOMAPPING
);
318 if(gc
++ >= FORMAT1CNST
)
333 AddFormat1(ss
,gs
-1);
343 AddFormat1(ss
,end
);
345 printf("========================================================*/\n");
350 uint16 off1
,off2
,off3
;
352 uint16 formatitem
= (((numOfItem
)>>2) + 1);
354 off2
= off1
+ formatitem
;
355 off3
= off2
+ numOfItem
* sizeof(uMapCell
) / sizeof(uint16
);
356 /* write itemOfList */
357 printf("/* Offset=0x%04X ItemOfList */\n 0x%04X,\n", cur
++, numOfItem
);
359 /* write offsetToFormatArray */
360 printf("/*-------------------------------------------------------*/\n");
361 printf("/* Offset=0x%04X offsetToFormatArray */\n 0x%04X,\n", cur
++,off1
);
363 /* write offsetToMapCellArray */
364 printf("/*-------------------------------------------------------*/\n");
365 printf("/* Offset=0x%04X offsetToMapCellArray */ \n 0x%04X,\n", cur
++,off2
);
367 /* write offsetToMappingTable */
368 printf("/*-------------------------------------------------------*/\n");
369 printf("/* Offset=0x%04X offsetToMappingTable */ \n 0x%04X,\n", cur
++,off3
);
371 /* write FormatArray */
372 printf("/*-------------------------------------------------------*/\n");
373 printf("/* Offset=0x%04X Start of Format Array */ \n",cur
);
374 printf("/* Total of Format 0 : 0x%04X */\n"
376 printf("/* Total of Format 1 : 0x%04X */\n"
378 printf("/* Total of Format 2 : 0x%04X */\n"
380 printf("/* Total of Format 3 : 0x%04X */\n"
382 for(i
=0;i
<formatitem
;i
++,cur
++)
386 printf("0x%04X, ",format
[i
]);
390 /* write MapCellArray */
391 printf("/*-------------------------------------------------------*/\n");
392 printf("/* Offset=0x%04X Start of MapCell Array */ \n",cur
);
393 for(i
=0;i
<numOfItem
;i
++,cur
+=3)
395 printf("/* %04X */ 0x%04X, 0x%04X, 0x%04X, \n",
397 cell
[i
].fmt
.format0
.srcBegin
,
398 cell
[i
].fmt
.format0
.srcEnd
,
399 cell
[i
].fmt
.format0
.destBegin
403 /* write MappingTable */
404 printf("/*-------------------------------------------------------*/\n");
405 printf("/* Offset=0x%04X Start of MappingTable */ \n",cur
);
406 for(i
=0;i
<mappinglen
;i
++,cur
++)
409 printf("\n/* %04X */ ",i
);
410 printf("0x%04X, ",mapping
[i
] );
413 printf("/* End of table Total Length = 0x%04X * 2 */\n",cur
);
418 fprintf(stderr
, "please indicate what kind of mapping mapping table you want to generate:\n");
419 fprintf(stderr
, "\t-uf : generate *.uf (from unicode) table, or\n");
420 fprintf(stderr
, "\t-ut : generate *.ut (to unicode) table\n");
422 parsearg(int argc
, char* argv
[])
427 if(strncmp("-uf", argv
[i
],3) == 0) {
428 if(! bInitFromOrTo
) {
429 bGenerateFromUnicodeTable
= 1;
436 if(strncmp("-ut", argv
[i
],3) == 0) {
437 if(! bInitFromOrTo
) {
438 bGenerateFromUnicodeTable
= 0;
445 if((strncmp("-0", argv
[i
],2) == 0) && ((i
+1) < argc
))
448 if(sscanf(argv
[i
+1], "%d", &cnst0
) == 1)
457 fprintf(stderr
, "argc error !!!!\n");
462 if((strncmp("-1", argv
[i
],2) == 0) && ((i
+1) < argc
))
465 if(sscanf(argv
[i
+1], "%d", &cnst1
) == 1)
474 fprintf(stderr
, "argc error !!!!\n");
485 fprintf(stderr
, "format 0 cnst = %d\n", FORMAT0CNST
);
486 fprintf(stderr
, "format 1 cnst = %d\n", FORMAT1CNST
);
487 fprintf(stderr
, "generate u%c table\n",
488 bGenerateFromUnicodeTable
? 'f' : 't');
494 for(;gets(buf
)!=NULL
;)
496 if(buf
[0]=='0' && buf
[1] == 'x')
498 sscanf(buf
,"%hx %hx",&c
,&u
);
499 if(bGenerateFromUnicodeTable
)
506 main(int argc
, char* argv
[])
508 parsearg(argc
, argv
);