Back to index

im-sdk  12.3.91
Functions
ParsePreedit.c File Reference
#include "PYIM.h"

Go to the source code of this file.

Functions

VOID DecompPeIntArray (JINT *pnOutPreedit, CHAR *szDspPreedit)
JINT MakeOPE (JINT nHalfMatchLen, JINT nIUVetc, JINT nYJCode)
VOID ParseRawInputStr (char *szPreedit, int *pnOutPreedit)
JINT GetNextUnit (char *szPreedit, JINT nPos, char *szNextUnit)
JINT MatchUnitByYinjie (char *szNextUnit)
VOID GetFirst9Yj (JINT *pnPrsYj, JINT *pnF9Yj, JINT *pnLen, JINT *pnMatchMode)

Function Documentation

VOID DecompPeIntArray ( JINT pnOutPreedit,
CHAR szDspPreedit 
)

Definition at line 63 of file ParsePreedit.c.

{
       JINT    i, j, tmp;
       JINT    nHalfMatchLen, nIUVetc, nYJCode;
       CHAR    szHalfMatch[7];
       
       i   = 0;
       tmp = 1;

       for (i = 0; i < 256; i++)
              szDspPreedit[i] = '\0';
              
       for (i = 0; pnOutPreedit[i] != 0; )
       {
              tmp = pnOutPreedit[i];
              nYJCode = tmp & 0x01FF;
              nIUVetc = (tmp >> 9) & 0x07;
              nHalfMatchLen = (tmp >> 12) & 0x0F;
              
              if (nIUVetc != 0)
              {
                     if (nIUVetc == 6)                        /* [$] */
                     {
                            strcat (szDspPreedit, "$");
                            i++;
                     }
                     else if (nIUVetc == 5)                   /* [#] */
                     {
                            strcat (szDspPreedit, "#");
                            i++;
                     }
                     else if (nIUVetc == 4)                   /* ['] */
                     {
                            strcat (szDspPreedit, "\'");
                            i++;
                     }
                     else                                      /* [i u v] */
                     {
                            /*
                            **  Add a space before [iuv] except that this is 
                            **  the first CHAR in Preedit string or a ['ivu]
                            **  ahead it.
                            **  MakeOPE(0, 1, 0) is 0000 001 000000000 = 0x0200 [i]
                            **  MakeOPE(0, 2, 0) is 0000 010 000000000 = 0x0400 [u]
                            **  MakeOPE(0, 3, 0) is 0000 011 000000000 = 0x0600 [v]
                            **  MakeOPE(0, 4, 0) is 0000 100 000000000 = 0x0800 [']
                            **
                            **  [#] and [$] don't affect [SPACE]
                            **
                            **  MakeOPE(0, 5, 0) is 0000 101 000000000 = 0x0A00 [#]
                            **  MakeOPE(0, 6, 0) is 0000 110 000000000 = 0x0C00 [$]
                            */
                            if ( (i > 0) && (pnOutPreedit[i-1] != 0x0200)    \
                                         && (pnOutPreedit[i-1] != 0x0400)    \
                                         && (pnOutPreedit[i-1] != 0x0600)    \
                                         && (pnOutPreedit[i-1] != 0x0800) )
                                   strcat (szDspPreedit, " ");
                            
                            if (nIUVetc == 1)
                                   strcat (szDspPreedit, "i");
                            else  if (nIUVetc == 2)
                                   strcat (szDspPreedit, "u");
                            else  if (nIUVetc == 3)
                                   strcat (szDspPreedit, "v");
                            i++;
                     }
              }
              
              else if ((nIUVetc == 0) && (nHalfMatchLen == 6))
              {
                     /*
                     ** A valid Yinjie code. Add a SPACE before
                     ** Yinjie string expect that there is a ['] ahead or it is the first.
                     ** MakeOPE(0, 4, 0) is 0000 100 000000000 = 0x0800
                     */
                     if ((i > 0) && (pnOutPreedit[i-1] != 0x0800))
                            strcat (szDspPreedit, " ");
                     
                     if (nYJCode >= 450)
                            strcat (szDspPreedit, SHENGMUSTR[nYJCode - 450]);
                     else if (nYJCode < 450)
                            strcat (szDspPreedit, YINJIESTR_CSZ[nYJCode]);
                            
                     i++;
              }
              
              else if ((nHalfMatchLen > 0) && (nHalfMatchLen < 6) && (nIUVetc == 0))
              {
                     for (j = 0; j < nHalfMatchLen; j++)
                            szHalfMatch[j] = (char)pnOutPreedit[i + j + 1];
                     szHalfMatch[j] = '\0';
                     if ((i > 0) && (pnOutPreedit[i-1] != 0x0800))
                            strcat (szDspPreedit, " ");
                     strcat (szDspPreedit, szHalfMatch);
                     i += (j + 1);
              }
              else
              {
                     i++;
                     fprintf (stderr, "Error in DecompPeIntArray()\n");
              }
       }
       
}
VOID GetFirst9Yj ( JINT pnPrsYj,
JINT pnF9Yj,
JINT pnLen,
JINT pnMatchMode 
)

Definition at line 545 of file ParsePreedit.c.

{
       JINT    i, nTmp1, nTmp2;
       JINT    nHalfMatchLen, nIUVetc, nYjcode;
       
       for(i = 0; i < 9; i++)
              pnF9Yj[i] = 0;

       *pnMatchMode = LU_MATCH_WIDELY;
       *pnLen       = 0;
       
       for (i = 0; (pnPrsYj[i] != 0) && ((*pnLen) < 9); )
       {
              nTmp1   = pnPrsYj[i];
              nTmp2   = pnPrsYj[i + 1];

              nYjcode       = nTmp1 & 0x01FF;
              nIUVetc       = (nTmp1 >> 9) & 0x07;
              nHalfMatchLen = (nTmp1 >> 12) & 0x0F;
              
              if ((nIUVetc == 0) && (nHalfMatchLen == 6))
              {
                     pnF9Yj[*pnLen] = nYjcode;
                     (*pnLen)++;
                     i++;
              }
              else if ((nIUVetc == 4) || (nIUVetc == 5) || (nIUVetc == 6))           /* ['][#][$] */
              {
                     i++;
                     nYjcode       = nTmp2 & 0x01FF;
                     nIUVetc       = (nTmp2 >> 9) & 0x07;
                     nHalfMatchLen = (nTmp2 >> 12) & 0x0F;
                     
                     if ((nIUVetc == 0) && (nHalfMatchLen == 6))
                     {
                            pnF9Yj[*pnLen]  = nYjcode + ((nIUVetc - 3) << 16);
                            (*pnLen)++;
                            i ++;
                     }
                     else
                     {
                            *pnMatchMode = LU_MATCH_STRICT;
                            break;
                     }
              }
              else
              {
                     *pnMatchMode = LU_MATCH_STRICT;
                     break;
              }
       }

       if (*pnMatchMode == LU_MATCH_WIDELY)
       {
              nTmp1   = pnPrsYj[i];

              nYjcode       = nTmp1 & 0x01FF;
              nIUVetc       = (nTmp1 >> 9) & 0x07;
              nHalfMatchLen = (nTmp1 >> 12) & 0x0F;
       
              if (nTmp1 == 0)
                     *pnMatchMode = LU_MATCH_WIDELY;
              else if ((nTmp1 != 0) && ((nIUVetc != 0) || (nHalfMatchLen != 6)))
                     *pnMatchMode = LU_MATCH_STRICT;
       }
}

Here is the caller graph for this function:

JINT GetNextUnit ( char *  szPreedit,
JINT  nPos,
char *  szNextUnit 
)
JINT MakeOPE ( JINT  nHalfMatchLen,
JINT  nIUVetc,
JINT  nYJCode 
)
JINT MatchUnitByYinjie ( char *  szNextUnit)
VOID ParseRawInputStr ( char *  szPreedit,
int *  pnOutPreedit 
)

Definition at line 196 of file ParsePreedit.c.

{
       CHAR    szNextUnit[10];
       JINT    nPELen;
       JINT    nCurOff, nOPEOff, nRef, nPy;
       JINT    nMatchFlag,  nMatchSMLen,  nMatchYMLenFit,  nMatchYMLenMax,  nMatchYinjie;
       JINT    nMatchFlag2, nMatchSMLen2, nMatchYMLenFit2, nMatchYMLenMax2, nMatchYinjie2;
       JINT    i, j, tmp, tmp1, tmp2;
       CHAR    cEnd, cNext;
       
       JINT    nHalfMatchLen, nIUVetc, nYJCode;

       nHalfMatchLen = nIUVetc = nYJCode = 0;
       nCurOff       = 0;
       nRef = nPy = 0;
       nOPEOff    = 0;
       
       nPELen = (int)strlen(szPreedit);
       
       while (nPELen > nCurOff)
       {
              for (i = 0; i < 10; i++)
                     szNextUnit[i] = '\0';
              
              tmp  = GetNextUnit(szPreedit, nCurOff, szNextUnit);
              nRef = (tmp >> 8) & 0x00FF;
              nPy  = tmp & 0x00FF;

              if (nRef == 1)           /* a ['] */
              {
                     pnOutPreedit[nOPEOff] = MakeOPE (0, 4, 0);
                     nOPEOff ++;
                     nCurOff ++;
              }
              else if (nRef == 2)      /* a [#] */
              {
                     pnOutPreedit[nOPEOff] = MakeOPE (0, 5, 0);
                     nOPEOff ++;
                     nCurOff ++;
              }
              else if (nRef == 3)      /* a [$] */
              {
                     pnOutPreedit[nOPEOff] = MakeOPE (0, 6, 0);
                     nOPEOff ++;
                     nCurOff ++;
              }
              
              if (nPy == 0)
              {
#ifdef _DEBUG
                     fprintf (stderr, "ParseRawInputStr() was exited from [nPy == 0]\n");
#endif
                     nCurOff = nPELen;    /* break;  OR: nCurOff = nPELen; */
              }
              else                        /* nPy > 0 */
              {
                     tmp = MatchUnitByYinjie (szNextUnit);
                     nMatchYMLenFit = (tmp >> 16) & 0x07;
                     nMatchFlag = (tmp >> 13) & 0x07;
                     nMatchSMLen = (tmp >> 12) & 0x01;
                     nMatchYMLenMax = (tmp >> 9) & 0x07;
                     nMatchYinjie = tmp & 0x01FF;
                     
                     tmp1 = nCurOff + nMatchSMLen + nMatchYMLenMax + 1;
                     
                     if (nMatchFlag == 1)
                     {
                            /* The first Char is [i][u][v] */
                            if (szNextUnit[0] == 'i')
                                   tmp = 1;
                            else if (szNextUnit[0] == 'u')
                                   tmp = 2;
                            else if (szNextUnit[0] == 'v')
                                   tmp = 3;
                                   
                            pnOutPreedit[nOPEOff] = MakeOPE(0, tmp, 0);
                            nOPEOff ++;
                            nCurOff ++;
                     }
                     /*
                     **   A Bug Fixed: ORG: zhonw => zhon w // NEW: zhonw => zh o n w
                     **   97-10-5
                     */
                     else if ( (nMatchFlag == 2) && (tmp1 == nPELen) )
                     {
                            nHalfMatchLen = nMatchSMLen + 1 + nMatchYMLenMax;
                            pnOutPreedit[nOPEOff] = MakeOPE (nHalfMatchLen, 0, 0);
                            nOPEOff ++;
                            for (j = 0; j < (nMatchSMLen + nMatchYMLenMax + 1); j++ )
                            {
                                   pnOutPreedit[nOPEOff] = (int)szNextUnit[j];
                                   nOPEOff ++;
                                   nCurOff ++;
                            }
                     }
                     else if (nMatchFlag == 0)
                     {
                            cEnd = szPreedit[nCurOff + nMatchSMLen + nMatchYMLenFit];
                            cNext = szPreedit[nCurOff + nMatchSMLen + 1 + nMatchYMLenFit];
                            
                            /*
                            ** G[aeou]  //  N[aeiouv]  //  R[aeiou]
                            */
                            if( ((cEnd == 'g') && ((cNext == 'a') || (cNext == 'e') ||     \
                                                 (cNext == 'o') || (cNext == 'u') ))       \
                             || ((cEnd == 'n') && ((cNext == 'a') || (cNext == 'e') ||     \
                                                   (cNext == 'i') || (cNext == 'o') ||     \
                                                   (cNext == 'u') || (cNext == 'v') ))     \
                             || ((cEnd == 'r') && ((cNext == 'a') || (cNext == 'e') ||     \
                                                   (cNext == 'i') || (cNext == 'o') ||     \
                                                   (cNext == 'u') )) )
                            {
                                   for (i = 0; i < (nMatchSMLen + nMatchYMLenFit); i++)
                                          szNextUnit[i] = szPreedit[nCurOff + i];
                                   for (i = (nMatchSMLen + nMatchYMLenFit); i < 7; i++)
                                          szNextUnit[i] = '\0';
                                   
                                   tmp2 = MatchUnitByYinjie (szNextUnit);
                                   nMatchYMLenFit2 = (tmp2 >> 16) & 0x07;
                                   nMatchFlag2 = (tmp2 >> 13) & 0x07;
                                   nMatchSMLen2 = (tmp2 >> 12) & 0x01;
                                   nMatchYMLenMax2 = (tmp2 >> 9) & 0x07;
                                   nMatchYinjie2 = tmp2 & 0x01FF;
                                   
                                   /*
                                   ** The following condition may be adjusted to get more
                                   ** precision and general. Thus, following syntax is equal.
                                   ** eran <==> er'an  ana <==> an'a  IS IT BEST????
                                   */
                                   if (nMatchFlag2 == 0)
                                   {
                                          nMatchYinjie = nMatchYinjie2;
                                          nMatchSMLen = nMatchSMLen2;
                                          nMatchYMLenFit = nMatchYMLenFit2;
                                   }
                            }
                            
                            pnOutPreedit[nOPEOff] = MakeOPE (6, 0, nMatchYinjie);
                            nOPEOff ++;
                            nCurOff += (nMatchSMLen + 1 + nMatchYMLenFit);
                     }
                     else
                     {
                            /* nMatchFlag = 3, or 2 in middle */
                            /* Setting nHalfMatchLen to 6 to avoid MakeOPE(0, 0, 0) */
                            
                            pnOutPreedit[nOPEOff] = MakeOPE (6, 0, nMatchYinjie);
                            nOPEOff ++;
                            nCurOff += (nMatchSMLen + 1 + nMatchYMLenFit);
                     }
              }
                     
       } /* End of While() */
       pnOutPreedit[nOPEOff] = 0;
}