[voikko-devel] Ehdotus: lisäys libvoikkoon

Hannu Väisänen hvaisane at joyx.joensuu.fi
Wed Jan 10 08:06:10 EET 2007


Libvoikon voikko_init* -funktiot alustavat myös malagan. Se on
järkevää oikoluvussa, mutta jos libvoikkoa käyttää jossain muussa
ohjelmassa (esim. Sukijassa tunnistettaessa väärin kirjoitettuja
sanoja), libvoikko olisi voitava alustaa ilman malagaa. Tätä varten
ehdotan libvoikkoon lisättäväksi kaksi funktiota

voikko_init_with_path_without_malaga
voikko_terminate_without_malaga

Ne toimivat samalla tavalla kuin funktiot voikko_init_with_path ja
voikko_terminate, mutta eivät tee mitään malagalle.

Seuraava projekti: subversionin opettelu. (-:


Libvoikon diffi:



diff -c -r libvoikko-1.2/ChangeLog libvoikko-1.2-hv/ChangeLog
*** libvoikko-1.2/ChangeLog	2006-11-02 15:33:43.000000000 +0200
--- libvoikko-1.2-hv/ChangeLog	2007-01-09 20:31:57.000000000 +0200
***************
*** 1,3 ****
--- 1,8 ----
+ 2007-01-09 Hannu VÀisÀnen  <firstname.lastname at joensuu.fi>
+ 
+ 	* Add functions voikko_init_with_path_without_malaga
+ 	  and voikko_terminate_without_malaga.
+ 
  2006-10-27 Harri PitkÀnen  <hatapitk at iki.fi>
  
  	* Implement version checking for malaga project files.
Only in libvoikko-1.2-hv: config.h
Only in libvoikko-1.2-hv: config.log
Only in libvoikko-1.2-hv: config.status
Only in libvoikko-1.2-hv: libtool
Only in libvoikko-1.2-hv: Makefile
Only in libvoikko-1.2-hv/src: .deps
Only in libvoikko-1.2-hv/src: .libs
Only in libvoikko-1.2-hv/src: libvoikko.la
Only in libvoikko-1.2-hv/src: Makefile
Only in libvoikko-1.2-hv/src: porting.lo
Only in libvoikko-1.2-hv/src: porting.o
Only in libvoikko-1.2-hv/src: voikko_charset.lo
Only in libvoikko-1.2-hv/src: voikko_charset.o
diff -c -r libvoikko-1.2/src/voikko.h libvoikko-1.2-hv/src/voikko.h
*** libvoikko-1.2/src/voikko.h	2006-11-02 15:33:43.000000000 +0200
--- libvoikko-1.2-hv/src/voikko.h	2006-12-23 16:04:45.000000000 +0200
***************
*** 139,144 ****
--- 139,161 ----
                                     int cache_size, const char * path);
  
  /**
+  * Initialises the library for use in the specified language, adding an extra directory
+  * to the standard dictionary search path. Do not initialise malaga. You must
+  * initialise malaga separately.
+  * @param handle after succesful initialisation handle will contain a handle that
+  *        refers to this particular instance of voikko
+  * @param langcode the language code, for example "fi_FI"
+  * @param cache_size size of the spellchecker cache. This can be -1 (no cache) or
+  *        >= 0 ( size in bytes = 2^cache_size * (6544*sizeof(wchar_t) + 1008) ).
+  * @param path path to a directory from which dictionary files should be searched
+  *        first before looking into the standard dictionary locatiosn
+  * @return null, if initialisation completed without error, otherwise a pointer
+  *         to a string describing the error
+  */
+ const char * voikko_init_with_path_without_malaga(int * handle, const char * langcode,
+                                                   int cache_size, const char * path);
+ 
+ /**
   * Terminates an instance of voikko.
   * @param handle voikko instance
   * @return true, if termination succeeded, otherwise false
***************
*** 146,151 ****
--- 163,176 ----
  int voikko_terminate(int handle);
  
  /**
+  * Terminates an instance of voikko without terminating malaga.
+  * You must terminate malaga separately.
+  * @param handle voikko instance
+  * @return true, if termination succeeded, otherwise false
+  */
+ int voikko_terminate_without_malaga(int handle);
+ 
+ /**
   * Sets a boolean option.
   * @param handle voikko instance
   * @param option option name
Only in libvoikko-1.2-hv/src: voikkohyphenate
Only in libvoikko-1.2-hv/src: voikko_hyphenate.lo
Only in libvoikko-1.2-hv/src: voikko_hyphenate.o
Only in libvoikko-1.2-hv/src: voikkohyphenate-porting.o
Only in libvoikko-1.2-hv/src: voikkohyphenate-voikkohyphenate.o
diff -c -r libvoikko-1.2/src/voikko_setup.c libvoikko-1.2-hv/src/voikko_setup.c
*** libvoikko-1.2/src/voikko_setup.c	2006-11-02 15:33:43.000000000 +0200
--- libvoikko-1.2-hv/src/voikko_setup.c	2006-12-23 15:59:18.000000000 +0200
***************
*** 176,181 ****
--- 176,246 ----
  	return 0;
  }
  
+ const char * voikko_init_with_path_without_malaga(int * handle, const char * langcode,
+                                                   int cache_size, const char * path) {
+ 	char * project;
+ 	voikko_options.ignore_dot = 0;
+ 	voikko_options.ignore_numbers = 0;
+ 	voikko_options.ignore_uppercase = 0;
+ 	voikko_options.accept_first_uppercase = 1;
+ 	voikko_options.accept_all_uppercase = 1;
+ 	voikko_options.no_ugly_hyphenation = 0;
+ 	voikko_options.intersect_compound_level = 1;
+ 	voikko_options.encoding = "UTF-8";
+ 	voikko_options.cache_size = cache_size;
+ 	
+ 	project = malloc(1024);
+ 	if (project == 0) return "Out of memory";
+ 	
+ 	/* FIXME: Temporary hack needed for MT unsafe malaga library */
+ 	if (voikko_handle_count++ > 0) return "Maximum handle count exceeded";
+ 	
+ 	/* Initialise converters */
+ 	voikko_options.iconv_ucs4_utf8 = iconv_open("UTF-8", "WCHAR_T");
+ 	if (voikko_options.iconv_ucs4_utf8 == (iconv_t) -1) {
+ 		free(project);
+ 		return "iconv_open(\"UTF-8\", \"WCHAR_T\") failed";
+ 	}
+ 	voikko_options.iconv_utf8_ucs4 = iconv_open("WCHAR_T", "UTF-8");
+ 	if (voikko_options.iconv_utf8_ucs4 == (iconv_t) -1) {
+ 		iconv_close(voikko_options.iconv_ucs4_utf8);
+ 		free(project);
+ 		return "iconv_open(\"WCHAR_T\", \"UTF-8\") failed";
+ 	}
+ 	voikko_options.iconv_ucs4_ext = iconv_open(voikko_options.encoding, "WCHAR_T");
+ 	if (voikko_options.iconv_ucs4_ext == (iconv_t) -1) {
+ 		iconv_close(voikko_options.iconv_utf8_ucs4);
+ 		iconv_close(voikko_options.iconv_ucs4_utf8);
+ 		free(project);
+ 		return "iconv_open(voikko_options.encoding, \"WCHAR_T\") failed";
+ 	}
+ 	voikko_options.iconv_ext_ucs4 = iconv_open("WCHAR_T", voikko_options.encoding);
+ 	if (voikko_options.iconv_ext_ucs4 == (iconv_t) -1) {
+ 		iconv_close(voikko_options.iconv_ucs4_ext);
+ 		iconv_close(voikko_options.iconv_utf8_ucs4);
+ 		iconv_close(voikko_options.iconv_ucs4_utf8);
+ 		free(project);
+ 		return "iconv_open(\"WCHAR_T\", voikko_options.encoding) failed";
+ 	}
+ 	
+ 	if (cache_size >= 0) {
+ 		voikko_options.cache = malloc(6544 * sizeof(wchar_t) << cache_size);
+ 		if (voikko_options.cache) {
+ 			voikko_options.cache_meta = malloc(1008 << cache_size);
+ 			if (voikko_options.cache_meta)
+ 				memset(voikko_options.cache_meta, 0, 1008 << cache_size);
+ 			else {
+ 				free(voikko_options.cache);
+ 				voikko_options.cache = 0;
+ 			}
+ 			memset(voikko_options.cache, 0, 6544 * sizeof(wchar_t) << cache_size);
+ 		}
+ 	}
+ 	else voikko_options.cache = 0;
+ 	*handle = voikko_handle_count;
+ 	return 0;
+ }
+ 
  int voikko_terminate(int handle) {
  	if (handle == 1 && voikko_handle_count > 0) {
  		voikko_handle_count--;
***************
*** 196,201 ****
--- 261,285 ----
  	else return 0;
  }
  
+ int voikko_terminate_without_malaga(int handle) {
+ 	if (handle == 1 && voikko_handle_count > 0) {
+ 		voikko_handle_count--;
+ 		iconv_close(voikko_options.iconv_ext_ucs4);
+ 		iconv_close(voikko_options.iconv_ucs4_ext);
+ 		iconv_close(voikko_options.iconv_utf8_ucs4);
+ 		iconv_close(voikko_options.iconv_ucs4_utf8);
+ 		/*int c = 0;
+ 		for (int i = 0; i < 1*1008; i++) if (voikko_options.cache_meta[i] == '.') c++;
+ 		printf("Cache slots used: %d\n", c);*/
+ 		if (voikko_options.cache) {
+ 			free(voikko_options.cache);
+ 			free(voikko_options.cache_meta);
+ 		}
+ 		return 1;
+ 	}
+ 	else return 0;
+ }
+ 
  #define VOIKKO_DICTIONARY_FILE "voikko-fi_FI.pro"
  #ifdef WIN32
  #define VOIKKO_KEY                   "SOFTWARE\\Voikko"
Only in libvoikko-1.2-hv/src: voikko_setup.lo
Only in libvoikko-1.2-hv/src: voikko_setup.o
Only in libvoikko-1.2-hv/src: voikkospell
Only in libvoikko-1.2-hv/src: voikko_spell.lo
Only in libvoikko-1.2-hv/src: voikko_spell.o
Only in libvoikko-1.2-hv/src: voikkospell-porting.o
Only in libvoikko-1.2-hv/src: voikkospell-voikkospell.o
Only in libvoikko-1.2-hv/src: voikko_suggest.lo
Only in libvoikko-1.2-hv/src: voikko_suggest.o
Only in libvoikko-1.2-hv/src: voikko_utils.lo
Only in libvoikko-1.2-hv/src: voikko_utils.o
Only in libvoikko-1.2-hv: stamp-h1



More information about the devel mailing list