home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / libi18n / umap.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  8.9 KB  |  237 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 "unicpriv.h"
  20.  
  21. typedef uint16 (* MapFormatFunc)(uint16 in,uTable *uTable,uMapCell *cell);
  22. typedef XP_Bool (* HitFormateFunc)(uint16 in,uMapCell *cell);
  23. typedef void (* IterateFormatFunc)(uTable *uTable, uMapCell *cell,uMapIterateFunc callback, uint16 context);
  24.  
  25. PRIVATE XP_Bool uHitFormate0(uint16 in,uMapCell *cell);
  26. PRIVATE XP_Bool uHitFormate1(uint16 in,uMapCell *cell);
  27. PRIVATE XP_Bool uHitFormate2(uint16 in,uMapCell *cell);
  28. PRIVATE uint16 uMapFormate0(uint16 in,uTable *uTable,uMapCell *cell);
  29. PRIVATE uint16 uMapFormate1(uint16 in,uTable *uTable,uMapCell *cell);
  30. PRIVATE uint16 uMapFormate2(uint16 in,uTable *uTable,uMapCell *cell);
  31. PRIVATE void uIterateFormate0(uTable *uTable, uMapCell *cell,uMapIterateFunc callback, uint16 context);
  32. PRIVATE void uIterateFormate1(uTable *uTable, uMapCell *cell,uMapIterateFunc callback, uint16 context);
  33. PRIVATE void uIterateFormate2(uTable *uTable, uMapCell *cell,uMapIterateFunc callback, uint16 context);
  34. PRIVATE uMapCell *uGetMapCell(uTable *uTable, int16 item);
  35. PRIVATE char uGetFormat(uTable *uTable, int16 item);
  36.  
  37.  
  38. /*=================================================================================
  39.  
  40. =================================================================================*/
  41. PRIVATE MapFormatFunc m_map[uNumFormatTag] =
  42. {
  43.     uMapFormate0,
  44.     uMapFormate1,
  45.     uMapFormate2,
  46. };
  47. /*=================================================================================
  48.  
  49. =================================================================================*/
  50. PRIVATE IterateFormatFunc m_iterate[uNumFormatTag] =
  51. {
  52.     uIterateFormate0,
  53.     uIterateFormate1,
  54.     uIterateFormate2,
  55. };
  56. /*=================================================================================
  57.  
  58. =================================================================================*/
  59. PRIVATE HitFormateFunc m_hit[uNumFormatTag] =
  60. {
  61.     uHitFormate0,
  62.     uHitFormate1,
  63.     uHitFormate2,
  64. };
  65.  
  66. /*
  67.     Need more work
  68. */
  69. /*=================================================================================
  70.  
  71. =================================================================================*/
  72. PRIVATE XP_Bool uHit(unsigned char format, uint16 in,uMapCell *cell)
  73. {
  74.     return     (* m_hit[format])((in),(cell));
  75. }
  76. /*=================================================================================
  77.  
  78. =================================================================================*/
  79. PRIVATE void uCellIterate(unsigned char format, uTable *uTable, uMapCell *cell,uMapIterateFunc callback, uint16 context)
  80. {
  81.     (* m_iterate[format])((uTable),(cell),(callback),(context));
  82. }
  83. /*    
  84.     Switch to Macro later for performance
  85.     
  86. #define    uHit(format,in,cell)         (* m_hit[format])((in),(cell))
  87. */
  88. /*=================================================================================
  89.  
  90. =================================================================================*/
  91. PRIVATE uint16 uMap(unsigned char format, uint16 in,uTable *uTable,uMapCell *cell)
  92. {
  93.     return     (* m_map[format])((in),(uTable),(cell));
  94. }
  95. /*     
  96.     Switch to Macro later for performance
  97.     
  98. #define uMap(format,in,cell)         (* m_map[format])((in),(cell))
  99. */
  100.  
  101. /*=================================================================================
  102.  
  103. =================================================================================*/
  104. /*    
  105.     Switch to Macro later for performance
  106. */
  107. PRIVATE uMapCell *uGetMapCell(uTable *uTable, int16 item)
  108. {
  109.     return ((uMapCell *)(((uint16 *)uTable) + uTable->offsetToMapCellArray) + item) ;
  110. }
  111. /*=================================================================================
  112.  
  113. =================================================================================*/
  114. /*    
  115.     Switch to Macro later for performance
  116. */
  117. PRIVATE char uGetFormat(uTable *uTable, int16 item)
  118. {
  119.     return (((((uint16 *)uTable) + uTable->offsetToFormatArray)[ item >> 2 ]
  120.         >> (( item % 4 ) << 2)) & 0x0f);
  121. }
  122. /*=================================================================================
  123.  
  124. =================================================================================*/
  125. MODULE_PRIVATE XP_Bool uMapCode(uTable *uTable, uint16 in, uint16* out)
  126. {
  127.     XP_Bool done = FALSE;
  128.     uint16 itemOfList = uTable->itemOfList;
  129.     uint16 i;
  130.     for(i=0;i<itemOfList;i++)
  131.     {
  132.         uMapCell* uCell;
  133.         char format = uGetFormat(uTable,i);
  134.         uCell = uGetMapCell(uTable,i);
  135.         if(uHit(format, in, uCell))
  136.         {
  137.             *out = uMap(format, in, uTable,uCell);
  138.             done = TRUE;
  139.             break;
  140.         }
  141.     }
  142.     return ( done && (*out != NOMAPPING));
  143. }
  144. /*=================================================================================
  145.  
  146. =================================================================================*/
  147. MODULE_PRIVATE void        uMapIterate(uTable *uTable, uMapIterateFunc callback, uint16 context)
  148. {
  149.     uint16 itemOfList = uTable->itemOfList;
  150.     uint16 i;
  151.     for(i=0;i<itemOfList;i++)
  152.     {
  153.         uMapCell* uCell;
  154.         char format = uGetFormat(uTable,i);
  155.         uCell = uGetMapCell(uTable,i);
  156.         uCellIterate(format, uTable ,uCell,callback, context);
  157.     }
  158. }
  159.  
  160. /*
  161.     member function
  162. */
  163. /*=================================================================================
  164.  
  165. =================================================================================*/
  166. PRIVATE XP_Bool uHitFormate0(uint16 in,uMapCell *cell)
  167. {
  168.     return ( (in >= cell->fmt.format0.srcBegin) &&
  169.                  (in <= cell->fmt.format0.srcEnd) ) ;
  170. }
  171. /*=================================================================================
  172.  
  173. =================================================================================*/
  174. PRIVATE XP_Bool uHitFormate1(uint16 in,uMapCell *cell)
  175. {
  176.     return  uHitFormate0(in,cell);
  177. }
  178. /*=================================================================================
  179.  
  180. =================================================================================*/
  181. PRIVATE XP_Bool uHitFormate2(uint16 in,uMapCell *cell)
  182. {
  183.     return (in == cell->fmt.format2.srcBegin);
  184. }
  185. /*=================================================================================
  186.  
  187. =================================================================================*/
  188. PRIVATE uint16 uMapFormate0(uint16 in,uTable *uTable,uMapCell *cell)
  189. {
  190.     return ((in - cell->fmt.format0.srcBegin) + cell->fmt.format0.destBegin);
  191. }
  192. /*=================================================================================
  193.  
  194. =================================================================================*/
  195. PRIVATE uint16 uMapFormate1(uint16 in,uTable *uTable,uMapCell *cell)
  196. {
  197.     return (*(((uint16 *)uTable) + uTable->offsetToMappingTable
  198.         + cell->fmt.format1.mappingOffset + in - cell->fmt.format1.srcBegin));
  199. }
  200. /*=================================================================================
  201.  
  202. =================================================================================*/
  203. PRIVATE uint16 uMapFormate2(uint16 in,uTable *uTable,uMapCell *cell)
  204. {
  205.     return (cell->fmt.format2.destBegin);
  206. }
  207.  
  208. /*=================================================================================
  209.  
  210. =================================================================================*/
  211. PRIVATE void uIterateFormate0(uTable *uTable, uMapCell *cell,uMapIterateFunc callback, uint16 context)
  212. {
  213.     uint16 ucs2;
  214.     uint16 med;
  215.     for(ucs2 = cell->fmt.format0.srcBegin, med = cell->fmt.format0.destBegin;
  216.                 ucs2 <= cell->fmt.format0.srcEnd ; ucs2++,med++)
  217.         (*callback)(ucs2, med, context);
  218. }
  219. /*=================================================================================
  220.  
  221. =================================================================================*/
  222. PRIVATE void uIterateFormate1(uTable *uTable, uMapCell *cell,uMapIterateFunc callback, uint16 context)
  223. {
  224.     uint16 ucs2;
  225.     uint16 *medpt;
  226.     medpt = (((uint16 *)uTable) + uTable->offsetToMappingTable    + cell->fmt.format1.mappingOffset);
  227.     for(ucs2 = cell->fmt.format1.srcBegin;    ucs2 <= cell->fmt.format1.srcEnd ; ucs2++, medpt++)
  228.         (*callback)(ucs2, *medpt, context);
  229. }
  230. /*=================================================================================
  231.  
  232. =================================================================================*/
  233. PRIVATE void uIterateFormate2(uTable *uTable, uMapCell *cell,uMapIterateFunc callback, uint16 context)
  234. {
  235.     (*callback)(cell->fmt.format2.srcBegin, cell->fmt.format2.destBegin, context);
  236. }
  237.