cvs: php4 /ext/pspell pspell.c

From: Date: Tue, 25 Jul 2000 22:06:38 +0000
Subject: cvs: php4 /ext/pspell pspell.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-919@lists.php.net to get a copy of this message
vlad Tue Jul 25 15:06:38 2000 EDT Modified files: /php4/ext/pspell pspell.c Log: - added several functions for manipulating wordlists - pspell_store_replacement(), pspell_add_to_personal(), pspell_add_to_session(), pspell_clear_session(). - fixed a few confusing typos in comments Index: php4/ext/pspell/pspell.c diff -u php4/ext/pspell/pspell.c:1.4 php4/ext/pspell/pspell.c:1.5 --- php4/ext/pspell/pspell.c:1.4 Sun Jul 23 18:39:48 2000 +++ php4/ext/pspell/pspell.c Tue Jul 25 15:06:38 2000 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: pspell.c,v 1.4 2000/07/24 01:39:48 david Exp $ */ +/* $Id: pspell.c,v 1.5 2000/07/25 22:06:38 vlad Exp $ */ #define IS_EXT_MODULE @@ -42,6 +42,10 @@ PHP_FE(pspell_runtogether, 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) }; static int le_pspell; @@ -116,7 +120,7 @@ /* }}} */ -/* {{{ proto int pspell_mode(string mode) +/* {{{ proto int pspell_mode(pspell int, string mode) Change the mode between 'fast', 'normal' and 'bad-spellers' */ PHP_FUNCTION(pspell_mode) { @@ -155,7 +159,7 @@ } /* }}} */ -/* {{{ proto int pspell_runtogether(string mode) +/* {{{ proto int pspell_runtogether(pspell int, string mode) Change the mode between whether we want to treat run-together words as valid */ PHP_FUNCTION(pspell_runtogether) { @@ -190,7 +194,7 @@ } /* }}} */ -/* {{{ proto int pspell_check(aspell int, string word) +/* {{{ proto int pspell_check(pspell int, string word) Return if word is valid */ PHP_FUNCTION(pspell_check){ int type; @@ -219,7 +223,7 @@ } /* }}} */ -/* {{{ proto array pspell_suggest(aspell int, string word) +/* {{{ proto array pspell_suggest(pspell int, string word) Return array of Suggestions */ PHP_FUNCTION(pspell_suggest) { @@ -260,6 +264,138 @@ } } /* }}} */ + + +/* {{{ proto int pspell_store_replacement(pspell int, string misspell, string correct) + Notify the dictionary of a user-selected replacement */ +PHP_FUNCTION(pspell_store_replacement) +{ + int type; + zval **scin,**miss,**corr; + PspellManager *manager; + + int argc; + argc = ZEND_NUM_ARGS(); + if (argc != 3 || zend_get_parameters_ex(argc, &scin,&miss,&corr) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long_ex(scin); + convert_to_string_ex(miss); + convert_to_string_ex(corr); + 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_store_replacement(manager, (*miss)->value.str.val, (*corr)->value.str.val); + if(pspell_manager_error_number(manager) == 0){ + RETURN_TRUE; + }else{ + php_error(E_WARNING, "pspell_store_replacement() gave error: %s", pspell_manager_error_message(manager)); + RETURN_FALSE; + } +} +/* }}} */ + +/* {{{ proto int pspell_add_to_personal(pspell int, string word) + Add a word to a personal list */ +PHP_FUNCTION(pspell_add_to_personal) +{ + int type; + zval **scin,**word; + PspellManager *manager; + + int argc; + argc = ZEND_NUM_ARGS(); + if (argc != 2 || zend_get_parameters_ex(argc, &scin,&word) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long_ex(scin); + convert_to_string_ex(word); + 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_add_to_personal(manager, (*word)->value.str.val); + if(pspell_manager_error_number(manager) == 0){ + RETURN_TRUE; + }else{ + php_error(E_WARNING, "pspell_add_to_personal() gave error: %s", pspell_manager_error_message(manager)); + RETURN_FALSE; + } +} +/* }}} */ + + +/* {{{ proto int pspell_add_to_session(pspell int, string word) + Add a word to the current session */ +PHP_FUNCTION(pspell_add_to_session) +{ + int type; + zval **scin,**word; + PspellManager *manager; + + int argc; + argc = ZEND_NUM_ARGS(); + if (argc != 2 || zend_get_parameters_ex(argc, &scin,&word) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long_ex(scin); + convert_to_string_ex(word); + 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_add_to_session(manager, (*word)->value.str.val); + if(pspell_manager_error_number(manager) == 0){ + RETURN_TRUE; + }else{ + php_error(E_WARNING, "pspell_add_to_session() gave error: %s", pspell_manager_error_message(manager)); + RETURN_FALSE; + } +} +/* }}} */ + + +/* {{{ proto int pspell_clear_session(pspell int) + Clear the current session */ +PHP_FUNCTION(pspell_clear_session) +{ + 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_clear_session(manager); + if(pspell_manager_error_number(manager) == 0){ + RETURN_TRUE; + }else{ + php_error(E_WARNING, "pspell_clear_session() gave error: %s", pspell_manager_error_message(manager)); + RETURN_FALSE; + } +} +/* }}} */ + PHP_MINFO_FUNCTION(pspell) {

« previous php.cvs (#919) next »