PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/enchant - enchant.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 141 253 55.7 %
Date: 2014-09-27 Functions: 16 30 53.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   +----------------------------------------------------------------------+
       3             :   | PHP Version 7                                                        |
       4             :   +----------------------------------------------------------------------+
       5             :   | Copyright (c) 1997-2014 The PHP Group                                |
       6             :   +----------------------------------------------------------------------+
       7             :   | This source file is subject to version 3.0 of the PHP license,       |
       8             :   | that is bundled with this package in the file LICENSE, and is        |
       9             :   | available at through the world-wide-web at                           |
      10             :   | http://www.php.net/license/3_0.txt.                                  |
      11             :   | If you did not receive a copy of the PHP license and are unable to   |
      12             :   | obtain it through the world-wide-web, please send a note to          |
      13             :   | license@php.net so we can mail you a copy immediately.               |
      14             :   +----------------------------------------------------------------------+
      15             :   | Author: Pierre-Alain Joye <paj@pearfr.org>                           |
      16             :   |         Ilia Alshanetsky <ilia@prohost.org>                          |
      17             :   +----------------------------------------------------------------------+
      18             : 
      19             :   $Id: ca337009826730a4535c3dc441527db0b6bd0302 $
      20             : */
      21             : 
      22             : #ifdef HAVE_CONFIG_H
      23             : #include "config.h"
      24             : #endif
      25             : 
      26             : #include "php.h"
      27             : #include "php_ini.h"
      28             : #include "ext/standard/info.h"
      29             : #include <enchant.h>
      30             : #include "php_enchant.h"
      31             : 
      32             : typedef EnchantBroker * EnchantBrokerPtr;
      33             : typedef struct _broker_struct enchant_broker;
      34             : typedef struct _dict_struct enchant_dict;
      35             : 
      36             : typedef enchant_broker * enchant_brokerPtr;
      37             : typedef enchant_dict * enchant_dictPtr;
      38             : 
      39             : typedef struct _broker_struct {
      40             :         EnchantBroker   *pbroker;
      41             :         enchant_dict    **dict;
      42             :         unsigned int    dictcnt;
      43             :         zend_resource   *rsrc;
      44             : } _enchant_broker;
      45             : 
      46             : typedef struct _dict_struct {
      47             :         unsigned int    id;
      48             :         EnchantDict             *pdict;
      49             :         enchant_broker  *pbroker;
      50             :         zend_resource   *rsrc;
      51             : } _enchant_dict;
      52             : 
      53             : 
      54             : /* True global resources - no need for thread safety here */
      55             : static int le_enchant_broker;
      56             : static int le_enchant_dict;
      57             : 
      58             : /* If you declare any globals in php_enchant.h uncomment this:*/
      59             : /*ZEND_DECLARE_MODULE_GLOBALS(enchant)*/
      60             : 
      61             : #define PHP_ENCHANT_MYSPELL 1
      62             : #define PHP_ENCHANT_ISPELL 2
      63             : 
      64             : /* {{{ arginfo */
      65             : ZEND_BEGIN_ARG_INFO(arginfo_enchant_broker_init, 0)
      66             : ZEND_END_ARG_INFO()
      67             : 
      68             : ZEND_BEGIN_ARG_INFO_EX(arginfo_enchant_broker_free, 0, 0, 1)
      69             :         ZEND_ARG_INFO(0, broker)
      70             : ZEND_END_ARG_INFO()
      71             : 
      72             : ZEND_BEGIN_ARG_INFO_EX(arginfo_enchant_broker_set_dict_path, 0, 0, 3)
      73             :         ZEND_ARG_INFO(0, broker)
      74             :         ZEND_ARG_INFO(0, name)
      75             :         ZEND_ARG_INFO(0, value)
      76             : ZEND_END_ARG_INFO()
      77             : 
      78             : ZEND_BEGIN_ARG_INFO_EX(arginfo_enchant_broker_get_dict_path, 0, 0, 2)
      79             :         ZEND_ARG_INFO(0, broker)
      80             :         ZEND_ARG_INFO(0, name)
      81             : ZEND_END_ARG_INFO()
      82             : 
      83             : ZEND_BEGIN_ARG_INFO_EX(arginfo_enchant_broker_request_dict, 0, 0, 2)
      84             :         ZEND_ARG_INFO(0, broker)
      85             :         ZEND_ARG_INFO(0, tag)
      86             : ZEND_END_ARG_INFO()
      87             : 
      88             : ZEND_BEGIN_ARG_INFO_EX(arginfo_enchant_broker_request_pwl_dict, 0, 0, 2)
      89             :         ZEND_ARG_INFO(0, broker)
      90             :         ZEND_ARG_INFO(0, filename)
      91             : ZEND_END_ARG_INFO()
      92             : 
      93             : ZEND_BEGIN_ARG_INFO_EX(arginfo_enchant_broker_free_dict, 0, 0, 1)
      94             :         ZEND_ARG_INFO(0, dict)
      95             : ZEND_END_ARG_INFO()
      96             : 
      97             : ZEND_BEGIN_ARG_INFO_EX(arginfo_enchant_broker_set_ordering, 0, 0, 3)
      98             :         ZEND_ARG_INFO(0, broker)
      99             :         ZEND_ARG_INFO(0, tag)
     100             :         ZEND_ARG_INFO(0, ordering)
     101             : ZEND_END_ARG_INFO()
     102             : 
     103             : ZEND_BEGIN_ARG_INFO_EX(arginfo_enchant_dict_quick_check, 0, 0, 2)
     104             :         ZEND_ARG_INFO(0, dict)
     105             :         ZEND_ARG_INFO(0, word)
     106             :         ZEND_ARG_INFO(1, suggestions)
     107             : ZEND_END_ARG_INFO()
     108             : 
     109             : ZEND_BEGIN_ARG_INFO_EX(arginfo_enchant_dict_check, 0, 0, 2)
     110             :         ZEND_ARG_INFO(0, dict)
     111             :         ZEND_ARG_INFO(0, word)
     112             : ZEND_END_ARG_INFO()
     113             : 
     114             : ZEND_BEGIN_ARG_INFO_EX(arginfo_enchant_dict_store_replacement, 0, 0, 3)
     115             :         ZEND_ARG_INFO(0, dict)
     116             :         ZEND_ARG_INFO(0, mis)
     117             :         ZEND_ARG_INFO(0, cor)
     118             : ZEND_END_ARG_INFO()
     119             : /* }}} */
     120             : 
     121             : /* {{{ enchant_functions[]
     122             :  *
     123             :  * Every user visible function must have an entry in enchant_functions[].
     124             :  */
     125             : zend_function_entry enchant_functions[] = {
     126             :         PHP_FE(enchant_broker_init,                     arginfo_enchant_broker_init)
     127             :         PHP_FE(enchant_broker_free,                     arginfo_enchant_broker_free)
     128             :         PHP_FE(enchant_broker_get_error,                arginfo_enchant_broker_free)
     129             :         PHP_FE(enchant_broker_set_dict_path,    arginfo_enchant_broker_set_dict_path)
     130             :         PHP_FE(enchant_broker_get_dict_path,    arginfo_enchant_broker_get_dict_path)
     131             :         PHP_FE(enchant_broker_list_dicts,               arginfo_enchant_broker_free)
     132             :         PHP_FE(enchant_broker_request_dict,             arginfo_enchant_broker_request_dict)
     133             :         PHP_FE(enchant_broker_request_pwl_dict, arginfo_enchant_broker_request_pwl_dict)
     134             :         PHP_FE(enchant_broker_free_dict,                arginfo_enchant_broker_free_dict)
     135             :         PHP_FE(enchant_broker_dict_exists,              arginfo_enchant_broker_request_dict)
     136             :         PHP_FE(enchant_broker_set_ordering,     arginfo_enchant_broker_set_ordering)
     137             :         PHP_FE(enchant_broker_describe,                 arginfo_enchant_broker_free)
     138             :         PHP_FE(enchant_dict_check,                              arginfo_enchant_dict_check)
     139             :         PHP_FE(enchant_dict_suggest,                    arginfo_enchant_dict_check)
     140             :         PHP_FE(enchant_dict_add_to_personal,    arginfo_enchant_dict_check)
     141             :         PHP_FE(enchant_dict_add_to_session,     arginfo_enchant_dict_check)
     142             :         PHP_FE(enchant_dict_is_in_session,              arginfo_enchant_dict_check)
     143             :         PHP_FE(enchant_dict_store_replacement,  arginfo_enchant_dict_store_replacement)
     144             :         PHP_FE(enchant_dict_get_error,                  arginfo_enchant_broker_free_dict)
     145             :         PHP_FE(enchant_dict_describe,                   arginfo_enchant_broker_free_dict)
     146             :         PHP_FE(enchant_dict_quick_check,                arginfo_enchant_dict_quick_check)
     147             :         PHP_FE_END
     148             : };
     149             : /* }}} */
     150             : 
     151             : /* {{{ enchant_module_entry
     152             :  */
     153             : zend_module_entry enchant_module_entry = {
     154             : #if ZEND_MODULE_API_NO >= 20010901
     155             :         STANDARD_MODULE_HEADER,
     156             : #endif
     157             :         "enchant",
     158             :         enchant_functions,
     159             :         PHP_MINIT(enchant),
     160             :         PHP_MSHUTDOWN(enchant),
     161             :         NULL,   /* Replace with NULL if there's nothing to do at request start */
     162             :         NULL,   /* Replace with NULL if there's nothing to do at request end */
     163             :         PHP_MINFO(enchant),
     164             : #if ZEND_MODULE_API_NO >= 20010901
     165             :         PHP_ENCHANT_VERSION,
     166             : #endif
     167             :         STANDARD_MODULE_PROPERTIES
     168             : };
     169             : /* }}} */
     170             : 
     171             : #ifdef COMPILE_DL_ENCHANT
     172             : ZEND_GET_MODULE(enchant)
     173             : #endif
     174             : 
     175             : static void
     176           1 : enumerate_providers_fn (const char * const name,
     177             :                         const char * const desc,
     178             :                         const char * const file,
     179             :                         void * ud) /* {{{ */
     180             : {
     181           1 :         zval *zdesc = (zval *) ud;
     182             :         zval tmp_array;
     183             : 
     184           1 :         array_init(&tmp_array);
     185             : 
     186           1 :         add_assoc_string(&tmp_array, "name", (char *)name);
     187           1 :         add_assoc_string(&tmp_array, "desc", (char *)desc);
     188           1 :         add_assoc_string(&tmp_array, "file", (char *)file);
     189             : 
     190           1 :         if (Z_TYPE_P(zdesc)!=IS_ARRAY) {
     191           1 :                 array_init(zdesc);
     192             :         }
     193             : 
     194           1 :         add_next_index_zval(zdesc, &tmp_array);
     195           1 : }
     196             : /* }}} */
     197             : 
     198             : static void
     199           0 : describe_dict_fn (const char * const lang,
     200             :                   const char * const name,
     201             :                   const char * const desc,
     202             :                   const char * const file,
     203             :                   void * ud) /* {{{ */
     204             : {
     205           0 :         zval *zdesc = (zval *) ud;
     206           0 :         array_init(zdesc);
     207           0 :         add_assoc_string(zdesc, "lang", (char *)lang);
     208           0 :         add_assoc_string(zdesc, "name", (char *)name);
     209           0 :         add_assoc_string(zdesc, "desc", (char *)desc);
     210           0 :         add_assoc_string(zdesc, "file", (char *)file);
     211           0 : }
     212             : /* }}} */
     213             : 
     214         210 : static void php_enchant_list_dicts_fn( const char * const lang_tag,
     215             :                 const char * const provider_name, const char * const provider_desc,
     216             :                 const char * const provider_file, void * ud) /* {{{ */
     217             : {
     218         210 :         zval *zdesc = (zval *) ud;
     219             :         zval tmp_array;
     220             : 
     221         210 :         array_init(&tmp_array);
     222         210 :         add_assoc_string(&tmp_array, "lang_tag", (char *)lang_tag);
     223         210 :         add_assoc_string(&tmp_array, "provider_name", (char *)provider_name);
     224         210 :         add_assoc_string(&tmp_array, "provider_desc", (char *)provider_desc);
     225         210 :         add_assoc_string(&tmp_array, "provider_file", (char *)provider_file);
     226             : 
     227         210 :         if (Z_TYPE_P(zdesc) != IS_ARRAY) {
     228           1 :                 array_init(zdesc);
     229             :         }
     230         210 :         add_next_index_zval(zdesc, &tmp_array);
     231             : 
     232         210 : }
     233             : /* }}} */
     234             : 
     235           8 : static void php_enchant_broker_free(zend_resource *rsrc TSRMLS_DC) /* {{{ */
     236             : {
     237           8 :         if (rsrc->ptr) {
     238           8 :                 enchant_broker *broker = (enchant_broker *)rsrc->ptr;
     239           8 :                 if (broker) {
     240           8 :                         if (broker->pbroker) {
     241           8 :                                 if (broker->dictcnt && broker->dict) {
     242           4 :                                         if (broker->dict) {
     243             :                                                 int total;
     244           4 :                                                 total = broker->dictcnt-1;
     245             :                                                 do {
     246           4 :                                                         if (broker->dict[total]) {
     247           0 :                                                                 enchant_dict *pdict = broker->dict[total];
     248           0 :                                                                 broker->dict[total] = NULL;
     249           0 :                                                                 zend_list_free(pdict->rsrc);
     250           0 :                                                                 efree(pdict);
     251             :                                                         }
     252           4 :                                                         total--;
     253           4 :                                                 } while (total>=0);
     254             :                                         }
     255           4 :                                         efree(broker->dict);
     256           4 :                                         broker->dict = NULL;
     257             :                                 }
     258           8 :                                 enchant_broker_free(broker->pbroker);
     259             :                         }
     260           8 :                         efree(broker);
     261             :                 }
     262             :         }
     263           8 : }
     264             : /* }}} */
     265             : 
     266           4 : static void php_enchant_dict_free(zend_resource *rsrc TSRMLS_DC) /* {{{ */
     267             : 
     268             : {
     269           4 :         if (rsrc->ptr) {
     270           4 :                 enchant_dict *pdict = (enchant_dict *)rsrc->ptr;
     271           4 :                 if (pdict) {
     272           4 :                         enchant_broker *pbroker = pdict->pbroker;
     273             : 
     274           4 :                         if (pdict->pdict && pbroker) {
     275           4 :                                 enchant_broker_free_dict(pbroker->pbroker, pdict->pdict);
     276             :                         }
     277             : 
     278           4 :                         pbroker->dict[pdict->id] = NULL;
     279           4 :                         efree(pdict);
     280           4 :                         zend_list_delete(pbroker->rsrc);
     281             :                 }
     282             :         }
     283           4 : }
     284             : /* }}} */
     285             : 
     286             : /* {{{ PHP_MINIT_FUNCTION
     287             :  */
     288       20352 : PHP_MINIT_FUNCTION(enchant)
     289             : {
     290       20352 :         le_enchant_broker = zend_register_list_destructors_ex(php_enchant_broker_free, NULL, "enchant_broker", module_number);
     291       20352 :         le_enchant_dict = zend_register_list_destructors_ex(php_enchant_dict_free, NULL, "enchant_dict", module_number);
     292       20352 :         REGISTER_LONG_CONSTANT("ENCHANT_MYSPELL", PHP_ENCHANT_MYSPELL, CONST_CS | CONST_PERSISTENT);
     293       20352 :         REGISTER_LONG_CONSTANT("ENCHANT_ISPELL", PHP_ENCHANT_ISPELL, CONST_CS | CONST_PERSISTENT);
     294       20352 :         return SUCCESS;
     295             : }
     296             : /* }}} */
     297             : 
     298             : /* {{{ PHP_MSHUTDOWN_FUNCTION
     299             :  */
     300       20386 : PHP_MSHUTDOWN_FUNCTION(enchant)
     301             : {
     302       20386 :         return SUCCESS;
     303             : }
     304             : /* }}} */
     305             : 
     306         143 : static void __enumerate_providers_fn (const char * const name,
     307             :                         const char * const desc,
     308             :                         const char * const file,
     309             :                         void * ud) /* {{{ */
     310             : {
     311         143 :         php_info_print_table_row(3, name, desc, file);
     312         143 : }
     313             : /* }}} */
     314             : 
     315             : /* {{{ PHP_MINFO_FUNCTION
     316             :  */
     317         143 : PHP_MINFO_FUNCTION(enchant)
     318             : {
     319             :         EnchantBroker *pbroker;
     320             : 
     321         143 :         pbroker = enchant_broker_init();
     322         143 :         php_info_print_table_start();
     323         143 :         php_info_print_table_header(2, "enchant support", "enabled");
     324         143 :         php_info_print_table_row(2, "Version", PHP_ENCHANT_VERSION);
     325             : #ifdef ENCHANT_VERSION_STRING
     326             :         php_info_print_table_row(2, "Libenchant Version", ENCHANT_VERSION_STRING);
     327             : #elif defined(HAVE_ENCHANT_BROKER_SET_PARAM)
     328             :         php_info_print_table_row(2, "Libenchant Version", "1.5.0 or later");
     329             : #endif
     330         143 :         php_info_print_table_row(2, "Revision", "$Id: ca337009826730a4535c3dc441527db0b6bd0302 $");
     331         143 :         php_info_print_table_end();
     332             : 
     333         143 :         php_info_print_table_start();
     334         143 :         enchant_broker_describe(pbroker, __enumerate_providers_fn, NULL);
     335         143 :         php_info_print_table_end();
     336         143 :         enchant_broker_free(pbroker);
     337         143 : }
     338             : /* }}} */
     339             : 
     340             : #define PHP_ENCHANT_GET_BROKER  \
     341             :         ZEND_FETCH_RESOURCE(pbroker, enchant_broker *, broker, -1, "enchant_broker", le_enchant_broker);      \
     342             :         if (!pbroker || !pbroker->pbroker) { \
     343             :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", "Resource broker invalid");       \
     344             :                 RETURN_FALSE;   \
     345             :         }
     346             : 
     347             : #define PHP_ENCHANT_GET_DICT    \
     348             :         ZEND_FETCH_RESOURCE(pdict, enchant_dict *, dict, -1, "enchant_dict", le_enchant_dict);        \
     349             :         if (!pdict || !pdict->pdict) {       \
     350             :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", "Invalid dictionary resource.");  \
     351             :                 RETURN_FALSE;   \
     352             :         }
     353             : 
     354             : /* {{{ proto resource enchant_broker_init()
     355             :    create a new broker object capable of requesting */
     356           8 : PHP_FUNCTION(enchant_broker_init)
     357             : {
     358             :         enchant_broker *broker;
     359             :         EnchantBroker *pbroker;
     360             : 
     361           8 :         if (zend_parse_parameters_none() == FAILURE) {
     362           0 :                 return;
     363             :         }
     364             : 
     365           8 :         pbroker = enchant_broker_init();
     366             : 
     367           8 :         if (pbroker) {
     368           8 :                 broker = (enchant_broker *) emalloc(sizeof(enchant_broker));
     369           8 :                 broker->pbroker = pbroker;
     370           8 :                 broker->dict = NULL;
     371           8 :                 broker->dictcnt = 0;
     372           8 :                 broker->rsrc = ZEND_REGISTER_RESOURCE(return_value, broker, le_enchant_broker);
     373             :         } else {
     374           0 :                 RETURN_FALSE;
     375             :         }
     376             : }
     377             : /* }}} */
     378             : 
     379             : /* {{{ proto boolean enchant_broker_free(resource broker)
     380             :    Destroys the broker object and its dictionnaries */
     381           1 : PHP_FUNCTION(enchant_broker_free)
     382             : {
     383             :         zval *broker;
     384             :         enchant_broker *pbroker;
     385             : 
     386           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &broker) == FAILURE) {
     387           0 :                 RETURN_FALSE;
     388             :         }
     389           1 :         PHP_ENCHANT_GET_BROKER;
     390             : 
     391           1 :         zend_list_close(Z_RES_P(broker));
     392           1 :         RETURN_TRUE;
     393             : }
     394             : /* }}} */
     395             : 
     396             : /* {{{ proto string enchant_broker_get_error(resource broker)
     397             :    Returns the last error of the broker */
     398           0 : PHP_FUNCTION(enchant_broker_get_error)
     399             : {
     400             :         zval *broker;
     401             :         enchant_broker *pbroker;
     402             :         char *msg;
     403             : 
     404           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &broker) == FAILURE) {
     405           0 :                 RETURN_FALSE;
     406             :         }
     407             : 
     408           0 :         PHP_ENCHANT_GET_BROKER;
     409             : 
     410           0 :         msg = enchant_broker_get_error(pbroker->pbroker);
     411           0 :         if (msg) {
     412           0 :                 RETURN_STRING((char *)msg);
     413             :         }
     414           0 :         RETURN_FALSE;
     415             : }
     416             : /* }}} */
     417             : 
     418             : #if HAVE_ENCHANT_BROKER_SET_PARAM
     419             : /* {{{ proto bool enchant_broker_set_dict_path(resource broker, int dict_type, string value)
     420             :         Set the directory path for a given backend, works with ispell and myspell */
     421             : PHP_FUNCTION(enchant_broker_set_dict_path)
     422             : {
     423             :         zval *broker;
     424             :         enchant_broker *pbroker;
     425             :         zend_long dict_type;
     426             :         char *value;
     427             :         size_t value_len;
     428             : 
     429             :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rls", &broker, &dict_type, &value, &value_len) == FAILURE) {
     430             :                 RETURN_FALSE;
     431             :         }
     432             : 
     433             :         if (!value_len) {
     434             :                 RETURN_FALSE;
     435             :         }
     436             :         
     437             :         PHP_ENCHANT_GET_BROKER;
     438             : 
     439             :         switch (dict_type) {
     440             :                 case PHP_ENCHANT_MYSPELL:
     441             :                         PHP_ENCHANT_GET_BROKER;
     442             :                         enchant_broker_set_param(pbroker->pbroker, "enchant.myspell.dictionary.path", (const char *)value);
     443             :                         RETURN_TRUE;
     444             :                         break;
     445             : 
     446             :                 case PHP_ENCHANT_ISPELL:
     447             :                         PHP_ENCHANT_GET_BROKER;
     448             :                         enchant_broker_set_param(pbroker->pbroker, "enchant.ispell.dictionary.path", (const char *)value);
     449             :                         RETURN_TRUE;
     450             :                         break;
     451             : 
     452             :                 default:
     453             :                         RETURN_FALSE;
     454             :         }
     455             : }
     456             : /* }}} */
     457             : 
     458             : 
     459             : /* {{{ proto string enchant_broker_get_dict_path(resource broker, int dict_type)
     460             :         Get the directory path for a given backend, works with ispell and myspell */
     461             : PHP_FUNCTION(enchant_broker_get_dict_path)
     462             : {
     463             :         zval *broker;
     464             :         enchant_broker *pbroker;
     465             :         zend_long dict_type;
     466             :         char *value;
     467             : 
     468             :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &broker, &dict_type) == FAILURE) {
     469             :                 RETURN_FALSE;
     470             :         }
     471             :         
     472             :         PHP_ENCHANT_GET_BROKER;
     473             : 
     474             :         switch (dict_type) {
     475             :                 case PHP_ENCHANT_MYSPELL:
     476             :                         PHP_ENCHANT_GET_BROKER;
     477             :                         value = enchant_broker_get_param(pbroker->pbroker, "enchant.myspell.dictionary.path");
     478             :                         break;
     479             : 
     480             :                 case PHP_ENCHANT_ISPELL:
     481             :                         PHP_ENCHANT_GET_BROKER;
     482             :                         value = enchant_broker_get_param(pbroker->pbroker, "enchant.ispell.dictionary.path");
     483             :                         break;
     484             : 
     485             :                 default:
     486             :                         RETURN_FALSE;
     487             :         }
     488             : 
     489             :         RETURN_STRING(value);
     490             : }
     491             : /* }}} */
     492             : #else
     493             : /* {{{ proto bool enchant_broker_set_dict_path(resource broker, int dict_type, string value)
     494             :         Set the directory path for a given backend, works with ispell and myspell */
     495           0 : PHP_FUNCTION(enchant_broker_set_dict_path)
     496             : {
     497           0 :         RETURN_FALSE;
     498             : }
     499             : /* }}} */
     500             : 
     501             : 
     502             : /* {{{ proto string enchant_broker_get_dict_path(resource broker, int dict_type)
     503             :         Get the directory path for a given backend, works with ispell and myspell */
     504           0 : PHP_FUNCTION(enchant_broker_get_dict_path)
     505             : {
     506           0 :         RETURN_FALSE;
     507             : }
     508             : /* }}} */
     509             : #endif
     510             : 
     511             : /* {{{ proto string enchant_broker_list_dicts(resource broker)
     512             :    Lists the dictionaries available for the given broker */
     513           1 : PHP_FUNCTION(enchant_broker_list_dicts)
     514             : {
     515             :         zval *broker;
     516             :         enchant_broker *pbroker;
     517             : 
     518           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &broker) == FAILURE) {
     519           0 :                 RETURN_FALSE;
     520             :         }
     521             : 
     522           1 :         PHP_ENCHANT_GET_BROKER;
     523             : 
     524           1 :         enchant_broker_list_dicts(pbroker->pbroker, php_enchant_list_dicts_fn, (void *)return_value);
     525             : }
     526             : /* }}} */
     527             : 
     528             : /* {{{ proto resource enchant_broker_request_dict(resource broker, string tag)
     529             :         create a new dictionary using tag, the non-empty language tag you wish to request
     530             :         a dictionary for ("en_US", "de_DE", ...) */
     531           4 : PHP_FUNCTION(enchant_broker_request_dict)
     532             : {
     533             :         zval *broker;
     534             :         enchant_broker *pbroker;
     535             :         enchant_dict *dict;
     536             :         EnchantDict *d;
     537             :         char *tag;
     538             :         size_t taglen;
     539             :         int pos;
     540             : 
     541           4 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &broker, &tag, &taglen) == FAILURE) {
     542           0 :                 RETURN_FALSE;
     543             :         }
     544             : 
     545           4 :         PHP_ENCHANT_GET_BROKER;
     546             :         
     547           4 :         if (taglen == 0) {
     548           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Tag cannot be empty");
     549           0 :                 RETURN_FALSE;
     550             :         }
     551             : 
     552           4 :         d = enchant_broker_request_dict(pbroker->pbroker, (const char *)tag);
     553           4 :         if (d) {
     554           4 :                 if (pbroker->dictcnt) {
     555           0 :                         pbroker->dict = (enchant_dict **)erealloc(pbroker->dict, sizeof(enchant_dict *) * pbroker->dictcnt);
     556           0 :                         pos = pbroker->dictcnt++;
     557             :                 } else {
     558           4 :                         pbroker->dict = (enchant_dict **)emalloc(sizeof(enchant_dict *));
     559           4 :                         pos = 0;
     560           4 :                         pbroker->dictcnt++;
     561             :                 }
     562             : 
     563           4 :                 dict = pbroker->dict[pos] = (enchant_dict *)emalloc(sizeof(enchant_dict));
     564           4 :                 dict->id = pos;
     565           4 :                 dict->pbroker = pbroker;
     566           4 :                 dict->pdict = d;
     567           4 :                 pbroker->dict[pos] = dict;
     568             : 
     569           4 :                 dict->rsrc = ZEND_REGISTER_RESOURCE(return_value, dict, le_enchant_dict);
     570           4 :                 pbroker->rsrc->gc.refcount++;
     571             :         } else {
     572           0 :                 RETURN_FALSE;
     573             :         }
     574             : }
     575             : /* }}} */
     576             : 
     577             : /* {{{ proto resource enchant_broker_request_pwl_dict(resource broker, string filename)
     578             :    creates a dictionary using a PWL file. A PWL file is personal word file one word per line. It must exist before the call.*/
     579           0 : PHP_FUNCTION(enchant_broker_request_pwl_dict)
     580             : {
     581             :         zval *broker;
     582             :         enchant_broker *pbroker;
     583             :         enchant_dict *dict;
     584             :         EnchantDict *d;
     585             :         char *pwl;
     586             :         size_t pwllen;
     587             :         int pos;
     588             : 
     589           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rp", &broker, &pwl, &pwllen) == FAILURE) {
     590           0 :                 RETURN_FALSE;
     591             :         }
     592             : 
     593             : #if PHP_API_VERSION < 20100412
     594             :         if ((PG(safe_mode) && (!php_checkuid(pwl, NULL, CHECKUID_CHECK_FILE_AND_DIR))) || php_check_open_basedir(pwl TSRMLS_CC)) {
     595             : #else
     596           0 :         if (php_check_open_basedir(pwl TSRMLS_CC)) {
     597             : #endif
     598           0 :                 RETURN_FALSE;
     599             :         }
     600             : 
     601           0 :         PHP_ENCHANT_GET_BROKER;
     602             : 
     603           0 :         d = enchant_broker_request_pwl_dict(pbroker->pbroker, (const char *)pwl);
     604           0 :         if (d) {
     605           0 :                 if (pbroker->dictcnt) {
     606           0 :                         pos = pbroker->dictcnt++;
     607           0 :                         pbroker->dict = (enchant_dict **)erealloc(pbroker->dict, sizeof(enchant_dict *) * pbroker->dictcnt);
     608             :                 } else {
     609           0 :                         pbroker->dict = (enchant_dict **)emalloc(sizeof(enchant_dict *));
     610           0 :                         pos = 0;
     611           0 :                         pbroker->dictcnt++;
     612             :                 }
     613           0 :                 dict = pbroker->dict[pos] = (enchant_dict *)emalloc(sizeof(enchant_dict));
     614           0 :                 dict->id = pos;
     615           0 :                 dict->pbroker = pbroker;
     616           0 :                 dict->pdict = d;
     617           0 :                 pbroker->dict[pos] = dict;
     618             : 
     619           0 :                 dict->rsrc = ZEND_REGISTER_RESOURCE(return_value, dict, le_enchant_dict);
     620           0 :                 pbroker->rsrc->gc.refcount++;
     621             :         } else {
     622           0 :                 RETURN_FALSE;
     623             :         }
     624             : }
     625             : /* }}} */
     626             : 
     627             : /* {{{ proto resource enchant_broker_free_dict(resource dict)
     628             :    Free the dictionary resource */
     629           0 : PHP_FUNCTION(enchant_broker_free_dict)
     630             : {
     631             :         zval *dict;
     632             :         enchant_dict *pdict;
     633             : 
     634           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &dict) == FAILURE) {
     635           0 :                 RETURN_FALSE;
     636             :         }
     637             : 
     638           0 :         PHP_ENCHANT_GET_DICT;
     639             : 
     640           0 :         zend_list_close(Z_RES_P(dict));
     641           0 :         RETURN_TRUE;
     642             : }
     643             : /* }}} */
     644             : 
     645             : /* {{{ proto bool enchant_broker_dict_exists(resource broker, string tag)
     646             :    Whether a dictionary exists or not. Using non-empty tag */
     647           1 : PHP_FUNCTION(enchant_broker_dict_exists)
     648             : {
     649             :         zval *broker;
     650             :         char *tag;
     651             :         size_t taglen;
     652             :         enchant_broker * pbroker;
     653             : 
     654           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &broker, &tag, &taglen) == FAILURE) {
     655           0 :                 RETURN_FALSE;
     656             :         }
     657             : 
     658           1 :         PHP_ENCHANT_GET_BROKER;
     659             : 
     660           1 :         RETURN_BOOL(enchant_broker_dict_exists(pbroker->pbroker, tag));
     661             : }
     662             : /* }}} */
     663             : 
     664             : /* {{{ proto bool enchant_broker_set_ordering(resource broker, string tag, string ordering)
     665             :         Declares a preference of dictionaries to use for the language
     666             :         described/referred to by 'tag'. The ordering is a comma delimited
     667             :         list of provider names. As a special exception, the "*" tag can
     668             :         be used as a language tag to declare a default ordering for any
     669             :         language that does not explicitly declare an ordering. */
     670             : 
     671           0 : PHP_FUNCTION(enchant_broker_set_ordering)
     672             : {
     673             :         zval *broker;
     674             :         char *pordering;
     675             :         size_t porderinglen;
     676             :         char *ptag;
     677             :         size_t ptaglen;
     678             :         enchant_broker * pbroker;
     679             : 
     680           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &broker, &ptag, &ptaglen, &pordering, &porderinglen) == FAILURE) {
     681           0 :                 RETURN_FALSE;
     682             :         }
     683             : 
     684           0 :         PHP_ENCHANT_GET_BROKER;
     685             : 
     686           0 :         enchant_broker_set_ordering(pbroker->pbroker, ptag, pordering);
     687           0 :         RETURN_TRUE;
     688             : }
     689             : /* }}} */
     690             : 
     691             : /* {{{ proto array enchant_broker_describe(resource broker)
     692             :         Enumerates the Enchant providers and tells you some rudimentary information about them. The same info is provided through phpinfo() */
     693           1 : PHP_FUNCTION(enchant_broker_describe)
     694             : {
     695           1 :         EnchantBrokerDescribeFn describetozval = enumerate_providers_fn;
     696             :         zval *broker;
     697             :         enchant_broker * pbroker;
     698             : 
     699           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &broker) == FAILURE) {
     700           0 :                 RETURN_FALSE;
     701             :         }
     702             : 
     703           1 :         PHP_ENCHANT_GET_BROKER;
     704             : 
     705           1 :         enchant_broker_describe(pbroker->pbroker, describetozval, (void *)return_value);
     706             : }
     707             : /* }}} */
     708             : 
     709             : /* {{{ proto bool enchant_dict_quick_check(resource dict, string word [, array &suggestions])
     710             :     If the word is correctly spelled return true, otherwise return false, if suggestions variable
     711             :     is provided, fill it with spelling alternatives. */
     712           1 : PHP_FUNCTION(enchant_dict_quick_check)
     713             : {
     714           1 :         zval *dict, *sugg = NULL;
     715             :         char *word;
     716             :         size_t wordlen;
     717             :         enchant_dict *pdict;
     718             : 
     719           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|z/", &dict, &word, &wordlen, &sugg) == FAILURE) {
     720           0 :                 RETURN_FALSE;
     721             :         }
     722             : 
     723           1 :         if (sugg) {
     724           1 :                 zval_dtor(sugg);
     725           1 :                 array_init(sugg);
     726             :         }
     727             : 
     728           1 :         PHP_ENCHANT_GET_DICT;
     729             : 
     730           1 :         if (enchant_dict_check(pdict->pdict, word, wordlen) > 0) {
     731             :                 int n_sugg;
     732             :                 size_t n_sugg_st;
     733             :                 char **suggs;
     734             : 
     735           1 :                 if (!sugg && ZEND_NUM_ARGS() == 2) {
     736           0 :                         RETURN_FALSE;
     737             :                 }
     738             : 
     739           1 :                 suggs = enchant_dict_suggest(pdict->pdict, word, wordlen, &n_sugg_st);
     740           1 :                 memcpy(&n_sugg, &n_sugg_st, sizeof(n_sugg));
     741           1 :                 if (suggs && n_sugg) {
     742             :                         int i;
     743           7 :                         for (i = 0; i < n_sugg; i++) {
     744           6 :                                 add_next_index_string(sugg, suggs[i]);
     745             :                         }
     746           1 :                         enchant_dict_free_suggestions(pdict->pdict, suggs);
     747             :                 }
     748             : 
     749             : 
     750           1 :                 RETURN_FALSE;
     751             :         }
     752           0 :         RETURN_TRUE;
     753             : }
     754             : /* }}} */
     755             : 
     756             : /* {{{ proto bool enchant_dict_check(resource dict, string word)
     757             :     If the word is correctly spelled return true, otherwise return false */
     758           0 : PHP_FUNCTION(enchant_dict_check)
     759             : {
     760             :         zval *dict;
     761             :         char *word;
     762             :         size_t wordlen;
     763             :         enchant_dict *pdict;
     764             : 
     765           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &dict, &word, &wordlen) == FAILURE) {
     766           0 :                 RETURN_FALSE;
     767             :         }
     768             : 
     769           0 :         PHP_ENCHANT_GET_DICT;
     770             : 
     771           0 :         RETURN_BOOL(!enchant_dict_check(pdict->pdict, word, wordlen));
     772             : }
     773             : /* }}} */
     774             : 
     775             : /* {{{ proto array enchant_dict_suggest(resource dict, string word)
     776             :     Will return a list of values if any of those pre-conditions are not met.*/
     777           1 : PHP_FUNCTION(enchant_dict_suggest)
     778             : {
     779             :         zval *dict;
     780             :         char *word;
     781             :         size_t wordlen;
     782             :         char **suggs;
     783             :         enchant_dict *pdict;
     784             :         int n_sugg;
     785             :         size_t n_sugg_st;
     786             : 
     787           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &dict, &word, &wordlen) == FAILURE) {
     788           0 :                 RETURN_FALSE;
     789             :         }
     790             : 
     791           1 :         PHP_ENCHANT_GET_DICT;
     792             : 
     793           1 :         suggs = enchant_dict_suggest(pdict->pdict, word, wordlen, &n_sugg_st);
     794           1 :         memcpy(&n_sugg, &n_sugg_st, sizeof(n_sugg));
     795           1 :         if (suggs && n_sugg) {
     796             :                 int i;
     797             : 
     798           1 :                 array_init(return_value);
     799           6 :                 for (i = 0; i < n_sugg; i++) {
     800           5 :                         add_next_index_string(return_value, suggs[i]);
     801             :                 }
     802             : 
     803           1 :                 enchant_dict_free_suggestions(pdict->pdict, suggs);
     804             :         }
     805             : }
     806             : /* }}} */
     807             : 
     808             : /* {{{ proto void enchant_dict_add_to_personal(resource dict, string word)
     809             :      add 'word' to personal word list */
     810           0 : PHP_FUNCTION(enchant_dict_add_to_personal)
     811             : {
     812             :         zval *dict;
     813             :         char *word;
     814             :         size_t wordlen;
     815             :         enchant_dict *pdict;
     816             : 
     817           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &dict, &word, &wordlen) == FAILURE) {
     818           0 :                 RETURN_FALSE;
     819             :         }
     820             : 
     821           0 :         PHP_ENCHANT_GET_DICT;
     822             : 
     823           0 :         enchant_dict_add_to_personal(pdict->pdict, word, wordlen);
     824             : }
     825             : /* }}} */
     826             : 
     827             : /* {{{ proto void enchant_dict_add_to_session(resource dict, string word)
     828             :    add 'word' to this spell-checking session */
     829           0 : PHP_FUNCTION(enchant_dict_add_to_session)
     830             : {
     831             :         zval *dict;
     832             :         char *word;
     833             :         size_t wordlen;
     834             :         enchant_dict *pdict;
     835             : 
     836           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &dict, &word, &wordlen) == FAILURE) {
     837           0 :                 RETURN_FALSE;
     838             :         }
     839             : 
     840           0 :         PHP_ENCHANT_GET_DICT;
     841             : 
     842           0 :         enchant_dict_add_to_session(pdict->pdict, word, wordlen);
     843             : }
     844             : /* }}} */
     845             : 
     846             : /* {{{ proto bool enchant_dict_is_in_session(resource dict, string word)
     847             :    whether or not 'word' exists in this spelling-session */
     848           0 : PHP_FUNCTION(enchant_dict_is_in_session)
     849             : {
     850             :         zval *dict;
     851             :         char *word;
     852             :         size_t wordlen;
     853             :         enchant_dict *pdict;
     854             : 
     855           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &dict, &word, &wordlen) == FAILURE) {
     856           0 :                 RETURN_FALSE;
     857             :         }
     858             : 
     859           0 :         PHP_ENCHANT_GET_DICT;
     860             : 
     861           0 :         RETURN_BOOL(enchant_dict_is_in_session(pdict->pdict, word, wordlen));
     862             : }
     863             : /* }}} */
     864             : 
     865             : /* {{{ proto void enchant_dict_store_replacement(resource dict, string mis, string cor)
     866             :         add a correction for 'mis' using 'cor'.
     867             :         Notes that you replaced @mis with @cor, so it's possibly more likely
     868             :         that future occurrences of @mis will be replaced with @cor. So it might
     869             :         bump @cor up in the suggestion list.*/
     870           0 : PHP_FUNCTION(enchant_dict_store_replacement)
     871             : {
     872             :         zval *dict;
     873             :         char *mis, *cor;
     874             :         size_t mislen, corlen;
     875             : 
     876             :         enchant_dict *pdict;
     877             : 
     878           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &dict, &mis, &mislen, &cor, &corlen) == FAILURE) {
     879           0 :                 RETURN_FALSE;
     880             :         }
     881             : 
     882           0 :         PHP_ENCHANT_GET_DICT;
     883             : 
     884           0 :         enchant_dict_store_replacement(pdict->pdict, mis, mislen, cor, corlen);
     885             : }
     886             : /* }}} */
     887             : 
     888             : /* {{{ proto string enchant_dict_get_error(resource dict)
     889             :    Returns the last error of the current spelling-session */
     890           0 : PHP_FUNCTION(enchant_dict_get_error)
     891             : {
     892             :         zval *dict;
     893             :         enchant_dict *pdict;
     894             :         char *msg;
     895             : 
     896           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &dict) == FAILURE) {
     897           0 :                 RETURN_FALSE;
     898             :         }
     899             : 
     900           0 :         PHP_ENCHANT_GET_DICT;
     901             : 
     902           0 :         msg = enchant_dict_get_error(pdict->pdict);
     903           0 :         if (msg) {
     904           0 :                 RETURN_STRING((char *)msg);
     905             :         }
     906             : 
     907           0 :         RETURN_FALSE;
     908             : }
     909             : /* }}} */
     910             : 
     911             : /* {{{ proto array enchant_dict_describe(resource dict)
     912             :    Describes an individual dictionary 'dict' */
     913           0 : PHP_FUNCTION(enchant_dict_describe)
     914             : {
     915             :         zval *dict;
     916             :         enchant_dict *pdict;
     917             : 
     918           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &dict) == FAILURE) {
     919           0 :                 RETURN_FALSE;
     920             :         }
     921             : 
     922           0 :         PHP_ENCHANT_GET_DICT;
     923             : 
     924           0 :         enchant_dict_describe(pdict->pdict, describe_dict_fn, (void *)return_value);
     925             : }
     926             : /* }}} */
     927             : 
     928             : /*
     929             :  * Local variables:
     930             :  * tab-width: 4
     931             :  * c-basic-offset: 4
     932             :  * End:
     933             :  * vim600: noet sw=4 ts=4 fdm=marker
     934             :  * vim<600: noet sw=4 ts=4
     935             :  */

Generated by: LCOV version 1.10

Generated at Sat, 27 Sep 2014 16:43:08 +0000 (4 days ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.