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: 143 256 55.9 %
Date: 2015-04-30 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-2015 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: c9f7ccf977f2c1a70d742aabba655a8778732d5a $
      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) /* {{{ */
     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) /* {{{ */
     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       20871 : PHP_MINIT_FUNCTION(enchant)
     289             : {
     290       20871 :         le_enchant_broker = zend_register_list_destructors_ex(php_enchant_broker_free, NULL, "enchant_broker", module_number);
     291       20871 :         le_enchant_dict = zend_register_list_destructors_ex(php_enchant_dict_free, NULL, "enchant_dict", module_number);
     292       20871 :         REGISTER_LONG_CONSTANT("ENCHANT_MYSPELL", PHP_ENCHANT_MYSPELL, CONST_CS | CONST_PERSISTENT);
     293       20871 :         REGISTER_LONG_CONSTANT("ENCHANT_ISPELL", PHP_ENCHANT_ISPELL, CONST_CS | CONST_PERSISTENT);
     294       20871 :         return SUCCESS;
     295             : }
     296             : /* }}} */
     297             : 
     298             : /* {{{ PHP_MSHUTDOWN_FUNCTION
     299             :  */
     300       20905 : PHP_MSHUTDOWN_FUNCTION(enchant)
     301             : {
     302       20905 :         return SUCCESS;
     303             : }
     304             : /* }}} */
     305             : 
     306         145 : static void __enumerate_providers_fn (const char * const name,
     307             :                         const char * const desc,
     308             :                         const char * const file,
     309             :                         void * ud) /* {{{ */
     310             : {
     311         145 :         php_info_print_table_row(3, name, desc, file);
     312         145 : }
     313             : /* }}} */
     314             : 
     315             : /* {{{ PHP_MINFO_FUNCTION
     316             :  */
     317         145 : PHP_MINFO_FUNCTION(enchant)
     318             : {
     319             :         EnchantBroker *pbroker;
     320             : 
     321         145 :         pbroker = enchant_broker_init();
     322         145 :         php_info_print_table_start();
     323         145 :         php_info_print_table_header(2, "enchant support", "enabled");
     324         145 :         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         145 :         php_info_print_table_row(2, "Revision", "$Id: c9f7ccf977f2c1a70d742aabba655a8778732d5a $");
     331         145 :         php_info_print_table_end();
     332             : 
     333         145 :         php_info_print_table_start();
     334         145 :         enchant_broker_describe(pbroker, __enumerate_providers_fn, NULL);
     335         145 :         php_info_print_table_end();
     336         145 :         enchant_broker_free(pbroker);
     337         145 : }
     338             : /* }}} */
     339             : 
     340             : #define PHP_ENCHANT_GET_BROKER  \
     341             :         pbroker = (enchant_broker *)zend_fetch_resource(Z_RES_P(broker), "enchant_broker", le_enchant_broker); \
     342             :         if (!pbroker || !pbroker->pbroker) { \
     343             :                 php_error_docref(NULL, E_WARNING, "%s", "Resource broker invalid"); \
     344             :                 RETURN_FALSE;   \
     345             :         }
     346             : 
     347             : #define PHP_ENCHANT_GET_DICT    \
     348             :         pdict = (enchant_dict *)zend_fetch_resource(Z_RES_P(dict), "enchant_dict", le_enchant_dict); \
     349             :         if (!pdict || !pdict->pdict) {       \
     350             :                 php_error_docref(NULL, 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(broker, le_enchant_broker);
     373           8 :                 RETURN_RES(broker->rsrc);
     374             :         } else {
     375           0 :                 RETURN_FALSE;
     376             :         }
     377             : }
     378             : /* }}} */
     379             : 
     380             : /* {{{ proto boolean enchant_broker_free(resource broker)
     381             :    Destroys the broker object and its dictionnaries */
     382           1 : PHP_FUNCTION(enchant_broker_free)
     383             : {
     384             :         zval *broker;
     385             :         enchant_broker *pbroker;
     386             : 
     387           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &broker) == FAILURE) {
     388           0 :                 RETURN_FALSE;
     389             :         }
     390           1 :         PHP_ENCHANT_GET_BROKER;
     391             : 
     392           1 :         zend_list_close(Z_RES_P(broker));
     393           1 :         RETURN_TRUE;
     394             : }
     395             : /* }}} */
     396             : 
     397             : /* {{{ proto string enchant_broker_get_error(resource broker)
     398             :    Returns the last error of the broker */
     399           0 : PHP_FUNCTION(enchant_broker_get_error)
     400             : {
     401             :         zval *broker;
     402             :         enchant_broker *pbroker;
     403             :         char *msg;
     404             : 
     405           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &broker) == FAILURE) {
     406           0 :                 RETURN_FALSE;
     407             :         }
     408             : 
     409           0 :         PHP_ENCHANT_GET_BROKER;
     410             : 
     411           0 :         msg = enchant_broker_get_error(pbroker->pbroker);
     412           0 :         if (msg) {
     413           0 :                 RETURN_STRING((char *)msg);
     414             :         }
     415           0 :         RETURN_FALSE;
     416             : }
     417             : /* }}} */
     418             : 
     419             : #if HAVE_ENCHANT_BROKER_SET_PARAM
     420             : /* {{{ proto bool enchant_broker_set_dict_path(resource broker, int dict_type, string value)
     421             :         Set the directory path for a given backend, works with ispell and myspell */
     422             : PHP_FUNCTION(enchant_broker_set_dict_path)
     423             : {
     424             :         zval *broker;
     425             :         enchant_broker *pbroker;
     426             :         zend_long dict_type;
     427             :         char *value;
     428             :         size_t value_len;
     429             : 
     430             :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rls", &broker, &dict_type, &value, &value_len) == FAILURE) {
     431             :                 RETURN_FALSE;
     432             :         }
     433             : 
     434             :         if (!value_len) {
     435             :                 RETURN_FALSE;
     436             :         }
     437             : 
     438             :         PHP_ENCHANT_GET_BROKER;
     439             : 
     440             :         switch (dict_type) {
     441             :                 case PHP_ENCHANT_MYSPELL:
     442             :                         PHP_ENCHANT_GET_BROKER;
     443             :                         enchant_broker_set_param(pbroker->pbroker, "enchant.myspell.dictionary.path", (const char *)value);
     444             :                         RETURN_TRUE;
     445             :                         break;
     446             : 
     447             :                 case PHP_ENCHANT_ISPELL:
     448             :                         PHP_ENCHANT_GET_BROKER;
     449             :                         enchant_broker_set_param(pbroker->pbroker, "enchant.ispell.dictionary.path", (const char *)value);
     450             :                         RETURN_TRUE;
     451             :                         break;
     452             : 
     453             :                 default:
     454             :                         RETURN_FALSE;
     455             :         }
     456             : }
     457             : /* }}} */
     458             : 
     459             : 
     460             : /* {{{ proto string enchant_broker_get_dict_path(resource broker, int dict_type)
     461             :         Get the directory path for a given backend, works with ispell and myspell */
     462             : PHP_FUNCTION(enchant_broker_get_dict_path)
     463             : {
     464             :         zval *broker;
     465             :         enchant_broker *pbroker;
     466             :         zend_long dict_type;
     467             :         char *value;
     468             : 
     469             :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &broker, &dict_type) == FAILURE) {
     470             :                 RETURN_FALSE;
     471             :         }
     472             : 
     473             :         PHP_ENCHANT_GET_BROKER;
     474             : 
     475             :         switch (dict_type) {
     476             :                 case PHP_ENCHANT_MYSPELL:
     477             :                         PHP_ENCHANT_GET_BROKER;
     478             :                         value = enchant_broker_get_param(pbroker->pbroker, "enchant.myspell.dictionary.path");
     479             :                         break;
     480             : 
     481             :                 case PHP_ENCHANT_ISPELL:
     482             :                         PHP_ENCHANT_GET_BROKER;
     483             :                         value = enchant_broker_get_param(pbroker->pbroker, "enchant.ispell.dictionary.path");
     484             :                         break;
     485             : 
     486             :                 default:
     487             :                         RETURN_FALSE;
     488             :         }
     489             : 
     490             :         RETURN_STRING(value);
     491             : }
     492             : /* }}} */
     493             : #else
     494             : /* {{{ proto bool enchant_broker_set_dict_path(resource broker, int dict_type, string value)
     495             :         Set the directory path for a given backend, works with ispell and myspell */
     496           0 : PHP_FUNCTION(enchant_broker_set_dict_path)
     497             : {
     498           0 :         RETURN_FALSE;
     499             : }
     500             : /* }}} */
     501             : 
     502             : 
     503             : /* {{{ proto string enchant_broker_get_dict_path(resource broker, int dict_type)
     504             :         Get the directory path for a given backend, works with ispell and myspell */
     505           0 : PHP_FUNCTION(enchant_broker_get_dict_path)
     506             : {
     507           0 :         RETURN_FALSE;
     508             : }
     509             : /* }}} */
     510             : #endif
     511             : 
     512             : /* {{{ proto string enchant_broker_list_dicts(resource broker)
     513             :    Lists the dictionaries available for the given broker */
     514           1 : PHP_FUNCTION(enchant_broker_list_dicts)
     515             : {
     516             :         zval *broker;
     517             :         enchant_broker *pbroker;
     518             : 
     519           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &broker) == FAILURE) {
     520           0 :                 RETURN_FALSE;
     521             :         }
     522             : 
     523           1 :         PHP_ENCHANT_GET_BROKER;
     524             : 
     525           1 :         enchant_broker_list_dicts(pbroker->pbroker, php_enchant_list_dicts_fn, (void *)return_value);
     526             : }
     527             : /* }}} */
     528             : 
     529             : /* {{{ proto resource enchant_broker_request_dict(resource broker, string tag)
     530             :         create a new dictionary using tag, the non-empty language tag you wish to request
     531             :         a dictionary for ("en_US", "de_DE", ...) */
     532           4 : PHP_FUNCTION(enchant_broker_request_dict)
     533             : {
     534             :         zval *broker;
     535             :         enchant_broker *pbroker;
     536             :         enchant_dict *dict;
     537             :         EnchantDict *d;
     538             :         char *tag;
     539             :         size_t taglen;
     540             :         int pos;
     541             : 
     542           4 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &broker, &tag, &taglen) == FAILURE) {
     543           0 :                 RETURN_FALSE;
     544             :         }
     545             : 
     546           4 :         PHP_ENCHANT_GET_BROKER;
     547             : 
     548           4 :         if (taglen == 0) {
     549           0 :                 php_error_docref(NULL, E_WARNING, "Tag cannot be empty");
     550           0 :                 RETURN_FALSE;
     551             :         }
     552             : 
     553           4 :         d = enchant_broker_request_dict(pbroker->pbroker, (const char *)tag);
     554           4 :         if (d) {
     555           4 :                 if (pbroker->dictcnt) {
     556           0 :                         pbroker->dict = (enchant_dict **)erealloc(pbroker->dict, sizeof(enchant_dict *) * pbroker->dictcnt);
     557           0 :                         pos = pbroker->dictcnt++;
     558             :                 } else {
     559           4 :                         pbroker->dict = (enchant_dict **)emalloc(sizeof(enchant_dict *));
     560           4 :                         pos = 0;
     561           4 :                         pbroker->dictcnt++;
     562             :                 }
     563             : 
     564           4 :                 dict = pbroker->dict[pos] = (enchant_dict *)emalloc(sizeof(enchant_dict));
     565           4 :                 dict->id = pos;
     566           4 :                 dict->pbroker = pbroker;
     567           4 :                 dict->pdict = d;
     568           4 :                 pbroker->dict[pos] = dict;
     569             : 
     570           4 :                 dict->rsrc = zend_register_resource(dict, le_enchant_dict);
     571           4 :                 pbroker->rsrc->gc.refcount++;
     572           4 :                 RETURN_RES(dict->rsrc);
     573             :         } else {
     574           0 :                 RETURN_FALSE;
     575             :         }
     576             : }
     577             : /* }}} */
     578             : 
     579             : /* {{{ proto resource enchant_broker_request_pwl_dict(resource broker, string filename)
     580             :    creates a dictionary using a PWL file. A PWL file is personal word file one word per line. It must exist before the call.*/
     581           0 : PHP_FUNCTION(enchant_broker_request_pwl_dict)
     582             : {
     583             :         zval *broker;
     584             :         enchant_broker *pbroker;
     585             :         enchant_dict *dict;
     586             :         EnchantDict *d;
     587             :         char *pwl;
     588             :         size_t pwllen;
     589             :         int pos;
     590             : 
     591           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rp", &broker, &pwl, &pwllen) == FAILURE) {
     592           0 :                 RETURN_FALSE;
     593             :         }
     594             : 
     595             : #if PHP_API_VERSION < 20100412
     596             :         if ((PG(safe_mode) && (!php_checkuid(pwl, NULL, CHECKUID_CHECK_FILE_AND_DIR))) || php_check_open_basedir(pwl)) {
     597             : #else
     598           0 :         if (php_check_open_basedir(pwl)) {
     599             : #endif
     600           0 :                 RETURN_FALSE;
     601             :         }
     602             : 
     603           0 :         PHP_ENCHANT_GET_BROKER;
     604             : 
     605           0 :         d = enchant_broker_request_pwl_dict(pbroker->pbroker, (const char *)pwl);
     606           0 :         if (d) {
     607           0 :                 if (pbroker->dictcnt) {
     608           0 :                         pos = pbroker->dictcnt++;
     609           0 :                         pbroker->dict = (enchant_dict **)erealloc(pbroker->dict, sizeof(enchant_dict *) * pbroker->dictcnt);
     610             :                 } else {
     611           0 :                         pbroker->dict = (enchant_dict **)emalloc(sizeof(enchant_dict *));
     612           0 :                         pos = 0;
     613           0 :                         pbroker->dictcnt++;
     614             :                 }
     615           0 :                 dict = pbroker->dict[pos] = (enchant_dict *)emalloc(sizeof(enchant_dict));
     616           0 :                 dict->id = pos;
     617           0 :                 dict->pbroker = pbroker;
     618           0 :                 dict->pdict = d;
     619           0 :                 pbroker->dict[pos] = dict;
     620             : 
     621           0 :                 dict->rsrc = zend_register_resource(dict, le_enchant_dict);
     622           0 :                 pbroker->rsrc->gc.refcount++;
     623           0 :                 RETURN_RES(dict->rsrc);
     624             :         } else {
     625           0 :                 RETURN_FALSE;
     626             :         }
     627             : }
     628             : /* }}} */
     629             : 
     630             : /* {{{ proto resource enchant_broker_free_dict(resource dict)
     631             :    Free the dictionary resource */
     632           0 : PHP_FUNCTION(enchant_broker_free_dict)
     633             : {
     634             :         zval *dict;
     635             :         enchant_dict *pdict;
     636             : 
     637           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &dict) == FAILURE) {
     638           0 :                 RETURN_FALSE;
     639             :         }
     640             : 
     641           0 :         PHP_ENCHANT_GET_DICT;
     642             : 
     643           0 :         zend_list_close(Z_RES_P(dict));
     644           0 :         RETURN_TRUE;
     645             : }
     646             : /* }}} */
     647             : 
     648             : /* {{{ proto bool enchant_broker_dict_exists(resource broker, string tag)
     649             :    Whether a dictionary exists or not. Using non-empty tag */
     650           1 : PHP_FUNCTION(enchant_broker_dict_exists)
     651             : {
     652             :         zval *broker;
     653             :         char *tag;
     654             :         size_t taglen;
     655             :         enchant_broker * pbroker;
     656             : 
     657           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &broker, &tag, &taglen) == FAILURE) {
     658           0 :                 RETURN_FALSE;
     659             :         }
     660             : 
     661           1 :         PHP_ENCHANT_GET_BROKER;
     662             : 
     663           1 :         RETURN_BOOL(enchant_broker_dict_exists(pbroker->pbroker, tag));
     664             : }
     665             : /* }}} */
     666             : 
     667             : /* {{{ proto bool enchant_broker_set_ordering(resource broker, string tag, string ordering)
     668             :         Declares a preference of dictionaries to use for the language
     669             :         described/referred to by 'tag'. The ordering is a comma delimited
     670             :         list of provider names. As a special exception, the "*" tag can
     671             :         be used as a language tag to declare a default ordering for any
     672             :         language that does not explicitly declare an ordering. */
     673             : 
     674           0 : PHP_FUNCTION(enchant_broker_set_ordering)
     675             : {
     676             :         zval *broker;
     677             :         char *pordering;
     678             :         size_t porderinglen;
     679             :         char *ptag;
     680             :         size_t ptaglen;
     681             :         enchant_broker * pbroker;
     682             : 
     683           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rss", &broker, &ptag, &ptaglen, &pordering, &porderinglen) == FAILURE) {
     684           0 :                 RETURN_FALSE;
     685             :         }
     686             : 
     687           0 :         PHP_ENCHANT_GET_BROKER;
     688             : 
     689           0 :         enchant_broker_set_ordering(pbroker->pbroker, ptag, pordering);
     690           0 :         RETURN_TRUE;
     691             : }
     692             : /* }}} */
     693             : 
     694             : /* {{{ proto array enchant_broker_describe(resource broker)
     695             :         Enumerates the Enchant providers and tells you some rudimentary information about them. The same info is provided through phpinfo() */
     696           1 : PHP_FUNCTION(enchant_broker_describe)
     697             : {
     698           1 :         EnchantBrokerDescribeFn describetozval = enumerate_providers_fn;
     699             :         zval *broker;
     700             :         enchant_broker * pbroker;
     701             : 
     702           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &broker) == FAILURE) {
     703           0 :                 RETURN_FALSE;
     704             :         }
     705             : 
     706           1 :         PHP_ENCHANT_GET_BROKER;
     707             : 
     708           1 :         enchant_broker_describe(pbroker->pbroker, describetozval, (void *)return_value);
     709             : }
     710             : /* }}} */
     711             : 
     712             : /* {{{ proto bool enchant_dict_quick_check(resource dict, string word [, array &suggestions])
     713             :     If the word is correctly spelled return true, otherwise return false, if suggestions variable
     714             :     is provided, fill it with spelling alternatives. */
     715           1 : PHP_FUNCTION(enchant_dict_quick_check)
     716             : {
     717           1 :         zval *dict, *sugg = NULL;
     718             :         char *word;
     719             :         size_t wordlen;
     720             :         enchant_dict *pdict;
     721             : 
     722           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|z/", &dict, &word, &wordlen, &sugg) == FAILURE) {
     723           0 :                 RETURN_FALSE;
     724             :         }
     725             : 
     726           1 :         if (sugg) {
     727           1 :                 zval_dtor(sugg);
     728           1 :                 array_init(sugg);
     729             :         }
     730             : 
     731           1 :         PHP_ENCHANT_GET_DICT;
     732             : 
     733           1 :         if (enchant_dict_check(pdict->pdict, word, wordlen) > 0) {
     734             :                 int n_sugg;
     735             :                 size_t n_sugg_st;
     736             :                 char **suggs;
     737             : 
     738           1 :                 if (!sugg && ZEND_NUM_ARGS() == 2) {
     739           0 :                         RETURN_FALSE;
     740             :                 }
     741             : 
     742           1 :                 suggs = enchant_dict_suggest(pdict->pdict, word, wordlen, &n_sugg_st);
     743           1 :                 memcpy(&n_sugg, &n_sugg_st, sizeof(n_sugg));
     744           1 :                 if (suggs && n_sugg) {
     745             :                         int i;
     746           7 :                         for (i = 0; i < n_sugg; i++) {
     747           6 :                                 add_next_index_string(sugg, suggs[i]);
     748             :                         }
     749           1 :                         enchant_dict_free_suggestions(pdict->pdict, suggs);
     750             :                 }
     751             : 
     752             : 
     753           1 :                 RETURN_FALSE;
     754             :         }
     755           0 :         RETURN_TRUE;
     756             : }
     757             : /* }}} */
     758             : 
     759             : /* {{{ proto bool enchant_dict_check(resource dict, string word)
     760             :     If the word is correctly spelled return true, otherwise return false */
     761           0 : PHP_FUNCTION(enchant_dict_check)
     762             : {
     763             :         zval *dict;
     764             :         char *word;
     765             :         size_t wordlen;
     766             :         enchant_dict *pdict;
     767             : 
     768           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &dict, &word, &wordlen) == FAILURE) {
     769           0 :                 RETURN_FALSE;
     770             :         }
     771             : 
     772           0 :         PHP_ENCHANT_GET_DICT;
     773             : 
     774           0 :         RETURN_BOOL(!enchant_dict_check(pdict->pdict, word, wordlen));
     775             : }
     776             : /* }}} */
     777             : 
     778             : /* {{{ proto array enchant_dict_suggest(resource dict, string word)
     779             :     Will return a list of values if any of those pre-conditions are not met.*/
     780           1 : PHP_FUNCTION(enchant_dict_suggest)
     781             : {
     782             :         zval *dict;
     783             :         char *word;
     784             :         size_t wordlen;
     785             :         char **suggs;
     786             :         enchant_dict *pdict;
     787             :         int n_sugg;
     788             :         size_t n_sugg_st;
     789             : 
     790           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &dict, &word, &wordlen) == FAILURE) {
     791           0 :                 RETURN_FALSE;
     792             :         }
     793             : 
     794           1 :         PHP_ENCHANT_GET_DICT;
     795             : 
     796           1 :         suggs = enchant_dict_suggest(pdict->pdict, word, wordlen, &n_sugg_st);
     797           1 :         memcpy(&n_sugg, &n_sugg_st, sizeof(n_sugg));
     798           1 :         if (suggs && n_sugg) {
     799             :                 int i;
     800             : 
     801           1 :                 array_init(return_value);
     802           6 :                 for (i = 0; i < n_sugg; i++) {
     803           5 :                         add_next_index_string(return_value, suggs[i]);
     804             :                 }
     805             : 
     806           1 :                 enchant_dict_free_suggestions(pdict->pdict, suggs);
     807             :         }
     808             : }
     809             : /* }}} */
     810             : 
     811             : /* {{{ proto void enchant_dict_add_to_personal(resource dict, string word)
     812             :      add 'word' to personal word list */
     813           0 : PHP_FUNCTION(enchant_dict_add_to_personal)
     814             : {
     815             :         zval *dict;
     816             :         char *word;
     817             :         size_t wordlen;
     818             :         enchant_dict *pdict;
     819             : 
     820           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &dict, &word, &wordlen) == FAILURE) {
     821           0 :                 RETURN_FALSE;
     822             :         }
     823             : 
     824           0 :         PHP_ENCHANT_GET_DICT;
     825             : 
     826           0 :         enchant_dict_add_to_personal(pdict->pdict, word, wordlen);
     827             : }
     828             : /* }}} */
     829             : 
     830             : /* {{{ proto void enchant_dict_add_to_session(resource dict, string word)
     831             :    add 'word' to this spell-checking session */
     832           0 : PHP_FUNCTION(enchant_dict_add_to_session)
     833             : {
     834             :         zval *dict;
     835             :         char *word;
     836             :         size_t wordlen;
     837             :         enchant_dict *pdict;
     838             : 
     839           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &dict, &word, &wordlen) == FAILURE) {
     840           0 :                 RETURN_FALSE;
     841             :         }
     842             : 
     843           0 :         PHP_ENCHANT_GET_DICT;
     844             : 
     845           0 :         enchant_dict_add_to_session(pdict->pdict, word, wordlen);
     846             : }
     847             : /* }}} */
     848             : 
     849             : /* {{{ proto bool enchant_dict_is_in_session(resource dict, string word)
     850             :    whether or not 'word' exists in this spelling-session */
     851           0 : PHP_FUNCTION(enchant_dict_is_in_session)
     852             : {
     853             :         zval *dict;
     854             :         char *word;
     855             :         size_t wordlen;
     856             :         enchant_dict *pdict;
     857             : 
     858           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &dict, &word, &wordlen) == FAILURE) {
     859           0 :                 RETURN_FALSE;
     860             :         }
     861             : 
     862           0 :         PHP_ENCHANT_GET_DICT;
     863             : 
     864           0 :         RETURN_BOOL(enchant_dict_is_in_session(pdict->pdict, word, wordlen));
     865             : }
     866             : /* }}} */
     867             : 
     868             : /* {{{ proto void enchant_dict_store_replacement(resource dict, string mis, string cor)
     869             :         add a correction for 'mis' using 'cor'.
     870             :         Notes that you replaced @mis with @cor, so it's possibly more likely
     871             :         that future occurrences of @mis will be replaced with @cor. So it might
     872             :         bump @cor up in the suggestion list.*/
     873           0 : PHP_FUNCTION(enchant_dict_store_replacement)
     874             : {
     875             :         zval *dict;
     876             :         char *mis, *cor;
     877             :         size_t mislen, corlen;
     878             : 
     879             :         enchant_dict *pdict;
     880             : 
     881           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "rss", &dict, &mis, &mislen, &cor, &corlen) == FAILURE) {
     882           0 :                 RETURN_FALSE;
     883             :         }
     884             : 
     885           0 :         PHP_ENCHANT_GET_DICT;
     886             : 
     887           0 :         enchant_dict_store_replacement(pdict->pdict, mis, mislen, cor, corlen);
     888             : }
     889             : /* }}} */
     890             : 
     891             : /* {{{ proto string enchant_dict_get_error(resource dict)
     892             :    Returns the last error of the current spelling-session */
     893           0 : PHP_FUNCTION(enchant_dict_get_error)
     894             : {
     895             :         zval *dict;
     896             :         enchant_dict *pdict;
     897             :         char *msg;
     898             : 
     899           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &dict) == FAILURE) {
     900           0 :                 RETURN_FALSE;
     901             :         }
     902             : 
     903           0 :         PHP_ENCHANT_GET_DICT;
     904             : 
     905           0 :         msg = enchant_dict_get_error(pdict->pdict);
     906           0 :         if (msg) {
     907           0 :                 RETURN_STRING((char *)msg);
     908             :         }
     909             : 
     910           0 :         RETURN_FALSE;
     911             : }
     912             : /* }}} */
     913             : 
     914             : /* {{{ proto array enchant_dict_describe(resource dict)
     915             :    Describes an individual dictionary 'dict' */
     916           0 : PHP_FUNCTION(enchant_dict_describe)
     917             : {
     918             :         zval *dict;
     919             :         enchant_dict *pdict;
     920             : 
     921           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &dict) == FAILURE) {
     922           0 :                 RETURN_FALSE;
     923             :         }
     924             : 
     925           0 :         PHP_ENCHANT_GET_DICT;
     926             : 
     927           0 :         enchant_dict_describe(pdict->pdict, describe_dict_fn, (void *)return_value);
     928             : }
     929             : /* }}} */
     930             : 
     931             : /*
     932             :  * Local variables:
     933             :  * tab-width: 4
     934             :  * c-basic-offset: 4
     935             :  * End:
     936             :  * vim600: noet sw=4 ts=4 fdm=marker
     937             :  * vim<600: noet sw=4 ts=4
     938             :  */

Generated by: LCOV version 1.10

Generated at Thu, 30 Apr 2015 23:10:02 +0000 (6 days ago)

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