Back to index

im-sdk  12.3.91
Functions
PyBasic.c File Reference
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "GeneType.h"
#include "PyBasic.h"

Go to the source code of this file.

Functions

JINT GbkHzcodeToYjcode (JINT nHzcode)
JINT HzcodeToYjcode (JINT nHzcode)
JINT Hzcode2244ToYjcode (JINT nHzcode)
JINT Hzcode2244ToYjSMcode (JINT nHzcode)
JINT GetDyzInfo (JINT nHzcode, JINT *pnDyzYjCode)
JINT EncodeDyzTo2244 (JINT nHzcode, JINT nYjcode)
JINT FastMatchYinJieStr (CHAR *szPystr)
UCHARRecovDyz2244 (UCHAR *szDyz2244)
CHAR LastChar (JINT nYinjieCode)
CHAR FirstChar (JINT nYinjieCode)
JINT ValidButLastChar (JINT nYinjieCode)
JINT ValidButFirstChar (JINT nYinjieCode)
JINT ValidAddChar (CHAR ch, JINT nYinjieCode)

Function Documentation

JINT EncodeDyzTo2244 ( JINT  nHzcode,
JINT  nYjcode 
)

Definition at line 1769 of file PyBasic.c.

{
       JINT    nHiHzPos, nLowHz;
       JINT    i;
       
       nHiHzPos = ((nHzcode & 0xFF00) >> 8) - 0xB0;
       if ((nHiHzPos < 0) || (nHiHzPos > (0xF7 - 0xB0)))
              return 0xFFFF;

       nLowHz = nHzcode & 0x00FF;
       
       for (i = INDEXOFDYZLIST[nHiHzPos]; i < INDEXOFDYZLIST[nHiHzPos + 1]; i++)
       {
              if ( ((DYZLIST[i] & 0x00FF) == nLowHz) && (DYZYJCODE[i] == nYjcode) )
                     return (i + 0x2001);
       }
       
       return 0xFFFF;
}
JINT FastMatchYinJieStr ( CHAR szPystr)

Definition at line 1794 of file PyBasic.c.

{
       JINT    i, j, nLen;
       CHAR    chFirst;
       JINT    nFromYJStr, nToYJStr, nShengmuIndex;     
       
       i = 0;
       nLen = (JINT)strlen(szPystr);
       
       j = 0;
       if (nLen > 0)
       {
              chFirst    = szPystr[0];
              nFromYJStr = INDEXSMTOYINJIE[ INDEXMAGIC[(JINT)(chFirst - 'a')] ];
              nToYJStr   = INDEXSMTOYINJIE[ INDEXMAGIC[(JINT)(chFirst - 'a')] + 1];
              nShengmuIndex = INDEXMAGIC[(JINT)(chFirst - 'a')];
              
              if ((chFirst == 'c') && (nLen > 1) && (szPystr[1] == 'h'))
              {
                     nFromYJStr = INDEXSMTOYINJIE[3];
                     nToYJStr   = INDEXSMTOYINJIE[4];
                     nShengmuIndex = 3;
              }
              else if ((chFirst == 's') && (nLen > 1) && (szPystr[1] == 'h'))
              {
                     nFromYJStr = INDEXSMTOYINJIE[19];
                     nToYJStr   = INDEXSMTOYINJIE[20];
                     nShengmuIndex = 19;
              }
              else if ((chFirst == 'z') && (nLen > 1) && (szPystr[1] == 'h'))
              {
                     nFromYJStr = INDEXSMTOYINJIE[25];
                     nToYJStr   = INDEXSMTOYINJIE[26];
                     nShengmuIndex = 25;
              }

              i = nFromYJStr;
              do {
                     j = strcmp (YINJIESTR_CSZ[i], szPystr);
                     i++;
              } while ((i < nToYJStr) && (j != 0));
       }
       
       if (j == 0)
              return (i - 1);
       else
              return (-1);
}
CHAR FirstChar ( JINT  nYinjieCode)

Definition at line 1866 of file PyBasic.c.

{
       CHAR   res = ' ';           /* SPACE */
       
       if ((nYinjieCode >= 0) && (nYinjieCode <= 414))
              res = YINJIESTR_CSZ[nYinjieCode][0];
       return res;
}
JINT GbkHzcodeToYjcode ( JINT  nHzcode)

Definition at line 81 of file PyBasic.c.

{
       JINT   hi, low;
       JINT   res;
       JINT   t1, t2, t3, t4;

       hi  = (nHzcode >> 8) & 0x00FF;
       low = nHzcode & 0x00FF;
       t1  = t2 = t3 = t4 = 0;

       res = 0xFFFF;
       if ((hi >= 0x81) && (hi <= 0xA0) && (low >= 0x40) && (low <= 0xFE))
       {
              t1 = (hi - 0x81) * 191 + (low - 0x40) + 1;
              t2 = (t1 * 9 - 1) / 32;
              t3 = ((t1 - 1) * 9 - 1) / 32;
              t4 = (t1 * 9) % 32;

              if (t2 > t3)
                     res = (JINT)( (GBKHZCODETOYJ[t2] >> (32 - t4)) & 0x01FF ) +
                           (JINT)( (GBKHZCODETOYJ[t3] << t4) & 0x01FF );
              else if (t2 == t3)
                     res = (JINT)( GBKHZCODETOYJ[t2] >> (32 - t4) ) & 0x01FF;
       }
       else if ((hi >= 0xAA) && (hi <= 0xFE) && (low >= 0x40) && (low <= 0xFE))
       {
              t1 = (hi - 0xAA) * 191 + (low - 0x40) + 1;
              t2 = (t1 * 9 - 1) / 32;
              t3 = ((t1 - 1) * 9 - 1) / 32;
              t4 = (t1 * 9) % 32;

              if (t2 > t3)
                     res = (JINT)( (GBKHZCODETOYJ[t2 + (9 * 191)] >> (32 - t4)) & 0x01FF ) +
                           (JINT)( (GBKHZCODETOYJ[t3 + (9 * 191)] << t4) & 0x01FF );
              else if (t2 == t3)
                     res = (JINT)( GBKHZCODETOYJ[t2 + (9 * 191)] >> (32 - t4) ) & 0x01FF;
       }
       else if ((nHzcode >= 0x2001) && (nHzcode <= 0x2244))
       {
              t1 = nHzcode - 0x2000;
              t2 = (t1 * 9 - 1) / 32;
              t3 = ((t1 - 1) * 9 - 1) / 32;
              t4 = (t1 * 9) % 32;

              if (t2 > t3)
                     res = (JINT)( (DYZCODETOYJ[t2] >> (32 - t4)) & 0x01FF ) +
                           (JINT)( (DYZCODETOYJ[t3] << t4) & 0x01FF );
              else if (t2 == t3)
                     res = (JINT)( DYZCODETOYJ[t2] >> (32 - t4) ) & 0x01FF;
       }
       else
              res = 0xFFFF;

       if (res == 0x01FF)
              res = 0xFFFF;

       return (res);
}

Here is the caller graph for this function:

JINT GetDyzInfo ( JINT  nHzcode,
JINT pnDyzYjCode 
)

Definition at line 1739 of file PyBasic.c.

{
       JINT    nHiHzPos, nLowHz;
       JINT    i, j;
       
       nHiHzPos = ((nHzcode & 0xFF00) >> 8) - 0xB0;
       nLowHz   = nHzcode & 0x00FF;
       
       j = 0;
       if ((nHiHzPos < 0) || (nHiHzPos > (0xF7 - 0xB0)))
              return j;

       for (i = INDEXOFDYZLIST[nHiHzPos]; i < INDEXOFDYZLIST[nHiHzPos + 1]; i++)
       {
              if( (DYZLIST[i] & 0x00FF) == nLowHz )
              {
                     pnDyzYjCode[j] = DYZYJCODE[i];
                     j++;
              }
       }
       return j;
}

Definition at line 428 of file PyBasic.c.

{
       JINT   hi, low;
       JINT   res;
       JINT   t1, t2, t3, t4;

       hi = (nHzcode >> 8) & 0x00FF;
       low = nHzcode & 0x00FF;
       t1 = t2 = t3 = t4 = 0;
       res = 0xFFFF;

       if ((hi >= 0xB0) && (hi <= 0xF7) && (low >= 0xA1) && (low <= 0xFE))
       {
              t1 = (hi - 0xB0) * 94 + (low - 0xA1) + 1;
              t2 = (t1 * 9 - 1) / 32;
              t3 = ((t1 - 1) * 9 - 1) / 32;
              t4 = (t1 * 9) % 32;

              if (t2 > t3)
                     res = (int)( (GBHZCODETOYJ[t2] >> (32 - t4)) & 0x01FF ) +
                           (int)( (GBHZCODETOYJ[t3] << t4) & 0x01FF );
              else if (t2 == t3)
                     res = (int)( GBHZCODETOYJ[t2] >> (32 - t4) ) & 0x01FF;
       }
       else if ((nHzcode >= 0x2001) && (nHzcode <= 0x2244))
       {
              t1 = nHzcode - 0x2000;
              t2 = (t1 * 9 - 1) / 32;
              t3 = ((t1 - 1) * 9 - 1) / 32;
              t4 = (t1 * 9) % 32;

              if (t2 > t3)
                     res = (int)( (DYZCODETOYJ[t2] >> (32 - t4)) & 0x01FF ) +
                           (int)( (DYZCODETOYJ[t3] << t4) & 0x01FF );
              else if (t2 == t3)
                     res = (int)( DYZCODETOYJ[t2] >> (32 - t4) ) & 0x01FF;
       }
       else
              res = 0xFFFF;

       return (res);
}

Here is the caller graph for this function:

Definition at line 478 of file PyBasic.c.

{
       JINT   nTmpRes;
       JINT   nRet;

       nTmpRes = Hzcode2244ToYjcode(nHzcode);

       if (nTmpRes != 0xFFFF)
       {
              if ((nTmpRes >= 38) && (nTmpRes < 57 ))          /* "ch" */
                     nRet = 3 + 450;
              else if ((nTmpRes >= 301) && (nTmpRes < 320))    /* "sh" */
                     nRet = 19 + 450;
              else if ((nTmpRes >= 395) && (nTmpRes < 415))    /* "zh" */
                     nRet = 25 + 450;
              else
                     nRet = INDEXMAGIC[(JINT)(YINJIESTR_CSZ[nTmpRes][0] - 'a')] + 450;

              return nRet;
       }

       return 0xFFFF;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JINT HzcodeToYjcode ( JINT  nHzcode)

Definition at line 28 of file PyBasic.c.

{
       JINT   hi, low;
       JINT   res;
       JINT   t1, t2, t3, t4;

       hi  = (nHzcode >> 8) & 0x00FF;
       low = nHzcode & 0x00FF;
       t1  = t2 = t3 = t4 = 0;

       res = 0xFFFF;

       if ((hi == 0xD7) && (low >= 0xFA) && (low <= 0xFE))
              res = 0xFFFF;
       else if ((hi >= 0xB0) && (hi <= 0xF7) && (low >= 0xA1) && (low <= 0xFE))
       {
              t1 = (hi - 0xB0) * 94 + (low - 0xA1) + 1;
              t2 = (t1 * 9 - 1) / 32;
              t3 = ((t1 - 1) * 9 - 1) / 32;
              t4 = (t1 * 9) % 32;

              if (t2 > t3)
                     res = (JINT)( (GBHZCODETOYJ[t2] >> (32 - t4)) & 0x01FF ) +
                           (JINT)( (GBHZCODETOYJ[t3] << t4) & 0x01FF );
              else if (t2 == t3)
                     res = (JINT)( GBHZCODETOYJ[t2] >> (32 - t4) ) & 0x01FF;
       }
       else if ((nHzcode >= 0x2001) && (nHzcode <= 0x2244))
       {
              t1 = nHzcode - 0x2000;
              t2 = (t1 * 9 - 1) / 32;
              t3 = ((t1 - 1) * 9 - 1) / 32;
              t4 = (t1 * 9) % 32;

              if (t2 > t3)
                     res = (JINT)( (DYZCODETOYJ[t2] >> (32 - t4)) & 0x01FF ) +
                           (JINT)( (DYZCODETOYJ[t3] << t4) & 0x01FF );
              else if (t2 == t3)
                     res = (JINT)( DYZCODETOYJ[t2] >> (32 - t4) ) & 0x01FF;
       }
       else
              res = 0xFFFF;

       return (res);
}

Here is the caller graph for this function:

CHAR LastChar ( JINT  nYinjieCode)

Definition at line 1848 of file PyBasic.c.

{
       CHAR   res = ' ';           /* SPACE */
       JINT   i = 0;
       
       if ((nYinjieCode >= 0) && (nYinjieCode <= 414))
       {
              while (YINJIESTR_CSZ[nYinjieCode][i] != '\0')
                     i++;
              res = YINJIESTR_CSZ[nYinjieCode][i-1];
       }
       return res;
}
UCHAR* RecovDyz2244 ( UCHAR szDyz2244)

Definition at line 1972 of file PyBasic.c.

{
       JINT    i, j, nLen, nHlfLen;
       JINT    nDyzCode, nNormCode;
       static  UCHAR*  szNorm = NULL; 
   
       nLen = strlen((CHAR*)szDyz2244);
       nHlfLen = nLen / 2;

       if(szNorm != NULL)
              free(szNorm);

       szNorm = (UCHAR*)malloc(nLen + MALIGN);
       if (szNorm == NULL)
       {
              fprintf(stderr, "Failed to alloc Memory in function RecovDyz2244()\n");
              return (szNorm);
       }
       memset(szNorm, '\0', (nLen + MALIGN));
       
       j = 0;
       for (i = 0; i < nHlfLen; i++)
       {
              nDyzCode = szDyz2244[(2 * i) + 1] + ((JINT)szDyz2244[2 * i] << 8);
              if ((nDyzCode >= 0x2001) && (nDyzCode <= 0x2244))
              {
                     nNormCode         = DYZLIST[nDyzCode - 0x2001];
                     szNorm[2 * i]     = (UCHAR)((nNormCode & 0xFF00) >> 8);
                     szNorm[2 * i + 1] = (UCHAR)(nNormCode & 0x00FF);
              }
              else
              {
                     szNorm[2 * i]      = szDyz2244[2 * i];
                     szNorm[2 * i + 1]  = szDyz2244[2 * i + 1];
              }
       }
       
       return (szNorm);
}

Here is the caller graph for this function:

JINT ValidAddChar ( CHAR  ch,
JINT  nYinjieCode 
)

Definition at line 1909 of file PyBasic.c.

{
       JINT    i, nTmpRes;
       CHAR    szStr[7];
       
       for (i = 0; i < 7; i++)
              szStr[i] = '\0';

       szStr[0] = ch;
       if ((nYinjieCode >= 0) && (nYinjieCode <= 414))
       {
              i = 0; 
              while (YINJIESTR_CSZ[nYinjieCode][i])
              {
                     szStr[i + 1] = YINJIESTR_CSZ[nYinjieCode][i];
                     i++;
              }
                     
              nTmpRes = FastMatchYinJieStr(szStr);
              if(nTmpRes != -1)
                     return nTmpRes;
       }
       
       return 0xFFFF;
}

Here is the call graph for this function:

JINT ValidButFirstChar ( JINT  nYinjieCode)

Definition at line 1940 of file PyBasic.c.

{
       JINT    i, nTmpRes;
       CHAR    szStr[7];
       
       for (i = 0; i < 7; i++)
              szStr[i] = '\0';
       
       if ((nYinjieCode >= 0) && (nYinjieCode <= 414))
       {
              i = 0; 
              while (YINJIESTR_CSZ[nYinjieCode][i+1])
              {
                     szStr[i] = YINJIESTR_CSZ[nYinjieCode][i+1];
                     i++;
              }
                     
              nTmpRes = FastMatchYinJieStr(szStr);
              if(nTmpRes != -1)
                     return nTmpRes;
       }
       
       return 0xFFFF;
}

Here is the call graph for this function:

JINT ValidButLastChar ( JINT  nYinjieCode)

Definition at line 1880 of file PyBasic.c.

{
       JINT    i, nTmpRes;
       CHAR    szStr[7];
       
       for (i = 0; i < 7; i++)
              szStr[i] = '\0';
       
       if ((nYinjieCode >= 0) && (nYinjieCode <= 414))
       {
              i = 0; 
              while (YINJIESTR_CSZ[nYinjieCode][i+1])
              {
                     szStr[i] = YINJIESTR_CSZ[nYinjieCode][i];
                     i++;
              }
                     
              nTmpRes = FastMatchYinJieStr(szStr);
              if(nTmpRes != -1)
                     return nTmpRes;
       }
       return 0xFFFF;
}

Here is the call graph for this function: