src/plugins/xdxf/include/engine_xdxf.h

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 *******************************************************************************/
00036 #ifndef _DICTIONARY_ENGINE_XDXF
00037 #define _DICTIONARY_ENGINE_XDXF
00038 
00039 #ifdef __cplusplus
00040         extern "C" {
00041 #endif
00042 
00043 /* headers with unix types/functions - onl for timers */
00044 #include <sys/types.h>
00045 #include <sys/stat.h>
00046 #include <sys/time.h>
00047 #include <fcntl.h>
00048 #include <unistd.h>
00049 
00050 #include <glib.h> /* header with GLIB definitions/functions/types */
00051 #include <libgnomevfs/gnome-vfs.h> /* header with gnome-vfs - recommended I/O
00052                                     * API for maemo */
00053 #include <expat.h> /* header with expat - XML Parser API */
00054 #include <string.h> /* manipulating strings */
00055 #include <dictionary_engine.h> /* header wit engine API */
00056 
00057 
00061 #define TIMER_START     TRUE
00062 
00063 #define TIMER_STOP      FALSE
00064 
00072 /* in final releases timer capapilities should be removed for increase
00073  * performance */
00074 /* static double timer(gboolean start, gchar* message); */
00075 
00080 #define DIC_ENG_VERSION "0.1b"
00081 
00083 #define DIC_ENG_FORMAT  "XDXF"
00084 
00086 #define DICT_CACHEING_BUFF_SIZE                 16*1024
00087 
00089 #define DICT_SEARCHING_WORD_LIST_BUFF_SIZE      16*1024
00090 
00092 #define DICT_SEARCHING_WORD_TRAN_BUFF_SIZE      16*1024
00093 
00100 #define DICT_MAX_WORD_LENGTH   512
00101 
00103 #define PRINT_STATE(state) ( (state) ? "TRUE" : "FALSE" )
00104 
00105 
00108 struct _XDXFCheckingData {
00109         gboolean further;
00111         gboolean good;
00114         guint    deep;
00116 };
00117 typedef struct _XDXFCheckingData XDXFCheckingData;
00118 
00121 struct _XDXFWordsListData {
00122         gchar*   last_word;
00124         gchar*   pattern;
00126         guint    pattern_len;
00128         guint    last_word_length;
00130         GArray*  result;
00132         guint    one_word;
00135         gboolean cont;
00137 };
00138 typedef struct _XDXFWordsListData       XDXFWordsListData;
00139 
00142 struct _XDXFWordsTransData {
00143         gchar*          last_word;
00145         gchar*          word;
00147         guint           word_len;
00149         guint           last_word_length;
00151         gchar*          translation;
00153         guint           one_word;
00156         gboolean        cont;
00158         gulong          last_start;
00161         XML_Parser*     parser;
00163         gboolean        found;
00165         GnomeVFSHandle* xdxf;
00167 };
00168 typedef struct _XDXFWordsTransData      XDXFWordsTransData;
00169 
00172 struct _XDXFCacheData {
00173         gchar*          buffer;
00175         long            last_start;
00178         long            last_stop;
00180         long            last_length;
00182         GnomeVFSHandle* cache;
00184         XML_Parser      parser;
00186         int             state;
00189         long            buffer_length;
00191 };
00192 typedef struct _XDXFCacheData           XDXFCacheData;
00193 
00196 struct _FilePart {
00197         guint offset;
00199         guint length;
00201 };
00202 typedef struct _FilePart        FilePart;
00203 
00206 struct _XDXFData {
00207         GnomeVFSHandle*         xdxf;
00209         GnomeVFSHandle*         cache;
00211         gchar*                  dict_path;
00213         EngineStatus            last_error;
00215         gboolean                auto_free;
00218         cb_progress             cb_progress_caching;
00221         gpointer                cb_progress_caching_data;
00224         gdouble                 cb_progress_caching_seed;
00228         cb_progress             cb_progress_word_list;
00231         gpointer                cb_progress_word_list_data;
00234         gdouble                 cb_progress_word_list_seed;
00238         cb_progress             cb_progress_word_trans;
00241         gpointer                cb_progress_word_trans_data;
00244         gdouble                 cb_progress_word_trans_seed;
00248         cb_word_list            cb_search_word_list;
00251         gpointer                cb_search_word_list_data;
00255         cb_word_translation     cb_search_word_trans;
00258         gpointer                cb_search_word_trans_data;
00261 };
00262 typedef struct _XDXFData        XDXFData;
00263 
00264 
00267 
00272 static void     is_xdxf_file_start(void *data,
00273                                    const char *el,
00274                                    const char **attr);
00275 
00280 static void     is_xdxf_file_end(void *data,  const char *el);
00281 
00286 static void     search_word_list_start(void *data,
00287                                        const char *el,
00288                                        const char **attr);
00293 static void     search_word_list_end(void *data, const char *el);
00294 
00299 static void     search_word_list_text(void *data, const XML_Char *txt, int len);
00300 
00305 static void     search_word_trans_start(void *data,
00306                                         const char *el,
00307                                         const char **attr);
00308 
00313 static void     search_word_trans_end(void *data, const char *el);
00314 
00319 static void     search_word_trans_text(void *data,
00320                                        const XML_Char *txt,
00321                                        int len);
00326 static gchar* read_file_part(FilePart* part, GnomeVFSHandle* file);
00327 
00329 static gchar*           string_to_path(gchar** string);
00330 
00332 static gboolean         is_xdxf_file(gchar* file);
00333 
00335 static guint64          get_file_size(GnomeVFSHandle* file);
00336 
00339 static guint            get_max_length(gchar* a, guint length);
00340 
00342 static gchar* word_translation_cache(XDXFData* data, gchar* word);
00343 
00345 static gchar* word_translation_xdxf(XDXFData* data, gchar* word);
00346 
00348 static void word_list_cache(XDXFData* data,
00349                             gchar* pattern,
00350                             GArray* result,
00351                             gpointer cb_data);
00352 
00354 static void word_list_xdxf(XDXFData* data,
00355                            gchar* pattern,
00356                            GArray* result,
00357                            gpointer cb_data);
00358 
00361 
00363 gboolean        xdxf_engine_check(gchar* location);
00364 
00366 gchar*          xdxf_engine_description();
00367 
00369 gchar*          xdxf_engine_format();
00370 
00372 gchar*          xdxf_engine_version();
00373 
00375 Engine*         xdxf_engine_create( gchar* location, 
00376                                     EngineOptimizationFlag flags,
00377                                     cb_progress progress_handler,
00378                                     gpointer progress_data,
00379                                     gdouble seed );
00385 
00387 void            xdxf_engine_close(Engine* engine);
00388 
00390 gchar*          xdxf_engine_location(Engine* engine);
00391 
00393 void            xdxf_engine_optimize(Engine* engine);
00394 
00396 gboolean        xdxf_engine_is_optimized(Engine* engine);
00397 
00399 void            xdxf_engine_set_auto_free(Engine* engine, gboolean state);
00400 
00402 gpointer        xdxf_engine_set_callbacks(Engine* engine,
00403                                      gchar* event,
00404                                      gpointer c_handler,
00405                                      gpointer user_data);
00406 
00408 void            xdxf_engine_set_progress_seed(Engine* engine,
00409                                          gchar* signal,
00410                                          gdouble seed);
00411 
00413 void            xdxf_engine_search_word_list(Engine* engine,
00414                                              gchar* pattern,
00415                                              gpointer data);
00416 
00418 void            xdxf_engine_search_word_translation(Engine* engine,
00419                                                     gchar* word,
00420                                                     gpointer data);
00421 
00422 /*** \brief dict_eng_search_word_translation_extended() function implementation.
00423  */
00424 /* this function was removed from engine API */
00425 /*void            xdxf_engine_search_word_translation_extended(Engine* engine,
00426                                                         gchar* word);
00427 */
00428 
00430 EngineStatus    xdxf_engine_error(Engine* engine);
00431 
00433 gchar*          xdxf_engine_error_message(EngineStatus error);
00434 
00436 gboolean        xdxf_engine_add_word(Engine* engine,
00437                                      gchar*  word,
00438                                      gchar*  translation);
00439 
00441 gboolean        xdxf_engine_remove_word(Engine* engine, gchar*  word);
00445 EngineModule    engine_global_functions();
00446 
00447 #ifdef __cplusplus
00448 }
00449 #endif
00450 #endif
00451 

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