📄 hzindex.c
字号:
#include "stdio.h"
/*#include "malloc.h"*/
#include "string.h"
#include "hzindex.h"
#ifndef NULL
#define NULL 0
#endif
INDEX_STRUCT *g_IndexTable = NULL;
static void FillToBuf(void *,struct _hanzi_ *);
static void ParseSectionToBuf(void *,struct _hanzi_ *);
static void FillToBuf(void *buf,struct _hanzi_ *p)
{
unsigned short *tb = (unsigned short *)buf;
*tb = p->hzst.Val;
tb++;
*tb = p->hzed.Val;
tb++;
if((++p)->name[0] == '#')
FillToBuf(tb,p);
if( (p)->name[0] == '*')
ParseSectionToBuf(tb,p);
}
static void ParseSectionToBuf(void *buf,struct _hanzi_ *p)
{
/*计算出中间的汉字内码,填入缓冲 */
unsigned short *tb;
unsigned char val;
unsigned char tbuf[2];
tb = (unsigned short *)buf;
tbuf[0] = p->hzst.Low;
for(val = p->hzst.High;val <= p->hzed.High;val++)
{
tbuf[1] = val;
*tb = *(unsigned short *)tbuf;
tb++;
}
if( (++p)->name[0] == '*')
ParseSectionToBuf(tb,p);
if((p)->name[0] == '#')
FillToBuf(tb,p);
}
static void* GetLocal(int curlocal)
{
int i;
int curasc = 'a' + curlocal;
for( i = 0;i < TABLE_UNITS -1;i++)
if(HanziTable[i].name[0] == curasc)
return ( void *) & HanziTable[i];
return ( void *) & HanziTable[TABLE_UNITS -1];
}
/*
生成映离散表功能的索引结构
*/
int CreateIndex(void)
{
int i;
if(g_IndexTable != NULL)
free((unsigned char*)g_IndexTable);
g_IndexTable = (INDEX_STRUCT *)malloc(sizeof(INDEX_STRUCT));
if(g_IndexTable == NULL)
return 0;
memset(g_IndexTable,0,sizeof(INDEX_STRUCT));
for(i = 0;i < INDEX_SIZE;i++)
g_IndexTable->index[i] = GetLocal(i);
return 1;
}
/*
释放索引表
*/
void DestroyIndex(void)
{
if(g_IndexTable)
{
free(g_IndexTable);
g_IndexTable = NULL;
}
}
/*
由输入拼音得到汉字的内码 ,一次只能输入一个汉字的拼音
*/
int GetHzRangeBySpell(char *spell,void *hzbuf)
{
struct _hanzi_ *p,*p2,*tp;
int len ;
int ret;
if( (len = strlen(spell)) <= 0&&spell == NULL ) return 0;
p = (struct _hanzi_ *)g_IndexTable->index[spell[0] - 'a'];/*找出查找界*/
p2 = (struct _hanzi_ *)g_IndexTable->index[(spell[0] - 'a' + 1)];
for(tp = p ;tp < p2;tp++)/*在查找界中搜索*/
{
ret = strcmp(spell,(char *)tp->name) ;
if( ret < 0)
{
if(tp->name[len] == '#')
{
FillToBuf(hzbuf,tp);
return 1;
}
}
else if(ret == 0)
{
ParseSectionToBuf(hzbuf,tp);
return 1;
}
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -