src/bookmarks/bdb/src/engine_bookmark.c

Go to the documentation of this file.
00001 /******************************************************************************
00002 This file is part of mdictionary.
00003 
00004 mdictionary is free software; you can redistribute it and/or modify
00005 it under the terms of the GNU General Public License as published by
00006 the Free Software Foundation; either version 2 of the License, or
00007 (at your option) any later version.
00008 
00009 mdictionary is distributed in the hope that it will be useful, 
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License 
00015 along with mdictionary; if not, write to the Free Software
00016 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00017 
00018 Copyright 2006-2008 ComArch S.A.
00019 ******************************************************************************/
00026 #include "engine_bookmark.h"
00027 
00028 #ifndef NOLOGS
00029         #include <glib/gstdio.h>
00030         #define LOGS g_debug
00031 #else
00032         #define LOGS(frm,...) while(FALSE)
00033 #endif
00034 
00035 
00036 static gint bm_compare_key_trans(const DBT *a, const DBT *b)
00037 {
00038         guint tmpa;// = (guint*)(a->data);
00039         guint tmpb;// = (guint*)(b->data);
00040         memcpy(&tmpa, a->data, sizeof(guint));
00041         memcpy(&tmpb, b->data, sizeof(guint));
00042 
00043         if(tmpa == tmpb) return 0;
00044         if(tmpa  > tmpb) return 1;
00045         else return -1;
00046 }
00047 
00048 static gint bm_compare_key_words(const DBT *a, const DBT *b)
00049 {
00050         gchar* tmpa = g_utf8_casefold((gchar*)(a->data),-1);
00051         gchar* tmpb = g_utf8_casefold((gchar*)(b->data),-1);
00052         gint result = g_utf8_collate(tmpa,tmpb);
00053         g_free(tmpa); tmpa = NULL;
00054         g_free(tmpb); tmpb = NULL;
00055         return result;
00056 }
00057 
00058 static void bm_save_freeID(BookData* data)
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 }
00099 
00100 static void bm_load_freeID(BookData* data)
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 }
00137 
00138 
00139 
00140 gboolean bm_engine_add_word( Engine* engine,
00141                              gchar*  word,
00142                              gchar*  translation)
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 }
00273 
00274 static gboolean bm_add_only_translation(BookData* data,
00275                                         gchar* translation,
00276                                         guint id)
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 }
00295 
00296 static gboolean bm_add_new_entry(gchar* word,gchar* translation,BookData* data)
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 }
00357 
00358 gboolean bm_engine_remove_word(Engine* engine,
00359                              gchar*  word)
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 }
00450 
00451 gchar* bm_engine_get_lang_from(Engine* engine)
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 }
00462 
00463 gchar* bm_engine_get_lang_to(Engine* engine)
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 }
00474 
00475 gchar* bm_engine_get_title(Engine* engine)
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 }
00486 
00487 gchar* bm_engine_get_icon_path(Engine* engine)
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 }
00498 
00499 void bm_engine_search_word_translation(Engine* engine,
00500                                        gchar* word,
00501                                        gpointer cb_data)
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 }
00585 
00586 void bm_engine_close(Engine* engine)
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 }
00608 
00609 Engine* bm_engine_create(gchar* location,
00610                       EngineOptimizationFlag auto_cache,
00611                       cb_progress progress_handler,
00612                       gpointer progress_data,
00613                       gdouble seed)
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 }
00752 
00753 
00754 static gboolean is_Bookmark_db_file(gchar* file)
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 }
00786 
00787 
00788 void bm_engine_optimize(Engine* engine)
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 }
00798 
00799 gboolean bm_engine_check(gchar* location) 
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 }
00861 
00862 gboolean bm_engine_is_optimized(Engine* engine) 
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 }
00878 
00879 void bm_engine_search_word_list(Engine* engine,
00880                                 gchar* pattern,
00881                                 gpointer cb_data)
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 }
00991 
00992 EngineModule engine_global_functions()
00993 {
00994         LOGS("Bookmark/%s->%s() called.\n",(gchar*)__FILE__,(gchar*)__FUNCTION__);
00995         EngineModule result;        
00996         result.engine_check             = bm_engine_check;
00997         result.engine_description       = bm_engine_description;
00998         result.engine_format            = bm_engine_format;
00999         result.engine_version           = bm_engine_version;
01000         result.engine_create            = bm_engine_create;
01001         LOGS("Bookmark/%s->%s()returned EngineModule at adress=%p.\n",
01002              (gchar*)__FILE__,
01003              (gchar*)__FUNCTION__,
01004              &result
01005             );
01006         return result;
01007 }
01008 
01009 gchar* bm_engine_status_message(EngineStatus error) 
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 }
01027 
01028 gchar* bm_engine_version() 
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 }
01039 
01040 gchar* bm_engine_format() 
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 }
01051 
01052 gchar* bm_engine_description() 
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 }
01063 
01064 gchar* bm_engine_location(Engine* engine)
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 }
01089 
01090 void bm_engine_set_auto_free(Engine* engine, gboolean state) 
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 }
01110 
01111 EngineStatus bm_engine_status(Engine* engine) 
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 }
01127 
01128 void bm_engine_set_progress_seed(Engine* engine, gchar* signal, gdouble seed) {
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 }
01149 
01150 gpointer bm_engine_set_callback(Engine* engine,
01151                              gchar* signal,
01152                              gpointer c_handler,
01153                              gpointer user_data)
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 }
01248 static gchar* string_to_path(gchar** string) {
01249         g_debug("XDXF/%s->%s() called.\n"
01250                 "-->PARAM:string=\'%s\'\n",
01251                 __FILE__,
01252                 __FUNCTION__,
01253                 string[0] );
01254         gchar* arg = string[0];
01255         gchar* new = NULL;
01256 
01257         /* cleaning from leading and trailing whitespaces */
01258         g_strstrip(arg);
01259 
01260         /* add current directory if this is not absolute directory */
01261         if (!g_path_is_absolute(arg))
01262         {
01263                 gchar* tmp = g_get_current_dir();
01264                 new = g_strconcat(tmp,"/",arg,NULL);
01265                 g_free(arg); arg = new; new = NULL;
01266         };
01267 
01268         /* this is not a directory */
01269         if (!g_file_test(arg, G_FILE_TEST_IS_DIR))
01270         {
01271                 /* if this is wrong filepath, string was wrong */
01272                 if (!g_file_test(arg, G_FILE_TEST_IS_REGULAR))
01273                 {
01274                         g_free(arg);
01275                         new = NULL;
01276                 }
01277                 else
01278                 {
01279                         /* if this is a file, remove filename */
01280                         new = g_path_get_dirname (arg);
01281                         g_free(arg);
01282                 }
01283         }
01284         else
01285         {
01286                 /* this is a directory ... */
01287                 /* remove suffix "/" if neded... */
01288                 if (g_str_has_suffix(arg,"/") )
01289                 {
01290                         new = g_path_get_dirname (arg);
01291                         g_free(arg);
01292                 }
01293                 else
01294                 {
01295                         new = arg;
01296                 }
01297         };
01298 
01299         /* now in new should be proper filepath, if not, string was wrong */
01300         if (!g_file_test(new, G_FILE_TEST_IS_DIR))
01301         {
01302                 /* if that directory does not exist, passed string wasn't proper
01303                  */
01304                 g_free(new);
01305                 new = NULL;
01306         };
01307 
01308         /* replace string under passed address */
01309         string[0] = new;
01310         g_debug("XDXF/%s->%s() returned string=\'%s\'\n",
01311                  __FILE__,
01312                  __FUNCTION__,
01313                  string[0] );
01314         return new;
01315 }
01316 
01317 /*
01318 static double bm_timer(gboolean start, gchar* message)
01319 {
01320         static GArray* stack = NULL;
01321         static gboolean first_run = TRUE;
01322         static struct timeval actual_time;
01323         static struct timeval last_time;
01324         static struct timeval result;
01325         static double seconds = 0.0;
01326         if(first_run) {
01327                 first_run = FALSE;
01328                 stack = g_array_new(TRUE, TRUE, sizeof(struct timeval));
01329         };
01330 
01331         if (start) {
01332                 LOGS("Bookmark->%s() start bm_timer for function '%s()'.\n",
01333                         (gchar*)__FUNCTION__,
01334                         message
01335                        );
01336                 g_array_prepend_val(stack, actual_time);
01337                 gettimeofday(&g_array_index(stack, struct timeval, 0),NULL);
01338                 return -1.0;
01339         }
01340         else
01341         {
01342                 gettimeofday(&actual_time,NULL);
01343                 last_time = g_array_index(stack, struct timeval, 0);
01344                 g_array_remove_index(stack, 0);
01345 
01346                 if (actual_time.tv_usec < last_time.tv_usec) {
01347                         int nsec = (last_time.tv_usec - actual_time.tv_usec) / 
01348                                         (1000000 + 1);
01349                         last_time.tv_usec -= 1000000 * nsec;
01350                         last_time.tv_sec += nsec;
01351                 }
01352                 if (actual_time.tv_usec - last_time.tv_usec > 1000000) {
01353                         int nsec = (last_time.tv_usec - actual_time.tv_usec) / 
01354                                         1000000;
01355                         last_time.tv_usec += 1000000 * nsec;
01356                         last_time.tv_sec -= nsec;
01357                 }
01358                 result.tv_sec = actual_time.tv_sec - last_time.tv_sec;
01359                 result.tv_usec = actual_time.tv_usec - last_time.tv_usec;
01360                 seconds = (((double)(result.tv_usec)) / 1e6) +
01361                            ((double)(result.tv_sec));
01362 
01363                 LOGS("Bookmark->%s() function \'%s()\' was working for: %g "
01364                      "[s] or %ld [us].\n",
01365                      (gchar*)__FUNCTION__,
01366                      message,
01367                      seconds,
01368                      ((long)(result.tv_sec*1e6)+(result.tv_usec)) );
01369                 if(stack->len == 0)
01370                 {
01371                         g_array_free(stack, TRUE);
01372                         first_run = TRUE;
01373                 }
01374         }
01375         return seconds;
01376 }
01377 */

Generated on Fri Jan 11 14:30:17 2008 for mDictionary Project by  doxygen 1.5.1