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

📄 cb_dicprivate.c

📁 利用micorwindows实现英英词典 此为:底层操作api
💻 C
📖 第 1 页 / 共 3 页
字号:
/*-------------------------------------------------** $RCSfile$* $Date$* $Author$* $Log$* Revision 1.5  2004/11/05 03:15:28 * BugId:v6100-* modify by for fix bugs.** Revision 1.4  2004/10/26 08:26:04 * BugId:v6100-* modify by .** Revision 1.3  2004/10/25 09:46:41 * BugId:v6100-* modify by for 显示解释图片的排版.** Revision 1.2  2004/10/25 07:49:09 * BugId:v6100-* modify by for display expl and jpeg file.** Revision 1.1  2004/10/21 08:33:40 * BugId:v6100-* modify by . 开始些engine. 主要是从文件中取一屏数据.** Function	:* Usage         :* Version	:* Return Code   :* Revision      :* Remark        :*--------------------------------------------------*/#pragma far_pid_on#pragma far_pic_on#define	DEBUG	1#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>#if LINUX_FS#include <unistd.h>#include <dirent.h>#endif#include "pda/pdadef.h"#include "pub/gvdb/dbapi.h"#include "cb_dic/cb_dicengine.h"//move from oldv6100////////////+**********************************//+function:由单词id和id索引的基址计算该id在索引的位置//+input:	input_id	单词id//			Index_Addr	id索引的基地址(id索引标,文法索引标等等),由结构体bq_base_info确定//+返回值:			//			函数返回值就是地址//+**********************************LONG get_addr_from_id(BQ_Init_t *base_info,UINT input_id){	UINT id_temp;	LONG data_offset;	UINT16 data_len;	UINT32	id_index_unit;		#if	CAM_FILE_SYS	GGV_FILE *fp;#else	FILE *fp;#endif	fp=base_info->fp;	id_temp=input_id/128;	data_offset=(LONG)(id_temp*PHY_INDEX_LEN+base_info->ID_INDEX_OFFSET);						#if	CAM_FILE_SYS	GGV_sseek(fp,data_offset,SEEK_SET);	id_index_unit=0;	GGV_sread((CHAR *)&id_index_unit,sizeof(UINT32),1,fp);#else	fseek(fp,data_offset,SEEK_SET);	id_index_unit=0;	fread(&id_index_unit,sizeof(UINT32),1,fp);#endif		data_offset=(LONG)id_index_unit;	id_temp=input_id%128;	while(id_temp)	{	#if	CAM_FILE_SYS		GGV_sseek(fp,data_offset,SEEK_SET);		data_len=0;		GGV_sread((CHAR *)&data_len,sizeof(UINT16),1,fp);	#else		fseek(fp,data_offset,SEEK_SET);		data_len=0;		fread(&data_len,sizeof(UINT16),1,fp);	#endif		data_offset=(LONG)data_len+data_offset;		id_temp--;	}	return data_offset;					}//+******************************************//+ function name :search_yb_flag//+ Function:	判断解压缩出来的部分主题词编码是否包含音标得标志,//+				如果包含则在此位置替换为0//+ Input:	//+			str		源字符串//+ Output:str//+ return:	没有找到返回0;找到了返回1,错误返回-1  //+ Destroy://+******************************************INT search_yb_flag(UCHAR *str){	CHAR *off;	CHAR yb_flag=0x04;	if(strlen(str)>MAX_LENGTH_ONE_CODE)	return -1;	off=strchr(str,yb_flag);	if(off==NULL) return 0;	else{		*off=0;		return 1;	}}//+**********************************//+function:code_buf中内容需要左移4位//+input:	code_buf//+output : code_buf//+**********************************void asl3_code_buf(BYTE *code_buf){		BYTE tmp1,tmp2,tmp3;	tmp1=((*code_buf)<<4);	tmp1=tmp1|(*(code_buf+1)>>4);	tmp2=((*(code_buf+1))<<4);	tmp2=tmp2|(*(code_buf+2)>>4);	tmp3=((*(code_buf+2))&0xf)<<4;	*code_buf=tmp1;	*(code_buf+1)=tmp2;	*(code_buf+2)=tmp3;}//+**************************************************************************************************//+function:根据压缩编码解读高频词的索引,并解压出数据//+input://+			index_unit	编码索引数据单元 --即编码数据的地址,这里是一个绝对地址//+			read_len	高频词数据长度//+output:	code_data_buf	output code data to here//+**************************************************************************************************INT read_code_data(BQ_Init_t *base_info,int code_level,BYTE *CodeBuf,UCHAR *code_data_buf) {	UINT code_index;	UINT nxt_code_index;	UINT freq_word_len=0;	LONG code_fp_off;	UINT unzip_code;	UINT tmp;	UINT tmp2;#if	CAM_FILE_SYS	GGV_FILE *fp=base_info->fp;#else	FILE *fp=base_info->fp;#endif	switch(code_level)	{	case 1:			unzip_code=((UINT)(*CodeBuf)>>4) & LEVEL1_COMP_CODE;			code_fp_off=base_info->CODE1_INDEX_OFFSET+unzip_code*CODE_INDEX_LEN;			break;		case 2:			unzip_code=(UINT)((*CodeBuf)&0x30)<<4;			tmp=(UINT)( (*(CodeBuf+1))&0xf0 )>>4;			tmp2=(UINT)((*CodeBuf)&0x0f)<<4;			unzip_code = unzip_code|tmp|tmp2; 			code_fp_off=base_info->CODE2_INDEX_OFFSET+unzip_code*CODE_INDEX_LEN;			break;		case 3:			unzip_code=(UINT)(*CodeBuf & LEVEL3_COMP_CODE)<<8;			unzip_code+=*(CodeBuf+1);			code_fp_off=base_info->CODE3_INDEX_OFFSET+unzip_code*CODE_INDEX_LEN;			break;		case 4:			unzip_code=(UINT)(*CodeBuf & LEVEL4_COMP_CODE)<<4;			unzip_code+= ( (UINT)(*(CodeBuf+1))>>4)       ;			unzip_code=(UINT)(unzip_code<<8);			tmp=*(CodeBuf+1);			tmp=tmp&0x0f;			tmp=(tmp<<4);			tmp2=*(CodeBuf+2);			tmp2=(tmp2>>4);			unzip_code+=tmp + tmp2 ;			code_fp_off=base_info->CODE4_INDEX_OFFSET+unzip_code*CODE_INDEX_LEN;			break;		default:				return(-1);	}#if	CAM_FILE_SYS	GGV_sseek(fp,code_fp_off,SEEK_SET);	code_index=0;	GGV_sread((CHAR *)&code_index,sizeof(UINT32),1,fp);	nxt_code_index=0;	GGV_sread((CHAR *)&nxt_code_index,sizeof(UINT32),1,fp);	freq_word_len=nxt_code_index-code_index;	code_fp_off=(LONG)code_index;	GGV_sseek(fp,code_fp_off,SEEK_SET);	GGV_sread((CHAR *)code_data_buf,sizeof(UCHAR),freq_word_len,fp );#else	fseek(fp,code_fp_off,SEEK_SET);	code_index=0;	fread(&code_index,sizeof(UINT32),1,fp);	nxt_code_index=0;	fread(&nxt_code_index,sizeof(UINT32),1,fp);	freq_word_len=nxt_code_index-code_index;	code_fp_off=(LONG)code_index;	fseek(fp,code_fp_off,SEEK_SET);	fread(code_data_buf,sizeof(UCHAR),freq_word_len,fp );#endif	return 0;}//+**********************************//+function:从输入指针取得一个编码数据,解码,修改相应的指针和标志//+input:	half_part_flag//			data_ptr//			code_data_buf	存放解出的内容到一个用户指定的字符串中//			4bit_counter	取出了几个4bits//+返回值:	取出了几个4bits//+UPDATE:  code_offset		//动态更新的,指向下面的内容//+**********************************int get_code(BQ_Init_t *base_info,BOOL *half_part_flag,LONG *code_offset,BYTE *code_data_buf){	BYTE code_buf[CODE_BUF_LEN];#if	CAM_FILE_SYS	GGV_FILE *fp;#else	FILE *fp;#endif#if LINUX_FS	bzero(code_data_buf,MAX_LENGTH_ONE_CODE);#else	memset(code_data_buf,0,MAX_LENGTH_ONE_CODE);#endif	fp=base_info->fp;#if	CAM_FILE_SYS	GGV_sseek(fp,*code_offset,SEEK_SET);	GGV_sread((CHAR *)code_buf,CODE_BUF_LEN,1,fp);#else	fseek(fp,*code_offset,SEEK_SET);	fread(code_buf,CODE_BUF_LEN,1,fp);#endif	if(*half_part_flag!=FIRST_HALF){		asl3_code_buf(code_buf);	}									if( (code_buf[0]&0x80)==0)	{			read_code_data(base_info,1,code_buf,code_data_buf);		if(*half_part_flag==FIRST_HALF){			*half_part_flag=SECOND_HALF;		}		else {			*half_part_flag=FIRST_HALF;			*code_offset+=1;		}		return(1);	}												//======================================	else if( (code_buf[0]&0xc0)==0x80 )	{		read_code_data(base_info,2,code_buf,code_data_buf);		if(*half_part_flag==FIRST_HALF){			*half_part_flag=SECOND_HALF;			*code_offset+=1;		}		else { 			*half_part_flag=FIRST_HALF;						*code_offset+=2;		}		return(3);	}													//======================================	else if( (code_buf[0]&0xe0)==0xc0 )	{														read_code_data(base_info,3,code_buf,code_data_buf);											*code_offset+=2;				return(4);				}													//======================================	else if( (code_buf[0]&0xf0)==0xe0 )		{							read_code_data(base_info,4,code_buf,code_data_buf);							if(*half_part_flag==FIRST_HALF){ 			*half_part_flag=SECOND_HALF;			*code_offset+=2;		}		else{			*half_part_flag=FIRST_HALF;			*code_offset+=3;		}		return(5);			}													//======================================	else if( code_buf[0] == (BYTE)0xf0 )	{						*code_data_buf=code_buf[1];		*(code_data_buf+1)='\0';		*code_offset+=2;			return(4);			}													//======================================	else{					asl3_code_buf(code_buf);		*code_data_buf=*code_buf;		*(code_data_buf+1)=*(code_buf+1);		*(code_data_buf+2)='\0';		if(*half_part_flag==FIRST_HALF){			*half_part_flag=SECOND_HALF;			*code_offset+=2;		}		else {			*half_part_flag=FIRST_HALF;			*code_offset+=3;		}		return(5);	}		}//+*******************************************************************//+ Function:解码单词的关键字,由入口地址指针解码到目标,共解get_word_len个byte//+				如果单词不到指定的长度就解压实际的长度,否则解到指定的长度为stop//+ Input:	//+		base_info//+		code_len		取数据的长度//+		input_ptr		要去code所在的地址//+ Output://+		output_addr		解码的目的地址//+ return://+					实际解码长度//+ Destroy://+ Note://+*********************************************************************INT decode_buf_s(BQ_Init_t *base_info,UINT code_len,LONG data_fp_offset,UCHAR *out_ptr){	UCHAR code_data_buf[MAX_LENGTH_ONE_CODE+1];	BOOL half_part_flag=FIRST_HALF;		LONG cur_code_offset=data_fp_offset;	INT y=0;	*out_ptr=0;	while(strlen(out_ptr)<=MAX_ITEM_LEN)	{#if LINUX_FS		bzero(code_data_buf,MAX_LENGTH_ONE_CODE);#else		memset(code_data_buf,0,MAX_LENGTH_ONE_CODE);#endif		get_code(base_info,&half_part_flag,&cur_code_offset,code_data_buf);		y=search_yb_flag(code_data_buf);		if(y==0)			strcat (out_ptr,code_data_buf);		else if(y==-1)			break;	//error!		else if(y==1){			strcat (out_ptr,code_data_buf);			break;		}		else{;}	}	return (strlen(out_ptr));}//**********function is over ***************//+*****************************************************************************//+ Function:	在逻辑地址解压单词放在缓冲区地址curr_word_buf中(主题词部分)//+ Input://+		cur_id			取单词的ID//+		base_info		//+		data_logic_addr	要去单词所在的逻辑地址//+		get_word_len	取多少字节//+ Output:  //+		word_length		当前单词解释长度//+		curr_word_buf	存放当前单词的头若干字节(由get_word_len指定)//+	//+ Destroy://+ Note://+*****************************************************************************void get_word(BQ_Init_t *base_info,UINT cur_id,LONG data_logic_offset,		UINT get_word_len,UINT *word_length,UCHAR *curr_word_buf){	UINT16	data_len_tmp;							UINT syntax_state;		LONG data_fp_off;#if	CAM_FILE_SYS	GGV_FILE *fp = base_info->fp;	GGV_sseek(fp, data_logic_offset, SEEK_SET);	data_len_tmp = 0;	GGV_sread( (CHAR *) &data_len_tmp, sizeof(UINT16), 1, fp );	*word_length = (UINT)data_len_tmp;	syntax_state = 0;	GGV_sread( (CHAR *) &syntax_state, 1, 1, fp );#else	FILE *fp=base_info->fp;	fseek(fp, data_logic_offset, SEEK_SET);	data_len_tmp = 0;	fread( &data_len_tmp, sizeof(UINT16),1 , fp );	*word_length = (UINT)data_len_tmp; 	syntax_state = 0;	fread( &syntax_state, 1, 1, fp);#endif	if(syntax_state){							data_fp_off=data_logic_offset+2+1+3 ;	}else{											data_fp_off=data_logic_offset+3;	}	decode_buf_s(base_info,get_word_len,data_fp_off,curr_word_buf);}//+*******************************************************//+ Function:	get the word item by logic id//+ Input:	base_info: the struct of the initiazed //+				input_id:索要查找的单词id//+ Output:		output_str:输出主题词的字符串//+				BQ_data_addr下一个单词的地址//+ retrun:	0成功,非零失败//+ Destroy://+ Note://+*******************************************************INT cbp_get_word_item(BQ_Init_t *base_info,UINT input_id, CHAR *output_str){	UINT  data_size=0;

⌨️ 快捷键说明

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