📄 cb_dicengine.c
字号:
/*-------------------------------------------------** $RCSfile$* $Date$* $Author$* $Log$* Function :* Usage :* Version :* Return Code :* Revision :* Remark :*--------------------------------------------------*/#pragma far_pid_on#pragma far_pic_on#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 "cb_dic/cb_dicengine.h"#include "pub/gvdb/dbapi.h"//#include "cb_dicprivate.c" //temp maskINT cbp_get_word_item(BQ_Init_t *base_info,UINT input_id, CHAR *output_str);INT32 cbp_get_list_ret( const BQ_Init_t *base_info, CB_LIST_INFO *list_info );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);void cbp_get_word_data(BQ_Init_t *base_info,UINT cur_id,UINT GetDataSize_Flag,CB_WORD_DETAIL* word_detail,INT fancha_flag);LONG cbp_get_ljaddr_from_id(BQ_Init_t* base_info,UINT example_id);void cbp_comm_get_data(BQ_Init_t* base_info,LONG data_fp_off,UINT word_length,BYTE *output_buf);INT32 cbp_his_read_record( INT32 fd, INT8 record_id );INT32 cbp_nw_read_record( INT32 fd, INT8 record_id );LONG get_addr_from_id(BQ_Init_t *base_info,UINT input_id);#define CAM_FILE_SYS 0static CB_LIST_INFO *list_info = NULL;static BQ_Init_t *BQ_base_info = NULL;static INT32 his_fd;static DB_INDEX cb_his_db_index[CB_HIS_INDEX_NUM];static DB_RECORD cb_his_db_record;static INT32 nw_fd; //A class new word db filestatic DB_INDEX cb_nw_db_index[CB_NW_INDEX_NUM];static DB_RECORD cb_nw_db_record;static void init_his_db( void ){ //bzero( cb_his_db_index, sizeof( DB_INDEX ) * 1 ); //only word id memset ( cb_his_db_index, 0, sizeof( DB_INDEX ) * 1 ); //only word id cb_his_db_index[0].keynum = 1; cb_his_db_index[0].item[0] = 0; cb_his_db_record.itemnum = 1; cb_his_db_record.db_item[0].type = TYPEINT; cb_his_db_record.db_item[0].num = 1;}/*****************************************************************func: history db initialize*in: *out: *i/o:*modify:*return: success -> cb_rtn_ok fail -> cb_rtn_error*author: ******************************************************************/INT8 his_init(void){#if LINUX_FS CHAR dbfile[L_PATH];#endif init_his_db( );#if LINUX_FS sprintf( dbfile, "%s/%s", getenv( "PDAROOT" ), CB_HIS_DB_FILE ); his_fd = DBopen( dbfile, 2 ); if( his_fd == -2 ) { his_fd = DBcreate( dbfile, cb_his_db_index, &cb_his_db_record, CB_HIS_MAX_WORD_NUM, CB_HIS_INDEX_NUM );#else his_fd = DBopen( "c:\\cb_his",2 ); if( his_fd == -2 ) { his_fd = DBcreate( "c:\\cb_his", cb_his_db_index, &cb_his_db_record, CB_HIS_MAX_WORD_NUM, CB_HIS_INDEX_NUM );#endif return CB_RTN_OK; } else if( his_fd < 0 ) { return CB_RTN_ERROR; } else { return CB_RTN_OK; } return CB_RTN_OK;}/*****************************************************************func: history function initialize*in: *out: *i/o:*modify:*return: the count of history record*author: ******************************************************************/INT8 cbe_his_rec_cnt( void ){ return DBrec_count(his_fd);}static void init_nw_db( void ){ memset ( cb_nw_db_index, 0, sizeof( DB_INDEX ) * 1 ); //only word id cb_nw_db_index[0].keynum = 1; cb_nw_db_index[0].item[0] = 0; cb_nw_db_record.itemnum = 1; cb_nw_db_record.db_item[0].type = TYPEINT; cb_nw_db_record.db_item[0].num = 1;}/*****************************************************************func: new word db initialize*in: *out: *i/o:*modify:*return: success -> cb_rtn_ok fail -> cb_rtn_error*author: ******************************************************************/INT8 new_word_init(void){ CHAR dbfile[L_PATH]; init_nw_db( );#if LINUX_FS sprintf( dbfile, "%s/%s", getenv( "PDAROOT" ), CB_NW_DB_FILE ); nw_fd = DBopen( dbfile, 2 ); if( nw_fd == -2 ) { nw_fd = DBcreate( dbfile, cb_nw_db_index, &cb_nw_db_record, CB_NW_MAX_WORD_NUM, CB_NW_INDEX_NUM );#else nw_fd = DBopen( "c:\\cb_nw",2 ); if( nw_fd == -2 ) { nw_fd = DBcreate( "c:\\cb_nw", cb_nw_db_index, &cb_nw_db_record, CB_NW_MAX_WORD_NUM, CB_NW_INDEX_NUM );#endif return CB_RTN_OK; } else if( nw_fd < 0 ) { return CB_RTN_ERROR; } else { return CB_RTN_OK; } return CB_RTN_OK;}/*****************************************************************func: read the file(dict_cam.bin) header, get some useful msg*in: *out: *i/o:*modify:*return: success -> cb_rtn_ok fail -> cb_rtn_error*author: ******************************************************************/INT8 cbe_init( void ){ CHAR path_data[L_PATH];#if LINUX_FS DIR *p_dirpath = NULL;#endif BQ_base_info = (BQ_Init_t *)malloc( sizeof(BQ_Init_t)); if( BQ_base_info == NULL ) { debug( "malloc error!\n" ); return CB_RTN_ERROR; } list_info = (CB_LIST_INFO *)malloc( sizeof(CB_LIST_INFO)); if( list_info == NULL ) { debug( "malloc error!\n" ); return CB_RTN_ERROR; } memset( BQ_base_info, 0, sizeof(BQ_Init_t)); memset( list_info, 0, sizeof(CB_LIST_INFO));#if LINUX_FS bzero( path_data, sizeof(path_data) ); sprintf( path_data, "%s/%s", getenv( "PDAROOT" ), PATH_CB_DIR ); p_dirpath = opendir( path_data ); if( p_dirpath == NULL ){ return CB_RTN_ERROR; } bzero( path_data, sizeof(path_data) ); sprintf( path_data, "%s/%s", getenv( "PDAROOT" ), PIC_DATA_FILE ); if( ( BQ_base_info->fp = fopen( path_data, "rb" ) ) == NULL ) { free(BQ_base_info); debug( "dict file not exist! [filename = %s]\n", path_data ); return CB_RTN_ERROR; } fseek( BQ_base_info->fp,0,SEEK_SET); BQ_base_info->last_word_id=0; fread((CHAR *) &BQ_base_info->last_word_id,3,1,BQ_base_info->fp); BQ_base_info->CODE1_INDEX_OFFSET=0; fread((CHAR *) &BQ_base_info->CODE1_INDEX_OFFSET,4,1,BQ_base_info->fp); BQ_base_info->CODE2_INDEX_OFFSET=0; fread((CHAR *) &BQ_base_info->CODE2_INDEX_OFFSET,4,1,BQ_base_info->fp); BQ_base_info->CODE3_INDEX_OFFSET=0; fread((CHAR *) &BQ_base_info->CODE3_INDEX_OFFSET,4,1,BQ_base_info->fp); BQ_base_info->CODE4_INDEX_OFFSET=0; fread((CHAR *) &BQ_base_info->CODE4_INDEX_OFFSET,4,1,BQ_base_info->fp); BQ_base_info->ID_INDEX_OFFSET=0; fread((CHAR *) &BQ_base_info->ID_INDEX_OFFSET,4,1,BQ_base_info->fp); BQ_base_info->ALPHA_INDEX_OFFSET=0; fread((CHAR *) &BQ_base_info->ALPHA_INDEX_OFFSET,4,1,BQ_base_info->fp); BQ_base_info->EXAMPLE_INDEX_OFFSET=0; fread((CHAR *) &BQ_base_info->EXAMPLE_INDEX_OFFSET,4,1,BQ_base_info->fp); BQ_base_info->SYNTAX_INDEX_OFFSET=0; fread((CHAR *) &BQ_base_info->SYNTAX_INDEX_OFFSET,4,1,BQ_base_info->fp); BQ_base_info->WQX_MAP_TBL_OFFSET=0; fread((CHAR *) &BQ_base_info->WQX_MAP_TBL_OFFSET,4,1,BQ_base_info->fp); BQ_base_info->BQ_MAP_TBL_OFFSET=0; fread((CHAR *) &BQ_base_info->BQ_MAP_TBL_OFFSET,4,1,BQ_base_info->fp); BQ_base_info->IMAGE_INDEX_OFFSET=0; fread((CHAR *) &BQ_base_info->IMAGE_INDEX_OFFSET,4,1,BQ_base_info->fp); BQ_base_info->SEE_ALSO_OFFSET=0; fread((CHAR *) &BQ_base_info->SEE_ALSO_OFFSET,4,1,BQ_base_info->fp);#else if( ( BQ_base_info->fp = GGV_fopen( "c:\\dict_cam.bin", "r" ) ) == NULL ) { free(BQ_base_info); debug( "dict file not exist! [filename = %s]\n", path_data ); return CB_RTN_ERROR; } GGV_fseek( BQ_base_info->fp,0,SEEK_SET); BQ_base_info->last_word_id=0; GGV_fread((CHAR *) &BQ_base_info->last_word_id,3,1,BQ_base_info->fp); BQ_base_info->CODE1_INDEX_OFFSET=0; GGV_fread((CHAR *) &BQ_base_info->CODE1_INDEX_OFFSET,4,1,BQ_base_info->fp); BQ_base_info->CODE2_INDEX_OFFSET=0; GGV_fread((CHAR *) &BQ_base_info->CODE2_INDEX_OFFSET,4,1,BQ_base_info->fp); BQ_base_info->CODE3_INDEX_OFFSET=0; GGV_fread((CHAR *) &BQ_base_info->CODE3_INDEX_OFFSET,4,1,BQ_base_info->fp); BQ_base_info->CODE4_INDEX_OFFSET=0; GGV_fread((CHAR *) &BQ_base_info->CODE4_INDEX_OFFSET,4,1,BQ_base_info->fp); BQ_base_info->ID_INDEX_OFFSET=0; GGV_fread((CHAR *) &BQ_base_info->ID_INDEX_OFFSET,4,1,BQ_base_info->fp); BQ_base_info->ALPHA_INDEX_OFFSET=0; GGV_fread((CHAR *) &BQ_base_info->ALPHA_INDEX_OFFSET,4,1,BQ_base_info->fp); BQ_base_info->EXAMPLE_INDEX_OFFSET=0; GGV_fread((CHAR *) &BQ_base_info->EXAMPLE_INDEX_OFFSET,4,1,BQ_base_info->fp); BQ_base_info->SYNTAX_INDEX_OFFSET=0; GGV_fread((CHAR *) &BQ_base_info->SYNTAX_INDEX_OFFSET,4,1,BQ_base_info->fp); BQ_base_info->WQX_MAP_TBL_OFFSET=0; GGV_fread((CHAR *) &BQ_base_info->WQX_MAP_TBL_OFFSET,4,1,BQ_base_info->fp); BQ_base_info->BQ_MAP_TBL_OFFSET=0; GGV_fread((CHAR *) &BQ_base_info->BQ_MAP_TBL_OFFSET,4,1,BQ_base_info->fp); BQ_base_info->IMAGE_INDEX_OFFSET=0; GGV_fread((CHAR *) &BQ_base_info->IMAGE_INDEX_OFFSET,4,1,BQ_base_info->fp); BQ_base_info->SEE_ALSO_OFFSET=0; GGV_fread((CHAR *) &BQ_base_info->SEE_ALSO_OFFSET,4,1,BQ_base_info->fp);#endif if(his_init( ) == CB_RTN_ERROR)return CB_RTN_ERROR; if(new_word_init( ) == CB_RTN_ERROR)return CB_RTN_ERROR; return CB_RTN_OK;}/**********************************************Func: Destroy CB dialoge*In: *Out: *I/O:*Modify:*Return: success -> CB_RTN_OK fail -> CB_RTN_ERROR*Author:**********************************************/INT8 cbe_destroy( void ){ if( BQ_base_info != NULL ) {#if LINUX_FS fclose( BQ_base_info->fp );#else GGV_fclose( BQ_base_info );#endif free( BQ_base_info); BQ_base_info = NULL; }else { return CB_RTN_ERROR; } if( his_fd <= 0 || DBclose( his_fd ) < 0 ) return CB_RTN_ERROR; if( nw_fd <= 0 || DBclose( nw_fd ) < 0 ) return CB_RTN_ERROR; return CB_RTN_OK;}/***************************************************Func: Set the counter of records per screen*In: num -> the counter of the record per scr*Out: *I/O:*Modify:*Return: success -> CB_RTN_OK fail -> CB_RTN_ERROR*Author:***************************************************/INT8 cbe_set_displistnum( const UINT8 num ){ if( num <= 0 ) return CB_RTN_ERROR; list_info->page_dispnum = num ; return CB_RTN_OK;}/*********************************************************************Func: History:Get one screen*In: num -> the action: CB_GET_UP previous screen CB_CUR_SCREEN current screen CB_GET_DOWN next screen CB_HOME_SCREEN the first screen CB_END_SCREEN the last screen type -> CB_SCROLL_SCREEN screen change CB_SCROLL_LINE line change*Out: *list -> the return content in the point of structure*I/O:*Modify:*Return: the number in 16 bits of the reburn INT32 the low 16 bits of return INT32: CB_RTN_ERROR --> fail CB_RTN_NOLR --> No left or right CB_RTN_LNOR --> left value and right not CB_RTN_RNOL --> right value and left not CB_RTN_LR --> left and right both value*Author:*********************************************************************/INT32 cbe_his_get_displist( HIS_GUI_MAIN* p_his_main, CB_WORD_DATA *list, const INT8 num, const 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_his_main->total_record_num == 0) p_his_main->total_record_num = DBrec_count(his_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_his_main->top_record_id == 0 ) { return CB_RTN_ERROR; } p_his_main->top_record_id -= line; if( p_his_main->top_record_id < 0 ){ p_his_main->top_record_id = 0; } } else if ( num == CB_GET_DOWN ) { //if( p_his_main->top_record_id + PAGE_NUM_RECORD >= if( p_his_main->top_record_id + 7 >= p_his_main->total_record_num+1 ) { return CB_RTN_ERROR; } p_his_main->top_record_id += line; } else if( num == CB_HOME_SCREEN ){ p_his_main->top_record_id = 0; } else if( num == CB_END_SCREEN ){ p_his_main->top_record_id = p_his_main->total_record_num+1 - //PAGE_NUM_RECORD; 7; if( p_his_main->top_record_id < 0 ) { p_his_main->top_record_id = 0; } } case CB_CUR_SCREEN: i = 0; for( cur_record_id = p_his_main->top_record_id; //cur_record_id < (p_his_main->top_record_id + PAGE_NUM_RECORD); cur_record_id++ ) { cur_record_id < (p_his_main->top_record_id + 7); cur_record_id++ ) { word_id = cbp_nw_read_record( nw_fd, cur_record_id ); cbp_get_word_item( BQ_base_info, word_id, (list+i)->word); if(( cur_record_id + 1 ) >= p_his_main->total_record_num )break; i++; } return cbp_get_list_ret( BQ_base_info, list_info ); } return CB_RTN_ERROR;}/*********************************************************************Func: Get one screen*In: num -> the action: CB_GET_UP previous screen CB_CUR_SCREEN current screen CB_GET_DOWN next screen CB_HOME_SCREEN the first screen CB_END_SCREEN the last screen type -> CB_SCROLL_SCREEN screen change CB_SCROLL_LINE line change*Out: *list -> the return content in the point of structure*I/O:*Modify:*Return: the number in 16 bits of the reburn INT32 the low 16 bits of return INT32: CB_RTN_ERROR --> fail CB_RTN_NOLR --> No left or right CB_RTN_LNOR --> left value and right not CB_RTN_RNOL --> right value and left not CB_RTN_LR --> left and right both value*Author:*TODO:1. icon* 2. word id the faint list*********************************************************************/INT32 cbe_get_displist( CB_WORD_DATA *list, const INT8 num, const INT8 type ){ UINT8 i; INT32 line; INT32 cur_id; switch( type ) { case CB_SCROLL_SCREEN: line = list_info->page_dispnum;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -