📄 pinyin.c
字号:
/*
******************************************************************
* XIAMEN YAXON NETWORK CO.LTD.
* XINXI BUILDING,HULI,XIAMEN
* (c) Copyright 2002,XIAMEN YAXON NETWORK CO.LTD. ,XIAMEN
* All Rights Reserved
*
* FileName : PINYIN.C
* Programmer(s): YANGLEI
* Description :
******************************************************************
*****************************************************************
* REVISION HISTORY
*
* Date: 2003-03-12
*****************************************************************
*/
#define CHINESE_GLOBALS
#include "includes.h"
#include "Pinyin.h"
#include "Flash.H"
#include "Fonts.h"
//#include "UARTDrv.h"
//static INT16U PinYinIndex[] = {0x00,0x05,0x015,0x037,0x4d,0x50,0x59,0x6c,0x7f,0x7f,0x8d,0x9f,0xb8,0xcb,0xe2,0xe4,0xf5,0x103,0x111,0x134,0x147,0x147,0x147,0x150,0x15e,0x16d,0x191};
static INT16U NumberIndex[] = {0x00,0x37,0x59,0x7f,0xb8,0xe4,0x134,0x147,0x191};
//将匹配汉字的首地址集合写入到matchedindex中,返回匹配的个数
static INT8U temppy[30][6];
static INT16U P_Y_index_temp[100];
static INT8U SearchChineseByNumber(INT8U *number,INT8U numlen, INT8U *matchedindex)
{
INT16U upindex,downindex,i;
INT8U* pytblptr;//地址
INT8U totalmatch = 0;
INT16U tempcnt = 0,pycnt=0;
INT8U tempmatch[40];
if (*number < '2' || *number > '9') return INVALID_SEARCH;
downindex = NumberIndex[*number - '2'];
upindex = NumberIndex[*number - '2' + 1];
memset(P_Y_index,NULL,sizeof(P_Y_index));
memset(P_Y_index_temp,NULL,sizeof(P_Y_index_temp));
memset(matchpy, 0x20, sizeof(matchpy));
for (i=downindex;i<upindex;i++) {
pytblptr = (INT8U*)(PY_GB_BASE + sizeof(PYTBL) * i);
memcpy((INT8U*)&CurPyTbl,pytblptr,sizeof(PYTBL));// 将pytblptr指向的内容赋给CurPyTbl
if (CurPyTbl.pylen > numlen + 1) continue;
if (memcmp(number,CurPyTbl.key,numlen) == 0) {
if (CurPyTbl.pylen == numlen) {//完全匹配的
P_Y_index[pycnt] = i * sizeof(PYTBL);
*matchedindex++ = CurPyTbl.chstartH;
*matchedindex++ = CurPyTbl.chstartL;
memcpy(&matchpy[pycnt][0],CurPyTbl.py,numlen);
memset(&matchpy[pycnt][numlen],0x20,6-numlen);
pycnt++;
} else {
P_Y_index_temp[tempcnt] = i * sizeof(PYTBL);
tempmatch[2*tempcnt] = CurPyTbl.chstartH;//多一个字母的匹配
tempmatch[2*tempcnt+1] = CurPyTbl.chstartL;
memcpy(&temppy[tempcnt][0], CurPyTbl.py, numlen+1);
memset(&temppy[tempcnt][numlen+1],0x20,5-numlen);
tempcnt++;
}
totalmatch++;
}
}
if (totalmatch == 0) totalmatch = INVALID_SEARCH;
for(i = 0;i<tempcnt;i++) P_Y_index[pycnt+i] = P_Y_index_temp[i];//P_Y_index存放匹配的拼音表首地址
memcpy(matchedindex, tempmatch, 2 * tempcnt);
memcpy(matchpy[pycnt], temppy, 6 * tempcnt);//将非完全匹配的拼音加入到matchpy后
return totalmatch;
}
//将index所指向的被选汉字复制到tbl中
void GetChineseMessage(INT16U index,CHINESETBL *tbl)
{
INT8U *pytblptr;
memset(tbl, NULL, sizeof(tbl));
if (index >= MAX_SEARCH) return;
pytblptr = (INT8U*)(PY_GB_BASE + index);
memcpy((INT8U*)&CurPyTbl,pytblptr,sizeof(PYTBL));
tbl->pylen = CurPyTbl.pylen;
tbl->chlen = CurPyTbl.chlen / 2;
memcpy(tbl->py,CurPyTbl.py,CurPyTbl.pylen);
pytblptr = (INT8U*)(GBCODE_BASE + (((INT16U)(CurPyTbl.chstartH)<<8) & 0xff00) + CurPyTbl.chstartL);
memcpy(tbl->chinese,pytblptr,CurPyTbl.chlen);
}
//wordaddr表示字在字表中的偏移地址;phrasestartaddr表示这个字所组词的序列在词表的起始偏移地址
//注意:词表中存放的是词字在字表的偏移地址,而不是字的ASCII码
BOOLEAN SearchPhraseByWord(INT16U wordaddr, INT8U* phrasestartaddr, INT8U *PHRNum)
{
INT8U *pytblptr, *phrasetblptr;
INT16U TEMPA;
PHRASETBL CurPhraseTbl;
pytblptr = (INT8U*)(GBCODE_BASE + wordaddr);
if(IsASCII(pytblptr)==TRUE) return FALSE;
phrasetblptr = (INT8U*)(PHRASEINDEX_BASE + (wordaddr/2)*5);
memcpy((INT8U*) &CurPhraseTbl, phrasetblptr, sizeof(PHRASETBL));
if(((*pytblptr)==(*phrasetblptr))&&((*(pytblptr+1))==(*(phrasetblptr+1)))) {//字表中的字和词表索引中的符合
TEMPA = CurPhraseTbl.phrasestartH;
TEMPA = (TEMPA<<8)+CurPhraseTbl.phrasestartL;
memset(phrasestartaddr, 0x00, sizeof(phrasestartaddr));
memcpy(phrasestartaddr, (INT8U*)(PHRASECODE_BASE+TEMPA), CurPhraseTbl.phraselen);
*PHRNum = CurPhraseTbl.phraselen;
return TRUE;
}else{
return FALSE;
}
}
//形参*Input表示目前selebox.asciichar,key表示新输入的数字键,返回匹配的所有字符的偏移地址
INT8U *HZQuery(INT8U *Input, INT8U key)
{
INT8U i,CurPos;
for (i=0; i<6;i++) PYTemp[i] = Input[i];
for (i=0; PYTemp[i]!=0; i++) ;//找出PYTEMP[]中最新一个为0的数组项
PYTemp[i] = key;
CurPos = i;
MatchNum = SearchChineseByNumber(PYTemp, CurPos + 1, PYMatchAddr);
if (MatchNum ==INVALID_SEARCH) {
MatchNum = SearchChineseByNumber(Input, CurPos, PYMatchAddr);
} else {//输入的key有效
Input[CurPos] = key;
}
if(MatchNum==INVALID_SEARCH) return NULL;
return PYMatchAddr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -