Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Functions | Variables
umaptable.c File Reference
#include <stdio.h>

Go to the source code of this file.

Classes

struct  uFormat0
struct  uFormat1
struct  uFormat2
struct  uMapCell
struct  uTable
union  uMapCell.fmt

Defines

#define NOMAPPING   0xfffd
#define MAXCELLNUM   1000
#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])

Typedefs

typedef short int16
typedef unsigned short uint16

Functions

void initmaps ()
void SetMapValue (short u, short c)
void AddFormat2 (uint16 srcBegin)
void AddFormat1 (uint16 srcBegin, uint16 srcEnd)
void AddFormat0 (uint16 srcBegin, uint16 srcEnd)
void printnpl ()
void gentable ()
void writetable ()
void usage ()
 parsearg (int argc, char *argv[])
void getinput ()
 main (int argc, char *argv[])

Variables

uint16 umap [256][256]
int bInitFromOrTo = 0
int bGenerateFromUnicodeTable = 0
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}
int FORMAT1CNST = 10
int FORMAT0CNST = 5

Class Documentation

struct uFormat0

Definition at line 50 of file umap.h.

Class Members
uint16 destBegin
PRUint16 destBegin
uint16 srcBegin
PRUint16 srcBegin
uint16 srcEnd
PRUint16 srcEnd
struct uFormat1

Definition at line 56 of file umap.h.

Class Members
uint16 mappingOffset
PRUint16 mappingOffset
uint16 srcBegin
PRUint16 srcBegin
uint16 srcEnd
PRUint16 srcEnd
struct uFormat2

Definition at line 62 of file umap.h.

Class Members
uint16 destBegin
PRUint16 destBegin
uint16 srcBegin
PRUint16 srcBegin
uint16 srcEnd
PRUint16 srcEnd
struct uMapCell

Definition at line 68 of file umap.h.

Class Members
union uMapCell fmt
union uMapCell fmt
struct uTable

Definition at line 78 of file umap.h.

Class Members
uint16 data
PRUint16 data
uint16 itemOfList
PRUint16 itemOfList
uint16 offsetToFormatArray
PRUint16 offsetToFormatArray
uint16 offsetToMapCellArray
PRUint16 offsetToMapCellArray
uint16 offsetToMappingTable
PRUint16 offsetToMappingTable
union uMapCell.fmt

Definition at line 63 of file umaptable.c.

Class Members
uFormat0 format0
uFormat1 format1
uFormat2 format2

Define Documentation

#define GetFormat (   n)    ( format[(n >> 2)] >> ((n & 0x0003) << 2)) &0x00FF)

Definition at line 95 of file umaptable.c.

#define MAPVALUE (   i)    (umap[(i >> 8) & 0xFF][(i) & 0xFF])

Definition at line 96 of file umaptable.c.

#define MAXCELLNUM   1000

Definition at line 85 of file umaptable.c.

#define NOMAPPING   0xfffd

Definition at line 42 of file umaptable.c.

#define SetFormat (   n,
  f 
)    { format[(n >> 2)] |= ((f) << ((n & 0x0003) << 2)); formatcount[f]++; }

Definition at line 94 of file umaptable.c.


Typedef Documentation

typedef short int16

Definition at line 39 of file umaptable.c.

typedef unsigned short uint16

Definition at line 40 of file umaptable.c.


Function Documentation

void AddFormat0 ( uint16  srcBegin,
uint16  srcEnd 
)

Definition at line 161 of file umaptable.c.

{
       uint16 i;
       uint16 destBegin = MAPVALUE(srcBegin);
       printf("Begin of Item %04X\n",numOfItem);
       printf(" Format 0\n");
       printf("  srcBegin = %04X\n", srcBegin);
       printf("  srcEnd = %04X\n", srcEnd );
       printf("  destBegin = %04X\n", destBegin );
       SetFormat(numOfItem,0);
       cell[numOfItem].fmt.format0.srcBegin = srcBegin;
       cell[numOfItem].fmt.format0.srcEnd = srcEnd;
       cell[numOfItem].fmt.format0.destBegin = destBegin;
       for(i=srcBegin ; i <= srcEnd ; i++)
       {
              /*     Unmark the umap */
              MAPVALUE(i) = NOMAPPING;
       }
       printf("End of Item %04X \n\n",numOfItem);
       numOfItem++;
}

Here is the caller graph for this function:

void AddFormat1 ( uint16  srcBegin,
uint16  srcEnd 
)

Definition at line 135 of file umaptable.c.

{
       uint16 i;
       printf("Begin of Item %04X\n",numOfItem);
       printf(" Format 1\n");
       printf("  srcBegin = %04X\n", srcBegin);
       printf("  srcEnd = %04X\n", srcEnd );
       printf("  mappingOffset = %04X\n", mappinglen);
       printf(" Mapping  = " );  
       SetFormat(numOfItem,1);
       cell[numOfItem].fmt.format1.srcBegin = srcBegin;
       cell[numOfItem].fmt.format1.srcEnd = srcEnd;
       cell[numOfItem].fmt.format1.mappingOffset = mappinglen;
       for(i=srcBegin ; i <= srcEnd ; i++,mappinglen++)
       {
              if( ((i-srcBegin) % 8) == 0)
                     printf("\n  ");
              mapping[mappinglen]= MAPVALUE(i);
              printf("%04X ",(mapping[mappinglen]  ));
              /*     Unmark the umap */
              MAPVALUE(i) = NOMAPPING;
       }
       printf("\n");
       printf("End of Item %04X \n\n",numOfItem);
       numOfItem++;
}

Here is the caller graph for this function:

void AddFormat2 ( uint16  srcBegin)

Definition at line 119 of file umaptable.c.

{
       uint16 destBegin = MAPVALUE(srcBegin);
       printf("Begin of Item %04X\n",numOfItem);
       printf(" Format 2\n");
       printf("  srcBegin = %04X\n", srcBegin);
       printf("  destBegin = %04X\n", destBegin );
       SetFormat(numOfItem,2);
       cell[numOfItem].fmt.format2.srcBegin = srcBegin;
       cell[numOfItem].fmt.format2.srcEnd = 0;
       cell[numOfItem].fmt.format2.destBegin = destBegin;
       printf("End of Item %04X \n\n",numOfItem);
       numOfItem++;
       /*     Unmark the umap */
       MAPVALUE(srcBegin) = NOMAPPING;
}

Here is the caller graph for this function:

Definition at line 222 of file umaptable.c.

{
       /*     OK! For now, we just use format 1 for each row */
       /*     We need to chage this to use other format to save the space */
       uint16 begin,end;
       uint16 ss,gs,gp,state,gc;   
       uint16 diff, lastdiff;

        printnpl();
       printf("/*========================================================\n");
       printf("  This is a Generated file. Please don't edit it.\n");
       printf("\n");
       printf("  The tool which used to generate this file is called umaptable.\n");
       printf("  You can find this tool under mozilla/intl/uconv/tools/umaptable.c.\n");

       printf("  If you have any problem of this file. Please contact \n"); 
       printf("  Netscape Client International Team or \n");
       printf("  ftang@netscape <Frank Tang> \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");
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 490 of file umaptable.c.

{
  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);
        }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 100 of file umaptable.c.

{
       int i,j;
       for(i=0;i<256;i++)
              for(j=0;j<256;j++) 
              {
                     umap[i][j]=   NOMAPPING;
              }
       for(i=0;i<MAXCELLNUM / 4;i++)
              format[i]=0;
}

Here is the caller graph for this function:

main ( int  argc,
char *  argv[] 
)

Definition at line 506 of file umaptable.c.

Here is the call graph for this function:

parsearg ( int  argc,
char *  argv[] 
)

Definition at line 422 of file umaptable.c.

{
       int i;
       for(i=0;i<argc;i++)
       {
              if(strncmp("-uf", argv[i],3) == 0) {
                        if(! bInitFromOrTo) {
                           bGenerateFromUnicodeTable = 1;
                           bInitFromOrTo = 1;
                        } else {
                           usage();
                           exit(-1);
                        }
                } 
              if(strncmp("-ut", argv[i],3) == 0) {
                        if(! bInitFromOrTo) {
                           bGenerateFromUnicodeTable = 0;
                           bInitFromOrTo = 1;
                        } else {
                           usage();
                           exit(-1);
                        }
                } 
              if((strncmp("-0", argv[i],2) == 0) && ((i+1) < argc))
              {
                     int cnst0;
                     if(sscanf(argv[i+1], "%d", &cnst0) == 1)
                     {
                            if(cnst0 > 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');
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 182 of file umaptable.c.

{
printf(
"/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */\n"
"/* ***** BEGIN LICENSE BLOCK *****\n"
" * Version: MPL 1.1/GPL 2.0/LGPL 2.1\n"
" *\n"
" * The contents of this file are subject to the Mozilla Public License Version\n"
" * 1.1 (the \"License\"); you may not use this file except in compliance with\n"
" * the License. You may obtain a copy of the License at\n"
" * http://www.mozilla.org/MPL/\n"
" *\n"
" * Software distributed under the License is distributed on an \"AS IS\" basis,\n"
" * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License\n"
" * for the specific language governing rights and limitations under the\n"
" * License.\n"
" *\n"
" * The Original Code is mozilla.org code.\n"
" *\n"
" * The Initial Developer of the Original Code is\n"
" * Netscape Communications Corporation.\n"
" * Portions created by the Initial Developer are Copyright (C) 2001\n"
" * the Initial Developer. All Rights Reserved.\n"
" *\n"
" * Contributor(s):\n"
" *\n"
" * Alternatively, the contents of this file may be used under the terms of\n"
" * either the GNU General Public License Version 2 or later (the \"GPL\"), or\n"
" * the GNU Lesser General Public License Version 2.1 or later (the \"LGPL\"),\n"
" * in which case the provisions of the GPL or the LGPL are applicable instead\n"
" * of those above. If you wish to allow use of your version of this file only\n"
" * under the terms of either the GPL or the LGPL, and not to allow others to\n"
" * use your version of this file under the terms of the MPL, indicate your\n"
" * decision by deleting the provisions above and replace them with the notice\n"
" * and other provisions required by the GPL or the LGPL. If you do not delete\n"
" * the provisions above, a recipient may use your version of this file under\n"
" * the terms of any one of the MPL, the GPL or the LGPL.\n"
" *\n"
" * ***** END LICENSE BLOCK ***** */\n");
}

Here is the caller graph for this function:

void SetMapValue ( short  u,
short  c 
)

Definition at line 111 of file umaptable.c.

{
        if(NOMAPPING == MAPVALUE(u))
          MAPVALUE(u) = c & 0x0000FFFF;
        else {
           fprintf(stderr, "warning- duplicate mapping %x map to both %x and %x\n", u, MAPVALUE(u), c);
        }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void usage ( void  )

Definition at line 416 of file umaptable.c.

{
  fprintf(stderr, "please indicate what kind of mapping mapping table you want to generate:\n");
  fprintf(stderr, "\t-uf : generate *.uf (from unicode) table, or\n");
  fprintf(stderr, "\t-ut : generate *.ut (to unicode) table\n");
}

Here is the call graph for this function:

Definition at line 347 of file umaptable.c.

{
       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<formatitem;i++,cur++)
       {
              if((i%8) == 0)       
                     printf("\n");
              printf("0x%04X, ",format[i]);
       }
       printf("\n");

       /*     write MapCellArray          */
       printf("/*-------------------------------------------------------*/\n");
       printf("/*       Offset=0x%04X   Start of MapCell Array */ \n",cur);
       for(i=0;i<numOfItem;i++,cur+=3)
       {
              printf("/* %04X */    0x%04X, 0x%04X, 0x%04X, \n", 
                     i,
                     cell[i].fmt.format0.srcBegin,
                     cell[i].fmt.format0.srcEnd,
                     cell[i].fmt.format0.destBegin
               );
       }

       /*     write MappingTable          */
       printf("/*-------------------------------------------------------*/\n");
       printf("/*       Offset=0x%04X   Start of MappingTable */ \n",cur);
       for(i=0;i<mappinglen;i++,cur++)
       {
              if((i%8) == 0)       
                     printf("\n/* %04X */    ",i);
              printf("0x%04X, ",mapping[i] );
       }
       printf("\n");
       printf("/*    End of table Total Length = 0x%04X * 2 */\n",cur);
}

Here is the caller graph for this function:


Variable Documentation

Definition at line 83 of file umaptable.c.

Definition at line 82 of file umaptable.c.

Definition at line 88 of file umaptable.c.

const char JSErrorCallback void const uintN JSErrorCallback void const uintN const char * format

Definition at line 89 of file umaptable.c.

Definition at line 99 of file umaptable.c.

Definition at line 98 of file umaptable.c.

int formatcount[4] = {0,0,0,0} [static]

Definition at line 92 of file umaptable.c.

uint16 mapping[256 *256]

Definition at line 90 of file umaptable.c.

int mappinglen = 0 [static]

Definition at line 91 of file umaptable.c.

int numOfItem = 0 [static]

Definition at line 87 of file umaptable.c.

uint16 umap[256][256]

Definition at line 81 of file umaptable.c.