]> granicus.if.org Git - php/commitdiff
added support for personalized dictionaries.
authorVlad Krupin <vlad@php.net>
Tue, 8 Aug 2000 18:46:41 +0000 (18:46 +0000)
committerVlad Krupin <vlad@php.net>
Tue, 8 Aug 2000 18:46:41 +0000 (18:46 +0000)
new functions: pspell_new_personal(), pspell_save_wordlist().

pspell_save_wordlist() needs to be changed to return error-codes
once pspell library gets fixed

ext/pspell/php_pspell.h
ext/pspell/pspell.c

index 21f931b827bdb56a073e86d9253cc6fca935938c..f3a7bfdd32515c13795efdf4211659a4ee4bb32b 100644 (file)
@@ -27,12 +27,14 @@ extern zend_module_entry pspell_module_entry;
 PHP_MINIT_FUNCTION(pspell);
 PHP_MINFO_FUNCTION(pspell);
 PHP_FUNCTION(pspell_new);
+PHP_FUNCTION(pspell_new_personal);
 PHP_FUNCTION(pspell_check);
 PHP_FUNCTION(pspell_suggest);
 PHP_FUNCTION(pspell_store_replacement);
 PHP_FUNCTION(pspell_add_to_personal);
 PHP_FUNCTION(pspell_add_to_session);
 PHP_FUNCTION(pspell_clear_session);
+PHP_FUNCTION(pspell_save_wordlist);
 #else
 #define pspell_module_ptr NULL
 #endif
index 95c2fccbfb0a2353e58459133a6cb7157ed5da62..28aede9f123ac986163d6d339bc28ce8fe8e3a14 100644 (file)
 
 function_entry pspell_functions[] = {
        PHP_FE(pspell_new,              NULL)
+       PHP_FE(pspell_new_personal,             NULL)
        PHP_FE(pspell_check,            NULL)
        PHP_FE(pspell_suggest,          NULL)
        PHP_FE(pspell_store_replacement,                NULL)
        PHP_FE(pspell_add_to_personal,          NULL)
        PHP_FE(pspell_add_to_session,           NULL)
        PHP_FE(pspell_clear_session,            NULL)
+       PHP_FE(pspell_save_wordlist,            NULL)
 };
 
 static int le_pspell;
@@ -62,7 +64,6 @@ static void php_pspell_close(PspellManager *manager){
        delete_pspell_manager(manager);
 }
 
-
 PHP_MINIT_FUNCTION(pspell){
        REGISTER_MAIN_LONG_CONSTANT("PSPELL_FAST", PSPELL_FAST, CONST_PERSISTENT | CONST_CS);
        REGISTER_MAIN_LONG_CONSTANT("PSPELL_NORMAL", PSPELL_NORMAL, CONST_PERSISTENT | CONST_CS);
@@ -148,6 +149,86 @@ PHP_FUNCTION(pspell_new){
 }
 /* }}} */
 
+/* {{{ proto int pspell_new_personal(string personal, string language [, string spelling [, string jargon [, string encoding [, int mode]]]])
+   Load a dictionary with a personal wordlist*/
+PHP_FUNCTION(pspell_new_personal){
+       zval **personal, **language,**spelling,**jargon,**encoding,**pmode;
+       long mode = 0L,  speed = 0L;
+       int argc;
+       int ind;
+
+       PspellCanHaveError *ret;
+       PspellManager *manager;
+       PspellConfig *config;
+       
+       argc = ZEND_NUM_ARGS();
+       if (argc < 2 || argc > 6 || zend_get_parameters_ex(argc,&personal,&language,&spelling,&jargon,&encoding,&pmode) == FAILURE) {
+               WRONG_PARAM_COUNT;
+       }
+
+       config = new_pspell_config();
+
+       convert_to_string_ex(personal);
+       pspell_config_replace(config, "personal", (*personal)->value.str.val);
+
+       convert_to_string_ex(language);
+       pspell_config_replace(config, "language-tag", (*language)->value.str.val);
+
+       if(argc > 2){
+               convert_to_string_ex(spelling);
+               if((*spelling)->value.str.len > 0){
+                       pspell_config_replace(config, "spelling", (*spelling)->value.str.val);
+               }
+       }
+
+       if(argc > 3){
+               convert_to_string_ex(jargon);
+               if((*jargon)->value.str.len > 0){
+                       pspell_config_replace(config, "jargon", (*jargon)->value.str.val);
+               }
+       }
+
+       if(argc > 4){
+               convert_to_string_ex(encoding);
+               if((*encoding)->value.str.len > 0){
+                       pspell_config_replace(config, "encoding", (*encoding)->value.str.val);
+               }
+       }
+
+       if(argc > 5){
+               convert_to_long_ex(pmode);
+               mode = Z_LVAL_PP(pmode);
+               speed = mode & PSPELL_SPEED_MASK_INTERNAL;
+
+               /* First check what mode we want (how many suggestions) */
+               if(speed == PSPELL_FAST){
+                       pspell_config_replace(config, "sug-mode", "fast");
+               }else if(speed == PSPELL_NORMAL){
+                       pspell_config_replace(config, "sug-mode", "normal");
+               }else if(speed == PSPELL_BAD_SPELLERS){
+                       pspell_config_replace(config, "sug-mode", "bad-spellers");
+               }
+               
+               /* Then we see if run-together words should be treated as valid components */
+               if(mode & PSPELL_RUN_TOGETHER){
+                       pspell_config_replace(config, "run-together", "true");
+               }
+       }
+
+       ret = new_pspell_manager(config);
+       delete_pspell_config(config);
+
+       if(pspell_error_number(ret) != 0){
+               php_error(E_WARNING, "PSPELL couldn't open the dictionary. reason: %s ", pspell_error_message(ret));
+               RETURN_FALSE;
+       }
+       
+       manager = to_pspell_manager(ret);
+       ind = zend_list_insert(manager, le_pspell);
+       RETURN_LONG(ind);
+}
+/* }}} */
+
 /* {{{ proto int pspell_check(int pspell, string word)
    Returns true if word is valid */
 PHP_FUNCTION(pspell_check){
@@ -219,7 +300,6 @@ PHP_FUNCTION(pspell_suggest)
 }
 /* }}} */
 
-
 /* {{{ proto int pspell_store_replacement(int pspell, string misspell, string correct)
    Notify the dictionary of a user-selected replacement */
 PHP_FUNCTION(pspell_store_replacement)
@@ -285,7 +365,6 @@ PHP_FUNCTION(pspell_add_to_personal)
 }
 /* }}} */
 
-
 /* {{{ proto int pspell_add_to_session(int pspell, string word)
    Adds a word to the current session */
 PHP_FUNCTION(pspell_add_to_session)
@@ -318,7 +397,6 @@ PHP_FUNCTION(pspell_add_to_session)
 }
 /* }}} */
 
-
 /* {{{ proto int pspell_clear_session(int pspell)
    Clears the current session */
 PHP_FUNCTION(pspell_clear_session)
@@ -350,6 +428,43 @@ PHP_FUNCTION(pspell_clear_session)
 }
 /* }}} */
 
+/* {{{ proto int pspell_save_wordlist(int pspell)
+   Saves the current (personal) wordlist */
+PHP_FUNCTION(pspell_save_wordlist)
+{
+       int type;
+       zval **scin;
+       PspellManager *manager;
+
+       int argc;
+       argc = ZEND_NUM_ARGS();
+       if (argc != 1 || zend_get_parameters_ex(argc, &scin) == FAILURE) {
+               WRONG_PARAM_COUNT;
+       }
+    
+       convert_to_long_ex(scin);
+       manager = (PspellManager *) zend_list_find((*scin)->value.lval, &type);
+       if(!manager){
+               php_error(E_WARNING, "%d is not an PSPELL result index",(*scin)->value.lval);
+               RETURN_FALSE;
+       }
+
+       pspell_manager_save_all_word_lists(manager);
+       RETURN_TRUE;
+/*     FIXME: The following should be back in place once Kevin Atkinson 
+       (the author of pspell & aspell) fixes pspell so that 
+       pspell_manager_save_all_word_lists() does not attempt to write to $HOME/.*.prepl
+       Current version (.11.1) generates an error that can be safely ignored.
+       if(pspell_manager_error_number(manager) == 0){
+               RETURN_TRUE;
+       }else{
+               php_error(E_WARNING, "pspell_save_wordlist() gave error: %s", pspell_manager_error_message(manager));
+               RETURN_FALSE;
+       }
+*/
+}
+/* }}} */
+
 
 PHP_MINFO_FUNCTION(pspell)
 {