File: aspell.c

package info (click to toggle)
php3 3%3A3.0.18-0potato1.1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 17,736 kB
  • ctags: 11,198
  • sloc: ansic: 108,120; sh: 2,512; php: 2,024; yacc: 1,887; makefile: 1,038; perl: 537; pascal: 238; awk: 90; cpp: 28; sql: 11
file content (221 lines) | stat: -rw-r--r-- 6,230 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
   +----------------------------------------------------------------------+
   | PHP HTML Embedded Scripting Language Version 3.0                     |
   +----------------------------------------------------------------------+
   | Copyright (c) 1997-2000 PHP Development Team (See Credits file)      |
   +----------------------------------------------------------------------+
   | This program is free software; you can redistribute it and/or modify |
   | it under the terms of one of the following licenses:                 |
   |                                                                      |
   |  A) the GNU General Public License as published by the Free Software |
   |     Foundation; either version 2 of the License, or (at your option) |
   |     any later version.                                               |
   |                                                                      |
   |  B) the PHP License as published by the PHP Development Team and     |
   |     included in the distribution in the file: LICENSE                |
   |                                                                      |
   | This program is distributed in the hope that it will be useful,      |
   | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
   | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        |
   | GNU General Public License for more details.                         |
   |                                                                      |
   | You should have received a copy of both licenses referred to here.   |
   | If you did not, or have any questions about PHP licensing, please    |
   | contact core@php.net.                                                |
   +----------------------------------------------------------------------+
   | Authors:                                                             |
   |                                                                      |
   +----------------------------------------------------------------------+
 */

/* $Id: aspell.c,v 1.6 2000/01/01 04:31:14 sas Exp $ */

#include <stdlib.h>
#include <ctype.h>
#include <stdio.h>
#include "php.h"
#ifndef MSVC5
#include "build-defs.h"
#endif
#include "internal_functions.h"
#include "php3_list.h"

#if HAVE_ASPELL

#include "php3_aspell.h"
#if APACHE
#  ifndef DEBUG
#  undef palloc
#  endif
#endif
#include <aspell-c.h>

function_entry aspell_functions[] = {
	{"aspell_new",		php3_aspell_new,		NULL},
	{"aspell_check",		php3_aspell_check,		NULL},
	{"aspell_check_raw",		php3_aspell_check_raw,		NULL},
	{"aspell_suggest",		php3_aspell_suggest,		NULL},
	{NULL, NULL, NULL}
};

int le_aspell;

php3_module_entry aspell_module_entry = {
	"Aspell", aspell_functions, php3_minit_aspell, NULL, NULL, NULL, php3_info_aspell, STANDARD_MODULE_PROPERTIES
};


#if COMPILE_DL
DLEXPORT php3_module_entry *get_module(void) { return &aspell_module_entry; }
#endif

int php3_minit_aspell(INIT_FUNC_ARGS)
{
    le_aspell = register_list_destructors(php3_aspell_close,NULL);
	return SUCCESS;

}
void php3_aspell_close(aspell *sc)
{
aspell_free(sc);
}

/* {{{ proto int aspell_new(string master [, string personal])
   Load a dictionary */
void php3_aspell_new(INTERNAL_FUNCTION_PARAMETERS)
{
	pval *master, *personal;
	int argc;
	aspell *sc;
	int ind;
	TLS_VARS;
	
	argc = ARG_COUNT(ht);
	if (argc < 1 || argc > 2 || getParameters(ht, argc, &master,&personal) == FAILURE) {
		WRONG_PARAM_COUNT;
	}
	convert_to_string(master);
	if(argc==2)
	  {
		convert_to_string(personal) ;
	sc=aspell_new(master->value.str.val,personal->value.str.val);
	  }
	else
	  sc=aspell_new(master->value.str.val,"");

	ind = php3_list_insert(sc, le_aspell);
	RETURN_LONG(ind);
}
/* }}} */

/* {{{ proto array aspell_suggest(aspell int, string word)
   Return array of Suggestions */
void php3_aspell_suggest(INTERNAL_FUNCTION_PARAMETERS)
{
	pval *scin, *word;
	int argc;
	aspell *sc;
	int ind,type;
	aspellSuggestions *sug;
	size_t i;

	TLS_VARS;
	
	argc = ARG_COUNT(ht);
	if (argc != 2 || getParameters(ht, argc, &scin,&word) == FAILURE) {
		WRONG_PARAM_COUNT;
	}
	convert_to_long(scin);
	convert_to_string(word);
	sc= (aspell *) php3_list_find(scin->value.lval, &type);
	if(!sc)
	  {
		php3_error(E_WARNING, "%d is not a ASPELL result index", scin->value.lval);
		RETURN_FALSE;
	  }

	if (array_init(return_value) == FAILURE) {
                RETURN_FALSE;
	}

	sug = aspell_suggest(sc, word->value.str.val);
	  for (i = 0; i != sug->size; ++i) {
                add_next_index_string(return_value,(char *)sug->data[i],1);
	  }
	  aspell_free_suggestions(sug);
}
/* }}} */

/* {{{ proto int aspell_check(aspell int, string word)
   Return if word is valid */
void php3_aspell_check(INTERNAL_FUNCTION_PARAMETERS)
{
   int type;
   pval *scin,*word;
   aspell *sc;
   int argc;
   TLS_VARS;
    argc = ARG_COUNT(ht);
    if (argc != 2 || getParameters(ht, argc, &scin,&word) == FAILURE) {
        WRONG_PARAM_COUNT;
    }
    convert_to_long(scin);
    convert_to_string(word);
    sc= (aspell *) php3_list_find(scin->value.lval, &type);
    if(!sc)
      {
        php3_error(E_WARNING, "%d is not a ASPELL result index", scin->value.lval);
        RETURN_FALSE;
      }
    if (aspell_check(sc, word->value.str.val)) 
      {
	RETURN_TRUE;
      }
    else 
      {
  RETURN_FALSE;
      }
}
/* }}} */

/* {{{ proto int aspell_check_raw(aspell int, string word)
   Return if word is valid, ignoring case or trying to trim it in any way */
void php3_aspell_check_raw(INTERNAL_FUNCTION_PARAMETERS)
{
  pval *scin,*word;
  int type;
  int argc;
  aspell *sc;
   TLS_VARS;

    argc = ARG_COUNT(ht);
    if (argc != 2 || getParameters(ht, argc, &scin,&word) == FAILURE) {
        WRONG_PARAM_COUNT;
    }
    convert_to_long(scin);
    convert_to_string(word);
    sc= (aspell *) php3_list_find(scin->value.lval, &type);
    if(!sc)
      {
        php3_error(E_WARNING, "%d is not a ASPELL result index", scin->value.lval);
        RETURN_FALSE;
      }
	if (aspell_check_raw(sc, word->value.str.val)) 
	  {
	    RETURN_TRUE;
	  }
	else
	  {
	    RETURN_FALSE;
	      }
}
/* }}} */

void php3_info_aspell(void)
{
	TLS_VARS;
	php3_printf("ASpell support enabled");

}

#endif