⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uiime_py.c

📁 嵌入工linux开发的源码
💻 C
字号:
/*********************************************************************/
//	文 件 名:	uiIme_PY.cpp
//	程序说明:	拼音输入法
//	程序设计:	张学平
//				2001.11.05		设计完成		说明文档:R004-S240-0001
//	程序审查:	宋军霞
//				2002.01.25		审查完成		说明文档:R004-S240-0001
//	项目编号:	R004-S240
//	版	  本:	V1.0
//	版    权:	Reality Plus Technology (ShenZhen) Co.,Ltd.
/*********************************************************************/
#include "uiIme_py.h"
#include "uiPY_TBL.res"
#include "uiPY_WORD.res"

/***********************************************
* pyStr:  code of pinying                      *
* offset: offset of candidate word             *
* return: total count of candidate word        *
************************************************/
int guiIme_py(char *pyStr, DWORD *offset)
{
	unsigned short iMid, iLeft, iRight;
	unsigned short startOffset, endOffset, index;
	char *pTemp;
	int iRet, len, wordNum;

	iLeft = 0;  iRight = PY_TABLE_COUNT-1;
	len = strlen(pyStr);
	if(!len)
		return 0;
	strlwr(pyStr);
	while(1)
	{
		iMid = (iRight+iLeft)/2;

		pTemp = (char *)PY_TABLE[iMid].codeStr;

		iRet = strncmp(pyStr, pTemp, len);
	
		if(!iRet)
		{
			startOffset = iMid;
			while(startOffset)
			{
				startOffset--;
				pTemp = (char *)PY_TABLE[startOffset].codeStr;
				iRet = strncmp(pyStr, pTemp, len);
				if(iRet)
				{
					startOffset++;
					break;
				}
				
			}
			
			endOffset = iMid;
			
			while(endOffset<PY_TABLE_COUNT)
			{				
				pTemp = (char *)PY_TABLE[endOffset].codeStr;

				iRet = strncmp(pyStr, pTemp, len);
				if(iRet)
					break;
				endOffset++;
			}
			if(endOffset==PY_TABLE_COUNT)
				endOffset--;
			
			index = PY_TABLE[startOffset].offset;
			*offset = (DWORD)&(PY_GB_WORD[index]);

			wordNum = PY_TABLE[endOffset].offset-index;
			if(!iRet)
				wordNum = PY_TABLE[endOffset].offset-index+PY_LAST_REPEATCOUNT;

			return (wordNum);
		}

		if(iRet<0)
			iRight = iMid-1;
		else
			iLeft = iMid+1;

		if(iLeft>iRight)
			break;
	}

	*offset = 0;
	return 0;
}

/******************************************************************
* offset: offset of candidate word, get from guiIme_py()          *
* totalCount: total count of candidate word, get form guiIme_py() *
* startPos: start position of word to read                        *
* toReadCount: number of word to read                             *
* pWordText: buffer of word                                       *
* return: actual number of word read                              *
*******************************************************************/
int guiGetCandidate_py(DWORD offset, unsigned short totalCount, unsigned short startPos, unsigned short toReadCount, unsigned short *pWordText)
{
	unsigned short *pWord;
	int readCount, i;
	
	if(!offset)
		return 0;

	if(startPos>totalCount)
		return 0;

	pWord = (unsigned short *)(offset+2*startPos);

	readCount = (totalCount>startPos+toReadCount)?toReadCount:(totalCount-startPos);

	for(i=0; i<readCount; i++)
		pWordText[i] = pWord[i];
	
	pWordText[readCount] = 0x0000; 
	
	return readCount;
}

#if _DEBUG && _DEBUG_IME_PY
unsigned short guiGetPy_Table(int index, char *pStr) 
{
	if(index >= PY_TABLE_COUNT)
		return 0;

	strcpy(pStr,PY_TABLE[index].codeStr);
	return PY_TABLE[index].offset;
}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -