1999-07-09 14:56:33 +00:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
1999-07-16 13:13:16 +00:00
|
|
|
| PHP version 4.0 |
|
1999-07-09 14:56:33 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2000-01-01 01:32:05 +00:00
|
|
|
| Copyright (c) 1997, 1998, 1999, 2000 The PHP Group |
|
1999-07-09 14:56:33 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2000-02-19 23:21:46 +00:00
|
|
|
| This source file is subject to version 2.01 of the PHP license, |
|
1999-07-16 13:13:16 +00:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available at through the world-wide-web at |
|
2000-02-19 23:21:46 +00:00
|
|
|
| http://www.php.net/license/2_01.txt. |
|
1999-07-16 13:13:16 +00:00
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
1999-07-09 14:56:33 +00:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Authors: |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
#include "php.h"
|
2000-04-05 22:30:19 +00:00
|
|
|
|
2000-05-02 00:44:35 +00:00
|
|
|
#if defined(COMPILE_DL) || defined(COMPILE_DL_ASPELL)
|
1999-07-09 14:56:33 +00:00
|
|
|
#include "phpdl.h"
|
|
|
|
#endif
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#if HAVE_ASPELL
|
|
|
|
|
1999-12-04 19:19:57 +00:00
|
|
|
#include "php_aspell.h"
|
1999-07-09 14:56:33 +00:00
|
|
|
#include <aspell-c.h>
|
2000-04-05 22:30:19 +00:00
|
|
|
#include "ext/standard/info.h"
|
1999-07-09 14:56:33 +00:00
|
|
|
|
|
|
|
function_entry aspell_functions[] = {
|
1999-07-26 20:09:08 +00:00
|
|
|
PHP_FE(aspell_new, NULL)
|
|
|
|
PHP_FE(aspell_check, NULL)
|
|
|
|
PHP_FE(aspell_check_raw, NULL)
|
|
|
|
PHP_FE(aspell_suggest, NULL)
|
1999-07-09 14:56:33 +00:00
|
|
|
{NULL, NULL, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static int le_aspell;
|
|
|
|
|
1999-12-17 20:55:31 +00:00
|
|
|
zend_module_entry aspell_module_entry = {
|
2000-03-06 18:44:01 +00:00
|
|
|
"aspell", aspell_functions, PHP_MINIT(aspell), NULL, NULL, NULL, PHP_MINFO(aspell), STANDARD_MODULE_PROPERTIES
|
1999-07-09 14:56:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-05-02 00:44:35 +00:00
|
|
|
#if defined(COMPILE_DL) || defined(COMPILE_DL_ASPELL)
|
2000-05-02 00:30:36 +00:00
|
|
|
ZEND_GET_MODULE(aspell)
|
1999-07-09 14:56:33 +00:00
|
|
|
#endif
|
|
|
|
|
1999-12-17 21:13:15 +00:00
|
|
|
static void php_aspell_close(aspell *sc)
|
|
|
|
{
|
|
|
|
aspell_free(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-07-26 20:09:08 +00:00
|
|
|
PHP_MINIT_FUNCTION(aspell)
|
1999-07-09 14:56:33 +00:00
|
|
|
{
|
1999-12-17 21:13:15 +00:00
|
|
|
le_aspell = register_list_destructors(php_aspell_close,NULL);
|
1999-07-09 14:56:33 +00:00
|
|
|
return SUCCESS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2000-02-24 15:55:10 +00:00
|
|
|
/* {{{ proto int aspell_new(string master [, string personal])
|
1999-07-09 14:56:33 +00:00
|
|
|
Load a dictionary */
|
1999-07-26 20:09:08 +00:00
|
|
|
PHP_FUNCTION(aspell_new)
|
1999-07-09 14:56:33 +00:00
|
|
|
{
|
1999-11-23 06:46:40 +00:00
|
|
|
pval **master,**personal;
|
1999-07-09 14:56:33 +00:00
|
|
|
int argc;
|
|
|
|
aspell *sc;
|
|
|
|
int ind;
|
|
|
|
|
|
|
|
argc = ARG_COUNT(ht);
|
1999-12-18 22:40:35 +00:00
|
|
|
if (argc < 1 || argc > 2 || zend_get_parameters_ex(argc,&master,&personal) == FAILURE) {
|
1999-07-09 14:56:33 +00:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
1999-11-23 06:46:40 +00:00
|
|
|
convert_to_string_ex(master);
|
1999-07-09 14:56:33 +00:00
|
|
|
if(argc==2)
|
|
|
|
{
|
1999-11-23 06:46:40 +00:00
|
|
|
convert_to_string_ex(personal) ;
|
|
|
|
sc=aspell_new((*master)->value.str.val,(*personal)->value.str.val);
|
1999-07-09 14:56:33 +00:00
|
|
|
}
|
|
|
|
else
|
1999-11-23 06:46:40 +00:00
|
|
|
sc=aspell_new((*master)->value.str.val,"");
|
1999-07-09 14:56:33 +00:00
|
|
|
|
1999-12-17 19:51:39 +00:00
|
|
|
ind = zend_list_insert(sc, le_aspell);
|
1999-07-09 14:56:33 +00:00
|
|
|
RETURN_LONG(ind);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
1999-07-26 20:09:08 +00:00
|
|
|
|
2000-02-24 15:55:10 +00:00
|
|
|
/* {{{ proto array aspell_suggest(aspell int, string word)
|
1999-07-09 14:56:33 +00:00
|
|
|
Return array of Suggestions */
|
1999-07-26 20:09:08 +00:00
|
|
|
PHP_FUNCTION(aspell_suggest)
|
1999-07-09 14:56:33 +00:00
|
|
|
{
|
1999-11-23 06:46:40 +00:00
|
|
|
pval **scin, **word;
|
1999-07-09 14:56:33 +00:00
|
|
|
int argc;
|
|
|
|
aspell *sc;
|
|
|
|
int ind,type;
|
|
|
|
aspellSuggestions *sug;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
|
|
|
|
argc = ARG_COUNT(ht);
|
1999-12-18 22:40:35 +00:00
|
|
|
if (argc != 2 || zend_get_parameters_ex(argc, &scin,&word) == FAILURE) {
|
1999-07-09 14:56:33 +00:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
1999-11-23 06:46:40 +00:00
|
|
|
convert_to_long_ex(scin);
|
|
|
|
convert_to_string_ex(word);
|
1999-12-17 19:51:39 +00:00
|
|
|
sc = (aspell *)zend_list_find((*scin)->value.lval, &type);
|
1999-07-09 14:56:33 +00:00
|
|
|
if(!sc)
|
|
|
|
{
|
1999-11-23 06:46:40 +00:00
|
|
|
php_error(E_WARNING, "%d is not an ASPELL result index",(*scin)->value.lval);
|
1999-07-09 14:56:33 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (array_init(return_value) == FAILURE) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
1999-11-23 06:46:40 +00:00
|
|
|
sug = aspell_suggest(sc, (*word)->value.str.val);
|
1999-07-09 14:56:33 +00:00
|
|
|
for (i = 0; i != sug->size; ++i) {
|
|
|
|
add_next_index_string(return_value,(char *)sug->data[i],1);
|
|
|
|
}
|
|
|
|
aspell_free_suggestions(sug);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2000-02-24 15:55:10 +00:00
|
|
|
/* {{{ proto int aspell_check(aspell int, string word)
|
1999-07-09 14:56:33 +00:00
|
|
|
Return if word is valid */
|
1999-07-26 20:09:08 +00:00
|
|
|
PHP_FUNCTION(aspell_check)
|
1999-07-09 14:56:33 +00:00
|
|
|
{
|
|
|
|
int type;
|
1999-11-23 06:46:40 +00:00
|
|
|
pval **scin,**word;
|
1999-07-09 14:56:33 +00:00
|
|
|
aspell *sc;
|
1999-07-12 19:18:07 +00:00
|
|
|
|
1999-07-09 14:56:33 +00:00
|
|
|
int argc;
|
|
|
|
argc = ARG_COUNT(ht);
|
1999-12-18 22:40:35 +00:00
|
|
|
if (argc != 2 || zend_get_parameters_ex(argc, &scin,&word) == FAILURE) {
|
1999-07-09 14:56:33 +00:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
1999-11-23 06:46:40 +00:00
|
|
|
convert_to_long_ex(scin);
|
|
|
|
convert_to_string_ex(word);
|
1999-12-17 19:51:39 +00:00
|
|
|
sc= (aspell *) zend_list_find((*scin)->value.lval, &type);
|
1999-07-09 14:56:33 +00:00
|
|
|
if(!sc)
|
|
|
|
{
|
1999-11-23 06:46:40 +00:00
|
|
|
php_error(E_WARNING, "%d is not an ASPELL result index",(*scin)->value.lval);
|
1999-07-09 14:56:33 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
1999-11-23 06:46:40 +00:00
|
|
|
if (aspell_check(sc, (*word)->value.str.val))
|
1999-07-09 14:56:33 +00:00
|
|
|
{
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2000-02-24 15:55:10 +00:00
|
|
|
/* {{{ proto int aspell_check_raw(aspell int, string word)
|
|
|
|
Return if word is valid, ignoring case or trying to trim it in any way */
|
1999-07-26 20:09:08 +00:00
|
|
|
PHP_FUNCTION(aspell_check_raw)
|
1999-07-09 14:56:33 +00:00
|
|
|
{
|
1999-11-23 06:46:40 +00:00
|
|
|
pval **scin,**word;
|
1999-07-09 14:56:33 +00:00
|
|
|
int type;
|
|
|
|
int argc;
|
|
|
|
aspell *sc;
|
|
|
|
|
|
|
|
argc = ARG_COUNT(ht);
|
1999-12-18 22:40:35 +00:00
|
|
|
if (argc != 2 || zend_get_parameters_ex(argc, &scin,&word) == FAILURE) {
|
1999-07-09 14:56:33 +00:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
1999-11-23 06:46:40 +00:00
|
|
|
convert_to_long_ex(scin);
|
|
|
|
convert_to_string_ex(word);
|
1999-12-17 19:51:39 +00:00
|
|
|
sc = (aspell *)zend_list_find((*scin)->value.lval, &type);
|
1999-07-09 14:56:33 +00:00
|
|
|
if(!sc)
|
|
|
|
{
|
1999-11-23 06:46:40 +00:00
|
|
|
php_error(E_WARNING, "%d is not an ASPELL result index",(*scin)->value.lval);
|
1999-07-09 14:56:33 +00:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
1999-11-23 06:46:40 +00:00
|
|
|
if (aspell_check_raw(sc, (*word)->value.str.val))
|
1999-07-09 14:56:33 +00:00
|
|
|
{
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
1999-07-26 20:09:08 +00:00
|
|
|
PHP_MINFO_FUNCTION(aspell)
|
1999-07-09 14:56:33 +00:00
|
|
|
{
|
2000-04-05 22:30:19 +00:00
|
|
|
php_info_print_table_start();
|
|
|
|
php_info_print_table_row(2, "ASpell Support", "enabled");
|
|
|
|
php_info_print_table_end();
|
1999-07-09 14:56:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|