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

📄 cb_dicengine.c

📁 利用micorwindows实现英英词典 此为:底层操作api
💻 C
📖 第 1 页 / 共 3 页
字号:
			break;		case CB_SCROLL_LINE:			line = 1;			break;		default:			return	CB_RTN_ERROR;	}	if(list_info->faint_flag == 0){	//not faintly disp list		switch( num ) {			case CB_GET_UP:			case CB_GET_DOWN:			case CB_HOME_SCREEN:			case CB_END_SCREEN:				if( num == CB_GET_UP ){					if( list_info->top_word_id == 0 ) {					return	CB_RTN_ERROR;				}				list_info->top_word_id -= line;				if( list_info->top_word_id < 0 ){					list_info->top_word_id = 0;				}			} else if( num == CB_GET_DOWN ) {				if( list_info->top_word_id + list_info->page_dispnum >= 						BQ_base_info->last_word_id+1 ) {					return	CB_RTN_ERROR;				}				list_info->top_word_id += line;			} else if( num == CB_HOME_SCREEN ){				list_info->top_word_id = 0;			} else if( num == CB_END_SCREEN ){				list_info->top_word_id = BQ_base_info->last_word_id+1 -								list_info->page_dispnum;				if( list_info->top_word_id < 0 ) {					list_info->top_word_id = 0;				}			}			//no break;		case CB_CUR_SCREEN:			i = 0;			for( cur_id = list_info->top_word_id;      				cur_id < (list_info->top_word_id + list_info->page_dispnum); 					cur_id++ ) {				cbp_get_word_item( BQ_base_info, cur_id, (list+i)->word);				if(  cur_id  >= BQ_base_info->last_word_id )break;				i++;			}			return	cbp_get_list_ret( BQ_base_info, list_info );		}	}else{		//faintly list		switch( num ) {			case CB_GET_UP:			case CB_GET_DOWN:				if( num == CB_GET_UP ){					if( list_info->top_word_id == 0 ) {						return	CB_RTN_ERROR;					}					for( i = 0, cur_id = list_info->top_word_id; i < list_info->page_dispnum; i++ ){						cur_id = cbe_get_pre_word( cur_id,(UCHAR*)list_info->inputStr);						if( cur_id  == CB_RTN_ERROR )	//reach to the last matched							return CB_RTN_ERROR;					}					list_info->top_word_id = cur_id;					}else if( num == CB_GET_DOWN ){					if( list_info->top_word_id == 0 )						return	CB_RTN_ERROR;					for( i = 0, cur_id = list_info->top_word_id; i < list_info->page_dispnum; i++ ){						if( ( cur_id ) >= BQ_base_info->last_word_id )break;						cur_id = cbe_get_next_word( cur_id,(UCHAR*)list_info->inputStr);						if( cur_id  == CB_RTN_ERROR )	//reach to the last matched							return CB_RTN_ERROR;					}					list_info->top_word_id = cur_id;					}				//no break;			case CB_CUR_SCREEN:				for( i = 0,cur_id = list_info->top_word_id; i < list_info->page_dispnum; ){					cbp_get_word_item( BQ_base_info, cur_id, (list+i)->word);					if( ( cur_id ) >= BQ_base_info->last_word_id )break;					cur_id = cbe_get_next_word( cur_id,(UCHAR*)list_info->inputStr);					i++;					if(  cur_id  == CB_RTN_ERROR )	//reach to the last matched						break;									}				//the icon need to do								//return	cbp_get_list_ret( BQ_base_info, list_info );			}		}	return	CB_RTN_ERROR;}/**********************************************Func:	get detail due to current id*In:	logic_id -> current word logic id*Out:	*word_detail -> where save detail*I/O:*Modify:*Return:success -> CB_RTN_OK	fail	-> CB_RTN_ERROR*Author:**********************************************/INT8 move_to_his( INT32 word_id ){	CB_HIS_RECORD rec;	if(his_fd <= 0)return CB_RTN_ERROR;	rec.word_id = word_id;	DBselidx(his_fd, &cb_his_db_index[0]);	return DBinsert(his_fd, (UCHAR*)&rec);}/*****************************************************************func:	 new word insert*in:	*out:	 *i/o:*modify:*return: *author: ******************************************************************/INT8 cbe_to_nw_db( INT32 wordID ){	CB_NW_RECORD rec;	if(nw_fd <= 0)return CB_RTN_ERROR;	rec.word_id = wordID;	DBselidx(nw_fd, &cb_nw_db_index[0]);	return DBinsert(nw_fd, (UCHAR*)&rec);}/**********************************************Func:	history:get detail due to current id*In:	current word id*Out:	*word_detail -> where save detail*I/O:*Modify:*Return:success -> CB_RTN_OK	fail	-> CB_RTN_ERROR*Author:**********************************************/INT8 cbe_get_his_detail( CB_WORD_DETAIL *word_detail, const INT32 record_id, INT8 fancha_flag){	INT32 word_id;	if( BQ_base_info->fp == NULL )	return	CB_RTN_ERROR;	word_id = cbp_his_read_record( his_fd, record_id );	word_detail->word_id = word_id;	if( word_id >= BQ_base_info->last_word_id + 1 )return CB_RTN_ERROR;	memset(word_detail,0,sizeof(CB_WORD_DETAIL));	//先不考虑反查:fancha_flag:0	cbp_get_word_data(BQ_base_info, word_id, 0, word_detail, 0);	return	CB_RTN_OK;}/**********************************************Func:	new word:get detail due to current id*In:	current word id*Out:	*word_detail -> where save detail*I/O:*Modify:*Return:success -> CB_RTN_OK	fail	-> CB_RTN_ERROR*Author:**********************************************/INT32 cbe_get_nw_detail( CB_WORD_DETAIL *word_detail, const INT32 record_id, INT8 fancha_flag){	INT32 word_id;	if( BQ_base_info->fp == NULL )	return	CB_RTN_ERROR;	word_id = cbp_nw_read_record( his_fd, record_id );	word_detail->word_id = word_id;	if( word_id >= BQ_base_info->last_word_id + 1 )return CB_RTN_ERROR;	memset(word_detail,0,sizeof(CB_WORD_DETAIL));	//先不考虑反查:fancha_flag:0	cbp_get_word_data(BQ_base_info, word_id, 0, word_detail, 0);	return	CB_RTN_OK;}/**********************************************Func:	get detail due to current id*In:	logic_id -> current word logic id*Out:	*word_detail -> where save detail*I/O:*Modify:*Return:success -> CB_RTN_OK	fail	-> CB_RTN_ERROR*Author:**********************************************/INT8 cbe_get_detail( CB_WORD_DETAIL *word_detail, const INT8 logic_id, INT8 fancha_flag){	INT32	cur_id;	if( BQ_base_info->fp == NULL )	return	CB_RTN_ERROR;	cur_id = logic_id + list_info->top_word_id;	word_detail->word_id = cur_id;	if( cur_id >= BQ_base_info->last_word_id + 1 )return CB_RTN_ERROR;	memset(word_detail,0,sizeof(CB_WORD_DETAIL));	//先不考虑反查:fancha_flag:0	cbp_get_word_data(BQ_base_info, cur_id, 0, word_detail, 0);	move_to_his(cur_id);	return	CB_RTN_OK;}//+******************************************//+ function :得到纯字母串//+ Input:   	//+		input_str//+	output:	//+		output_str //+******************************************void key_buf_proc(CHAR *input_str,CHAR *output_str){	int i=0;	int j=0;	CHAR ch;	*output_str=0;	while(i <= MAX_INPUT_LEN)	{		ch=*(input_str+i);		i++;		if(isalpha(ch)){			*(output_str+j)=tolower(ch);			j++;			*(output_str+j)=0;		}		if(ch==0){			*(output_str+j)=0;			break;		}	}}//************************************************************//function : get the pure item string,made of only alpha ////处理原则:	<> () 中得内容删除包括括号	//				obj、Aus,Br等内容及其之后字符删除掉//				遇到标点符号则删除//				删除多余的空格//************************************************************void get_pure_item(UCHAR *out_str,UCHAR *input_str){	int i,j;	int input_len;	CHAR *str_ptr;	UCHAR ch;	CHAR str_tmp[MAX_ITEM_LEN+1];	for(i=0;i<MAX_ITEM_LEN+1;i++)		str_tmp[i]=0;	input_len=strlen(input_str);	str_ptr=strchr(input_str,',');	if(str_ptr!=NULL) *str_ptr=0;	str_ptr=strchr(input_str,'<');	if(str_ptr!=NULL)	{		ch=*str_ptr;		while(ch!=0){			*str_ptr=' ';				if(ch=='>')				break;			str_ptr++;			ch=*str_ptr;		}	}	str_ptr=strchr(input_str,'(');	if(str_ptr!=NULL)	{		ch=*str_ptr;		while(ch!=0){			*str_ptr=' ';			if(ch==')')				break;			str_ptr++;			ch=*str_ptr;		}	}	str_ptr=strstr(input_str,"obj");	if(str_ptr!=NULL)		if(!isalpha(*(str_ptr+3)) )		{			*(str_ptr+0)=' ';			*(str_ptr+1)=' ';			*(str_ptr+2)=' ';		}	str_ptr=strstr(input_str,"Br");	if(str_ptr!=NULL)		if(!isalpha(*(str_ptr+2)) )		{			*(str_ptr+0)=' ';			*(str_ptr+1)=' ';		}		str_ptr=strstr(input_str,"Aus");	if(str_ptr!=NULL)		if(!isalpha(*(str_ptr+3)) )		{			*(str_ptr+0)=' ';			*(str_ptr+1)=' ';			*(str_ptr+2)=' ';		}		str_ptr=strstr(input_str,"esp.");	if(str_ptr!=NULL)		if(!isalpha(*(str_ptr+4)) )		{			*(str_ptr+0)=' ';			*(str_ptr+1)=' ';			*(str_ptr+2)=' ';			*(str_ptr+3)=' ';		}	for(i=0,j=0;i<MAX_ITEM_LEN+1;i++)	{		ch=*(input_str+i);			if(isalpha(ch)){			str_tmp[j++]=tolower(ch);			continue;		}		else if(ch==0)		{			str_tmp[j]=ch;			break;		}		else			continue;	}	strcpy(out_str,str_tmp);}//+**********************************//+function:在字母索引标中查找最靠近检索单词的id和逻辑地址//+input:	pure_key_buf, BQ_base_info//+output:	data_offset ,最靠近检索单词的单词所在文件的偏移//+返回值:	最近检索单词的id//+**********************************UINT  search_alpha_index(BQ_Init_t *BQ_base_info,CHAR *pure_key_buf,LONG *data_offset ){	int keybuf_off;	CHAR ch;	UINT index_unit_buf[3];	INT	fun_return;		UINT cur_word_id=0xffffffff;	LONG cur_word_fp_off;		LONG next_index_offset;	LONG cur_index_offset;	FILE *fp_sear_index;	cur_index_offset=BQ_base_info->ALPHA_INDEX_OFFSET;	keybuf_off=0;	fp_sear_index=BQ_base_info->fp;	index_unit_buf[0]=0;	index_unit_buf[1]=0;	index_unit_buf[2]=0;#if LINUX_FS	fun_return=fseek(fp_sear_index,cur_index_offset,SEEK_SET);#else	fun_return=GGV_fseek(fp_sear_index,cur_index_offset,SEEK_SET);#endif	if(fun_return==-1){;}#if LINUX_FS	fun_return=fread(index_unit_buf,sizeof(UINT32),3,fp_sear_index);#else	fun_return=GGV_fread(index_unit_buf,sizeof(UINT32),3,fp_sear_index);#endif	if(fun_return==-1){;}	//read error	next_index_offset=index_unit_buf[0];	cur_word_fp_off=index_unit_buf[1];	cur_word_id=index_unit_buf[2];	while(keybuf_off<=MAX_INPUT_LEN)	{		ch=*(pure_key_buf+keybuf_off);				if (ch==0){			*data_offset=cur_word_fp_off;			return cur_word_id;		}/*				fun_return=(INT)ch;		fun_return-='a';		cur_index_offset=(LONG)(fun_return*12)+cur_index_offset;*/		cur_index_offset = (LONG)((LONG)((LONG)ch-'a')*12)+cur_index_offset;		index_unit_buf[0]=0;		index_unit_buf[1]=0;		index_unit_buf[2]=0;#if LINUX_FS		fseek(fp_sear_index,cur_index_offset,SEEK_SET);		fread(index_unit_buf,sizeof(UINT32),3,fp_sear_index);#else		GGV_fseek(fp_sear_index,cur_index_offset,SEEK_SET);		GGV_fread(index_unit_buf,sizeof(UINT32),3,fp_sear_index);#endif		next_index_offset=index_unit_buf[0];		cur_word_fp_off=index_unit_buf[1];		cur_word_id=index_unit_buf[2];				if(next_index_offset==0)		{				*data_offset=cur_word_fp_off;			return	cur_word_id;		}		keybuf_off++;							cur_index_offset=next_index_offset;	}	return 0xffffffff;	}//************************************************************//judge whether include "*","?"  asterist //input keyin_buf//return 0 there is n't wildcard, and return 1 ,there are //************************************************************int if_have_wildcard(UCHAR *keyin){	if( strchr(keyin,'*')==NULL &&		strchr(keyin,'?')==NULL)	{		return 0;	}	else		return 1;}//+******************************************//+ function name :del_somechar_in_str//+ Function:删除' ' '.' '-'等//+ Input:   	//+				str1	源字符串//+ Output:	str1  保留字母和wildcard//+ Destroy://+ comment: usage only to wildcard//+******************************************void del_somechar_in_str(CHAR *str){	int x,y;	CHAR kin_tmp[MAX_INPUT_LEN+1];	CHAR ch;  	kin_tmp[MAX_INPUT_LEN]=0;	for(x=0,y=0;x<MAX_INPUT_LEN;x++)	{		ch=*(str+x);		if( ch=='*'||ch=='?'||isalpha(ch) )		{			kin_tmp[y]=ch;			y++;			kin_tmp[y]=0;		}		else if(ch==0)		{			kin_tmp[y]=ch;			break;		}		else{;}	}	strcpy(str,kin_tmp);}//+******************************************//+ function name :get_pure_str//+ Function:源输入字符串统配符前的纯字母部分save to key_buf2//+ Input:   	//+		key_buf:source string : the pure alpha string入口为只包含字母和wildcard的字符串//+		key_buf2:aim string   output the string before the first wildcard. //+ Output:	key_buf2//+ Destroy://+******************************************void gen_kin_proc(CHAR *kin_buf,CHAR *key_buf2){	int x;	CHAR *ptr;	strcpy(key_buf2,kin_buf);	ptr=strchr(key_buf2,'*');	if(ptr==NULL)		ptr=strchr(key_buf2,'?');	if(ptr==NULL)		return;		//no wildcard 	*ptr++=0;	x=0;	while(x<MAX_INPUT_LEN-1){		if(*ptr==0){

⌨️ 快捷键说明

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