php-src/ext/aspell/aspell.c

205 lines
5.0 KiB
C
Raw Normal View History

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
+----------------------------------------------------------------------+
| Copyright (c) 1997, 1998, 1999, 2000 The PHP Group |
1999-07-09 14:56:33 +00:00
+----------------------------------------------------------------------+
| This source file is subject to version 2.02 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 |
| http://www.php.net/license/2_02.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-05-23 09:33:51 +00:00
#ifdef 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
#include "php_aspell.h"
1999-07-09 14:56:33 +00:00
#include <aspell-c.h>
#include "ext/standard/info.h"
1999-07-09 14:56:33 +00:00
function_entry aspell_functions[] = {
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;
zend_module_entry aspell_module_entry = {
"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-23 09:33:51 +00:00
#ifdef COMPILE_DL_ASPELL
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);
}
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 */
PHP_FUNCTION(aspell_new)
1999-07-09 14:56:33 +00:00
{
pval **master,**personal;
1999-07-09 14:56:33 +00:00
int argc;
aspell *sc;
int ind;
argc = ZEND_NUM_ARGS();
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;
}
convert_to_string_ex(master);
1999-07-09 14:56:33 +00:00
if(argc==2)
{
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
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);
}
/* }}} */
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 */
PHP_FUNCTION(aspell_suggest)
1999-07-09 14:56:33 +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 = ZEND_NUM_ARGS();
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;
}
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)
{
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;
}
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 */
PHP_FUNCTION(aspell_check)
1999-07-09 14:56:33 +00:00
{
int type;
pval **scin,**word;
1999-07-09 14:56:33 +00:00
aspell *sc;
1999-07-09 14:56:33 +00:00
int argc;
argc = ZEND_NUM_ARGS();
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;
}
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)
{
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 (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 */
PHP_FUNCTION(aspell_check_raw)
1999-07-09 14:56:33 +00:00
{
pval **scin,**word;
1999-07-09 14:56:33 +00:00
int type;
int argc;
aspell *sc;
argc = ZEND_NUM_ARGS();
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;
}
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)
{
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 (aspell_check_raw(sc, (*word)->value.str.val))
1999-07-09 14:56:33 +00:00
{
RETURN_TRUE;
}
else
{
RETURN_FALSE;
}
}
/* }}} */
PHP_MINFO_FUNCTION(aspell)
1999-07-09 14:56:33 +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