📄 cb_dicengine.c
字号:
*ptr++=0; return; } *ptr++=0; x++; }}//+**************************************************************** INT8 StrCmp(INT8 *s1, INT8 *s2)/* s1: 辞典中的主题词;s2: 输入的带通配符的字符串 * 对于模糊匹配来说,只有通配符前的字符才能确定主题词是否大于/小于输入串(返回-1); * 其它情况下,要么匹配(返回0),要么不匹配(此时返回1);这样对于调用者来说,只要返回 * 值不是-1说明还可以继续查找。 * Note: 在有多个星号*时,其实只有当前星号才有效,此前的星号没有再利用的价值!!! *///+**************************************************************** { UINT8 i,j,l1,l2; UINT8 pos1,pos2; l1=strlen(s1); l2=strlen(s2); i=0; j=0; //是否有通配符? while(s2[i]!='*'){ if(s1[i]==s2[i]){ if(s1[i]==0) return 0; //同时到尾部 } else if(s2[i]=='?'){ if(s1[i]==0){ //说明与通配符前的字符数相等, return 1; //不管通配符后是否还有字符 } j=1; } else if(j==0) return -1; //说明通配符前的字符串已经不等 else return 1; //有通配符时还要继续查找 i++; } pos1=i; j=i+1; pos2=j; while(i<l1){ //在比较时,只有到达主题词尾部才会得出比较结果 if(s1[i]==s2[j]){ i++; j++; } else if(s2[j]=='?'){ i++; j++; } else if(s2[j]=='*'){ pos1=i; j++; pos2=j; } else{ //如果输入串首先到达串尾,则会运行到这里 i=++pos1; j=pos2; } } if(j>=l2) return 0; //如果同时到达尾部,说明主题词与输入串相匹配 else return 1; //因为有通配符,可以继续找}/***************************************************Func: Search the most match word with the input*In: input_word -> the input string*Out: *I/O:*Modify:*Return: success -> CB_RTN_OK fail -> CB_RTN_ERROR*Author:***************************************************/INT8 cbe_set_search( CHAR *input_word ){ UINT cur_id; UINT word_length; UINT loop_cnt; UCHAR bak_input_str[MAX_INPUT_LEN+1]; UCHAR pure_key_buf[MAX_INPUT_LEN+1]; UCHAR curr_word_buf[MAX_ITEM_LEN+1]; UCHAR curr_word_buf2[MAX_ITEM_LEN+1]; INT tmp; LONG data_logic_fp_off; memset(list_info->inputStr,0,sizeof(list_info->inputStr)); strcpy(list_info->inputStr,input_word); if(if_have_wildcard(input_word)) { list_info->faint_flag = 1; //faint search flag strcpy(bak_input_str,input_word); del_somechar_in_str(input_word); gen_kin_proc(input_word,pure_key_buf); cur_id=search_alpha_index(BQ_base_info,pure_key_buf,&data_logic_fp_off); if(cur_id>BQ_base_info->last_word_id){ strcpy(input_word,bak_input_str); //return(0xffffffff); return CB_RTN_ERROR; } //======================查找开头的单词 while( cur_id<=BQ_base_info->last_word_id ) { #if 0 if (check_key()) { //新按键打断查找过程 strcpy(input_word,bak_input_str); return -1; } #endif get_word(BQ_base_info,cur_id,data_logic_fp_off,MAX_ITEM_LEN,&word_length,curr_word_buf); get_pure_item(curr_word_buf2,curr_word_buf); tmp=strcmp((CHAR *)curr_word_buf2,(CHAR *)pure_key_buf); if(tmp >= 0){ break; } else { if(cur_id == BQ_base_info->last_word_id){ strcpy(input_word,bak_input_str); return CB_RTN_ERROR; } else if(cur_id>BQ_base_info->last_word_id){ return CB_RTN_ERROR; }else{ data_logic_fp_off += word_length; cur_id++; continue; } } } if(cur_id > BQ_base_info->last_word_id){ strcpy(input_word,bak_input_str); return CB_RTN_ERROR; } //引用全局变量 loop_cnt=0; while(cur_id<=BQ_base_info->last_word_id) { if (loop_cnt>=1435){ tmp=0; } #if 0 if (check_key()) { strcpy(input_word,bak_input_str); return -1; } #endif get_word(BQ_base_info,cur_id,data_logic_fp_off,MAX_ITEM_LEN,&word_length,curr_word_buf); get_pure_item(curr_word_buf2,curr_word_buf); tmp=StrCmp(curr_word_buf2,input_word); //faintly str cmp if(tmp==0){ strcpy(input_word,bak_input_str); break; }else if(tmp>0) { if(cur_id >= BQ_base_info->last_word_id){ strcpy(input_word,bak_input_str); return CB_RTN_ERROR; }else{ data_logic_fp_off+=word_length; cur_id++; #if 0 if(!(loop_cnt%3)) draw_searching_icon(loop_cnt%5,assist_fp);// 在屏幕上画图// loop_cnt++; continue; #endif } } else { strcpy(input_word,bak_input_str); return CB_RTN_ERROR; } } } else { list_info->faint_flag = 0; //not faint search key_buf_proc(input_word,pure_key_buf); cur_id=search_alpha_index(BQ_base_info,pure_key_buf,&data_logic_fp_off); if(cur_id > BQ_base_info->last_word_id){ return(CB_RTN_ERROR); } while( cur_id <= BQ_base_info->last_word_id ) { #if 0 //not check key temp if (check_key()) { return -1; } #endif get_word(BQ_base_info,cur_id,data_logic_fp_off,MAX_ITEM_LEN,&word_length,curr_word_buf); get_pure_item(curr_word_buf2,curr_word_buf); tmp=strcmp((CHAR *)curr_word_buf2,(CHAR *)pure_key_buf); if(tmp==0){ break; } else if(tmp>0){ break; } else { if(cur_id==BQ_base_info->last_word_id){ cur_id=BQ_base_info->last_word_id; break; } else if(cur_id>BQ_base_info->last_word_id){ return CB_RTN_ERROR; } else{ data_logic_fp_off+=word_length; cur_id++; continue; } } } } list_info->top_word_id = cur_id; return CB_RTN_OK;}/*************************************************************Func: Get the example data by example id*In: *Out: *I/O:*Modify:*Return: *Author: **************************************************************/void cbe_get_exam(UINT cur_lj_id,UCHAR *output_buf){ LONG example_offset; UINT word_length; UINT16 example_len=0; LONG start_off; example_offset=cbp_get_ljaddr_from_id(BQ_base_info,cur_lj_id); start_off=example_offset;#if LINUX_FS fseek(BQ_base_info->fp,example_offset,SEEK_SET); fread(&example_len,sizeof(UINT16),1,BQ_base_info->fp);#else GGV_fseek(BQ_base_info->fp,example_offset,SEEK_SET); GGV_fread(&example_len,sizeof(UINT16),1,BQ_base_info->fp);#endif example_offset+=2; word_length=(UINT)example_len - 2; cbp_comm_get_data(BQ_base_info,example_offset,word_length,output_buf);}/*****************************************************************func: new word function initialize*in: *out: *i/o:*modify:*return: the count of new word sub db *author: ******************************************************************/INT32 cbe_get_nw_record_num( ){ return DBrec_count(nw_fd);}/**********************************************Func: new word: get one screen of group*In: num -> 所翻的屏数 CB_GET_UP 获取上一屏 CB_CUR_SCREEN 获取当前屏 CB_GET_DOW 获取下一屏 CB_HOME_SCREEN 获取第一屏 CB_END_SCREEN 获取最后一屏 type -> CB_SCROLL_SCREEN 翻屏 CB_SCROLL_LINE 翻行*Out: *list -> 结构体数组指针,用于存放返回内容信息*I/O:*Modify:*Return: 高字节返回个数 低字节返回 -> CB_RTN_ERROR --> 失败 CB_RTN_NOLR --> 左、右标志无效 CB_RTN_LNOR --> 左标志有效,右标志无效 CB_RTN_RNOL --> 左标志无效,右标志有效 CB_RTN_LR --> 左、右标志有效*Author: **********************************************/INT32 cbe_nw_get_displist( NW_GUI_MAIN *p_nw_main, CB_WORD_DATA *p_list, INT8 num, INT8 type ){ UINT8 i; INT32 line; INT8 cur_record_id; INT32 word_id; switch( type ) { case CB_SCROLL_SCREEN: //line = PAGE_NUM_RECORD; line = 7; break; case CB_SCROLL_LINE: line = 1; break; default: return CB_RTN_ERROR; } if(p_nw_main->total_num_record == 0) p_nw_main->total_num_record = DBrec_count(nw_fd); switch( num ) { case CB_GET_UP: case CB_GET_DOWN: case CB_HOME_SCREEN: case CB_END_SCREEN: if( num == CB_GET_UP ){ if( p_nw_main->top_record_id == 0 ) { return CB_RTN_ERROR; } p_nw_main->top_record_id -= line; if( p_nw_main->top_record_id < 0 ){ p_nw_main->top_record_id = 0; } } else if ( num == CB_GET_DOWN ) { //if( p_nw_main->top_record_id + PAGE_NUM_RECORD >= if( p_nw_main->top_record_id + 7 >= p_nw_main->total_num_record + 1 ) { return CB_RTN_ERROR; } p_nw_main->top_record_id += line; } else if( num == CB_HOME_SCREEN ){ p_nw_main->top_record_id = 0; } else if( num == CB_END_SCREEN ){ p_nw_main->top_record_id = p_nw_main->total_num_record + 1 - //PAGE_NUM_RECORD; 7; if( p_nw_main->top_record_id < 0 ) { p_nw_main->top_record_id = 0; } } case CB_CUR_SCREEN: i = 0; for( cur_record_id = p_nw_main->top_record_id; //cur_record_id < (p_nw_main->top_record_id + PAGE_NUM_RECORD); cur_record_id++ ) { cur_record_id < (p_nw_main->top_record_id + 7); cur_record_id++ ) { word_id = cbp_his_read_record( his_fd, cur_record_id ); cbp_get_word_item( BQ_base_info, word_id, (p_list+i)->word); if(( cur_record_id + 1 ) >= p_nw_main->total_num_record )break; i++; } return cbp_get_list_ret( BQ_base_info, list_info ); } return CB_RTN_ERROR;}//+******************************************//+ function name :int BQ_Get_Pre_Word//+ Function: 查找当前单词的上一个单词的id//+ Input: BQ_base_info存放初始化数据变量的数据结构地址//+ cur_id:当前单词id//+ kin_buf用户输入的字符串//+ output : matching_flag //+ retrun: 一个合法的id,则找到下一个单词//+ 非法id入0xffffff,则没有找到//+ Destroy://+ Note://+******************************************INT32 cbe_get_pre_word(INT32 cur_id,UCHAR *kin_buf){ UCHAR bak_kin_buf[MAX_INPUT_LEN]; UCHAR pure_key_buf[MAX_INPUT_LEN]; UINT temp_id; LONG item_data_off; UINT word_length; UCHAR curr_word_buf[MAX_ITEM_LEN+1]; UCHAR curr_word_buf2[MAX_ITEM_LEN+1]; int tmp; UINT loop_cnt; if(cur_id<=0){ return CB_RTN_ERROR; } //=========================== strcpy(bak_kin_buf,kin_buf); //========================================== if(if_have_wildcard(kin_buf)==0) { return (cur_id-1); }//=================================== else{ if(BQ_base_info->fp==NULL) { return CB_RTN_ERROR; } del_somechar_in_str(kin_buf); gen_kin_proc(kin_buf,pure_key_buf); temp_id=cur_id-1; loop_cnt=0; while(temp_id<BQ_base_info->last_word_id) { #if 0 if(check_key()){ return 1; } #endif item_data_off=get_addr_from_id(BQ_base_info,temp_id); get_word(BQ_base_info,temp_id,item_data_off,MAX_ITEM_LEN,&word_length,curr_word_buf); get_pure_item(curr_word_buf2,curr_word_buf); tmp=StrCmp(curr_word_buf2,kin_buf); if(tmp==0){ break; } else if(tmp<0){ return CB_RTN_ERROR; } else{ if(temp_id<=0){ return CB_RTN_ERROR; } temp_id--; continue; loop_cnt++; } } strcpy(kin_buf,bak_kin_buf); return temp_id; } strcpy(kin_buf,bak_kin_buf); return CB_RTN_ERROR;}//+******************************************//+ function name :int BQ_Get_Next_Word//+ Function: 查找当前单词的下一个单词的id//+ Input: BQ_base_info存放初始化数据变量的数据结构地址//+ cur_id:当前单词id//+ kin_buf用户输入的字符串 // matching_flag //+ retrun: 一个合法的id,则找到下一个单词//+ 非法id入0xffffff,则没有找到//+ Destroy://+ Note://+******************************************INT32 cbe_get_next_word(INT32 cur_id,UCHAR *kin_buf){ UCHAR bak_kin_buf[MAX_INPUT_LEN]; UCHAR pure_key_buf[MAX_INPUT_LEN]; UINT temp_id; LONG item_data_off; UINT word_length; UCHAR curr_word_buf[MAX_ITEM_LEN+1]; UCHAR curr_word_buf2[MAX_ITEM_LEN+1]; UINT loop_cnt; int tmp; strcpy(bak_kin_buf,kin_buf); //================================================================ if(if_have_wildcard(kin_buf)==0) { if(cur_id>=BQ_base_info->last_word_id){ return CB_RTN_ERROR; } else return (cur_id+1); }//================================================================ else{ if(cur_id>BQ_base_info->last_word_id){ return CB_RTN_ERROR; } if(BQ_base_info->fp==NULL) { return CB_RTN_ERROR; } del_somechar_in_str(kin_buf); gen_kin_proc(kin_buf,pure_key_buf); temp_id=cur_id+1; item_data_off=get_addr_from_id(BQ_base_info,temp_id); loop_cnt=0; while(temp_id<BQ_base_info->last_word_id) { #if 0 if(check_key()){ strcpy(kin_buf,bak_kin_buf); return 1; } #endif get_word(BQ_base_info,temp_id,item_data_off,MAX_ITEM_LEN,&word_length,curr_word_buf); get_pure_item(curr_word_buf2,curr_word_buf); tmp=StrCmp(curr_word_buf2,kin_buf); if(tmp==0){ break; } else if(tmp<0){ return CB_RTN_ERROR; } else{ if(temp_id>=BQ_base_info->last_word_id){ return CB_RTN_ERROR; } item_data_off+=word_length; temp_id++; loop_cnt++; continue; } } strcpy(kin_buf,bak_kin_buf); return temp_id; } strcpy(kin_buf,bak_kin_buf); return CB_RTN_ERROR;}#pragma far_pic_off#pragma far_pid_off
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -