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 ComArch S.A. 00019 *******************************************************************************/ 00020 #ifndef _DICTIONARY__XDXF 00021 #define _DICTIONARY_ENGINE_XDXF 00022 00023 #ifdef __cplusplus 00024 extern "C" { 00025 #endif 00026 00027 //______________________________________________________________________________ 00028 // ***************************************************************************** 00029 //************************************************************* HEADERS SECTION: 00030 //------------------------------------------------------------------------------ 00031 // headers with unix types/functions - onl for timers 00032 #include <sys/types.h> 00033 #include <sys/stat.h> 00034 #include <sys/time.h> 00035 #include <fcntl.h> 00036 #include <unistd.h> 00037 //------------------------------------------------------------------------------ 00038 // header with GLIB definitions/functions/types 00039 #include <glib.h> 00040 //------------------------------------------------------------------------------ 00041 // header with gnome-vfs - recommended I/O API for maemo 00042 #include <libgnomevfs/gnome-vfs.h> 00043 //------------------------------------------------------------------------------ 00044 // header with expat - XML Parser API 00045 #include <expat.h> 00046 //------------------------------------------------------------------------------ 00047 // header wit engine API 00048 #include <dictionary_engine.h> 00049 //------------------------------------------------------------------------------ 00050 #include <stdio.h> 00051 00052 00053 //______________________________________________________________________________ 00054 // ***************************************************************************** 00055 //********************************************************* DEFINITIONS SECTION: 00056 //------------------------------------------------------------------------------ 00057 // definitions for timer function - flag telling if we want to start or stop 00058 // timing 00059 #define TIMER_START TRUE 00060 #define TIMER_STOP FALSE 00061 //------------------------------------------------------------------------------ 00062 // definitions of version and format which engine handles 00063 static const gchar* DIC_ENG_VERSION = "0.1"; 00064 static const gchar* DIC_ENG_FORMAT = "Users' Bookmarks"; 00065 static const gchar* DIC_ENG_DESCRIPTION = "This module handles users' bookmarks."; 00066 //------------------------------------------------------------------------------ 00067 // defines lenght of buffers for particular functions in engine which needs 00068 // big buffers 00069 #define DICT_CACHEING_BUFF_SIZE 16*1024 00070 #define DICT_SEARCHING_WORD_LIST_BUFF_SIZE 16*1024 00071 #define DICT_SEARCHING_WORD_TRAN_BUFF_SIZE 16*1024 00072 //------------------------------------------------------------------------------ 00073 // maximum length of word possible to find in any dictionary 00074 #define DICT_MAX_WORD_LENGTH 512 00075 //------------------------------------------------------------------------------ 00076 // macro for "printing" gboolean statement - "TRUE" or "FALSE" 00077 #define PRINT_STATE(state) ( (state) ? "TRUE" : "FALSE" ) 00078 //------------------------------------------------------------------------------ 00079 00080 00081 //______________________________________________________________________________ 00082 // ***************************************************************************** 00083 //****************************************** DATA STRUCTURE DEFINITIONS SECTION: 00084 //------------------------------------------------------------------------------ 00087 struct _XDXFCheckingData { 00088 gboolean further; 00089 gboolean good; 00090 guint deep; 00091 }; 00092 typedef struct _XDXFCheckingData XDXFCheckingData; 00093 //------------------------------------------------------------------------------ 00096 struct _XDXFWordsListData { 00097 gchar* last_word; 00098 gchar* pattern; 00099 guint pattern_len; 00100 guint last_word_length; 00101 GArray* result; 00102 guint one_word; 00103 gboolean cont; 00104 }; 00105 typedef struct _XDXFWordsListData XDXFWordsListData; 00106 //------------------------------------------------------------------------------ 00109 struct _XDXFWordsTransData { 00110 gchar* last_word; 00111 gchar* word; 00112 guint word_len; 00113 guint last_word_length; 00114 gchar* translation; 00115 guint one_word; 00116 gboolean cont; 00117 gulong last_start; 00118 XML_Parser* parser; 00119 gboolean found; 00120 GnomeVFSHandle* xdxf; 00121 }; 00122 typedef struct _XDXFWordsTransData XDXFWordsTransData; 00123 //------------------------------------------------------------------------------ 00126 struct _XDXFCacheData { 00127 gchar* buffer; 00128 long last_start; 00129 long last_stop; 00130 long last_length; 00131 GnomeVFSHandle* cache; 00132 XML_Parser parser; 00133 int state; 00134 long buffer_length; 00135 }; 00136 typedef struct _XDXFCacheData XDXFCacheData; 00137 //------------------------------------------------------------------------------ 00140 struct _FilePart { 00141 guint offset; 00142 guint length; 00143 }; 00144 typedef struct _FilePart FilePart; 00145 //------------------------------------------------------------------------------ 00148 struct _XDXFData { 00149 GnomeVFSHandle* xdxf; 00150 GnomeVFSHandle* cache; 00151 gchar* dict_path; 00152 EngineStatus last_error; 00153 gboolean auto_free; 00154 00155 cb_progress cb_progress_caching; 00156 gpointer cb_progress_caching_data; 00157 gdouble cb_progress_caching_seed; 00158 00159 cb_progress cb_progress_word_list; 00160 gpointer cb_progress_word_list_data; 00161 gdouble cb_progress_word_list_seed; 00162 00163 cb_progress cb_progress_word_trans; 00164 gpointer cb_progress_word_trans_data; 00165 gdouble cb_progress_word_trans_seed; 00166 00167 cb_word_list cb_search_word_list; 00168 gpointer cb_search_word_list_data; 00169 00170 cb_word_translation cb_search_word_trans; 00171 gpointer cb_search_word_trans_data; 00172 }; 00173 typedef struct _XDXFData XDXFData; 00174 //------------------------------------------------------------------------------ 00175 00176 00177 //______________________________________________________________________________ 00178 // ***************************************************************************** 00179 //*************************************************** PARSING FUNCTIONS SECTION: 00180 //------------------------------------------------------------------------------ 00181 // while is_bm_file() is working 00182 static void is_bm_file_start(void *data, 00183 const char *el, 00184 const char **attr); 00185 static void is_bm_file_end(void *data, const char *el); 00186 //------------------------------------------------------------------------------ 00187 // while dict_eng_search_word_list() is working 00188 static void search_word_list_start(void *data, 00189 const char *el, 00190 const char **attr); 00191 static void search_word_list_end(void *data, const char *el); 00192 static void search_word_list_text(void *data, const XML_Char *txt, int len); 00193 //------------------------------------------------------------------------------ 00194 // // while dict_eng_search_word_translation() is working 00195 static void search_word_trans_start(void *data, 00196 const char *el, 00197 const char **attr); 00198 static void search_word_trans_end(void *data, const char *el); 00199 static void search_word_trans_text(void *data, 00200 const XML_Char *txt, 00201 int len); 00202 //------------------------------------------------------------------------------ 00203 00204 00205 //______________________________________________________________________________ 00206 // ***************************************************************************** 00207 //************************************************ ADDITIONAL FUNCTIONS SECTION: 00208 //------------------------------------------------------------------------------ 00209 // returning concrete part of file 00210 static gchar* read_file_part(FilePart* part, GnomeVFSHandle* file); 00211 //------------------------------------------------------------------------------ 00212 //convert string to proper path name (no filename, no "/" at the ned, file exist) 00213 static gchar* string_to_path(gchar** string); 00214 //------------------------------------------------------------------------------ 00215 // tells if file is in XDXF format (file should exist) 00216 static gboolean is_bm_file(gchar* file); 00217 //------------------------------------------------------------------------------ 00218 // start/stop timers - returnet -1.0 if we start or seconds passed from start 00219 // if we want to stop timer 00220 static double timer(gboolean start, gchar* message); 00221 //------------------------------------------------------------------------------ 00222 // return size of files 00223 static guint64 get_file_size(GnomeVFSHandle* file); 00224 //------------------------------------------------------------------------------ 00225 // return how many records (from cache file) are in current buffer a with length 00226 // length. 00227 static guint get_max_length(gchar* a, guint length); 00228 //------------------------------------------------------------------------------ 00229 // return translation of word using cache file 00230 static gchar* word_translation_cache(XDXFData* data, gchar* word); 00231 //------------------------------------------------------------------------------ 00232 // return translation of word but using only xdxf dictionary file 00233 static gchar* word_translation_xdxf(XDXFData* data, gchar* word); 00234 //------------------------------------------------------------------------------ 00235 00236 // return translation of word using cache file 00237 static void word_list_cache(XDXFData* data, gchar* pattern, GArray* result); 00238 //------------------------------------------------------------------------------ 00239 // return translation of word but using only xdxf dictionary file 00240 static void word_list_xdxf(XDXFData* data, gchar* pattern, GArray* result); 00241 //------------------------------------------------------------------------------ 00242 00243 00244 00245 //______________________________________________________________________________ 00246 // ***************************************************************************** 00247 //****************************************************** MAIN FUNCTIONS SECTION: 00248 //------------------------------------------------------------------------------ 00249 // implementation of dict_eng_module_check(module,location) function 00250 gboolean bm_engine_check(gchar* location); 00251 //------------------------------------------------------------------------------ 00252 // implementation of dict_eng_module_get_description(module) function 00253 gchar* bm_engine_description(); 00254 //------------------------------------------------------------------------------ 00255 // implementation of dict_eng_module_get_format(module) function 00256 gchar* bm_engine_format(); 00257 //------------------------------------------------------------------------------ 00258 // implementation of dict_eng_module_get_version(module) function 00259 gchar* bm_engine_version(); 00260 //------------------------------------------------------------------------------ 00261 // implementation of dict_eng_module_create(module,location,flags) and 00262 // dict_eng_module_create_ext(module,location,flags) functions 00263 Engine* bm_engine_create(gchar* location, 00264 EngineOptimizationFlag flags, 00265 cb_progress progress_handler, 00266 gpointer progress_data, 00267 gdouble seed); 00268 //------------------------------------------------------------------------------ 00269 // implementation of dict_eng_destroy(engine) function 00270 void bm_engine_close(Engine* engine); 00271 //------------------------------------------------------------------------------ 00272 // implementation of dict_eng_get_location(engine) function 00273 gchar* bm_engine_location(Engine* engine); 00274 //------------------------------------------------------------------------------ 00275 // implementation of dict_eng_optimize(engine) function 00276 void bm_engine_optimize(Engine* engine); 00277 //------------------------------------------------------------------------------ 00278 // implementation of dict_eng_is_optimized( engine ) function 00279 gboolean bm_engine_is_optimized(Engine* engine); 00280 //------------------------------------------------------------------------------ 00281 // implementation of dict_eng_set_auto_free(engine, state) function 00282 void bm_engine_set_auto_free(Engine* engine, gboolean state); 00283 //------------------------------------------------------------------------------ 00284 // implementation of dict_eng_set_callback(engine,signal,c_handler,data) 00285 // function 00286 gpointer bm_engine_set_callbacks(Engine* engine, 00287 gchar* event, 00288 gpointer c_handler, 00289 gpointer user_data); 00290 //------------------------------------------------------------------------------ 00291 // implementation of dict_eng_set_progress_seed(engine, signal, val) function 00292 void bm_engine_set_progress_seed(Engine* engine, 00293 gchar* signal, 00294 gdouble seed); 00295 //------------------------------------------------------------------------------ 00296 // implementation ofdict_eng_search_word_list(engine,pattern) function 00297 void bm_engine_search_word_list(Engine* engine, gchar* pattern); 00298 //------------------------------------------------------------------------------ 00299 // implementation of dict_eng_search_word_translation(engine,word) function 00300 void bm_engine_search_word_translation(Engine* engine, gchar* word); 00301 //------------------------------------------------------------------------------ 00302 // implementation of dict_eng_search_word_translation_extended(engine,word) 00303 // function 00304 void bm_engine_search_word_translation_extended(Engine* engine, 00305 gchar* word); 00306 //------------------------------------------------------------------------------ 00307 // implementation of dict_eng_get_last_state(engine) function 00308 EngineStatus bm_engine_error(Engine* engine); 00309 //------------------------------------------------------------------------------ 00310 // implementation of dict_eng_state_message(error) function 00311 gchar* bm_engine_error_message(EngineStatus error); 00312 //------------------------------------------------------------------------------ 00313 // implementation of engine_global_functions(void) function 00314 // API 2.0 00315 gboolean bm_engine_add_word(Engine* engine, 00316 gchar* word, 00317 gchar* translation); 00318 00319 gboolean bm_engine_remove_word(Engine* engine, gchar* word); 00320 00321 EngineModule engine_global_functions(); 00322 00323 #ifdef __cplusplus 00324 } 00325 #endif 00326 #endif