Back to index

lightning-sunbird  0.9+nobinonly
umap.c
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   jeroen.dobbelaere@acunia.com
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 /* #include "PRIntlpriv.h" */
00039 #include "unicpriv.h" 
00040 
00041 
00042 typedef PRUint16 (* MapFormatFunc)(PRUint16 in,const uTable *uT,const uMapCell *cell);
00043 typedef PRBool (* HitFormateFunc)(PRUint16 in,const uMapCell *cell);
00044 typedef void (* FillInfoFormateFunc)(const uTable *uT, const uMapCell *cell, PRUint32* info);
00045 
00046 
00047 PRIVATE PRBool uHitFormate0(PRUint16 in,const uMapCell *cell);
00048 PRIVATE PRBool uHitFormate2(PRUint16 in,const uMapCell *cell);
00049 PRIVATE PRUint16 uMapFormate0(PRUint16 in,const uTable *uT,const uMapCell *cell);
00050 PRIVATE PRUint16 uMapFormate1(PRUint16 in,const uTable *uT,const uMapCell *cell);
00051 PRIVATE PRUint16 uMapFormate2(PRUint16 in,const uTable *uT,const uMapCell *cell);
00052 PRIVATE void uFillInfoFormate0(const uTable *uT,const uMapCell *cell,PRUint32* aInfo);
00053 PRIVATE void uFillInfoFormate1(const uTable *uT,const uMapCell *cell,PRUint32* aInfo);
00054 PRIVATE void uFillInfoFormate2(const uTable *uT,const uMapCell *cell,PRUint32* aInfo);
00055 
00056 
00057 PRIVATE const uMapCell *uGetMapCell(const uTable *uT, PRInt16 item);
00058 PRIVATE char uGetFormat(const uTable *uT, PRInt16 item);
00059 
00060 
00061 /*=================================================================================
00062 
00063 =================================================================================*/
00064 PRIVATE const MapFormatFunc m_map[uNumFormatTag] =
00065 {
00066     uMapFormate0,
00067     uMapFormate1,
00068     uMapFormate2,
00069 };
00070 
00071 /*=================================================================================
00072 
00073 =================================================================================*/
00074 PRIVATE const FillInfoFormateFunc m_fillinfo[uNumFormatTag] =
00075 {
00076     uFillInfoFormate0,
00077     uFillInfoFormate1,
00078     uFillInfoFormate2,
00079 };
00080 
00081 /*=================================================================================
00082 
00083 =================================================================================*/
00084 PRIVATE const HitFormateFunc m_hit[uNumFormatTag] =
00085 {
00086     uHitFormate0,
00087     uHitFormate0,
00088     uHitFormate2,
00089 };
00090 
00091 #define uHit(format,in,cell)   (* m_hit[(format)])((in),(cell))
00092 #define uMap(format,in,uT,cell)  (* m_map[(format)])((in),(uT),(cell))
00093 #define uFillInfoCell(format,uT,cell,info)  (* m_fillinfo[(format)])((uT),(cell),(info))
00094 #define uGetMapCell(uT, item) ((uMapCell *)(((PRUint16 *)uT) + (uT)->offsetToMapCellArray + (item)*(UMAPCELL_SIZE/sizeof(PRUint16))))
00095 #define uGetFormat(uT, item) (((((PRUint16 *)uT) + (uT)->offsetToFormatArray)[(item)>> 2 ] >> (((item)% 4 ) << 2)) & 0x0f)
00096 
00097 /*=================================================================================
00098 
00099 =================================================================================*/
00100 MODULE_PRIVATE void uFillInfo(const uTable *uT, PRUint32* aInfo)
00101 {
00102   PRUint16 itemOfList = uT->itemOfList;
00103   PRUint16 i;
00104   for(i=0;i<itemOfList;i++)
00105   {
00106     const uMapCell* uCell;
00107     PRInt8 format = uGetFormat(uT,i);
00108     uCell = uGetMapCell(uT,i);
00109     uFillInfoCell(format, uT, uCell, aInfo);
00110   }
00111 }
00112 /*=================================================================================
00113 
00114 =================================================================================*/
00115 MODULE_PRIVATE PRBool uMapCode(const uTable *uT, PRUint16 in, PRUint16* out)
00116 {
00117   PRBool done = PR_FALSE;
00118   PRUint16 itemOfList = uT->itemOfList;
00119   PRUint16 i;
00120   *out = NOMAPPING;
00121   for(i=0;i<itemOfList;i++)
00122   {
00123     const uMapCell* uCell;
00124     PRInt8 format = uGetFormat(uT,i);
00125     uCell = uGetMapCell(uT,i);
00126     if(uHit(format, in, uCell))
00127     {
00128       *out = uMap(format, in, uT,uCell);
00129       done = PR_TRUE;
00130       break;
00131     }
00132   }
00133   return ( done && (*out != NOMAPPING));
00134 }
00135 
00136 
00137 /*
00138 member function
00139 */
00140 /*=================================================================================
00141 
00142 =================================================================================*/
00143 PRIVATE PRBool uHitFormate0(PRUint16 in,const uMapCell *cell)
00144 {
00145   return ( (in >= cell->fmt.format0.srcBegin) &&
00146     (in <= cell->fmt.format0.srcEnd) ) ;
00147 }
00148 /*=================================================================================
00149 
00150 =================================================================================*/
00151 PRIVATE PRBool uHitFormate2(PRUint16 in,const uMapCell *cell)
00152 {
00153   return (in == cell->fmt.format2.srcBegin);
00154 }
00155 /*=================================================================================
00156 
00157 =================================================================================*/
00158 PRIVATE PRUint16 uMapFormate0(PRUint16 in,const uTable *uT,const uMapCell *cell)
00159 {
00160   return ((in - cell->fmt.format0.srcBegin) + cell->fmt.format0.destBegin);
00161 }
00162 /*=================================================================================
00163 
00164 =================================================================================*/
00165 PRIVATE PRUint16 uMapFormate1(PRUint16 in,const uTable *uT,const uMapCell *cell)
00166 {
00167   return (*(((PRUint16 *)uT) + uT->offsetToMappingTable
00168     + cell->fmt.format1.mappingOffset + in - cell->fmt.format1.srcBegin));
00169 }
00170 /*=================================================================================
00171 
00172 =================================================================================*/
00173 PRIVATE PRUint16 uMapFormate2(PRUint16 in,const uTable *uT,const uMapCell *cell)
00174 {
00175   return (cell->fmt.format2.destBegin);
00176 }
00177 
00178 #define SET_REPRESENTABLE(info, c)  (info)[(c) >> 5] |= (1L << ((c) & 0x1f))
00179 /*=================================================================================
00180 
00181 =================================================================================*/
00182 PRIVATE void uFillInfoFormate0(const uTable *uT,const uMapCell *cell,PRUint32* info)
00183 {
00184   PRUint16 begin, end, i;
00185   begin = cell->fmt.format0.srcBegin;
00186   end = cell->fmt.format0.srcEnd;
00187   if( (begin >> 5) == (end >> 5)) /* High 17 bits are the same */
00188   {
00189     for(i = begin; i <= end; i++)
00190       SET_REPRESENTABLE(info, i);
00191   } 
00192   else {
00193     PRUint32 b = begin >> 5;
00194     PRUint32 e = end >> 5;
00195     info[ b ] |= (0xFFFFFFFFL << ((begin) & 0x1f)); 
00196     info[ e ] |= (0xFFFFFFFFL >> (31 - ((end) & 0x1f)));
00197     for(b++ ; b < e ; b++)
00198       info[b] |= 0xFFFFFFFFL;
00199   }
00200 }
00201 /*=================================================================================
00202 
00203 =================================================================================*/
00204 PRIVATE void uFillInfoFormate1(const uTable *uT,const uMapCell *cell,PRUint32* info)
00205 {
00206   PRUint16 begin, end, i;
00207   PRUint16 *base;
00208   begin = cell->fmt.format0.srcBegin;
00209   end = cell->fmt.format0.srcEnd;
00210   base = (((PRUint16 *)uT) + uT->offsetToMappingTable + cell->fmt.format1.mappingOffset);
00211   for(i = begin; i <= end; i++) 
00212   {
00213     if(0xFFFD != base[i - begin])  /* check every item */
00214       SET_REPRESENTABLE(info, i);
00215   }
00216 }
00217 /*=================================================================================
00218 
00219 =================================================================================*/
00220 PRIVATE void uFillInfoFormate2(const uTable *uT,const uMapCell *cell,PRUint32* info)
00221 {
00222   SET_REPRESENTABLE(info, cell->fmt.format2.srcBegin);
00223 }
00224