From: Vlad Krupin Date: Wed, 26 Jul 2000 21:32:29 +0000 (+0000) Subject: Changed syntax of pspell_new() (one more parameter - mode) X-Git-Tag: PRE_FILE_COMPILE_API_CHANGE~115 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3d3d23802162c256cad5b33ed4cdd7f028803c27;p=php Changed syntax of pspell_new() (one more parameter - mode) pspell_new() parameters that are empty ("") are now ignored Removed pspell_mode() and pspell_runtogether() - their functionality moved to pspell_new() because the ability to dynamically change those settings is not in ISPELL, and is likely do disappear from ASPELL, according to ASPELL author. Created a new constant - PSPELL_RUN_TOGETHER for pspell_new() fixed a bug in pspell_new() that caused non-English dictionaries to be ignored removed a bogus line from pspell_new() that could result in a memory leak --- diff --git a/ext/pspell/pspell.c b/ext/pspell/pspell.c index 96de60724c..d5287ffc1a 100644 --- a/ext/pspell/pspell.c +++ b/ext/pspell/pspell.c @@ -32,14 +32,14 @@ #include #include "ext/standard/info.h" -#define PSPELL_FAST 1 -#define PSPELL_NORMAL 2 -#define PSPELL_BAD_SPELLERS 3 +#define PSPELL_FAST 1L +#define PSPELL_NORMAL 2L +#define PSPELL_BAD_SPELLERS 3L +#define PSPELL_SPEED_MASK_INTERNAL 3L +#define PSPELL_RUN_TOGETHER 8L function_entry pspell_functions[] = { PHP_FE(pspell_new, NULL) - PHP_FE(pspell_mode, NULL) - PHP_FE(pspell_runtogether, NULL) PHP_FE(pspell_check, NULL) PHP_FE(pspell_suggest, NULL) PHP_FE(pspell_store_replacement, NULL) @@ -67,14 +67,16 @@ 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); REGISTER_MAIN_LONG_CONSTANT("PSPELL_BAD_SPELLERS", PSPELL_BAD_SPELLERS, CONST_PERSISTENT | CONST_CS); + REGISTER_MAIN_LONG_CONSTANT("PSPELL_RUN_TOGETHER", PSPELL_RUN_TOGETHER, CONST_PERSISTENT | CONST_CS); le_pspell = register_list_destructors(php_pspell_close,NULL); return SUCCESS; } -/* {{{ proto int pspell_new(string language [, string spelling [, string jargon [, string encoding]]]) +/* {{{ proto int pspell_new(string language [, string spelling [, string jargon [, string encoding [, mode]]]]) Load a dictionary */ PHP_FUNCTION(pspell_new){ - zval **language,**spelling,**jargon,**encoding; + zval **language,**spelling,**jargon,**encoding,**pmode; + long mode = 0L, speed = 0L; int argc; int ind; @@ -83,25 +85,53 @@ PHP_FUNCTION(pspell_new){ PspellConfig *config; argc = ZEND_NUM_ARGS(); - if (argc < 1 || argc > 4 || zend_get_parameters_ex(argc,&language,&spelling,&jargon,&encoding) == FAILURE) { + if (argc < 1 || argc > 5 || zend_get_parameters_ex(argc,&language,&spelling,&jargon,&encoding,&pmode) == FAILURE) { WRONG_PARAM_COUNT; } config = new_pspell_config(); convert_to_string_ex(language); + pspell_config_replace(config, "language-tag", (*language)->value.str.val); + if(argc > 1){ - convert_to_string_ex(spelling) ; - pspell_config_replace(config, "spelling", (*spelling)->value.str.val); + convert_to_string_ex(spelling); + if((*spelling)->value.str.len > 0){ + pspell_config_replace(config, "spelling", (*spelling)->value.str.val); + } } if(argc > 2){ - convert_to_string_ex(jargon) ; - pspell_config_replace(config, "jargon", (*jargon)->value.str.val); + convert_to_string_ex(jargon); + if((*jargon)->value.str.len > 0){ + pspell_config_replace(config, "jargon", (*jargon)->value.str.val); + } } if(argc > 3){ - convert_to_string_ex(encoding) ; - pspell_config_replace(config, "encoding", (*encoding)->value.str.val); + convert_to_string_ex(encoding); + if((*encoding)->value.str.len > 0){ + pspell_config_replace(config, "encoding", (*encoding)->value.str.val); + } + } + + if(argc > 4){ + 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); @@ -113,87 +143,11 @@ PHP_FUNCTION(pspell_new){ } manager = to_pspell_manager(ret); - config = pspell_manager_config(manager); ind = zend_list_insert(manager, le_pspell); RETURN_LONG(ind); } /* }}} */ - -/* {{{ proto int pspell_mode(pspell int, string mode) - Change the mode between 'fast', 'normal' and 'bad-spellers' */ -PHP_FUNCTION(pspell_mode) -{ - int type; - zval **scin, **pmode; - int argc; - long mode = 0L; - PspellManager *manager; - PspellConfig *config; - - argc = ZEND_NUM_ARGS(); - if (argc != 2 || zend_get_parameters_ex(argc, &scin, &pmode) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_long_ex(scin); - convert_to_long_ex(pmode); - mode = Z_LVAL_PP(pmode); - 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; - } - config = pspell_manager_config(manager); - - if(mode == PSPELL_FAST){ - pspell_config_replace(config, "sug-mode", "fast"); - }else if(mode == PSPELL_NORMAL){ - pspell_config_replace(config, "sug-mode", "normal"); - }else if(mode == PSPELL_BAD_SPELLERS){ - pspell_config_replace(config, "sug-mode", "bad-spellers"); - }else{ - RETURN_FALSE; - } - RETURN_TRUE; -} -/* }}} */ - -/* {{{ 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) -{ - int type; - zval **scin, **pruntogether; - int argc; - int runtogether; - PspellManager *manager; - PspellConfig *config; - - argc = ZEND_NUM_ARGS(); - if (argc != 2 || zend_get_parameters_ex(argc, &scin, &pruntogether) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_long_ex(scin); - convert_to_boolean_ex(pruntogether); - runtogether = (*pruntogether)->value.lval; - 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; - } - config = pspell_manager_config(manager); - - if(runtogether){ - pspell_config_replace(config, "run-together", "true"); - }else{ - pspell_config_replace(config, "run-together", "false"); - } - RETURN_TRUE; -} -/* }}} */ - /* {{{ proto int pspell_check(pspell int, string word) Return if word is valid */ PHP_FUNCTION(pspell_check){