Files | |
file | engine_bookmark.h |
Header for bookmark dictionary engine. | |
file | engine_bookmark.c |
Code of bookmark dictionary engine. | |
Data Structures | |
struct | _BookData |
Internal data structure of Bookmark Engine. More... | |
Module functions | |
gboolean | bm_engine_check (gchar *location) |
dict_eng_module_check() function implementation. | |
gchar * | bm_engine_description () |
dict_eng_module_get_description() function implementation. | |
gchar * | bm_engine_format () |
dict_eng_module_get_format() function implementation. | |
gchar * | bm_engine_version () |
dict_eng_module_get_version() function implementation. | |
Engine * | bm_engine_create (gchar *location, EngineOptimizationFlag flags, cb_progress progress_handler, gpointer progress_data, gdouble seed) |
dict_eng_module_create() function implementation. | |
Particular dictionary function | |
gboolean | bm_engine_add_word (Engine *engine, gchar *word, gchar *translation) |
dict_eng_add_word() function implementation. | |
gboolean | bm_engine_remove_word (Engine *engine, gchar *word) |
dict_eng_remove_word() function implementation. | |
gchar * | bm_engine_get_lang_from (Engine *engine) |
dict_eng_get_lang_from() function implementation. | |
gchar * | bm_engine_get_lang_to (Engine *engine) |
dict_eng_get_lang_to() function implementation. | |
gchar * | bm_engine_get_title (Engine *engine) |
dict_eng_get_title() function implementation. | |
gchar * | bm_engine_get_icon_path (Engine *engine) |
dict_eng_get_icon_path() function implementation. | |
void | bm_engine_close (Engine *engine) |
dict_eng_destroy() function implementation. | |
gchar * | bm_engine_location (Engine *engine) |
dict_eng_get_location() function implementation. | |
void | bm_engine_optimize (Engine *engine) |
dict_eng_optimize() function implementation. | |
gboolean | bm_engine_is_optimized (Engine *engine) |
dict_eng_is_optimized() function implementation. | |
void | bm_engine_set_auto_free (Engine *engine, gboolean state) |
dict_eng_set_auto_free() function implementation. | |
gpointer | bm_engine_set_callback (Engine *engine, gchar *event, gpointer c_handler, gpointer user_data) |
dict_eng_set_callback() function implementation. | |
void | bm_engine_set_progress_seed (Engine *engine, gchar *signal, gdouble seed) |
dict_eng_set_progress_seed() function implementation. | |
void | bm_engine_search_word_list (Engine *engine, gchar *pattern, gpointer data) |
dict_eng_search_word_list() function implementation. | |
void | bm_engine_search_word_translation (Engine *engine, gchar *word, gpointer data) |
dict_eng_search_word_translation() function implementation. | |
EngineStatus | bm_engine_status (Engine *engine) |
dict_eng_get_last_status() function implementation. | |
gchar * | bm_engine_status_message (EngineStatus error) |
dict_eng_status_message() function implementation. | |
Timers | |
#define | TIMER_START TRUE |
Flags telling that we want to start timer. | |
#define | TIMER_STOP FALSE |
Flags telling that we want to stop timer. | |
Defines | |
#define | PRINT_STATE(state) ( (state) ? "TRUE" : "FALSE" ) |
Translate boolean value into string. | |
#define | LOGS g_debug |
Typedefs | |
typedef _BookData | BookData |
Functions | |
static gchar * | string_to_path (gchar **string) |
Convert string to proper path name. | |
static gboolean | is_Bookmark_db_file (gchar *file) |
Tells if file is in Bookmarks format (file should exist). | |
static gboolean | bm_add_new_entry (gchar *word, gchar *translation, BookData *data) |
Add new translation for word. | |
static void | bm_load_freeID (BookData *data) |
Get minimal free value available for word's id. | |
static void | bm_save_freeID (BookData *data) |
Get minimal free value available for word's id. | |
static gboolean | bm_add_only_translation (BookData *data, gchar *translation, guint id) |
Add only new translation with id. | |
static gint | bm_compare_key_trans (const DBT *a, const DBT *b) |
Compare method for searching in translation file. | |
static gint | bm_compare_key_words (const DBT *a, const DBT *b) |
Compare method for searching in words file. | |
EngineModule | engine_global_functions () |
implementation of engine_global_functions(void) function. | |
Variables | |
static const gchar * | DIC_ENG_VERSION = "0.2" |
Start/stop timers.Version of bookmark engine. | |
static const gchar * | DIC_ENG_FORMAT = "Users' Bookmarks" |
Short description of format supported by the current engine. | |
static const gchar * | DIC_ENG_DESCRIPTION |
Short description of engine. |
This is library with dictionary engine supporting bookmarks. It uses Berkeley DB as a storage method.
TODO: currently bookmark engine does not support all function from engine API! It need implementation of API version 0.2 function, like getting icon path etc.
#define PRINT_STATE | ( | state | ) | ( (state) ? "TRUE" : "FALSE" ) |
Translate boolean value into string.
Definition at line 94 of file engine_bookmark.h.
Referenced by bm_engine_check(), bm_engine_is_optimized(), bm_engine_set_auto_free(), is_xdxf_file(), xdxf_engine_check(), xdxf_engine_is_optimized(), and xdxf_engine_set_auto_free().
#define TIMER_START TRUE |
Flags telling that we want to start timer.
Definition at line 66 of file engine_bookmark.h.
Referenced by ws_gui_dbus_return_words().
#define TIMER_STOP FALSE |
Flags telling that we want to stop timer.
Definition at line 68 of file engine_bookmark.h.
Referenced by ws_gui_dbus_return_words().
static gboolean bm_add_new_entry | ( | gchar * | word, | |
gchar * | translation, | |||
BookData * | data | |||
) | [static] |
Add new translation for word.
Definition at line 296 of file engine_bookmark.c.
References bm_save_freeID(), _BookData::db_trans, _BookData::db_words, ENGINE_COULDNT_WRITE, ENGINE_INTERNAL_ERROR, _BookData::freeID, _BookData::last_error, and LOGS.
Referenced by bm_engine_add_word().
00297 { 00298 guint hash = g_str_hash(translation); 00299 gboolean result = TRUE; 00300 00301 DBT new_key = { &(data->freeID) , sizeof(guint) }; 00302 DBT new_val = { translation , strlen(translation) + 1}; 00303 gint db_res = data->db_trans->put(data->db_trans, 00304 &new_key, 00305 &new_val, 00306 R_NOOVERWRITE 00307 ); 00308 if(-1 == db_res) 00309 { 00310 data->last_error = ENGINE_COULDNT_WRITE; 00311 result = FALSE; 00312 } 00313 else 00314 { 00315 new_key.data = word; 00316 new_key.size = strlen(word) + 1; 00317 00318 // { number of entries , id of the first entry , hash #1 } 00319 guint temp[3] = { 1 , data->freeID, hash }; 00320 new_val.data = temp; 00321 new_val.size = sizeof(guint) * 3; 00322 00323 db_res = data->db_words->put(data->db_words, 00324 &new_key, 00325 &new_val, 00326 R_NOOVERWRITE 00327 ); 00328 if(-1 == db_res) 00329 { 00330 new_key.data = &(data->freeID); 00331 new_key.size = sizeof(guint); 00332 data->db_trans->del(data->db_trans, &new_key, 0); 00333 result = FALSE; 00334 data->last_error = ENGINE_INTERNAL_ERROR; 00335 } 00336 else 00337 { 00338 result = TRUE; 00339 (data->freeID)++; 00340 bm_save_freeID(data); 00341 } 00342 } 00343 db_res = data->db_words->sync(data->db_words,0); 00344 db_res |= data->db_trans->sync(data->db_trans,0); 00345 if(0 == db_res) 00346 { 00347 LOGS("Bookmark/%s->%s() adding new bookmark successful.\n", 00348 (gchar*)__FILE__,(gchar*)__FUNCTION__); 00349 } 00350 else 00351 { 00352 LOGS("Bookmark/%s->%s() adding new bookmark failed.\n", 00353 (gchar*)__FILE__,(gchar*)__FUNCTION__); 00354 } 00355 return result; 00356 }
static gboolean bm_add_only_translation | ( | BookData * | data, | |
gchar * | translation, | |||
guint | id | |||
) | [static] |
Add only new translation with id.
Definition at line 274 of file engine_bookmark.c.
References _BookData::db_trans, and LOGS.
Referenced by bm_engine_add_word().
00277 { 00278 DBT key = { &id , sizeof(id) }; 00279 DBT val = { translation , strlen(translation) + 1 }; 00280 gint res = data->db_trans->put(data->db_trans, 00281 &key, 00282 &val, 00283 R_NOOVERWRITE); 00284 if(-1 == res) { 00285 LOGS("Error while adding only translation!\n"); 00286 return FALSE; 00287 } 00288 res = data->db_trans->sync(data->db_trans, 0); 00289 if(-1 == res) { 00290 LOGS("Error while synchronizing file with data\n"); 00291 return FALSE; 00292 } 00293 return TRUE; 00294 }
static gint bm_compare_key_trans | ( | const DBT * | a, | |
const DBT * | b | |||
) | [static] |
static gint bm_compare_key_words | ( | const DBT * | a, | |
const DBT * | b | |||
) | [static] |
gboolean bm_engine_add_word | ( | Engine * | engine, | |
gchar * | word, | |||
gchar * | translation | |||
) |
dict_eng_add_word() function implementation.
Definition at line 140 of file engine_bookmark.c.
References bm_add_new_entry(), bm_add_only_translation(), bm_save_freeID(), _BookData::db_words, ENGINE_COULDNT_READ, _Engine::engine_data, _BookData::freeID, _BookData::last_error, and LOGS.
Referenced by bm_engine_create().
00143 { 00144 LOGS("Bookmark/%s->%s() called. Param\nEngine at address: %p\n" 00145 "word: %s\ntranslation address: %p\n", 00146 (gchar*)__FILE__, 00147 (gchar*)__FUNCTION__, 00148 engine, 00149 word, 00150 translation 00151 ); 00152 g_assert(engine != NULL); 00153 g_assert(word != NULL); 00154 g_assert(translation != NULL); 00155 00156 /* start bm_timer for this function */ 00157 /* bm_timer(TIMER_START, (gchar*)(gchar*)__FUNCTION__); */ 00158 00159 gboolean result = TRUE; 00160 BookData* data = (BookData*)(engine->engine_data); 00161 guint length = strlen(word) + 1; 00162 DBT key = { word , length }; 00163 DBT val = { NULL , 0 }; 00164 00165 00166 gint db_res = data->db_words->get(data->db_words, &key, &val, 0); 00167 if ( 0 == db_res ) 00168 { 00169 // there is already entry for this key - check if this translation is in 00170 // database - check string hash equality 00171 LOGS("Bookmark/%s->%s() updating entry for key: %s", 00172 (gchar*)__FILE__, 00173 (gchar*)__FUNCTION__, 00174 (gchar*)(key.data) 00175 ); 00176 00177 guint hash = g_str_hash(translation); 00178 guint* values = (guint*)(val.data); 00179 guint N = values[0]; 00180 memcpy(&N, values, sizeof(guint)); 00181 guint i = N; 00182 guint tmp_hash = 0; 00183 gboolean exist = FALSE; 00184 ++values; 00185 while(i--) 00186 { 00187 memcpy(&tmp_hash, values + (i*2+1), sizeof(guint)); 00188 if( tmp_hash == hash) 00189 { 00190 exist = TRUE; 00191 break; 00192 } 00193 } 00194 if(!exist) 00195 { 00196 LOGS("Bookmark/%s->%s() Adding new translation to " 00197 "already exist word in dictionary.\n", 00198 (gchar*)__FILE__, 00199 (gchar*)__FUNCTION__ 00200 ); 00201 values = (guint*)(val.data); 00202 guint* tmp = g_malloc(val.size + sizeof(guint)*2); 00203 g_memmove(tmp, values, val.size); 00204 tmp[0]++; 00205 tmp[N*2+1] = data->freeID; 00206 tmp[N*2+2] = hash; 00207 val.data = tmp; 00208 val.size += 2*sizeof(guint); 00209 gint o = data->db_words->del(data->db_words,&key,0); 00210 if(0 != o) 00211 { 00212 LOGS("Bookmark/%s->%s() Error while removing!", 00213 (gchar*)__FILE__, 00214 (gchar*)__FUNCTION__ 00215 ); 00216 } 00217 o = data->db_words->sync(data->db_words, 0); 00218 if(0 != o) { 00219 LOGS("Error while 1st synchronizing file with data!\n"); 00220 } 00221 00222 o = data->db_words->put(data->db_words, 00223 &key, 00224 &val, 00225 R_NOOVERWRITE); 00226 if(0 != o) { 00227 LOGS("Error while putting new info about word!\n"); 00228 } 00229 o = data->db_words->sync(data->db_words, 0); 00230 if(0 != o) { 00231 LOGS("Error while 2nd synchronizing file with data!\n"); 00232 } 00233 bm_add_only_translation(data,translation,data->freeID); 00234 (data->freeID)++; 00235 bm_save_freeID(data); 00236 if(NULL != tmp) { 00237 g_free(tmp); 00238 tmp = NULL; 00239 } 00240 } 00241 else 00242 { 00243 LOGS("Bookmark/%s->%s() This translation already exist!", 00244 (gchar*)__FILE__, 00245 (gchar*)__FUNCTION__ 00246 ); 00247 } 00248 } 00249 else if ( 1 == db_res ) 00250 { 00251 // there is no such a key - word in database - create new entry 00252 LOGS("Bookmark/%s->%s() adding new entry for key: %s", 00253 (gchar*)__FILE__, 00254 (gchar*)__FUNCTION__, 00255 (gchar*)(key.data) 00256 ); 00257 result = bm_add_new_entry(word,translation,data); 00258 } 00259 else { 00260 // there was an error, while accessing to the database 00261 LOGS("Bookmark/%s->%s() Error while trying to add new word: %s", 00262 (gchar*)__FILE__, 00263 (gchar*)__FUNCTION__, 00264 (gchar*)(key.data) 00265 ); 00266 data->last_error = ENGINE_COULDNT_READ; 00267 result = FALSE; 00268 } 00269 00270 /* bm_timer(TIMER_STOP, (gchar*)(gchar*)__FUNCTION__); */ 00271 return result; 00272 }
gboolean bm_engine_check | ( | gchar * | location | ) |
dict_eng_module_check() function implementation.
Definition at line 799 of file engine_bookmark.c.
References is_Bookmark_db_file(), LOGS, PRINT_STATE, and string_to_path().
Referenced by engine_global_functions().
00800 { 00801 LOGS("Bookmark/%s->%s() called.\n-->PARAM:location=\'%s\'\n", 00802 (gchar*)__FILE__, 00803 (gchar*)__FUNCTION__, 00804 location 00805 ); 00806 /* bm_timer(TIMER_START,(gchar*)(gchar*)__FUNCTION__); */ 00807 gboolean result = TRUE; 00808 gchar* filepath = g_strdup(location); 00809 gchar* tmp = NULL; 00810 gchar* tmp2 = NULL; 00811 00812 string_to_path(&filepath); 00813 if (filepath == NULL) { 00814 result = FALSE; 00815 LOGS("Bookmark/%s->%s() location \'%s\' is not a proper " 00816 "path!\n", 00817 (gchar*)__FILE__, 00818 (gchar*)__FUNCTION__, 00819 location 00820 ); 00821 } 00822 else 00823 { 00824 tmp = g_strconcat(filepath,"/bm_words.db",NULL); 00825 tmp2 = g_strconcat(filepath,"/bm_trans.db",NULL); 00826 g_free(filepath); 00827 filepath = tmp; 00828 tmp = NULL; 00829 00830 LOGS("Bookmark/%s->%s() finnal file to check is: %s\n", 00831 (gchar*)__FILE__, 00832 (gchar*)__FUNCTION__, 00833 filepath 00834 ); 00835 if (!g_file_test(filepath, G_FILE_TEST_IS_REGULAR) || 00836 !g_file_test(tmp2, G_FILE_TEST_IS_REGULAR) 00837 ) { 00838 LOGS("Bookmark/%s->%s() file \'%s\' does not exists!\n", 00839 (gchar*)__FILE__, 00840 (gchar*)__FUNCTION__, 00841 filepath 00842 ); 00843 result = FALSE; 00844 }; 00845 }; 00846 if (result != FALSE) { 00847 result = is_Bookmark_db_file(filepath) & 00848 is_Bookmark_db_file(tmp2); 00849 }; 00850 00851 g_free(filepath); filepath = NULL; 00852 g_free(tmp2); tmp2 = NULL; 00853 /* bm_timer(TIMER_STOP,(gchar*)(gchar*)__FUNCTION__); */ 00854 LOGS("Bookmark/%s->%s() returned bool statement=%s.\n", 00855 (gchar*)__FILE__, 00856 (gchar*)__FUNCTION__, 00857 PRINT_STATE(result) 00858 ); 00859 return result; 00860 }
void bm_engine_close | ( | Engine * | engine | ) |
dict_eng_destroy() function implementation.
Definition at line 586 of file engine_bookmark.c.
References _BookData::db_trans, _BookData::db_words, _BookData::dict_path, _Engine::engine_data, and LOGS.
Referenced by bm_engine_create().
00587 { 00588 LOGS("Bookmark/%s->%s() called.\n-->PARAM: engine adress=%p\n", 00589 (gchar*)__FILE__, 00590 (gchar*)__FUNCTION__, 00591 engine); 00592 g_assert(engine != NULL); 00593 00594 BookData* data = (BookData*)(engine->engine_data); 00595 data->db_words->close(data->db_words); 00596 data->db_trans->close(data->db_trans); 00597 00598 LOGS("Bookmark/%s->%s() engine at adress=%p is deleted.\n", 00599 (gchar*)__FILE__, 00600 (gchar*)__FUNCTION__, 00601 engine); 00602 g_free(data->dict_path); 00603 g_free(data); 00604 data = NULL; 00605 g_free(engine); 00606 engine = NULL; 00607 }
Engine * bm_engine_create | ( | gchar * | location, | |
EngineOptimizationFlag | flags, | |||
cb_progress | progress_handler, | |||
gpointer | progress_data, | |||
gdouble | seed | |||
) |
dict_eng_module_create() function implementation.
Definition at line 609 of file engine_bookmark.c.
References _BookData::auto_free, bm_compare_key_trans(), bm_compare_key_words(), bm_engine_add_word(), bm_engine_close(), bm_engine_get_icon_path(), bm_engine_get_lang_from(), bm_engine_get_lang_to(), bm_engine_get_title(), bm_engine_is_optimized(), bm_engine_location(), bm_engine_optimize(), bm_engine_remove_word(), bm_engine_search_word_list(), bm_engine_search_word_translation(), bm_engine_set_auto_free(), bm_engine_set_callback(), bm_engine_set_progress_seed(), bm_engine_status(), bm_engine_status_message(), bm_load_freeID(), _BookData::cb_progress_caching, _BookData::cb_progress_caching_data, _BookData::cb_progress_caching_seed, _BookData::cb_progress_word_list, _BookData::cb_progress_word_list_data, _BookData::cb_progress_word_list_seed, _BookData::cb_progress_word_trans, _BookData::cb_progress_word_trans_data, _BookData::cb_progress_word_trans_seed, _BookData::cb_search_word_list, _BookData::cb_search_word_list_data, _BookData::cb_search_word_trans, _BookData::cb_search_word_trans_data, _BookData::db_trans, _BookData::db_words, _BookData::dict_path, _Engine::engine_add_word, _Engine::engine_close, _Engine::engine_data, _Engine::engine_get_icon_path, _Engine::engine_get_lang_from, _Engine::engine_get_lang_to, _Engine::engine_get_title, _Engine::engine_is_optimized, _Engine::engine_location, _Engine::engine_optimize, _Engine::engine_remove_word, _Engine::engine_search_word_list, _Engine::engine_search_word_translation, _Engine::engine_set_auto_free, _Engine::engine_set_callback, _Engine::engine_set_progress_seed, _Engine::engine_status, _Engine::engine_status_message, _BookData::info_trans, _BookData::info_words, LOGS, and string_to_path().
Referenced by engine_global_functions().
00614 { 00615 LOGS("Bookmark/%s->%s() called.\n" 00616 "-->PARAM:location=\'%s\'\n" 00617 "-->PARAM:auto_cache=%d\n", 00618 (gchar*)__FILE__, 00619 (gchar*)__FUNCTION__, 00620 location, 00621 (guint)auto_cache 00622 ); 00623 /* bm_timer(TIMER_START,(gchar*)(gchar*)__FUNCTION__); */ 00624 00625 gchar* tmp = g_strdup(location); 00626 string_to_path(&tmp); 00627 00628 Engine* result = (Engine*)g_try_malloc(sizeof(Engine)); 00629 result->engine_location = bm_engine_location; 00630 result->engine_is_optimized = bm_engine_is_optimized; 00631 result->engine_optimize = bm_engine_optimize; 00632 result->engine_search_word_list = bm_engine_search_word_list; 00633 result->engine_search_word_translation = 00634 bm_engine_search_word_translation; 00635 result->engine_close = bm_engine_close; 00636 result->engine_status = bm_engine_status; 00637 result->engine_status_message = bm_engine_status_message; 00638 result->engine_set_callback = bm_engine_set_callback; 00639 result->engine_set_progress_seed = bm_engine_set_progress_seed; 00640 result->engine_set_auto_free = bm_engine_set_auto_free; 00641 // 0.2 API: 00642 result->engine_add_word = bm_engine_add_word; 00643 result->engine_remove_word = bm_engine_remove_word; 00644 result->engine_get_lang_from = bm_engine_get_lang_from; 00645 result->engine_get_lang_to = bm_engine_get_lang_to; 00646 result->engine_get_title = bm_engine_get_title; 00647 result->engine_get_icon_path = bm_engine_get_icon_path; 00648 00649 00650 BookData* data = (BookData*)g_try_malloc(sizeof(BookData)); 00651 result->engine_data = (gpointer)data; 00652 00653 LOGS("Bookmark/%s->%s() opening file...\'%s\'.\n", 00654 (gchar*)__FILE__, 00655 (gchar*)__FUNCTION__, 00656 location 00657 ); 00658 00659 u_int32_t flags = O_CREAT | O_RDWR; 00660 gchar* tmp_w = g_strconcat(tmp,"/bm_words.db",NULL); 00661 gchar* tmp_t = g_strconcat(tmp,"/bm_trans.db",NULL); 00662 00663 BTREEINFO inf = { 00664 0, /* permit duplicate keys? */ 00665 0, /* cache size; 0 - default size */ 00666 0, /* page size; 0 - default */ 00667 0, /* byte order; 0 - use host order */ 00668 0, /* min page number per page; 0 - default=2 */ 00669 bm_compare_key_words, /* comparision function */ 00670 NULL /* prefix comparision function */ 00671 }; 00672 data->info_words = inf; 00673 inf.compare = bm_compare_key_trans; 00674 data->info_trans = inf; 00675 00676 data->db_words = 00677 dbopen(tmp_w, /* On-disk file that holds the database. */ 00678 flags, /* flags, like O_CREAT etc. */ 00679 0755, /* mode same as flags <hmmm> ? */ 00680 DB_BTREE, /* type */ 00681 &(data->info_words) 00682 ); 00683 if(data->db_words == NULL) 00684 { 00685 g_free(data); 00686 g_free(result); 00687 result = NULL; 00688 } 00689 else { 00690 data->db_trans = 00691 dbopen(tmp_t, 00692 flags, 00693 0755, 00694 DB_BTREE, 00695 &(data->info_trans) 00696 ); 00697 00698 if(data->db_trans == NULL) 00699 { 00700 data->db_words->close(data->db_words); 00701 g_free(data); 00702 g_free(result); 00703 result = NULL; 00704 } 00705 00706 } 00707 g_free(tmp_w); tmp_w = NULL; 00708 g_free(tmp_t); tmp_t = NULL; 00709 if(result == NULL) { 00710 LOGS("Bookmark/%s->%s() opening bookmark file failed.\n", 00711 (gchar*)__FILE__, 00712 (gchar*)__FUNCTION__ 00713 ); 00714 } 00715 else { 00716 LOGS("Bookmark/%s->%s()opening dictionary file successed.\n", 00717 (gchar*)__FILE__, 00718 (gchar*)__FUNCTION__ 00719 ); 00720 data->dict_path = g_strdup(tmp); 00721 data->cb_progress_caching = progress_handler; 00722 data->cb_progress_caching_data = progress_data; 00723 data->cb_progress_caching_seed = seed; 00724 data->cb_progress_word_list = NULL; 00725 data->cb_progress_word_list_data = NULL; 00726 data->cb_progress_word_list_seed = 0.01; 00727 data->cb_progress_word_trans = NULL; 00728 data->cb_progress_word_trans_data = NULL; 00729 data->cb_progress_word_trans_seed = 0.01; 00730 00731 data->cb_search_word_list = NULL; 00732 data->cb_search_word_list_data = NULL; 00733 00734 data->cb_search_word_trans = NULL; 00735 data->cb_search_word_trans_data = NULL; 00736 00737 data->auto_free = FALSE; 00738 00739 bm_load_freeID(data); 00740 00741 } 00742 g_free(tmp); tmp = NULL; 00743 00744 /* bm_timer(TIMER_STOP,(gchar*)(gchar*)__FUNCTION__); */ 00745 LOGS("Bookmark/%s->%s() returned Engine at adress=%p\n", 00746 (gchar*)__FILE__, 00747 (gchar*)__FUNCTION__, 00748 result 00749 ); 00750 return result; 00751 }
gchar * bm_engine_description | ( | ) |
dict_eng_module_get_description() function implementation.
Definition at line 1052 of file engine_bookmark.c.
References DIC_ENG_DESCRIPTION, and LOGS.
Referenced by engine_global_functions().
01053 { 01054 LOGS("Bookmark/%s->%s() called.\n",(gchar*)__FILE__,(gchar*)__FUNCTION__); 01055 gchar* result = g_strdup(DIC_ENG_DESCRIPTION); 01056 LOGS("Bookmark/%s->%s() return string=%s\n", 01057 (gchar*)__FILE__, 01058 (gchar*)__FUNCTION__, 01059 result 01060 ); 01061 return result; 01062 }
gchar * bm_engine_format | ( | ) |
dict_eng_module_get_format() function implementation.
Definition at line 1040 of file engine_bookmark.c.
References DIC_ENG_FORMAT, and LOGS.
Referenced by engine_global_functions().
01041 { 01042 LOGS("Bookmark/%s->%s() called.\n",(gchar*)__FILE__,(gchar*)__FUNCTION__); 01043 gchar* result = g_strdup(DIC_ENG_FORMAT); 01044 LOGS("Bookmark/%s->%s() return string=%s\n", 01045 (gchar*)__FILE__, 01046 (gchar*)__FUNCTION__, 01047 result 01048 ); 01049 return result; 01050 }
gchar * bm_engine_get_icon_path | ( | Engine * | engine | ) |
dict_eng_get_icon_path() function implementation.
Definition at line 487 of file engine_bookmark.c.
References LOGS.
Referenced by bm_engine_create().
00488 { 00489 LOGS("Bookmark/%s->%s() called.\n",(gchar*)__FILE__,(gchar*)__FUNCTION__); 00490 gchar* result = g_strdup("/usr/share/pixmaps/ws_eng_bookmark_icon.png"); 00491 LOGS("Bookmark/%s->%s() return string=%s\n", 00492 (gchar*)__FILE__, 00493 (gchar*)__FUNCTION__, 00494 result 00495 ); 00496 return result; 00497 }
gchar * bm_engine_get_lang_from | ( | Engine * | engine | ) |
dict_eng_get_lang_from() function implementation.
Definition at line 451 of file engine_bookmark.c.
References LOGS.
Referenced by bm_engine_create().
00452 { 00453 LOGS("Bookmark/%s->%s() called.\n",(gchar*)__FILE__,(gchar*)__FUNCTION__); 00454 gchar* result = g_strdup("any"); 00455 LOGS("Bookmark/%s->%s() return string=%s\n", 00456 (gchar*)__FILE__, 00457 (gchar*)__FUNCTION__, 00458 result 00459 ); 00460 return result; 00461 }
gchar * bm_engine_get_lang_to | ( | Engine * | engine | ) |
dict_eng_get_lang_to() function implementation.
Definition at line 463 of file engine_bookmark.c.
References LOGS.
Referenced by bm_engine_create().
00464 { 00465 LOGS("Bookmark/%s->%s() called.\n",(gchar*)__FILE__,(gchar*)__FUNCTION__); 00466 gchar* result = g_strdup("any"); 00467 LOGS("Bookmark/%s->%s() return string=%s\n", 00468 (gchar*)__FILE__, 00469 (gchar*)__FUNCTION__, 00470 result 00471 ); 00472 return result; 00473 }
gchar * bm_engine_get_title | ( | Engine * | engine | ) |
dict_eng_get_title() function implementation.
Definition at line 475 of file engine_bookmark.c.
References LOGS.
Referenced by bm_engine_create().
00476 { 00477 LOGS("Bookmark/%s->%s() called.\n",(gchar*)__FILE__,(gchar*)__FUNCTION__); 00478 gchar* result = g_strconcat(g_get_user_name(),"s' bookmarks",NULL); 00479 LOGS("Bookmark/%s->%s() return string=%s\n", 00480 (gchar*)__FILE__, 00481 (gchar*)__FUNCTION__, 00482 result 00483 ); 00484 return result; 00485 }
gboolean bm_engine_is_optimized | ( | Engine * | engine | ) |
dict_eng_is_optimized() function implementation.
Definition at line 862 of file engine_bookmark.c.
References LOGS, and PRINT_STATE.
Referenced by bm_engine_create().
00863 { 00864 LOGS("Bookmark/%s->%s() called.\n-->PARAM: engine adress=%p\n", 00865 (gchar*)__FILE__, 00866 (gchar*)__FUNCTION__, 00867 engine 00868 ); 00869 g_assert(engine != NULL); 00870 gboolean result = FALSE; 00871 LOGS("Bookmark/%s->%s() returned bool statement=%s.\n", 00872 (gchar*)__FILE__, 00873 (gchar*)__FUNCTION__, 00874 PRINT_STATE(result) 00875 ); 00876 return result; 00877 }
gchar * bm_engine_location | ( | Engine * | engine | ) |
dict_eng_get_location() function implementation.
Definition at line 1064 of file engine_bookmark.c.
References _BookData::auto_free, _BookData::dict_path, _Engine::engine_data, and LOGS.
Referenced by bm_engine_create().
01065 { 01066 LOGS("Bookmark/%s->%s() called.\n-->PARAM: engine adress=%p\n", 01067 (gchar*)__FILE__, 01068 (gchar*)__FUNCTION__, 01069 engine 01070 ); 01071 g_assert(engine != NULL); 01072 BookData* data = (BookData*)(engine->engine_data); 01073 01074 gchar* result; 01075 if(data->auto_free) { 01076 result = data->dict_path; 01077 } 01078 else { 01079 result = g_strdup(data->dict_path); 01080 } 01081 01082 LOGS("Bookmark/%s->%s() returned string=%s\n", 01083 (gchar*)__FILE__, 01084 (gchar*)__FUNCTION__, 01085 result 01086 ); 01087 return result; 01088 }
void bm_engine_optimize | ( | Engine * | engine | ) |
dict_eng_optimize() function implementation.
Definition at line 788 of file engine_bookmark.c.
References LOGS.
Referenced by bm_engine_create().
00789 { 00790 LOGS("Bookmark/%s->%s() called for engine at adress=%p\n", 00791 (gchar*)__FILE__, 00792 (gchar*)__FUNCTION__, 00793 engine 00794 ); 00795 LOGS("Unsupported optimization mechanizm for this engine!\n"); 00796 LOGS("Bookmark/%s->%s()'s work finished.\n",(gchar*)__FILE__,(gchar*)__FUNCTION__); 00797 }
gboolean bm_engine_remove_word | ( | Engine * | engine, | |
gchar * | word | |||
) |
dict_eng_remove_word() function implementation.
Definition at line 358 of file engine_bookmark.c.
References _BookData::db_trans, _BookData::db_words, _Engine::engine_data, and LOGS.
Referenced by bm_engine_create().
00360 { 00361 gboolean result = TRUE; 00362 00363 LOGS("Bookmark/%s->%s() called. Param\nEngine at address: %p\n" 00364 "word: %s\n",(gchar*)__FILE__,(gchar*)__FUNCTION__,engine,word); 00365 g_assert(engine != NULL); 00366 g_assert(word != NULL); 00367 /* bm_timer(TIMER_START, (gchar*)(gchar*)__FUNCTION__); */ 00368 00369 BookData* data = (BookData*)(engine->engine_data); 00370 00371 DBT key = { word , strlen(word) + 1 }; 00372 DBT val = { NULL , 0 }; 00373 00374 gint db_res = data->db_words->get(data->db_words, &key, &val, 0); 00375 if ( 0 == db_res ) 00376 { 00377 guint* t = (guint*)(val.data); 00378 guint N = t[0]; 00379 guint id = 0; 00380 memcpy(&N, t, sizeof(guint)); 00381 ++t; 00382 guint i = 0; 00383 key.size = sizeof(guint); 00384 key.data = &id; 00385 while( i < N ) { 00386 memcpy(&id, t + i*2, sizeof(guint)); 00387 db_res = data->db_trans->del(data->db_trans, &key, 0); 00388 if(0 != db_res) { 00389 LOGS("Error while removing translation # %u for word: %s",i+1,word); 00390 } 00391 ++i; 00392 } 00393 } 00394 else if( -1 == db_res) { 00395 LOGS("Bookmark/%s->%s() Error while removing word: %s!", 00396 (gchar*)__FILE__, 00397 (gchar*)__FUNCTION__, 00398 word 00399 ); 00400 return FALSE; 00401 } 00402 else { 00403 LOGS("Bookmark/%s->%s() Ther is no such a word!", 00404 (gchar*)__FILE__, 00405 (gchar*)__FUNCTION__ 00406 ); 00407 return TRUE; 00408 }; 00409 00410 // all data from trnaslation database has been deleted - now delete 00411 // record in words database. 00412 00413 DBT key_del = { word , strlen(word) + 1 }; 00414 db_res = data->db_words->del(data->db_words,&key_del,0); 00415 if(-1 == db_res) 00416 { 00417 LOGS("Bookmark/%s->%s() Error while removing!\n", 00418 (gchar*)__FILE__, 00419 (gchar*)__FUNCTION__ 00420 ); 00421 } 00422 else if(1 == db_res) 00423 { 00424 LOGS("Bookmark/%s->%s() There is no such a word!\n", 00425 (gchar*)__FILE__, 00426 (gchar*)__FUNCTION__ 00427 ); 00428 } 00429 else if(0 == db_res) 00430 { 00431 LOGS("Bookmark/%s->%s() word deleted successfully!\n", 00432 (gchar*)__FILE__, 00433 (gchar*)__FUNCTION__ 00434 ); 00435 } 00436 db_res = data->db_words->sync(data->db_words, 0); 00437 00438 if((0 != db_res) || (NULL == data->db_words) || (NULL == data->db_trans)) { 00439 LOGS("Error while 2nd synchronizing file with data!\n"); 00440 } 00441 00442 00443 /* bm_timer(TIMER_STOP, (gchar*)(gchar*)__FUNCTION__); */ 00444 LOGS("Bookmark/%s->%s() finished work.\n", 00445 (gchar*)__FILE__, 00446 (gchar*)__FUNCTION__ 00447 ); 00448 return result; 00449 }
void bm_engine_search_word_list | ( | Engine * | engine, | |
gchar * | pattern, | |||
gpointer | data | |||
) |
dict_eng_search_word_list() function implementation.
Definition at line 879 of file engine_bookmark.c.
References _BookData::cb_search_word_list, _BookData::cb_search_word_list_data, _BookData::db_words, _Engine::engine_data, ENGINE_NO_ERROR, and LOGS.
Referenced by bm_engine_create().
00882 { 00883 LOGS("Bookmark/%s->%s() called. Searching words list\n" 00884 "-->PARAM:engine at adress=%p\n" 00885 "-->PARAM:pattern=\"%s\"\n", 00886 (gchar*)__FILE__, 00887 (gchar*)__FUNCTION__, 00888 engine, 00889 pattern 00890 ); 00891 g_assert(engine != NULL); 00892 g_assert(pattern != NULL); 00893 00894 /* bm_timer(TIMER_START,(gchar*)(gchar*)__FUNCTION__); */ 00895 BookData* data = (BookData*)(engine->engine_data); 00896 if(data->cb_search_word_list == NULL) { 00897 LOGS("Bookmark/%s->%s() callback for Word List not set. " 00898 "Searching aborted.\n", 00899 (gchar*)__FILE__, 00900 (gchar*)__FUNCTION__ 00901 ); 00902 /* bm_timer(TIMER_STOP,(gchar*)(gchar*)__FUNCTION__); */ 00903 return; 00904 }; 00905 00906 GArray* result = g_array_new(TRUE, TRUE, sizeof(gchar*) ); 00907 guint a = G_MAXUINT32; 00908 DBT search = { &a , sizeof(a) }; 00909 DBT reply = { NULL , 0 }; 00910 gchar* down_word = NULL; 00911 gchar *tmp; 00912 00913 GPatternSpec* regex; 00914 regex = g_pattern_spec_new (g_utf8_casefold(pattern,-1)); 00915 00916 gint code = data->db_words->sync(data->db_words, 0); 00917 code = data->db_words->seq(data->db_words, &search, &reply, R_FIRST); 00918 00919 /* 00920 if((('*' == pattern[0]) && ('\0' == pattern[1])) || ('\0' == pattern[0])) 00921 { 00922 // especiall treat if user give only '*' 00923 while(0 == code) { 00924 gchar* cos = g_strdup(search.data); 00925 g_array_append_val(result,cos); 00926 code = data->db_words->seq(data->db_words, &search, &reply, R_NEXT); 00927 // we are giving to the user all words from dictionary 00928 } 00929 } 00930 else 00931 {*/ 00932 while(0 == code) { 00933 tmp = g_strconcat ((gchar*)(search.data), " ", NULL); 00934 down_word = g_utf8_casefold(tmp,-1); 00935 g_free (tmp); 00936 tmp = g_utf8_casefold ((gchar*)(search.data),-1); 00937 00938 if(( g_pattern_match_string( regex, down_word ) == TRUE ) || 00939 ( g_pattern_match_string( regex, tmp ) == TRUE )) 00940 { 00941 g_free (tmp); 00942 tmp = g_strdup(search.data); 00943 g_array_append_val(result, tmp ); 00944 }; 00945 00946 /* eg_free(reply.data); */ 00947 if(NULL != down_word) 00948 { 00949 g_free(down_word); 00950 down_word = NULL; 00951 } 00952 code = data->db_words->seq(data->db_words, &search, &reply, R_NEXT); 00953 } 00954 00955 /* bm_timer(TIMER_STOP,(gchar*)(gchar*)__FUNCTION__); */ 00956 g_pattern_spec_free (regex); 00957 00958 00959 /* bm_timer(TIMER_START,"callback for returning words LIST START"); */ 00960 // calling callback for word translation 00961 00962 if ( NULL == cb_data ) 00963 { 00964 cb_data = data->cb_search_word_list_data; 00965 } 00966 data->cb_search_word_list(result, pattern, cb_data, ENGINE_NO_ERROR); 00967 00968 00969 /* if(data->auto_free) { 00970 LOGS("Bookmark/%s->%s() deleting all dynamic data because " 00971 "AUTO_FREE=TRUE\n", 00972 (gchar*)__FILE__, 00973 (gchar*)__FUNCTION__ 00974 ); 00975 len = 0; 00976 while(NULL != (tmp = g_array_index(result,gchar*,len++))) 00977 { 00978 g_free(tmp); tmp = NULL; 00979 } 00980 g_array_free(result, TRUE); 00981 }*/ 00982 guint len = 0; 00983 00984 while(NULL != (tmp = g_array_index(result,gchar*,len++))) 00985 { 00986 g_free(tmp); tmp = NULL; 00987 } 00988 g_array_free(result, TRUE); 00989 /* bm_timer(TIMER_STOP,"callback for returning word LIST END"); */ 00990 }
void bm_engine_search_word_translation | ( | Engine * | engine, | |
gchar * | word, | |||
gpointer | data | |||
) |
dict_eng_search_word_translation() function implementation.
Definition at line 499 of file engine_bookmark.c.
References _BookData::cb_search_word_trans, _BookData::cb_search_word_trans_data, _BookData::db_trans, _BookData::db_words, _Engine::engine_data, ENGINE_NO_ERROR, and LOGS.
Referenced by bm_engine_create().
00502 { 00503 LOGS("Bookmark/%s->%s() called.\n-->PARAM:engine at adress=%p\n" 00504 "-->PARAM:word=\'%s\'\n", 00505 (gchar*)__FILE__, 00506 (gchar*)__FUNCTION__, 00507 engine, 00508 word 00509 ); 00510 g_assert(engine != NULL); 00511 g_assert(word != NULL); 00512 // start bm_timer for this function 00513 /* bm_timer(TIMER_START, (gchar*)(gchar*)__FUNCTION__); */ 00514 BookData* data = (BookData*)(engine->engine_data); 00515 00516 gchar* down_word = g_utf8_strdown(word,-1); 00517 DBT search = { down_word , strlen(down_word) + 1 }; 00518 DBT info = { NULL , 0 }; 00519 DBT trans = { NULL , 0 }; 00520 gchar* tran = NULL; 00521 gchar* tran_ = NULL; 00522 00523 gint tmp = data->db_words->get(data->db_words, &search, &info, 0); 00524 if(0 == tmp) 00525 { 00526 // plugin found some information about this word 00527 00528 guint* records = (guint*)(info.data); 00529 guint count = records[0]; 00530 memcpy(&count, records, sizeof(guint)); 00531 //printf("Buffer (memcpy): %#x-%#x-%#x\n",count,records[1],records[2]); 00532 ++records; 00533 guint id = 0; 00534 search.data = &id; 00535 search.size = sizeof(guint); 00536 00537 while(count-- > 0 && count < 100) 00538 { 00539 //printf("--> LOOP:count = %#x\n",count); 00540 memcpy(search.data, records, sizeof(guint)); 00541 records += 2; 00542 tmp = data->db_trans->get(data->db_trans, &search, &trans, 0); 00543 if(0 == tmp) 00544 { 00545 if(NULL == tran) 00546 { 00547 tran = g_strdup(trans.data); 00548 } 00549 else 00550 { 00551 tran_ = 00552 g_strconcat(tran,"<br />",trans.data,NULL); 00553 g_free(tran); 00554 tran = tran_; 00555 tran_ = NULL; 00556 } 00557 } 00558 } 00559 }; 00560 g_free(down_word); 00561 /* bm_timer(TIMER_STOP,(gchar*)(gchar*)__FUNCTION__); 00562 bm_timer(TIMER_START,"callback for returning word's translation START"); 00563 */ 00564 // calling callback for word translation 00565 00566 if ( NULL == cb_data ) 00567 { 00568 cb_data = data->cb_search_word_trans_data; 00569 } 00570 data->cb_search_word_trans(tran, word, cb_data, ENGINE_NO_ERROR); 00571 00572 /* bm_timer(TIMER_STOP,"callback for returning word's translation END"); 00573 */ 00574 // if(data->auto_free) { 00575 // LOGS("Bookmark/%s->%s() deleting all dynamic data because " 00576 // "AUTO_FREE=TRUE\n", 00577 // (gchar*)__FILE__, 00578 // (gchar*)__FUNCTION__ 00579 // ); 00580 // g_free(tran); 00581 // } 00582 g_free(tran); 00583 tran = NULL; 00584 }
void bm_engine_set_auto_free | ( | Engine * | engine, | |
gboolean | state | |||
) |
dict_eng_set_auto_free() function implementation.
Definition at line 1090 of file engine_bookmark.c.
References _BookData::auto_free, _Engine::engine_data, LOGS, and PRINT_STATE.
Referenced by bm_engine_create().
01091 { 01092 LOGS("Bookmark/%s->%s() called.\n" 01093 "-->PARAM:engine at adress=%p\n" 01094 "-->PARAM:state=%s\n", 01095 (gchar*)__FILE__, 01096 (gchar*)__FUNCTION__, 01097 engine, 01098 PRINT_STATE(state) 01099 ); 01100 g_assert(engine != NULL); 01101 BookData* data = (BookData*)(engine->engine_data); 01102 01103 data->auto_free = state; 01104 LOGS("Bookmark/%s->%s() Current auto_free is %s\n", 01105 (gchar*)__FILE__, 01106 (gchar*)__FUNCTION__, 01107 PRINT_STATE(data->auto_free) 01108 ); 01109 }
gpointer bm_engine_set_callback | ( | Engine * | engine, | |
gchar * | event, | |||
gpointer | c_handler, | |||
gpointer | user_data | |||
) |
dict_eng_set_callback() function implementation.
Definition at line 1150 of file engine_bookmark.c.
References _BookData::cb_progress_caching, _BookData::cb_progress_caching_data, _BookData::cb_search_word_list, _BookData::cb_search_word_list_data, _BookData::cb_search_word_trans, _BookData::cb_search_word_trans_data, _Engine::engine_data, ENGINE_PROGRESS_OPTIMIZING_SIGNAL, ENGINE_WORD_LIST_SIGNAL, ENGINE_WORD_TRANSLATION_SIGNAL, and LOGS.
Referenced by bm_engine_create().
01154 { 01155 LOGS("Bookmark/%s->%s() called.\n",(gchar*)__FILE__,(gchar*)__FUNCTION__); 01156 g_assert(engine != NULL); 01157 g_assert(signal != NULL); 01158 g_assert(c_handler != NULL); 01159 BookData* data = (BookData*)(engine->engine_data); 01160 if(g_ascii_strcasecmp(signal,ENGINE_PROGRESS_OPTIMIZING_SIGNAL) == 0) { 01161 gpointer result = data->cb_progress_caching; 01162 data->cb_progress_caching = c_handler; 01163 data->cb_progress_caching_data = user_data; 01164 LOGS("Bookmark/%s->%s() sets handler for signal \"%s\".\n", 01165 (gchar*)__FILE__, 01166 (gchar*)__FUNCTION__, 01167 signal 01168 ); 01169 LOGS("Bookmark/%s->%s() Function at adress = %d.\n", 01170 (gchar*)__FILE__, 01171 (gchar*)__FUNCTION__, 01172 (guint)c_handler 01173 ); 01174 LOGS("Bookmark/%s->%s() Data at adress = %d.\n", 01175 (gchar*)__FILE__, 01176 (gchar*)__FUNCTION__, 01177 (guint)user_data 01178 ); 01179 return result; 01180 } 01181 else if(g_ascii_strcasecmp(signal, ENGINE_WORD_LIST_SIGNAL) == 0) { 01182 gpointer result = data->cb_search_word_list; 01183 data->cb_search_word_list = c_handler; 01184 data->cb_search_word_list_data = user_data; 01185 LOGS("Bookmark/%s->%s() sets handler for signal \"%s\".\n", 01186 (gchar*)__FILE__, 01187 (gchar*)__FUNCTION__, 01188 signal 01189 ); 01190 LOGS("Bookmark/%s->%s() Function at adress = %d.\n", 01191 (gchar*)__FILE__, 01192 (gchar*)__FUNCTION__, 01193 (guint)c_handler 01194 ); 01195 LOGS("Bookmark/%s->%s() Data at adress = %d.\n", 01196 (gchar*)__FILE__, 01197 (gchar*)__FUNCTION__, 01198 (guint)user_data 01199 ); 01200 return result; 01201 } 01202 else if(g_ascii_strcasecmp(signal, 01203 ENGINE_WORD_TRANSLATION_SIGNAL) == 0) { 01204 gpointer result = data->cb_search_word_trans; 01205 data->cb_search_word_trans = c_handler; 01206 data->cb_search_word_trans_data = user_data; 01207 LOGS("Bookmark/%s->%s() sets handler for signal \"%s\".\n", 01208 (gchar*)__FILE__, 01209 (gchar*)__FUNCTION__, 01210 signal 01211 ); 01212 LOGS("Bookmark/%s->%s() Function at adress = %d.\n", 01213 (gchar*)__FILE__, 01214 (gchar*)__FUNCTION__, 01215 (guint)c_handler 01216 ); 01217 LOGS("Bookmark/%s->%s() Data at adress = %d.\n", 01218 (gchar*)__FILE__, 01219 (gchar*)__FUNCTION__, 01220 (guint)user_data 01221 ); 01222 return result; 01223 } 01224 else { 01225 g_warning("Bookmark/%s->%s() unsupported signal: %s.\n", 01226 (gchar*)__FILE__, 01227 (gchar*)__FUNCTION__, 01228 signal 01229 ); 01230 return NULL; 01231 } 01232 }
void bm_engine_set_progress_seed | ( | Engine * | engine, | |
gchar * | signal, | |||
gdouble | seed | |||
) |
dict_eng_set_progress_seed() function implementation.
Definition at line 1128 of file engine_bookmark.c.
References _BookData::cb_progress_caching_seed, _Engine::engine_data, ENGINE_PROGRESS_OPTIMIZING_SIGNAL, and LOGS.
Referenced by bm_engine_create().
01128 { 01129 LOGS("Bookmark/%s->%s() called.\n",(gchar*)__FILE__,(gchar*)__FUNCTION__); 01130 BookData* data = (BookData*)(engine->engine_data); 01131 if(g_ascii_strcasecmp(signal,ENGINE_PROGRESS_OPTIMIZING_SIGNAL) == 0) { 01132 data->cb_progress_caching_seed = seed; 01133 LOGS("Bookmark/%s->%s() sets new seed=%0.2f for for signal " 01134 "\"%s\".\n", 01135 (gchar*)__FILE__, 01136 (gchar*)__FUNCTION__, 01137 seed, 01138 signal 01139 ); 01140 } 01141 else { 01142 LOGS("Bookmark/%s->%s() unsupported signalfor progress: %s.\n", 01143 (gchar*)__FILE__, 01144 (gchar*)__FUNCTION__, 01145 signal 01146 ); 01147 }; 01148 }
EngineStatus bm_engine_status | ( | Engine * | engine | ) |
dict_eng_get_last_status() function implementation.
Definition at line 1111 of file engine_bookmark.c.
References _Engine::engine_data, _BookData::last_error, and LOGS.
Referenced by bm_engine_create().
01112 { 01113 LOGS("Bookmark/%s->%s() called.\n" 01114 "-->PARAM:engine at adress=%p\n", 01115 (gchar*)__FILE__, 01116 (gchar*)__FUNCTION__, 01117 engine 01118 ); 01119 BookData* data = (BookData*)(engine->engine_data); 01120 LOGS("Bookmark/%s->%s() returned error code: %d\n", 01121 (gchar*)__FILE__, 01122 (gchar*)__FUNCTION__, 01123 (gint)(data->last_error) 01124 ); 01125 return data->last_error; 01126 }
gchar * bm_engine_status_message | ( | EngineStatus | error | ) |
dict_eng_status_message() function implementation.
Definition at line 1009 of file engine_bookmark.c.
References ENGINE_COULDNT_READ, ENGINE_NO_ERROR, ENGINE_NO_FILE, ENGINE_OUT_OF_MEMORY, ENGINE_WRONG_FILE, and LOGS.
Referenced by bm_engine_create().
01010 { 01011 LOGS("Bookmark/%s->%s() called.\n",(gchar*)__FILE__,(gchar*)__FUNCTION__); 01012 switch (error) { 01013 case ENGINE_NO_ERROR: 01014 return "No error."; 01015 case ENGINE_WRONG_FILE: 01016 return "File which You are trying to use is wrong type."; 01017 case ENGINE_COULDNT_READ: 01018 return "Could not read from file."; 01019 case ENGINE_NO_FILE: 01020 return "There is no such a file."; 01021 case ENGINE_OUT_OF_MEMORY: 01022 return "There were no enough memory for this action."; 01023 default: 01024 return "Wrong engine's status identifier!"; 01025 } 01026 }
gchar * bm_engine_version | ( | ) |
dict_eng_module_get_version() function implementation.
Definition at line 1028 of file engine_bookmark.c.
References DIC_ENG_VERSION, and LOGS.
Referenced by engine_global_functions().
01029 { 01030 LOGS("Bookmark/%s->%s() called.\n",(gchar*)__FILE__,(gchar*)__FUNCTION__); 01031 gchar* result = g_strdup(DIC_ENG_VERSION); 01032 LOGS("Bookmark/%s->%s() return string=%s\n", 01033 (gchar*)__FILE__, 01034 (gchar*)__FUNCTION__, 01035 result 01036 ); 01037 return result; 01038 }
static void bm_load_freeID | ( | BookData * | data | ) | [static] |
Get minimal free value available for word's id.
Definition at line 100 of file engine_bookmark.c.
References _BookData::db_trans, ENGINE_INTERNAL_ERROR, _BookData::freeID, _BookData::last_error, and LOGS.
Referenced by bm_engine_create().
00101 { 00102 guint temp = 0; 00103 DBT key = { &temp , sizeof(guint) }; 00104 DBT val = { NULL , 0 }; 00105 00106 gint res = data->db_trans->get(data->db_trans, &key, &val, 0); 00107 if(-1 == res) 00108 { 00109 data->last_error = ENGINE_INTERNAL_ERROR; 00110 LOGS("Bookmark/%s->%s() Error while getting access to trans " 00111 "database!", 00112 (gchar*)__FILE__, 00113 (gchar*)__FUNCTION__ 00114 ); 00115 } 00116 else if( 1 != res) 00117 { 00118 memcpy(&(data->freeID), val.data, sizeof(guint)); 00119 //data->freeID = *((guint*)(val.data)); 00120 LOGS("Bookmark/%s->%s() Available next free ID is equal = %d", 00121 (gchar*)__FILE__, 00122 (gchar*)__FUNCTION__, 00123 data->freeID 00124 ); 00125 } 00126 else 00127 { 00128 LOGS("Bookmark/%s->%s() Could not load the minimal, available" 00129 " ID for next record - translation!", 00130 (gchar*)__FILE__, 00131 (gchar*)__FUNCTION__ 00132 ); 00133 data->freeID = 1; 00134 data->last_error = ENGINE_INTERNAL_ERROR; 00135 } 00136 }
static void bm_save_freeID | ( | BookData * | data | ) | [static] |
Get minimal free value available for word's id.
Definition at line 58 of file engine_bookmark.c.
References _BookData::db_trans, ENGINE_INTERNAL_ERROR, _BookData::freeID, _BookData::last_error, and LOGS.
Referenced by bm_add_new_entry(), and bm_engine_add_word().
00059 { 00060 LOGS("Saveing new freeID=%u...\n",data->freeID); 00061 guint temp = 0; 00062 DBT key = { &temp , sizeof(guint)}; 00063 DBT val = { &(data->freeID) , sizeof(guint) }; 00064 00065 gint res = data->db_trans->del(data->db_trans, &key, 0); 00066 if(-1 == res) 00067 { 00068 data->last_error = ENGINE_INTERNAL_ERROR; 00069 LOGS("Error while trying to delete old freeID!\n"); 00070 return; 00071 } 00072 else 00073 { 00074 LOGS("Old freeID=%u deleted successfully!\n",data->freeID-1); 00075 } 00076 00077 res = data->db_trans->put(data->db_trans, &key, &val, R_NOOVERWRITE); 00078 if(-1 == res || 1 == res) 00079 { 00080 data->last_error = ENGINE_INTERNAL_ERROR; 00081 LOGS("Error while trying to write new value for freeID!\n"); 00082 } 00083 else 00084 { 00085 LOGS("New freeID=%u written successfully!\n",data->freeID); 00086 } 00087 00088 res = data->db_trans->sync(data->db_trans, 0); 00089 if(-1 == res || 1 == res) 00090 { 00091 data->last_error = ENGINE_INTERNAL_ERROR; 00092 LOGS("Error while trying to write data to fuile!\n"); 00093 } 00094 else 00095 { 00096 LOGS("New data saved successfully to file!\n"); 00097 } 00098 }
EngineModule engine_global_functions | ( | void | ) |
implementation of engine_global_functions(void) function.
Definition at line 1325 of file engine_stardict.c.
01326 { 01327 eg_debug("-> %s() called.\n",__FUNCTION__); 01328 EngineModule result; 01329 result.engine_check = sd_engine_check; 01330 result.engine_description= sd_engine_description; 01331 result.engine_format = sd_engine_format; 01332 result.engine_version = sd_engine_version; 01333 result.engine_create = sd_engine_create; 01334 eg_debug("<- %s() returned EngineModule at adress=%p.\n", 01335 __FUNCTION__, 01336 &result 01337 ); 01338 return result; 01339 }
static gboolean is_Bookmark_db_file | ( | gchar * | file | ) | [static] |
Tells if file is in Bookmarks format (file should exist).
Definition at line 754 of file engine_bookmark.c.
References LOGS.
Referenced by bm_engine_check().
00755 { 00756 LOGS("Bookmark/%s->%s() called.\n\ 00757 -->PARAM:file=\'%s\'\n", 00758 (gchar*)__FILE__, 00759 (gchar*)__FUNCTION__, 00760 file 00761 ); 00762 00763 u_int32_t flags = O_RDWR; 00764 DB* dbp = dbopen(file,flags,0755,DB_BTREE,NULL); 00765 00766 if(NULL == dbp) 00767 { 00768 LOGS("Could no open! Wrong database! Not a bookmark.\n"); 00769 return FALSE; 00770 }; 00771 00772 DBT search = {"four",sizeof("four")}; 00773 DBT result = {NULL, 0}; 00774 00775 int errCode = dbp->get(dbp,&search,&result,0); 00776 dbp->close(dbp); 00777 g_free(result.data); 00778 00779 if(-1 == errCode) 00780 { 00781 LOGS("Could not read! Wrong database! Not a bookmark.\n"); 00782 return FALSE; 00783 }; 00784 return TRUE; 00785 }
static gchar* string_to_path | ( | gchar ** | string | ) | [static] |
Convert string to proper path name.
Translate given string to proper full file path. Function works "in-situ". It means that string is translated and replaced by proper full file path if this file path exists, or this string is cleared and setted to NULL, if string was representing wrong path. This function is static - to use only within this module.
string | pointer to to string representing file path - it will be replaced by a proper filepath. It should be path to directory or file, ended with "/" or not, absolute or not |
Referenced by bm_engine_check(), bm_engine_create(), xdxf_engine_check(), and xdxf_engine_create().
const gchar* DIC_ENG_DESCRIPTION [static] |
Initial value:
"This module handles users' book" "marks. Based on Berkeley DB 1.85"
Definition at line 90 of file engine_bookmark.h.
Referenced by bm_engine_description().
const gchar* DIC_ENG_FORMAT = "Users' Bookmarks" [static] |
Short description of format supported by the current engine.
Definition at line 87 of file engine_bookmark.h.
const gchar* DIC_ENG_VERSION = "0.2" [static] |