Back to index

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

Go to the source code of this file.

Functions

JINT GbkHzcodeToYjcode (JINT nHzcode)
JINT GetNextLine (FILE *pfFile, CHAR *szBuf)
VOID ProcGbkHz (VOID)
VOID ReadGbkLine (VOID)
VOID CreateGbkHzcodeToYj ()
VOID TestGbkHzcodeToYj ()
JINT FastMatchYinJieStr (CHAR *szPystr)
JINT HzcodeToYjcode (JINT nHzcode)
VOID Show32To9Int (JUINT *pnHzYj32)

Variables

static UCHAR szGbkLine [30000][40]
static JWORD wGbkCode [30000]
static JINT nGbkYj [30000]
static JINT nGbkLine
JINT nGbkNumByYj [NUM_YINJIE]
JWORD wGbkHzByYj [NUM_YINJIE][400]
JINT nYj [0xFFFF]

Function Documentation

Definition at line 145 of file ProcGbk.c.

{
       JINT   i, j, k, w, nTmp, nHzcode;
       JUINT  nHzYj32[32];

       /* Init nYj[] Array */
       for (i = 0; i < 0xFFFF; i++)
              nYj[i] = 0x01FF;

       /* Fill nYj[] with data come from nGbkYj[] */
       w = 0;
       for (i = 0; i < nGbkLine; i++)
              if ((nGbkYj[i] >= 0) && (nGbkYj[i] < NUM_YINJIE))
              {
                     nYj[wGbkCode[i]] = nGbkYj[i];
                     w++;
              }
       printf("Valid Yinjie in nGbkYj is %d\n", w);

       /* I => High, J => Low */
       /* Recover these GB Info by GOOD data */
       w = 0;
       for (i = 0xB0; i <= 0xF7; i++)
              for (j = 0xA1; j <= 0xFE; j++)
              {
                     nHzcode = (i << 8) + j;
                     nTmp   = HzcodeToYjcode(nHzcode);
                     if ((nTmp >= 0) && (nTmp < NUM_YINJIE))
                     {
                            nYj[nHzcode] = nTmp;
                            w++;
                     }
              }
       printf("Valid Yinjie in HzcodeToYjcode() is %d\n", w);


       /* [0x8140 ~ 0xA0FE], include 0x??7F */
       /* 32 * 191 */
       w = 0;
       for (k = 0; k < 32; k++)
              nHzYj32[k] = 0x01FF;

       for (i = 0x81; i <= 0xA0; i++)
       {
              for (j = 0x40; j <= 0xFE; j++)
              {
                     nHzcode          = (i << 8) + j;
                     nHzYj32[w] = nYj[nHzcode];
                     w++;
                     if (w == 32)
                     {
                            Show32To9Int(nHzYj32);
                            w = 0;
                            for (k = 0; k < 32; k++)
                                   nHzYj32[k] = 0x01FF;
                     }
              }
       }
       if (w != 0)
              Show32To9Int(nHzYj32);
       printf("\n**0x8140 ~ 0xA0FE**\n");

       /* 85 * 191 */
       w = 0;
       for (k = 0; k < 32; k++)
              nHzYj32[k] = 0x01FF;

       for (i = 0xAA; i <= 0xFE; i++)
       {
              for (j = 0x40; j <= 0xFE; j++)
              {
                     nHzcode          = (i << 8) + j;
                     nHzYj32[w] = nYj[nHzcode];
                     w++;
                     if (w == 32)
                     {
                            Show32To9Int(nHzYj32);
                            w = 0;
                            for (k = 0; k < 32; k++)
                                   nHzYj32[k] = 0x01FF;
                     }
              }
       }
       if (w != 0)
              Show32To9Int(nHzYj32);
       printf("\n**0xAA40 ~ 0xFEFE**\n");
}

Here is the call graph for this function:

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);
}

Here is the caller graph for this function:

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 GetNextLine ( FILE *  pfFile,
CHAR szBuf 
)

Definition at line 889 of file NewPY.c.

{
       JINT    i = 0;
       
       do
       {
              fread (&szBuf[i], 1, 1, pfFile);
              i ++;
       } while (!feof(pfFile) && (szBuf[i-1] != 0x0A));
       
       szBuf[i-1] = '\0';
       if ((i >= 2) && (szBuf[i-2] == 0x0D))
              szBuf[i-2] = '\0';
       
       if (!feof(pfFile))
              return 1;
       else
              return 0;
}

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);
}

CreateGbkHzcodeToYj(); TestGbkHzcodeToYj();

Definition at line 27 of file ProcGbk.c.

{
       JINT   i, nTmp, nTmp2, nTmp3;

       ReadGbkLine();

       memset (nGbkNumByYj, '\0', NUM_YINJIE * sizeof(JINT));
       for (i = 0; i < NUM_YINJIE; i++)
              memset (wGbkHzByYj[i], '\0', 400 * sizeof(JWORD));

       nTmp2 = nTmp3 = 0;
       nTmp = 0;
       for (i = 0; i < nGbkLine; i++)
       {
              if (nGbkYj[i] != 0xFFFF)
              {
                     /* From 0xB0A1 to 0xF7FF was processed as Normal GB2312 Hanzi */
                     if( (wGbkCode[i] >= 0x8140) && ( ! ( ((wGbkCode[i] & 0xFF00) >= 0xB000) && ((wGbkCode[i] & 0xFF00) <= 0xF700)
                                                   && ((wGbkCode[i] & 0x00FF) >= 0x00A1))) )
                     {
                            wGbkHzByYj[nGbkYj[i]][nGbkNumByYj[nGbkYj[i]]] = wGbkCode[i];
                            nGbkNumByYj[nGbkYj[i]] ++;
                            nTmp2 ++;
                     }
              }
              else
              {
              /*     printf ("!!%s", szGbkLine[i]);     */
                     nTmp ++;
              }
       }
       printf ("Total %d Non_Standard Yinjie in < GBK.txt >\n", nTmp);

       for (i = 0; i < NUM_YINJIE; i++)
       {
              if ((i != 0) && (i % 5 == 0))
                     printf ("\n");
              printf("%3d|%-6s[%3d] ", i, YINJIESTR_CSZ[i], nGbkNumByYj[i]);
       }
       printf("\n");

}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 75 of file ProcGbk.c.

{
       FILE*  pfGbk;
       CHAR   szGbkName[] = "GBK.txt";
       UCHAR  szTmp[40];
       JINT   i, k, m, t2, t3;
       JINT   nTmp, nInvalidNum;

       pfGbk = fopen (szGbkName, "rb");
       if (pfGbk == NULL)
       {
              printf ("Failed to Open File %s\n", szGbkName);
              exit (FALSE);
       }

       k = 0;
       for (t2 = 1; t2 == 1;  )
       {
              memset(szTmp, '\0', 40);
              t2 = GetNextLine(pfGbk, (CHAR*)szTmp);
              t3 = strlen((CHAR*)szTmp);

              if (t3 > 2)
              {
                     for (m = 0; m < t3; m++)
                            szGbkLine[k][m] = szTmp[m];
                     k++;
              }
       }

       fclose (pfGbk);
       nGbkLine = k;
       printf("nGbkLine is %d\n", nGbkLine);

       /* Get GBK Hanzi Code. */
       memset (wGbkCode, 0, sizeof(JWORD) * 30000);
       for (i = 0; i < nGbkLine; i++)
              wGbkCode[i] = (JWORD)(((JWORD)szGbkLine[i][7] << 8) + szGbkLine[i][8]);

       /* Get GBK Yinjie Code. If not a standard Yinjie, use 0xFFFF instead */
       nInvalidNum = 0;
       memset (nGbkYj, 0, sizeof(JINT) * 30000);
       for (i = 0; i < nGbkLine; i++)
       {
              memset(szTmp, '\0', 40);
              for (k = 10; (szGbkLine[i][k] >= 'a') && (szGbkLine[i][k] <= 'z'); k++)
                     szTmp[k - 10] = szGbkLine[i][k];

              nTmp = FastMatchYinJieStr((CHAR*)szTmp);
              if (nTmp == -1)
              {
                     nGbkYj[i] = 0xFFFF;
                     nInvalidNum ++;
              }
              else
                     nGbkYj[i] = nTmp;
       }

       printf("nInvalidNum in GBK.txt is %d\n", nInvalidNum);
}

Here is the call graph for this function:

Here is the caller graph for this function:

VOID Show32To9Int ( JUINT pnHzYj32)

Definition at line 237 of file ProcGbk.c.

{
       JUINT  nNine[9];
       JUINT  i, nFrom, nTo, nToMode, nTmp1, nTmp2;

       for (i = 0; i < 9; i++)
              nNine[i] = 0x00000000;

       for (i = 0; i < 32; i++)
       {
              nFrom = (i * 9) / 32;
              nTo   = ((i + 1) * 9) / 32;
              if (nFrom == nTo)
              {
                     nToMode = 32 - (((i + 1) * 9) % 32);
                     nTmp1  = nNine[nFrom];
                     nTmp2  = pnHzYj32[i] << nToMode;
                     nTmp2  |= nTmp1;
                     nNine[nFrom] |= nTmp2;
              }
              else /* (nTo > nFrom) */
              {
                     nToMode = ((i + 1) * 9) % 32;

                     nTmp1  = nNine[nFrom];
                     nTmp2  = pnHzYj32[i] >> nToMode;
                     nTmp2  |= nTmp1;
                     nNine[nFrom] |= nTmp2;

                     nTmp1  = nNine[nTo];
                     nTmp2  = pnHzYj32[i] << (32 - nToMode);
                     nTmp2  |= nTmp1;
                     nNine[nTo] |= nTmp2;
              }
       }

       printf("    ");
       for (i = 0; i < 9; i++)
              printf("0x%08X, ", nNine[i]);
       printf("\n");
}

Here is the caller graph for this function:

Definition at line 280 of file ProcGbk.c.

{
       UCHAR  chHz[3];
       JINT   nHzcode;
       JINT   nYj;
       JINT   w;

       w = 0;
       chHz[2] = '\0';
       for (chHz[0] = 0x81; chHz[0] <= 0xFE; chHz[0]++)
       {
              for (chHz[1] = 0x40; chHz[1] <= 0xFE; chHz[1]++)
              {
                     nHzcode = ((JINT)chHz[0] << 8) + (JINT)chHz[1];
                     nYj    = GbkHzcodeToYjcode(nHzcode);
                     printf("0x%02X%02X  %s      ", (JUINT)chHz[0], (JUINT)chHz[1], chHz);
                     if (nYj == 0x01FF)
                            printf("[NONE]\n");
                     else if ((nYj >= 0) && (nYj < NUM_YINJIE ))
                     {
                            printf("%s\n", YINJIESTR_CSZ[nYj]);
                            w++;
                     }
                     else
                            printf("*Error*\n");
              }
       }

       printf("Valid Yinjie in GBKHZCODETOYJ[] is %d", w);
}

Here is the call graph for this function:


Variable Documentation

JINT nGbkLine [static]

Definition at line 21 of file ProcGbk.c.

Definition at line 23 of file ProcGbk.c.

JINT nGbkYj[30000] [static]

Definition at line 20 of file ProcGbk.c.

JINT nYj[0xFFFF]

Definition at line 25 of file ProcGbk.c.

UCHAR szGbkLine[30000][40] [static]

Definition at line 18 of file ProcGbk.c.

JWORD wGbkCode[30000] [static]

Definition at line 19 of file ProcGbk.c.

Definition at line 24 of file ProcGbk.c.