Annotation of embedaddon/php/ext/enchant/enchant.c, revision 1.1

1.1     ! misho       1: /*
        !             2:   +----------------------------------------------------------------------+
        !             3:   | PHP Version 5                                                        |
        !             4:   +----------------------------------------------------------------------+
        !             5:   | Copyright (c) 1997-2012 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: enchant.c 321634 2012-01-01 13:15:04Z felipe $
        !            20: */
        !            21: 
        !            22: #ifdef HAVE_CONFIG_H
        !            23: #include "config.h"
        !            24: #endif
        !            25: 
        !            26: #include <enchant.h>
        !            27: #include "php.h"
        !            28: #include "php_ini.h"
        !            29: #include "ext/standard/info.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: enumerate_providers_fn (const char * const name,
        !           179:                         const char * const desc,
        !           180:                         const char * const file,
        !           181:                         void * ud) /* {{{ */
        !           182: {
        !           183:        zval *zdesc = (zval *) ud;
        !           184:        zval *tmp_array;
        !           185: 
        !           186:        MAKE_STD_ZVAL(tmp_array);
        !           187:        array_init(tmp_array);
        !           188: 
        !           189:        add_assoc_string(tmp_array, "name", (char *)name, 1);
        !           190:        add_assoc_string(tmp_array, "desc", (char *)desc, 1);
        !           191:        add_assoc_string(tmp_array, "file", (char *)file, 1);
        !           192: 
        !           193:        if (Z_TYPE_P(zdesc)!=IS_ARRAY) {
        !           194:                array_init(zdesc);
        !           195:        }
        !           196: 
        !           197:        add_next_index_zval(zdesc, tmp_array);
        !           198: }
        !           199: /* }}} */
        !           200: 
        !           201: static void
        !           202: 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:        zval *zdesc = (zval *) ud;
        !           209:        array_init(zdesc);
        !           210:        add_assoc_string(zdesc, "lang", (char *)lang, 1);
        !           211:        add_assoc_string(zdesc, "name", (char *)name, 1);
        !           212:        add_assoc_string(zdesc, "desc", (char *)desc, 1);
        !           213:        add_assoc_string(zdesc, "file", (char *)file, 1);
        !           214: }
        !           215: /* }}} */
        !           216: 
        !           217: 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:        zval *zdesc = (zval *) ud;
        !           222:        zval *tmp_array;
        !           223: 
        !           224:        MAKE_STD_ZVAL(tmp_array);
        !           225:        array_init(tmp_array);
        !           226:        add_assoc_string(tmp_array, "lang_tag", (char *)lang_tag, 1);
        !           227:        add_assoc_string(tmp_array, "provider_name", (char *)provider_name, 1);
        !           228:        add_assoc_string(tmp_array, "provider_desc", (char *)provider_desc, 1);
        !           229:        add_assoc_string(tmp_array, "provider_file", (char *)provider_file, 1);
        !           230: 
        !           231:        if (Z_TYPE_P(zdesc) != IS_ARRAY) {
        !           232:                array_init(zdesc);
        !           233:        }
        !           234:        add_next_index_zval(zdesc, tmp_array);
        !           235: 
        !           236: }
        !           237: /* }}} */
        !           238: 
        !           239: static void php_enchant_broker_free(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{ */
        !           240: {
        !           241:        if (rsrc->ptr) {
        !           242:                enchant_broker *broker = (enchant_broker *)rsrc->ptr;
        !           243:                if (broker) {
        !           244:                        if (broker->pbroker) {
        !           245:                                if (broker->dictcnt && broker->dict) {
        !           246:                                        if (broker->dict) {
        !           247:                                                int total, tofree;
        !           248:                                                tofree = total = broker->dictcnt-1;
        !           249:                                                do {
        !           250:                                                        zend_list_delete(broker->dict[total]->rsrc_id);
        !           251:                                                        efree(broker->dict[total]);
        !           252:                                                        total--;
        !           253:                                                } while (total>=0);
        !           254:                                        }
        !           255:                                        efree(broker->dict);
        !           256:                                        broker->dict = NULL;
        !           257:                                }
        !           258:                                enchant_broker_free(broker->pbroker);
        !           259:                        }
        !           260:                        efree(broker);
        !           261:                }
        !           262:        }
        !           263: }
        !           264: /* }}} */
        !           265: 
        !           266: static void php_enchant_dict_free(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{ */
        !           267: 
        !           268: {
        !           269:        if (rsrc->ptr) {
        !           270:                enchant_dict *pdict = (enchant_dict *)rsrc->ptr;
        !           271:                if (pdict) {
        !           272:                        if (pdict->pdict && pdict->pbroker) {
        !           273:                                enchant_broker_free_dict(pdict->pbroker->pbroker, pdict->pdict);
        !           274:                                if (pdict->id) {
        !           275:                                        pdict->pbroker->dict[pdict->id-1]->next = NULL;
        !           276:                                }
        !           277:                                zend_list_delete(pdict->pbroker->rsrc_id);
        !           278:                        }
        !           279: 
        !           280:                }
        !           281:        }
        !           282: }
        !           283: /* }}} */
        !           284: 
        !           285: /* {{{ PHP_MINIT_FUNCTION
        !           286:  */
        !           287: PHP_MINIT_FUNCTION(enchant)
        !           288: {
        !           289:        le_enchant_broker = zend_register_list_destructors_ex(php_enchant_broker_free, NULL, "enchant_broker", module_number);
        !           290:        le_enchant_dict = zend_register_list_destructors_ex(php_enchant_dict_free, NULL, "enchant_dict", module_number);
        !           291:        REGISTER_LONG_CONSTANT("ENCHANT_MYSPELL", PHP_ENCHANT_MYSPELL, CONST_CS | CONST_PERSISTENT);
        !           292:        REGISTER_LONG_CONSTANT("ENCHANT_ISPELL", PHP_ENCHANT_ISPELL, CONST_CS | CONST_PERSISTENT);
        !           293:        return SUCCESS;
        !           294: }
        !           295: /* }}} */
        !           296: 
        !           297: /* {{{ PHP_MSHUTDOWN_FUNCTION
        !           298:  */
        !           299: PHP_MSHUTDOWN_FUNCTION(enchant)
        !           300: {
        !           301:        return SUCCESS;
        !           302: }
        !           303: /* }}} */
        !           304: 
        !           305: static void __enumerate_providers_fn (const char * const name,
        !           306:                         const char * const desc,
        !           307:                         const char * const file,
        !           308:                         void * ud) /* {{{ */
        !           309: {
        !           310:        php_info_print_table_row(3, name, desc, file);
        !           311: }
        !           312: /* }}} */
        !           313: 
        !           314: /* {{{ PHP_MINFO_FUNCTION
        !           315:  */
        !           316: PHP_MINFO_FUNCTION(enchant)
        !           317: {
        !           318:        EnchantBroker *pbroker;
        !           319: 
        !           320:        pbroker = enchant_broker_init();
        !           321:        php_info_print_table_start();
        !           322:        php_info_print_table_header(2, "enchant support", "enabled");
        !           323:        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:        php_info_print_table_row(2, "Revision", "$Revision: 321634 $");
        !           330:        php_info_print_table_end();
        !           331: 
        !           332:        php_info_print_table_start();
        !           333:        enchant_broker_describe(pbroker, __enumerate_providers_fn, NULL);
        !           334:        php_info_print_table_end();
        !           335:        enchant_broker_free(pbroker);
        !           336: }
        !           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: PHP_FUNCTION(enchant_broker_init)
        !           356: {
        !           357:        enchant_broker *broker;
        !           358:        EnchantBroker *pbroker;
        !           359: 
        !           360:        if (ZEND_NUM_ARGS()) {
        !           361:                ZEND_WRONG_PARAM_COUNT();
        !           362:        }
        !           363: 
        !           364:        pbroker = enchant_broker_init();
        !           365: 
        !           366:        if (pbroker) {
        !           367:                broker = (enchant_broker *) emalloc(sizeof(enchant_broker));
        !           368:                broker->pbroker = pbroker;
        !           369:                broker->dict = NULL;
        !           370:                broker->dictcnt = 0;
        !           371:                broker->rsrc_id = ZEND_REGISTER_RESOURCE(return_value, broker, le_enchant_broker);
        !           372:        } else {
        !           373:                RETURN_FALSE;
        !           374:        }
        !           375: }
        !           376: /* }}} */
        !           377: 
        !           378: /* {{{ proto boolean enchant_broker_free(resource broker)
        !           379:    Destroys the broker object and its dictionnaries */
        !           380: PHP_FUNCTION(enchant_broker_free)
        !           381: {
        !           382:        zval *broker;
        !           383:        enchant_broker *pbroker;
        !           384: 
        !           385:        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &broker) == FAILURE) {
        !           386:                RETURN_FALSE;
        !           387:        }
        !           388:        PHP_ENCHANT_GET_BROKER;
        !           389: 
        !           390:        zend_list_delete(Z_RESVAL_P(broker));
        !           391:        RETURN_TRUE;
        !           392: }
        !           393: /* }}} */
        !           394: 
        !           395: /* {{{ proto string enchant_broker_get_error(resource broker)
        !           396:    Returns the last error of the broker */
        !           397: PHP_FUNCTION(enchant_broker_get_error)
        !           398: {
        !           399:        zval *broker;
        !           400:        enchant_broker *pbroker;
        !           401:        char *msg;
        !           402: 
        !           403:        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &broker) == FAILURE) {
        !           404:                RETURN_FALSE;
        !           405:        }
        !           406: 
        !           407:        PHP_ENCHANT_GET_BROKER;
        !           408: 
        !           409:        msg = enchant_broker_get_error(pbroker->pbroker);
        !           410:        if (msg) {
        !           411:                RETURN_STRING((char *)msg, 1);
        !           412:        }
        !           413:        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: PHP_FUNCTION(enchant_broker_set_dict_path)
        !           495: {
        !           496:        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: PHP_FUNCTION(enchant_broker_get_dict_path)
        !           504: {
        !           505:        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: PHP_FUNCTION(enchant_broker_list_dicts)
        !           513: {
        !           514:        zval *broker;
        !           515:        enchant_broker *pbroker;
        !           516: 
        !           517:        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &broker) == FAILURE) {
        !           518:                RETURN_FALSE;
        !           519:        }
        !           520: 
        !           521:        PHP_ENCHANT_GET_BROKER;
        !           522: 
        !           523:        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: 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:        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &broker, &tag, &taglen) == FAILURE) {
        !           541:                RETURN_FALSE;
        !           542:        }
        !           543: 
        !           544:        PHP_ENCHANT_GET_BROKER;
        !           545: 
        !           546:        d = enchant_broker_request_dict(pbroker->pbroker, (const char *)tag);
        !           547:        if (d) {
        !           548:                if (pbroker->dictcnt) {
        !           549:                        pbroker->dict = (enchant_dict **)erealloc(pbroker->dict, sizeof(enchant_dict *) * pbroker->dictcnt);
        !           550:                        pos = pbroker->dictcnt++;
        !           551:                } else {
        !           552:                        pbroker->dict = (enchant_dict **)emalloc(sizeof(enchant_dict *));
        !           553:                        pos = 0;
        !           554:                        pbroker->dictcnt++;
        !           555:                }
        !           556: 
        !           557:                dict = pbroker->dict[pos] = (enchant_dict *)emalloc(sizeof(enchant_dict));
        !           558:                dict->id = pos;
        !           559:                dict->pbroker = pbroker;
        !           560:                dict->pdict = d;
        !           561:                dict->prev = pos ? pbroker->dict[pos-1] : NULL;
        !           562:                dict->next = NULL;
        !           563:                pbroker->dict[pos] = dict;
        !           564: 
        !           565:                if (pos) {
        !           566:                        pbroker->dict[pos-1]->next = dict;
        !           567:                }
        !           568: 
        !           569:                dict->rsrc_id = ZEND_REGISTER_RESOURCE(return_value, dict, le_enchant_dict);
        !           570:                zend_list_addref(pbroker->rsrc_id);
        !           571:        } else {
        !           572:                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: 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:        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &broker, &pwl, &pwllen) == FAILURE) {
        !           590:                RETURN_FALSE;
        !           591:        }
        !           592: 
        !           593:        if (strlen(pwl) != pwllen) {
        !           594:                RETURN_FALSE;
        !           595:        }
        !           596: 
        !           597: #if PHP_API_VERSION < 20100412
        !           598:        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:                RETURN_FALSE;
        !           603:        }
        !           604: 
        !           605:        PHP_ENCHANT_GET_BROKER;
        !           606: 
        !           607:        d = enchant_broker_request_pwl_dict(pbroker->pbroker, (const char *)pwl);
        !           608:        if (d) {
        !           609:                if (pbroker->dictcnt) {
        !           610:                        pos = pbroker->dictcnt++;
        !           611:                        pbroker->dict = (enchant_dict **)erealloc(pbroker->dict, sizeof(enchant_dict *) * pbroker->dictcnt);
        !           612:                } else {
        !           613:                        pbroker->dict = (enchant_dict **)emalloc(sizeof(enchant_dict *));
        !           614:                        pos = 0;
        !           615:                        pbroker->dictcnt++;
        !           616:                }
        !           617:                dict = pbroker->dict[pos] = (enchant_dict *)emalloc(sizeof(enchant_dict));
        !           618:                dict->id = pos;
        !           619:                dict->pbroker = pbroker;
        !           620:                dict->pdict = d;
        !           621:                dict->prev = pos?pbroker->dict[pos-1]:NULL;
        !           622:                dict->next = NULL;
        !           623:                pbroker->dict[pos] = dict;
        !           624:                if (pos) {
        !           625:                        pbroker->dict[pos-1]->next = dict;
        !           626:                }
        !           627:                dict->rsrc_id = ZEND_REGISTER_RESOURCE(return_value, dict, le_enchant_dict);
        !           628:        } else {
        !           629:                RETURN_FALSE;
        !           630:        }
        !           631: }
        !           632: /* }}} */
        !           633: 
        !           634: /* {{{ proto resource enchant_broker_free_dict(resource dict)
        !           635:    Free the dictionary resource */
        !           636: PHP_FUNCTION(enchant_broker_free_dict)
        !           637: {
        !           638:        zval *dict;
        !           639:        enchant_dict *pdict;
        !           640: 
        !           641:        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &dict) == FAILURE) {
        !           642:                RETURN_FALSE;
        !           643:        }
        !           644: 
        !           645:        PHP_ENCHANT_GET_DICT;
        !           646: 
        !           647:        zend_list_delete(Z_RESVAL_P(dict));
        !           648:        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: PHP_FUNCTION(enchant_broker_dict_exists)
        !           655: {
        !           656:        zval *broker;
        !           657:        char *tag;
        !           658:        int taglen;
        !           659:        enchant_broker * pbroker;
        !           660: 
        !           661:        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &broker, &tag, &taglen) == FAILURE) {
        !           662:                RETURN_FALSE;
        !           663:        }
        !           664: 
        !           665:        PHP_ENCHANT_GET_BROKER;
        !           666: 
        !           667:        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: 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:        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &broker, &ptag, &ptaglen, &pordering, &porderinglen) == FAILURE) {
        !           688:                RETURN_FALSE;
        !           689:        }
        !           690: 
        !           691:        PHP_ENCHANT_GET_BROKER;
        !           692: 
        !           693:        enchant_broker_set_ordering(pbroker->pbroker, ptag, pordering);
        !           694:        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: PHP_FUNCTION(enchant_broker_describe)
        !           701: {
        !           702:        EnchantBrokerDescribeFn describetozval = enumerate_providers_fn;
        !           703:        zval *broker;
        !           704:        enchant_broker * pbroker;
        !           705: 
        !           706:        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &broker) == FAILURE) {
        !           707:                RETURN_FALSE;
        !           708:        }
        !           709: 
        !           710:        PHP_ENCHANT_GET_BROKER;
        !           711: 
        !           712:        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: PHP_FUNCTION(enchant_dict_quick_check)
        !           720: {
        !           721:        zval *dict, *sugg = NULL;
        !           722:        char *word;
        !           723:        int wordlen;
        !           724:        enchant_dict *pdict;
        !           725: 
        !           726:        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|z/", &dict, &word, &wordlen, &sugg) == FAILURE) {
        !           727:                RETURN_FALSE;
        !           728:        }
        !           729: 
        !           730:        if (sugg) {
        !           731:                zval_dtor(sugg);
        !           732:        }
        !           733: 
        !           734:        PHP_ENCHANT_GET_DICT;
        !           735: 
        !           736:        if (enchant_dict_check(pdict->pdict, word, wordlen) > 0) {
        !           737:                int n_sugg;
        !           738:                size_t n_sugg_st;
        !           739:                char **suggs;
        !           740: 
        !           741:                if (!sugg && ZEND_NUM_ARGS() == 2) {
        !           742:                        RETURN_FALSE;
        !           743:                }
        !           744: 
        !           745:                array_init(sugg);
        !           746: 
        !           747:                suggs = enchant_dict_suggest(pdict->pdict, word, wordlen, &n_sugg_st);
        !           748:                memcpy(&n_sugg, &n_sugg_st, sizeof(n_sugg));
        !           749:                if (suggs && n_sugg) {
        !           750:                        int i;
        !           751:                        for (i = 0; i < n_sugg; i++) {
        !           752:                                add_next_index_string(sugg, suggs[i], 1);
        !           753:                        }
        !           754:                        enchant_dict_free_suggestions(pdict->pdict, suggs);
        !           755:                }
        !           756: 
        !           757: 
        !           758:                RETURN_FALSE;
        !           759:        }
        !           760:        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: PHP_FUNCTION(enchant_dict_check)
        !           767: {
        !           768:        zval *dict;
        !           769:        char *word;
        !           770:        int wordlen;
        !           771:        enchant_dict *pdict;
        !           772: 
        !           773:        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &dict, &word, &wordlen) == FAILURE) {
        !           774:                RETURN_FALSE;
        !           775:        }
        !           776: 
        !           777:        PHP_ENCHANT_GET_DICT;
        !           778: 
        !           779:        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: 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:        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &dict, &word, &wordlen) == FAILURE) {
        !           796:                RETURN_FALSE;
        !           797:        }
        !           798: 
        !           799:        PHP_ENCHANT_GET_DICT;
        !           800: 
        !           801:        suggs = enchant_dict_suggest(pdict->pdict, word, wordlen, &n_sugg_st);
        !           802:        memcpy(&n_sugg, &n_sugg_st, sizeof(n_sugg));
        !           803:        if (suggs && n_sugg) {
        !           804:                int i;
        !           805: 
        !           806:                array_init(return_value);
        !           807:                for (i = 0; i < n_sugg; i++) {
        !           808:                        add_next_index_string(return_value, suggs[i], 1);
        !           809:                }
        !           810: 
        !           811:                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: PHP_FUNCTION(enchant_dict_add_to_personal)
        !           819: {
        !           820:        zval *dict;
        !           821:        char *word;
        !           822:        int wordlen;
        !           823:        enchant_dict *pdict;
        !           824: 
        !           825:        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &dict, &word, &wordlen) == FAILURE) {
        !           826:                RETURN_FALSE;
        !           827:        }
        !           828: 
        !           829:        PHP_ENCHANT_GET_DICT;
        !           830: 
        !           831:        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: PHP_FUNCTION(enchant_dict_add_to_session)
        !           838: {
        !           839:        zval *dict;
        !           840:        char *word;
        !           841:        int wordlen;
        !           842:        enchant_dict *pdict;
        !           843: 
        !           844:        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &dict, &word, &wordlen) == FAILURE) {
        !           845:                RETURN_FALSE;
        !           846:        }
        !           847: 
        !           848:        PHP_ENCHANT_GET_DICT;
        !           849: 
        !           850:        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: PHP_FUNCTION(enchant_dict_is_in_session)
        !           857: {
        !           858:        zval *dict;
        !           859:        char *word;
        !           860:        int wordlen;
        !           861:        enchant_dict *pdict;
        !           862: 
        !           863:        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &dict, &word, &wordlen) == FAILURE) {
        !           864:                RETURN_FALSE;
        !           865:        }
        !           866: 
        !           867:        PHP_ENCHANT_GET_DICT;
        !           868: 
        !           869:        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: 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:        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &dict, &mis, &mislen, &cor, &corlen) == FAILURE) {
        !           887:                RETURN_FALSE;
        !           888:        }
        !           889: 
        !           890:        PHP_ENCHANT_GET_DICT;
        !           891: 
        !           892:        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: PHP_FUNCTION(enchant_dict_get_error)
        !           899: {
        !           900:        zval *dict;
        !           901:        enchant_dict *pdict;
        !           902:        char *msg;
        !           903: 
        !           904:        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &dict) == FAILURE) {
        !           905:                RETURN_FALSE;
        !           906:        }
        !           907: 
        !           908:        PHP_ENCHANT_GET_DICT;
        !           909: 
        !           910:        msg = enchant_dict_get_error(pdict->pdict);
        !           911:        if (msg) {
        !           912:                RETURN_STRING((char *)msg, 1);
        !           913:        }
        !           914: 
        !           915:        RETURN_FALSE;
        !           916: }
        !           917: /* }}} */
        !           918: 
        !           919: /* {{{ proto array enchant_dict_describe(resource dict)
        !           920:    Describes an individual dictionary 'dict' */
        !           921: PHP_FUNCTION(enchant_dict_describe)
        !           922: {
        !           923:        zval *dict;
        !           924:        enchant_dict *pdict;
        !           925: 
        !           926:        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &dict) == FAILURE) {
        !           927:                RETURN_FALSE;
        !           928:        }
        !           929: 
        !           930:        PHP_ENCHANT_GET_DICT;
        !           931: 
        !           932:        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:  */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>