home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / libi18n / ugendata.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  10.9 KB  |  319 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  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/
  7.  *
  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
  11.  * NPL.
  12.  *
  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
  16.  * Reserved.
  17.  */
  18. #include "intlpriv.h"
  19. #include "ugen.h"
  20. #include "unicpriv.h"
  21. #include "prtypes.h"    /* For IS_LITTLE_ENDIAN */
  22.  
  23. #ifdef XP_WIN
  24. /*    We try to move to UNICODE 2.0 BASE 
  25.     The FULL_KOREAN_TABLE is only defined in Window platform when we use 
  26.     UNICODE 2.0 table .
  27.     We do not defined FULL_KOREAN_TABLE if we use UNICODE 1.1 BASE
  28.     We do not defined FULL_KOREAN_TABLE for Mac and UNIX since the 2.0 Korean 
  29.     Table for Mac and UNIX is only the part that these platform can handle
  30.     (So it is still a GL table )
  31. */
  32.  
  33.  
  34. #define FULL_KOREAN_TABLE 1 
  35.  
  36. #endif
  37.  
  38. /*
  39.     GenTableData.c
  40.  
  41. */
  42. /*=========================================================================================
  43.         Generator Table
  44. =========================================================================================*/
  45. #define PACK(h,l)        (int16)(( (h) << 8) | (l))
  46.  
  47. #if    defined(IS_LITTLE_ENDIAN)
  48. #define ShiftCell(sub,len,min,max,minh,minl,maxh,maxl)    \
  49.         PACK(len,sub), PACK(max,min), PACK(minl,minh), PACK(maxl,maxh)
  50. #else
  51. #define ShiftCell(sub,len,min,max,minh,minl,maxh,maxl)    \
  52.         PACK(sub,len), PACK(min, max), PACK(minh,minl), PACK(maxh,maxl)
  53. #endif
  54. /*-----------------------------------------------------------------------------------
  55.         ShiftTable for single byte encoding 
  56. -----------------------------------------------------------------------------------*/
  57. PRIVATE int16 sbShiftT[] =     { 
  58.     0, u1ByteCharset, 
  59.     ShiftCell(0,0,0,0,0,0,0,0) 
  60. };
  61. /*-----------------------------------------------------------------------------------
  62.         ShiftTable for two byte encoding 
  63. -----------------------------------------------------------------------------------*/
  64. PRIVATE int16 tbShiftT[] =     { 
  65.     0, u2BytesCharset, 
  66.     ShiftCell(0,0,0,0,0,0,0,0) 
  67. };
  68. /*-----------------------------------------------------------------------------------
  69.         ShiftTable for two byte encoding 
  70. -----------------------------------------------------------------------------------*/
  71. PRIVATE int16 tbGRShiftT[] =     { 
  72.     0, u2BytesGRCharset, 
  73.     ShiftCell(0,0,0,0,0,0,0,0) 
  74. };
  75. /*-----------------------------------------------------------------------------------
  76.         ShiftTable for KSC encoding 
  77. -----------------------------------------------------------------------------------*/
  78. #ifdef FULL_KOREAN_TABLE
  79. #define tbKSCShiftT    tbShiftT
  80. #else    
  81. #define tbKSCShiftT    tbGRShiftT    
  82. #endif  
  83. /*-----------------------------------------------------------------------------------
  84.         ShiftTable for shift jis encoding 
  85. -----------------------------------------------------------------------------------*/
  86. PRIVATE int16 sjisShiftT[] = { 
  87.     4, uMultibytesCharset,     
  88.     ShiftCell(u1ByteChar,     1, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x7F),
  89.     ShiftCell(u1ByteChar,     1, 0xA1, 0xDF, 0x00, 0xA1, 0x00, 0xDF),
  90.     ShiftCell(u2BytesChar,    2, 0x81, 0x9F, 0x81, 0x40, 0x9F, 0xFC),
  91.     ShiftCell(u2BytesChar,     2, 0xE0, 0xFC, 0xE0, 0x40, 0xFC, 0xFC)
  92. };
  93. /*-----------------------------------------------------------------------------------
  94.         ShiftTable for JIS0212 in EUCJP encoding 
  95. -----------------------------------------------------------------------------------*/
  96. PRIVATE int16 x0212ShiftT[] =     { 
  97.     0, u2BytesGRPrefix8FCharset, 
  98.     ShiftCell(0,0,0,0,0,0,0,0) 
  99. };
  100. /*-----------------------------------------------------------------------------------
  101.         ShiftTable for CNS11643-2 in EUC_TW encoding 
  102. -----------------------------------------------------------------------------------*/
  103. PRIVATE int16 cns2ShiftT[] =     { 
  104.     0, u2BytesGRPrefix8EA2Charset, 
  105.     ShiftCell(0,0,0,0,0,0,0,0) 
  106. };
  107. /*-----------------------------------------------------------------------------------
  108.         ShiftTable for big5 encoding 
  109. -----------------------------------------------------------------------------------*/
  110. PRIVATE int16 big5ShiftT[] = { 
  111.     2, uMultibytesCharset,     
  112.     ShiftCell(u1ByteChar,     1, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x7F),
  113.     ShiftCell(u2BytesChar,     2, 0xA1, 0xFE, 0xA1, 0x40, 0xFE, 0xFE)
  114. };
  115. /*-----------------------------------------------------------------------------------
  116.         ShiftTable for jis0201 for euc_jp encoding 
  117. -----------------------------------------------------------------------------------*/
  118. PRIVATE int16 x0201ShiftT[] = { 
  119.     2, uMultibytesCharset,     
  120.     ShiftCell(u1ByteChar,         1, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x7F),
  121.     ShiftCell(u1BytePrefix8EChar, 2, 0x8E, 0x8E, 0x00, 0xA1, 0x00, 0xDF)
  122. };
  123. /*-----------------------------------------------------------------------------------
  124.         ShiftTable for utf8
  125. -----------------------------------------------------------------------------------*/
  126. PRIVATE int16 utf8ShiftT[] = { 
  127.     3, uMultibytesCharset,     
  128.     ShiftCell(u1ByteChar,         1, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x7F),
  129.     ShiftCell(u2BytesUTF8,        2, 0xC0, 0xDF, 0x00, 0x00, 0x07, 0xFF),
  130.     ShiftCell(u3BytesUTF8,        3, 0xE0, 0xEF, 0x08, 0x00, 0xFF, 0xFF)
  131. };
  132. /*-----------------------------------------------------------------------------------
  133.         Array of ShiftTable Pointer
  134. -----------------------------------------------------------------------------------*/
  135. /* This table is used for npc and unicode to unknow encoding conversion */
  136. /* for those font csid, it do not shift GR/GL */
  137. PRIVATE    int16*    npcShiftTable[MAXCSIDINTBL] =
  138. {
  139.     sbShiftT,    sbShiftT,    sbShiftT,    0,                sjisShiftT,    0,            sbShiftT,    big5ShiftT,    
  140.     tbGRShiftT,    0,            sbShiftT,    sbShiftT,        tbKSCShiftT,    0,            sbShiftT,    sbShiftT,
  141.     sbShiftT,    sbShiftT,    sbShiftT,    sbShiftT,        sbShiftT,    sbShiftT,    sbShiftT,    sbShiftT,
  142.     tbShiftT,    tbShiftT,    tbShiftT,    sbShiftT,        tbShiftT,    sbShiftT,    tbShiftT,    tbShiftT,
  143.     0,            0,            0,            0,                0,            big5ShiftT,    0,            sbShiftT,
  144.     sbShiftT,    sbShiftT,    sbShiftT,    sbShiftT,        sbShiftT,    sbShiftT,    sbShiftT,            0,
  145.     0,            0,            0,            0,                0,            0,            0,            0,
  146.     0,            0,            0,            0,                0,            0,            sbShiftT,    0
  147. };
  148.  
  149. /* This table is used for unicode to single encoding conversion */
  150. /* for those font csid, it always shift GR/GL */
  151. PRIVATE    int16*    strShiftTable[MAXCSIDINTBL] =
  152. {
  153.     sbShiftT,    sbShiftT,    sbShiftT,    0,                sjisShiftT,    0,            sbShiftT,    big5ShiftT,    
  154.     tbGRShiftT,    0,            sbShiftT,    sbShiftT,        tbKSCShiftT,    0,            sbShiftT,    sbShiftT,
  155.     sbShiftT,    sbShiftT,    sbShiftT,    sbShiftT,        sbShiftT,    sbShiftT,    sbShiftT,    sbShiftT,
  156.     tbGRShiftT,    cns2ShiftT,    tbGRShiftT,    x0201ShiftT,    tbGRShiftT,    sbShiftT,    x0212ShiftT,tbGRShiftT,
  157.     0,            0,            utf8ShiftT,    0,                0,            big5ShiftT,    0,            sbShiftT,
  158.     sbShiftT,    sbShiftT,    sbShiftT,    sbShiftT,        sbShiftT,    sbShiftT,    sbShiftT,            0,
  159.     0,            0,            0,            0,                0,            0,            0,            0,
  160.     0,            0,            0,            0,                0,            0,            sbShiftT,    0
  161. };
  162.  
  163. PRIVATE UnicodeTableSet unicodetableset[] =
  164. {
  165. #ifdef XP_MAC
  166.     {    CS_BIG5,    {        
  167.         {CS_BIG5,0x81,0xFC},        
  168.         {CS_ASCII,0x00,0x7E},        
  169.         {CS_DEFAULT,0xFF,0x00},        
  170.         {CS_DEFAULT,0xFF,0x00}
  171.     }},
  172.     {    CS_GB_8BIT,    {        
  173.         {CS_GB_8BIT,0xA1,0xFE},        
  174.         {CS_ASCII,0x00,0x7E},        
  175.         {CS_DEFAULT,0xFF,0x00},
  176.         {CS_DEFAULT,0xFF,0x00}
  177.     }},
  178.         /*    We do not change the Mac Korean even we  use 2.0 base table */
  179.         /*    This is because the Mac table is not the full table        */
  180.         /*     It is still a GL table                        */
  181.     {    CS_KSC_8BIT,    {        
  182.         {CS_KSC_8BIT,0xA1,0xFE},         
  183.         {CS_ASCII,0x00,0x7E},        
  184.         {CS_DEFAULT,0xFF,0x00},
  185.         {CS_DEFAULT,0xFF,0x00}
  186.     }},
  187.     {    CS_USER_DEFINED_ENCODING, {
  188.         {CS_ASCII,0x00,0x7E},        
  189.         {CS_DEFAULT,    0xFF,0x00},        
  190.         {CS_DEFAULT,    0xFF,0x00},        
  191.         {CS_DEFAULT,    0xFF,0x00} 
  192.     }},
  193.     {    CS_DEFAULT,    {        
  194.         {CS_DEFAULT,0xFF,0x00},
  195.         {CS_DEFAULT,0xFF,0x00},
  196.         {CS_DEFAULT,0xFF,0x00},
  197.         {CS_DEFAULT,0xFF,0x00}
  198.     }}
  199. #endif
  200. #if defined(XP_WIN) || defined(XP_OS2)
  201.     {    CS_BIG5,    {        
  202.         {CS_BIG5,0x81,0xFC},        
  203.         {CS_ASCII,0x00,0x7E},        
  204.         {CS_DEFAULT,0xFF,0x00},        
  205.         {CS_DEFAULT,0xFF,0x00}
  206.     }},
  207.     {    CS_GB_8BIT,    {        
  208.         {CS_GB_8BIT,0xA1,0xFE},        
  209.         {CS_ASCII,0x00,0x7E},        
  210.         {CS_DEFAULT,0xFF,0x00},
  211.         {CS_DEFAULT,0xFF,0x00}
  212.     }},
  213. #ifdef    FULL_KOREAN_TABLE
  214.     {    CS_KSC_8BIT,    {        
  215.         {CS_KSC_8BIT,0x81,0xFE},        /* CAREFUL: it is 0x81 not 0xA1 here */
  216.         {CS_ASCII,0x00,0x7E},        
  217.         {CS_DEFAULT,0xFF,0x00},
  218.         {CS_DEFAULT,0xFF,0x00}
  219.     }},
  220. #else
  221.     {    CS_KSC_8BIT,    {        
  222.         {CS_KSC_8BIT,0xA1,0xFE},        
  223.         {CS_ASCII,0x00,0x7E},        
  224.         {CS_DEFAULT,0xFF,0x00},
  225.         {CS_DEFAULT,0xFF,0x00}
  226.     }},
  227. #endif
  228.     {    CS_USER_DEFINED_ENCODING, {
  229.         {CS_ASCII,0x00,0x7E},        
  230.         {CS_DEFAULT,    0xFF,0x00},        
  231.         {CS_DEFAULT,    0xFF,0x00},        
  232.         {CS_DEFAULT,    0xFF,0x00} 
  233.     }},
  234.     {    CS_DEFAULT,    {        
  235.         {CS_DEFAULT,0xFF,0x00},
  236.         {CS_DEFAULT,0xFF,0x00},
  237.         {CS_DEFAULT,0xFF,0x00},
  238.         {CS_DEFAULT,0xFF,0x00}
  239.     }}
  240. #endif
  241. #ifdef XP_UNIX
  242.     {    CS_EUCJP,    {        
  243.         {CS_JISX0208,0xA1,0xFE},        
  244.         {CS_JISX0201,0x20,0x7E},        
  245.         {CS_JISX0201,0x8E,0x8E},        
  246.         {CS_JISX0212,0x8F,0x8F}
  247.     }},
  248.     {    CS_BIG5,    {        
  249.         {CS_X_BIG5,0x81,0xFC},        
  250.         {CS_ASCII,0x00,0x7E},        
  251.         {CS_DEFAULT,0xFF,0x00},        
  252.         {CS_DEFAULT,0xFF,0x00}
  253.     }},
  254.     {    CS_CNS_8BIT,    {        
  255.         {CS_CNS11643_1,0xA1,0xFE},        
  256.         {CS_CNS11643_2,0x8E,0x8E},        
  257.         {CS_ASCII,0x00,0x7E},        
  258.         {CS_DEFAULT,0xFF,0x00}
  259.     }},
  260.     {    CS_GB_8BIT,    {        
  261.         {CS_GB2312,0xA1,0xFE},        
  262.         {CS_ASCII,0x00,0x7E},        
  263.         {CS_DEFAULT,0xFF,0x00},
  264.         {CS_DEFAULT,0xFF,0x00}
  265.     }},
  266.         /*    We do not change the UNIX Korean even we  use 2.0 base table */
  267.         /*    This is because the UNIX table is not the full table        */
  268.         /*     It is still a GL table                        */
  269.     {    CS_KSC_8BIT,    {        
  270.         {CS_KSC5601,0xA1,0xFE},        
  271.         {CS_ASCII,0x00,0x7E},        
  272.         {CS_DEFAULT,0xFF,0x00},
  273.         {CS_DEFAULT,0xFF,0x00}
  274.     }},
  275.     {    CS_USER_DEFINED_ENCODING, {
  276.         {CS_ASCII,0x00,0x7E},        
  277.         {CS_DEFAULT,    0xFF,0x00},        
  278.         {CS_DEFAULT,    0xFF,0x00},        
  279.         {CS_DEFAULT,    0xFF,0x00} 
  280.     }},
  281.     {    CS_USRDEF2, {
  282.         {CS_ASCII,0x00,0x7E},        
  283.         {CS_DEFAULT,    0xFF,0x00},        
  284.         {CS_DEFAULT,    0xFF,0x00},        
  285.         {CS_DEFAULT,    0xFF,0x00} 
  286.     }},
  287.     {    CS_DEFAULT,    {        
  288.         {CS_DEFAULT,0xFF,0x00},
  289.         {CS_DEFAULT,0xFF,0x00},
  290.         {CS_DEFAULT,0xFF,0x00},
  291.         {CS_DEFAULT,0xFF,0x00}
  292.     }}
  293. #endif
  294.  
  295. };
  296.  
  297. MODULE_PRIVATE UnicodeTableSet* GetUnicodeTableSet(uint16 csid)
  298. {
  299.     int i;
  300.     for(i=0;unicodetableset[i].maincsid != CS_DEFAULT;i++)
  301.     {
  302.         if(unicodetableset[i].maincsid == csid)
  303.             return &(unicodetableset[i]);     
  304.     }
  305.     return NULL;
  306. }
  307.  
  308. /*-----------------------------------------------------------------------------------
  309.         Public Function
  310. -----------------------------------------------------------------------------------*/
  311. MODULE_PRIVATE uShiftTable* GetShiftTableFromCsid(uint16 csid)
  312. {
  313.     return (uShiftTable*)(strShiftTable[csid & 0x3F]);
  314. }
  315. MODULE_PRIVATE uShiftTable* InfoToShiftTable(unsigned char info)
  316. {
  317.     return (uShiftTable*)(npcShiftTable[info & (MAXCSIDINTBL - 1)]);
  318. }
  319.