-/**********************************************************************************
- * copyright (C) 2006, Dariusz Wiechecki
- * dariusz.wiechecki@gmail.com
- * 14 August 2006, Lodz, Poland
- **********************************************************************************
- * This file is part of str-vfs-test.
- *
- * str-vfs-test is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * str-vfs-test is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with str-vfs-test; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *********************************************************************************/
-#ifndef _DICTIONARY_ENGINE_BASE
-#define _DICTIONARY_ENGINE_BASE
-
-#ifdef __cplusplus
-extern "C" { // to make it possible to use this header in C++ programms
+/*******************************************************************************
+This file is part of WhiteStork.
+
+WhiteStork is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+WhiteStork is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with WhiteStork; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+Copyright 2006 ComArch S.A.
+*******************************************************************************/
+#ifndef _DICTIONARY_ENGINE_BASE
+#define _DICTIONARY_ENGINE_BASE
+
+#ifdef __cplusplus
+ extern "C" {
#endif
-//______________________________________________________________________________________________________
-// ******************************************************************************************************
-//********************************************************************************************* HEADERS:
+
+//______________________________________________________________________________
+// *****************************************************************************
+//************************************************************* HEADERS SECTION:
+//------------------------------------------------------------------------------
+// header with gnu library for C - most of types and functions needed it (all
+// started from g* and g_*().
#include <glib.h>
+//------------------------------------------------------------------------------
-//______________________________________________________________________________________________________
-// ******************************************************************************************************
-//************************************************************************************ GLOBAL MACROS:
+//______________________________________________________________________________
+// *****************************************************************************
+//******************************************************* GLOBAL MACROS SECTION:
+//------------------------------------------------------------------------------
/** \brief Checks if module is peaceable with concrete location.
-*
-* If user of engine module want to know if concrete module can handle concrete location, he can call <i>dict_eng_module_check()</i>
-*and check the result of this function.
+ *
+ * If user of engine module want to know if concrete module can handle concrete
+ * location, he can call <i>dict_eng_module_check()</i>and check the result
+ * of this function.
+ *
* @param module :: <b>EngineModule</b> - module engine which will be testing
* @param location :: <b>gchar*</b> - location on wich engine will be testing
- * @return <i><b>gboolean</b></i> :: tells if location <i>location</i> can be handled by module <i>module</i>
+ * @return <i><b>gboolean</b></i> :: tells if location <i>location</i> can be
+ * handled by module <i>module</i>
*/
-#define dict_eng_module_check(module,location) ( (module).engine_check( (location) ) )
-
-
+#define dict_eng_module_check(module,location) \
+ ( (module).engine_check( (location) ) )
+//------------------------------------------------------------------------------
/** \brief Get short description of engine module.
*
- * If there is need to present to the user of end programm some information about enigne he is using, we can call dict_eng_module_get_description() and
+ * If there is need to present to the user of end programm some information
+ * about enigne he is using, we can call dict_eng_module_get_description() and
* print/show the result of this call.
- * @param module :: <b>EngineModule</b> - module engine which description we want
- * @return <i><b>gchar*</b></i> :: there is string, decribing module engine <i>module</i>, in this pointer. User should NOT free this pointer as it points to static table of chars
+ *
+ * @param module :: <b>EngineModule</b>- module engine which description we want
+ * @return <i><b>gchar*</b></i> :: there is string, decribing module engine
+ * <i>module</i>, in this pointer. User should NOT free this pointer as it
+ * points to static table of chars
*/
-#define dict_eng_module_get_description(module) ( (module).engine_description() )
-
-
+#define dict_eng_module_get_description(module) \
+ ( (module).engine_description() )
+//------------------------------------------------------------------------------
/** \brief Get version of engine module.
*
- * Sometimes it could be useful to get know what version of engine module we are using. We can call this function to retrieve these informations from module.
- * Note that version information could be also placed in description of module, but here user will get only string representing version, what could be needed in some situation
- * (e.g.: if end-user will have two the same module, then programm has to decide which should be used, or ask user).
- * @param module :: <b>EngineModule</b> - module engine which implementation version we want
- * @return <i><b>gchar*</b></i> :: pointer to string representing module <i>module</i>version. User should NOT free this pointer as it points to static table of chars
+ * Sometimes it could be useful to get know what version of engine module we are
+ * using. We can call this function to retrieve these informations from module.
+ * Note that version information could be also placed in description of module,
+ * but here user will get only string representing version, what could be needed
+ * in some situation (e.g.: if end-user will have two the same module, then
+ * programm has to decide which should be used, or ask user).
+ *
+ * @param module :: <b>EngineModule</b> - module engine which implementation
+ * version we want
+ * @return <i><b>gchar*</b></i> :: pointer to string representing module
+ * <i>module</i>version. User should NOT free this pointer as it points to
+ * static table of chars
*/
-#define dict_eng_module_get_version(module) ( (module).engine_version() )
-
-
+#define dict_eng_module_get_version(module) \
+ ( (module).engine_version() )
+//------------------------------------------------------------------------------
/** \brief Get format on which working engnine module.
*
- * If we want to know on what dictionary format works current engine module, we can call this function. As a result we will retrieve string telling us what format-based is
- * concrete engine module (e.g. XDXF, WordNet etc.).
- * @param module :: <b>EngineModule</b> - engine module which dictionary format we want to get
- * @return <i><b>gchar*</b></i> :: string representing format of dictionary on which module <i>module</i> can works. User should NOT free this pointer as it points
- * to static table of chars
+ * If we want to know on what dictionary format works current engine module, we
+ * can call this function. As a result we will retrieve string telling us what
+ * format-based is concrete engine module (e.g. XDXF, WordNet etc.).
+ *
+ * @param module :: <b>EngineModule</b> - engine module which dictionary format
+ * we want to get
+ * @return <i><b>gchar*</b></i> :: string representing format of dictionary on
+ * which module <i>module</i> can works. User should NOT free this pointer as
+ * it points to static table of chars
*/
-#define dict_eng_module_get_format(module) ( (module).engine_version() )
-
-
+#define dict_eng_module_get_format(module) \
+ ( (module).engine_version() )
+//------------------------------------------------------------------------------
/** \brief Open concrete dictionary.
-*
-* This functions opens location (this could mean: filename, URL, any other way to specify concrete localization of dictionary database). To be more sure that this function will be sucefull,
-* user can call before dict_eng_module_check() to check if this module can handle dictionary under passed location. But this do not warrant that calling dict_eng_module_create() will not
-* fail. User should check the result of function to be sure that everything was ok.
- * @param module :: <b>EngineModule</b> - engine module which should be used to open location <i>location</i>
- * @param location :: <b>gchar*</b> - location of dictionary database (file, directory, URL etc.)
- * @param flags :: <b>EngineOptimizationFlag</b> - flags defines how program shoud automaticlly use optimization methods for opened dictionary
- * @return <i><b>Engine*</b></i> :: pointer to new enigne structure; After use, if this structure will not be needed anymore, user should call dict_eng_destroy() to free memory
- * \sa EngineOptimizationFlag :|: dict_eng_module_check() :|: EngineModule :|: Engine
+ *
+ * This functions opens location (this could mean: filename, URL, any other way
+ * to specify concrete localization of dictionary database). To be more sure
+ * that this function will be sucefull, user can call before
+ * dict_eng_module_check() to check if this module can handle dictionary under
+ * passed location. But this do not warrant that calling
+ * dict_eng_module_create() will not fail. User should check the result of
+ * function to be sure that everything was ok.
+ *
+ * @param module :: <b>EngineModule</b> - engine module which should be used to
+ * open location <i>location</i>
+ * @param location :: <b>gchar*</b> - location of dictionary database (file,
+ * directory, URL etc.)
+ * @param flags :: <b>EngineOptimizationFlag</b> - flags defines how program
+ * shoud automaticlly use optimization methods for opened dictionary
+ * @return <i><b>Engine*</b></i> :: pointer to new enigne structure; After use,
+ * if this structure will not be needed anymore, user should call
+ * dict_eng_destroy() to free memory
+ * \sa EngineOptimizationFlag :|: dict_eng_module_check() :|: EngineModule :|:
+ * Engine
*/
-#define dict_eng_module_create(module,location,flags) ( (module).engine_create( (location), (flags), NULL, NULL, 0.01 ) )
-
-
-#define dict_eng_module_create_ext(module,location,flags,progress_handler,progress_data,seed) ( (module).engine_create( (location), (flags), (progress_handler), (progress_data), (seed) ) )
-
-
-
-//______________________________________________________________________________________________________
-// ******************************************************************************************************
-//********************************************************************** CONCRETE DICTIONARY MACROS:
-
-#define dict_eng_set_progress_seed(engine, signal, val) ( (engine)->engine_set_progress_seed((engine), (signal), (val) ) )
-
-#define dict_eng_set_auto_free(engine, state) ( (engine)->engine_set_auto_free( (engine), (state) )
-
-
+#define dict_eng_module_create(module,location,flags) \
+ ( (module).engine_create( (location), (flags), NULL, NULL, 0.01 ) )
+//------------------------------------------------------------------------------
+/** \brief Open concrete dictionary - define handler for signal of progress
+ *
+ * This functions is similiar to dict_eng_module_create(module,location,flags).
+ * In addition to it, this function get additional parameters, defining how
+ * engine should "inform" the user about progress of eventuall caching proccess.
+ *
+ * @param module :: <b>EngineModule</b> - engine module which should be used to
+ * open location <i>location</i>
+ * @param location :: <b>gchar*</b> - location of dictionary database (file,
+ * directory, URL etc.)
+ * @param flags :: <b>EngineOptimizationFlag</b> - flags defines how program
+ * shoud automaticlly use optimization methods for opened dictionary
+ * @param progress_handler :: <b>cb_progress</b> - handler which will be called
+ * from time to time, to give to the user any response about caching progress
+ * @param progress_data :: <b>gpointer</b> - pointer to data which will be given
+ * as a user_data argument for progress_data function during its calling
+ * @param seed :: <b>gdouble</b> - defines after how big step (in percentage)
+ * in progress of caching, engine send new signal - call progress_handler with
+ * actual value of progress
+ * @return <i><b>Engine*</b></i> :: pointer to new enigne structure; After use,
+ * if this structure will not be needed anymore, user should call
+ * dict_eng_destroy() to free memory
+ * \sa EngineOptimizationFlag :|: dict_eng_module_check() :|: EngineModule :|:
+ * Engine :|: cb_progress
+ */
+#define dict_eng_module_create_ext(module, \
+ location, \
+ flags, \
+ progress_handler, \
+ progress_data, \
+ seed \
+ ) ( \
+ (module).engine_create( (location), \
+ (flags), \
+ (progress_handler), \
+ (progress_data), \
+ (seed) \
+ ))
+//------------------------------------------------------------------------------
+
+
+//______________________________________________________________________________
+// *****************************************************************************
+//****************************************** CONCRETE DICTIONARY MACROS SECTION:
+//------------------------------------------------------------------------------
+#define dict_eng_set_progress_seed(engine, signal, val) ( \
+ (engine) -> engine_set_progress_seed( (engine), \
+ (signal), \
+ (val) \
+ ))
+//------------------------------------------------------------------------------
+
+#define dict_eng_set_auto_free(engine, state) ( \
+ (engine) -> engine_set_auto_free( (engine), (state) )
+//------------------------------------------------------------------------------
/** \brief Activate optimization mechanizms for concrete engine.
*
- * Every engine could have some optimization methods. By calling this function we enabled this option. For the user of engine it is not important what kind
- * of optimization is used in current engine, how does it work etc. It should be opaque for engine's users.
+ * Every engine could have some optimization methods. By calling this function
+ * we enabled this option. For the user of engine it is not important what kind
+ * of optimization is used in current engine, how does it work etc. It should
+ * be opaque for engine's users.
*
* @param engine :: <b>Engine*</b> - pointer to engine which should optimized
- * @return <i><b>void</b></i> :: nothing. This function only take a chance to make engine working faster, but it is not said that every step will be succesful.
- * But even if not - engine has to work properly.
+ * @return <i><b>void</b></i> :: nothing. This function only take a chance to
+ * make engine working faster, but it is not said that every step
+ * will be succesful. But even if not - engine has to work properly.
* \sa dict_eng_module_create() :|: dict_eng_is_optimized() :|: Engine
*/
-#define dict_eng_optimize(engine) ( ( engine )->engine_optimize( (engine) ) )
-
-
+#define dict_eng_optimize(engine) \
+ ((engine) -> engine_optimize( (engine) ))
+//------------------------------------------------------------------------------
/** \brief Checks if current engine has activated optimization.
*
- * User can call this function to get know if concrete engine has enabled optimization. Optimization can be activated by calling dict_eng_optimize() or passing
- * ENGINE_CREATE or ENGINE_REFRESH flags to dict_eng_module_create() while opening concrete dictionary.
+ * User can call this function to get know if concrete engine has enabled
+ * optimization. Optimization can be activated by calling dict_eng_optimize()
+ * or passing ENGINE_CREATE or ENGINE_REFRESH flags to dict_eng_module_create()
+ * while opening concrete dictionary.
*
- * @param engine :: <b>Engine*</b> - pointer to engine which should checked if is optimized now
- * @return <i><b>gboolean</b></i> :: nothing. This function only take a chance to make engine working faster, but it is not said that every step will be succesful
+ * @param engine :: <b>Engine*</b> - pointer to engine which should be checked
+ * if is optimized now
+ * @return <i><b>gboolean</b></i> :: nothing. This function only take a chance
+ * to make engine working faster, but it is not said that every step
+ * will be succesful
* \sa dict_eng_optimize() :|: Engine :|: EngineOptimizationFlag
*/
-#define dict_eng_is_optimized( engine ) ( ( engine )->engine_is_optimized( (engine) ) )
-
-
+#define dict_eng_is_optimized( engine ) \
+ ((engine) -> engine_is_optimized( (engine) ))
+//------------------------------------------------------------------------------
/** \brief To get know from what location was created current dictionary.
*
- * If user of engine want to get know from what locatione exactly was created concrete engine, he could call this function. It returns string,
- * most likely the same as the one passed earlier to dict_eng_module_create() function as a <i>location</i> argument.
+ * If user of engine want to get know from what locatione exactly was created
+ * concrete engine, he could call this function. It returns string, most likely
+ * the same as the one passed earlier to dict_eng_module_create() function
+ * as a <i>location</i> argument.
*
- * @param engine :: <b>Engine*</b> - dictionary from which we want to get location
- * @return <i><b>gchar*</b></i> :: pointer to chars, from which concrete dictionary was created
+ * @param engine :: <b>Engine*</b> - dictionary from which we want to get
+ * location
+ * @return <i><b>gchar*</b></i> :: pointer to chars, from which concrete
+ * dictionary was created
* \sa dict_eng_module_create()
*/
-#define dict_eng_get_location(engine) ( (engine)->engine_location( (engine) ) )
-
-
+#define dict_eng_get_location(engine) \
+ ((engine) -> engine_location( (engine) ))
+//------------------------------------------------------------------------------
/** \brief Tells if last operation was sucesfull.
*
- * If user want to be sure that everything was ok, during last operation (it has finished with success), he has to check if dict_eng_get_last_state() is equal to
- * ENGINE_NO_ERROR. If not, he can also find the reason why operation failed.
- * @param engine :: <b>Engine*</b> - dictionary which last operation's returned code we want to get
+ * If user want to be sure that everything was ok, during last operation
+ * (it has finished with success), he has to check if dict_eng_get_last_status()
+ * is equal to ENGINE_NO_ERROR. If not, he can also find the reason
+ * why operation failed.
+ * @param engine :: <b>Engine*</b> - dictionary which last operation's returned
+ * code we want to get
* @return <i><b>EngineStatus</b></i> :: finish code of last operation
* \sa EngineStatus :|: dict_eng_state_message()
*/
-#define dict_eng_get_last_state(engine) ( (engine)->engine_error( (engine) ) )
-
-
+#define dict_eng_get_last_status(engine) \
+ ((engine) -> engine_error( (engine) ))
+//------------------------------------------------------------------------------
/** \brief Translate pure state code to meaningfull message.
*
- * If there was a error during engine was working, we can present to the user the reason for this error in meaningfull form.
+ * If there was a error during engine was working, we can present to the user
+ * the reason for this error in meaningfull form.
+ *
* @param error :: <b>EngineState</b> - code which we want to translate
* @return <i><b>gchar*</b></i> :: message describing concrete error code
* \sa EngineStatus :|: dict_eng_state_message()
*/
-#define dict_eng_state_message(error) ( (engine)->engine_error_message( error ) )
-
-
+#define dict_eng_state_message(error) \
+ ((engine) -> engine_error_message( (error) ))
+//------------------------------------------------------------------------------
/** \brief Destroy gently and completly current dictionary.
*
- * When user do not need anymore concrete dictionary, he must destroy it to free memory allocated by this dictionary. It will close avery opened file descriptor,
- * free any additional memory block allocated while engine was working etc. User are not allowed to call free() on dictionary without calling before dict_eng_destroy().
+ * When user do not need anymore concrete dictionary, he must destroy it to
+ * free memory allocated by this dictionary. It will close avery opened file
+ * descriptor, free any additional memory block allocated while engine was
+ * working etc. User are not allowed to call free() on dictionary without
+ * calling before dict_eng_destroy().
*
- * @param engine :: <b>Engine*</b> - pointer to dictionary which is not needed anymore
- * @return <i><b>void</b></i> :: nothing. This function should work properly, and free any resources which arelady are in use by current dictionary.
+ * @param engine :: <b>Engine*</b> - pointer to dictionary which is not
+ * needed anymore
+ * @return <i><b>void</b></i> :: nothing. This function should work properly,
+ * and free any resources which arelady are in use by current dictionary.
* \sa dict_eng_module_create() :|: Engine
*/
-#define dict_eng_destroy(engine) ( (engine)->engine_close( (engine)) )
-
-
+#define dict_eng_destroy(engine) \
+ ((engine) -> engine_close( (engine) ))
+//------------------------------------------------------------------------------
/** \brief Start searching for words list.
*
- * This function starts searching for words list. User should set before callback for ENGINE_WORD_LIST_SIGNAL, to be able to retrieve words list, because this
- * function do not return any value.
+ * This function starts searching for words list. User should set before
+ * callback for ENGINE_WORD_LIST_SIGNAL, to be able to retrieve words list,
+ * because this function do not return any value.
*
- * @param engine :: <b>Engine*</b> - pointer to dictionary in which we are looking for words matching to pattern
- * @param pattern :: <b>gchar*</b> - string representing pattern to which returned word should be matching
- * @return <i><b>void</b></i> :: nothing. Result of searching can be retrieved by callback for signal ENGINE_WORD_LIST_SIGNAL
- * \sa dict_eng_search_word_translation() :|: dict_eng_search_word_translation_extended() :|: dict_eng_set_callback() :|: ENGINE_WORD_LIST_SIGNAL
+ * @param engine :: <b>Engine*</b> - pointer to dictionary in which we
+ * are looking for words matching to pattern
+ * @param pattern :: <b>gchar*</b> - string representing pattern to which
+ * returned word should be matching
+ * @return <i><b>void</b></i> :: nothing. Result of searching can be retrieved
+ * by callback for signal ENGINE_WORD_LIST_SIGNAL
+ * \sa dict_eng_search_word_translation() :|:
+ * dict_eng_search_word_translation_extended() :|: dict_eng_set_callback() :|:
+ * ENGINE_WORD_LIST_SIGNAL
*/
-#define dict_eng_search_word_list(engine,pattern) ( (engine)->engine_search_word_list((engine), (pattern)) )
-
-
+#define dict_eng_search_word_list(engine,pattern) \
+ ((engine) -> engine_search_word_list( (engine), \
+ (pattern) \
+ ))
+//------------------------------------------------------------------------------
/** \brief Start searching for word translation in dictionary.
*
- * Start searching for translation of word. To be able to retrieve translation user should use callback for ENGINE_WORD_TRANSLATION_SIGNAL signal.
+ * Start searching for translation of word. To be able to retrieve translation
+ * user should use callback for ENGINE_WORD_TRANSLATION_SIGNAL signal.
*
- * @param engine :: <b>Engine*</b> - dictionary in which we want find word's translation
- * @param word :: <b>gchar*</b> - string representing word which translation we are looking for
- * @return <i><b>void</b></i> :: nothing. Result of searching can be retrieved by callback for signal ENGINE_WORD_TRANSLATION_SIGNAL
- * \sa dict_eng_search_word_list() :|: dict_eng_search_word_translation_extended() :|: dict_eng_set_callback() :|: ENGINE_WORD_TRANSLATION_SIGNAL
+ * @param engine :: <b>Engine*</b> - dictionary in which we want find word's
+ * translation
+ * @param word :: <b>gchar*</b> - string representing word which translation
+ * we are looking for
+ * @return <i><b>void</b></i> :: nothing. Result of searching can be retrieved
+ * by callback for signal ENGINE_WORD_TRANSLATION_SIGNAL
+ * \sa dict_eng_search_word_list() :|:
+ * dict_eng_search_word_translation_extended() :|: dict_eng_set_callback() :|:
+ * ENGINE_WORD_TRANSLATION_SIGNAL
*/
-#define dict_eng_search_word_translation(engine,word) ( (engine)->engine_search_word_translation((engine), (word)) )
-
-
+#define dict_eng_search_word_translation(engine,word) \
+ ((engine) -> engine_search_word_translation( (engine), \
+ (word) \
+ ))
+//------------------------------------------------------------------------------
/** \brief Start searching for extended word translation in dictionary.
*
- * Start searching for extended translation of word. To be able to retrieve translation user should use callback for ENGINE_WORD_TRANSLATION_SIGNAL signal. Extended means
- * that retrieved translation's string could be some more than plain text (e.g. HTML, Image, etc.). User of engine should know what kind of data will retrieve ofter calling this method.
- * \todo This option are in projecting phase. In the future callback for ENGINE_WORD_TRANSLATION_SIGNAL should take parameter <i>gpointer</i> than <i>gchar*</i> to make possible
- * for user of engine to retrieve data different than gchar*. There shold be also some additional function letting know user what kind of data he will retrieve.
+ * Start searching for extended translation of word. To be able to retrieve
+ * translation user should use callback for ENGINE_WORD_TRANSLATION_SIGNAL
+ * signal. Extended means that retrieved translation's string could be some more
+ * than plain text (e.g. HTML, Image, etc.). User of engine should know what
+ * kind of data will retrieve ofter calling this method.
+ *
+ * \todo This option are in projecting phase. In the future callback for
+ * ENGINE_WORD_TRANSLATION_SIGNAL should take parameter <i>gpointer</i> than
+ * <i>gchar*</i> to make possible for user of engine to retrieve data different
+ * than gchar*. There shold be also some additional function letting know user
+ * what kind of data he will retrieve.
*
- * @param engine :: <b>Engine*</b> - dictionary in which we want find word's translation
- * @param word :: <b>gchar*</b> - string representing word which translation we are looking for
- * @return <i><b>void</b></i> :: nothing. Result of searching can be retrieved by callback for signal ENGINE_WORD_TRANSLATION_SIGNAL
- * \sa dict_eng_search_word_list() :|: dict_eng_search_word_translation() :|: dict_eng_set_callback() :|: ENGINE_WORD_TRANSLATION_SIGNAL
+ * @param engine :: <b>Engine*</b> - dictionary in which we want find word's
+ * translation
+ * @param word :: <b>gchar*</b> - string representing word which translation
+ * we are looking for
+ * @return <i><b>void</b></i> :: nothing. Result of searching can be retrieved
+ * by callback for signal ENGINE_WORD_TRANSLATION_SIGNAL
+ * \sa dict_eng_search_word_list() :|: dict_eng_search_word_translation() :|:
+ * dict_eng_set_callback() :|: ENGINE_WORD_TRANSLATION_SIGNAL
*/
-#define dict_eng_search_word_translation_extended(engine,word) ( (engine)->engine_search_word_translation_extended((engine), (pattern)) )
-
-
+#define dict_eng_search_word_translation_extended(engine,word) \
+ ((engine) -> engine_search_word_translation_extended((engine), \
+ (pattern) \
+ ))
+//------------------------------------------------------------------------------
/** \brief Setting any callback for current dictionary.
*
- * As long as functions which search for words list or translation do not return any value, user has to set callback which will be called after searching end. This make easy
- * calling these functions from other proccess, threads etc. This function sets callbacks for every signal.
+ * As long as functions which search for words list or translation do not
+ * return any value, user has to set callback which will be called after
+ * searching end. This make easy calling these functions from other proccess,
+ * threads etc. This function sets callbacks for every signal.
*
- * @param engine :: <b>Engine*</b> - dictionary for which we want set some callback
- * @param signal :: <b>gchar*</b> - string representing for what signal we want to set callback
- * @param c_handler :: <b>gpointer</b> - pointer to function which will be called after signal <i>signal</i> will occured
- * @param data :: <b>gpointer</b> - pointer to user data, which will be always passed to callback <i>c_handler</i> for signal <i>signal</i>as a last argument
- * @return <i><b>gpointer</b></i> :: pointer to previous callback; if this callbacks was not set yet, it returns NULL
- * \sa cb_word_list :|: cb_word_translation :|: ENGINE_WORD_LIST_SIGNAL :|: ENGINE_WORD_TRANSLATION_SIGNAL
- */
-#define dict_eng_set_callback(engine,signal,c_handler,data) ( (engine)->engine_set_callback((engine),(signal),(c_handler),(data)) )
-
-//______________________________________________________________________________________________________
-// ******************************************************************************************************
-//******************************************************************* SIGNALS DEFINITION FOR CALLBACKS:
-/** \brief Signal description's definition for callback called when word list was found.
- *
- * ENGINE_WORD_LIST_SIGNAL defines name for signal passed to dict_eng_set_callback() function as a
- * signal parameter. Function set to handle this signal should be called from dict_eng_search_word_list() only
+ * @param engine :: <b>Engine*</b> - dictionary for which we want set some
+ * callback
+ * @param signal :: <b>gchar*</b> - string representing for what signal we want
+ * to set callback
+ * @param c_handler :: <b>gpointer</b> - pointer to function which will be
+ * called after signal <i>signal</i> will occured
+ * @param data :: <b>gpointer</b> - pointer to user data, which will be always
+ * passed to callback <i>c_handler</i> for signal <i>signal</i>
+ * as a last argument
+ * @return <i><b>gpointer</b></i> :: pointer to previous callback; if this
+ * callbacks was not set yet, it returns NULL
+ * \sa cb_word_list :|: cb_word_translation :|: ENGINE_WORD_LIST_SIGNAL :|:
+ * ENGINE_WORD_TRANSLATION_SIGNAL
+ */
+#define dict_eng_set_callback(engine,signal,c_handler,data) \
+ ((engine) -> engine_set_callback( (engine), \
+ (signal), \
+ (c_handler), \
+ (data) \
+ ))
+//------------------------------------------------------------------------------
+
+
+//______________________________________________________________________________
+// *****************************************************************************
+//************************************ SIGNALS DEFINITION FOR CALLBACKS SECTION:
+//------------------------------------------------------------------------------
+/** \brief Signal definition for callback called when word list was found.
+ *
+ * ENGINE_WORD_LIST_SIGNAL defines name for signal passed to
+ * dict_eng_set_callback() function as a signal parameter. Function set
+ * to handle this signal should be called from dict_eng_search_word_list() only
* and have cb_word_list type.
- * <b>NOTE:</b> programmers must not use value of ENGINE_WORD_LIST_SIGNAL directly!
- * \sa cb_word_list :|: dict_eng_set_callback() :|: dict_eng_search_word_list() :|: ENGINE_WORD_TRANSLATION_SIGNAL
+ * <b>NOTE:</b> programmers must not use value of ENGINE_WORD_LIST_SIGNAL
+ * directly!
+ * \sa cb_word_list :|: dict_eng_set_callback() :|: dict_eng_search_word_list()
+ * :|: ENGINE_WORD_TRANSLATION_SIGNAL
*/
-#define ENGINE_WORD_LIST_SIGNAL "on_word_list_found"
-
-
-/** \brief Signal description's definition for callback called when word translation was found.
+#define ENGINE_WORD_LIST_SIGNAL "on_word_list_found"
+//------------------------------------------------------------------------------
+/** \brief Signal definition for callback called when word trans. was found.
*
- * ENGINE_WORD_TRANSLATION_SIGNAL defines name for signal passed to dict_eng_set_callback() function as a
- * signal parameter. Function set to handle this signal should be called from dict_eng_search_word_translation() and dict_eng_search_word_translation_extended() only
- * and have cb_word_translation.
- * <b>NOTE:</b> programmers must not use value of ENGINE_WORD_LIST_SIGNAL directly!
- * \sa cb_word_translation :|: dict_eng_set_callback() :|: dict_eng_search_word_translation() :|: ENGINE_WORD_LIST_SIGNAL
+ * ENGINE_WORD_TRANSLATION_SIGNAL defines name for signal passed to
+ * dict_eng_set_callback() function as a signal parameter. Function set
+ * to handle this signal should be called from
+ * dict_eng_search_word_translation() and
+ * dict_eng_search_word_translation_extended() only and have cb_word_translation.
+ * <b>NOTE:</b> programmers must not use value of ENGINE_WORD_LIST_SIGNAL
+ * directly!
+ * \sa cb_word_translation :|: dict_eng_set_callback() :|:
+ * dict_eng_search_word_translation() :|: ENGINE_WORD_LIST_SIGNAL
*/
-#define ENGINE_WORD_TRANSLATION_SIGNAL "on_word_translation_found"
+#define ENGINE_WORD_TRANSLATION_SIGNAL "on_word_translation_found"
+//------------------------------------------------------------------------------
+#define ENGINE_PROGRESS_OPTIMIZING_SIGNAL "on_progress_optimizing"
+//------------------------------------------------------------------------------
-#define ENGINE_PROGRESS_CACHING "on_progress_caching"
-//______________________________________________________________________________________________________
-// ******************************************************************************************************
-//************************************************************************** DEFINITIONS OF ENUMS TYPES:
-/** \brief Codes of flags used to auto optimizing dictionary file (passes to dict_eng_module_create() function as a parameter flags).
+//______________________________________________________________________________
+// *****************************************************************************
+//************************************************** DEFINITIONS OF ENUMS TYPES:
+//------------------------------------------------------------------------------
+/** \brief Codes of flags used to auto optimizing dictionary file.
*
- * - Enum type for flags used as a flags parameter for dict_eng_module_create() function.
+ * - Enum type for flags used as a flags parameter for dict_eng_module_create()
+ * function.
*/
typedef enum
{
- ENGINE_CREATE = 0, ///< :: flags says thatoptimization (any methods of optimalization) should be enabled. If optimization methods needs to make some files and these files exists, enigne will just use it (do not refresh).
- ENGINE_NO, ///< :: flags says that for this particular dictionary programm should disabled optimization.
- ENGINE_REFRESH ///< :: the same flags as ENGINE_CREATE, but tells dict_eng_module_create() function that even if file (or any resources) for optimizatione methods exists, they should be recreated/refreshed.
-}
-EngineOptimizationFlag;
-
+ /**
+ * :: flags says thatoptimization (any methodsof optimalization) should
+ * be enabled. If optimization methods needs to make some files and
+ * these files exists, enigne will just use it (do not refresh).
+ */
+ ENGINE_CREATE = 0,
+ /**
+ * :: flags says that for this particular dictionary programm should
+ * disable optimization.
+ */
+ ENGINE_NO,
+ /**
+ * :: the same flags as ENGINE_CREATE, but tells
+ * dict_eng_module_create() function that even if file (or any
+ * resources) for optimizatione methods exists, they should be
+ * recreated/refreshed.
+ */
+ ENGINE_REFRESH
+} EngineOptimizationFlag;
+//------------------------------------------------------------------------------
/** \brief Codes of possible errors which can occured while engine is working.
-*
-* - Enum type for errors' codes. One of this code is always in last error variable (variable 'last error' is invisible for programmers -
-* they should use function engine_error() and optionally engine_error_message() to get know what kind of error occured).
-*/
+ *
+ * - Enum type for errors' codes. One of this code is always in last error
+ * variable (variable 'last error' is invisible for programmers - they should
+ * use function engine_error() and optionally engine_error_message() to get know
+ * what kind of error occured).
+ */
typedef enum
{
- ENGINE_NO_ERROR = 0, ///< :: there was no error - last action successed
- ENGINE_WRONG_FILE, ///< :: file, which engine tried to read, has wrong format or it is corrupted.
- ENGINE_COULDNT_READ, ///< :: user do not have permission to read/open file, which engine tried to open/read.
- ENGINE_NO_FILE, ///< :: file, on which engine tried to operate, do not exist
- ENGINE_OUT_OF_MEMORY ///< :: while engine was working, "Out Of Memory" error occured
+ /**
+ * :: there was no error - last action successed
+ */
+ ENGINE_NO_ERROR = 0,
+ /**
+ * :: file, which engine tried to read, has wrong format or
+ * it is corrupted.
+ */
+ ENGINE_WRONG_FILE,
+ /**
+ * :: user do not have permission to read/open file, which engine tried
+ * to open/read.
+ */
+ ENGINE_COULDNT_READ,
+ /**
+ * :: file, on which engine tried to operate, do not exist
+ */
+ ENGINE_NO_FILE,
+ /**
+ * :: while engine was working, "Out Of Memory" error occured
+ */
+ ENGINE_OUT_OF_MEMORY
}
EngineStatus;
+//------------------------------------------------------------------------------
-//______________________________________________________________________________________________________
-// ******************************************************************************************************
-//********************************************************************* DEFINITIONS OF CALLBACK'S TYPES:
+//______________________________________________________________________________
+// *****************************************************************************
+//********************************************* DEFINITIONS OF CALLBACK'S TYPES:
+//------------------------------------------------------------------------------
/** \brief Type of callback functions for retrieving word list.
*
- * Function which is set by dict_eng_set_callback() to signal ENGINE_WORD_LIST_SIGNAL should be exactly this type.
+ * Function which is set by dict_eng_set_callback() to signal
+ * ENGINE_WORD_LIST_SIGNAL should be exactly this type.
+ *
* @param list :: <b>GArray*</b> - there will be all found words in this array
- * @param pattern :: <b>gchar*</b> - pattern to which we have been looking for word lists
- * @param error :: <b>EngineStatus</b> - error code; if everything was ok it is ENGINE_NO_ERROR
- * @param user_data :: <b>gpointer</b> - data set by user to be passing to each callback for ENGINE_WORD_LIST_SIGNAL signal
+ * @param pattern :: <b>gchar*</b> - pattern to which we have been looking for
+ * word lists
+ * @param error :: <b>EngineStatus</b> - error code; if everything was ok it is
+ * ENGINE_NO_ERROR
+ * @param user_data :: <b>gpointer</b> - data set by user to be passing to each
+ * callback for ENGINE_WORD_LIST_SIGNAL signal
*/
-typedef void (*cb_word_list)(GArray* list, gchar* pattern, gpointer user_data, EngineStatus error);
-
-
+typedef void (*cb_word_list)(GArray* list,
+ gchar* pattern,
+ gpointer user_data,
+ EngineStatus error);
+//------------------------------------------------------------------------------
/** \brief Type of callback functions for retrieving word's translation.
*
- * Function which is set by dict_eng_set_callback() to signal ENGINE_WORD_TRANSLATION_SIGNAL should be exactly this type.
+ * Function which is set by dict_eng_set_callback() to signal
+ * ENGINE_WORD_TRANSLATION_SIGNAL should be exactly this type.
+ *
* @param translation :: <b>gchar*</b> - translation of word <i>word</i>
* @param word :: <b>gchar*</b> - word which translation we already retrieved
- * @param error :: <b>EngineStatus</b> - error code; if everything was ok it is ENGINE_NO_ERROR
- * @param user_data :: <b>gpointer</b> - data set by user to be passing to each callback for ENGINE_WORD_TRANSLATION_SIGNAL signal
+ * @param error :: <b>EngineStatus</b> - error code; if everything was ok it is
+ * ENGINE_NO_ERROR
+ * @param user_data :: <b>gpointer</b> - data set by user to be passing to each
+ * callback for ENGINE_WORD_TRANSLATION_SIGNAL signal
*/
-typedef void (*cb_word_translation)(gchar* translation, gchar* word, gpointer user_data, EngineStatus error);
-
-
-
-typedef void (*cb_progress)(gdouble value, gpointer user_data, EngineStatus error);
-
-
-//______________________________________________________________________________________________________
-// ******************************************************************************************************
-//*************************************************************** DEFINITIONS OF BASIC FUNCTIONS TYPES:
-// /** \brief Predeclaration for structure Engine.
+typedef void (*cb_word_translation)(gchar* translation,
+ gchar* word,
+ gpointer user_data,
+ EngineStatus error);
+//------------------------------------------------------------------------------
+/** \brief Type of callback functions for updating progress bar.
+ *
+ * Function which is set by dict_eng_set_callback() to signal
+ * ENGINE_PROGRESS_OPTIMIZING_SIGNAL should be exactly this type.
+ *
+ * @param value :: <b>double</b> - current progres of process [0.0 - 1.0]
+ * @param user_data :: <b>gpointer</b> - data set by user to be passing to each
+ * callback for ENGINE_PROGRESS_OPTIMIZING_SIGNAL signal
+ * @param error :: <b>EngineStatus</b> - error code; if everything is ok it has
+ * ENGINE_NO_ERROR value
+ */
+typedef void (*cb_progress)(gdouble value,
+ gpointer user_data,
+ EngineStatus error);
+//------------------------------------------------------------------------------
+
+
+//______________________________________________________________________________
+// *****************************************************************************
+//**************************************** DEFINITIONS OF BASIC FUNCTIONS TYPES:
+//------------------------------------------------------------------------------
typedef struct _Engine Engine;
-
-/** \brief Type of function getting some chars from engin.
+/** \brief Type of function getting some chars from engine.
*
- * Function of this type should be used for functions which intention is to get some string from concrete dictionary.
- * @param engine :: <i>Engine*</i> - pointer to engine on which this functions has to work
- * @return <i><b>gchar*</b></i> :: chars which represents some information depends on concrete functions (e.g engine path etc.)
+ * Function of this type should be used for functions which intention is to get
+ * some string from concrete dictionary.
+ *
+ * @param engine :: <i>Engine*</i> - pointer to engine on which this functions
+ * has to work
+ * @return <i><b>gchar*</b></i> :: chars which represents some information
+ * depends on concrete functions (e.g engine path etc.)
*/
typedef gchar* (*getting_char)(Engine* engine);
-
-
+//------------------------------------------------------------------------------
/** \brief Type of function getting boolean statement from engine.
*
- * Function of this type should be used for functions which intention is to get boolean statement
- * from concrete dictionary (e.g. to get know if engine has cach file - is cashed).
- * @param engine :: <i>Engine*</i> - pointer to engine on which this functions has to work
- * @return <i><b>gboolean</b></i> :: gboolean statement which gives programmers some information about state of dictionary/engine
-*/
+ * Function of this type should be used for functions which intention is to get
+ * boolean statement from concrete dictionary (e.g. to get know if engine has
+ * cache file - is optimized).
+ *
+ * @param engine :: <i>Engine*</i> - pointer to engine on which this functions
+ * has to work
+ * @return <i><b>gboolean</b></i> :: gboolean statement which gives programmers
+ * some information about state of dictionary/engine
+ */
typedef gboolean (*getting_bool)(Engine* engine);
-
-/** \brief Type of function which hasn't got to return any value (only perform some actions).
+//------------------------------------------------------------------------------
+/** \brief Type of function which hasn't got to return any value.
*
- * Function of this type should be used for functions which intention is only to do something
- * on concrete dictionary (e.g. to make cache file, delete etc.).
- * @param engine :: <i>Engine*</i> - pointer to engine on which this functions has to work
- * @return nothing. Functions of this type should only perform some action - there is no result
+ * Function of this type should be used for functions which intention is only
+ * to do something on concrete dictionary (e.g. to make cache file etc).
+ *
+ * @param engine :: <i>Engine*</i> - pointer to engine on which this functions
+ * has to work
+ * @return nothing. Functions of this type should only perform some action -
+ * there is no result
*/
typedef void (*doing_only)(Engine* engine);
-
+//------------------------------------------------------------------------------
/** \brief Type of function which can find words list from dictionary.
-*
-* Function of this type should be used as a function for searching words list matching to pattern.
-* @param engine :: <i>Engine*</i> - pointer to engine on which this functions has to work
-* @param pattern :: <i>gchar*</i> - pointer to chars which describes pattern for searching words
-* @return nothing. This function do not return anything - result should be retrievwe by callbacks
-*/
-typedef void (*searching_word_list)(Engine* engine, gchar* pattern);
-
+ *
+ * Function of this type should be used as a function for searching words list
+ * matching to pattern.
+ *
+ * @param engine :: <i>Engine*</i> - pointer to engine on which this functions
+ * has to work
+ * @param pattern :: <i>gchar*</i> - pointer to chars which describes pattern
+ * for searching words
+ * @return nothing. This function do not return anything - result should be
+ * retrieve by callbacks
+ */
+typedef void (*searching_word_list)(Engine* engine, gchar* pattern);
+//------------------------------------------------------------------------------
/** \brief Type of function which can find word's translation from dictionary.
*
- * Functions of this type should be used as a function for searching word translation in concrete dictionary.
- * @param engine :: <i>Engine*</i> - pointer to engine on which this functions has to work
- * @param word :: <i>gchar*</i> - pointer to chars which tells what word's translation we are looking for
- * @return nothing. This function do not return anything - result should be retrievwe by callback
+ * Functions of this type should be used as a function for searching word
+ * translation in concrete dictionary.
+ *
+ * @param engine :: <i>Engine*</i> - pointer to engine on which this functions
+ * has to work
+ * @param word :: <i>gchar*</i> - pointer to chars which tells what word's
+ * translation we are looking for
+ * @return nothing. This function do not return anything - result should be
+ * retrieve by callback
*/
-typedef void (*searching_word_translation)(Engine* engine, gchar* word);
-
-/** \brief Type of function which can <i>translate</i> error code to descriptive message.
+typedef void (*searching_word_translation)(Engine* engine, gchar* word);
+//------------------------------------------------------------------------------
+/** \brief Type of function which can trans. error code to descriptive message.
*
- * Functions of this type should be used as <i>translator</i> from error code to meaningful message.
+ * Functions of this type should be used as <i>translator</i> from error code
+ * to meaningful message.
+ *
* @param error :: <i>EngineStatus</i> - error to which we want get description
- * @return <i><b>gchar*</b></i> :: chars which describes us what kind of error occured (e.g. "Dictionary file has wrong file format or it is corrupted.")
+ * @return <i><b>gchar*</b></i> :: chars which describes us what kind of error
+ * occured (e.g. "Dictionary file has wrong file format or it is corrupted.")
*/
-typedef gchar* (*error_to_message)(EngineStatus error);
-
-/** \brief Type of function which should be used to set new callback for some event.
+typedef gchar* (*error_to_message)(EngineStatus error);
+//------------------------------------------------------------------------------
+/** \brief Type of function which should be used to set callbacks for signals.
*
- * Functions of this type should be used as a <i>setter</i> for new callback functions
- * @param engine :: <i>Engine*</i> - pointer to engine on which this functions has to work
- * @param signal :: <i>gchars*</i> - pointer to chars which tell us what kind of event should new_functions handle (e.g. "word_list_found", "translation_found" etc.)
+ * Functions of this type should be used as a <i>setter</i> for new callback
+ * functions
+ *
+ * @param engine :: <i>Engine*</i> - pointer to engine on which this functions
+ * has to work
+ * @param signal :: <i>gchars*</i> - pointer to chars which tell us what kind
+ * of event should new_functions handle (e.g. "word_list_found",
+ * "translation_found" etc.)
* @param c_handler :: <i>gpointer</i> - new callback function
- * @param user_data :: <i>gpointer</i> - pointer do structure, which should be passed as a last argument when calling new mounted callback
- * @return <i><b>gpointer</b></i> :: gpointer to previous callback. If NULL there could be some error so programmers should check by engine_error() function if there was some
- * (if NULL and engine_error() return ENGINE_NO_ERROR that means that this callback was unused before).
- * \sa ENGINE_WORD_LIST_SIGNAL :|: ENGINE_WORD_TRANSLATION_SIGNAL :|: dict_eng_set_callback() :|: cb_word_list :|: cb_word_translation
-*/
-typedef gpointer (*setting_callbacks)(Engine* engine, gchar* signal, gpointer c_handler, gpointer user_data);
-
-
+ * @param user_data :: <i>gpointer</i> - pointer do structure, which should be
+ * passed as a last argument when calling new mounted callback
+ * @return <i><b>gpointer</b></i> :: gpointer to previous callback. If NULL
+ * there could be some error so programmers should check by engine_error()
+ * function if there was some (if NULL and engine_error() return
+ * ENGINE_NO_ERROR that means that this callback was unused before).
+ * \sa ENGINE_WORD_LIST_SIGNAL :|: ENGINE_WORD_TRANSLATION_SIGNAL :|:
+ * dict_eng_set_callback() :|: cb_word_list :|: cb_word_translation
+ */
+typedef gpointer (*setting_callbacks)(Engine* engine,
+ gchar* signal,
+ gpointer c_handler,
+ gpointer user_data);
+//------------------------------------------------------------------------------
/** \brief Type of function which can get some int value from dictionary.
*
- * Functions of this type should be used if programmer want to get some int value from dictionary.
- * @param enigne :: <i>Engine*</i> - pointer to engine on which this functions has to work
- * @return <i><b>gint</b></i> :: int value which user wanted to get from dictionary
+ * Functions of this type should be used if programmer want to get some int
+ * value from dictionary.
+ *
+ * @param enigne :: <i>Engine*</i> - pointer to engine on which this functions
+ * has to work
+ * @return <i><b>gint</b></i> :: int value which user wanted to get from
+ * dictionary
*/
typedef gint (*getting_int)(Engine* engine);
-
-
-//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+//------------------------------------------------------------------------------
typedef EngineStatus (*getting_status)(Engine* engine);
-typedef void (*setting_progress_seed)(Engine* engine, gchar* signal, gdouble seed);
-
-//______________________________________________________________________________________________________
-// ******************************************************************************************************
-//********************************************************* DEFINITIONS OF ADDITIONAL FUNCTIONS TYPES:
-/** \brief Additional functions type: Type of function which should be used to check if this module could handle some location (e.g filename, URI, etc.).
+//------------------------------------------------------------------------------
+typedef void (*setting_progress_seed)(Engine* engine,
+ gchar* signal,
+ gdouble seed);
+//------------------------------------------------------------------------------
+
+
+//______________________________________________________________________________
+// *****************************************************************************
+//*********************************** DEFINITIONS OF ADDITIONAL FUNCTIONS TYPES:
+//------------------------------------------------------------------------------
+/** \brief Additional functions type.
*
- * Functions of this type should be used to check if dictionary in location could be handled by this engine.
- * @param location :: <i>gchar*</i> - chars which describe location of dictionary to check
- * @return <i><b>gboolean</i></b> :: statement telling us if this module could or could not handle dictionary under location.
+ * Functions of this type should be used to check if dictionary in location
+ * could be handled by this engine.
+ *
+ * @param location :: <i>gchar*</i> - chars which describe location of
+ * dictionary to check
+ * @return <i><b>gboolean</i></b> :: statement telling us if this module could
+ * or could not handle dictionary under location.
*/
typedef gboolean (*checking_compatibiliti)(gchar* location);
-
-
-/** \brief Additional functions type: Type of function which should be used to get some chars from concrete module/engine (NOT DICTIONARY!).
+//------------------------------------------------------------------------------
+/** \brief Additional functions type.
*
- * Functions of this type should be used to get some descriptions from engine/module.
- * Information retrievs by this kind of functions are global for module (e.g: description of handles fromat, description of module etc.).
+ * Functions of this type should be used to get some descriptions from
+ * engine/module. Information retrievs by this kind of functions are global for
+ * module (e.g: description of handles fromat, description of module etc.).
+ *
* @return <i><b>gchar*</i></b> :: chars which we wanted
*/
-typedef gchar* (*getting_chars_engine)(void);
-
-/** \brief Additional functions type: Type of function which should be used to open (create) new dictionary from location.
+typedef gchar* (*getting_chars_engine)(void);
+//------------------------------------------------------------------------------
+/** \brief Additional functions type.
*
* Functions of this type should be used to opening dictionary.
- * @param location :: <i>gchar*</i> - chars which describe where is the dictionary which we want to open
- * @param flags :: <i>EngineOptimizationFlag</i> - flags to initialize/use optimization methods for opening dictionary.
- * @return <i><b>gpointer</i></b> ::pointer to opened Engine. If NULL there was some error - programmers should check error type by calling engine_error() function.
+ * @param location :: <i>gchar*</i> - chars which describe where is the
+ * dictionary which we want to open
+ * @param flags :: <i>EngineOptimizationFlag</i> - flags to initialize/use
+ * optimization methods for opening dictionary.
+ * @return <i><b>gpointer</i></b> ::pointer to opened Engine. If NULL there was
+ * some error - programmers should check error type by calling
+ * engine_error() function.
*/
-typedef Engine* (*creating_engine)(gchar* location, EngineOptimizationFlag flags, cb_progress progress_handler, gpointer progress_data, gdouble seed);
-
-
+typedef Engine* (*creating_engine)(gchar* location,
+ EngineOptimizationFlag flags,
+ cb_progress progress_handler,
+ gpointer progress_data,
+ gdouble seed);
+//------------------------------------------------------------------------------
/** \brief General dictionary structure.
-*
-* This structure contains every data which are needed to make dictionary working. Data of dictionary are
-* invisible for user of finnal module. User can operate on dictionary with functions to which there are pointers
-* in this structure also. engine_data is for module programmer use only. Programmer of module can put there any
-* data he want. He should not give end user any information about engine_data structure.
-*/
+ *
+ * This structure contains every data which are needed to make dictionary
+ * working. Data of dictionary are invisible for user of finnal module. User can
+ * operate on dictionary with functions to which there are pointers in this
+ * structure also. engine_data is for module programmer use only. Programmer of
+ * module can put there any data he want. He should not give end user any
+ * information about engine_data structure.
+ */
struct _Engine
{
- void (*engine_set_auto_free)(Engine* engine, gboolean state);
-
-
- /** \brief Getting location of dictionary.
- *
- * User can use this function if want to get location of concrete dictionary.
- * \sa getting_char
- */
- getting_char engine_location;
-
- /** \brief Getting information if this dictionary is cached.
- *
- * User can use this function if want to know is dictionary cached actually.
- * \sa getting_bool
- */
- getting_bool engine_is_optimized;
-
- /** \brief Making cache file for dictionary.
- *
- * User can use this function if want to make cache file for concrete dictionary.
- * \sa doing_only
- */
- doing_only engine_optimize;
-
- /** \brief Searching word list.
- *
- * User call this function to start searching for word list.
- * \sa searching_word_list
- */
- searching_word_list engine_search_word_list;
-
- /** \brief Searching word's translation.
- *
- * User call this function to start searching for word's translation.
- * \sa searching_word_translation
- */
- searching_word_translation engine_search_word_translation;
-
- /** \brief Searching word's translation (preformatted HTML).
- *
- * User call this function to start searching for word's translation. It differs from engine_search_word_translation
- * that it returns preformatted string (HTML format).
- * \sa searching_word_translation
- */
- searching_word_translation engine_search_word_translation_extended;
-
- /** \brief Close dictionary.
- *
- * User call this if work with dictionary is finished and there is no need to keep this further working.
- * \sa doing_only
- */
- doing_only engine_close;
-
- /** \brief Functions return laste error which occured in dictionary.
- *
- * Programmer should use this function after each action to check if there was not any errors.
- * \sa getting_int
- */
- getting_status engine_error;
-
- /** \brief <i>Tranlsate</i> error code to meaningful message.
- *
- * Programmer can call this function if want to get meaningful message describes concrete error code
- * \sa error_to_message
- */
- error_to_message engine_error_message;
-
- /** \brief Function to setting any callback for this dictionary.
- *
- * This function can be used to set some callback function for concrete dictionary. Programmer
- * should always set callback "word_list_found" and "word_translation_found". Developers of
- * new modules should also define for what kind of event end user will be able to set callback.
- */
- setting_callbacks engine_set_callback;
-
-
- setting_progress_seed engine_set_progress_seed;
-
- /** \brief Module's private data area. Used only by module programmer.
- *
- * Here module programmer should keep their own data (e.g. some data for searching optimalization etc.).
- * Programmer whose only using module, should not use engine_data at all.
- */
- gpointer engine_data;
+ void (*engine_set_auto_free)(Engine* engine, gboolean state);
+
+
+ /** \brief Getting location of dictionary.
+ *
+ * User can use this function if want to get location of concrete
+ * dictionary.
+ * \sa getting_char
+ */
+ getting_char engine_location;
+
+ /** \brief Getting information if this dictionary is cached.
+ *
+ * User can use this function if want to know is dictionary cached
+ * actually.
+ * \sa getting_bool
+ */
+ getting_bool engine_is_optimized;
+
+ /** \brief Making cache file for dictionary.
+ *
+ * User can use this function if want to make cache file for concrete
+ * dictionary.
+ * \sa doing_only
+ */
+ doing_only engine_optimize;
+
+ /** \brief Searching word list.
+ *
+ * User call this function to start searching for word list.
+ * \sa searching_word_list
+ */
+ searching_word_list engine_search_word_list;
+
+ /** \brief Searching word's translation.
+ *
+ * User call this function to start searching for word's translation.
+ * \sa searching_word_translation
+ */
+ searching_word_translation engine_search_word_translation;
+
+ /** \brief Searching word's translation (preformatted HTML).
+ *
+ * User call this function to start searching for word's translation.
+ * It differs from engine_search_word_translation that it returns
+ * preformatted string (HTML format).
+ * \sa searching_word_translation
+ */
+ searching_word_translation engine_search_word_translation_extended;
+
+ /** \brief Close dictionary.
+ *
+ * User call this if work with dictionary is finished and there is no
+ * need to keep this further working.
+ * \sa doing_only
+ */
+ doing_only engine_close;
+
+ /** \brief Functions return laste error which occured in dictionary.
+ *
+ * Programmer should use this function after each action to check if
+ * there was not any errors.
+ * \sa getting_int
+ */
+ getting_status engine_error;
+
+ /** \brief <i>Tranlsate</i> error code to meaningful message.
+ *
+ * Programmer can call this function if want to get meaningful message
+ * describes concrete error code
+ * \sa error_to_message
+ */
+ error_to_message engine_error_message;
+
+ /** \brief Function to setting any callback for this dictionary.
+ *
+ * This function can be used to set some callback function for concrete
+ * dictionary. Programmer should always set callback "word_list_found"
+ * and "word_translation_found". Developers of new modules should also
+ * define for what kind of event end user will be able to set callback.
+ */
+ setting_callbacks engine_set_callback;
+
+
+ setting_progress_seed engine_set_progress_seed;
+
+ /** \brief Module's private data area. Used only by module programmer.
+ *
+ * Here module programmer should keep their own data (e.g. some data for
+ * searching optimalization etc.). Programmer whose only using module,
+ * should not use engine_data at all.
+ */
+ gpointer engine_data;
};
-
-/** \brief Structure that has, as a members, pointers to helpfull functions for programmer.
-*
-* There are pointers to some functions in this structure. Programmer whom using module could use it to
-* get some useful informationa about module (e.g: format handled by module, it's version etc.). The most important
-* functions are: \n
-* engine_check() - to check if this module can handle concrete location \n
-* engine_open() - to open location
-*/
+//------------------------------------------------------------------------------
+/** \brief Structure that has pointers to helpfull functions for programmer.
+ *
+ * There are pointers to some functions in this structure. Programmer whom using
+ * module could use it to get some useful informationa about module (e.g: format
+ * handled by module, it's version etc.). The most important functions are: \n
+ * engine_check() - to check if this module can handle concrete location \n
+ * engine_open() - to open location
+ */
typedef struct {
-
- /** \brief Function to check compatibility beetwen module and location.
- *
- * Helps programmer to check if this concrete module was designed to work with dictionary under location passed as a argument to this function
- * \sa checking_compatibiliti
- */
- checking_compatibiliti engine_check;
-
- /** \brief Function to get some short description of module/engine.
- *
- * This function returns short description of module, to make possible displaying for end user what kind of module he is useing.
- * \sa getting_chars_engine
- */
- getting_chars_engine engine_description;
-
- /** \brief Function to get module's format.
- *
- * This function returns format of dictionary which this module can handle.
- * \sa getting_chars_engine
- */
- getting_chars_engine engine_format;
-
- /** \brief Function to get version of module.
- *
- * This functions return version of this module/engine.
- * \sa getting_chars_engine
- */
- getting_chars_engine engine_version;
-
- /** \brief Function to open/create new dictionary.
- *
- * This functions allow programmer to open/create module from concrete location.
- * \sa creating_engine
- */
- creating_engine engine_create;
+
+ /** \brief Function to check compatibility beetwen module and location.
+ *
+ * Helps programmer to check if this concrete module was designed to work
+ * with dictionary under location passed as a argument to this function.
+ * \sa checking_compatibiliti
+ */
+ checking_compatibiliti engine_check;
+
+ /** \brief Function to get some short description of module/engine.
+ *
+ * This function returns short description of module, to make possible
+ * displaying for end user what kind of module he is using.
+ * \sa getting_chars_engine
+ */
+ getting_chars_engine engine_description;
+
+ /** \brief Function to get module's format.
+ *
+ * This function returns format of dictionaries which this module handles
+ * \sa getting_chars_engine
+ */
+ getting_chars_engine engine_format;
+
+ /** \brief Function to get version of module.
+ *
+ * This functions return version of this module/engine.
+ * \sa getting_chars_engine
+ */
+ getting_chars_engine engine_version;
+
+ /** \brief Function to open/create new dictionary.
+ *
+ * This functions allow programmer to open/create module from concrete
+ * location.
+ * \sa creating_engine
+ */
+ creating_engine engine_create;
}
EngineModule;
-
-
-/** \brief Additional functions type: type of functions wich helps load others function from module.
+//------------------------------------------------------------------------------
+/** \brief Additional functions type.
*
- * There should be in each module exactly one function of this type named: engine_global_functions. This function
- * makes easier to load dynamically module. For doing this then you need only to mapped only this one function
- * and the rest will be avaiable for you from returned structure EngineModule.
- * @return <i><b>EngineModule</b></i> :: structure EngineModule from which you can call next functions
+ * There should be in each module exactly one function of this type named:
+ * engine_global_functions. This function makes easier to load dynamically
+ * module. For doing this then you need only to mapped only this one function
+ * and the rest will be avaiable from returned structure EngineModule.
+ *
+ * @return <i><b>EngineModule</b></i> :: structure EngineModule from which you
+ * can call next functions
* \sa engine_global_functions()
*/
typedef EngineModule (*getting_additional)(void);
-
-/** \brief Function that helps programmer to load basic functions from engine's module.
+//------------------------------------------------------------------------------
+/** \brief Function that helps programmer to load basic functions from module.
*
- * This function helps programmers to dynamically load module to their programms. Only this function needed to be
- * mapped from *.so file. Rest of function are in returned structure EngineModule. User of module could mapped himslef
- * others functions from concrete modules, but it is not recommended as far as developers of module could, in fact, give different
- * names for functions. In structure EngineModule names will be always the same. NOTE for module developer: this function should be always defined in your
- * code, to help next programmers whose will be using yours module in theirs own programms.
- * @return <i><b>EngineModule</b></i> :: Structure EngineModule which members are functions for basic operations for this module
+ * This function helps programmers to dynamically load module to their
+ * programms. Only this function needed to be mapped from *.so file. Rest of
+ * function are in returned structure EngineModule. User of module could mapped
+ * himslef others functions from concrete modules, but it is not recommended as
+ * far as developers of module could, in fact, give different names for
+ * functions. In structure EngineModule names will be always the same. \n
+ * NOTE for module developer: this function should be always defined in your
+ * code, to help next programmers whose will be using yours module in theirs own
+ * programms.
+ *
+ * @return <i><b>EngineModule</b></i> :: Structure EngineModule which members
+ * are functions for basic operations for this module
*/
extern EngineModule engine_global_functions(void);
+//------------------------------------------------------------------------------
+
#ifdef __cplusplus
-}
-#endif // END OF: extern "C" {
-#endif // END OF: _DICTIONARY_ENGINE_BASE
+}
+#endif // END OF: extern "C" {
+
+#endif // END OF: _DICTIONARY_ENGINE_BASE
-/**********************************************************************************
- * copyright (C) 2006, Dariusz Wiechecki
- * dariusz.wiechecki@gmail.com
- * 14 August 2006, Lodz, Poland
- **********************************************************************************
- * This file is part of str-vfs-test.
- *
- * str-vfs-test is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * str-vfs-test is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with str-vfs-test; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *********************************************************************************/
+/*******************************************************************************
+This file is part of WhiteStork.
+
+WhiteStork is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+WhiteStork is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with WhiteStork; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+Copyright 2006 ComArch S.A.
+*******************************************************************************/
#ifndef _DICTIONARY_ENGINE_XDXF
#define _DICTIONARY_ENGINE_XDXF
+
#ifdef __cplusplus
-extern "C" {
+ extern "C" {
#endif
-#include <expat.h>
+//______________________________________________________________________________
+// *****************************************************************************
+//************************************************************* HEADERS SECTION:
+//------------------------------------------------------------------------------
+// headers with unix types/functions - onl for timers
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <fcntl.h>
#include <unistd.h>
-
+//------------------------------------------------------------------------------
+// header with GLIB definitions/functions/types
#include <glib.h>
+//------------------------------------------------------------------------------
+// header with gnome-vfs - recommended I/O API for maemo
#include <libgnomevfs/gnome-vfs.h>
-
+//------------------------------------------------------------------------------
+// header with expat - XML Parser API
+#include <expat.h>
+//------------------------------------------------------------------------------
+// header wit engine API
#include "dictionary_engine.h"
-
-#define TIMER_START TRUE
-#define TIMER_STOP FALSE
-
+//------------------------------------------------------------------------------
+
+
+//______________________________________________________________________________
+// *****************************************************************************
+//********************************************************* DEFINITIONS SECTION:
+//------------------------------------------------------------------------------
+// definitions for timer function - flag telling if we want to start or stop
+// timing
+#define TIMER_START TRUE
+#define TIMER_STOP FALSE
+//------------------------------------------------------------------------------
+// definitions of version and format which engine handles
#define DIC_ENG_VERSION "0.1b"
#define DIC_ENG_FORMAT "XDXF"
-
-
-#define DICT_CACHEING_BUFF_SIZE 16*1024
-#define DICT_SEARCHING_WORD_LIST_BUFF_SIZE 16*1024
-#define DICT_SEARCHING_WORD_TRAN_BUFF_SIZE 16*1024
-
+//------------------------------------------------------------------------------
+// defines lenght of buffers for particular functions in engine which needs
+// big buffers
+#define DICT_CACHEING_BUFF_SIZE 16*1024
+#define DICT_SEARCHING_WORD_LIST_BUFF_SIZE 16*1024
+#define DICT_SEARCHING_WORD_TRAN_BUFF_SIZE 16*1024
+//------------------------------------------------------------------------------
// maximum length of word possible to find in any dictionary
#define DICT_MAX_WORD_LENGTH 512
-
+//------------------------------------------------------------------------------
+// macro for "printing" gboolean statement - "TRUE" or "FALSE"
#define PRINT_STATE(state) ( (state) ? "TRUE" : "FALSE" )
+//------------------------------------------------------------------------------
+
-/** \brief Structure to help check if concrete location is compatuible with this module.
+//______________________________________________________________________________
+// *****************************************************************************
+//****************************************** DATA STRUCTURE DEFINITIONS SECTION:
+//------------------------------------------------------------------------------
+/** \brief Structure used while dict_eng_module_check() is working.
*/
struct _XDXFCheckingData {
- gboolean further;
- gboolean good;
- guint deep;
+ gboolean further;
+ gboolean good;
+ guint deep;
};
-typedef struct _XDXFCheckingData XDXFCheckingData;
-
+typedef struct _XDXFCheckingData XDXFCheckingData;
+//------------------------------------------------------------------------------
/** \brief Structure to help parse xdxf file for searching words list.
*/
struct _XDXFWordsListData {
- gchar* last_word;
- gchar* pattern;
- guint pattern_len;
- guint last_word_length;
- GArray* result;
- guint one_word;
- gboolean cont;
+ gchar* last_word;
+ gchar* pattern;
+ guint pattern_len;
+ guint last_word_length;
+ GArray* result;
+ guint one_word;
+ gboolean cont;
};
-typedef struct _XDXFWordsListData XDXFWordsListData;
-
+typedef struct _XDXFWordsListData XDXFWordsListData;
+//------------------------------------------------------------------------------
/** \brief Structure to help parse xdxf file for searching word's translation.
*/
struct _XDXFWordsTransData {
- gchar* last_word;
- gchar* word;
- guint word_len;
- guint last_word_length;
- gchar* translation;
- guint one_word;
- gboolean cont;
- gulong last_start;
- XML_Parser* parser;
- gboolean found;
- GnomeVFSHandle* xdxf;
+ gchar* last_word;
+ gchar* word;
+ guint word_len;
+ guint last_word_length;
+ gchar* translation;
+ guint one_word;
+ gboolean cont;
+ gulong last_start;
+ XML_Parser* parser;
+ gboolean found;
+ GnomeVFSHandle* xdxf;
};
-typedef struct _XDXFWordsTransData XDXFWordsTransData;
-
+typedef struct _XDXFWordsTransData XDXFWordsTransData;
+//------------------------------------------------------------------------------
/** \brief Structure to help make optimization possible
*/
struct _XDXFCacheData {
- gchar* buffer;
- long last_start;
- long last_stop;
- long last_length;
- GnomeVFSHandle* cache;
- XML_Parser parser;
- int state;
- long buffer_length;
+ gchar* buffer;
+ long last_start;
+ long last_stop;
+ long last_length;
+ GnomeVFSHandle* cache;
+ XML_Parser parser;
+ int state;
+ long buffer_length;
};
-typedef struct _XDXFCacheData XDXFCacheData;
-
-
-/** \brief Internal data structure of XDXF Engine (in Engine structure it is field: engine_data).
- */
-struct _XDXFData {
- GnomeVFSHandle* xdxf;
- GnomeVFSHandle* cache;
- gchar* dict_path;
- EngineStatus last_error;
- gboolean auto_free;
-
- cb_progress cb_progress_caching;
- gpointer cb_progress_caching_data;
- gdouble cb_progress_caching_seed;
-
- cb_progress cb_progress_word_list;
- gpointer cb_progress_word_list_data;
- gdouble cb_progress_word_list_seed;
-
- cb_progress cb_progress_word_trans;
- gpointer cb_progress_word_trans_data;
- gdouble cb_progress_word_trans_seed;
-
- cb_word_list cb_search_word_list;
- gpointer cb_search_word_list_data;
-
- cb_word_translation cb_search_word_trans;
- gpointer cb_search_word_trans_data;
-};
-typedef struct _XDXFData XDXFData;
-
-
-
+typedef struct _XDXFCacheData XDXFCacheData;
+//------------------------------------------------------------------------------
/** \brief Internal data structure for representing part of file.
*/
struct _FilePart {
- guint offset;
- guint length;
+ guint offset;
+ guint length;
};
-typedef struct _FilePart FilePart;
-
-
-
-// helpfull functions
-static gchar* read_file_part(FilePart* part, GnomeVFSHandle* file); // written
-static gchar* string_to_path(gchar** string); // written
-static gboolean is_xdxf_file(gchar* file); // written
-static double timer(gboolean start, gchar* message); // written
-static guint64 get_file_size(GnomeVFSHandle* file);
-static guint get_max_length(gchar* a, guint length);
-
-// static functions for parsing file in different functions:
-static void is_xdxf_file_start(void *data, const char *el, const char **attr); // written
-static void is_xdxf_file_end(void *data, const char *el); // written
-
-static void search_word_list_start(void *data, const char *el, const char **attr); // written
-static void search_word_list_end(void *data, const char *el); // written
-static void search_word_list_text(void *data, const XML_Char *txt, int len);
-
-static void search_word_trans_start(void *data, const char *el, const char **attr);
-static void search_word_trans_end(void *data, const char *el);
-static void search_word_trans_text(void *data, const XML_Char *txt, int len);
-
-// declarations of functions
-gboolean engine_check(gchar* location);
-gchar* engine_description();
-gchar* engine_format();
-gchar* engine_version();
-Engine* engine_create(gchar* location, EngineOptimizationFlag flags, cb_progress progress_handler, gpointer progress_data, gdouble seed);
-gpointer* module_set_callback(EngineModule module, gchar* signal, gpointer c_handler, gpointer user_data);
-gpointer* module_set_progress_seed(EngineModule module, gchar* signal, gpointer c_handler, gpointer user_data);
-
+typedef struct _FilePart FilePart;
+//------------------------------------------------------------------------------
+/** \brief Internal data structure of XDXF Engine.
+ */
+struct _XDXFData {
+ GnomeVFSHandle* xdxf;
+ GnomeVFSHandle* cache;
+ gchar* dict_path;
+ EngineStatus last_error;
+ gboolean auto_free;
-void engine_close(Engine* engine);
-gchar* engine_location(Engine* engine);
-void engine_optimize(Engine* engine);
-gboolean engine_is_optimized(Engine* engine);
-void engine_set_auto_free(Engine* engine, gboolean state);
+ cb_progress cb_progress_caching;
+ gpointer cb_progress_caching_data;
+ gdouble cb_progress_caching_seed;
-gpointer engine_set_callbacks(Engine* engine, gchar* event, gpointer new_funtions, gpointer user_data);
-void engine_set_progress_seed(Engine* engine, gchar* signal, gdouble seed);
+ cb_progress cb_progress_word_list;
+ gpointer cb_progress_word_list_data;
+ gdouble cb_progress_word_list_seed;
-void engine_search_word_list(Engine* engine, gchar* pattern);
-void engine_search_word_translation(Engine* engine, gchar* word);
-void engine_search_word_translation_extended(Engine* engine, gchar* word);
+ cb_progress cb_progress_word_trans;
+ gpointer cb_progress_word_trans_data;
+ gdouble cb_progress_word_trans_seed;
-EngineStatus engine_error(Engine* engine);
-gchar* engine_error_message(EngineStatus error);
+ cb_word_list cb_search_word_list;
+ gpointer cb_search_word_list_data;
-EngineModule engine_global_functions();
+ cb_word_translation cb_search_word_trans;
+ gpointer cb_search_word_trans_data;
+};
+typedef struct _XDXFData XDXFData;
+//------------------------------------------------------------------------------
+
+
+//______________________________________________________________________________
+// *****************************************************************************
+//*************************************************** PARSING FUNCTIONS SECTION:
+//------------------------------------------------------------------------------
+// while is_xdxf_file() is working
+static void is_xdxf_file_start(void *data,
+ const char *el,
+ const char **attr);
+static void is_xdxf_file_end(void *data, const char *el);
+//------------------------------------------------------------------------------
+// while dict_eng_search_word_list() is working
+static void search_word_list_start(void *data,
+ const char *el,
+ const char **attr);
+static void search_word_list_end(void *data, const char *el);
+static void search_word_list_text(void *data, const XML_Char *txt, int len);
+//------------------------------------------------------------------------------
+// // while dict_eng_search_word_translation() is working
+static void search_word_trans_start(void *data,
+ const char *el,
+ const char **attr);
+static void search_word_trans_end(void *data, const char *el);
+static void search_word_trans_text(void *data,
+ const XML_Char *txt,
+ int len);
+//------------------------------------------------------------------------------
+
+
+//______________________________________________________________________________
+// *****************************************************************************
+//************************************************ ADDITIONAL FUNCTIONS SECTION:
+//------------------------------------------------------------------------------
+// returning concrete part of file
+static gchar* read_file_part(FilePart* part, GnomeVFSHandle* file);
+//------------------------------------------------------------------------------
+// convert string to proper path name (no filename, no "/" at the ned, file \
+// exist)
+static gchar* string_to_path(gchar** string);
+//------------------------------------------------------------------------------
+// tells if file is in XDXF format (file should exist)
+static gboolean is_xdxf_file(gchar* file);
+//------------------------------------------------------------------------------
+// start/stop timers - returnet -1.0 if we start or seconds passed from start
+// if we want to stop timer
+static double timer(gboolean start, gchar* message);
+//------------------------------------------------------------------------------
+// return size of files
+static guint64 get_file_size(GnomeVFSHandle* file);
+//------------------------------------------------------------------------------
+// return how many records (from cache file) are in current buffer a with length
+// length.
+static guint get_max_length(gchar* a, guint length);
+//------------------------------------------------------------------------------
+// return translation of word using cache file
+static gchar* word_translation_cache(XDXFData* data, gchar* word);
+//------------------------------------------------------------------------------
+// return translation of word but using only xdxf dictionary file
+static gchar* word_translation_xdxf(XDXFData* data, gchar* word);
+//------------------------------------------------------------------------------
+
+// return translation of word using cache file
+static void word_list_cache(XDXFData* data, gchar* pattern, GArray* result);
+//------------------------------------------------------------------------------
+// return translation of word but using only xdxf dictionary file
+static void word_list_xdxf(XDXFData* data, gchar* pattern, GArray* result);
+//------------------------------------------------------------------------------
+
+
+
+//______________________________________________________________________________
+// *****************************************************************************
+//****************************************************** MAIN FUNCTIONS SECTION:
+//------------------------------------------------------------------------------
+// implementation of dict_eng_module_check(module,location) function
+gboolean engine_check(gchar* location);
+//------------------------------------------------------------------------------
+// implementation of dict_eng_module_get_description(module) function
+gchar* engine_description();
+//------------------------------------------------------------------------------
+// implementation of dict_eng_module_get_format(module) function
+gchar* engine_format();
+//------------------------------------------------------------------------------
+// implementation of dict_eng_module_get_version(module) function
+gchar* engine_version();
+//------------------------------------------------------------------------------
+// implementation of dict_eng_module_create(module,location,flags) and
+// dict_eng_module_create_ext(module,location,flags) functions
+Engine* engine_create(gchar* location,
+ EngineOptimizationFlag flags,
+ cb_progress progress_handler,
+ gpointer progress_data,
+ gdouble seed);
+//------------------------------------------------------------------------------
+// implementation of dict_eng_destroy(engine) function
+void engine_close(Engine* engine);
+//------------------------------------------------------------------------------
+// implementation of dict_eng_get_location(engine) function
+gchar* engine_location(Engine* engine);
+//------------------------------------------------------------------------------
+// implementation of dict_eng_optimize(engine) function
+void engine_optimize(Engine* engine);
+//------------------------------------------------------------------------------
+// implementation of dict_eng_is_optimized( engine ) function
+gboolean engine_is_optimized(Engine* engine);
+//------------------------------------------------------------------------------
+// implementation of dict_eng_set_auto_free(engine, state) function
+void engine_set_auto_free(Engine* engine, gboolean state);
+//------------------------------------------------------------------------------
+// implementation of dict_eng_set_callback(engine,signal,c_handler,data)
+// function
+gpointer engine_set_callbacks(Engine* engine,
+ gchar* event,
+ gpointer c_handler,
+ gpointer user_data);
+//------------------------------------------------------------------------------
+// implementation of dict_eng_set_progress_seed(engine, signal, val) function
+void engine_set_progress_seed(Engine* engine,
+ gchar* signal,
+ gdouble seed);
+//------------------------------------------------------------------------------
+// implementation ofdict_eng_search_word_list(engine,pattern) function
+void engine_search_word_list(Engine* engine, gchar* pattern);
+//------------------------------------------------------------------------------
+// implementation of dict_eng_search_word_translation(engine,word) function
+void engine_search_word_translation(Engine* engine, gchar* word);
+//------------------------------------------------------------------------------
+// implementation of dict_eng_search_word_translation_extended(engine,word)
+// function
+void engine_search_word_translation_extended(Engine* engine,
+ gchar* word);
+//------------------------------------------------------------------------------
+// implementation of dict_eng_get_last_state(engine) function
+EngineStatus engine_error(Engine* engine);
+//------------------------------------------------------------------------------
+// implementation of dict_eng_state_message(error) function
+gchar* engine_error_message(EngineStatus error);
+//------------------------------------------------------------------------------
+// implementation of engine_global_functions(void) function
+EngineModule engine_global_functions();
#ifdef __cplusplus
}
-#include "../include/engine_xdxf.h"
-
+/******************************************************************************
+This file is part of WhiteStork.
+WhiteStork is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
-void engine_search_word_translation(Engine* engine, gchar* word)
-{
- g_debug("XDXF/%s->%s() called.\n-->PARAM:engine at adress=%p\n-->PARAM:word=\'%s\'\n",__FILE__,__FUNCTION__,engine,word);
- g_assert(engine != NULL);
- g_assert(word != NULL);
+WhiteStork is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
- timer(TIMER_START,(gchar*)__FUNCTION__);
- XDXFData* data = (XDXFData*)(engine->engine_data);
- if(data->cb_search_word_trans == NULL)
- {
- g_warning("XDXF/%s->%s() callback for Word Translation not set. Searching aborted.\n",__FILE__,__FUNCTION__);
- timer(TIMER_STOP,(gchar*)__FUNCTION__);
- return;
- };
- guint word_length = strlen(word);
- gchar* trans;
+You should have received a copy of the GNU General Public License
+along with WhiteStork; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- if(data->cache != NULL)
- { // dictionary is optimized
- gnome_vfs_seek(data->cache, GNOME_VFS_SEEK_START, 0);
- gchar b[DICT_SEARCHING_WORD_TRAN_BUFF_SIZE + 1];
- GnomeVFSFileSize bytes_readed;
-
- guint record_length = 0;
- guint trans_offset = 0;
- guint already = 0;
- guint64 readed = 0;
- gchar* buffer = NULL;
- guint file_size = get_file_size(data->cache);
- while(TRUE)
- {
- gnome_vfs_read(data->cache, b, DICT_SEARCHING_WORD_TRAN_BUFF_SIZE, &bytes_readed);
- guint max_length = (guint)get_max_length(b,bytes_readed);
- readed += max_length;
- buffer = b;
- already = 0;
- while(already < max_length)
- {
- memcpy(&record_length, buffer, sizeof(guint));
- memcpy(&trans_offset, buffer+record_length-2*sizeof(guint), sizeof(guint));
- buffer[record_length-sizeof(guint)*2] = '\0';
- if( ((record_length - 3*sizeof(guint)) == word_length) &&
- (g_utf8_collate(word,buffer+sizeof(guint)) == 0))
- {
- FilePart translation = {0,0};
- translation.offset = trans_offset;
- memcpy(&(translation.length),buffer + record_length - sizeof(guint), sizeof(guint));
- trans = read_file_part(&translation, data->xdxf);
- break;
- }
- already += record_length;
- buffer += record_length;
- };
+Copyright 2006 ComArch S.A.
+******************************************************************************/
- if( ( bytes_readed < DICT_SEARCHING_WORD_TRAN_BUFF_SIZE ) ||
- ( readed > (file_size - 3) ))
- {
- break;
- };
- gnome_vfs_seek(data->cache, GNOME_VFS_SEEK_CURRENT, ((gint)max_length) - DICT_SEARCHING_WORD_TRAN_BUFF_SIZE);
- }
- }
- else
- { // dictionary is not optimized right now
- gnome_vfs_seek(data->xdxf, GNOME_VFS_SEEK_START, 0);
- GnomeVFSResult vfs_result;
- GnomeVFSFileSize bytes_readed = DICT_SEARCHING_WORD_TRAN_BUFF_SIZE;
- gchar buffer[DICT_SEARCHING_WORD_TRAN_BUFF_SIZE+1];
- guint64 file_size = get_file_size(data->xdxf);
- //guint word_len = strlen(word); added by me
-
- XML_Parser parser = XML_ParserCreate(NULL);
- if (!parser)
- {
- g_warning("XDXF/%s->%s() Could not open initialize XML parser.\n",__FILE__,__FUNCTION__);
- timer(TIMER_STOP,(gchar*)__FUNCTION__);
- return;
- };
+// header with data structure and function definition for XDXF engine.
+// Also Engine API.
+#include "../include/engine_xdxf.h"
+//------------------------------------------------------------------------------
- gchar tmp[DICT_MAX_WORD_LENGTH];
- XDXFWordsTransData search_data = {tmp, word, word_length, 0, NULL, FALSE, TRUE, 0, &parser, FALSE, data->xdxf};
- XML_SetElementHandler(parser, search_word_trans_start, search_word_trans_end);
- XML_SetCharacterDataHandler(parser, search_word_trans_text);
-
- XML_SetUserData(parser, &search_data);
- gdouble last_prog = 0;
- while(TRUE)
- {
- vfs_result = gnome_vfs_read(data->xdxf, buffer, DICT_SEARCHING_WORD_TRAN_BUFF_SIZE, &bytes_readed);
- XML_Parse(parser, buffer, bytes_readed, bytes_readed < DICT_SEARCHING_WORD_TRAN_BUFF_SIZE);
-
- gdouble last_prog = 0.0;
- if(data->cb_progress_word_trans != NULL)
- {
- GnomeVFSFileSize act_pos;
- gnome_vfs_tell(data->xdxf, &act_pos);
- gdouble progress = ((gdouble)act_pos)/((gdouble)file_size);
- if( (((progress - last_prog)/(data->cb_progress_word_trans_seed)) > 1.0) ||
- (progress >= 1.0))
- {
- data->cb_progress_word_trans(progress, data->cb_progress_word_trans_data, ENGINE_NO_ERROR);
- last_prog = progress;
- };
- }
- if(bytes_readed < DICT_SEARCHING_WORD_TRAN_BUFF_SIZE)
- {
- break;
- }
- if(search_data.cont == FALSE)
- {
- break;
- }
- }
- XML_ParserFree(parser);
- trans = search_data.translation;
- };
- g_debug("XDXF/%s->%s() found for word \'%s\' translation:\n\'%s\'\n",__FILE__,__FUNCTION__,word,trans);
- timer(TIMER_STOP,(gchar*)__FUNCTION__);
- timer(TIMER_START,"callback for returning word's translation START");
- data->cb_search_word_trans(trans, word, data->cb_search_word_trans_data, ENGINE_NO_ERROR);
- timer(TIMER_STOP,"callback for returning word's translation END");
- if(data->auto_free)
- {
- g_debug("XDXF/%s->%s() deleting all dynamic data because AUTO_FREE=TRUE\n",__FILE__,__FUNCTION__);
- g_free(trans);
- }
- trans = NULL;
+// searching word translation in cache file
+static gchar* word_translation_cache(XDXFData* data, gchar* word)
+{
+ gnome_vfs_seek(data->cache, GNOME_VFS_SEEK_START, 0);
+ gchar b[DICT_SEARCHING_WORD_TRAN_BUFF_SIZE + 1];
+ GnomeVFSFileSize bytes_readed;
+
+ guint word_length = strlen(word);
+ guint record_length = 0;
+ guint trans_offset = 0;
+ guint already = 0;
+ guint64 readed = 0;
+ gchar* buffer = NULL;
+ gchar* trans = NULL;
+ guint file_size = get_file_size(data->cache);
+ while(TRUE) {
+ gnome_vfs_read(data->cache,
+ b,
+ DICT_SEARCHING_WORD_TRAN_BUFF_SIZE,
+ &bytes_readed
+ );
+ guint max_length = (guint)get_max_length(b,bytes_readed);
+ readed += max_length;
+ buffer = b;
+ already = 0;
+ while(already < max_length) {
+ memcpy(&record_length, buffer, sizeof(guint));
+ memcpy(&trans_offset,
+ buffer+record_length-2*sizeof(guint),
+ sizeof(guint)
+ );
+ buffer[record_length-sizeof(guint)*2] = '\0';
+ if(((record_length - 3*sizeof(guint)) == word_length) &&
+ (g_utf8_collate(word,buffer+sizeof(guint)) == 0)) {
+ FilePart translation = {0,0};
+ translation.offset = trans_offset;
+ memcpy(&(translation.length),
+ buffer + record_length - sizeof(guint),
+ sizeof(guint)
+ );
+ trans =read_file_part(&translation, data->xdxf);
+ break;
+ };
+ already += record_length;
+ buffer += record_length;
+ };
+
+ if( ( bytes_readed < DICT_SEARCHING_WORD_TRAN_BUFF_SIZE ) ||
+ ( readed > (file_size - 3) )) {
+ break;
+ };
+ gnome_vfs_seek(data->cache,
+ GNOME_VFS_SEEK_CURRENT,
+ ((gint)max_length) -
+ DICT_SEARCHING_WORD_TRAN_BUFF_SIZE
+ );
+ }
+ return trans;
}
-
-static void search_word_trans_start(void *data, const char *el, const char **attr)
+//------------------------------------------------------------------------------
+// searching word translation in xdxf dictionary
+static gchar* word_translation_xdxf(XDXFData* data, gchar* word) {
+ guint word_length = strlen(word);
+ gchar* trans = NULL;
+ gnome_vfs_seek(data->xdxf, GNOME_VFS_SEEK_START, 0);
+ GnomeVFSResult vfs_result;
+ GnomeVFSFileSize bytes_readed = DICT_SEARCHING_WORD_TRAN_BUFF_SIZE;
+ gchar buffer[DICT_SEARCHING_WORD_TRAN_BUFF_SIZE+1];
+ guint64 file_size = get_file_size(data->xdxf);
+ //guint word_len = strlen(word); added by me
+
+ XML_Parser parser = XML_ParserCreate(NULL);
+ if (!parser) {
+ g_warning("XDXF/%s->%s() Could not open initialize "
+ "XML parser.\n",
+ __FILE__,
+ __FUNCTION__
+ );
+ timer(TIMER_STOP,(gchar*)__FUNCTION__);
+ return;
+ };
+
+ gchar tmp[DICT_MAX_WORD_LENGTH];
+ XDXFWordsTransData search_data = {tmp,
+ word,
+ word_length,
+ 0,
+ NULL,
+ FALSE,
+ TRUE,
+ 0,
+ &parser,
+ FALSE,
+ data->xdxf
+ };
+ XML_SetElementHandler(parser,
+ search_word_trans_start,
+ search_word_trans_end
+ );
+ XML_SetCharacterDataHandler(parser, search_word_trans_text);
+
+ XML_SetUserData(parser, &search_data);
+
+ gdouble last_prog = 0;
+ while(TRUE) {
+ vfs_result = gnome_vfs_read(data->xdxf,
+ buffer,
+ DICT_SEARCHING_WORD_TRAN_BUFF_SIZE,
+ &bytes_readed
+ );
+ XML_Parse(parser,
+ buffer,
+ bytes_readed,
+ bytes_readed < DICT_SEARCHING_WORD_TRAN_BUFF_SIZE
+ );
+
+ gdouble last_prog = 0.0;
+ if(data->cb_progress_word_trans != NULL) {
+ GnomeVFSFileSize act_pos;
+ gnome_vfs_tell(data->xdxf, &act_pos);
+ gdouble progress =
+ ((gdouble)act_pos)/((gdouble)file_size);
+ if((( (progress - last_prog)/
+ (data->cb_progress_word_trans_seed) ) > 1.0) ||
+ (progress >= 1.0)) {
+ data->
+ cb_progress_word_trans(progress,
+ data->cb_progress_word_trans_data,
+ ENGINE_NO_ERROR
+ );
+ last_prog = progress;
+ };
+ }
+ if(bytes_readed < DICT_SEARCHING_WORD_TRAN_BUFF_SIZE) {
+ break;
+ }
+ if(search_data.cont == FALSE) {
+ break;
+ }
+ }
+ XML_ParserFree(parser);
+ trans = search_data.translation;
+ return trans;
+}
+//------------------------------------------------------------------------------
+// searching word by concrete engine
+void engine_search_word_translation(Engine* engine, gchar* word)
{
- XDXFWordsTransData* loc_data = (XDXFWordsTransData*)data;
- if((loc_data->translation != NULL) || !(loc_data->cont))
- {
- return;
- };
-
- if(g_utf8_collate(el,"k") == 0)
- {
- loc_data->one_word = 1;
- }
- else if(g_utf8_collate(el,"ar") == 0)
- {
- loc_data->last_start = XML_GetCurrentByteIndex(*(loc_data->parser));
- }
+ g_debug("XDXF/%s->%s() called.\n"
+ "-->PARAM:engine at adress=%p\n"
+ "-->PARAM:word=\'%s\'\n",
+ __FILE__,
+ __FUNCTION__,
+ engine,
+ word);
+ g_assert(engine != NULL);
+ g_assert(word != NULL);
+ // start timer for this function
+ timer(TIMER_START, (gchar*)__FUNCTION__);
+ XDXFData* data = (XDXFData*)(engine->engine_data);
+ // if callback is not set, we do not have to search word
+ if(data->cb_search_word_trans == NULL) {
+ g_warning("XDXF/%s->%s() callback for Word Translation not set."
+ " Searching aborted.\n",
+ __FILE__,
+ __FUNCTION__
+ );
+ timer(TIMER_STOP,(gchar*)__FUNCTION__);
+ // do not send any signal, just exit
+ return;
+ };
+
+ guint word_length = strlen(word);
+ gchar* trans;
+
+ // dictionary is optimized
+ if(data->cache != NULL) {
+ trans = word_translation_cache(data, word);
+ // dictionary is not optimized right now
+ } else
+ {
+ trans = word_translation_xdxf(data, word);
+ };
+
+ g_debug("XDXF/%s->%s() found for word \'%s\' translation:\n\'%s\'\n",
+ __FILE__,
+ __FUNCTION__,
+ word,
+ trans
+ );
+ timer(TIMER_STOP,(gchar*)__FUNCTION__);
+ timer(TIMER_START,"callback for returning word's translation START");
+ // calling callback for word translation
+ data->cb_search_word_trans(trans,
+ word,
+ data->cb_search_word_trans_data,
+ ENGINE_NO_ERROR
+ );
+ timer(TIMER_STOP,"callback for returning word's translation END");
+ if(data->auto_free) {
+ g_debug("XDXF/%s->%s() deleting all dynamic data because "
+ "AUTO_FREE=TRUE\n",
+ __FILE__,
+ __FUNCTION__
+ );
+ g_free(trans);
+ }
+ trans = NULL;
}
-
-static void search_word_trans_end(void *data, const char *el)
+//------------------------------------------------------------------------------
+static void search_word_trans_start(void *data,
+ const char *el,
+ const char **attr
+ )
{
- XDXFWordsTransData* loc_data = (XDXFWordsTransData*)data;
- if((loc_data->translation != NULL) || !(loc_data->cont))
- {
- return;
- };
-
- if(g_utf8_collate(el,"k") == 0)
- {
- loc_data->one_word = 0;
- //gboolean matched = FALSE;
- // checking last found word
-
- //gchar* stra = g_utf8_casefold(loc_data->last_word, -1);
- //gchar* strb = g_utf8_casefold(loc_data->word, -1);
- //guint min = MIN(loc_data->last_word_length, loc_data->word_len);
- //gint com = g_ascii_strncasecmp(loc_data->last_word, loc_data->word, min);
- //added by me
- gint com = g_utf8_collate(loc_data->last_word, loc_data->word);
- if(com > 0)
- {
- g_debug("Przeszlo przez");
- loc_data->cont = FALSE;
- return;
- }
- else if(( loc_data->last_word_length == loc_data->word_len ) &&
- ( com == 0 )
- )
- {
- // matched = TRUE;
- loc_data->found = TRUE;
- };
-
- // "clearing" buffer for next word
- loc_data->last_word_length = 0;
- }
- else if((g_utf8_collate(el,"ar") == 0) && (loc_data->found))
- {
- loc_data->found = FALSE;
- loc_data->cont = FALSE;
- gulong last_stop = (gulong)XML_GetCurrentByteIndex(*(loc_data->parser));
- last_stop += strlen("</ar>");
- FilePart fp = {loc_data->last_start, (last_stop - (loc_data->last_start))};
- loc_data->translation = read_file_part(&fp, loc_data->xdxf);
- }
+ XDXFWordsTransData* loc_data = (XDXFWordsTransData*)data;
+ if((loc_data->translation != NULL) || !(loc_data->cont)) {
+ return;
+ };
+
+ if(g_utf8_collate(el,"k") == 0) {
+ loc_data->one_word = 1;
+ } else if(g_utf8_collate(el,"ar") == 0) {
+ loc_data->last_start =
+ XML_GetCurrentByteIndex(*(loc_data->parser));
+ }
}
-
+//------------------------------------------------------------------------------
+static void search_word_trans_end(void *data, const char *el)
+{
+ XDXFWordsTransData* loc_data = (XDXFWordsTransData*)data;
+ if((loc_data->translation != NULL) || !(loc_data->cont)) {
+ return;
+ };
+
+ if(g_utf8_collate(el,"k") == 0) {
+ loc_data->one_word = 0;
+
+ gint com = g_utf8_collate(loc_data->last_word, loc_data->word);
+ if(com > 0) {
+ loc_data->cont = FALSE;
+ return;
+ } else if((loc_data->last_word_length == loc_data->word_len) &&
+ ( com == 0 )
+ ) {
+ loc_data->found = TRUE;
+ };
+ // "clearing" buffer for next word
+ loc_data->last_word_length = 0;
+ }
+ else if((g_utf8_collate(el,"ar") == 0) && (loc_data->found)) {
+ loc_data->found = FALSE;
+ loc_data->cont = FALSE;
+ gulong last_stop =
+ (gulong)XML_GetCurrentByteIndex(*(loc_data->parser));
+ last_stop += strlen("</ar>");
+ FilePart fp = {loc_data->last_start,
+ (last_stop - (loc_data->last_start))
+ };
+ loc_data->translation = read_file_part(&fp, loc_data->xdxf);
+ }
+}
+//------------------------------------------------------------------------------
static void search_word_trans_text(void *data, const XML_Char *txt, int len)
{
- XDXFWordsTransData* loc_data = (XDXFWordsTransData*)data;
- if((loc_data->translation != NULL) || !(loc_data->cont))
- {
- return;
- };
-
- if(loc_data->one_word == 1)
- {
- memcpy(&(loc_data->last_word[loc_data->last_word_length]), (gchar*)txt, len);
- loc_data->last_word_length += (guint)len;
- loc_data->last_word[loc_data->last_word_length] = '\0';
- };
+ XDXFWordsTransData* loc_data = (XDXFWordsTransData*)data;
+ if((loc_data->translation != NULL) || !(loc_data->cont)) {
+ return;
+ };
+
+ if(loc_data->one_word == 1) {
+ memcpy(&(loc_data->last_word[loc_data->last_word_length]),
+ (gchar*)txt,
+ len
+ );
+ loc_data->last_word_length += (guint)len;
+ loc_data->last_word[loc_data->last_word_length] = '\0';
+ };
}
-
-
-
-
-
+//------------------------------------------------------------------------------
void engine_search_word_translation_extended(Engine* engine, gchar* word)
{
- g_debug("XDXF/%s->%s() called.\n",__FILE__,__FUNCTION__);
+ g_debug("XDXF/%s->%s() called.\n",__FILE__,__FUNCTION__);
}
-
+//------------------------------------------------------------------------------
void engine_set_progress_seed(Engine* engine, gchar* signal, gdouble seed) {
- g_debug("XDXF/%s->%s() called.\n",__FILE__,__FUNCTION__);
- XDXFData* data = (XDXFData*)(engine->engine_data);
- if(g_ascii_strcasecmp(signal,ENGINE_PROGRESS_CACHING) == 0)
- {
- data->cb_progress_caching_seed = seed;
- g_debug("XDXF/%s->%s() sets new seed=%0.2f for for signal \"%s\".\n",__FILE__,__FUNCTION__,seed,signal);
- }
- else
- {
- g_warning("XDXF/%s->%s() unsupported signal for progress: %s.\n",__FILE__,__FUNCTION__, signal);
- };
+ g_debug("XDXF/%s->%s() called.\n",__FILE__,__FUNCTION__);
+ XDXFData* data = (XDXFData*)(engine->engine_data);
+ if(g_ascii_strcasecmp(signal,ENGINE_PROGRESS_OPTIMIZING_SIGNAL) == 0) {
+ data->cb_progress_caching_seed = seed;
+ g_debug("XDXF/%s->%s() sets new seed=%0.2f for for signal "
+ "\"%s\".\n",
+ __FILE__,
+ __FUNCTION__,
+ seed,
+ signal
+ );
+ }
+ else {
+ g_warning("XDXF/%s->%s() unsupported signal"
+ "for progress: %s.\n",
+ __FILE__,
+ __FUNCTION__,
+ signal
+ );
+ };
}
-
-gpointer engine_set_callback(Engine* engine, gchar* signal, gpointer c_handler, gpointer user_data)
+//------------------------------------------------------------------------------
+gpointer engine_set_callback(Engine* engine,
+ gchar* signal,
+ gpointer c_handler,
+ gpointer user_data)
{
- g_debug("XDXF/%s->%s() called.\n",__FILE__,__FUNCTION__);
- XDXFData* data = (XDXFData*)(engine->engine_data);
- if(g_ascii_strcasecmp(signal,ENGINE_PROGRESS_CACHING) == 0)
- {
- gpointer result = data->cb_progress_caching;
- data->cb_progress_caching = c_handler;
- data->cb_progress_caching_data = user_data;
- g_debug("XDXF/%s->%s() sets handler for signal \"%s\".\n",__FILE__,__FUNCTION__,signal);
- g_debug("XDXF/%s->%s() Function at adress = %d.\n",__FILE__,__FUNCTION__,(guint)c_handler);
- g_debug("XDXF/%s->%s() Data at adress = %d.\n",__FILE__,__FUNCTION__,(guint)user_data);
- return result;
- }
- else if(g_ascii_strcasecmp(signal, ENGINE_WORD_LIST_SIGNAL) == 0)
- {
- gpointer result = data->cb_search_word_list;
- data->cb_search_word_list = c_handler;
- data->cb_search_word_list_data = user_data;
- g_debug("XDXF/%s->%s() sets handler for signal \"%s\".\n",__FILE__,__FUNCTION__,signal);
- g_debug("XDXF/%s->%s() Function at adress = %d.\n",__FILE__,__FUNCTION__,(guint)c_handler);
- g_debug("XDXF/%s->%s() Data at adress = %d.\n",__FILE__,__FUNCTION__,(guint)user_data);
- return result;
- }
- else if(g_ascii_strcasecmp(signal, ENGINE_WORD_TRANSLATION_SIGNAL) == 0)
- {
- gpointer result = data->cb_search_word_trans;
- data->cb_search_word_trans = c_handler;
- data->cb_search_word_trans_data = user_data;
- g_debug("XDXF/%s->%s() sets handler for signal \"%s\".\n",__FILE__,__FUNCTION__,signal);
- g_debug("XDXF/%s->%s() Function at adress = %d.\n",__FILE__,__FUNCTION__,(guint)c_handler);
- g_debug("XDXF/%s->%s() Data at adress = %d.\n",__FILE__,__FUNCTION__,(guint)user_data);
- return result;
- }
- else
- {
- g_warning("XDXF/%s->%s() unsupported signal: %s.\n",__FILE__,__FUNCTION__, signal);
- return NULL;
- }
+ g_debug("XDXF/%s->%s() called.\n",__FILE__,__FUNCTION__);
+ g_assert(engine != NULL);
+ g_assert(signal != NULL);
+ g_assert(c_handler != NULL);
+ XDXFData* data = (XDXFData*)(engine->engine_data);
+ if(g_ascii_strcasecmp(signal,ENGINE_PROGRESS_OPTIMIZING_SIGNAL) == 0) {
+ gpointer result = data->cb_progress_caching;
+ data->cb_progress_caching = c_handler;
+ data->cb_progress_caching_data = user_data;
+ g_debug("XDXF/%s->%s() sets handler for signal \"%s\".\n",
+ __FILE__,
+ __FUNCTION__,
+ signal
+ );
+ g_debug("XDXF/%s->%s() Function at adress = %d.\n",
+ __FILE__,
+ __FUNCTION__,
+ (guint)c_handler
+ );
+ g_debug("XDXF/%s->%s() Data at adress = %d.\n",
+ __FILE__,
+ __FUNCTION__,
+ (guint)user_data
+ );
+ return result;
+ }
+ else if(g_ascii_strcasecmp(signal, ENGINE_WORD_LIST_SIGNAL) == 0) {
+ gpointer result = data->cb_search_word_list;
+ data->cb_search_word_list = c_handler;
+ data->cb_search_word_list_data = user_data;
+ g_debug("XDXF/%s->%s() sets handler for signal \"%s\".\n",
+ __FILE__,
+ __FUNCTION__,
+ signal
+ );
+ g_debug("XDXF/%s->%s() Function at adress = %d.\n",
+ __FILE__,
+ __FUNCTION__,
+ (guint)c_handler
+ );
+ g_debug("XDXF/%s->%s() Data at adress = %d.\n",
+ __FILE__,
+ __FUNCTION__,
+ (guint)user_data
+ );
+ return result;
+ }
+ else if(g_ascii_strcasecmp(signal,
+ ENGINE_WORD_TRANSLATION_SIGNAL) == 0) {
+ gpointer result = data->cb_search_word_trans;
+ data->cb_search_word_trans = c_handler;
+ data->cb_search_word_trans_data = user_data;
+ g_debug("XDXF/%s->%s() sets handler for signal \"%s\".\n",
+ __FILE__,
+ __FUNCTION__,
+ signal
+ );
+ g_debug("XDXF/%s->%s() Function at adress = %d.\n",
+ __FILE__,
+ __FUNCTION__,
+ (guint)c_handler
+ );
+ g_debug("XDXF/%s->%s() Data at adress = %d.\n",
+ __FILE__,
+ __FUNCTION__,
+ (guint)user_data
+ );
+ return result;
+ }
+ else {
+ g_warning("XDXF/%s->%s() unsupported signal: %s.\n",
+ __FILE__,
+ __FUNCTION__,
+ signal
+ );
+ return NULL;
+ }
}
-
+//------------------------------------------------------------------------------
void engine_close(Engine* engine)
{
- g_debug("XDXF/%s->%s() called.\n-->PARAM: engine adress=%p\n",__FILE__,__FUNCTION__,engine);
- XDXFData* data = (XDXFData*)(engine->engine_data);
- if(data->cache != NULL)
- {
- gnome_vfs_close(data->cache);
- };
- if(data->xdxf != NULL)
- {
- gnome_vfs_close(data->xdxf);
- };
-
- g_free(data->dict_path);
- g_free(data);
- g_free(engine);
- g_debug("XDXF/%s->%s() engine at adress=%p is deleted.\n",__FILE__,__FUNCTION__,engine);
+ g_debug("XDXF/%s->%s() called.\n-->PARAM: engine adress=%p\n",
+ __FILE__,
+ __FUNCTION__,
+ engine);
+ if(engine == NULL) {
+ g_warning("XDXF/%s->%s() Trying delete not existed engine.\n",
+ __FILE__,
+ __FUNCTION__,
+ engine
+ );
+ return;
+ }
+ XDXFData* data = (XDXFData*)(engine->engine_data);
+ if(data->cache != NULL) {
+ gnome_vfs_close(data->cache);
+ };
+ if(data->xdxf != NULL) {
+ gnome_vfs_close(data->xdxf);
+ };
+
+ g_free(data->dict_path);
+ g_free(data);
+ g_free(engine);
+ g_debug("XDXF/%s->%s() engine at adress=%p is deleted.\n",
+ __FILE__,
+ __FUNCTION__,
+ engine);
}
-
-
-
+//------------------------------------------------------------------------------
gchar* engine_error_message(EngineStatus error)
{
- g_debug("XDXF/%s->%s() called.\n",__FILE__,__FUNCTION__);
- return "Error";
+ g_debug("XDXF/%s->%s() called.\n",__FILE__,__FUNCTION__);
+ return "Error - not yet implemented.";
}
-
-
-
-Engine* engine_create(gchar* location, EngineOptimizationFlag auto_cache, cb_progress progress_handler, gpointer progress_data, gdouble seed)
+//------------------------------------------------------------------------------
+Engine* engine_create(gchar* location,
+ EngineOptimizationFlag auto_cache,
+ cb_progress progress_handler,
+ gpointer progress_data,
+ gdouble seed)
{
- g_debug("XDXF/%s->%s() called.\n-->PARAM:location=\'%s\'\n-->PARAM:auto_cache=%d\n",__FILE__,__FUNCTION__,location,(guint)auto_cache);
- timer(TIMER_START,(gchar*)__FUNCTION__);
- GnomeVFSResult open_result;
-
- if(!gnome_vfs_initialized ()) {
- gnome_vfs_init (); // initialize Gnome-VFS system
- };
-
- gchar* tmp = g_strdup(location);
- string_to_path(&tmp);
-
- Engine* result = (Engine*)g_try_malloc(sizeof(Engine));
- result->engine_location = engine_location;
- result->engine_is_optimized = engine_is_optimized;
- result->engine_optimize = engine_optimize;
- result->engine_search_word_list = engine_search_word_list;
- result->engine_search_word_translation = engine_search_word_translation;
- result->engine_search_word_translation_extended = engine_search_word_translation_extended;
- result->engine_close = engine_close;
- result->engine_error = engine_error;
- result->engine_error_message = engine_error_message;
- result->engine_set_callback = engine_set_callback;
- result->engine_set_progress_seed = engine_set_progress_seed;
- result->engine_set_auto_free = engine_set_auto_free;
-
- XDXFData* data = (XDXFData*)g_try_malloc(sizeof(XDXFData));
- result->engine_data = (gpointer)data;
-
- g_debug("XDXF/%s->%s() opening file...\'%s\'.\n",__FILE__,__FUNCTION__,location);
- gchar* tmp2 = g_strconcat(tmp,"/dict.xdxf",NULL);
- open_result = gnome_vfs_open (&(data->xdxf), tmp2, GNOME_VFS_OPEN_READ);
- g_free(tmp2); tmp2 = NULL;
- if(open_result != GNOME_VFS_OK)
- {
- g_warning("XDXF/%s->%s() opening dictionary file failed due to reason: %s.\n",__FILE__,__FUNCTION__,gnome_vfs_result_to_string(open_result));
- result->engine_data = NULL;
- g_free(data);
- g_free(result);
- result = NULL;
- }
- else
- {
- g_debug("XDXF/%s->%s() opening dictionary file successed.\n",__FILE__,__FUNCTION__);
- data->dict_path = g_strdup(tmp);
- data->cache = NULL;
- data->cb_progress_caching = progress_handler;
- data->cb_progress_caching_data = progress_data;
- data->cb_progress_caching_seed = seed;
- data->cb_progress_word_list = NULL;
- data->cb_progress_word_list_data = NULL;
- data->cb_progress_word_list_seed = 0.01;
- data->cb_progress_word_trans = NULL;
- data->cb_progress_word_trans_data = NULL;
- data->cb_progress_word_trans_seed = 0.01;
-
- data->cb_search_word_list = NULL;
- data->cb_search_word_list_data = NULL;
-
- data->cb_search_word_trans = NULL;
- data->cb_search_word_trans_data = NULL;
-
- data->auto_free = FALSE;
- if(auto_cache != ENGINE_NO)
- {
- if(auto_cache == ENGINE_REFRESH)
- {
- engine_optimize(result);
- }
- else if(auto_cache == ENGINE_CREATE)
- {
- gchar* cache_path = g_strconcat(data->dict_path, "/dict.cache", NULL);
- open_result = gnome_vfs_open (&(data->cache), cache_path, GNOME_VFS_OPEN_READ);
- if(open_result != GNOME_VFS_OK)
- {
- engine_optimize(result);
- };
- g_free(cache_path); cache_path = NULL;
- }
- };
- }
- g_free(tmp); tmp = NULL;
-
- timer(TIMER_STOP,(gchar*)__FUNCTION__);
- g_debug("XDXF/%s->%s() returned Engine at adress=%p\n",__FILE__,__FUNCTION__,result);
- return result;
-}
-
-
-
-
-// moddificate xml to html page "in situ"
-static void preformat_XML_to_HTML(gchar** xml)
-{
- gchar* arg = xml[0];
- guint xml_len = strlen(arg);
- gchar* result = NULL;
-
+ g_debug("XDXF/%s->%s() called.\n"
+ "-->PARAM:location=\'%s\'\n"
+ "-->PARAM:auto_cache=%d\n",
+ __FILE__,
+ __FUNCTION__,
+ location,
+ (guint)auto_cache
+ );
+ timer(TIMER_START,(gchar*)__FUNCTION__);
+ GnomeVFSResult open_result;
+
+ if(!gnome_vfs_initialized ()) {
+ gnome_vfs_init ();
+ };
+
+ gchar* tmp = g_strdup(location);
+ string_to_path(&tmp);
+
+ Engine* result = (Engine*)g_try_malloc(sizeof(Engine));
+ result->engine_location = engine_location;
+ result->engine_is_optimized = engine_is_optimized;
+ result->engine_optimize = engine_optimize;
+ result->engine_search_word_list = engine_search_word_list;
+ result->engine_search_word_translation =
+ engine_search_word_translation;
+ result->engine_search_word_translation_extended =
+ engine_search_word_translation_extended;
+ result->engine_close = engine_close;
+ result->engine_error = engine_error;
+ result->engine_error_message = engine_error_message;
+ result->engine_set_callback = engine_set_callback;
+ result->engine_set_progress_seed = engine_set_progress_seed;
+ result->engine_set_auto_free = engine_set_auto_free;
+
+ XDXFData* data = (XDXFData*)g_try_malloc(sizeof(XDXFData));
+ result->engine_data = (gpointer)data;
+
+ g_debug("XDXF/%s->%s() opening file...\'%s\'.\n",
+ __FILE__,
+ __FUNCTION__,
+ location
+ );
+ gchar* tmp2 = g_strconcat(tmp,"/dict.xdxf",NULL);
+ open_result =
+ gnome_vfs_open (&(data->xdxf), tmp2, GNOME_VFS_OPEN_READ);
+ g_free(tmp2); tmp2 = NULL;
+
+ if(open_result != GNOME_VFS_OK) {
+ g_warning("XDXF/%s->%s() opening dictionary file failed"
+ " due to reason: %s.\n",
+ __FILE__,
+ __FUNCTION__,
+ gnome_vfs_result_to_string(open_result)
+ );
+ result->engine_data = NULL;
+ g_free(data);
+ g_free(result);
+ result = NULL;
+ }
+ else {
+ g_debug("XDXF/%s->%s() opening dictionary file successed.\n",
+ __FILE__,
+ __FUNCTION__
+ );
+ data->dict_path = g_strdup(tmp);
+ data->cache = NULL;
+ data->cb_progress_caching = progress_handler;
+ data->cb_progress_caching_data = progress_data;
+ data->cb_progress_caching_seed = seed;
+ data->cb_progress_word_list = NULL;
+ data->cb_progress_word_list_data = NULL;
+ data->cb_progress_word_list_seed = 0.01;
+ data->cb_progress_word_trans = NULL;
+ data->cb_progress_word_trans_data = NULL;
+ data->cb_progress_word_trans_seed = 0.01;
+
+ data->cb_search_word_list = NULL;
+ data->cb_search_word_list_data = NULL;
+
+ data->cb_search_word_trans = NULL;
+ data->cb_search_word_trans_data = NULL;
+
+ data->auto_free = FALSE;
+ if(auto_cache != ENGINE_NO) {
+ if(auto_cache == ENGINE_REFRESH) {
+ engine_optimize(result);
+ }
+ else if(auto_cache == ENGINE_CREATE) {
+ gchar* cache_path = g_strconcat(data->dict_path,
+ "/dict.cache",
+ NULL);
+ open_result =
+ gnome_vfs_open (&(data->cache),
+ cache_path,
+ GNOME_VFS_OPEN_READ
+ );
+ if(open_result != GNOME_VFS_OK) {
+ engine_optimize(result);
+ };
+ g_free(cache_path); cache_path = NULL;
+ }
+ };
+ }
+ g_free(tmp); tmp = NULL;
+
+ timer(TIMER_STOP,(gchar*)__FUNCTION__);
+ g_debug("XDXF/%s->%s() returned Engine at adress=%p\n",
+ __FILE__,
+ __FUNCTION__,
+ result
+ );
+ return result;
}
-
-
+//------------------------------------------------------------------------------
EngineModule engine_global_functions()
{
- g_debug("XDXF/%s->%s() called.\n",__FILE__,__FUNCTION__);
- EngineModule result;
- result.engine_check = engine_check;
- result.engine_description = engine_description;
- result.engine_format = engine_format;
- result.engine_version = engine_version;
- result.engine_create = engine_create;
- g_debug("XDXF/%s->%s() returned EngineModule at adress=%p.\n",__FILE__,__FUNCTION__,&result);
- return result;
+ g_debug("XDXF/%s->%s() called.\n",__FILE__,__FUNCTION__);
+ EngineModule result;
+ result.engine_check = engine_check;
+ result.engine_description = engine_description;
+ result.engine_format = engine_format;
+ result.engine_version = engine_version;
+ result.engine_create = engine_create;
+ g_debug("XDXF/%s->%s() returned EngineModule at adress=%p.\n",
+ __FILE__,
+ __FUNCTION__,
+ &result
+ );
+ return result;
}
-
+//------------------------------------------------------------------------------
static double timer(gboolean start, gchar* message)
{
- static GArray* stack = NULL;
- static gboolean first_run = TRUE;
- static struct timeval actual_time;
- static struct timeval last_time;
- static struct timeval result;
- static double seconds = 0.0;
- if(first_run)
- {
- first_run = FALSE;
- //g_debug("XDXF->%s() - TOP OF THE STACK!\n",__FUNCTION__);
- stack = g_array_new(TRUE, TRUE, sizeof(struct timeval));
- };
-
- if (start) // things to do on the beggining of function's work
- {
- g_debug("XDXF->%s() start counting time for function '%s()'.\n",__FUNCTION__,message);
- g_array_prepend_val(stack, actual_time);
- gettimeofday(&g_array_index(stack, struct timeval, 0),NULL);
- return -1.0;
- }
- else { // we just want to end some timer - print some information about working time;
- gettimeofday(&actual_time,NULL);
- last_time = g_array_index(stack, struct timeval, 0);
- g_array_remove_index(stack, 0);
-
- if (actual_time.tv_usec < last_time.tv_usec) {
- int nsec = (last_time.tv_usec - actual_time.tv_usec) / 1000000 + 1;
- last_time.tv_usec -= 1000000 * nsec;
- last_time.tv_sec += nsec;
- }
- if (actual_time.tv_usec - last_time.tv_usec > 1000000) {
- int nsec = (last_time.tv_usec - actual_time.tv_usec) / 1000000;
- last_time.tv_usec += 1000000 * nsec;
- last_time.tv_sec -= nsec;
- }
- result.tv_sec = actual_time.tv_sec - last_time.tv_sec;
- result.tv_usec = actual_time.tv_usec - last_time.tv_usec;
- seconds = (((double)(result.tv_usec)) / 1e6) + ((double)(result.tv_sec));
-
- g_debug("XDXF->%s() function \'%s()\' was working for: %g [s] or %ld [us].\n",__FUNCTION__,message,seconds,((long)(result.tv_sec*1e6)+(result.tv_usec)));
- if(stack->len == 0) // stack is empty so we delete everything
- {
- g_array_free(stack, TRUE);
- first_run = TRUE;
- }
- return seconds;
- }
- return -2.0;
+ static GArray* stack = NULL;
+ static gboolean first_run = TRUE;
+ static struct timeval actual_time;
+ static struct timeval last_time;
+ static struct timeval result;
+ static double seconds = 0.0;
+ if(first_run) {
+ first_run = FALSE;
+ stack = g_array_new(TRUE, TRUE, sizeof(struct timeval));
+ };
+
+ if (start) {
+ g_debug("XDXF->%s() start counting time for function '%s()'.\n",
+ __FUNCTION__,
+ message
+ );
+ g_array_prepend_val(stack, actual_time);
+ gettimeofday(&g_array_index(stack, struct timeval, 0),NULL);
+ return -1.0;
+ }
+ // we just want to end some timer - print some information about
+ // working time;
+ else {
+ gettimeofday(&actual_time,NULL);
+ last_time = g_array_index(stack, struct timeval, 0);
+ g_array_remove_index(stack, 0);
+
+ if (actual_time.tv_usec < last_time.tv_usec) {
+ int nsec = (last_time.tv_usec - actual_time.tv_usec) /
+ (1000000 + 1);
+ last_time.tv_usec -= 1000000 * nsec;
+ last_time.tv_sec += nsec;
+ }
+ if (actual_time.tv_usec - last_time.tv_usec > 1000000) {
+ int nsec = (last_time.tv_usec - actual_time.tv_usec) /
+ 1000000;
+ last_time.tv_usec += 1000000 * nsec;
+ last_time.tv_sec -= nsec;
+ }
+ result.tv_sec = actual_time.tv_sec - last_time.tv_sec;
+ result.tv_usec = actual_time.tv_usec - last_time.tv_usec;
+ seconds = (((double)(result.tv_usec)) / 1e6) +
+ ((double)(result.tv_sec));
+
+ g_debug("XDXF->%s() function \'%s()\' was working for: %g [s] "
+ "or %ld [us].\n",
+ __FUNCTION__,
+ message,
+ seconds,
+ ((long)(result.tv_sec*1e6)+(result.tv_usec))
+ );
+ // stack is empty so we delete everything
+ if(stack->len == 0)
+ {
+ g_array_free(stack, TRUE);
+ first_run = TRUE;
+ }
+ }
+ return seconds;
}
-/**
-*
-*/
+//------------------------------------------------------------------------------
static gchar* read_file_part(FilePart* part, GnomeVFSHandle* file)
{
- g_debug("XDXF/%s->%s() called.\n",__FILE__,__FUNCTION__);
- timer(TIMER_START,(gchar*)__FUNCTION__);
- gchar* result = NULL;
- GnomeVFSResult f_result;
- GnomeVFSFileSize bytes_read;
-
- f_result = gnome_vfs_seek(file, GNOME_VFS_SEEK_START, part->offset);
- if(f_result != GNOME_VFS_OK)
- {
- g_warning("XDXF/%s->%s() failed. Not possible to seek through file!\n",__FILE__,__FUNCTION__);
- timer(TIMER_STOP,(gchar*)__FUNCTION__);
- return result;
-
- };
- result = g_try_malloc((part->length + 1) * sizeof(gchar));
- if(result == NULL)
- {
- g_warning("XDXF/%s->%s() failed. Not possible to allocata so big memmory chunk!\n",__FILE__,__FUNCTION__);
- timer(TIMER_STOP,(gchar*)__FUNCTION__);
- return result;
- };
- f_result = gnome_vfs_read (file, result, part->length, &bytes_read);
- if((f_result != GNOME_VFS_OK) ||
- (((gulong)bytes_read) != part->length))
- {
- g_debug("XDXF/%s->%s() failed. Not possible to read from file!\n",__FILE__,__FUNCTION__);
- timer(TIMER_STOP,(gchar*)__FUNCTION__);
- g_free(result); result = NULL;
- return result;
- };
- result[part->length] = '\0';
-
- g_debug("XDXF/%s->%s() returned string=\n\'%s\'.\n",__FILE__,__FUNCTION__,result);
- timer(TIMER_STOP,(gchar*)__FUNCTION__);
-
- return result;
+ g_debug("XDXF/%s->%s() called.\n",__FILE__,__FUNCTION__);
+ timer(TIMER_START,(gchar*)__FUNCTION__);
+ gchar* result = NULL;
+ GnomeVFSResult f_result;
+ GnomeVFSFileSize bytes_read;
+
+ f_result = gnome_vfs_seek(file, GNOME_VFS_SEEK_START, part->offset);
+ if(f_result != GNOME_VFS_OK) {
+ g_warning("XDXF/%s->%s() failed. Not possible to seek "
+ "through file!\n",
+ __FILE__,
+ __FUNCTION__
+ );
+ timer(TIMER_STOP,(gchar*)__FUNCTION__);
+ return result;
+
+ };
+ result = g_try_malloc((part->length + 1) * sizeof(gchar));
+ if(result == NULL) {
+ g_warning("XDXF/%s->%s() failed. Not possible to allocate "
+ "so big memmory chunk!\n",
+ __FILE__,
+ __FUNCTION__
+ );
+ timer(TIMER_STOP,(gchar*)__FUNCTION__);
+ return result;
+ };
+ f_result = gnome_vfs_read (file, result, part->length, &bytes_read);
+ if((f_result != GNOME_VFS_OK) ||
+ (((gulong)bytes_read) != part->length)) {
+ g_debug("XDXF/%s->%s() failed. Not possible to read from "
+ "file!\n",
+ __FILE__,
+ __FUNCTION__
+ );
+ timer(TIMER_STOP,(gchar*)__FUNCTION__);
+ g_free(result); result = NULL;
+ return result;
+ };
+ result[part->length] = '\0';
+
+ g_debug("XDXF/%s->%s() returned string=\n\'%s\'.\n",
+ __FILE__,
+ __FUNCTION__,
+ result
+ );
+ timer(TIMER_STOP,(gchar*)__FUNCTION__);
+ return result;
}
-
-/** 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.
-* @param string :: <b><i>gchar**</i></b> - pointer to pointer 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 (ZELEZNE WZGLEDEM AKTUALNEGO KATALOGU)
-* @return <b><i>gchar*</i></b> - pointer to new full file path, it is the same as string[0] in fact and it is returned only for
-* abillity of nesting of functions
-* by pointer to string identyfying full file path
-* @todo tranlsate some miising text.
+//------------------------------------------------------------------------------
+/** 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.
+*
+* @param string :: <b><i>gchar**</i></b> - pointer to pointer 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
+* @return <b><i>gchar*</i></b> - pointer to new full file path, it is the same
+* as string[0] in fact and it is returned only for abillity of nesting of
+* functions by pointer to string identyfying full file path
*/
static gchar* string_to_path(gchar** string) {
- g_debug("XDXF/%s->%s() called.\n-->PARAM:string=\'%s\'\n",__FILE__,__FUNCTION__,string[0]);
- gchar* arg = string[0];
- gchar* new = NULL;
- g_strstrip(arg); // cleaning from leading and trailing whitespaces
-
- if (!g_path_is_absolute(arg)) // add current directory if this is not absolute directory
- {
- gchar* tmp = g_get_current_dir();
- new = g_strconcat(tmp,"/",arg,NULL);
- g_free(arg); arg = new; new = NULL;
- };
-
- if (!g_file_test(arg, G_FILE_TEST_IS_DIR))
- { // this is not a directory
- if (!g_file_test(arg, G_FILE_TEST_IS_REGULAR))
- { // if this is wrong filepath, string was wrong
- g_free(arg);
- new = NULL;
- }
- else
- { //if this is a file, remove filename
- new = g_path_get_dirname (arg);
- g_free(arg);
- }
- }
- else // if arg == G_FILE_TEST_IS_DIR
- { // this is a directory
- if (g_str_has_suffix(arg,"/") )
- { // remove suffix "/" if neded...
- new = g_path_get_dirname (arg);
- g_free(arg);
- }
- else
- { //... if not just leave it as it is
- new = arg;
- }
- }; // if arg == G_FILE_TEST_IS_DIR
-
- // now in new should be proper filepath, if not, string was wrong
- if (!g_file_test(new, G_FILE_TEST_IS_DIR))
- { // if that directory does not exist, passed string was not proper
- g_free(new);
- new = NULL;
- };
-
- string[0] = new;
- g_debug("XDXF/%s->%s() returned string=\'%s\'\n",__FILE__,__FUNCTION__,string[0]);
- return new;
+ g_debug("XDXF/%s->%s() called.\n\
+ -->PARAM:string=\'%s\'\n",
+ __FILE__,
+ __FUNCTION__,
+ string[0]
+ );
+ gchar* arg = string[0];
+ gchar* new = NULL;
+ // cleaning from leading and trailing whitespaces
+ g_strstrip(arg);
+ // add current directory if this is not absolute directory
+ if (!g_path_is_absolute(arg)) {
+ gchar* tmp = g_get_current_dir();
+ new = g_strconcat(tmp,"/",arg,NULL);
+ g_free(arg); arg = new; new = NULL;
+ };
+ // this is not a directory
+ if (!g_file_test(arg, G_FILE_TEST_IS_DIR)) {
+ // if this is wrong filepath, string was wrong
+ if (!g_file_test(arg, G_FILE_TEST_IS_REGULAR)) {
+ g_free(arg);
+ new = NULL;
+ }
+ //if this is a file, remove filename
+ else
+ {
+ new = g_path_get_dirname (arg);
+ g_free(arg);
+ }
+ }
+ // this is a directory
+ else {
+ // remove suffix "/" if neded...
+ if (g_str_has_suffix(arg,"/") ) {
+ new = g_path_get_dirname (arg);
+ g_free(arg);
+ }
+ else {
+ new = arg;
+ }
+ };
+ // now in new should be proper filepath, if not, string was wrong
+ if (!g_file_test(new, G_FILE_TEST_IS_DIR)) {
+ // if that directory does not exist, passed string wasn't proper
+ g_free(new);
+ new = NULL;
+ };
+ // replace string under passed address
+ string[0] = new;
+ g_debug("XDXF/%s->%s() returned string=\'%s\'\n",
+ __FILE__,
+ __FUNCTION__,
+ string[0]
+ );
+ return new;
}
-
+//------------------------------------------------------------------------------
static gboolean is_xdxf_file(gchar* file) {
- g_debug("XDXF/%s->%s() called.\n-->PARAM:file=\'%s\'\n",__FILE__,__FUNCTION__,file);
- gboolean result = TRUE;
- GnomeVFSHandle* fd = NULL;
- GnomeVFSResult file_result;
- GnomeVFSFileSize bytes_read;
-
- if(!gnome_vfs_initialized ()) {
- gnome_vfs_init (); // initialize Gnome-VFS system
- };
-
- file_result = gnome_vfs_open (&fd, file, GNOME_VFS_OPEN_READ);
- if(file_result != GNOME_VFS_OK)
- {
- g_warning("XDXF/%s->%s() Could not open the file.\n",__FILE__,__FUNCTION__);
- return FALSE;
- };
-
- XML_Parser p = XML_ParserCreate(NULL);
- if (!p)
- {
- g_warning("XDXF/%s->%s() Could not open initialize XML parser.\n",__FILE__,__FUNCTION__);
- gnome_vfs_close(fd);
- return FALSE;
- };
- XML_SetElementHandler(p, is_xdxf_file_start, is_xdxf_file_end);
- XDXFCheckingData user_data = {TRUE, FALSE, 0};
- XML_SetUserData(p, &user_data);
- gchar buffer[DICT_CACHEING_BUFF_SIZE];
-
- guint loop_count = 0;
- while(TRUE)
- {
- file_result = gnome_vfs_read (fd, buffer, DICT_CACHEING_BUFF_SIZE, &bytes_read);
- if (file_result != GNOME_VFS_OK)
- {
- result = FALSE;
- g_warning("XDXF/%s->%s() Could not read enought from file.\n",__FILE__,__FUNCTION__);
- break;
- };
-
- if (! XML_Parse(p, buffer, (gulong)bytes_read, ((gulong)bytes_read) < DICT_CACHEING_BUFF_SIZE) )
- {
- result = FALSE;
- g_warning("XDXF/%s->%s() Could not parse file.\n",__FILE__,__FUNCTION__);
- break;
- };
-
- if (user_data.further == FALSE)
- {
- result = user_data.good;
- g_debug("XDXF/%s->%s() statement: location is compatible with this module, is %s\n",__FILE__,__FUNCTION__,(result)?"TRUE":"FALSE");
- break;
- };
-
- if (loop_count > 1)
- {
- result = FALSE;
- g_debug("XDXF/%s->%s() Wrong file format.\n",__FILE__,__FUNCTION__);
- break;
- };
- loop_count++;
- }
-
- gnome_vfs_close(fd);
- XML_ParserFree(p);
- g_debug("XDXF/%s->%s() returned bool statement=%s.\n",__FILE__,__FUNCTION__,(result?"TRUE":"FALSE"));
- return result;
+ g_debug("XDXF/%s->%s() called.\n\
+ -->PARAM:file=\'%s\'\n",
+ __FILE__,
+ __FUNCTION__,
+ file
+ );
+ gboolean result = TRUE;
+ GnomeVFSHandle* fd = NULL;
+ GnomeVFSResult file_result;
+ GnomeVFSFileSize bytes_read;
+
+ if(!gnome_vfs_initialized ()) {
+ gnome_vfs_init ();
+ };
+
+ file_result = gnome_vfs_open (&fd, file, GNOME_VFS_OPEN_READ);
+ if(file_result != GNOME_VFS_OK) {
+ g_warning("XDXF/%s->%s() Could not open the file.\n",
+ __FILE__,
+ __FUNCTION__
+ );
+ return FALSE;
+ };
+
+ XML_Parser p = XML_ParserCreate(NULL);
+ if (!p) {
+ g_warning("XDXF/%s->%s() Could not open initialize "
+ "XML parser.\n",
+ __FILE__,
+ __FUNCTION__
+ );
+ gnome_vfs_close(fd);
+ return FALSE;
+ };
+ XML_SetElementHandler(p, is_xdxf_file_start, is_xdxf_file_end);
+ XDXFCheckingData user_data = {TRUE, FALSE, 0};
+ XML_SetUserData(p, &user_data);
+ gchar buffer[DICT_CACHEING_BUFF_SIZE];
+
+ guint loop_count = 0;
+ while(TRUE) {
+ file_result = gnome_vfs_read (fd,
+ buffer,
+ DICT_CACHEING_BUFF_SIZE,
+ &bytes_read
+ );
+ if (file_result != GNOME_VFS_OK) {
+ result = FALSE;
+ g_warning("XDXF/%s->%s() Could not read enought from"
+ " file.\n",
+ __FILE__,
+ __FUNCTION__
+ );
+ break;
+ };
+ if (! XML_Parse(p,
+ buffer,
+ (gulong)bytes_read,
+ ((gulong)bytes_read) < DICT_CACHEING_BUFF_SIZE
+ ) ) {
+ result = FALSE;
+ g_warning("XDXF/%s->%s() Could not parse file.\n",
+ __FILE__,
+ __FUNCTION__
+ );
+ break;
+ };
+ if (user_data.further == FALSE) {
+ result = user_data.good;
+ g_debug("XDXF/%s->%s() statement: location is "
+ "compatible with this module, is %s\n",
+ __FILE__,
+ __FUNCTION__,
+ PRINT_STATE(result)
+ );
+ break;
+ };
+ if (loop_count > 1) {
+ result = FALSE;
+ g_debug("XDXF/%s->%s() Wrong file format.\n",
+ __FILE__,
+ __FUNCTION__
+ );
+ break;
+ };
+ loop_count++;
+ }
+
+ gnome_vfs_close(fd);
+ XML_ParserFree(p);
+ g_debug("XDXF/%s->%s() returned bool statement=%s.\n",
+ __FILE__,
+ __FUNCTION__,
+ PRINT_STATE(result)
+ );
+ return result;
}
-
+//------------------------------------------------------------------------------
static void is_xdxf_file_start(void *data, const char *el, const char **attr)
{
- XDXFCheckingData* user_data = (XDXFCheckingData*)data;
- if (user_data->deep == 0)
- {
- if (g_utf8_collate (el,"xdxf") != 0)
- {
- user_data->good = FALSE;
- }
- else
- {
- user_data->good = TRUE;
- }
- user_data->further = FALSE;
- }
- user_data->deep++;
+ XDXFCheckingData* user_data = (XDXFCheckingData*)data;
+ if (user_data->deep == 0) {
+ if (g_utf8_collate (el,"xdxf") != 0) {
+ user_data->good = FALSE;
+ }
+ else {
+ user_data->good = TRUE;
+ }
+ user_data->further = FALSE;
+ }
+ user_data->deep++;
}
-
-
+//------------------------------------------------------------------------------
static void is_xdxf_file_end(void *data, const char *el)
{
+ // clear as far as in this callback is nothing to do
}
-
-
-
+//------------------------------------------------------------------------------
EngineStatus engine_error(Engine* engine)
{
- g_debug("XDXF/%s->%s() called.\n",__FILE__,__FUNCTION__);
- XDXFData* data = (XDXFData*)(engine->engine_data);
- g_debug("XDXF/%s->%s() returned error code: %d\n",__FILE__,__FUNCTION__,(gint)(data->last_error));
- return data->last_error;
+ g_debug("XDXF/%s->%s() called.\n",__FILE__,__FUNCTION__);
+ XDXFData* data = (XDXFData*)(engine->engine_data);
+ g_debug("XDXF/%s->%s() returned error code: %d\n",
+ __FILE__,
+ __FUNCTION__,
+ (gint)(data->last_error)
+ );
+ return data->last_error;
}
-
-
+//------------------------------------------------------------------------------
static void caching_expat_start(void *data, const char *el, const char **attr) {
- XDXFCacheData* loc_data = (XDXFCacheData*)data;
- if(g_utf8_collate(el,"ar") == 0)
- {
- loc_data->last_start = XML_GetCurrentByteIndex(loc_data->parser);
- }
- else if(g_utf8_collate(el,"k") == 0)
- {
- loc_data->state = 1;
- }
- else
- {
- loc_data->state = 0;
- }
+ XDXFCacheData* loc_data = (XDXFCacheData*)data;
+ if(g_utf8_collate(el,"ar") == 0) {
+ loc_data->last_start =
+ XML_GetCurrentByteIndex(loc_data->parser);
+ }
+ else if(g_utf8_collate(el,"k") == 0) {
+ loc_data->state = 1;
+ }
+ else {
+ loc_data->state = 0;
+ }
}
-
+//------------------------------------------------------------------------------
static void caching_expat_end(void *data, const char *el) {
- XDXFCacheData* loc_data = (XDXFCacheData*)data;
- loc_data->last_stop = XML_GetCurrentByteIndex(loc_data->parser);
-
- static guint record_length;
- static guint start;
- static guint length;
- static guint buffer_length;
-
- if( (g_utf8_collate("k",el) == 0) &&
- (loc_data->state == 1))
- {
- loc_data->state = 2;
- }
- else if((g_utf8_collate("ar",el) == 0) &&
- (loc_data->state == 2))
- {
- buffer_length = loc_data->buffer_length;
- record_length = sizeof(guint)*3 + loc_data->buffer_length;
- start = loc_data->last_start;
- length = loc_data->last_stop + strlen("</ar>") - loc_data->last_start;
-
- gboolean error_writting = FALSE;
- GnomeVFSFileSize bytes_written;
- GnomeVFSResult vfs_result;
- vfs_result = gnome_vfs_write(loc_data->cache, &record_length, sizeof(guint), &bytes_written);
- if(vfs_result != GNOME_VFS_OK) error_writting = TRUE;
- vfs_result = gnome_vfs_write(loc_data->cache, loc_data->buffer, loc_data->buffer_length, &bytes_written);
- if(vfs_result != GNOME_VFS_OK) error_writting = TRUE;
- vfs_result = gnome_vfs_write(loc_data->cache, &start, sizeof(guint), &bytes_written);
- if(vfs_result != GNOME_VFS_OK) error_writting = TRUE;
- vfs_result = gnome_vfs_write(loc_data->cache, &length, sizeof(guint), &bytes_written);
- if(vfs_result != GNOME_VFS_OK) error_writting = TRUE;
-
- loc_data->buffer[0] = '\0';
- loc_data->buffer_length = 0;
- loc_data->state = 0;
- };
+ XDXFCacheData* loc_data = (XDXFCacheData*)data;
+ loc_data->last_stop = XML_GetCurrentByteIndex(loc_data->parser);
+
+ static guint record_length;
+ static guint start;
+ static guint length;
+ static guint buffer_length;
+
+ if((g_utf8_collate("k",el) == 0) &&
+ (loc_data->state == 1)) {
+ loc_data->state = 2;
+ }
+ else if((g_utf8_collate("ar",el) == 0) &&
+ (loc_data->state == 2)) {
+ buffer_length = loc_data->buffer_length;
+ record_length = sizeof(guint)*3 + loc_data->buffer_length;
+ start = loc_data->last_start;
+ length = loc_data->last_stop + strlen("</ar>") -
+ loc_data->last_start;
+
+ gboolean error_writting = FALSE;
+ GnomeVFSFileSize bytes_written;
+ GnomeVFSResult vfs_result;
+ vfs_result = gnome_vfs_write(loc_data->cache,
+ &record_length,
+ sizeof(guint),
+ &bytes_written
+ );
+ if(vfs_result != GNOME_VFS_OK) error_writting = TRUE;
+ vfs_result = gnome_vfs_write(loc_data->cache,
+ loc_data->buffer,
+ loc_data->buffer_length,
+ &bytes_written
+ );
+ if(vfs_result != GNOME_VFS_OK) error_writting = TRUE;
+ vfs_result = gnome_vfs_write(loc_data->cache,
+ &start,
+ sizeof(guint),
+ &bytes_written
+ );
+ if(vfs_result != GNOME_VFS_OK) error_writting = TRUE;
+ vfs_result = gnome_vfs_write(loc_data->cache,
+ &length,
+ sizeof(guint),
+ &bytes_written
+ );
+ if(vfs_result != GNOME_VFS_OK) error_writting = TRUE;
+
+ loc_data->buffer[0] = '\0';
+ loc_data->buffer_length = 0;
+ loc_data->state = 0;
+ };
}
-
+//------------------------------------------------------------------------------
static void caching_expat_text(void *data, const XML_Char *txt, int len) {
- XDXFCacheData* loc_data = (XDXFCacheData*)data;
-
- if(loc_data->state == 1)
- {
- memcpy(&(loc_data->buffer[loc_data->buffer_length]), (gchar*)txt, len);
- loc_data->buffer_length += (long)len;
- loc_data->buffer[loc_data->buffer_length] = '\0';
- };
+ XDXFCacheData* loc_data = (XDXFCacheData*)data;
+
+ if(loc_data->state == 1) {
+ memcpy(&(loc_data->buffer[loc_data->buffer_length]),
+ (gchar*)txt,
+ len
+ );
+ loc_data->buffer_length += (long)len;
+ loc_data->buffer[loc_data->buffer_length] = '\0';
+ };
}
-
+//------------------------------------------------------------------------------
static guint64 get_file_size(GnomeVFSHandle* file)
{
- guint64 result = 0;
- guint64 old_pos = 0;
- gnome_vfs_tell(file, &old_pos);
-
- if( gnome_vfs_seek(file, GNOME_VFS_SEEK_END, 0) != GNOME_VFS_OK)
- return 0;
-
- if( gnome_vfs_tell(file, &result) != GNOME_VFS_OK)
- result = 0;
-
- gnome_vfs_seek(file, GNOME_VFS_SEEK_START, old_pos);
- return result;
+ guint64 result = 0;
+ guint64 old_pos = 0;
+ gnome_vfs_tell(file, &old_pos);
+
+ if( gnome_vfs_seek(file, GNOME_VFS_SEEK_END, 0) != GNOME_VFS_OK) {
+ return 0;
+ }
+
+ if( gnome_vfs_tell(file, &result) != GNOME_VFS_OK) {
+ result = 0;
+ }
+
+ gnome_vfs_seek(file, GNOME_VFS_SEEK_START, old_pos);
+ return result;
}
-
-
-
+//------------------------------------------------------------------------------
void engine_optimize(Engine* engine)
{
- g_debug("XDXF/%s->%s() called for engine at adress=%p\n",__FILE__,__FUNCTION__,engine);
- timer(TIMER_START,(gchar*)__FUNCTION__);
-
- GnomeVFSResult vfs_result;
- XDXFData* data = (XDXFData*)(engine->engine_data);
- gchar* cache_path = g_strconcat(data->dict_path,"/dict.cache",NULL);
- vfs_result = gnome_vfs_create(&(data->cache), cache_path, GNOME_VFS_OPEN_WRITE, FALSE, 0666);
- if(vfs_result != GNOME_VFS_OK)
- {
- data->cache = NULL;
- g_warning("XDXF/%s->%s(). Could not create new cache file.\n",__FILE__,__FUNCTION__);
- g_warning("XDXF/%s->%s(). Cache file: %s.\n",__FILE__,__FUNCTION__,cache_path);
- }
- else
- {
- XDXFCacheData* c_data = (XDXFCacheData*)g_try_malloc(sizeof(XDXFCacheData));
- c_data->parser = XML_ParserCreate(NULL);
- c_data->cache = data->cache;
- c_data->buffer = (gchar*)g_try_malloc(sizeof(gchar)*DICT_CACHEING_BUFF_SIZE);
- c_data->buffer_length = 0;
- c_data->last_start = c_data->last_stop = c_data->last_length = 0;
-
- guint64 file_size = get_file_size(data->xdxf);
- g_debug("XDXF/%s->%s(): caching dictionaries size is %.2f kB [%d bytes = %.2f MB].\n",__FILE__,__FUNCTION__,((gdouble)file_size)/1024.0,file_size,((gdouble)file_size)/(1024.0*1024.0));
-
- XML_SetUserData(c_data->parser, (gpointer)c_data);
- XML_SetElementHandler(c_data->parser, caching_expat_start, caching_expat_end);
- XML_SetCharacterDataHandler(c_data->parser, caching_expat_text);
-
- GnomeVFSFileSize bytes_readed = DICT_CACHEING_BUFF_SIZE;
- gchar b[DICT_CACHEING_BUFF_SIZE + 1];
- gdouble last_prog = 0;
- while(TRUE)
- {
- vfs_result = gnome_vfs_read(data->xdxf, b, DICT_CACHEING_BUFF_SIZE, &bytes_readed);
- XML_Parse(c_data->parser, b, bytes_readed, bytes_readed < DICT_CACHEING_BUFF_SIZE);
-
- if(data->cb_progress_caching != NULL)
- {
- GnomeVFSFileSize act_pos;
- gnome_vfs_tell(data->xdxf, &act_pos);
- gdouble progress = ((gdouble)act_pos)/((gdouble)file_size);
- if( (((progress - last_prog)/(data->cb_progress_caching_seed)) > 1.0) ||
- (progress >= 1.0))
- {
- data->cb_progress_caching(progress, data->cb_progress_caching_data, ENGINE_NO_ERROR);
- last_prog = progress;
- };
- }
- if(bytes_readed < DICT_CACHEING_BUFF_SIZE) break;
- }
-
- g_free(c_data->buffer);
- g_free(c_data);
- }
-
- vfs_result = gnome_vfs_close(data->cache);
- vfs_result = gnome_vfs_open(&(data->cache), cache_path, GNOME_VFS_OPEN_READ);
- g_free(cache_path); cache_path = NULL;
- timer(TIMER_STOP,(gchar*)__FUNCTION__);
- g_debug("XDXF/%s->%s()'s work finished.\n",__FILE__,__FUNCTION__);
+ g_debug("XDXF/%s->%s() called for engine at adress=%p\n",
+ __FILE__,
+ __FUNCTION__,
+ engine
+ );
+ timer(TIMER_START,(gchar*)__FUNCTION__);
+
+ GnomeVFSResult vfs_result;
+ XDXFData* data = (XDXFData*)(engine->engine_data);
+ gchar* cache_path = g_strconcat(data->dict_path,"/dict.cache",NULL);
+ vfs_result = gnome_vfs_create(&(data->cache),
+ cache_path,
+ GNOME_VFS_OPEN_WRITE,
+ FALSE,
+ 0666
+ );
+ if(vfs_result != GNOME_VFS_OK) {
+ data->cache = NULL;
+ g_warning("XDXF/%s->%s().Could not create new cache file: %s.\n",
+ __FILE__,
+ __FUNCTION__,
+ cache_path
+ );
+ }
+ else {
+ XDXFCacheData* c_data =
+ (XDXFCacheData*)g_try_malloc(sizeof(XDXFCacheData));
+ c_data->parser = XML_ParserCreate(NULL);
+ c_data->cache = data->cache;
+ c_data->buffer =
+ (gchar*)g_try_malloc(sizeof(gchar)*DICT_CACHEING_BUFF_SIZE);
+ c_data->buffer_length = 0;
+ c_data->last_start = 0;
+ c_data->last_stop = 0;
+ c_data->last_length = 0;
+
+ guint64 file_size = get_file_size(data->xdxf);
+ g_debug("XDXF/%s->%s(): caching dictionaries size is %.2f kB "
+ "[%d bytes = %.2f MB].\n",
+ __FILE__,
+ __FUNCTION__,
+ ((gdouble)file_size)/1024.0,
+ file_size,
+ ((gdouble)file_size)/(1024.0*1024.0)
+ );
+
+ XML_SetUserData(c_data->parser, (gpointer)c_data);
+ XML_SetElementHandler(c_data->parser,
+ caching_expat_start,
+ caching_expat_end
+ );
+ XML_SetCharacterDataHandler(c_data->parser, caching_expat_text);
+
+ GnomeVFSFileSize bytes_readed = DICT_CACHEING_BUFF_SIZE;
+ gchar b[DICT_CACHEING_BUFF_SIZE + 1];
+ gdouble last_prog = 0;
+ while(TRUE) {
+ vfs_result = gnome_vfs_read(data->xdxf,
+ b,
+ DICT_CACHEING_BUFF_SIZE,
+ &bytes_readed
+ );
+ XML_Parse(c_data->parser,
+ b,
+ bytes_readed,
+ bytes_readed < DICT_CACHEING_BUFF_SIZE
+ );
+
+ if(data->cb_progress_caching != NULL) {
+ GnomeVFSFileSize act_pos;
+ gnome_vfs_tell(data->xdxf, &act_pos);
+ gdouble progress = ((gdouble)act_pos)/
+ ((gdouble)file_size);
+ if((( (progress - last_prog) /
+ (data->cb_progress_caching_seed) ) > 1.0) ||
+ (progress >= 1.0)) {
+ data->cb_progress_caching(
+ progress,
+ data->cb_progress_caching_data,
+ ENGINE_NO_ERROR
+ );
+ last_prog = progress;
+ };
+ }
+ if(bytes_readed < DICT_CACHEING_BUFF_SIZE) break;
+ }
+
+ g_free(c_data->buffer);
+ g_free(c_data);
+ }
+
+ vfs_result = gnome_vfs_close(data->cache);
+ vfs_result = gnome_vfs_open(&(data->cache),
+ cache_path,
+ GNOME_VFS_OPEN_READ
+ );
+ g_free(cache_path); cache_path = NULL;
+ timer(TIMER_STOP,(gchar*)__FUNCTION__);
+ g_debug("XDXF/%s->%s()'s work finished.\n",__FILE__,__FUNCTION__);
}
-
+//------------------------------------------------------------------------------
gboolean engine_check(gchar* location)
-{
- g_debug("XDXF/%s->%s() called.\n-->PARAM:location=\'%s\'\n",__FILE__,__FUNCTION__,location);
- timer(TIMER_START,(gchar*)__FUNCTION__);
- gboolean result = TRUE;
- gchar* filepath = g_strdup(location);
- gchar* tmp = NULL;
-
- string_to_path(&filepath);
- if (filepath == NULL)
- {
- result = FALSE;
- g_warning("XDXF/%s->%s() location \'%s\' is not a proper path!\n",__FILE__,__FUNCTION__,location);
- }
- else {
- tmp = g_strconcat(filepath,"/dict.xdxf",NULL);
- g_free(filepath);
- filepath = tmp;
- tmp = NULL;
-
- g_debug("XDXF/%s->%s() finnal file to check is: %s\n",__FILE__,__FUNCTION__,filepath);
- if (!g_file_test(filepath, G_FILE_TEST_IS_REGULAR))
- {
- g_warning("XDXF/%s->%s() file \'%s\' does not exists!\n",__FILE__,__FUNCTION__,filepath);
- result = FALSE;
- };
- };
- if (result != FALSE)
- {
- result = is_xdxf_file(filepath);
- };
-
- g_free(filepath);
- timer(TIMER_STOP,(gchar*)__FUNCTION__);
- g_debug("XDXF/%s->%s() returned bool statement=%s.\n",__FILE__,__FUNCTION__,(result?"TRUE":"FALSE"));
- return result;
+{
+ g_debug("XDXF/%s->%s() called.\n-->PARAM:location=\'%s\'\n",
+ __FILE__,
+ __FUNCTION__,
+ location
+ );
+ timer(TIMER_START,(gchar*)__FUNCTION__);
+ gboolean result = TRUE;
+ gchar* filepath = g_strdup(location);
+ gchar* tmp = NULL;
+
+ string_to_path(&filepath);
+ if (filepath == NULL) {
+ result = FALSE;
+ g_warning("XDXF/%s->%s() location \'%s\' is not a proper "
+ "path!\n",
+ __FILE__,
+ __FUNCTION__,
+ location
+ );
+ }
+ else {
+ tmp = g_strconcat(filepath,"/dict.xdxf",NULL);
+ g_free(filepath);
+ filepath = tmp;
+ tmp = NULL;
+
+ g_debug("XDXF/%s->%s() finnal file to check is: %s\n",
+ __FILE__,
+ __FUNCTION__,
+ filepath
+ );
+ if (!g_file_test(filepath, G_FILE_TEST_IS_REGULAR)) {
+ g_warning("XDXF/%s->%s() file \'%s\' does not "
+ "exists!\n",
+ __FILE__,
+ __FUNCTION__,
+ filepath
+ );
+ result = FALSE;
+ };
+ };
+ if (result != FALSE) {
+ result = is_xdxf_file(filepath);
+ };
+
+ g_free(filepath);
+ timer(TIMER_STOP,(gchar*)__FUNCTION__);
+ g_debug("XDXF/%s->%s() returned bool statement=%s.\n",
+ __FILE__,
+ __FUNCTION__,
+ PRINT_STATE(result)
+ );
+ return result;
}
-
-
-
+//------------------------------------------------------------------------------
static guint get_max_length(gchar* a, guint length)
{
- gchar* b = a;
- guint len = 0;
- guint n = 0;
- memcpy(&n,b,sizeof(guint));
- while((len + n) <= (length - 4))
- {
- len += n;
- b = b + n;
- memcpy(&n,b,sizeof(guint));
- }
- return len;
+ gchar* b = a;
+ guint len = 0;
+ guint n = 0;
+ memcpy(&n,b,sizeof(guint));
+ while((len + n) <= (length - 4)) {
+ len += n;
+ b = b + n;
+ memcpy(&n,b,sizeof(guint));
+ }
+ return len;
}
-
-
-//================================================================================================================================================
-//------------------------------------------------------------------------------------------------------------------------------------------------
-//________________________________________________________________________________________________________________________________________________
-//************************************************************************************************************************************************
- // finished functions:
+//------------------------------------------------------------------------------ // finished functions:
void engine_set_auto_free(Engine* engine, gboolean state)
{
- g_debug("XDXF/%s->%s() called.\n-->PARAM:engine at adress=%p\n-->PARAM:state=%s\n",__FILE__,__FUNCTION__,engine,PRINT_STATE(state));
- g_asert(engine != NULL);
- XDXFData* data = (XDXFData*)(engine->engine_data);
- data->auto_free = state;
- g_debug("XDXF/%s->%s() Current auto_free is %s\n",__FILE__,__FUNCTION__,PRINT_STATE(data->auto_free));
+ g_debug("XDXF/%s->%s() called.\n"
+ "-->PARAM:engine at adress=%p\n"
+ "-->PARAM:state=%s\n",
+ __FILE__,
+ __FUNCTION__,
+ engine,
+ PRINT_STATE(state)
+ );
+ g_asert(engine != NULL);
+ XDXFData* data = (XDXFData*)(engine->engine_data);
+ data->auto_free = state;
+ g_debug("XDXF/%s->%s() Current auto_free is %s\n",
+ __FILE__,
+ __FUNCTION__,
+ PRINT_STATE(data->auto_free)
+ );
}
-
+//------------------------------------------------------------------------------
gchar* engine_version()
{
- g_debug("XDXF/%s->%s() called.\n",__FILE__,__FUNCTION__);
- gchar* result = g_strdup(DIC_ENG_VERSION);
- g_debug("XDXF/%s->%s() return string=%s\n",__FILE__,__FUNCTION__,result);
- return result;
+ g_debug("XDXF/%s->%s() called.\n",__FILE__,__FUNCTION__);
+ gchar* result = g_strdup(DIC_ENG_VERSION);
+ g_debug("XDXF/%s->%s() return string=%s\n",
+ __FILE__,
+ __FUNCTION__,
+ result
+ );
+ return result;
}
+//------------------------------------------------------------------------------
gchar* engine_format()
{
- g_debug("XDXF/%s->%s() called.\n",__FILE__,__FUNCTION__);
- gchar* result = g_strdup(DIC_ENG_FORMAT);
- g_debug("XDXF/%s->%s() return string=%s\n",__FILE__,__FUNCTION__,result);
- return result;
+ g_debug("XDXF/%s->%s() called.\n",__FILE__,__FUNCTION__);
+ gchar* result = g_strdup(DIC_ENG_FORMAT);
+ g_debug("XDXF/%s->%s() return string=%s\n",
+ __FILE__,
+ __FUNCTION__,
+ result
+ );
+ return result;
}
+//------------------------------------------------------------------------------
gchar* engine_description()
{
- g_debug("XDXF/%s->%s() called.\n",__FILE__,__FUNCTION__);
- gchar* result = g_strdup("This module operates on " DIC_ENG_FORMAT " dictionaries. Version " DIC_ENG_VERSION ".");
- g_debug("XDXF/%s->%s() return string=%s\n",__FILE__,__FUNCTION__,result);
- return result;
+ g_debug("XDXF/%s->%s() called.\n",__FILE__,__FUNCTION__);
+ gchar* result = g_strdup("This module operates on "
+ DIC_ENG_FORMAT
+ " dictionaries. Version "
+ DIC_ENG_VERSION
+ "."
+ );
+ g_debug("XDXF/%s->%s() return string=%s\n",
+ __FILE__,
+ __FUNCTION__,
+ result
+ );
+ return result;
}
-
+//------------------------------------------------------------------------------
gboolean engine_is_optimized(Engine* engine)
{
- g_debug("XDXF/%s->%s() called.\n-->PARAM: engine adress=%p\n",__FILE__,__FUNCTION__,engine);
- g_asert(engine != NULL);
- gboolean result = FALSE;
- XDXFData* data = (XDXFData*)(engine->engine_data);
- if(data->cache != NULL)
- {
- result = TRUE;
- };
- g_debug("XDXF/%s->%s() returned bool statement=%s.\n",__FILE__,__FUNCTION__,PRINT_STATE(result));
- return result;
+ g_debug("XDXF/%s->%s() called.\n-->PARAM: engine adress=%p\n",
+ __FILE__,
+ __FUNCTION__,
+ engine
+ );
+ g_asert(engine != NULL);
+ XDXFData* data = (XDXFData*)(engine->engine_data);
+ gboolean result = (data->cache != NULL);
+ g_debug("XDXF/%s->%s() returned bool statement=%s.\n",
+ __FILE__,
+ __FUNCTION__,
+ PRINT_STATE(result)
+ );
+ return result;
}
-
+//------------------------------------------------------------------------------
gchar* engine_location(Engine* engine)
{
- g_debug("XDXF/%s->%s() called.\n-->PARAM: engine adress=%p\n",__FILE__,__FUNCTION__,engine);
- g_asert(engine != NULL);
- XDXFData* data = (XDXFData*)(engine->engine_data);
- gchar* result;
- if(data->auto_free)
- {
- result = data->dict_path;
- }
- else
- {
- result = g_strdup(data->dict_path);
- }
-
- g_debug("XDXF/%s->%s() returned string=%s\n",__FILE__,__FUNCTION__,result);
- return result;
+ g_debug("XDXF/%s->%s() called.\n-->PARAM: engine adress=%p\n",
+ __FILE__,
+ __FUNCTION__,
+ engine
+ );
+ g_asert(engine != NULL);
+ XDXFData* data = (XDXFData*)(engine->engine_data);
+ gchar* result;
+ if(data->auto_free) {
+ result = data->dict_path;
+ }
+ else {
+ result = g_strdup(data->dict_path);
+ }
+
+ g_debug("XDXF/%s->%s() returned string=%s\n",
+ __FILE__,
+ __FUNCTION__,
+ result
+ );
+ return result;
}
-
-
-static void search_word_list_start(void *data, const char *el, const char **attr)
+//------------------------------------------------------------------------------
+static void search_word_list_start(void *data,
+ const char *el,
+ const char **attr
+ )
{
- XDXFWordsListData* loc_data = (XDXFWordsListData*)data;
- if(g_utf8_collate(el,"k") == 0)
- {
- loc_data->one_word = 1;
- };
+ XDXFWordsListData* loc_data = (XDXFWordsListData*)data;
+ if(g_utf8_collate(el,"k") == 0) {
+ loc_data->one_word = 1;
+ };
}
-
-static void search_word_list_end(void *data, const char *el)
+//------------------------------------------------------------------------------
+static void search_word_list_end(void *data, const char *el)
{
- XDXFWordsListData* loc_data = (XDXFWordsListData*)data;
- if(g_utf8_collate(el,"k") == 0)
- {
- loc_data->one_word = 0;
- }
- else
- {
- return;
- }
- static gboolean any_found = FALSE;
- gboolean matched = FALSE;
- // checking last found word
-//
-
- if( ( loc_data->last_word_length >= loc_data->pattern_len ) &&
- (g_ascii_strncasecmp(loc_data->last_word, loc_data->pattern, loc_data->pattern_len) == 0 )
- )
- {
- matched = TRUE;
- any_found = TRUE;
- gchar* new = g_strdup(loc_data->last_word);
- g_array_append_val((loc_data->result), new);
- g_debug("New Word for pattern \"%s\" found: %s\n",loc_data->pattern,new);
- };
-
- // "clearing" buffer for next word
- loc_data->last_word_length = 0;
- // if we passed words matching -> ends
- if(any_found && !matched)
- {
- loc_data->cont = FALSE;
- };
- matched = FALSE;//added by me
- any_found = FALSE;//added by me
+ XDXFWordsListData* loc_data = (XDXFWordsListData*)data;
+ if(g_utf8_collate(el,"k") == 0) {
+ loc_data->one_word = 0;
+ }
+ else {
+ return;
+ }
+ static gboolean any_found = FALSE;
+ gboolean matched = FALSE;
+
+ if(( loc_data->last_word_length >= loc_data->pattern_len ) &&
+ (g_ascii_strncasecmp(loc_data->last_word,
+ loc_data->pattern,
+ loc_data->pattern_len) == 0)) {
+ matched = TRUE;
+ any_found = TRUE;
+ gchar* new = g_strdup(loc_data->last_word);
+ g_array_append_val((loc_data->result), new);
+ g_debug("New Word for pattern \"%s\" found: %s\n",
+ loc_data->pattern,
+ new
+ );
+ };
+ // "clearing" buffer for next word
+ loc_data->last_word_length = 0;
+ // if we passed words matching -> ends
+ if(any_found && !matched) {
+ loc_data->cont = FALSE;
+ };
+ matched = FALSE;
+ any_found = FALSE;
}
-
+//------------------------------------------------------------------------------
static void search_word_list_text(void *data, const XML_Char *txt, int len)
{
- XDXFWordsListData* loc_data = (XDXFWordsListData*)data;
-
- if(loc_data->one_word == 1)
- {
- memcpy(&(loc_data->last_word[loc_data->last_word_length]), (gchar*)txt, len);
- loc_data->last_word_length += (guint)len;
- loc_data->last_word[loc_data->last_word_length] = '\0';
- };
+ XDXFWordsListData* loc_data = (XDXFWordsListData*)data;
+
+ if(loc_data->one_word == 1) {
+ memcpy(&(loc_data->last_word[loc_data->last_word_length]),
+ (gchar*)txt,
+ len
+ );
+ loc_data->last_word_length += (guint)len;
+ loc_data->last_word[loc_data->last_word_length] = '\0';
+ };
}
-
+//------------------------------------------------------------------------------
+// return translation of word using cache file
+static void word_list_cache(XDXFData* data, gchar* pattern, GArray* result) {
+ gnome_vfs_seek(data->cache, GNOME_VFS_SEEK_START, 0);
+ GnomeVFSResult vfs_result;
+ GnomeVFSFileSize bytes_readed;
+ guint record_length = 0;
+ gchar buffer[DICT_SEARCHING_WORD_LIST_BUFF_SIZE];
+ gchar* buf;
+ guint already = 0;
+ guint max_length = 0;
+ guint64 file_size = get_file_size(data->cache);
+ guint pattern_len = strlen(pattern);
+ while(TRUE) {
+ gnome_vfs_read(data->cache,
+ buffer,
+ DICT_SEARCHING_WORD_LIST_BUFF_SIZE,
+ &bytes_readed
+ );
+
+ max_length = get_max_length(buffer, (guint)bytes_readed);
+ already += max_length;
+ buf = buffer;
+
+ guint how_far = 0;
+ while(how_far < max_length) {
+ memcpy(&record_length, buf, sizeof(guint));
+ if(((record_length - 3*sizeof(guint)) >= pattern_len) &&
+ ( g_ascii_strncasecmp(buf + sizeof(guint),
+ pattern,
+ pattern_len
+ ) == 0 ) ) {
+ gchar* new = g_strndup(buf + sizeof(guint),
+ record_length -
+ 3*sizeof(guint));
+ g_array_append_val(result, new);
+ g_debug("New Word for pattern \"%s\" found: "
+ "%s\n",
+ pattern,
+ new
+ );
+ };
+ how_far += record_length;
+ buf = buf + record_length;
+
+ }
+ if( (bytes_readed < DICT_SEARCHING_WORD_LIST_BUFF_SIZE) ||
+ (already > (file_size -3)) ) {
+ break;
+ }
+ gnome_vfs_seek(data->cache,
+ GNOME_VFS_SEEK_CURRENT,
+ ((gint)max_length) -
+ DICT_SEARCHING_WORD_LIST_BUFF_SIZE
+ );
+ }
+
+ timer(TIMER_STOP,(gchar*)__FUNCTION__);
+ timer(TIMER_START,"callback for returning words list START");
+ data->cb_search_word_list(result,
+ pattern,
+ data->cb_search_word_list_data,
+ ENGINE_NO_ERROR
+ );
+ timer(TIMER_STOP,"callback for returning words list END");
+}
+//------------------------------------------------------------------------------
+// return translation of word but using only xdxf dictionary file
+static void word_list_xdxf(XDXFData* data, gchar* pattern, GArray* result) {
+ gnome_vfs_seek(data->xdxf, GNOME_VFS_SEEK_START, 0);
+ GnomeVFSResult vfs_result;
+ GnomeVFSFileSize bytes_readed = DICT_SEARCHING_WORD_LIST_BUFF_SIZE;
+ gchar buffer[DICT_SEARCHING_WORD_LIST_BUFF_SIZE+1];
+ guint64 file_size = get_file_size(data->xdxf);
+ guint pattern_len = strlen(pattern);
+
+
+ XML_Parser parser = XML_ParserCreate(NULL);
+ if (!parser) {
+ g_warning("XDXF/%s->%s() Could not open initialize XML "
+ "parser.\n",
+ __FILE__,
+ __FUNCTION__
+ );
+ timer(TIMER_STOP,(gchar*)__FUNCTION__);
+ return;
+ };
+
+ gchar tmp[DICT_MAX_WORD_LENGTH];
+ XML_SetElementHandler(parser,
+ search_word_list_start,
+ search_word_list_end
+ );
+ XML_SetCharacterDataHandler(parser, search_word_list_text);
+
+ // buffer for single word
+ // pattern to search
+ // length of pattern
+ // actal length of readed word
+ // array to append words
+ // continuation of the same word
+ // continue of searching?
+ XDXFWordsListData search_data = {tmp,
+ pattern,
+ pattern_len,
+ 0,
+ result,
+ 0,
+ TRUE
+ };
+ XML_SetUserData(parser, &search_data);
+
+ gdouble last_prog = 0;
+ while(TRUE) {
+ vfs_result = gnome_vfs_read(data->xdxf,
+ buffer,
+ DICT_SEARCHING_WORD_LIST_BUFF_SIZE,
+ &bytes_readed
+ );
+ XML_Parse(parser,
+ buffer,
+ bytes_readed,
+ bytes_readed < DICT_SEARCHING_WORD_LIST_BUFF_SIZE
+ );
+
+ if(data->cb_progress_word_list != NULL) {
+ GnomeVFSFileSize act_pos;
+ gnome_vfs_tell(data->xdxf, &act_pos);
+ gdouble progress = ((gdouble)act_pos)/
+ ((gdouble)file_size);
+ if((((progress - last_prog)/
+ (data->cb_progress_word_list_seed)) > 1.0) ||
+ (progress >= 1.0)) {
+ data->cb_progress_word_list(
+ progress,
+ data->cb_progress_word_list_data,
+ ENGINE_NO_ERROR
+ );
+ last_prog = progress;
+ };
+ }
+ if(bytes_readed < DICT_SEARCHING_WORD_LIST_BUFF_SIZE) {
+ break;
+ }
+ if((search_data.cont) == FALSE) {
+ g_debug("XDXF/%s->%s() We found every words matching "
+ "pattern \"%s\". Abort further searching.\n",
+ __FILE__,
+ __FUNCTION__,
+ pattern
+ );
+ break;
+ }
+ }
+ XML_ParserFree(parser);
+
+ timer(TIMER_STOP,(gchar*)__FUNCTION__);
+ timer(TIMER_START,"callback for returning words list START");
+ data->cb_search_word_list(result,
+ pattern,
+ data->cb_search_word_list_data,
+ ENGINE_NO_ERROR
+ );
+ timer(TIMER_STOP,"callback for returning words list END");
+}
+//------------------------------------------------------------------------------
void engine_search_word_list(Engine* engine, gchar* pattern)
{
- g_debug("XDXF/%s->%s() called. Searching words list\n-->PARAM:engine at adress=%p\n-->PARAM:pattern=\"%s\"\n",__FILE__,__FUNCTION__,engine,pattern);
- g_assert(engine != NULL);
- g_assert(pattern != NULL);
-
- timer(TIMER_START,(gchar*)__FUNCTION__);
- XDXFData* data = (XDXFData*)(engine->engine_data);
- if(data->cb_search_word_list == NULL)
- {
- g_warning("XDXF/%s->%s() callback for Word List not set. Searching aborted.\n",__FILE__,__FUNCTION__);
- timer(TIMER_STOP,(gchar*)__FUNCTION__);
- return;
- };
- GArray* result = g_array_new(TRUE,FALSE,sizeof(gchar*));
- if(data->cache != NULL)
- { // dictionary is optimized so search in cache file
- gnome_vfs_seek(data->cache, GNOME_VFS_SEEK_START, 0);
- GnomeVFSResult vfs_result;
- GnomeVFSFileSize bytes_readed;
- guint record_length = 0;
- gchar buffer[DICT_SEARCHING_WORD_LIST_BUFF_SIZE];
- gchar* buf;
- guint already = 0;
- guint max_length = 0;
- guint64 file_size = get_file_size(data->cache);
- guint pattern_len = strlen(pattern);
- while(TRUE)
- {
- gnome_vfs_read(data->cache, buffer, DICT_SEARCHING_WORD_LIST_BUFF_SIZE, &bytes_readed);
-
- max_length = get_max_length(buffer, (guint)bytes_readed);
- already += max_length;
- buf = buffer;
-
- guint how_far = 0;
- while(how_far < max_length)
- {
- memcpy(&record_length, buf, sizeof(guint));
- if( ( (record_length - 3*sizeof(guint)) >= pattern_len ) &&
- ( g_ascii_strncasecmp(buf + sizeof(guint), pattern, pattern_len) == 0 )
- )
- {
- gchar* new = g_strndup(buf + sizeof(guint), record_length - 3*sizeof(guint));
- g_array_append_val(result, new);
- g_debug("New Word for pattern \"%s\" found: %s\n",pattern,new);
- };
- how_far += record_length;
- buf = buf + record_length;
-
- }
- if( (bytes_readed < DICT_SEARCHING_WORD_LIST_BUFF_SIZE) ||
- (already > (file_size -3)) )
- {
- break;
- }
- gnome_vfs_seek(data->cache, GNOME_VFS_SEEK_CURRENT, ((gint)max_length) - DICT_SEARCHING_WORD_LIST_BUFF_SIZE);
- }
-
- timer(TIMER_STOP,(gchar*)__FUNCTION__);
- timer(TIMER_START,"callback for returning words list START");
- data->cb_search_word_list(result,pattern,data->cb_search_word_list_data, ENGINE_NO_ERROR);
- timer(TIMER_STOP,"callback for returning words list END");
- }
- else
- { // dictionary is not optimized so search directly fom XDXF file
- gnome_vfs_seek(data->xdxf, GNOME_VFS_SEEK_START, 0);
- GnomeVFSResult vfs_result;
- GnomeVFSFileSize bytes_readed = DICT_SEARCHING_WORD_LIST_BUFF_SIZE;
- gchar buffer[DICT_SEARCHING_WORD_LIST_BUFF_SIZE+1];
- guint64 file_size = get_file_size(data->xdxf);
- guint pattern_len = strlen(pattern);
-
-
- XML_Parser parser = XML_ParserCreate(NULL);
- if (!parser)
- {
- g_warning("XDXF/%s->%s() Could not open initialize XML parser.\n",__FILE__,__FUNCTION__);
- timer(TIMER_STOP,(gchar*)__FUNCTION__);
- return;
- };
-
- gchar tmp[DICT_MAX_WORD_LENGTH];
- XML_SetElementHandler(parser, search_word_list_start, search_word_list_end);
- XML_SetCharacterDataHandler(parser, search_word_list_text);
- XDXFWordsListData search_data = {tmp, pattern, pattern_len, 0, result, 0, TRUE}; //buffer for single word - pattern to search - length of pattern - actal length of readed word - array to append words - continuation of the same word - continue of searching?
- XML_SetUserData(parser, &search_data);
-
- gdouble last_prog = 0;
- while(TRUE)
- {
- vfs_result = gnome_vfs_read(data->xdxf, buffer, DICT_SEARCHING_WORD_LIST_BUFF_SIZE, &bytes_readed);
- XML_Parse(parser, buffer, bytes_readed, bytes_readed < DICT_SEARCHING_WORD_LIST_BUFF_SIZE);
-
- if(data->cb_progress_word_list != NULL)
- {
- GnomeVFSFileSize act_pos;
- gnome_vfs_tell(data->xdxf, &act_pos);
- gdouble progress = ((gdouble)act_pos)/((gdouble)file_size);
- if( (((progress - last_prog)/(data->cb_progress_word_list_seed)) > 1.0) ||
- (progress >= 1.0))
- {
- data->cb_progress_word_list(progress, data->cb_progress_word_list_data, ENGINE_NO_ERROR);
- last_prog = progress;
- };
- }
- if(bytes_readed < DICT_SEARCHING_WORD_LIST_BUFF_SIZE)
- {
- break;
- }
- if((search_data.cont) == FALSE)
- {
- g_debug("XDXF/%s->%s() We found every words matching pattern \"%s\". Abort further searching.\n",__FILE__,__FUNCTION__,pattern);
- break;
- }
- }
- XML_ParserFree(parser);
-
- timer(TIMER_STOP,(gchar*)__FUNCTION__);
- timer(TIMER_START,"callback for returning words list START");
- data->cb_search_word_list(result,pattern,data->cb_search_word_list_data, ENGINE_NO_ERROR);
- timer(TIMER_STOP,"callback for returning words list END");
- };
-
- if(data->auto_free == TRUE)
- {
- g_debug("XDXF/%s->%s() deleting all dynamic data because AUTO_FREE=TRUE\n",__FILE__,__FUNCTION__);
- gchar* tmp;
- guint i = 0;
- while((tmp = g_array_index(result, gchar*, i)) != NULL)
- {
- g_free(tmp); tmp = NULL;
- i++;
- }
- g_array_free(result, TRUE);
- };
- g_debug("XDXF/%s->%s() finished definately its work.\n",__FILE__,__FUNCTION__);
+ g_debug("XDXF/%s->%s() called. Searching words list\n"
+ "-->PARAM:engine at adress=%p\n"
+ "-->PARAM:pattern=\"%s\"\n",
+ __FILE__,
+ __FUNCTION__,
+ engine,
+ pattern
+ );
+ g_assert(engine != NULL);
+ g_assert(pattern != NULL);
+
+ timer(TIMER_START,(gchar*)__FUNCTION__);
+ XDXFData* data = (XDXFData*)(engine->engine_data);
+ if(data->cb_search_word_list == NULL) {
+ g_warning("XDXF/%s->%s() callback for Word List not set. "
+ "Searching aborted.\n",
+ __FILE__,
+ __FUNCTION__
+ );
+ timer(TIMER_STOP,(gchar*)__FUNCTION__);
+ return;
+ };
+ GArray* result = g_array_new(TRUE,FALSE,sizeof(gchar*));
+ // dictionary is optimized so search in cache file
+ if(data->cache != NULL) {
+ word_list_cache(data, pattern, result);
+ }
+ // dictionary is not optimized so search directly fom XDXF file
+ else {
+ word_list_xdxf(data, pattern, result);
+ };
+
+ if(data->auto_free == TRUE) {
+ g_debug("XDXF/%s->%s() deleting all dynamic data because "
+ "AUTO_FREE=TRUE\n",
+ __FILE__,
+ __FUNCTION__
+ );
+ gchar* tmp;
+ guint i = 0;
+ while((tmp = g_array_index(result, gchar*, i)) != NULL)
+ {
+ g_free(tmp); tmp = NULL;
+ i++;
+ }
+ g_array_free(result, TRUE);
+ };
+ g_debug("XDXF/%s->%s() finished definately its work.\n",
+ __FILE__,
+ __FUNCTION__
+ );
}
-
-
-
-
-
-
-
-/**********************************************************************************
- * copyright (C) 2006, Dariusz Wiechecki
- * dariusz.wiechecki@gmail.com
- * 14 August 2006, Lodz, Poland
- **********************************************************************************
- * This file is part of str-vfs-test.
- *
- * str-vfs-test is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * str-vfs-test is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with str-vfs-test; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *********************************************************************************/
-#ifndef _DICTIONARY_ENGINE_BASE
-#define _DICTIONARY_ENGINE_BASE
-
-#ifdef __cplusplus
-extern "C" { // to make it possible to use this header in C++ programms
+/*******************************************************************************
+This file is part of WhiteStork.
+
+WhiteStork is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+WhiteStork is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with WhiteStork; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+Copyright 2006 ComArch S.A.
+*******************************************************************************/
+#ifndef _DICTIONARY_ENGINE_BASE
+#define _DICTIONARY_ENGINE_BASE
+
+#ifdef __cplusplus
+ extern "C" {
#endif
-//______________________________________________________________________________________________________
-// ******************************************************************************************************
-//********************************************************************************************* HEADERS:
+
+//______________________________________________________________________________
+// *****************************************************************************
+//************************************************************* HEADERS SECTION:
+//------------------------------------------------------------------------------
+// header with gnu library for C - most of types and functions needed it (all
+// started from g* and g_*().
#include <glib.h>
+//------------------------------------------------------------------------------
-//______________________________________________________________________________________________________
-// ******************************************************************************************************
-//************************************************************************************ GLOBAL MACROS:
+//______________________________________________________________________________
+// *****************************************************************************
+//******************************************************* GLOBAL MACROS SECTION:
+//------------------------------------------------------------------------------
/** \brief Checks if module is peaceable with concrete location.
-*
-* If user of engine module want to know if concrete module can handle concrete location, he can call <i>dict_eng_module_check()</i>
-*and check the result of this function.
+ *
+ * If user of engine module want to know if concrete module can handle concrete
+ * location, he can call <i>dict_eng_module_check()</i>and check the result
+ * of this function.
+ *
* @param module :: <b>EngineModule</b> - module engine which will be testing
* @param location :: <b>gchar*</b> - location on wich engine will be testing
- * @return <i><b>gboolean</b></i> :: tells if location <i>location</i> can be handled by module <i>module</i>
+ * @return <i><b>gboolean</b></i> :: tells if location <i>location</i> can be
+ * handled by module <i>module</i>
*/
-#define dict_eng_module_check(module,location) ( (module).engine_check( (location) ) )
-
-
+#define dict_eng_module_check(module,location) \
+ ( (module).engine_check( (location) ) )
+//------------------------------------------------------------------------------
/** \brief Get short description of engine module.
*
- * If there is need to present to the user of end programm some information about enigne he is using, we can call dict_eng_module_get_description() and
+ * If there is need to present to the user of end programm some information
+ * about enigne he is using, we can call dict_eng_module_get_description() and
* print/show the result of this call.
- * @param module :: <b>EngineModule</b> - module engine which description we want
- * @return <i><b>gchar*</b></i> :: there is string, decribing module engine <i>module</i>, in this pointer. User should NOT free this pointer as it points to static table of chars
+ *
+ * @param module :: <b>EngineModule</b>- module engine which description we want
+ * @return <i><b>gchar*</b></i> :: there is string, decribing module engine
+ * <i>module</i>, in this pointer. User should NOT free this pointer as it
+ * points to static table of chars
*/
-#define dict_eng_module_get_description(module) ( (module).engine_description() )
-
-
+#define dict_eng_module_get_description(module) \
+ ( (module).engine_description() )
+//------------------------------------------------------------------------------
/** \brief Get version of engine module.
*
- * Sometimes it could be useful to get know what version of engine module we are using. We can call this function to retrieve these informations from module.
- * Note that version information could be also placed in description of module, but here user will get only string representing version, what could be needed in some situation
- * (e.g.: if end-user will have two the same module, then programm has to decide which should be used, or ask user).
- * @param module :: <b>EngineModule</b> - module engine which implementation version we want
- * @return <i><b>gchar*</b></i> :: pointer to string representing module <i>module</i>version. User should NOT free this pointer as it points to static table of chars
+ * Sometimes it could be useful to get know what version of engine module we are
+ * using. We can call this function to retrieve these informations from module.
+ * Note that version information could be also placed in description of module,
+ * but here user will get only string representing version, what could be needed
+ * in some situation (e.g.: if end-user will have two the same module, then
+ * programm has to decide which should be used, or ask user).
+ *
+ * @param module :: <b>EngineModule</b> - module engine which implementation
+ * version we want
+ * @return <i><b>gchar*</b></i> :: pointer to string representing module
+ * <i>module</i>version. User should NOT free this pointer as it points to
+ * static table of chars
*/
-#define dict_eng_module_get_version(module) ( (module).engine_version() )
-
-
+#define dict_eng_module_get_version(module) \
+ ( (module).engine_version() )
+//------------------------------------------------------------------------------
/** \brief Get format on which working engnine module.
*
- * If we want to know on what dictionary format works current engine module, we can call this function. As a result we will retrieve string telling us what format-based is
- * concrete engine module (e.g. XDXF, WordNet etc.).
- * @param module :: <b>EngineModule</b> - engine module which dictionary format we want to get
- * @return <i><b>gchar*</b></i> :: string representing format of dictionary on which module <i>module</i> can works. User should NOT free this pointer as it points
- * to static table of chars
+ * If we want to know on what dictionary format works current engine module, we
+ * can call this function. As a result we will retrieve string telling us what
+ * format-based is concrete engine module (e.g. XDXF, WordNet etc.).
+ *
+ * @param module :: <b>EngineModule</b> - engine module which dictionary format
+ * we want to get
+ * @return <i><b>gchar*</b></i> :: string representing format of dictionary on
+ * which module <i>module</i> can works. User should NOT free this pointer as
+ * it points to static table of chars
*/
-#define dict_eng_module_get_format(module) ( (module).engine_version() )
-
-
+#define dict_eng_module_get_format(module) \
+ ( (module).engine_version() )
+//------------------------------------------------------------------------------
/** \brief Open concrete dictionary.
-*
-* This functions opens location (this could mean: filename, URL, any other way to specify concrete localization of dictionary database). To be more sure that this function will be sucefull,
-* user can call before dict_eng_module_check() to check if this module can handle dictionary under passed location. But this do not warrant that calling dict_eng_module_create() will not
-* fail. User should check the result of function to be sure that everything was ok.
- * @param module :: <b>EngineModule</b> - engine module which should be used to open location <i>location</i>
- * @param location :: <b>gchar*</b> - location of dictionary database (file, directory, URL etc.)
- * @param flags :: <b>EngineOptimizationFlag</b> - flags defines how program shoud automaticlly use optimization methods for opened dictionary
- * @return <i><b>Engine*</b></i> :: pointer to new enigne structure; After use, if this structure will not be needed anymore, user should call dict_eng_destroy() to free memory
- * \sa EngineOptimizationFlag :|: dict_eng_module_check() :|: EngineModule :|: Engine
+ *
+ * This functions opens location (this could mean: filename, URL, any other way
+ * to specify concrete localization of dictionary database). To be more sure
+ * that this function will be sucefull, user can call before
+ * dict_eng_module_check() to check if this module can handle dictionary under
+ * passed location. But this do not warrant that calling
+ * dict_eng_module_create() will not fail. User should check the result of
+ * function to be sure that everything was ok.
+ *
+ * @param module :: <b>EngineModule</b> - engine module which should be used to
+ * open location <i>location</i>
+ * @param location :: <b>gchar*</b> - location of dictionary database (file,
+ * directory, URL etc.)
+ * @param flags :: <b>EngineOptimizationFlag</b> - flags defines how program
+ * shoud automaticlly use optimization methods for opened dictionary
+ * @return <i><b>Engine*</b></i> :: pointer to new enigne structure; After use,
+ * if this structure will not be needed anymore, user should call
+ * dict_eng_destroy() to free memory
+ * \sa EngineOptimizationFlag :|: dict_eng_module_check() :|: EngineModule :|:
+ * Engine
*/
-#define dict_eng_module_create(module,location,flags) ( (module).engine_create( (location), (flags), NULL, NULL, 0.01 ) )
-
-
-#define dict_eng_module_create_ext(module,location,flags,progress_handler,progress_data,seed) ( (module).engine_create( (location), (flags), (progress_handler), (progress_data), (seed) ) )
-
-
-
-//______________________________________________________________________________________________________
-// ******************************************************************************************************
-//********************************************************************** CONCRETE DICTIONARY MACROS:
-
-#define dict_eng_set_progress_seed(engine, signal, val) ( (engine)->engine_set_progress_seed((engine), (signal), (val) ) )
-
-#define dict_eng_set_auto_free(engine, state) ( (engine)->engine_set_auto_free( (engine), (state) )
-
-
+#define dict_eng_module_create(module,location,flags) \
+ ( (module).engine_create( (location), (flags), NULL, NULL, 0.01 ) )
+//------------------------------------------------------------------------------
+/** \brief Open concrete dictionary - define handler for signal of progress
+ *
+ * This functions is similiar to dict_eng_module_create(module,location,flags).
+ * In addition to it, this function get additional parameters, defining how
+ * engine should "inform" the user about progress of eventuall caching proccess.
+ *
+ * @param module :: <b>EngineModule</b> - engine module which should be used to
+ * open location <i>location</i>
+ * @param location :: <b>gchar*</b> - location of dictionary database (file,
+ * directory, URL etc.)
+ * @param flags :: <b>EngineOptimizationFlag</b> - flags defines how program
+ * shoud automaticlly use optimization methods for opened dictionary
+ * @param progress_handler :: <b>cb_progress</b> - handler which will be called
+ * from time to time, to give to the user any response about caching progress
+ * @param progress_data :: <b>gpointer</b> - pointer to data which will be given
+ * as a user_data argument for progress_data function during its calling
+ * @param seed :: <b>gdouble</b> - defines after how big step (in percentage)
+ * in progress of caching, engine send new signal - call progress_handler with
+ * actual value of progress
+ * @return <i><b>Engine*</b></i> :: pointer to new enigne structure; After use,
+ * if this structure will not be needed anymore, user should call
+ * dict_eng_destroy() to free memory
+ * \sa EngineOptimizationFlag :|: dict_eng_module_check() :|: EngineModule :|:
+ * Engine :|: cb_progress
+ */
+#define dict_eng_module_create_ext(module, \
+ location, \
+ flags, \
+ progress_handler, \
+ progress_data, \
+ seed \
+ ) ( \
+ (module).engine_create( (location), \
+ (flags), \
+ (progress_handler), \
+ (progress_data), \
+ (seed) \
+ ))
+//------------------------------------------------------------------------------
+
+
+//______________________________________________________________________________
+// *****************************************************************************
+//****************************************** CONCRETE DICTIONARY MACROS SECTION:
+//------------------------------------------------------------------------------
+#define dict_eng_set_progress_seed(engine, signal, val) ( \
+ (engine) -> engine_set_progress_seed( (engine), \
+ (signal), \
+ (val) \
+ ))
+//------------------------------------------------------------------------------
+
+#define dict_eng_set_auto_free(engine, state) ( \
+ (engine) -> engine_set_auto_free( (engine), (state) )
+//------------------------------------------------------------------------------
/** \brief Activate optimization mechanizms for concrete engine.
*
- * Every engine could have some optimization methods. By calling this function we enabled this option. For the user of engine it is not important what kind
- * of optimization is used in current engine, how does it work etc. It should be opaque for engine's users.
+ * Every engine could have some optimization methods. By calling this function
+ * we enabled this option. For the user of engine it is not important what kind
+ * of optimization is used in current engine, how does it work etc. It should
+ * be opaque for engine's users.
*
* @param engine :: <b>Engine*</b> - pointer to engine which should optimized
- * @return <i><b>void</b></i> :: nothing. This function only take a chance to make engine working faster, but it is not said that every step will be succesful.
- * But even if not - engine has to work properly.
+ * @return <i><b>void</b></i> :: nothing. This function only take a chance to
+ * make engine working faster, but it is not said that every step
+ * will be succesful. But even if not - engine has to work properly.
* \sa dict_eng_module_create() :|: dict_eng_is_optimized() :|: Engine
*/
-#define dict_eng_optimize(engine) ( ( engine )->engine_optimize( (engine) ) )
-
-
+#define dict_eng_optimize(engine) \
+ ((engine) -> engine_optimize( (engine) ))
+//------------------------------------------------------------------------------
/** \brief Checks if current engine has activated optimization.
*
- * User can call this function to get know if concrete engine has enabled optimization. Optimization can be activated by calling dict_eng_optimize() or passing
- * ENGINE_CREATE or ENGINE_REFRESH flags to dict_eng_module_create() while opening concrete dictionary.
+ * User can call this function to get know if concrete engine has enabled
+ * optimization. Optimization can be activated by calling dict_eng_optimize()
+ * or passing ENGINE_CREATE or ENGINE_REFRESH flags to dict_eng_module_create()
+ * while opening concrete dictionary.
*
- * @param engine :: <b>Engine*</b> - pointer to engine which should checked if is optimized now
- * @return <i><b>gboolean</b></i> :: nothing. This function only take a chance to make engine working faster, but it is not said that every step will be succesful
+ * @param engine :: <b>Engine*</b> - pointer to engine which should be checked
+ * if is optimized now
+ * @return <i><b>gboolean</b></i> :: nothing. This function only take a chance
+ * to make engine working faster, but it is not said that every step
+ * will be succesful
* \sa dict_eng_optimize() :|: Engine :|: EngineOptimizationFlag
*/
-#define dict_eng_is_optimized( engine ) ( ( engine )->engine_is_optimized( (engine) ) )
-
-
+#define dict_eng_is_optimized( engine ) \
+ ((engine) -> engine_is_optimized( (engine) ))
+//------------------------------------------------------------------------------
/** \brief To get know from what location was created current dictionary.
*
- * If user of engine want to get know from what locatione exactly was created concrete engine, he could call this function. It returns string,
- * most likely the same as the one passed earlier to dict_eng_module_create() function as a <i>location</i> argument.
+ * If user of engine want to get know from what locatione exactly was created
+ * concrete engine, he could call this function. It returns string, most likely
+ * the same as the one passed earlier to dict_eng_module_create() function
+ * as a <i>location</i> argument.
*
- * @param engine :: <b>Engine*</b> - dictionary from which we want to get location
- * @return <i><b>gchar*</b></i> :: pointer to chars, from which concrete dictionary was created
+ * @param engine :: <b>Engine*</b> - dictionary from which we want to get
+ * location
+ * @return <i><b>gchar*</b></i> :: pointer to chars, from which concrete
+ * dictionary was created
* \sa dict_eng_module_create()
*/
-#define dict_eng_get_location(engine) ( (engine)->engine_location( (engine) ) )
-
-
+#define dict_eng_get_location(engine) \
+ ((engine) -> engine_location( (engine) ))
+//------------------------------------------------------------------------------
/** \brief Tells if last operation was sucesfull.
*
- * If user want to be sure that everything was ok, during last operation (it has finished with success), he has to check if dict_eng_get_last_state() is equal to
- * ENGINE_NO_ERROR. If not, he can also find the reason why operation failed.
- * @param engine :: <b>Engine*</b> - dictionary which last operation's returned code we want to get
+ * If user want to be sure that everything was ok, during last operation
+ * (it has finished with success), he has to check if dict_eng_get_last_status()
+ * is equal to ENGINE_NO_ERROR. If not, he can also find the reason
+ * why operation failed.
+ * @param engine :: <b>Engine*</b> - dictionary which last operation's returned
+ * code we want to get
* @return <i><b>EngineStatus</b></i> :: finish code of last operation
* \sa EngineStatus :|: dict_eng_state_message()
*/
-#define dict_eng_get_last_state(engine) ( (engine)->engine_error( (engine) ) )
-
-
+#define dict_eng_get_last_status(engine) \
+ ((engine) -> engine_error( (engine) ))
+//------------------------------------------------------------------------------
/** \brief Translate pure state code to meaningfull message.
*
- * If there was a error during engine was working, we can present to the user the reason for this error in meaningfull form.
+ * If there was a error during engine was working, we can present to the user
+ * the reason for this error in meaningfull form.
+ *
* @param error :: <b>EngineState</b> - code which we want to translate
* @return <i><b>gchar*</b></i> :: message describing concrete error code
* \sa EngineStatus :|: dict_eng_state_message()
*/
-#define dict_eng_state_message(error) ( (engine)->engine_error_message( error ) )
-
-
+#define dict_eng_state_message(error) \
+ ((engine) -> engine_error_message( (error) ))
+//------------------------------------------------------------------------------
/** \brief Destroy gently and completly current dictionary.
*
- * When user do not need anymore concrete dictionary, he must destroy it to free memory allocated by this dictionary. It will close avery opened file descriptor,
- * free any additional memory block allocated while engine was working etc. User are not allowed to call free() on dictionary without calling before dict_eng_destroy().
+ * When user do not need anymore concrete dictionary, he must destroy it to
+ * free memory allocated by this dictionary. It will close avery opened file
+ * descriptor, free any additional memory block allocated while engine was
+ * working etc. User are not allowed to call free() on dictionary without
+ * calling before dict_eng_destroy().
*
- * @param engine :: <b>Engine*</b> - pointer to dictionary which is not needed anymore
- * @return <i><b>void</b></i> :: nothing. This function should work properly, and free any resources which arelady are in use by current dictionary.
+ * @param engine :: <b>Engine*</b> - pointer to dictionary which is not
+ * needed anymore
+ * @return <i><b>void</b></i> :: nothing. This function should work properly,
+ * and free any resources which arelady are in use by current dictionary.
* \sa dict_eng_module_create() :|: Engine
*/
-#define dict_eng_destroy(engine) ( (engine)->engine_close( (engine)) )
-
-
+#define dict_eng_destroy(engine) \
+ ((engine) -> engine_close( (engine) ))
+//------------------------------------------------------------------------------
/** \brief Start searching for words list.
*
- * This function starts searching for words list. User should set before callback for ENGINE_WORD_LIST_SIGNAL, to be able to retrieve words list, because this
- * function do not return any value.
+ * This function starts searching for words list. User should set before
+ * callback for ENGINE_WORD_LIST_SIGNAL, to be able to retrieve words list,
+ * because this function do not return any value.
*
- * @param engine :: <b>Engine*</b> - pointer to dictionary in which we are looking for words matching to pattern
- * @param pattern :: <b>gchar*</b> - string representing pattern to which returned word should be matching
- * @return <i><b>void</b></i> :: nothing. Result of searching can be retrieved by callback for signal ENGINE_WORD_LIST_SIGNAL
- * \sa dict_eng_search_word_translation() :|: dict_eng_search_word_translation_extended() :|: dict_eng_set_callback() :|: ENGINE_WORD_LIST_SIGNAL
+ * @param engine :: <b>Engine*</b> - pointer to dictionary in which we
+ * are looking for words matching to pattern
+ * @param pattern :: <b>gchar*</b> - string representing pattern to which
+ * returned word should be matching
+ * @return <i><b>void</b></i> :: nothing. Result of searching can be retrieved
+ * by callback for signal ENGINE_WORD_LIST_SIGNAL
+ * \sa dict_eng_search_word_translation() :|:
+ * dict_eng_search_word_translation_extended() :|: dict_eng_set_callback() :|:
+ * ENGINE_WORD_LIST_SIGNAL
*/
-#define dict_eng_search_word_list(engine,pattern) ( (engine)->engine_search_word_list((engine), (pattern)) )
-
-
+#define dict_eng_search_word_list(engine,pattern) \
+ ((engine) -> engine_search_word_list( (engine), \
+ (pattern) \
+ ))
+//------------------------------------------------------------------------------
/** \brief Start searching for word translation in dictionary.
*
- * Start searching for translation of word. To be able to retrieve translation user should use callback for ENGINE_WORD_TRANSLATION_SIGNAL signal.
+ * Start searching for translation of word. To be able to retrieve translation
+ * user should use callback for ENGINE_WORD_TRANSLATION_SIGNAL signal.
*
- * @param engine :: <b>Engine*</b> - dictionary in which we want find word's translation
- * @param word :: <b>gchar*</b> - string representing word which translation we are looking for
- * @return <i><b>void</b></i> :: nothing. Result of searching can be retrieved by callback for signal ENGINE_WORD_TRANSLATION_SIGNAL
- * \sa dict_eng_search_word_list() :|: dict_eng_search_word_translation_extended() :|: dict_eng_set_callback() :|: ENGINE_WORD_TRANSLATION_SIGNAL
+ * @param engine :: <b>Engine*</b> - dictionary in which we want find word's
+ * translation
+ * @param word :: <b>gchar*</b> - string representing word which translation
+ * we are looking for
+ * @return <i><b>void</b></i> :: nothing. Result of searching can be retrieved
+ * by callback for signal ENGINE_WORD_TRANSLATION_SIGNAL
+ * \sa dict_eng_search_word_list() :|:
+ * dict_eng_search_word_translation_extended() :|: dict_eng_set_callback() :|:
+ * ENGINE_WORD_TRANSLATION_SIGNAL
*/
-#define dict_eng_search_word_translation(engine,word) ( (engine)->engine_search_word_translation((engine), (word)) )
-
-
+#define dict_eng_search_word_translation(engine,word) \
+ ((engine) -> engine_search_word_translation( (engine), \
+ (word) \
+ ))
+//------------------------------------------------------------------------------
/** \brief Start searching for extended word translation in dictionary.
*
- * Start searching for extended translation of word. To be able to retrieve translation user should use callback for ENGINE_WORD_TRANSLATION_SIGNAL signal. Extended means
- * that retrieved translation's string could be some more than plain text (e.g. HTML, Image, etc.). User of engine should know what kind of data will retrieve ofter calling this method.
- * \todo This option are in projecting phase. In the future callback for ENGINE_WORD_TRANSLATION_SIGNAL should take parameter <i>gpointer</i> than <i>gchar*</i> to make possible
- * for user of engine to retrieve data different than gchar*. There shold be also some additional function letting know user what kind of data he will retrieve.
+ * Start searching for extended translation of word. To be able to retrieve
+ * translation user should use callback for ENGINE_WORD_TRANSLATION_SIGNAL
+ * signal. Extended means that retrieved translation's string could be some more
+ * than plain text (e.g. HTML, Image, etc.). User of engine should know what
+ * kind of data will retrieve ofter calling this method.
+ *
+ * \todo This option are in projecting phase. In the future callback for
+ * ENGINE_WORD_TRANSLATION_SIGNAL should take parameter <i>gpointer</i> than
+ * <i>gchar*</i> to make possible for user of engine to retrieve data different
+ * than gchar*. There shold be also some additional function letting know user
+ * what kind of data he will retrieve.
*
- * @param engine :: <b>Engine*</b> - dictionary in which we want find word's translation
- * @param word :: <b>gchar*</b> - string representing word which translation we are looking for
- * @return <i><b>void</b></i> :: nothing. Result of searching can be retrieved by callback for signal ENGINE_WORD_TRANSLATION_SIGNAL
- * \sa dict_eng_search_word_list() :|: dict_eng_search_word_translation() :|: dict_eng_set_callback() :|: ENGINE_WORD_TRANSLATION_SIGNAL
+ * @param engine :: <b>Engine*</b> - dictionary in which we want find word's
+ * translation
+ * @param word :: <b>gchar*</b> - string representing word which translation
+ * we are looking for
+ * @return <i><b>void</b></i> :: nothing. Result of searching can be retrieved
+ * by callback for signal ENGINE_WORD_TRANSLATION_SIGNAL
+ * \sa dict_eng_search_word_list() :|: dict_eng_search_word_translation() :|:
+ * dict_eng_set_callback() :|: ENGINE_WORD_TRANSLATION_SIGNAL
*/
-#define dict_eng_search_word_translation_extended(engine,word) ( (engine)->engine_search_word_translation_extended((engine), (pattern)) )
-
-
+#define dict_eng_search_word_translation_extended(engine,word) \
+ ((engine) -> engine_search_word_translation_extended((engine), \
+ (pattern) \
+ ))
+//------------------------------------------------------------------------------
/** \brief Setting any callback for current dictionary.
*
- * As long as functions which search for words list or translation do not return any value, user has to set callback which will be called after searching end. This make easy
- * calling these functions from other proccess, threads etc. This function sets callbacks for every signal.
+ * As long as functions which search for words list or translation do not
+ * return any value, user has to set callback which will be called after
+ * searching end. This make easy calling these functions from other proccess,
+ * threads etc. This function sets callbacks for every signal.
*
- * @param engine :: <b>Engine*</b> - dictionary for which we want set some callback
- * @param signal :: <b>gchar*</b> - string representing for what signal we want to set callback
- * @param c_handler :: <b>gpointer</b> - pointer to function which will be called after signal <i>signal</i> will occured
- * @param data :: <b>gpointer</b> - pointer to user data, which will be always passed to callback <i>c_handler</i> for signal <i>signal</i>as a last argument
- * @return <i><b>gpointer</b></i> :: pointer to previous callback; if this callbacks was not set yet, it returns NULL
- * \sa cb_word_list :|: cb_word_translation :|: ENGINE_WORD_LIST_SIGNAL :|: ENGINE_WORD_TRANSLATION_SIGNAL
- */
-#define dict_eng_set_callback(engine,signal,c_handler,data) ( (engine)->engine_set_callback((engine),(signal),(c_handler),(data)) )
-
-//______________________________________________________________________________________________________
-// ******************************************************************************************************
-//******************************************************************* SIGNALS DEFINITION FOR CALLBACKS:
-/** \brief Signal description's definition for callback called when word list was found.
- *
- * ENGINE_WORD_LIST_SIGNAL defines name for signal passed to dict_eng_set_callback() function as a
- * signal parameter. Function set to handle this signal should be called from dict_eng_search_word_list() only
+ * @param engine :: <b>Engine*</b> - dictionary for which we want set some
+ * callback
+ * @param signal :: <b>gchar*</b> - string representing for what signal we want
+ * to set callback
+ * @param c_handler :: <b>gpointer</b> - pointer to function which will be
+ * called after signal <i>signal</i> will occured
+ * @param data :: <b>gpointer</b> - pointer to user data, which will be always
+ * passed to callback <i>c_handler</i> for signal <i>signal</i>
+ * as a last argument
+ * @return <i><b>gpointer</b></i> :: pointer to previous callback; if this
+ * callbacks was not set yet, it returns NULL
+ * \sa cb_word_list :|: cb_word_translation :|: ENGINE_WORD_LIST_SIGNAL :|:
+ * ENGINE_WORD_TRANSLATION_SIGNAL
+ */
+#define dict_eng_set_callback(engine,signal,c_handler,data) \
+ ((engine) -> engine_set_callback( (engine), \
+ (signal), \
+ (c_handler), \
+ (data) \
+ ))
+//------------------------------------------------------------------------------
+
+
+//______________________________________________________________________________
+// *****************************************************************************
+//************************************ SIGNALS DEFINITION FOR CALLBACKS SECTION:
+//------------------------------------------------------------------------------
+/** \brief Signal definition for callback called when word list was found.
+ *
+ * ENGINE_WORD_LIST_SIGNAL defines name for signal passed to
+ * dict_eng_set_callback() function as a signal parameter. Function set
+ * to handle this signal should be called from dict_eng_search_word_list() only
* and have cb_word_list type.
- * <b>NOTE:</b> programmers must not use value of ENGINE_WORD_LIST_SIGNAL directly!
- * \sa cb_word_list :|: dict_eng_set_callback() :|: dict_eng_search_word_list() :|: ENGINE_WORD_TRANSLATION_SIGNAL
+ * <b>NOTE:</b> programmers must not use value of ENGINE_WORD_LIST_SIGNAL
+ * directly!
+ * \sa cb_word_list :|: dict_eng_set_callback() :|: dict_eng_search_word_list()
+ * :|: ENGINE_WORD_TRANSLATION_SIGNAL
*/
-#define ENGINE_WORD_LIST_SIGNAL "on_word_list_found"
-
-
-/** \brief Signal description's definition for callback called when word translation was found.
+#define ENGINE_WORD_LIST_SIGNAL "on_word_list_found"
+//------------------------------------------------------------------------------
+/** \brief Signal definition for callback called when word trans. was found.
*
- * ENGINE_WORD_TRANSLATION_SIGNAL defines name for signal passed to dict_eng_set_callback() function as a
- * signal parameter. Function set to handle this signal should be called from dict_eng_search_word_translation() and dict_eng_search_word_translation_extended() only
- * and have cb_word_translation.
- * <b>NOTE:</b> programmers must not use value of ENGINE_WORD_LIST_SIGNAL directly!
- * \sa cb_word_translation :|: dict_eng_set_callback() :|: dict_eng_search_word_translation() :|: ENGINE_WORD_LIST_SIGNAL
+ * ENGINE_WORD_TRANSLATION_SIGNAL defines name for signal passed to
+ * dict_eng_set_callback() function as a signal parameter. Function set
+ * to handle this signal should be called from
+ * dict_eng_search_word_translation() and
+ * dict_eng_search_word_translation_extended() only and have cb_word_translation.
+ * <b>NOTE:</b> programmers must not use value of ENGINE_WORD_LIST_SIGNAL
+ * directly!
+ * \sa cb_word_translation :|: dict_eng_set_callback() :|:
+ * dict_eng_search_word_translation() :|: ENGINE_WORD_LIST_SIGNAL
*/
-#define ENGINE_WORD_TRANSLATION_SIGNAL "on_word_translation_found"
+#define ENGINE_WORD_TRANSLATION_SIGNAL "on_word_translation_found"
+//------------------------------------------------------------------------------
+#define ENGINE_PROGRESS_OPTIMIZING_SIGNAL "on_progress_optimizing"
+//------------------------------------------------------------------------------
-#define ENGINE_PROGRESS_CACHING "on_progress_caching"
-//______________________________________________________________________________________________________
-// ******************************************************************************************************
-//************************************************************************** DEFINITIONS OF ENUMS TYPES:
-/** \brief Codes of flags used to auto optimizing dictionary file (passes to dict_eng_module_create() function as a parameter flags).
+//______________________________________________________________________________
+// *****************************************************************************
+//************************************************** DEFINITIONS OF ENUMS TYPES:
+//------------------------------------------------------------------------------
+/** \brief Codes of flags used to auto optimizing dictionary file.
*
- * - Enum type for flags used as a flags parameter for dict_eng_module_create() function.
+ * - Enum type for flags used as a flags parameter for dict_eng_module_create()
+ * function.
*/
typedef enum
{
- ENGINE_CREATE = 0, ///< :: flags says thatoptimization (any methods of optimalization) should be enabled. If optimization methods needs to make some files and these files exists, enigne will just use it (do not refresh).
- ENGINE_NO, ///< :: flags says that for this particular dictionary programm should disabled optimization.
- ENGINE_REFRESH ///< :: the same flags as ENGINE_CREATE, but tells dict_eng_module_create() function that even if file (or any resources) for optimizatione methods exists, they should be recreated/refreshed.
-}
-EngineOptimizationFlag;
-
+ /**
+ * :: flags says thatoptimization (any methodsof optimalization) should
+ * be enabled. If optimization methods needs to make some files and
+ * these files exists, enigne will just use it (do not refresh).
+ */
+ ENGINE_CREATE = 0,
+ /**
+ * :: flags says that for this particular dictionary programm should
+ * disable optimization.
+ */
+ ENGINE_NO,
+ /**
+ * :: the same flags as ENGINE_CREATE, but tells
+ * dict_eng_module_create() function that even if file (or any
+ * resources) for optimizatione methods exists, they should be
+ * recreated/refreshed.
+ */
+ ENGINE_REFRESH
+} EngineOptimizationFlag;
+//------------------------------------------------------------------------------
/** \brief Codes of possible errors which can occured while engine is working.
-*
-* - Enum type for errors' codes. One of this code is always in last error variable (variable 'last error' is invisible for programmers -
-* they should use function engine_error() and optionally engine_error_message() to get know what kind of error occured).
-*/
+ *
+ * - Enum type for errors' codes. One of this code is always in last error
+ * variable (variable 'last error' is invisible for programmers - they should
+ * use function engine_error() and optionally engine_error_message() to get know
+ * what kind of error occured).
+ */
typedef enum
{
- ENGINE_NO_ERROR = 0, ///< :: there was no error - last action successed
- ENGINE_WRONG_FILE, ///< :: file, which engine tried to read, has wrong format or it is corrupted.
- ENGINE_COULDNT_READ, ///< :: user do not have permission to read/open file, which engine tried to open/read.
- ENGINE_NO_FILE, ///< :: file, on which engine tried to operate, do not exist
- ENGINE_OUT_OF_MEMORY ///< :: while engine was working, "Out Of Memory" error occured
+ /**
+ * :: there was no error - last action successed
+ */
+ ENGINE_NO_ERROR = 0,
+ /**
+ * :: file, which engine tried to read, has wrong format or
+ * it is corrupted.
+ */
+ ENGINE_WRONG_FILE,
+ /**
+ * :: user do not have permission to read/open file, which engine tried
+ * to open/read.
+ */
+ ENGINE_COULDNT_READ,
+ /**
+ * :: file, on which engine tried to operate, do not exist
+ */
+ ENGINE_NO_FILE,
+ /**
+ * :: while engine was working, "Out Of Memory" error occured
+ */
+ ENGINE_OUT_OF_MEMORY
}
EngineStatus;
+//------------------------------------------------------------------------------
-//______________________________________________________________________________________________________
-// ******************************************************************************************************
-//********************************************************************* DEFINITIONS OF CALLBACK'S TYPES:
+//______________________________________________________________________________
+// *****************************************************************************
+//********************************************* DEFINITIONS OF CALLBACK'S TYPES:
+//------------------------------------------------------------------------------
/** \brief Type of callback functions for retrieving word list.
*
- * Function which is set by dict_eng_set_callback() to signal ENGINE_WORD_LIST_SIGNAL should be exactly this type.
+ * Function which is set by dict_eng_set_callback() to signal
+ * ENGINE_WORD_LIST_SIGNAL should be exactly this type.
+ *
* @param list :: <b>GArray*</b> - there will be all found words in this array
- * @param pattern :: <b>gchar*</b> - pattern to which we have been looking for word lists
- * @param error :: <b>EngineStatus</b> - error code; if everything was ok it is ENGINE_NO_ERROR
- * @param user_data :: <b>gpointer</b> - data set by user to be passing to each callback for ENGINE_WORD_LIST_SIGNAL signal
+ * @param pattern :: <b>gchar*</b> - pattern to which we have been looking for
+ * word lists
+ * @param error :: <b>EngineStatus</b> - error code; if everything was ok it is
+ * ENGINE_NO_ERROR
+ * @param user_data :: <b>gpointer</b> - data set by user to be passing to each
+ * callback for ENGINE_WORD_LIST_SIGNAL signal
*/
-typedef void (*cb_word_list)(GArray* list, gchar* pattern, gpointer user_data, EngineStatus error);
-
-
+typedef void (*cb_word_list)(GArray* list,
+ gchar* pattern,
+ gpointer user_data,
+ EngineStatus error);
+//------------------------------------------------------------------------------
/** \brief Type of callback functions for retrieving word's translation.
*
- * Function which is set by dict_eng_set_callback() to signal ENGINE_WORD_TRANSLATION_SIGNAL should be exactly this type.
+ * Function which is set by dict_eng_set_callback() to signal
+ * ENGINE_WORD_TRANSLATION_SIGNAL should be exactly this type.
+ *
* @param translation :: <b>gchar*</b> - translation of word <i>word</i>
* @param word :: <b>gchar*</b> - word which translation we already retrieved
- * @param error :: <b>EngineStatus</b> - error code; if everything was ok it is ENGINE_NO_ERROR
- * @param user_data :: <b>gpointer</b> - data set by user to be passing to each callback for ENGINE_WORD_TRANSLATION_SIGNAL signal
+ * @param error :: <b>EngineStatus</b> - error code; if everything was ok it is
+ * ENGINE_NO_ERROR
+ * @param user_data :: <b>gpointer</b> - data set by user to be passing to each
+ * callback for ENGINE_WORD_TRANSLATION_SIGNAL signal
*/
-typedef void (*cb_word_translation)(gchar* translation, gchar* word, gpointer user_data, EngineStatus error);
-
-
-
-typedef void (*cb_progress)(gdouble value, gpointer user_data, EngineStatus error);
-
-
-//______________________________________________________________________________________________________
-// ******************************************************************************************************
-//*************************************************************** DEFINITIONS OF BASIC FUNCTIONS TYPES:
-// /** \brief Predeclaration for structure Engine.
+typedef void (*cb_word_translation)(gchar* translation,
+ gchar* word,
+ gpointer user_data,
+ EngineStatus error);
+//------------------------------------------------------------------------------
+/** \brief Type of callback functions for updating progress bar.
+ *
+ * Function which is set by dict_eng_set_callback() to signal
+ * ENGINE_PROGRESS_OPTIMIZING_SIGNAL should be exactly this type.
+ *
+ * @param value :: <b>double</b> - current progres of process [0.0 - 1.0]
+ * @param user_data :: <b>gpointer</b> - data set by user to be passing to each
+ * callback for ENGINE_PROGRESS_OPTIMIZING_SIGNAL signal
+ * @param error :: <b>EngineStatus</b> - error code; if everything is ok it has
+ * ENGINE_NO_ERROR value
+ */
+typedef void (*cb_progress)(gdouble value,
+ gpointer user_data,
+ EngineStatus error);
+//------------------------------------------------------------------------------
+
+
+//______________________________________________________________________________
+// *****************************************************************************
+//**************************************** DEFINITIONS OF BASIC FUNCTIONS TYPES:
+//------------------------------------------------------------------------------
typedef struct _Engine Engine;
-
-/** \brief Type of function getting some chars from engin.
+/** \brief Type of function getting some chars from engine.
*
- * Function of this type should be used for functions which intention is to get some string from concrete dictionary.
- * @param engine :: <i>Engine*</i> - pointer to engine on which this functions has to work
- * @return <i><b>gchar*</b></i> :: chars which represents some information depends on concrete functions (e.g engine path etc.)
+ * Function of this type should be used for functions which intention is to get
+ * some string from concrete dictionary.
+ *
+ * @param engine :: <i>Engine*</i> - pointer to engine on which this functions
+ * has to work
+ * @return <i><b>gchar*</b></i> :: chars which represents some information
+ * depends on concrete functions (e.g engine path etc.)
*/
typedef gchar* (*getting_char)(Engine* engine);
-
-
+//------------------------------------------------------------------------------
/** \brief Type of function getting boolean statement from engine.
*
- * Function of this type should be used for functions which intention is to get boolean statement
- * from concrete dictionary (e.g. to get know if engine has cach file - is cashed).
- * @param engine :: <i>Engine*</i> - pointer to engine on which this functions has to work
- * @return <i><b>gboolean</b></i> :: gboolean statement which gives programmers some information about state of dictionary/engine
-*/
+ * Function of this type should be used for functions which intention is to get
+ * boolean statement from concrete dictionary (e.g. to get know if engine has
+ * cache file - is optimized).
+ *
+ * @param engine :: <i>Engine*</i> - pointer to engine on which this functions
+ * has to work
+ * @return <i><b>gboolean</b></i> :: gboolean statement which gives programmers
+ * some information about state of dictionary/engine
+ */
typedef gboolean (*getting_bool)(Engine* engine);
-
-/** \brief Type of function which hasn't got to return any value (only perform some actions).
+//------------------------------------------------------------------------------
+/** \brief Type of function which hasn't got to return any value.
*
- * Function of this type should be used for functions which intention is only to do something
- * on concrete dictionary (e.g. to make cache file, delete etc.).
- * @param engine :: <i>Engine*</i> - pointer to engine on which this functions has to work
- * @return nothing. Functions of this type should only perform some action - there is no result
+ * Function of this type should be used for functions which intention is only
+ * to do something on concrete dictionary (e.g. to make cache file etc).
+ *
+ * @param engine :: <i>Engine*</i> - pointer to engine on which this functions
+ * has to work
+ * @return nothing. Functions of this type should only perform some action -
+ * there is no result
*/
typedef void (*doing_only)(Engine* engine);
-
+//------------------------------------------------------------------------------
/** \brief Type of function which can find words list from dictionary.
-*
-* Function of this type should be used as a function for searching words list matching to pattern.
-* @param engine :: <i>Engine*</i> - pointer to engine on which this functions has to work
-* @param pattern :: <i>gchar*</i> - pointer to chars which describes pattern for searching words
-* @return nothing. This function do not return anything - result should be retrievwe by callbacks
-*/
-typedef void (*searching_word_list)(Engine* engine, gchar* pattern);
-
+ *
+ * Function of this type should be used as a function for searching words list
+ * matching to pattern.
+ *
+ * @param engine :: <i>Engine*</i> - pointer to engine on which this functions
+ * has to work
+ * @param pattern :: <i>gchar*</i> - pointer to chars which describes pattern
+ * for searching words
+ * @return nothing. This function do not return anything - result should be
+ * retrieve by callbacks
+ */
+typedef void (*searching_word_list)(Engine* engine, gchar* pattern);
+//------------------------------------------------------------------------------
/** \brief Type of function which can find word's translation from dictionary.
*
- * Functions of this type should be used as a function for searching word translation in concrete dictionary.
- * @param engine :: <i>Engine*</i> - pointer to engine on which this functions has to work
- * @param word :: <i>gchar*</i> - pointer to chars which tells what word's translation we are looking for
- * @return nothing. This function do not return anything - result should be retrievwe by callback
+ * Functions of this type should be used as a function for searching word
+ * translation in concrete dictionary.
+ *
+ * @param engine :: <i>Engine*</i> - pointer to engine on which this functions
+ * has to work
+ * @param word :: <i>gchar*</i> - pointer to chars which tells what word's
+ * translation we are looking for
+ * @return nothing. This function do not return anything - result should be
+ * retrieve by callback
*/
-typedef void (*searching_word_translation)(Engine* engine, gchar* word);
-
-/** \brief Type of function which can <i>translate</i> error code to descriptive message.
+typedef void (*searching_word_translation)(Engine* engine, gchar* word);
+//------------------------------------------------------------------------------
+/** \brief Type of function which can trans. error code to descriptive message.
*
- * Functions of this type should be used as <i>translator</i> from error code to meaningful message.
+ * Functions of this type should be used as <i>translator</i> from error code
+ * to meaningful message.
+ *
* @param error :: <i>EngineStatus</i> - error to which we want get description
- * @return <i><b>gchar*</b></i> :: chars which describes us what kind of error occured (e.g. "Dictionary file has wrong file format or it is corrupted.")
+ * @return <i><b>gchar*</b></i> :: chars which describes us what kind of error
+ * occured (e.g. "Dictionary file has wrong file format or it is corrupted.")
*/
-typedef gchar* (*error_to_message)(EngineStatus error);
-
-/** \brief Type of function which should be used to set new callback for some event.
+typedef gchar* (*error_to_message)(EngineStatus error);
+//------------------------------------------------------------------------------
+/** \brief Type of function which should be used to set callbacks for signals.
*
- * Functions of this type should be used as a <i>setter</i> for new callback functions
- * @param engine :: <i>Engine*</i> - pointer to engine on which this functions has to work
- * @param signal :: <i>gchars*</i> - pointer to chars which tell us what kind of event should new_functions handle (e.g. "word_list_found", "translation_found" etc.)
+ * Functions of this type should be used as a <i>setter</i> for new callback
+ * functions
+ *
+ * @param engine :: <i>Engine*</i> - pointer to engine on which this functions
+ * has to work
+ * @param signal :: <i>gchars*</i> - pointer to chars which tell us what kind
+ * of event should new_functions handle (e.g. "word_list_found",
+ * "translation_found" etc.)
* @param c_handler :: <i>gpointer</i> - new callback function
- * @param user_data :: <i>gpointer</i> - pointer do structure, which should be passed as a last argument when calling new mounted callback
- * @return <i><b>gpointer</b></i> :: gpointer to previous callback. If NULL there could be some error so programmers should check by engine_error() function if there was some
- * (if NULL and engine_error() return ENGINE_NO_ERROR that means that this callback was unused before).
- * \sa ENGINE_WORD_LIST_SIGNAL :|: ENGINE_WORD_TRANSLATION_SIGNAL :|: dict_eng_set_callback() :|: cb_word_list :|: cb_word_translation
-*/
-typedef gpointer (*setting_callbacks)(Engine* engine, gchar* signal, gpointer c_handler, gpointer user_data);
-
-
+ * @param user_data :: <i>gpointer</i> - pointer do structure, which should be
+ * passed as a last argument when calling new mounted callback
+ * @return <i><b>gpointer</b></i> :: gpointer to previous callback. If NULL
+ * there could be some error so programmers should check by engine_error()
+ * function if there was some (if NULL and engine_error() return
+ * ENGINE_NO_ERROR that means that this callback was unused before).
+ * \sa ENGINE_WORD_LIST_SIGNAL :|: ENGINE_WORD_TRANSLATION_SIGNAL :|:
+ * dict_eng_set_callback() :|: cb_word_list :|: cb_word_translation
+ */
+typedef gpointer (*setting_callbacks)(Engine* engine,
+ gchar* signal,
+ gpointer c_handler,
+ gpointer user_data);
+//------------------------------------------------------------------------------
/** \brief Type of function which can get some int value from dictionary.
*
- * Functions of this type should be used if programmer want to get some int value from dictionary.
- * @param enigne :: <i>Engine*</i> - pointer to engine on which this functions has to work
- * @return <i><b>gint</b></i> :: int value which user wanted to get from dictionary
+ * Functions of this type should be used if programmer want to get some int
+ * value from dictionary.
+ *
+ * @param enigne :: <i>Engine*</i> - pointer to engine on which this functions
+ * has to work
+ * @return <i><b>gint</b></i> :: int value which user wanted to get from
+ * dictionary
*/
typedef gint (*getting_int)(Engine* engine);
-
-
-//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+//------------------------------------------------------------------------------
typedef EngineStatus (*getting_status)(Engine* engine);
-typedef void (*setting_progress_seed)(Engine* engine, gchar* signal, gdouble seed);
-
-//______________________________________________________________________________________________________
-// ******************************************************************************************************
-//********************************************************* DEFINITIONS OF ADDITIONAL FUNCTIONS TYPES:
-/** \brief Additional functions type: Type of function which should be used to check if this module could handle some location (e.g filename, URI, etc.).
+//------------------------------------------------------------------------------
+typedef void (*setting_progress_seed)(Engine* engine,
+ gchar* signal,
+ gdouble seed);
+//------------------------------------------------------------------------------
+
+
+//______________________________________________________________________________
+// *****************************************************************************
+//*********************************** DEFINITIONS OF ADDITIONAL FUNCTIONS TYPES:
+//------------------------------------------------------------------------------
+/** \brief Additional functions type.
*
- * Functions of this type should be used to check if dictionary in location could be handled by this engine.
- * @param location :: <i>gchar*</i> - chars which describe location of dictionary to check
- * @return <i><b>gboolean</i></b> :: statement telling us if this module could or could not handle dictionary under location.
+ * Functions of this type should be used to check if dictionary in location
+ * could be handled by this engine.
+ *
+ * @param location :: <i>gchar*</i> - chars which describe location of
+ * dictionary to check
+ * @return <i><b>gboolean</i></b> :: statement telling us if this module could
+ * or could not handle dictionary under location.
*/
typedef gboolean (*checking_compatibiliti)(gchar* location);
-
-
-/** \brief Additional functions type: Type of function which should be used to get some chars from concrete module/engine (NOT DICTIONARY!).
+//------------------------------------------------------------------------------
+/** \brief Additional functions type.
*
- * Functions of this type should be used to get some descriptions from engine/module.
- * Information retrievs by this kind of functions are global for module (e.g: description of handles fromat, description of module etc.).
+ * Functions of this type should be used to get some descriptions from
+ * engine/module. Information retrievs by this kind of functions are global for
+ * module (e.g: description of handles fromat, description of module etc.).
+ *
* @return <i><b>gchar*</i></b> :: chars which we wanted
*/
-typedef gchar* (*getting_chars_engine)(void);
-
-/** \brief Additional functions type: Type of function which should be used to open (create) new dictionary from location.
+typedef gchar* (*getting_chars_engine)(void);
+//------------------------------------------------------------------------------
+/** \brief Additional functions type.
*
* Functions of this type should be used to opening dictionary.
- * @param location :: <i>gchar*</i> - chars which describe where is the dictionary which we want to open
- * @param flags :: <i>EngineOptimizationFlag</i> - flags to initialize/use optimization methods for opening dictionary.
- * @return <i><b>gpointer</i></b> ::pointer to opened Engine. If NULL there was some error - programmers should check error type by calling engine_error() function.
+ * @param location :: <i>gchar*</i> - chars which describe where is the
+ * dictionary which we want to open
+ * @param flags :: <i>EngineOptimizationFlag</i> - flags to initialize/use
+ * optimization methods for opening dictionary.
+ * @return <i><b>gpointer</i></b> ::pointer to opened Engine. If NULL there was
+ * some error - programmers should check error type by calling
+ * engine_error() function.
*/
-typedef Engine* (*creating_engine)(gchar* location, EngineOptimizationFlag flags, cb_progress progress_handler, gpointer progress_data, gdouble seed);
-
-
+typedef Engine* (*creating_engine)(gchar* location,
+ EngineOptimizationFlag flags,
+ cb_progress progress_handler,
+ gpointer progress_data,
+ gdouble seed);
+//------------------------------------------------------------------------------
/** \brief General dictionary structure.
-*
-* This structure contains every data which are needed to make dictionary working. Data of dictionary are
-* invisible for user of finnal module. User can operate on dictionary with functions to which there are pointers
-* in this structure also. engine_data is for module programmer use only. Programmer of module can put there any
-* data he want. He should not give end user any information about engine_data structure.
-*/
+ *
+ * This structure contains every data which are needed to make dictionary
+ * working. Data of dictionary are invisible for user of finnal module. User can
+ * operate on dictionary with functions to which there are pointers in this
+ * structure also. engine_data is for module programmer use only. Programmer of
+ * module can put there any data he want. He should not give end user any
+ * information about engine_data structure.
+ */
struct _Engine
{
- void (*engine_set_auto_free)(Engine* engine, gboolean state);
-
-
- /** \brief Getting location of dictionary.
- *
- * User can use this function if want to get location of concrete dictionary.
- * \sa getting_char
- */
- getting_char engine_location;
-
- /** \brief Getting information if this dictionary is cached.
- *
- * User can use this function if want to know is dictionary cached actually.
- * \sa getting_bool
- */
- getting_bool engine_is_optimized;
-
- /** \brief Making cache file for dictionary.
- *
- * User can use this function if want to make cache file for concrete dictionary.
- * \sa doing_only
- */
- doing_only engine_optimize;
-
- /** \brief Searching word list.
- *
- * User call this function to start searching for word list.
- * \sa searching_word_list
- */
- searching_word_list engine_search_word_list;
-
- /** \brief Searching word's translation.
- *
- * User call this function to start searching for word's translation.
- * \sa searching_word_translation
- */
- searching_word_translation engine_search_word_translation;
-
- /** \brief Searching word's translation (preformatted HTML).
- *
- * User call this function to start searching for word's translation. It differs from engine_search_word_translation
- * that it returns preformatted string (HTML format).
- * \sa searching_word_translation
- */
- searching_word_translation engine_search_word_translation_extended;
-
- /** \brief Close dictionary.
- *
- * User call this if work with dictionary is finished and there is no need to keep this further working.
- * \sa doing_only
- */
- doing_only engine_close;
-
- /** \brief Functions return laste error which occured in dictionary.
- *
- * Programmer should use this function after each action to check if there was not any errors.
- * \sa getting_int
- */
- getting_status engine_error;
-
- /** \brief <i>Tranlsate</i> error code to meaningful message.
- *
- * Programmer can call this function if want to get meaningful message describes concrete error code
- * \sa error_to_message
- */
- error_to_message engine_error_message;
-
- /** \brief Function to setting any callback for this dictionary.
- *
- * This function can be used to set some callback function for concrete dictionary. Programmer
- * should always set callback "word_list_found" and "word_translation_found". Developers of
- * new modules should also define for what kind of event end user will be able to set callback.
- */
- setting_callbacks engine_set_callback;
-
-
- setting_progress_seed engine_set_progress_seed;
-
- /** \brief Module's private data area. Used only by module programmer.
- *
- * Here module programmer should keep their own data (e.g. some data for searching optimalization etc.).
- * Programmer whose only using module, should not use engine_data at all.
- */
- gpointer engine_data;
+ void (*engine_set_auto_free)(Engine* engine, gboolean state);
+
+
+ /** \brief Getting location of dictionary.
+ *
+ * User can use this function if want to get location of concrete
+ * dictionary.
+ * \sa getting_char
+ */
+ getting_char engine_location;
+
+ /** \brief Getting information if this dictionary is cached.
+ *
+ * User can use this function if want to know is dictionary cached
+ * actually.
+ * \sa getting_bool
+ */
+ getting_bool engine_is_optimized;
+
+ /** \brief Making cache file for dictionary.
+ *
+ * User can use this function if want to make cache file for concrete
+ * dictionary.
+ * \sa doing_only
+ */
+ doing_only engine_optimize;
+
+ /** \brief Searching word list.
+ *
+ * User call this function to start searching for word list.
+ * \sa searching_word_list
+ */
+ searching_word_list engine_search_word_list;
+
+ /** \brief Searching word's translation.
+ *
+ * User call this function to start searching for word's translation.
+ * \sa searching_word_translation
+ */
+ searching_word_translation engine_search_word_translation;
+
+ /** \brief Searching word's translation (preformatted HTML).
+ *
+ * User call this function to start searching for word's translation.
+ * It differs from engine_search_word_translation that it returns
+ * preformatted string (HTML format).
+ * \sa searching_word_translation
+ */
+ searching_word_translation engine_search_word_translation_extended;
+
+ /** \brief Close dictionary.
+ *
+ * User call this if work with dictionary is finished and there is no
+ * need to keep this further working.
+ * \sa doing_only
+ */
+ doing_only engine_close;
+
+ /** \brief Functions return laste error which occured in dictionary.
+ *
+ * Programmer should use this function after each action to check if
+ * there was not any errors.
+ * \sa getting_int
+ */
+ getting_status engine_error;
+
+ /** \brief <i>Tranlsate</i> error code to meaningful message.
+ *
+ * Programmer can call this function if want to get meaningful message
+ * describes concrete error code
+ * \sa error_to_message
+ */
+ error_to_message engine_error_message;
+
+ /** \brief Function to setting any callback for this dictionary.
+ *
+ * This function can be used to set some callback function for concrete
+ * dictionary. Programmer should always set callback "word_list_found"
+ * and "word_translation_found". Developers of new modules should also
+ * define for what kind of event end user will be able to set callback.
+ */
+ setting_callbacks engine_set_callback;
+
+
+ setting_progress_seed engine_set_progress_seed;
+
+ /** \brief Module's private data area. Used only by module programmer.
+ *
+ * Here module programmer should keep their own data (e.g. some data for
+ * searching optimalization etc.). Programmer whose only using module,
+ * should not use engine_data at all.
+ */
+ gpointer engine_data;
};
-
-/** \brief Structure that has, as a members, pointers to helpfull functions for programmer.
-*
-* There are pointers to some functions in this structure. Programmer whom using module could use it to
-* get some useful informationa about module (e.g: format handled by module, it's version etc.). The most important
-* functions are: \n
-* engine_check() - to check if this module can handle concrete location \n
-* engine_open() - to open location
-*/
+//------------------------------------------------------------------------------
+/** \brief Structure that has pointers to helpfull functions for programmer.
+ *
+ * There are pointers to some functions in this structure. Programmer whom using
+ * module could use it to get some useful informationa about module (e.g: format
+ * handled by module, it's version etc.). The most important functions are: \n
+ * engine_check() - to check if this module can handle concrete location \n
+ * engine_open() - to open location
+ */
typedef struct {
-
- /** \brief Function to check compatibility beetwen module and location.
- *
- * Helps programmer to check if this concrete module was designed to work with dictionary under location passed as a argument to this function
- * \sa checking_compatibiliti
- */
- checking_compatibiliti engine_check;
-
- /** \brief Function to get some short description of module/engine.
- *
- * This function returns short description of module, to make possible displaying for end user what kind of module he is useing.
- * \sa getting_chars_engine
- */
- getting_chars_engine engine_description;
-
- /** \brief Function to get module's format.
- *
- * This function returns format of dictionary which this module can handle.
- * \sa getting_chars_engine
- */
- getting_chars_engine engine_format;
-
- /** \brief Function to get version of module.
- *
- * This functions return version of this module/engine.
- * \sa getting_chars_engine
- */
- getting_chars_engine engine_version;
-
- /** \brief Function to open/create new dictionary.
- *
- * This functions allow programmer to open/create module from concrete location.
- * \sa creating_engine
- */
- creating_engine engine_create;
+
+ /** \brief Function to check compatibility beetwen module and location.
+ *
+ * Helps programmer to check if this concrete module was designed to work
+ * with dictionary under location passed as a argument to this function.
+ * \sa checking_compatibiliti
+ */
+ checking_compatibiliti engine_check;
+
+ /** \brief Function to get some short description of module/engine.
+ *
+ * This function returns short description of module, to make possible
+ * displaying for end user what kind of module he is using.
+ * \sa getting_chars_engine
+ */
+ getting_chars_engine engine_description;
+
+ /** \brief Function to get module's format.
+ *
+ * This function returns format of dictionaries which this module handles
+ * \sa getting_chars_engine
+ */
+ getting_chars_engine engine_format;
+
+ /** \brief Function to get version of module.
+ *
+ * This functions return version of this module/engine.
+ * \sa getting_chars_engine
+ */
+ getting_chars_engine engine_version;
+
+ /** \brief Function to open/create new dictionary.
+ *
+ * This functions allow programmer to open/create module from concrete
+ * location.
+ * \sa creating_engine
+ */
+ creating_engine engine_create;
}
EngineModule;
-
-
-/** \brief Additional functions type: type of functions wich helps load others function from module.
+//------------------------------------------------------------------------------
+/** \brief Additional functions type.
*
- * There should be in each module exactly one function of this type named: engine_global_functions. This function
- * makes easier to load dynamically module. For doing this then you need only to mapped only this one function
- * and the rest will be avaiable for you from returned structure EngineModule.
- * @return <i><b>EngineModule</b></i> :: structure EngineModule from which you can call next functions
+ * There should be in each module exactly one function of this type named:
+ * engine_global_functions. This function makes easier to load dynamically
+ * module. For doing this then you need only to mapped only this one function
+ * and the rest will be avaiable from returned structure EngineModule.
+ *
+ * @return <i><b>EngineModule</b></i> :: structure EngineModule from which you
+ * can call next functions
* \sa engine_global_functions()
*/
typedef EngineModule (*getting_additional)(void);
-
-/** \brief Function that helps programmer to load basic functions from engine's module.
+//------------------------------------------------------------------------------
+/** \brief Function that helps programmer to load basic functions from module.
*
- * This function helps programmers to dynamically load module to their programms. Only this function needed to be
- * mapped from *.so file. Rest of function are in returned structure EngineModule. User of module could mapped himslef
- * others functions from concrete modules, but it is not recommended as far as developers of module could, in fact, give different
- * names for functions. In structure EngineModule names will be always the same. NOTE for module developer: this function should be always defined in your
- * code, to help next programmers whose will be using yours module in theirs own programms.
- * @return <i><b>EngineModule</b></i> :: Structure EngineModule which members are functions for basic operations for this module
+ * This function helps programmers to dynamically load module to their
+ * programms. Only this function needed to be mapped from *.so file. Rest of
+ * function are in returned structure EngineModule. User of module could mapped
+ * himslef others functions from concrete modules, but it is not recommended as
+ * far as developers of module could, in fact, give different names for
+ * functions. In structure EngineModule names will be always the same. \n
+ * NOTE for module developer: this function should be always defined in your
+ * code, to help next programmers whose will be using yours module in theirs own
+ * programms.
+ *
+ * @return <i><b>EngineModule</b></i> :: Structure EngineModule which members
+ * are functions for basic operations for this module
*/
extern EngineModule engine_global_functions(void);
+//------------------------------------------------------------------------------
+
#ifdef __cplusplus
-}
-#endif // END OF: extern "C" {
-#endif // END OF: _DICTIONARY_ENGINE_BASE
+}
+#endif // END OF: extern "C" {
+
+#endif // END OF: _DICTIONARY_ENGINE_BASE
-/************************************************************************************************
+/*******************************************************************************
This file is part of WhiteStork.
WhiteStork is free software; you can redistribute it and/or modify
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Copyright 2006 ComArch S.A.
-************************************************************************************************/
+*******************************************************************************/
#ifndef _DICTIONARY_ENGINE_XDXF
#define _DICTIONARY_ENGINE_XDXF
-#include <stdio.h>
-#include <expat.h>
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+//______________________________________________________________________________
+// *****************************************************************************
+//************************************************************* HEADERS SECTION:
+//------------------------------------------------------------------------------
+// headers with unix types/functions - onl for timers
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <fcntl.h>
#include <unistd.h>
-
-
+//------------------------------------------------------------------------------
+// header with GLIB definitions/functions/types
+#include <glib.h>
+//------------------------------------------------------------------------------
+// header with gnome-vfs - recommended I/O API for maemo
+#include <libgnomevfs/gnome-vfs.h>
+//------------------------------------------------------------------------------
+// header with expat - XML Parser API
+#include <expat.h>
+//------------------------------------------------------------------------------
+// header wit engine API
#include "dictionary_engine.h"
+//------------------------------------------------------------------------------
+
-#define DIC_ENG_VERSION "0.1a"
+//______________________________________________________________________________
+// *****************************************************************************
+//********************************************************* DEFINITIONS SECTION:
+//------------------------------------------------------------------------------
+// definitions for timer function - flag telling if we want to start or stop
+// timing
+#define TIMER_START TRUE
+#define TIMER_STOP FALSE
+//------------------------------------------------------------------------------
+// definitions of version and format which engine handles
+#define DIC_ENG_VERSION "0.1b"
#define DIC_ENG_FORMAT "XDXF"
+//------------------------------------------------------------------------------
+// defines lenght of buffers for particular functions in engine which needs
+// big buffers
+#define DICT_CACHEING_BUFF_SIZE 16*1024
+#define DICT_SEARCHING_WORD_LIST_BUFF_SIZE 16*1024
+#define DICT_SEARCHING_WORD_TRAN_BUFF_SIZE 16*1024
+//------------------------------------------------------------------------------
+// maximum length of word possible to find in any dictionary
+#define DICT_MAX_WORD_LENGTH 512
+//------------------------------------------------------------------------------
+// macro for "printing" gboolean statement - "TRUE" or "FALSE"
+#define PRINT_STATE(state) ( (state) ? "TRUE" : "FALSE" )
+//------------------------------------------------------------------------------
-#define _BUFFER_CHECK_SIZE 1024
-#define _BUFFER_CACHEING_SIZE 1024
-#define _BUFFER_INDEX_SIZE 16*1024
+//______________________________________________________________________________
+// *****************************************************************************
+//****************************************** DATA STRUCTURE DEFINITIONS SECTION:
+//------------------------------------------------------------------------------
+/** \brief Structure used while dict_eng_module_check() is working.
+ */
struct _XDXFCheckingData {
- int deep;
- gboolean good;
+ gboolean further;
+ gboolean good;
+ guint deep;
+};
+typedef struct _XDXFCheckingData XDXFCheckingData;
+//------------------------------------------------------------------------------
+/** \brief Structure to help parse xdxf file for searching words list.
+ */
+struct _XDXFWordsListData {
+ gchar* last_word;
+ gchar* pattern;
+ guint pattern_len;
+ guint last_word_length;
+ GArray* result;
+ guint one_word;
+ gboolean cont;
+};
+typedef struct _XDXFWordsListData XDXFWordsListData;
+//------------------------------------------------------------------------------
+/** \brief Structure to help parse xdxf file for searching word's translation.
+ */
+struct _XDXFWordsTransData {
+ gchar* last_word;
+ gchar* word;
+ guint word_len;
+ guint last_word_length;
+ gchar* translation;
+ guint one_word;
+ gboolean cont;
+ gulong last_start;
+ XML_Parser* parser;
+ gboolean found;
+ GnomeVFSHandle* xdxf;
+};
+typedef struct _XDXFWordsTransData XDXFWordsTransData;
+//------------------------------------------------------------------------------
+/** \brief Structure to help make optimization possible
+ */
+struct _XDXFCacheData {
+ gchar* buffer;
+ long last_start;
+ long last_stop;
+ long last_length;
+ GnomeVFSHandle* cache;
+ XML_Parser parser;
+ int state;
+ long buffer_length;
};
-typedef struct _XDXFCheckingData XDXFCheckingData;
-
-struct _XDXFChacheData {
- gchar* buffer;
- long last_start;
- long last_stop;
- long last_length;
- int output_file;
- XML_Parser p;
- int state;
+typedef struct _XDXFCacheData XDXFCacheData;
+//------------------------------------------------------------------------------
+/** \brief Internal data structure for representing part of file.
+ */
+struct _FilePart {
+ guint offset;
+ guint length;
};
-typedef struct _XDXFChacheData XDXFChacheData;
+typedef struct _FilePart FilePart;
+//------------------------------------------------------------------------------
+/** \brief Internal data structure of XDXF Engine.
+ */
+struct _XDXFData {
+ GnomeVFSHandle* xdxf;
+ GnomeVFSHandle* cache;
+ gchar* dict_path;
+ EngineStatus last_error;
+ gboolean auto_free;
+ cb_progress cb_progress_caching;
+ gpointer cb_progress_caching_data;
+ gdouble cb_progress_caching_seed;
-struct _XDXFData {
- gchar* location;
- int xdxf;
- int cache;
-
- gpointer word_list;
- gpointer translation;
- gpointer cache_progress;
-
- EngineStatus error;
- cb_word_list callback_on_word_list;
- cb_word_translation callback_on_word_translation;
- cb_cache_update callback_caching_progress;
+ cb_progress cb_progress_word_list;
+ gpointer cb_progress_word_list_data;
+ gdouble cb_progress_word_list_seed;
+
+ cb_progress cb_progress_word_trans;
+ gpointer cb_progress_word_trans_data;
+ gdouble cb_progress_word_trans_seed;
+
+ cb_word_list cb_search_word_list;
+ gpointer cb_search_word_list_data;
+
+ cb_word_translation cb_search_word_trans;
+ gpointer cb_search_word_trans_data;
};
-typedef struct _XDXFData XDXFData;
+typedef struct _XDXFData XDXFData;
+//------------------------------------------------------------------------------
-// helpfull functions
-gdouble time_info(struct timeval *y, gchar* message);
+//______________________________________________________________________________
+// *****************************************************************************
+//*************************************************** PARSING FUNCTIONS SECTION:
+//------------------------------------------------------------------------------
+// while is_xdxf_file() is working
+static void is_xdxf_file_start(void *data,
+ const char *el,
+ const char **attr);
+static void is_xdxf_file_end(void *data, const char *el);
+//------------------------------------------------------------------------------
+// while dict_eng_search_word_list() is working
+static void search_word_list_start(void *data,
+ const char *el,
+ const char **attr);
+static void search_word_list_end(void *data, const char *el);
+static void search_word_list_text(void *data, const XML_Char *txt, int len);
+//------------------------------------------------------------------------------
+// // while dict_eng_search_word_translation() is working
+static void search_word_trans_start(void *data,
+ const char *el,
+ const char **attr);
+static void search_word_trans_end(void *data, const char *el);
+static void search_word_trans_text(void *data,
+ const XML_Char *txt,
+ int len);
+//------------------------------------------------------------------------------
-// declarations of functions
-gboolean check_compatibilit_xdxf(gchar* location);
-gchar* get_engine_descritpion();
-gchar* get_engine_format();
-gchar* get_engine_version();
-gchar* get_location(Engine* engine);
-gboolean is_cached(Engine* engine);
-void do_cache(Engine* engine);
-void search_word_list(Engine* engine, gchar* pattern);
-void search_word_translation(Engine* engine, gchar* word);
-void search_word_translationHTML(Engine* engine, gchar* word);
-gchar* error_message(EngineStatus error);
+//______________________________________________________________________________
+// *****************************************************************************
+//************************************************ ADDITIONAL FUNCTIONS SECTION:
+//------------------------------------------------------------------------------
+// returning concrete part of file
+static gchar* read_file_part(FilePart* part, GnomeVFSHandle* file);
+//------------------------------------------------------------------------------
+// convert string to proper path name (no filename, no "/" at the ned, file \
+// exist)
+static gchar* string_to_path(gchar** string);
+//------------------------------------------------------------------------------
+// tells if file is in XDXF format (file should exist)
+static gboolean is_xdxf_file(gchar* file);
+//------------------------------------------------------------------------------
+// start/stop timers - returnet -1.0 if we start or seconds passed from start
+// if we want to stop timer
+static double timer(gboolean start, gchar* message);
+//------------------------------------------------------------------------------
+// return size of files
+static guint64 get_file_size(GnomeVFSHandle* file);
+//------------------------------------------------------------------------------
+// return how many records (from cache file) are in current buffer a with length
+// length.
+static guint get_max_length(gchar* a, guint length);
+//------------------------------------------------------------------------------
+// return translation of word using cache file
+static gchar* word_translation_cache(XDXFData* data, gchar* word);
+//------------------------------------------------------------------------------
+// return translation of word but using only xdxf dictionary file
+static gchar* word_translation_xdxf(XDXFData* data, gchar* word);
+//------------------------------------------------------------------------------
-gpointer set_callbacks(Engine* engine, gchar* event, gpointer new_funtions, gpointer user_data);
-void close_engine(Engine* engine);
-Engine* create_engine(gchar* location, EngineOptimizationFlag auto_cache);
-EngineModule engine_global_functions();
+// return translation of word using cache file
+static void word_list_cache(XDXFData* data, gchar* pattern, GArray* result);
+//------------------------------------------------------------------------------
+// return translation of word but using only xdxf dictionary file
+static void word_list_xdxf(XDXFData* data, gchar* pattern, GArray* result);
+//------------------------------------------------------------------------------
+
+
+//______________________________________________________________________________
+// *****************************************************************************
+//****************************************************** MAIN FUNCTIONS SECTION:
+//------------------------------------------------------------------------------
+// implementation of dict_eng_module_check(module,location) function
+gboolean engine_check(gchar* location);
+//------------------------------------------------------------------------------
+// implementation of dict_eng_module_get_description(module) function
+gchar* engine_description();
+//------------------------------------------------------------------------------
+// implementation of dict_eng_module_get_format(module) function
+gchar* engine_format();
+//------------------------------------------------------------------------------
+// implementation of dict_eng_module_get_version(module) function
+gchar* engine_version();
+//------------------------------------------------------------------------------
+// implementation of dict_eng_module_create(module,location,flags) and
+// dict_eng_module_create_ext(module,location,flags) functions
+Engine* engine_create(gchar* location,
+ EngineOptimizationFlag flags,
+ cb_progress progress_handler,
+ gpointer progress_data,
+ gdouble seed);
+//------------------------------------------------------------------------------
+// implementation of dict_eng_destroy(engine) function
+void engine_close(Engine* engine);
+//------------------------------------------------------------------------------
+// implementation of dict_eng_get_location(engine) function
+gchar* engine_location(Engine* engine);
+//------------------------------------------------------------------------------
+// implementation of dict_eng_optimize(engine) function
+void engine_optimize(Engine* engine);
+//------------------------------------------------------------------------------
+// implementation of dict_eng_is_optimized( engine ) function
+gboolean engine_is_optimized(Engine* engine);
+//------------------------------------------------------------------------------
+// implementation of dict_eng_set_auto_free(engine, state) function
+void engine_set_auto_free(Engine* engine, gboolean state);
+//------------------------------------------------------------------------------
+// implementation of dict_eng_set_callback(engine,signal,c_handler,data)
+// function
+gpointer engine_set_callbacks(Engine* engine,
+ gchar* event,
+ gpointer c_handler,
+ gpointer user_data);
+//------------------------------------------------------------------------------
+// implementation of dict_eng_set_progress_seed(engine, signal, val) function
+void engine_set_progress_seed(Engine* engine,
+ gchar* signal,
+ gdouble seed);
+//------------------------------------------------------------------------------
+// implementation ofdict_eng_search_word_list(engine,pattern) function
+void engine_search_word_list(Engine* engine, gchar* pattern);
+//------------------------------------------------------------------------------
+// implementation of dict_eng_search_word_translation(engine,word) function
+void engine_search_word_translation(Engine* engine, gchar* word);
+//------------------------------------------------------------------------------
+// implementation of dict_eng_search_word_translation_extended(engine,word)
+// function
+void engine_search_word_translation_extended(Engine* engine,
+ gchar* word);
+//------------------------------------------------------------------------------
+// implementation of dict_eng_get_last_state(engine) function
+EngineStatus engine_error(Engine* engine);
+//------------------------------------------------------------------------------
+// implementation of dict_eng_state_message(error) function
+gchar* engine_error_message(EngineStatus error);
+//------------------------------------------------------------------------------
+// implementation of engine_global_functions(void) function
+EngineModule engine_global_functions();
+
+#ifdef __cplusplus
+}
+#endif
#endif