/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- * * ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is mozilla.org Code. * * The Initial Developer of the Original Code is * Netscape Communications Corporation. * Portions created by the Initial Developer are Copyright (C) 1998 * the Initial Developer. All Rights Reserved. * * Contributor(s): * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), * in which case the provisions of the GPL or the LGPL are applicable instead * of those above. If you wish to allow use of your version of this file only * under the terms of either the GPL or the LGPL, and not to allow others to * use your version of this file under the terms of the MPL, indicate your * decision by deleting the provisions above and replace them with the notice * and other provisions required by the GPL or the LGPL. If you do not delete * the provisions above, a recipient may use your version of this file under * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ #include typedef short int16; typedef unsigned short uint16; #define NOMAPPING 0xfffd typedef struct { uint16 srcBegin; /* 2 byte */ uint16 srcEnd; /* 2 byte */ uint16 destBegin; /* 2 byte */ } uFormat0; typedef struct { uint16 srcBegin; /* 2 byte */ uint16 srcEnd; /* 2 byte */ uint16 mappingOffset; /* 2 byte */ } uFormat1; typedef struct { uint16 srcBegin; /* 2 byte */ uint16 srcEnd; /* 2 byte -waste */ uint16 destBegin; /* 2 byte */ } uFormat2; typedef struct { union { uFormat0 format0; uFormat1 format1; uFormat2 format2; } fmt; } uMapCell; /* ================================================= uTable ================================================= */ typedef struct { uint16 itemOfList; uint16 offsetToFormatArray; uint16 offsetToMapCellArray; uint16 offsetToMappingTable; uint16 data[1]; } uTable; uint16 umap[256][256]; int bInitFromOrTo = 0; int bGenerateFromUnicodeTable = 0; #define MAXCELLNUM 1000 static int numOfItem = 0; uMapCell cell[MAXCELLNUM]; uint16 format[MAXCELLNUM / 4]; uint16 mapping[256*256]; static int mappinglen = 0; static int formatcount[4] = {0,0,0,0}; #define SetFormat(n,f) { format[(n >> 2)] |= ((f) << ((n & 0x0003) << 2)); formatcount[f]++; } #define GetFormat(n) ( format[(n >> 2)] >> ((n & 0x0003) << 2)) &0x00FF) #define MAPVALUE(i) (umap[(i >> 8) & 0xFF][(i) & 0xFF]) int FORMAT1CNST = 10 ; int FORMAT0CNST = 5 ; void initmaps() { int i,j; for(i=0;i<256;i++) for(j=0;j<256;j++) { umap[i][j]= NOMAPPING; } for(i=0;i \n"); printf("\n"); printf(" Table in Debug form \n"); for(begin = 0; MAPVALUE(begin) ==NOMAPPING; begin++) ; for(end = 0xFFFF; MAPVALUE(end) ==NOMAPPING; end--) ; if(end != begin) { lastdiff = MAPVALUE(begin) - begin; for(gp=begin+1,state = 0 ; gp<=end; gp++) { int input ; diff = MAPVALUE(gp) - gp; input = (diff == lastdiff); switch(state) { case 0: if(input) { state = 1; ss = gp -1; gc = 2; } break; case 1: if(input) { if(gc++ >= FORMAT0CNST) { state = 2; } } else { state = 0; } break; case 2: if(input) { } else { AddFormat0(ss,gp-1); state = 0; } break; } lastdiff = diff; } } if(state == 2) AddFormat0(ss,end); for(;(MAPVALUE(begin) ==NOMAPPING) && (begin <= end); begin++) ; if(begin <= end) { for(;(MAPVALUE(end)==NOMAPPING) && (end >= begin); end--) ; for(ss=gp=begin,state = 0 ; gp<=end; gp++) { int input = (MAPVALUE(gp) == NOMAPPING); switch(state) { case 0: if(input) { gc = 1; gs = gp; state = 1; } break; case 1: if(input) { if(gc++ >= FORMAT1CNST) state = 2; } else state = 0; break; case 2: if(input) { } else { if(gs == (ss+1)) AddFormat2(ss); else AddFormat1(ss ,gs-1); state = 0; ss = gp; } break; } } if(end == ss) AddFormat2(ss ); else AddFormat1(ss ,end ); } printf("========================================================*/\n"); } void writetable() { uint16 i; uint16 off1,off2,off3; uint16 cur = 0; uint16 formatitem = (((numOfItem)>>2) + 1); off1 = 4; off2 = off1 + formatitem ; off3 = off2 + numOfItem * sizeof(uMapCell) / sizeof(uint16); /* write itemOfList */ printf("/* Offset=0x%04X ItemOfList */\n 0x%04X,\n", cur++, numOfItem); /* write offsetToFormatArray */ printf("/*-------------------------------------------------------*/\n"); printf("/* Offset=0x%04X offsetToFormatArray */\n 0x%04X,\n", cur++,off1); /* write offsetToMapCellArray */ printf("/*-------------------------------------------------------*/\n"); printf("/* Offset=0x%04X offsetToMapCellArray */ \n 0x%04X,\n", cur++,off2); /* write offsetToMappingTable */ printf("/*-------------------------------------------------------*/\n"); printf("/* Offset=0x%04X offsetToMappingTable */ \n 0x%04X,\n", cur++,off3); /* write FormatArray */ printf("/*-------------------------------------------------------*/\n"); printf("/* Offset=0x%04X Start of Format Array */ \n",cur); printf("/* Total of Format 0 : 0x%04X */\n" , formatcount[0]); printf("/* Total of Format 1 : 0x%04X */\n" , formatcount[1]); printf("/* Total of Format 2 : 0x%04X */\n" , formatcount[2]); printf("/* Total of Format 3 : 0x%04X */\n" , formatcount[3]); for(i=0;i 0) { FORMAT0CNST = cnst0; } } else { fprintf(stderr, "argc error !!!!\n"); exit(-1); } i++; } if((strncmp("-1", argv[i],2) == 0) && ((i+1) < argc)) { int cnst1; if(sscanf(argv[i+1], "%d", &cnst1) == 1) { if(cnst1 > 0) { FORMAT1CNST = cnst1; } } else { fprintf(stderr, "argc error !!!!\n"); exit(-1); } i++; } } if(! bInitFromOrTo) { usage(); exit(-1); } fprintf(stderr, "format 0 cnst = %d\n", FORMAT0CNST); fprintf(stderr, "format 1 cnst = %d\n", FORMAT1CNST); fprintf(stderr, "generate u%c table\n", bGenerateFromUnicodeTable ? 'f' : 't'); } void getinput() { char buf[256]; short c,u; for(;gets(buf)!=NULL;) { if(buf[0]=='0' && buf[1] == 'x') { sscanf(buf,"%hx %hx",&c,&u); if(bGenerateFromUnicodeTable) SetMapValue(u, c); else SetMapValue(c, u); } } } main(int argc, char* argv[]) { parsearg(argc, argv); initmaps(); getinput(); gentable(); writetable(); }