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: 145 258 56.2 %
Date: 2014-08-04 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-2014 The PHP Group                                |
       6             :   +----------------------------------------------------------------------+
       7             :   | This source file is subject to version 3.0 of the PHP license,       |
       8             :   | that is bundled with this package in the file LICENSE, and is        |
       9             :   | available at through the world-wide-web at                           |
      10             :   | http://www.php.net/license/3_0.txt.                                  |
      11             :   | If you did not receive a copy of the PHP license and are unable to   |
      12             :   | obtain it through the world-wide-web, please send a note to          |
      13             :   | license@php.net so we can mail you a copy immediately.               |
      14             :   +----------------------------------------------------------------------+
      15             :   | Author: Pierre-Alain Joye <paj@pearfr.org>                           |
      16             :   |         Ilia Alshanetsky <ilia@prohost.org>                          |
      17             :   +----------------------------------------------------------------------+
      18             : 
      19             :   $Id: 6de2feac8047059326b85565067ecdba8fb4f363 $
      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             : zend_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;
     248           4 :                                                 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       21265 : PHP_MINIT_FUNCTION(enchant)
     288             : {
     289       21265 :         le_enchant_broker = zend_register_list_destructors_ex(php_enchant_broker_free, NULL, "enchant_broker", module_number);
     290       21265 :         le_enchant_dict = zend_register_list_destructors_ex(php_enchant_dict_free, NULL, "enchant_dict", module_number);
     291       21265 :         REGISTER_LONG_CONSTANT("ENCHANT_MYSPELL", PHP_ENCHANT_MYSPELL, CONST_CS | CONST_PERSISTENT);
     292       21265 :         REGISTER_LONG_CONSTANT("ENCHANT_ISPELL", PHP_ENCHANT_ISPELL, CONST_CS | CONST_PERSISTENT);
     293       21265 :         return SUCCESS;
     294             : }
     295             : /* }}} */
     296             : 
     297             : /* {{{ PHP_MSHUTDOWN_FUNCTION
     298             :  */
     299       21298 : PHP_MSHUTDOWN_FUNCTION(enchant)
     300             : {
     301       21298 :         return SUCCESS;
     302             : }
     303             : /* }}} */
     304             : 
     305         150 : static void __enumerate_providers_fn (const char * const name,
     306             :                         const char * const desc,
     307             :                         const char * const file,
     308             :                         void * ud) /* {{{ */
     309             : {
     310         150 :         php_info_print_table_row(3, name, desc, file);
     311         150 : }
     312             : /* }}} */
     313             : 
     314             : /* {{{ PHP_MINFO_FUNCTION
     315             :  */
     316         150 : PHP_MINFO_FUNCTION(enchant)
     317             : {
     318             :         EnchantBroker *pbroker;
     319             : 
     320         150 :         pbroker = enchant_broker_init();
     321         150 :         php_info_print_table_start();
     322         150 :         php_info_print_table_header(2, "enchant support", "enabled");
     323         150 :         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         150 :         php_info_print_table_row(2, "Revision", "$Id: 6de2feac8047059326b85565067ecdba8fb4f363 $");
     330         150 :         php_info_print_table_end();
     331             : 
     332         150 :         php_info_print_table_start();
     333         150 :         enchant_broker_describe(pbroker, __enumerate_providers_fn, NULL);
     334         150 :         php_info_print_table_end();
     335         150 :         enchant_broker_free(pbroker);
     336         150 : }
     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_parse_parameters_none() == FAILURE) {
     361           0 :                 return;
     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 :         if (taglen == 0) {
     547           0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Tag cannot be empty");
     548           0 :                 RETURN_FALSE;
     549             :         }
     550             : 
     551           4 :         d = enchant_broker_request_dict(pbroker->pbroker, (const char *)tag);
     552           4 :         if (d) {
     553           4 :                 if (pbroker->dictcnt) {
     554           0 :                         pbroker->dict = (enchant_dict **)erealloc(pbroker->dict, sizeof(enchant_dict *) * pbroker->dictcnt);
     555           0 :                         pos = pbroker->dictcnt++;
     556             :                 } else {
     557           4 :                         pbroker->dict = (enchant_dict **)emalloc(sizeof(enchant_dict *));
     558           4 :                         pos = 0;
     559           4 :                         pbroker->dictcnt++;
     560             :                 }
     561             : 
     562           4 :                 dict = pbroker->dict[pos] = (enchant_dict *)emalloc(sizeof(enchant_dict));
     563           4 :                 dict->id = pos;
     564           4 :                 dict->pbroker = pbroker;
     565           4 :                 dict->pdict = d;
     566           4 :                 dict->prev = pos ? pbroker->dict[pos-1] : NULL;
     567           4 :                 dict->next = NULL;
     568           4 :                 pbroker->dict[pos] = dict;
     569             : 
     570           4 :                 if (pos) {
     571           0 :                         pbroker->dict[pos-1]->next = dict;
     572             :                 }
     573             : 
     574           4 :                 dict->rsrc_id = ZEND_REGISTER_RESOURCE(return_value, dict, le_enchant_dict);
     575           4 :                 zend_list_addref(pbroker->rsrc_id);
     576             :         } else {
     577           0 :                 RETURN_FALSE;
     578             :         }
     579             : }
     580             : /* }}} */
     581             : 
     582             : /* {{{ proto resource enchant_broker_request_pwl_dict(resource broker, string filename)
     583             :    creates a dictionary using a PWL file. A PWL file is personal word file one word per line. It must exist before the call.*/
     584           0 : PHP_FUNCTION(enchant_broker_request_pwl_dict)
     585             : {
     586             :         zval *broker;
     587             :         enchant_broker *pbroker;
     588             :         enchant_dict *dict;
     589             :         EnchantDict *d;
     590             :         char *pwl;
     591             :         int pwllen;
     592             :         int pos;
     593             : 
     594           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rp", &broker, &pwl, &pwllen) == FAILURE) {
     595           0 :                 RETURN_FALSE;
     596             :         }
     597             : 
     598             : #if PHP_API_VERSION < 20100412
     599             :         if ((PG(safe_mode) && (!php_checkuid(pwl, NULL, CHECKUID_CHECK_FILE_AND_DIR))) || php_check_open_basedir(pwl TSRMLS_CC)) {
     600             : #else
     601           0 :         if (php_check_open_basedir(pwl TSRMLS_CC)) {
     602             : #endif
     603           0 :                 RETURN_FALSE;
     604             :         }
     605             : 
     606           0 :         PHP_ENCHANT_GET_BROKER;
     607             : 
     608           0 :         d = enchant_broker_request_pwl_dict(pbroker->pbroker, (const char *)pwl);
     609           0 :         if (d) {
     610           0 :                 if (pbroker->dictcnt) {
     611           0 :                         pos = pbroker->dictcnt++;
     612           0 :                         pbroker->dict = (enchant_dict **)erealloc(pbroker->dict, sizeof(enchant_dict *) * pbroker->dictcnt);
     613             :                 } else {
     614           0 :                         pbroker->dict = (enchant_dict **)emalloc(sizeof(enchant_dict *));
     615           0 :                         pos = 0;
     616           0 :                         pbroker->dictcnt++;
     617             :                 }
     618           0 :                 dict = pbroker->dict[pos] = (enchant_dict *)emalloc(sizeof(enchant_dict));
     619           0 :                 dict->id = pos;
     620           0 :                 dict->pbroker = pbroker;
     621           0 :                 dict->pdict = d;
     622           0 :                 dict->prev = pos?pbroker->dict[pos-1]:NULL;
     623           0 :                 dict->next = NULL;
     624           0 :                 pbroker->dict[pos] = dict;
     625           0 :                 if (pos) {
     626           0 :                         pbroker->dict[pos-1]->next = dict;
     627             :                 }
     628           0 :                 dict->rsrc_id = ZEND_REGISTER_RESOURCE(return_value, dict, le_enchant_dict);
     629             :         } else {
     630           0 :                 RETURN_FALSE;
     631             :         }
     632             : }
     633             : /* }}} */
     634             : 
     635             : /* {{{ proto resource enchant_broker_free_dict(resource dict)
     636             :    Free the dictionary resource */
     637           0 : PHP_FUNCTION(enchant_broker_free_dict)
     638             : {
     639             :         zval *dict;
     640             :         enchant_dict *pdict;
     641             : 
     642           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &dict) == FAILURE) {
     643           0 :                 RETURN_FALSE;
     644             :         }
     645             : 
     646           0 :         PHP_ENCHANT_GET_DICT;
     647             : 
     648           0 :         zend_list_delete(Z_RESVAL_P(dict));
     649           0 :         RETURN_TRUE;
     650             : }
     651             : /* }}} */
     652             : 
     653             : /* {{{ proto bool enchant_broker_dict_exists(resource broker, string tag)
     654             :    Whether a dictionary exists or not. Using non-empty tag */
     655           1 : PHP_FUNCTION(enchant_broker_dict_exists)
     656             : {
     657             :         zval *broker;
     658             :         char *tag;
     659             :         int taglen;
     660             :         enchant_broker * pbroker;
     661             : 
     662           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &broker, &tag, &taglen) == FAILURE) {
     663           0 :                 RETURN_FALSE;
     664             :         }
     665             : 
     666           1 :         PHP_ENCHANT_GET_BROKER;
     667             : 
     668           1 :         RETURN_BOOL(enchant_broker_dict_exists(pbroker->pbroker, tag));
     669             : }
     670             : /* }}} */
     671             : 
     672             : /* {{{ proto bool enchant_broker_set_ordering(resource broker, string tag, string ordering)
     673             :         Declares a preference of dictionaries to use for the language
     674             :         described/referred to by 'tag'. The ordering is a comma delimited
     675             :         list of provider names. As a special exception, the "*" tag can
     676             :         be used as a language tag to declare a default ordering for any
     677             :         language that does not explicitly declare an ordering. */
     678             : 
     679           0 : PHP_FUNCTION(enchant_broker_set_ordering)
     680             : {
     681             :         zval *broker;
     682             :         char *pordering;
     683             :         int porderinglen;
     684             :         char *ptag;
     685             :         int ptaglen;
     686             :         enchant_broker * pbroker;
     687             : 
     688           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &broker, &ptag, &ptaglen, &pordering, &porderinglen) == FAILURE) {
     689           0 :                 RETURN_FALSE;
     690             :         }
     691             : 
     692           0 :         PHP_ENCHANT_GET_BROKER;
     693             : 
     694           0 :         enchant_broker_set_ordering(pbroker->pbroker, ptag, pordering);
     695           0 :         RETURN_TRUE;
     696             : }
     697             : /* }}} */
     698             : 
     699             : /* {{{ proto array enchant_broker_describe(resource broker)
     700             :         Enumerates the Enchant providers and tells you some rudimentary information about them. The same info is provided through phpinfo() */
     701           1 : PHP_FUNCTION(enchant_broker_describe)
     702             : {
     703           1 :         EnchantBrokerDescribeFn describetozval = enumerate_providers_fn;
     704             :         zval *broker;
     705             :         enchant_broker * pbroker;
     706             : 
     707           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &broker) == FAILURE) {
     708           0 :                 RETURN_FALSE;
     709             :         }
     710             : 
     711           1 :         PHP_ENCHANT_GET_BROKER;
     712             : 
     713           1 :         enchant_broker_describe(pbroker->pbroker, describetozval, (void *)return_value);
     714             : }
     715             : /* }}} */
     716             : 
     717             : /* {{{ proto bool enchant_dict_quick_check(resource dict, string word [, array &suggestions])
     718             :     If the word is correctly spelled return true, otherwise return false, if suggestions variable
     719             :     is provided, fill it with spelling alternatives. */
     720           1 : PHP_FUNCTION(enchant_dict_quick_check)
     721             : {
     722           1 :         zval *dict, *sugg = NULL;
     723             :         char *word;
     724             :         int wordlen;
     725             :         enchant_dict *pdict;
     726             : 
     727           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|z/", &dict, &word, &wordlen, &sugg) == FAILURE) {
     728           0 :                 RETURN_FALSE;
     729             :         }
     730             : 
     731           1 :         if (sugg) {
     732           1 :                 zval_dtor(sugg);
     733           1 :                 array_init(sugg);
     734             :         }
     735             : 
     736           1 :         PHP_ENCHANT_GET_DICT;
     737             : 
     738           1 :         if (enchant_dict_check(pdict->pdict, word, wordlen) > 0) {
     739             :                 int n_sugg;
     740             :                 size_t n_sugg_st;
     741             :                 char **suggs;
     742             : 
     743           1 :                 if (!sugg && ZEND_NUM_ARGS() == 2) {
     744           0 :                         RETURN_FALSE;
     745             :                 }
     746             : 
     747           1 :                 suggs = enchant_dict_suggest(pdict->pdict, word, wordlen, &n_sugg_st);
     748           1 :                 memcpy(&n_sugg, &n_sugg_st, sizeof(n_sugg));
     749           1 :                 if (suggs && n_sugg) {
     750             :                         int i;
     751           7 :                         for (i = 0; i < n_sugg; i++) {
     752           6 :                                 add_next_index_string(sugg, suggs[i], 1);
     753             :                         }
     754           1 :                         enchant_dict_free_suggestions(pdict->pdict, suggs);
     755             :                 }
     756             : 
     757             : 
     758           1 :                 RETURN_FALSE;
     759             :         }
     760           0 :         RETURN_TRUE;
     761             : }
     762             : /* }}} */
     763             : 
     764             : /* {{{ proto bool enchant_dict_check(resource dict, string word)
     765             :     If the word is correctly spelled return true, otherwise return false */
     766           0 : PHP_FUNCTION(enchant_dict_check)
     767             : {
     768             :         zval *dict;
     769             :         char *word;
     770             :         int wordlen;
     771             :         enchant_dict *pdict;
     772             : 
     773           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &dict, &word, &wordlen) == FAILURE) {
     774           0 :                 RETURN_FALSE;
     775             :         }
     776             : 
     777           0 :         PHP_ENCHANT_GET_DICT;
     778             : 
     779           0 :         RETURN_BOOL(!enchant_dict_check(pdict->pdict, word, wordlen));
     780             : }
     781             : /* }}} */
     782             : 
     783             : /* {{{ proto array enchant_dict_suggest(resource dict, string word)
     784             :     Will return a list of values if any of those pre-conditions are not met.*/
     785           1 : PHP_FUNCTION(enchant_dict_suggest)
     786             : {
     787             :         zval *dict;
     788             :         char *word;
     789             :         int wordlen;
     790             :         char **suggs;
     791             :         enchant_dict *pdict;
     792             :         int n_sugg;
     793             :         size_t n_sugg_st;
     794             : 
     795           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &dict, &word, &wordlen) == FAILURE) {
     796           0 :                 RETURN_FALSE;
     797             :         }
     798             : 
     799           1 :         PHP_ENCHANT_GET_DICT;
     800             : 
     801           1 :         suggs = enchant_dict_suggest(pdict->pdict, word, wordlen, &n_sugg_st);
     802           1 :         memcpy(&n_sugg, &n_sugg_st, sizeof(n_sugg));
     803           1 :         if (suggs && n_sugg) {
     804             :                 int i;
     805             : 
     806           1 :                 array_init(return_value);
     807           6 :                 for (i = 0; i < n_sugg; i++) {
     808           5 :                         add_next_index_string(return_value, suggs[i], 1);
     809             :                 }
     810             : 
     811           1 :                 enchant_dict_free_suggestions(pdict->pdict, suggs);
     812             :         }
     813             : }
     814             : /* }}} */
     815             : 
     816             : /* {{{ proto void enchant_dict_add_to_personal(resource dict, string word)
     817             :      add 'word' to personal word list */
     818           0 : PHP_FUNCTION(enchant_dict_add_to_personal)
     819             : {
     820             :         zval *dict;
     821             :         char *word;
     822             :         int wordlen;
     823             :         enchant_dict *pdict;
     824             : 
     825           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &dict, &word, &wordlen) == FAILURE) {
     826           0 :                 RETURN_FALSE;
     827             :         }
     828             : 
     829           0 :         PHP_ENCHANT_GET_DICT;
     830             : 
     831           0 :         enchant_dict_add_to_personal(pdict->pdict, word, wordlen);
     832             : }
     833             : /* }}} */
     834             : 
     835             : /* {{{ proto void enchant_dict_add_to_session(resource dict, string word)
     836             :    add 'word' to this spell-checking session */
     837           0 : PHP_FUNCTION(enchant_dict_add_to_session)
     838             : {
     839             :         zval *dict;
     840             :         char *word;
     841             :         int wordlen;
     842             :         enchant_dict *pdict;
     843             : 
     844           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &dict, &word, &wordlen) == FAILURE) {
     845           0 :                 RETURN_FALSE;
     846             :         }
     847             : 
     848           0 :         PHP_ENCHANT_GET_DICT;
     849             : 
     850           0 :         enchant_dict_add_to_session(pdict->pdict, word, wordlen);
     851             : }
     852             : /* }}} */
     853             : 
     854             : /* {{{ proto bool enchant_dict_is_in_session(resource dict, string word)
     855             :    whether or not 'word' exists in this spelling-session */
     856           0 : PHP_FUNCTION(enchant_dict_is_in_session)
     857             : {
     858             :         zval *dict;
     859             :         char *word;
     860             :         int wordlen;
     861             :         enchant_dict *pdict;
     862             : 
     863           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &dict, &word, &wordlen) == FAILURE) {
     864           0 :                 RETURN_FALSE;
     865             :         }
     866             : 
     867           0 :         PHP_ENCHANT_GET_DICT;
     868             : 
     869           0 :         RETURN_BOOL(enchant_dict_is_in_session(pdict->pdict, word, wordlen));
     870             : }
     871             : /* }}} */
     872             : 
     873             : /* {{{ proto void enchant_dict_store_replacement(resource dict, string mis, string cor)
     874             :         add a correction for 'mis' using 'cor'.
     875             :         Notes that you replaced @mis with @cor, so it's possibly more likely
     876             :         that future occurrences of @mis will be replaced with @cor. So it might
     877             :         bump @cor up in the suggestion list.*/
     878           0 : PHP_FUNCTION(enchant_dict_store_replacement)
     879             : {
     880             :         zval *dict;
     881             :         char *mis, *cor;
     882             :         int mislen, corlen;
     883             : 
     884             :         enchant_dict *pdict;
     885             : 
     886           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &dict, &mis, &mislen, &cor, &corlen) == FAILURE) {
     887           0 :                 RETURN_FALSE;
     888             :         }
     889             : 
     890           0 :         PHP_ENCHANT_GET_DICT;
     891             : 
     892           0 :         enchant_dict_store_replacement(pdict->pdict, mis, mislen, cor, corlen);
     893             : }
     894             : /* }}} */
     895             : 
     896             : /* {{{ proto string enchant_dict_get_error(resource dict)
     897             :    Returns the last error of the current spelling-session */
     898           0 : PHP_FUNCTION(enchant_dict_get_error)
     899             : {
     900             :         zval *dict;
     901             :         enchant_dict *pdict;
     902             :         char *msg;
     903             : 
     904           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &dict) == FAILURE) {
     905           0 :                 RETURN_FALSE;
     906             :         }
     907             : 
     908           0 :         PHP_ENCHANT_GET_DICT;
     909             : 
     910           0 :         msg = enchant_dict_get_error(pdict->pdict);
     911           0 :         if (msg) {
     912           0 :                 RETURN_STRING((char *)msg, 1);
     913             :         }
     914             : 
     915           0 :         RETURN_FALSE;
     916             : }
     917             : /* }}} */
     918             : 
     919             : /* {{{ proto array enchant_dict_describe(resource dict)
     920             :    Describes an individual dictionary 'dict' */
     921           0 : PHP_FUNCTION(enchant_dict_describe)
     922             : {
     923             :         zval *dict;
     924             :         enchant_dict *pdict;
     925             : 
     926           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &dict) == FAILURE) {
     927           0 :                 RETURN_FALSE;
     928             :         }
     929             : 
     930           0 :         PHP_ENCHANT_GET_DICT;
     931             : 
     932           0 :         enchant_dict_describe(pdict->pdict, describe_dict_fn, (void *)return_value);
     933             : }
     934             : /* }}} */
     935             : 
     936             : /*
     937             :  * Local variables:
     938             :  * tab-width: 4
     939             :  * c-basic-offset: 4
     940             :  * End:
     941             :  * vim600: noet sw=4 ts=4 fdm=marker
     942             :  * vim<600: noet sw=4 ts=4
     943             :  */

Generated by: LCOV version 1.10

Generated at Mon, 04 Aug 2014 15:49:03 +0000 (44 days ago)

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