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: 144 257 56.0 %
Date: 2014-04-18 Functions: 16 30 53.3 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10

Generated at Fri, 18 Apr 2014 07:01:26 +0000 (5 days ago)

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