Back to index

im-sdk  12.3.91
CikuOper.c
Go to the documentation of this file.
00001 /*
00002 Copyright 1990-2001 Sun Microsystems, Inc. All Rights Reserved.
00003 
00004 Permission is hereby granted, free of charge, to any person obtaining a
00005 copy of this software and associated documentation files (the
00006 "Software"), to deal in the Software without restriction, including
00007 without limitation the rights to use, copy, modify, merge, publish,
00008 distribute, sublicense, and/or sell copies of the Software, and to
00009 permit persons to whom the Software is furnished to do so, subject to
00010 the following conditions: The above copyright notice and this
00011 permission notice shall be included in all copies or substantial
00012 portions of the Software.
00013 
00014 
00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00016 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00017 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00018 IN NO EVENT SHALL THE OPEN GROUP OR SUN MICROSYSTEMS, INC. BE LIABLE
00019 FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
00020 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
00021 THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE EVEN IF
00022 ADVISED IN ADVANCE OF THE POSSIBILITY OF SUCH DAMAGES.
00023 
00024 
00025 Except as contained in this notice, the names of The Open Group and/or
00026 Sun Microsystems, Inc. shall not be used in advertising or otherwise to
00027 promote the sale, use or other dealings in this Software without prior
00028 written authorization from The Open Group and/or Sun Microsystems,
00029 Inc., as applicable.
00030 
00031 
00032 X Window System is a trademark of The Open Group
00033 
00034 OSF/1, OSF/Motif and Motif are registered trademarks, and OSF, the OSF
00035 logo, LBX, X Window System, and Xinerama are trademarks of the Open
00036 Group. All other trademarks and registered trademarks mentioned herein
00037 are the property of their respective owners. No right, title or
00038 interest in or to any trademark, service mark, logo or trade name of
00039 Sun Microsystems, Inc. or its licensors is granted.
00040 
00041 */
00042 #include "PYIM.h"
00043 
00044 /* Jword.c */
00045 JINT    GbkHz2244ToYjSM(JINT nHzcode);
00046 JINT    GbkHz2244ToYj(JINT nHzcode);
00047 UCHAR*  RecovDyz2244(UCHAR *szDyz2244);
00048 VOID    Jword2Uchar(JWORD* pwJword, UCHAR* szUch, JINT nMaxLen);
00049 VOID    JwordNCpy(JWORD* pwDst, JWORD* pwSrc, JINT nLen);
00050 JINT    JwordValidLen(JWORD* pwJwordArray, JINT nMaxLen);
00051 JINT    JwordHanziLen(JWORD* pwJwordArray, JINT nMaxLen);
00052 JINT    JwordNCmp(JWORD* pwSrc1, JWORD* pwSrc2, JINT nNum);
00053 JINT    IsGbkkkHz(JWORD wHz);
00054 
00055 JINT    GetCikuData(CHAR* szSysCikuName);
00056 JINT    WriteCikuData(CHAR* szSysCikuName, JINT nTimeStamp);
00057 JINT    EnumCandi(JINT* pnOrgYj, JINT nLenYj, SysCandi* psc, UdcCandi* puc, JINT* pnSize, JINT nMatchMode, JINT nMode);
00058 VOID    InitStructSc(SysCandi* psc);
00059 VOID    InitStructUc(UdcCandi* puc);
00060 JINT    LookupCiku(JINT* pnOrgYj, JINT nLenYj, JINT nMatchMode, SysCandi* psc, UdcCandi* puc);
00061 VOID    SortCandi(SysCandi* psc, UdcCandi* puc);
00062 VOID    AdjustFreq(JWORD* pwHz2244, JINT nLenThis);
00063 JINT    IsCizuExist(JWORD* pwHz2244, JINT nLenThis);
00064 JINT    IsGbkkkHz(JWORD wHz);
00065 
00066 VOID    WarpByte(VOID* pv, JINT n);
00067 VOID    WarpIndex(ShIndex* pInt419);
00068 VOID    WarpCikuHeader(CikuHeader* pCh);
00069 
00070 BYTE   *pCkAll = NULL;
00071 extern  UdcMemAll  udcAll;
00072 
00073 CHAR      szLocale[10] = "zh.GBK";
00074 
00075 /*
00076 **  Warp 4 Bytes or Warp 2 Bytes.
00077 **  Because SPARC and Intel x86 have different byte order.
00078 */
00079 VOID WarpByte(VOID* pv, JINT n)
00080 {
00081        JINT    nInt;
00082        JWORD   wWord;
00083        
00084        nInt = wWord = 0;
00085        if (n == 4)
00086        {
00087               nInt = *((JINT*)pv);
00088               *((JINT*)pv) = ((nInt & 0x000000FF) << 24) + ((nInt & 0x0000FF00) << 8) +
00089                              ((nInt & 0xFF000000) >> 24) + ((nInt & 0x00FF0000) >> 8);
00090        }
00091        else if (n == 2)
00092        {
00093               wWord = *((JWORD*)pv);
00094               *((JWORD*)pv) = (JWORD)( ((wWord & 0x00FF) << 8) + ((wWord & 0xFF00) >> 8) );
00095        }
00096        else
00097               return;
00098 }
00099 
00100 /*
00101 **  Both CikuHeader and UdCikuHeader have same structure.
00102 */
00103 VOID WarpCikuHeader(CikuHeader* pCh)
00104 {
00105        JINT    i;
00106        
00107        for (i = 0; i < 4; i++)
00108        {
00109               WarpByte( (VOID*)((JINT*)pCh + i), 4);
00110        }
00111        
00112        for (i = 24; i < 32; i++)
00113        {
00114               WarpByte( (VOID*)((JINT*)pCh + i), 4);
00115        }
00116 }
00117 
00118 /*
00119 **  All ShIndex, DhIndex, MhIndex, GbkIndex and UdcIndex have same structure.
00120 */
00121 VOID WarpIndex(ShIndex* pInt419)
00122 {
00123        JINT    i;
00124        
00125        for (i = 0; i < 419; i++)
00126        {
00127               WarpByte( (VOID*)((JINT*)pInt419 + i), 4);
00128        }
00129 }
00130 
00131 
00132 /*
00133 **  Read out all those data in System Ciku file to pCkAll.
00134 */
00135 JINT GetCikuData(CHAR* szSysCikuName)
00136 {
00137        FILE*   pfCiku;
00138        JINT    i, k;
00139        JINT    nFileSize;
00140        JINT    nWarpFlag;     /* Flag to indicate whether it is necessary to */
00141        
00142        CikuHeader  *pCkh;
00143        ShIndex     *pShi;
00144        DhIndex     *pDhi;
00145        MhIndex     *pMhi;
00146        GbkIndex    *pGbki;
00147        BYTE        *pShArea;
00148        BYTE        *pDhArea;
00149        BYTE        *pMhArea;
00150        BYTE        *pGbkArea;
00151        
00152        nWarpFlag = FALSE;
00153        
00154        pfCiku = fopen(szSysCikuName, "rb");
00155        if (pfCiku == NULL)
00156        {
00157               return FALSE;
00158        }
00159        
00160        pCkh = (CikuHeader*)malloc(sizeof(CikuHeader));
00161        if (pCkh == NULL)
00162        {
00163               return FALSE;
00164        }
00165        
00166        fseek(pfCiku, 0, SEEK_SET);
00167        if (fread (pCkh, 1, sizeof(CikuHeader), pfCiku) != sizeof(CikuHeader) )
00168        {
00169               return FALSE;
00170        }
00171        
00172        /* Check Magic Word in Header */
00173        if ((pCkh->nMagicDescHi != 0x35303539) || (pCkh->nMagicDescLow != 0x34333442))
00174        {
00175               /* Is SPARC or x86 File? */
00176               if ((pCkh->nMagicDescHi == 0x39353035) && (pCkh->nMagicDescLow == 0x42343334))
00177               {
00178                      nWarpFlag = TRUE;
00179               }
00180               else
00181                      return FALSE;
00182        }
00183        
00184        if (nWarpFlag == TRUE)
00185               WarpCikuHeader(pCkh);
00186        
00187        nFileSize = pCkh->nFileSize;
00188        
00189        fseek(pfCiku, 0, SEEK_END);
00190        if (nFileSize != ftell(pfCiku))
00191        {
00192               return FALSE;
00193        }
00194        
00195        free(pCkh);
00196        pCkh = NULL;
00197        
00198        pCkAll = (BYTE*)malloc(nFileSize);
00199        if (pCkAll == NULL)
00200        {
00201               fprintf(stderr, "Failed to malloc() for pCkAll in GetCikuInfo.\n");
00202               return FALSE;
00203        }
00204        
00205        fseek(pfCiku, 0, SEEK_SET);
00206        if ((JINT)fread (pCkAll, 1, nFileSize, pfCiku) != nFileSize )
00207        {
00208               fprintf(stderr, "Failed to fread() System Ciku File.\n");
00209               return FALSE;
00210        }
00211        fclose(pfCiku);
00212        
00213        pCkh     = (CikuHeader *)pCkAll;
00214        if (nWarpFlag == TRUE)
00215               WarpCikuHeader(pCkh);
00216 
00217        pShi     = (ShIndex  *)(pCkAll + pCkh->nIdxShPos);
00218        pDhi     = (DhIndex  *)(pCkAll + pCkh->nIdxDhPos);
00219        pMhi     = (MhIndex  *)(pCkAll + pCkh->nIdxMhPos);
00220        pGbki    = (GbkIndex *)(pCkAll + pCkh->nIdxGbkPos);
00221        
00222        if (nWarpFlag == TRUE)
00223        {
00224               WarpIndex((ShIndex *)pShi);
00225               WarpIndex((ShIndex *)pDhi);
00226               WarpIndex((ShIndex *)pMhi);
00227               WarpIndex((ShIndex *)pGbki);
00228        }
00229        
00230        pShArea  = (BYTE *)(pCkAll + pShi->nStartPos);
00231        pDhArea  = (BYTE *)(pCkAll + pDhi->nStartPos);
00232        pMhArea  = (BYTE *)(pCkAll + pMhi->nStartPos);
00233        pGbkArea = (BYTE *)(pCkAll + pGbki->nStartPos);
00234        
00235        for(i = 0; i < NUM_YINJIE; i++)
00236               for(k = (pShi->nYjOff[i] & 0x00FFFFFF); k < (pShi->nYjOff[i + 1] & 0x00FFFFFF); k++)
00237                      *(pShArea + k) ^= (BYTE)((i + 56) / 2);
00238 
00239        for(i = 0; i < NUM_YINJIE; i++)
00240               for(k = pDhi->nYjOff[i]; k < pDhi->nYjOff[i + 1]; k++)
00241                      *(pDhArea + k) ^= (BYTE)((i + 56) / 2);
00242 
00243        for(i = 0; i < NUM_YINJIE; i++)
00244               for(k = pMhi->nYjOff[i]; k < pMhi->nYjOff[i + 1]; k++)
00245                      *(pMhArea + k) ^= (BYTE)((i + 56) / 2);
00246 
00247        for(i = 0; i < NUM_YINJIE; i++)
00248               for(k = pGbki->nYjOff[i]; k < pGbki->nYjOff[i + 1]; k++)
00249                      *(pGbkArea + k) ^= (BYTE)((i + 56) / 2);
00250 
00251        return TRUE;
00252 }
00253 
00254 
00255 JINT WriteCikuData(CHAR* szSysCikuName, JINT nTimeStamp)
00256 {
00257        FILE*   pfCiku;
00258        JINT    i, k;
00259        JINT    nFileSize, nTmp;
00260        
00261        CikuHeader  *pCkh;
00262        ShIndex     *pShi;
00263        DhIndex     *pDhi;
00264        MhIndex     *pMhi;
00265        GbkIndex    *pGbki;
00266        BYTE        *pShArea;
00267        BYTE        *pDhArea;
00268        BYTE        *pMhArea;
00269        BYTE        *pGbkArea;
00270 
00271        pCkh     = (CikuHeader *)pCkAll;
00272        pShi     = (ShIndex  *)(pCkAll + pCkh->nIdxShPos);
00273        pDhi     = (DhIndex  *)(pCkAll + pCkh->nIdxDhPos);
00274        pMhi     = (MhIndex  *)(pCkAll + pCkh->nIdxMhPos);
00275        pGbki    = (GbkIndex *)(pCkAll + pCkh->nIdxGbkPos);
00276        
00277        pShArea  = (BYTE *)(pCkAll + pShi->nStartPos);
00278        pDhArea  = (BYTE *)(pCkAll + pDhi->nStartPos);
00279        pMhArea  = (BYTE *)(pCkAll + pMhi->nStartPos);
00280        pGbkArea = (BYTE *)(pCkAll + pGbki->nStartPos);
00281        
00282        pCkh->nLatestTime = nTimeStamp;
00283        
00284        /* Write These data back to file */
00285        pfCiku = fopen(szSysCikuName, "wb");
00286        if (pfCiku == NULL)
00287        {
00288               fprintf(stderr, "Failed to Create System Ciku File: %s\n", szSysCikuName);
00289               return FALSE;
00290        }
00291        
00292        for(i = 0; i < NUM_YINJIE; i++)
00293               for(k = (pShi->nYjOff[i] & 0x00FFFFFF); k < (pShi->nYjOff[i + 1] & 0x00FFFFFF); k++)
00294                      *(pShArea + k) ^= (BYTE)((i + 56) / 2);
00295 
00296        for(i = 0; i < NUM_YINJIE; i++)
00297               for(k = pDhi->nYjOff[i]; k < pDhi->nYjOff[i + 1]; k++)
00298                      *(pDhArea + k) ^= (BYTE)((i + 56) / 2);
00299 
00300        for(i = 0; i < NUM_YINJIE; i++)
00301               for(k = pMhi->nYjOff[i]; k < pMhi->nYjOff[i + 1]; k++)
00302                      *(pMhArea + k) ^= (BYTE)((i + 56) / 2);
00303        
00304        for(i = 0; i < NUM_YINJIE; i++)
00305               for(k = pGbki->nYjOff[i]; k < pGbki->nYjOff[i + 1]; k++)
00306                      *(pGbkArea + k) ^= (BYTE)((i + 56) / 2);
00307 
00308        nFileSize = pCkh->nFileSize;
00309 
00310        fseek(pfCiku, 0, SEEK_SET);
00311        nTmp = (JINT)fwrite (pCkAll, nFileSize, 1, pfCiku);
00312        
00313        for(i = 0; i < NUM_YINJIE; i++)
00314               for(k = (pShi->nYjOff[i] & 0x00FFFFFF); k < (pShi->nYjOff[i + 1] & 0x00FFFFFF); k++)
00315                      *(pShArea + k) ^= (BYTE)((i + 56) / 2);
00316 
00317        for(i = 0; i < NUM_YINJIE; i++)
00318               for(k = pDhi->nYjOff[i]; k < pDhi->nYjOff[i + 1]; k++)
00319                      *(pDhArea + k) ^= (BYTE)((i + 56) / 2);
00320 
00321        for(i = 0; i < NUM_YINJIE; i++)
00322               for(k = pMhi->nYjOff[i]; k < pMhi->nYjOff[i + 1]; k++)
00323                      *(pMhArea + k) ^= (BYTE)((i + 56) / 2);
00324        
00325        for(i = 0; i < NUM_YINJIE; i++)
00326               for(k = pGbki->nYjOff[i]; k < pGbki->nYjOff[i + 1]; k++)
00327                      *(pGbkArea + k) ^= (BYTE)((i + 56) / 2);
00328 
00329        if (nTmp != 1)
00330        {
00331               fprintf(stderr, "Failed to fwrite() System Ciku File.\n");
00332               return FALSE;
00333        }
00334        
00335        fclose (pfCiku);
00336        return TRUE;
00337 }
00338 
00339 
00340 /*
00341 **  Free the memory alloc to pCkAll
00342 */
00343 VOID FreePckAll()
00344 {
00345        free(pCkAll);
00346        pCkAll = NULL;
00347 }
00348 
00349 
00350 /*  
00351 **  pnSize:     If nMode is LU_CANDI_CALC, Calculate the size need totally to contain all those SysCandis,
00352 **              and set nNumShCandi, nNumDhCandi, nNumMhCandi, nSizShCandi, nSizDhCandi, nSizMhCandi of struct psc.
00353 **              [pnSize is in JWORD]
00354 **
00355 **  nMatchMode: LU_MATCH_STRICT   ==> Match Strictly. Used by nLenYj >= 5. Condition: nCzLen == nLenYj  
00356 **              LU_MATCH_WIDELY   ==> Match Widely.   Used by nLenYj >= 5. Condition: nCzLen >= nLenYj
00357 **              Condition for LU_MATCH_WIDLY:
00358 **                        zhong hua ren min gong // zhong hua ren min gong h  // zhong hua ren min gong he
00359 **              Condition for LU_MATCH_STRICT:  => Last YjString is unmatched and meanless.
00360 **                        zhong hua ren min gong [go gon cho chon cua]
00361 **
00362 **  nMode:      LU_CANDI_WRITE ==> Write all those SysCandis to allocated memory for Sh, Dh, Mh Candidates.
00363 **              LU_CANDI_CALC  ==> Calculate the space size which needed to contain all those SysCandis.
00364 **
00365 **  NOTES:      Structure psc was filled after two calling of this function: First in Mode LU_CANDI_CALC,
00366 **              second in Mode LU_CANDI_WRITE.
00367 **
00368 **  CONTENTS OF pwMhCandi + pwDhCandi + pwShCandi + pwGbkCandi + pwSpecCandi + pwUdc28Candi
00369 **             Mh:    fhhhhhh0fhhh0fhhhh0
00370 **             Dh:    fhh0fhh0fhh0fhh0fhh0fhh0fhh0fhh0fhh0fhh0fhh0fhh0
00371 **             Sh:    XX0XX0h0h0h0h0h0h0h0h0h0h0h0 + 0     OR
00372 **                    Q0Q0Q0Q0Q0Q0Q0h0h0h0h0h0h0h0h0 + 0
00373 **             Gbk:   h0h0h0h0h0h0h0h0
00374 **             Spec:  In ucUdcCandi->pwSpecCandi[6]
00375 **             Udc28: fhhhh0fhhhhhh0fhh0
00376 **             Notes:  f  ==> JWORD of Frequence and Length
00377 **                     h  ==> JWORD of a Single Hanzi
00378 **                     XX ==> JWORDs of Xian Form Candi
00379 **                     Q  ==> JWORD of High frequence Hanzi of a Specified Yinjie ShengMu, Ex, Q->7
00380 **                            "可开空口科克看"
00381 **
00382 */
00383 JINT EnumCandi(JINT* pnOrgYj, JINT nLenYj, SysCandi* psc, UdcCandi* puc, JINT* pnSize, JINT nMatchMode, JINT nMode)
00384 {
00385        JINT    nFromOff, nToOff;
00386        JINT    nFromYj, nToYj, nXianNum;         /* For Single Hanzi Area Searching */
00387        UCHAR   chHi, chLow;                      /* For Single Hanzi Area Searching */
00388        JINT    nCzLen, i, m, k, nTmp;
00389        JWORD   wCzHz[10], wMhLenFreq, wDhFreq;
00390        JINT    nEqualFlag;
00391        CHAR    *pszYj1, *pszYj2;                 /* For DhCandi, compare string directly */
00392        CHAR    szYj3[14], szYj4[14];
00393        JINT    nfGbkCizu;
00394 
00395        /* Definition for puc */
00396        JINT    nCurSize;
00397        JINT    nUdc28FreqLen, nUdc28Len;
00398 
00399        CikuHeader  *pCkh;
00400        ShIndex     *pShi;
00401        DhIndex     *pDhi;
00402        MhIndex     *pMhi;
00403        GbkIndex    *pGbki;
00404        BYTE        *pShArea;
00405        BYTE        *pDhArea;
00406        BYTE        *pMhArea;
00407        BYTE        *pGbkArea;
00408 
00409        pCkh     = (CikuHeader *)pCkAll;
00410        pShi     = (ShIndex  *)(pCkAll + pCkh->nIdxShPos);
00411        pDhi     = (DhIndex  *)(pCkAll + pCkh->nIdxDhPos);
00412        pMhi     = (MhIndex  *)(pCkAll + pCkh->nIdxMhPos);
00413        pGbki    = (GbkIndex *)(pCkAll + pCkh->nIdxGbkPos);
00414        
00415        pShArea  = (BYTE *)(pCkAll + pShi->nStartPos);
00416        pDhArea  = (BYTE *)(pCkAll + pDhi->nStartPos);
00417        pMhArea  = (BYTE *)(pCkAll + pMhi->nStartPos);
00418        pGbkArea = (BYTE *)(pCkAll + pGbki->nStartPos);
00419 
00420        *pnSize  = 0;
00421        if (nMode == LU_CANDI_WRITE)
00422        {
00423               psc->nSizMhCandi  = 0;
00424               psc->nSizDhCandi  = 0;
00425               psc->nSizShCandi  = 0;
00426               psc->nSizGbkCandi = 0;
00427                      
00428               psc->nNumMhCandi  = 0;
00429               psc->nNumDhCandi  = 0;
00430               psc->nNumShCandi  = 0;
00431               psc->nNumGbkCandi = 0;
00432 
00433               puc->nNumSpecCandi  = 0;
00434               puc->nNumUdc28Candi = 0;
00435               puc->nSizUdc28Candi = 0;
00436        }
00437 
00438        if (nLenYj >= 3)
00439        {
00440               /*
00441               **  Determine the FromOff and ToOff which to used for searching by the pnOrgYj[0].
00442               */
00443               if ((pnOrgYj[0] >= 0) && (pnOrgYj[0] < NUM_YINJIE))
00444               {
00445                      nFromOff = pMhi->nYjOff[ pnOrgYj[0] ];
00446                      nToOff   = pMhi->nYjOff[ pnOrgYj[0] + 1];
00447               }
00448               else   /* ((pnOrgYj[0] >= 450) && (pnOrgYj[0] <= 475)) */
00449               {
00450                      nFromOff = pMhi->nYjOff[ INDEXSMTOYINJIE[pnOrgYj[0] - 450] ];
00451                      nToOff   = pMhi->nYjOff[ INDEXSMTOYINJIE[pnOrgYj[0] - 450 + 1] ];
00452               }
00453               
00454               /* !! DON'T add k++ in this FOR sentence !! */
00455               for (k = nFromOff; k < nToOff; )
00456               {
00457                      wMhLenFreq = (JWORD)*(pMhArea + k);
00458                      nCzLen     = 2 + ((UCHAR)*(pMhArea + k) & 0x07);
00459                      k++;
00460                      
00461                      for (m = 0; m < 10; m++)
00462                             wCzHz[m]   = 0x0000;
00463                      for (m = 0; m < nCzLen; m++)
00464                      {
00465                             wCzHz[m]   = (JWORD)(*(pMhArea + k + 1) + ((*(pMhArea + k)) << 8));
00466                             k += 2;
00467                      }
00468                      
00469                      /*
00470                      ** DON'T CONVERT wCzItem into YJSTRING and CALL ParsePreedit() HERE, BECAUSE THAT
00471                      ** IS TOO COMPLEX AND UN_LOGICALLY.
00472                      ** For Example, zai xian shi qu ==> zai xi'an shi qu [Four ~ Five !!!!]
00473                      */
00474 
00475                      nEqualFlag = FALSE;
00476                      if (( (nLenYj <= 4) && (nCzLen <= nLenYj) ) || 
00477                          ( (nLenYj >= 5) && (nMatchMode == LU_MATCH_WIDELY) ) || 
00478                          ( (nLenYj >= 5) && (nMatchMode == LU_MATCH_STRICT) && (nCzLen <= nLenYj) )  )
00479                      {
00480                             nEqualFlag = TRUE;
00481                             
00482                             for(m = 0; m < _MIN(nLenYj, nCzLen); m++)
00483                                    if ( ( pnOrgYj[m] != GbkHz2244ToYjSM((JINT)wCzHz[m]) ) &&                    \
00484                                         ( pnOrgYj[m] != GbkHz2244ToYj((JINT)wCzHz[m])   ) )
00485                                    {
00486                                           nEqualFlag = FALSE;
00487                                           break;
00488                                    }
00489                      }
00490                      
00491                      if ((nEqualFlag == TRUE) && (nMode == LU_CANDI_CALC))
00492                      {
00493                             psc->nSizMhCandi += (nCzLen + 2);  /* Add two JWORD Here to contain Freq&Len Word and a ZERO */
00494                             psc->nNumMhCandi += 1;
00495                             *pnSize += (nCzLen + 2);
00496                      }
00497                      else if ((nEqualFlag == TRUE) && (nMode == LU_CANDI_WRITE))
00498                      {
00499                             psc->pwMhCandi[psc->nSizMhCandi] = wMhLenFreq;
00500                             for (m = 0; m < nCzLen; m++)
00501                                    psc->pwMhCandi[psc->nSizMhCandi + m + 1] = wCzHz[m];
00502                             
00503                             psc->nSizMhCandi += (nCzLen + 2);
00504                             psc->nNumMhCandi += 1;
00505                             *pnSize += (nCzLen + 2);
00506                      }
00507               }
00508        }
00509        
00510 
00511        if (nLenYj >= 2)
00512        {
00513               /*
00514               **  Determine the FromOff and ToOff which to used for searching by the pnOrgYj[0].
00515               */
00516               if ((pnOrgYj[0] >= 0) && (pnOrgYj[0] < NUM_YINJIE))
00517               {
00518                      nFromOff = pDhi->nYjOff[ pnOrgYj[0] ];
00519                      nToOff   = pDhi->nYjOff[ pnOrgYj[0] + 1];
00520               }
00521               else /* ((pnOrgYj[0] >= 450) && (pnOrgYj[0] <= 475)) */
00522               {
00523                      nFromOff = pDhi->nYjOff[ INDEXSMTOYINJIE[pnOrgYj[0] - 450] ];
00524                      nToOff   = pDhi->nYjOff[ INDEXSMTOYINJIE[pnOrgYj[0] - 450 + 1] ];
00525               }
00526        
00527               /* !! DON'T add k++ in this FOR sentence !! */
00528               for (k = nFromOff; k < nToOff; )
00529               {
00530                      wDhFreq  = (JWORD)*(pDhArea + k);
00531                      nCzLen   = 2;
00532                      k ++;
00533 
00534                      for (m = 0; m < 10; m++)
00535                             wCzHz[m]   = 0x0000;
00536                      for (m = 0; m < nCzLen; m++)
00537                      {
00538                             wCzHz[m]   = (JWORD)(*(pDhArea + k + 1) + ((*(pDhArea + k)) << 8));
00539                             k += 2;
00540                      }
00541 
00542                      for (m = 0; m < 14; m++)
00543                      {
00544                             szYj3[m]   = '\0';
00545                             szYj4[m]   = '\0';
00546                      }
00547                      
00548                      if ((pnOrgYj[0] >= 450) && (pnOrgYj[0] <= 475))
00549                             pszYj1 = SHENGMUSTR[ pnOrgYj[0] - 450 ];
00550                      else
00551                             /* Rewrite this line to proc [fangan] ==> [fan gan] and [fang an]. Scott Ma 98-05-12 */
00552                             /* pszYj1 = YINJIESTR_CSZ[ pnOrgYj[0] ];  */
00553                             pszYj1 = YINJIESTR_CSZ[ GbkHz2244ToYj((JINT)wCzHz[0]) ];
00554 
00555                      if ((pnOrgYj[1] >= 450) && (pnOrgYj[1] <= 475))
00556                             pszYj2 = SHENGMUSTR[ GbkHz2244ToYjSM((JINT)wCzHz[1]) - 450 ];
00557                      else
00558                             pszYj2 = YINJIESTR_CSZ[ GbkHz2244ToYj((JINT)wCzHz[1]) ];
00559                      strcat(strcat(szYj3, pszYj1), pszYj2);
00560 
00561                      /* Add the following 4 lines to proc [fangan] ==> [fan gan] and [fang an]. Scott Ma 98-05-12 */
00562                      if ((pnOrgYj[0] >= 450) && (pnOrgYj[0] <= 475))
00563                             pszYj1 = SHENGMUSTR[ pnOrgYj[0] - 450 ];
00564                      else
00565                             pszYj1 = YINJIESTR_CSZ[ pnOrgYj[0] ];
00566 
00567                      if ((pnOrgYj[1] >= 450) && (pnOrgYj[1] <= 475))
00568                             pszYj2 = SHENGMUSTR[ pnOrgYj[1] - 450 ];
00569                      else
00570                             pszYj2 = YINJIESTR_CSZ[ pnOrgYj[1] ];
00571                      strcat(strcat(szYj4, pszYj1), pszYj2);
00572 
00573                      nEqualFlag = TRUE;
00574                      if ( strcmp (szYj3, szYj4) != 0)
00575                             nEqualFlag = FALSE;
00576                      
00577                      if ((nEqualFlag == TRUE) && (nMode == LU_CANDI_CALC))
00578                      {
00579                             psc->nSizDhCandi += (nCzLen + 2);  /* Add two JWORD Here to contain Freq Word and a ZERO */
00580                             psc->nNumDhCandi += 1;
00581                             *pnSize += (nCzLen + 2);
00582                      }
00583                      else if ((nEqualFlag == TRUE) && (nMode == LU_CANDI_WRITE))
00584                      {
00585                             psc->pwDhCandi[psc->nSizDhCandi] = wDhFreq;
00586                             for (m = 0; m < nCzLen; m++)
00587                                    psc->pwDhCandi[psc->nSizDhCandi + m + 1] = wCzHz[m];
00588                             
00589                             psc->nSizDhCandi += (nCzLen + 2);
00590                             psc->nNumDhCandi += 1;
00591                             *pnSize += (nCzLen + 2);
00592                      }
00593               }
00594        }
00595 
00596        /* GB Single Hanzi */
00597        if (nLenYj >= 1)
00598        {
00599               /*
00600               **  Order of Single Hanzi Candidates:
00601               **  IF pnOrgYj[0] is a SM, place HIFREQHANZI[?][14] at the head of ShCandi Area
00602               **                         Place Single Hanzi by Frequence and Yinjie Sequence
00603               **  IF pnOrgYj[0] is Normal Yinjie [0 ~ 414], place XianForm candis at the head.
00604               **                         place Single Hanzi by Frequence and Yinjie Sequence
00605               **
00606               **  Determine the Fromyj and ToYj which to used for searching by the pnOrgYj[0].
00607               **  NOTICE: This is different from DhCandi and MhCandi.  
00608               */
00609               if ((pnOrgYj[0] >= 0) && (pnOrgYj[0] < NUM_YINJIE))
00610               {
00611                      nFromYj  = pnOrgYj[0];
00612                      nToYj    = pnOrgYj[0] + 1;
00613 
00614                      nXianNum = (pShi->nYjOff[nToYj] & 0x0F000000) >> 24;
00615                      for (k = 0; k < nXianNum; k++)
00616                      {
00617                             if (nMode == LU_CANDI_CALC)
00618                             {
00619                                    psc->nSizShCandi += 3;        /* Add one ZERO After this Xian Candi */
00620                                    psc->nNumShCandi += 1;
00621                                    *pnSize += 3;
00622                             }
00623                             else if (nMode == LU_CANDI_WRITE)
00624                             {
00625                                    nTmp  = pShi->nYjOff[nToYj] & 0x00FFFFFF;
00626                                    chHi  = (UCHAR)*(pShArea + nTmp - (nXianNum * 4) + (k * 4));
00627                                    chLow = (UCHAR)*(pShArea + nTmp - (nXianNum * 4) + (k * 4) + 1);
00628                                    psc->pwShCandi[psc->nSizShCandi]     = (JWORD)((chHi << 8) + chLow);
00629                                    
00630                                    chHi  = (UCHAR)*(pShArea + nTmp - (nXianNum * 4) + (k * 4) + 2);
00631                                    chLow = (UCHAR)*(pShArea + nTmp - (nXianNum * 4) + (k * 4) + 3);
00632                                    psc->pwShCandi[psc->nSizShCandi + 1] = (JWORD)((chHi << 8) + chLow);
00633                                    
00634                                    psc->pwShCandi[psc->nSizShCandi + 2] = 0x0000;
00635 
00636                                    psc->nSizShCandi += 3;
00637                                    psc->nNumShCandi += 1;
00638                                    *pnSize += 3;
00639                             }
00640                      }
00641               }
00642               else   /* ((pnOrgYj[0] >= 450) && (pnOrgYj[0] <= 475)) */
00643               {
00644                      nFromYj  = INDEXSMTOYINJIE[ pnOrgYj[0] - 450 ];
00645                      nToYj    = INDEXSMTOYINJIE[ pnOrgYj[0] - 450 + 1 ];
00646 
00647                      for (m = 0; m < 7; m++)         /* There are 7 HIFREQHANZI in each SM Yinjie. See PyBasic.h */
00648                      {
00649                             if (nMode == LU_CANDI_CALC)
00650                             {
00651                                    psc->nSizShCandi += 2;        /* Add one ZERO After this HIFREQHANZI */
00652                                    psc->nNumShCandi += 1;
00653                                    *pnSize += 2;
00654                             }
00655                             else if (nMode == LU_CANDI_WRITE)
00656                             {
00657                                    chHi  = HIFREQHANZI[pnOrgYj[0] - 450][2 * m];
00658                                    chLow = HIFREQHANZI[pnOrgYj[0] - 450][2 * m + 1];
00659                                    psc->pwShCandi[psc->nSizShCandi]     = (JWORD)((chHi << 8) + chLow);
00660                                    
00661                                    psc->nSizShCandi += 2;
00662                                    psc->nNumShCandi += 1;
00663                                    *pnSize += 2;
00664                             }
00665                      }
00666               }
00667               
00668               /*
00669               **  Because 'Xian' Form is already included in above processing (0 ~ 414), and no necessary
00670               **  for (450 ~ 475), So, not to include then in the following reclycle.
00671               */
00672               for(k = nFromYj; k < nToYj; k++)
00673               {
00674                      nXianNum = (pShi->nYjOff[k + 1] & 0x0F000000) >> 24;
00675                      nFromOff = pShi->nYjOff[ k ] & 0x00FFFFFF;
00676                      nToOff   = (pShi->nYjOff[ k + 1] & 0x00FFFFFF) - (4 * nXianNum);
00677                      
00678                      /* !!Don't add m++ in this FOR sentence!! */
00679                      for(m = nFromOff; m < nToOff;  )
00680                      {
00681                             if (nMode == LU_CANDI_CALC)
00682                             {
00683                                    psc->nSizShCandi += 2;        /* Add one ZERO After each Single Hanzi Candidate */
00684                                    psc->nNumShCandi += 1;
00685                                    *pnSize += 2;
00686                                    m += 2;
00687                             }
00688                             else if (nMode == LU_CANDI_WRITE)
00689                             {
00690                                    chHi  = (UCHAR)*(pShArea + m);
00691                                    chLow = (UCHAR)*(pShArea + m + 1);
00692                                    psc->pwShCandi[psc->nSizShCandi]   = (JWORD)((chHi << 8) + chLow);
00693                                    
00694                                    psc->nSizShCandi += 2;
00695                                    psc->nNumShCandi += 1;
00696                                    *pnSize += 2;
00697                                    m += 2;
00698                             }
00699                      }
00700               }
00701        }
00702        
00703        /* GBKKKK!!! Single Hanzi */
00704 #ifdef _DRAW_IM_WIN_H
00705        if (nLenYj >= 1)
00706 #else  
00707        if ((nLenYj >= 1) && (strcmp(szLocale, "zh.GBK") == 0))
00708 #endif
00709        {
00710               nTmp = pnOrgYj[0];
00711 
00712               /* Process "a", "e", "o", "m", "n" */
00713               if (nTmp == 450)
00714                      nTmp = 0;
00715               else if (nTmp == 455)
00716                      nTmp = 80;
00717               else if (nTmp == 462)
00718                      nTmp = 191;
00719               else if (nTmp == 463)
00720                      nTmp = 211;
00721               else if (nTmp == 464)
00722                      nTmp = 237;
00723 
00724               if ((nTmp >= 0) && (nTmp < NUM_YINJIE))
00725               {
00726                      nFromOff = pGbki->nYjOff[ nTmp ];
00727                      nToOff   = pGbki->nYjOff[ nTmp + 1];
00728               
00729                      /* !!Don't add m++ in this FOR sentence!! */
00730                      for(m = nFromOff; m < nToOff;  )
00731                      {
00732                             if (nMode == LU_CANDI_CALC)
00733                             {
00734                                    psc->nSizGbkCandi += 2;       /* Add one ZERO After each GBK Single Hanzi Candidate */
00735                                    psc->nNumGbkCandi += 1;
00736                                    *pnSize += 2;
00737                                    m += 2;
00738                             }
00739                             else if (nMode == LU_CANDI_WRITE)
00740                             {
00741                                    chHi  = (UCHAR)*(pGbkArea + m);
00742                                    chLow = (UCHAR)*(pGbkArea + m + 1);
00743                                    psc->pwGbkCandi[psc->nSizGbkCandi]   = (JWORD)((chHi << 8) + chLow);
00744                             
00745                                    psc->nSizGbkCandi += 2;
00746                                    psc->nNumGbkCandi += 1;
00747                                    *pnSize += 2;
00748                                    m += 2;
00749                             }
00750                      }
00751               }
00752        }
00753        
00754 
00755        /****************************************************************************************
00756        **************************    Enum Candi in udcAll     **********************************
00757        ****************************************************************************************/
00758        /*
00759        ** Get puc->pwSpecCandi[6]. pwSepcCandi only be given if pnOrgYj[0] is among [0 ~ 414]
00760        */
00761        if ((nLenYj >= 1) && (pnOrgYj[0] >= 0) && (pnOrgYj[0] < NUM_YINJIE))
00762        {
00763               nTmp = 0;
00764               for (i = 0; i < (udcAll.udcfh.nSizeSpecHz / 2); i++)
00765               {
00766                      if (udcAll.pwUdcSh[i] == 0x0000)
00767                             nTmp++;
00768                      
00769                      if (nTmp == (pnOrgYj[0] + 1))
00770                      {
00771                             i++;
00772                             for (m = i; udcAll.pwUdcSh[m] != 0x0000; m++)
00773                             {
00774                                    /* MAX: 6 Special Hanzi for each Yinjie in < UdCiku.dat >!! */
00775                                    if ((m - i) > 5)
00776                                           break;       /* Break out FOR_m */
00777                                    
00778                                    if (nMode == LU_CANDI_WRITE)
00779                                           puc->pwSpecCandi[m - i] = udcAll.pwUdcSh[m];
00780                                    puc->nNumSpecCandi ++;
00781                             }
00782                             break;           /* Break out FOR_i */
00783                      }
00784               }
00785        }
00786        else
00787               puc->nNumSpecCandi = 0;
00788 
00789        /*
00790        **  Get puc->nNumUdc28Candi and puc->nSizUdc28Candi, AND
00791        **  fill puc->pwUdc28Candi[] if nMode == LU_CANDI_WRITE
00792        */
00793        if (nLenYj >= 2)
00794        {
00795               /*
00796               **  Determine the nFromYj and nToYj which to used for searching by the pnOrgYj[0].
00797               */
00798               if ((pnOrgYj[0] >= 0) && (pnOrgYj[0] < NUM_YINJIE))
00799               {
00800                      nFromYj  = pnOrgYj[0];
00801                      nToYj    = pnOrgYj[0] + 1;
00802               }
00803               else   /* ((pnOrgYj[0] >= 450) && (pnOrgYj[0] <= 475)) */
00804               {
00805                      nFromYj  = INDEXSMTOYINJIE[ pnOrgYj[0] - 450 ];
00806                      nToYj    = INDEXSMTOYINJIE[ pnOrgYj[0] - 450 + 1 ];
00807               }
00808 
00809               for(k = nFromYj; k < nToYj; k++)
00810               {
00811                      nCurSize   = udcAll.udci.nYjOff[k + 1] - udcAll.udci.nYjOff[k];      /* In BYTE */
00812 
00813                      /* NO i++ in this FOR sentence */
00814                      for (i = 0; i < nCurSize / 2; )
00815                      {
00816                             nUdc28FreqLen =  udcAll.pwUdc28[k][i] & 0x00FF;
00817                             nUdc28Len     = (udcAll.pwUdc28[k][i] & 0x0007) + 2;
00818                             i++;
00819 
00820                             for (m = 0; m < 10; m++)
00821                                    wCzHz[m]  = 0x0000;
00822                             for (m = 0; m < nUdc28Len; m++)
00823                             {
00824                                    wCzHz[m]  = udcAll.pwUdc28[k][i];
00825                                    i++;
00826                             }
00827                      
00828                             nEqualFlag = FALSE;
00829                             if (( (nLenYj <= 4) && (nUdc28Len  <= nLenYj) ) || 
00830                                 ( (nLenYj >= 5) && (nMatchMode == LU_MATCH_WIDELY) ) || 
00831                                 ( (nLenYj >= 5) && (nMatchMode == LU_MATCH_STRICT) && (nUdc28Len <= nLenYj) )  )
00832                             {
00833                                    nEqualFlag = TRUE;
00834                             
00835                                    for(m = 0; m < _MIN(nLenYj, nUdc28Len); m++)
00836                                           if ( ( pnOrgYj[m] != GbkHz2244ToYjSM((JINT)wCzHz[m]) ) &&                    \
00837                                                ( pnOrgYj[m] != GbkHz2244ToYj  ((JINT)wCzHz[m]) ) )
00838                                           {
00839                                                  nEqualFlag = FALSE;
00840                                                  break;
00841                                           }
00842                             }
00843 
00844                             /* Is there any GBK UdcCizu that to be omitted? */
00845                             if (nEqualFlag == TRUE)
00846                             {
00847                                    nfGbkCizu = FALSE;
00848                                    for (m = 0; m < nUdc28Len; m++)
00849                                    {
00850                                           if (IsGbkkkHz(wCzHz[m]) == TRUE)
00851                                           {
00852                                                  nfGbkCizu = TRUE;
00853                                                  break;
00854                                           }
00855                                    }
00856                                    
00857                                    if ((nfGbkCizu == TRUE) && (strcmp(szLocale, "zh") == 0))
00858                                           nEqualFlag = FALSE;
00859 #ifdef _DRAW_IM_WIN_H
00860                                    nEqualFlag = TRUE;
00861 #endif                             
00862                             }
00863                             
00864                             if ((nEqualFlag == TRUE) && (nMode == LU_CANDI_CALC))
00865                             {
00866                                    puc->nSizUdc28Candi += (nUdc28Len + 2);   /* Add two JWORD Here to contain Freq&Len Word and a ZERO */
00867                                    puc->nNumUdc28Candi += 1;
00868                                    *pnSize += (nUdc28Len + 2);
00869                             }
00870                             else if ((nEqualFlag == TRUE) && (nMode == LU_CANDI_WRITE))
00871                             {
00872                                    puc->pwUdc28Candi[puc->nSizUdc28Candi] = (JWORD)nUdc28FreqLen;
00873                                    for (m = 0; m < nUdc28Len; m++)
00874                                           puc->pwUdc28Candi[puc->nSizUdc28Candi + m + 1] = wCzHz[m];
00875                             
00876                                    puc->nSizUdc28Candi += (nUdc28Len + 2);
00877                                    puc->nNumUdc28Candi += 1;
00878                                    *pnSize += (nUdc28Len + 2);
00879                             }
00880                      }
00881               }
00882        }
00883        
00884        *pnSize += 1;
00885        return TRUE;
00886 }
00887 
00888 
00889 /*
00890 **  Initialize Structure SysCandi
00891 */
00892 VOID InitStructSc(SysCandi* psc)
00893 {
00894        JINT    i;
00895        
00896        for(i = 0; i < 9; i++)
00897               psc->nOrgYj[i]     = 0x00000000;
00898 
00899        psc->nLenYj       = 0;
00900        psc->nNumShCandi  = 0;
00901        psc->nNumDhCandi  = 0;
00902        psc->nNumMhCandi  = 0;
00903        psc->nNumGbkCandi = 0;
00904        
00905        psc->nSizShCandi  = 0;
00906        psc->nSizDhCandi  = 0;
00907        psc->nSizMhCandi  = 0;
00908        psc->nSizGbkCandi = 0;
00909        
00910        free (psc->pwShCandi);
00911        free (psc->pwDhCandi);
00912        free (psc->pwMhCandi);
00913        free (psc->pwGbkCandi);
00914        psc->pwShCandi   = NULL;
00915        psc->pwDhCandi   = NULL;
00916        psc->pwMhCandi   = NULL;
00917        psc->pwGbkCandi  = NULL;
00918 }
00919 
00920 
00921 /*
00922 **  nLenYj indicates the length of pnOrgYj. 
00923 **  Max Length of nLenYj is 9, even Max Hanzi Length in
00924 **  current PyCiku.dat is 7.
00925 **
00926 **  Notice here: pnOrgYj[i] may be 0x00010000 + [0 ~ 475] to indicates there is 
00927 **               ['] before corressponding yinjie string.
00928 **  return TRUE or FALSE
00929 */
00930 JINT LookupCiku(JINT* pnOrgYj, JINT nLenYj, JINT nMatchMode, SysCandi* psc, UdcCandi* puc)
00931 {
00932        JINT    nSize, i;
00933 
00934        nSize = 0;
00935 
00936        InitStructSc(psc);
00937        InitStructUc(puc);
00938        
00939        /* 
00940        ** Set the content of psc->nOrgYj and pscYj->nLenYj    AND 
00941        ** Filter those Yjcode which start with a [']. 
00942        */
00943        for(i = 0; i < nLenYj; i++)
00944        {
00945               psc->nOrgYj[i]  = pnOrgYj[i];
00946               pnOrgYj[i]     &= 0x0000FFFF;
00947        }
00948        psc->nLenYj  = nLenYj;
00949        
00950        EnumCandi(pnOrgYj, nLenYj, psc, puc, &nSize, nMatchMode, LU_CANDI_CALC);
00951        
00952        psc->pwMhCandi    = (JWORD*)malloc((psc->nSizMhCandi  + MALIGN) * sizeof(JWORD));
00953        psc->pwDhCandi    = (JWORD*)malloc((psc->nSizDhCandi  + MALIGN) * sizeof(JWORD));
00954        psc->pwShCandi    = (JWORD*)malloc((psc->nSizShCandi  + MALIGN) * sizeof(JWORD));
00955        psc->pwGbkCandi   = (JWORD*)malloc((psc->nSizGbkCandi + MALIGN) * sizeof(JWORD));
00956        puc->pwUdc28Candi = (JWORD*)malloc((puc->nSizUdc28Candi + MALIGN) * sizeof(JWORD));
00957 
00958        if ((psc->pwMhCandi == NULL)  || (psc->pwDhCandi == NULL) || (psc->pwShCandi == NULL) || 
00959               (psc->pwGbkCandi == NULL) || (puc->pwUdc28Candi == NULL) )
00960        {
00961               fprintf(stderr, "Error!! Failed to Malloc() in Function LookupCiku().\n");
00962               return FALSE;
00963        }
00964 
00965        memset(psc->pwMhCandi,  '\0', (psc->nSizMhCandi  + MALIGN) * sizeof(JWORD));
00966        memset(psc->pwDhCandi,  '\0', (psc->nSizDhCandi  + MALIGN) * sizeof(JWORD));
00967        memset(psc->pwShCandi,  '\0', (psc->nSizShCandi  + MALIGN) * sizeof(JWORD));
00968        memset(psc->pwGbkCandi, '\0', (psc->nSizGbkCandi + MALIGN) * sizeof(JWORD));
00969        memset(puc->pwUdc28Candi, '\0', (puc->nSizUdc28Candi + MALIGN) * sizeof(JWORD));
00970        
00971        EnumCandi(pnOrgYj, nLenYj, psc, puc, &nSize, nMatchMode, LU_CANDI_WRITE);
00972        
00973        /* Additional Process for Spec Hanzi Candi, MXL 98.01.12 */
00974        if (0 == (psc->nNumMhCandi + psc->nNumDhCandi + puc->nNumUdc28Candi))
00975               puc->nNumSpecCandi = 0;
00976        
00977        /* Sort Candidates in structure SysCandi and UdcCandi by Frequence */
00978        SortCandi(psc, puc);
00979        
00980        return TRUE;
00981 }
00982 
00983 
00984 /*
00985 **  Sort Candidates in Structure SysCandi by Length and Frequence
00986 **  
00987 **  NOT IMPROVED:
00988 **  [** TO IMPROVE: In SortSysCandi(), Rearrange XIAN candies to proper position **] 97.11.28.
00989 **  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
00990 */
00991 VOID SortCandi(SysCandi* psc, UdcCandi* puc)
00992 {
00993        JINT    nNumM, nSizM, nNumD, nSizD, nNumUdc28, nSizUdc28;
00994        JINT    nBuf, nTmp, i, k, m, n, p, nLenM, nFreqM, nLenUdc28, nFreqUdc28;
00995        JWORD   *pwBuf = NULL;
00996        
00997        nNumM   = psc->nNumMhCandi;
00998        nSizM   = psc->nSizMhCandi;
00999        nNumD   = psc->nNumDhCandi;
01000        nSizD   = psc->nSizDhCandi;
01001        nNumUdc28 = puc->nNumUdc28Candi;
01002        nSizUdc28 = puc->nSizUdc28Candi;
01003 
01004        if ((nNumM <= 1) && (nNumD <= 1) && (nNumUdc28 <= 1))
01005               return;
01006        
01007        nBuf = _MAX(nSizM, nSizD);
01008        nBuf = _MAX(nBuf, nSizUdc28);
01009        
01010        pwBuf = (JWORD *)malloc((nBuf + MALIGN) * sizeof(JWORD));
01011        if (pwBuf == NULL)
01012        {
01013               fprintf(stderr, "Failed to alloc Memory in function SortSysCandi().\n");
01014               return;
01015        }
01016        
01017        /*
01018        **  For MultipleHanzi Candidates, by Length First, by Frequence Second.
01019        */
01020        nLenM = nFreqM = 0;
01021        if(nNumM > 1)
01022        {
01023               memset(pwBuf, '\0', (nBuf + MALIGN) * sizeof(JWORD));
01024               
01025               p = m = n = 0;
01026               for(i = 0xFF; (i >= 0x00) && (p < nNumM); i--)
01027               {
01028                      for(k = 0; k < nSizM; )
01029                      {
01030                             /*
01031                             **  Exchange [Freq + Len] to [Len + Freq] (nTmp), because by Length first.
01032                             **  Notice: (nLen + 2) is the really length of this Mh Cizu,
01033                             **          another 2 is (Len+Freq) WORD in front and Zero WORD in End.
01034                             */
01035                             nLenM  = psc->pwMhCandi[k] & 0x07;
01036                             nFreqM = psc->pwMhCandi[k] & 0xF8;
01037                             nTmp   = (nLenM << 5) + (nFreqM >> 3);
01038                             if(nTmp == i)
01039                             {
01040                                    for(m = 0; m < (nLenM + 2 + 2); m++)
01041                                           pwBuf[n++] = psc->pwMhCandi[k + m];
01042                                    p++;
01043                             }
01044                             k += (nLenM + 2 + 2);
01045                      }
01046               }
01047               
01048               for(i = 0; i < nSizM; i++)
01049                      psc->pwMhCandi[i] = pwBuf[i];
01050        }
01051        
01052        /*
01053        **  For DoubleHanzi Candidates, by Frequence only.
01054        */
01055        if(nNumD > 1)
01056        {
01057               memset(pwBuf, '\0', (nBuf + MALIGN) * sizeof(JWORD));
01058               
01059               p = m = n = 0;
01060               for(i = 0xFF; (i >= 0x00) && (p < nNumD); i--)
01061               {
01062                      for(k = 0; k < nSizD; k++)
01063                      {
01064                             nTmp   = psc->pwDhCandi[k];
01065                             if(nTmp == i)
01066                             {
01067                                    for(m = 0; m < (2 + 2); m++)
01068                                           pwBuf[n++] = psc->pwDhCandi[k + m];
01069                                    p++;
01070                             }
01071                      }
01072               }
01073               
01074               for(i = 0; i < nSizD; i++)
01075                      psc->pwDhCandi[i] = pwBuf[i];
01076        }
01077 
01078 
01079        /*
01080        **  For Udc come from <UdCiku.dat>, by Length First, by Frequence Second.
01081        */
01082        nLenUdc28 = nFreqUdc28 = 0;
01083        if(nNumUdc28 > 1)
01084        {
01085               memset(pwBuf, '\0', (nBuf + MALIGN) * sizeof(JWORD));
01086               
01087               p = m = n = 0;
01088               for(i = 0xFF; (i >= 0x00) && (p < nNumUdc28); i--)
01089               {
01090                      for(k = 0; k < nSizUdc28; )
01091                      {
01092                             /*
01093                             **  Exchange [Freq + Len] to [Len + Freq] (nTmp), because by Length first.
01094                             **  Notice: (nLen + 2) is the really length of this Mh Cizu,
01095                             **          another 2 is (Len+Freq) WORD in front and Zero WORD in End.
01096                             */
01097                             nLenUdc28  = puc->pwUdc28Candi[k] & 0x07;
01098                             nFreqUdc28 = puc->pwUdc28Candi[k] & 0xF8;
01099                             nTmp   = (nLenUdc28 << 5) + (nFreqUdc28 >> 3);
01100                             if(nTmp == i)
01101                             {
01102                                    for(m = 0; m < (nLenUdc28 + 2 + 2); m++)
01103                                           pwBuf[n++] = puc->pwUdc28Candi[k + m];
01104                                    p++;
01105                             }
01106                             k += (nLenUdc28 + 2 + 2);
01107                      }
01108               }
01109               
01110               for(i = 0; i < nSizUdc28; i++)
01111                      puc->pwUdc28Candi[i] = pwBuf[i];
01112        }
01113 
01114        free(pwBuf);
01115 }
01116 
01117 
01118 /*
01119 **  Adjust the freqence of a specified Ciku. Length of this cizu is 
01120 **  specified in nLen.
01121 **
01122 **  Increase the frequence of this Dh or Mh, decrease the frequence
01123 **  of other Dh or Mh which have same Yjcode.
01124 **
01125 **  For Sh, move the Hanzi forward to a certain place, move other
01126 **  Hanzies backward.
01127 */
01128 VOID AdjustFreq(JWORD* pwHz2244, JINT nLenThis)
01129 {
01130        JINT    nYjFirst;
01131        JINT    nCzLen, i, k, m, t;
01132        JINT    nFromOff, nToOff;
01133        JWORD   wCzHz, wMhLenFreq, wFreq;
01134        JINT    nEqualFlag;
01135        CHAR    szDhYj1[14], szDhYj2[14];
01136        UCHAR   pchHz2244[20];     /* Max is 9 Hanzi!! */
01137        JINT    nFindFlag;
01138        JINT    nUdc28FreqLen, nUdc28Len;
01139        JINT    nCurSize;
01140        JINT    nXianNum, nPos;
01141        BYTE    *pbAreaBase;
01142 
01143        CikuHeader  *pCkh;
01144        ShIndex     *pShi;
01145        DhIndex     *pDhi;
01146        MhIndex     *pMhi;
01147        GbkIndex    *pGbki;
01148        BYTE        *pShArea;
01149        BYTE        *pDhArea;
01150        BYTE        *pMhArea;
01151        BYTE        *pGbkArea;
01152 
01153        pCkh     = (CikuHeader *)pCkAll;
01154        pShi     = (ShIndex  *)(pCkAll + pCkh->nIdxShPos);
01155        pDhi     = (DhIndex  *)(pCkAll + pCkh->nIdxDhPos);
01156        pMhi     = (MhIndex  *)(pCkAll + pCkh->nIdxMhPos);
01157        pGbki    = (GbkIndex *)(pCkAll + pCkh->nIdxGbkPos);
01158        
01159        pShArea  = (BYTE *)(pCkAll + pShi->nStartPos);
01160        pDhArea  = (BYTE *)(pCkAll + pDhi->nStartPos);
01161        pMhArea  = (BYTE *)(pCkAll + pMhi->nStartPos);
01162        pGbkArea = (BYTE *)(pCkAll + pGbki->nStartPos);
01163 
01164        memset(pchHz2244, '\0', 20);
01165        Jword2Uchar(pwHz2244, pchHz2244, nLenThis);
01166        
01167        nFindFlag = FALSE;
01168        /* nYjFirst must be in range 0~414 */
01169        nYjFirst = GbkHz2244ToYj((JINT)pwHz2244[0]);
01170 
01171        if (nLenThis >= 3)
01172        {
01173               /*
01174               **  Determine the FromOff and ToOff which to used for searching by the pnOrgYj[0].
01175               */
01176               nFromOff = pMhi->nYjOff[ nYjFirst ];
01177               nToOff   = pMhi->nYjOff[ nYjFirst + 1];
01178               
01179               /* !! DON'T add k++ in this FOR sentence !! */
01180               for (k = nFromOff; k < nToOff; )
01181               {
01182                      wMhLenFreq = (JWORD)*(pMhArea + k);
01183                      nCzLen     = 2 + ((UCHAR)*(pMhArea + k) & 0x07);
01184                      k++;
01185 
01186                      /*  It is just this Cizu, Increase its frequence here. */
01187                      if ((nCzLen == nLenThis) &&
01188                             (strncmp((CHAR*)(&pMhArea[k]), (CHAR*)pchHz2244, 2 * nCzLen) == 0) )
01189                      {
01190                             /* Just set Frequence to highest. */
01191                             *(pMhArea + k - 1) = (BYTE)(0xF8 + (nCzLen - 2));
01192                             k += (2 * nCzLen);
01193                             nFindFlag = TRUE;
01194                      }
01195                      /*
01196                      **  Have the same length. Is it also have same Yjcode? If yes, 
01197                      **  reduce the frequence.
01198                      */
01199                      else if ((nCzLen == nLenThis) &&
01200                              (strncmp((CHAR*)(&pMhArea[k]), (CHAR*)pchHz2244, 2 * nCzLen) != 0) )
01201                      {
01202                             nEqualFlag = TRUE;
01203 
01204                             /*
01205                             ** Compare from the second Hanzi, because the first Hanzi must
01206                             ** same Yjcode. So, skip the first by adding t += 2.
01207                             */
01208                             t = k;
01209                             t += 2;
01210                             for (m = 1; m < nCzLen; m++)
01211                             {
01212                                    wCzHz   = (JWORD)(*(pMhArea + t + 1) + ((*(pMhArea + t)) << 8));
01213                                    t += 2;
01214 
01215                                    if ( GbkHz2244ToYj((JINT)pwHz2244[1]) != GbkHz2244ToYj((JINT)wCzHz) )
01216                                    {
01217                                           nEqualFlag = FALSE;
01218                                           break;
01219                                    }
01220                             }
01221 
01222                             /* Have same Yjcodes in every Hanzi, reduce its Frequence Here. */
01223                             if (nEqualFlag == TRUE)
01224                             {
01225                                    wMhLenFreq = (JWORD)*(pMhArea + k - 1);
01226                                    /*
01227                                    ** Length bits have the lowest 3 bits.  -8 means reduce the Frequence
01228                                    ** by ONE level. if its Freq Level is 1, no reduce needed.
01229                                    */
01230                                    if (wMhLenFreq >= 16)
01231                                           *(pMhArea + k - 1) -= 8;
01232                             }
01233 
01234                             k += (2 * nCzLen);
01235                      }
01236                      /* If it doesn't have the same length, just skip this cizu. */
01237                      else
01238                             k += (2 * nCzLen);
01239               }
01240        }
01241        
01242        else if (nLenThis == 2)
01243        {
01244               /*
01245               **  Determine the FromOff and ToOff which to used for searching by the pnOrgYj[0].
01246               */
01247               nFromOff = pDhi->nYjOff[ nYjFirst ];
01248               nToOff   = pDhi->nYjOff[ nYjFirst + 1];
01249               
01250               /* !! DON'T add k++ in this FOR sentence !! */
01251               for (k = nFromOff; k < nToOff; )
01252               {
01253                      wFreq   = (JWORD)*(pDhArea + k);
01254                      nCzLen  = 2;
01255                      k++;
01256 
01257                      /*  It is just this Cizu, Increase its frequence here. */
01258                      if (strncmp((CHAR*)(&pDhArea[k]), (CHAR*)pchHz2244, 4) == 0)
01259                      {
01260                             *(pDhArea + k - 1) = 0xFF;
01261                             k += 4;
01262                             nFindFlag = TRUE;
01263                      }
01264                      /*
01265                      **  Have the same length. Is it also have same Yjcode? If yes, 
01266                      **  reduce the frequence.
01267                      */
01268                      else
01269                      {
01270                             for(i = 0; i < 14; i++)
01271                                    szDhYj1[i] = szDhYj2[i] = '\0';
01272 
01273                             /* Cat total YinjieString into szDhYj1 */
01274                             strcat( strcat(szDhYj1, YINJIESTR_CSZ[nYjFirst]),       
01275                                                     YINJIESTR_CSZ[GbkHz2244ToYj((JINT)pwHz2244[1])] );
01276 
01277                             t = k;
01278                             wCzHz   = (JWORD)(*(pDhArea + t + 1) + ((*(pDhArea + t)) << 8));
01279                             strcat(szDhYj2, YINJIESTR_CSZ[GbkHz2244ToYj((JINT)wCzHz)]);
01280 
01281                             t += 2;
01282                             wCzHz   = (JWORD)(*(pDhArea + t + 1) + ((*(pDhArea + t)) << 8));
01283                             strcat(szDhYj2, YINJIESTR_CSZ[GbkHz2244ToYj((JINT)wCzHz)]);
01284 
01285                             nEqualFlag = TRUE;
01286                             if (strcmp(szDhYj1, szDhYj2) != 0)
01287                                    nEqualFlag = FALSE;
01288 
01289                             /* Have same Yjcodes in every Hanzi, reduce its Frequence Here. */
01290                             if (nEqualFlag == TRUE)
01291                             {
01292                                    wFreq = (JWORD)*(pDhArea + k - 1);
01293                                    /*
01294                                    ** Decrease by ONE Level.
01295                                    */
01296                                    if (wFreq >= 2)
01297                                           *(pDhArea + k - 1) -= 1;
01298                             }
01299                             k += 4;
01300 
01301                      }
01302               }
01303        }
01304 
01305        /* nLenThis == 1, GB and GBK */
01306        else if (nLenThis == 1)
01307        {
01308               if (IsGbkkkHz(pwHz2244[0]) == TRUE)   /* GbKkk */
01309               {
01310                      nFromOff   = pGbki->nYjOff[ nYjFirst ];
01311                      nToOff     = pGbki->nYjOff[ nYjFirst + 1 ];
01312                      pbAreaBase = pGbkArea;
01313               }
01314               else    /* Normal GB */
01315               {
01316                      nXianNum   = (pShi->nYjOff[nYjFirst + 1] & 0x0F000000) >> 24;
01317                      nFromOff   = pShi->nYjOff[nYjFirst] & 0x00FFFFFF;
01318                      nToOff     = (pShi->nYjOff[nYjFirst + 1] & 0x00FFFFFF) - (4 * nXianNum);
01319                      pbAreaBase = pShArea;
01320               }
01321               
01322               nPos = 0;
01323               for (k = nFromOff; k < nToOff; k += 2)
01324               {
01325                      if (strncmp((CHAR*)(&pbAreaBase[k]), (CHAR*)pchHz2244, 2) == 0)
01326                      {
01327                             nPos = (k - nFromOff) / 2;
01328                             break;
01329                      }
01330               }
01331               
01332               /*
01333               **  If NOT the first Hanzi in ShArea[nYj] or GbkArea[nYj], move this Hanzi
01334               **  forward by (nPos / 4  + 1)
01335               */
01336               if (nPos > 0)
01337               {
01338                      m = 0;
01339                      for (k = nFromOff + (2 * nPos); m < (nPos / 4  + 1); )
01340                      {
01341                             pbAreaBase[k + 1] = pbAreaBase[k - 1];
01342                             pbAreaBase[k]     = pbAreaBase[k - 2];
01343                             k -= 2;
01344                             m++;
01345                      }
01346                      pbAreaBase[k + 1] = pchHz2244[1];
01347                      pbAreaBase[k]     = pchHz2244[0];
01348               }
01349        }
01350 
01351        /*
01352        **  Otherwise, this must be an UserDefinedCizu.
01353        */
01354        if ((nLenThis >= 2) && (nFindFlag == FALSE))
01355        {
01356               nCurSize   = udcAll.udci.nYjOff[nYjFirst + 1] - udcAll.udci.nYjOff[nYjFirst];      /* In BYTE */
01357 
01358               /* NO i++ in this FOR sentence */
01359               for (i = 0; i < nCurSize / 2; )
01360               {
01361                      nUdc28FreqLen =  udcAll.pwUdc28[nYjFirst][i] & 0x00FF;
01362                      nUdc28Len     = (udcAll.pwUdc28[nYjFirst][i] & 0x0007) + 2;
01363                      i++;
01364 
01365                      /*  It is just this Cizu, Increase its frequence here. */
01366                      if ((nUdc28Len == nLenThis) &&
01367                             (strncmp((CHAR*)&(udcAll.pwUdc28[nYjFirst][i]), (CHAR*)pchHz2244, 2 * nUdc28Len) == 0) )
01368                      {
01369                             /* Just set Frequence to highest. */
01370                             udcAll.pwUdc28[nYjFirst][i - 1] = (BYTE)(0xF8 + (nUdc28Len - 2));
01371                             i += nUdc28Len;
01372                             nFindFlag = TRUE;
01373                      }
01374                      else
01375                      {
01376                             if (nUdc28FreqLen >= 0x0010)
01377                                    udcAll.pwUdc28[nYjFirst][i - 1] -= 8;
01378                             i += nUdc28Len;
01379                      }
01380               }
01381        }
01382 
01383 }
01384 
01385 
01386 /*
01387 **  Lookup the System Ciku and User Defined Ciku to find out whether pwHz2244 Exist or not.
01388 **  Length of this Cizu is given in nLenThis.  Constant is defined file <CikuOper.h>
01389 **  If NO,                           RETURN 0;  ==>  NON_EXIST_CIZU 
01390 **  If YES && in System Ciku,        RETURN 1;  ==>  SYS_EXIST_CIZU 
01391 **  If YES && in User Defined Ciku,  RETURN 2;  ==>  UDC_EXIST_CIZU 
01392 */
01393 JINT IsCizuExist(JWORD* pwHz2244, JINT nLenThis)
01394 {
01395        JINT    nFindFlag;
01396        
01397        JINT    nYjFirst;
01398        JINT    nCzLen, i, k;
01399        JINT    nFromOff, nToOff;
01400        JWORD   wMhLenFreq, wFreq;
01401        UCHAR   pchHz2244[20];     /* Max is 9 Hanzi!! */
01402        JINT    nCurSize, nUdc28FreqLen, nUdc28Len;
01403 
01404        CikuHeader  *pCkh;
01405        ShIndex     *pShi;
01406        DhIndex     *pDhi;
01407        MhIndex     *pMhi;
01408        GbkIndex    *pGbki;
01409        BYTE        *pShArea;
01410        BYTE        *pDhArea;
01411        BYTE        *pMhArea;
01412        BYTE        *pGbkArea;
01413 
01414        pCkh     = (CikuHeader *)pCkAll;
01415        pShi     = (ShIndex  *)(pCkAll + pCkh->nIdxShPos);
01416        pDhi     = (DhIndex  *)(pCkAll + pCkh->nIdxDhPos);
01417        pMhi     = (MhIndex  *)(pCkAll + pCkh->nIdxMhPos);
01418        pGbki    = (GbkIndex *)(pCkAll + pCkh->nIdxGbkPos);
01419        
01420        pShArea  = (BYTE *)(pCkAll + pShi->nStartPos);
01421        pDhArea  = (BYTE *)(pCkAll + pDhi->nStartPos);
01422        pMhArea  = (BYTE *)(pCkAll + pMhi->nStartPos);
01423        pGbkArea = (BYTE *)(pCkAll + pGbki->nStartPos);
01424 
01425        nFindFlag = NON_EXIST_CIZU;
01426        memset(pchHz2244, '\0', 20);
01427        Jword2Uchar(pwHz2244, pchHz2244, nLenThis);
01428        
01429        /* nYjFirst must be in range 0~414 */
01430        nYjFirst = GbkHz2244ToYj((JINT)pwHz2244[0]);
01431 
01432        if (nLenThis >= 3)
01433        {
01434               /*
01435               **  Determine the FromOff and ToOff which to used for searching by the pnOrgYj[0].
01436               */
01437               nFromOff = pMhi->nYjOff[ nYjFirst ];
01438               nToOff   = pMhi->nYjOff[ nYjFirst + 1];
01439               
01440               /* !! DON'T add k++ in this FOR sentence !! */
01441               for (k = nFromOff; k < nToOff; )
01442               {
01443                      wMhLenFreq = (JWORD)*(pMhArea + k);
01444                      nCzLen     = 2 + ((UCHAR)*(pMhArea + k) & 0x07);
01445                      k++;
01446 
01447                      /*  It is just this Cizu, Set nFindFlag and return */
01448                      if ((nCzLen == nLenThis) &&
01449                             (strncmp((CHAR*)(&pMhArea[k]), (CHAR*)pchHz2244, 2 * nCzLen) == 0) )
01450                      {
01451                             nFindFlag  = SYS_EXIST_CIZU;
01452                             return nFindFlag;
01453                      }
01454                      /* Just Skip this Mh Word */
01455                      else
01456                             k += (2 * nCzLen);
01457               }
01458        }
01459        
01460        else if (nLenThis == 2)
01461        {
01462               /*
01463               **  Determine the FromOff and ToOff which to used for searching by the pnOrgYj[0].
01464               */
01465               nFromOff = pDhi->nYjOff[ nYjFirst ];
01466               nToOff   = pDhi->nYjOff[ nYjFirst + 1];
01467               
01468               /* !! DON'T add k++ in this FOR sentence !! */
01469               for (k = nFromOff; k < nToOff; )
01470               {
01471                      wFreq   = (JWORD)*(pDhArea + k);
01472                      nCzLen  = 2;
01473                      k++;
01474 
01475                      /* It is just this Cizu, Increase its frequence here. */
01476                      if (strncmp((CHAR*)(&pDhArea[k]), (CHAR*)pchHz2244, 4) == 0)
01477                      {
01478                             nFindFlag  = SYS_EXIST_CIZU;
01479                             return nFindFlag;
01480                      }
01481                      /* Just Skip this Dh Cizu */
01482                      else
01483                             k += 2 * nCzLen;
01484               }
01485        }
01486        
01487        else if (nLenThis == 1)
01488        {
01489               nFindFlag = SYS_EXIST_CIZU;
01490               return nFindFlag;
01491        }
01492        
01493        if (nFindFlag == NON_EXIST_CIZU)
01494        {
01495               nCurSize   = udcAll.udci.nYjOff[nYjFirst + 1] - udcAll.udci.nYjOff[nYjFirst];      /* In BYTE */
01496 
01497               /* NO i++ in this FOR sentence */
01498               for (i = 0; i < nCurSize / 2; )
01499               {
01500                      nUdc28FreqLen =  udcAll.pwUdc28[nYjFirst][i] & 0x00FF;
01501                      nUdc28Len     = (udcAll.pwUdc28[nYjFirst][i] & 0x0007) + 2;
01502                      i++;
01503 
01504                      /*  It is just this Cizu, Increase its frequence here. 
01505                      **
01506                      **  A Small & Big BUG was Arrested!! aHa!! 97-12-28!!
01507                      **  This bug appear in INTEL x86 CPU!!
01508                      if ((nUdc28Len == nLenThis) &&
01509                             (strncmp((CHAR*)&(udcAll.pwUdc28[nYjFirst][i]), (CHAR*)pchHz2244, 2 * nUdc28Len) == 0) )
01510                      */
01511                      if ((nUdc28Len == nLenThis) &&
01512                             (JwordNCmp(&(udcAll.pwUdc28[nYjFirst][i]), pwHz2244, nUdc28Len) == 0) )
01513                      {
01514                             nFindFlag  = UDC_EXIST_CIZU;
01515                             return nFindFlag;
01516                      }
01517                      else
01518                             i += nUdc28Len;
01519               }
01520        }
01521        
01522        return nFindFlag;      /* Must be NON_EXIST_CIZU HERE. */
01523 }
01524 
01525 
01526 /*
01527 **  Enumlate all those Mh, Dh and Sh selections in pSge->pwSlctHz
01528 **  AND call AdjustFreq().
01529 **  JWORD     pwSlctHz[512];     Selected Hanzi of Every Step, each seperated by 0009
01530 **  JWORD     pwSlctRawPy[512];  Crossponding Pinyin (include <'> <~>) of above Hz2244, septed by 0009
01531 **  JINT      nSlctSteps;        Step Number of Selection
01532 **
01533 **  This function may only be called after FULL COMMITTED!!!
01534 */
01535 VOID ProcFreq(SesGuiElement* pSge)
01536 {
01537        JINT    i, k, m;
01538        JWORD   wThisSel[9];        /* Contain Hz2244 Cizu Item */
01539        JINT    nLenThis;
01540 
01541        k = 0;
01542        nLenThis = 0;
01543        for(m = 0; m < 9; m++)
01544               wThisSel[m] = 0x0000;
01545 
01546        /* Don't add i++ and k++ in this FOR sentence */
01547        for (i = 0; (i < pSge->nSlctSteps) && (k < UTWO); )
01548        {
01549               if (pSge->pwSlctHz[k] == 0x0009)
01550               {
01551                      k++;
01552                      i++;
01553                      AdjustFreq(wThisSel, nLenThis);
01554                      for(m = 0; m < 9; m++)
01555                             wThisSel[m] = 0x0000;
01556                      nLenThis = 0;
01557               }
01558               else
01559               {
01560                      wThisSel[nLenThis] = pSge->pwSlctHz[k];
01561                      nLenThis++;
01562                      k++;
01563               }
01564        }
01565 }
01566