cvs: php4 /ext/pspell php_pspell.h pspell.c
| From: | Vlad Krupin | Date: | Tue, 08 Aug 2000 18:46:42 +0000 |
| Subject: | cvs: php4 /ext/pspell php_pspell.h pspell.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-1105@lists.php.net to get a copy of this message | ||
vlad Tue Aug 8 11:46:42 2000 EDT
Modified files:
/php4/ext/pspell php_pspell.h pspell.c
Log:
added support for personalized dictionaries.
new functions: pspell_new_personal(), pspell_save_wordlist().
pspell_save_wordlist() needs to be changed to return error-codes
once pspell library gets fixed
Index: php4/ext/pspell/php_pspell.h
diff -u php4/ext/pspell/php_pspell.h:1.5 php4/ext/pspell/php_pspell.h:1.6
--- php4/ext/pspell/php_pspell.h:1.5 Wed Jul 26 14:24:17 2000
+++ php4/ext/pspell/php_pspell.h Tue Aug 8 11:46:41 2000
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_pspell.h,v 1.5 2000/07/26 21:24:17 vlad Exp $ */
+/* $Id: php_pspell.h,v 1.6 2000/08/08 18:46:41 vlad Exp $ */
#ifndef _PSPELL_H
#define _PSPELL_H
@@ -27,12 +27,14 @@
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: php4/ext/pspell/pspell.c
diff -u php4/ext/pspell/pspell.c:1.8 php4/ext/pspell/pspell.c:1.9
--- php4/ext/pspell/pspell.c:1.8 Sun Aug 6 12:53:56 2000
+++ php4/ext/pspell/pspell.c Tue Aug 8 11:46:41 2000
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: pspell.c,v 1.8 2000/08/06 19:53:56 eschmid Exp $ */
+/* $Id: pspell.c,v 1.9 2000/08/08 18:46:41 vlad Exp $ */
#define IS_EXT_MODULE
@@ -40,12 +40,14 @@
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 @@
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 @@
}
/* }}} */
+/* {{{ 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 @@
}
/* }}} */
-
/* {{{ 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 @@
}
/* }}} */
-
/* {{{ 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 @@
}
/* }}} */
-
/* {{{ proto int pspell_clear_session(int pspell)
Clears the current session */
PHP_FUNCTION(pspell_clear_session)
@@ -347,6 +425,43 @@
php_error(E_WARNING, "pspell_clear_session() gave error: %s",
pspell_manager_error_message(manager));
RETURN_FALSE;
}
+}
+/* }}} */
+
+/* {{{ 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;
+ }
+*/
}
/* }}} */