libextractor-php

GNU libextractor
Log | Files | Refs | README

extractor.c (5480B)


      1 /*
      2   +----------------------------------------------------------------------+
      3   | PHP Version 5                                                        |
      4   +----------------------------------------------------------------------+
      5   | Copyright (c) 1997-2004 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 through the world-wide-web at the following url:           |
     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: Manfred Weber                                                |
     16   +----------------------------------------------------------------------+
     17 */
     18 
     19 /* $Id: extractor.c,v 1.1 2004/12/23 06:20:22 manfred Exp $ */
     20 
     21 #ifdef HAVE_CONFIG_H
     22 #include "config.h"
     23 #endif
     24 
     25 #include "php.h"
     26 #include "php_ini.h"
     27 #include "ext/standard/info.h"
     28 #include "php_extractor.h"
     29 #include <extractor.h>
     30 
     31 /* If you declare any globals in php_extractor.h uncomment this:
     32 ZEND_DECLARE_MODULE_GLOBALS(extractor)
     33 */
     34 
     35 /* True global resources - no need for thread safety here */
     36 static int le_extractor;
     37 
     38 /* {{{ extractor_functions[]
     39  *
     40  * Every user visible function must have an entry in extractor_functions[].
     41  */
     42 function_entry extractor_functions[] = {
     43 	PHP_FE(extractor_getkeywords,	NULL)
     44 	{NULL, NULL, NULL}	/* Must be the last line in extractor_functions[] */
     45 };
     46 /* }}} */
     47 
     48 /* {{{ extractor_module_entry
     49  */
     50 zend_module_entry extractor_module_entry = {
     51 #if ZEND_MODULE_API_NO >= 20010901
     52 	STANDARD_MODULE_HEADER,
     53 #endif
     54 	"extractor",
     55 	extractor_functions,
     56 	PHP_MINIT(extractor),
     57 	PHP_MSHUTDOWN(extractor),
     58 	PHP_RINIT(extractor),		/* Replace with NULL if there's nothing to do at request start */
     59 	PHP_RSHUTDOWN(extractor),	/* Replace with NULL if there's nothing to do at request end */
     60 	PHP_MINFO(extractor),
     61 #if ZEND_MODULE_API_NO >= 20010901
     62 	"0.1", /* Replace with version number for your extension */
     63 #endif
     64 	STANDARD_MODULE_PROPERTIES
     65 };
     66 /* }}} */
     67 
     68 #ifdef COMPILE_DL_EXTRACTOR
     69 ZEND_GET_MODULE(extractor)
     70 #endif
     71 
     72 /* {{{ PHP_INI
     73  */
     74 /* Remove comments and fill if you need to have entries in php.ini
     75 PHP_INI_BEGIN()
     76     STD_PHP_INI_ENTRY("extractor.global_value",      "42", PHP_INI_ALL, OnUpdateLong, global_value, zend_extractor_globals, extractor_globals)
     77     STD_PHP_INI_ENTRY("extractor.global_string", "foobar", PHP_INI_ALL, OnUpdateString, global_string, zend_extractor_globals, extractor_globals)
     78 PHP_INI_END()
     79 */
     80 /* }}} */
     81 
     82 /* {{{ php_extractor_init_globals
     83  */
     84 /* Uncomment this function if you have INI entries
     85 static void php_extractor_init_globals(zend_extractor_globals *extractor_globals)
     86 {
     87 	extractor_globals->global_value = 0;
     88 	extractor_globals->global_string = NULL;
     89 }
     90 */
     91 /* }}} */
     92 
     93 /* {{{ PHP_MINIT_FUNCTION
     94  */
     95 PHP_MINIT_FUNCTION(extractor)
     96 {
     97 	/* If you have INI entries, uncomment these lines 
     98 	ZEND_INIT_MODULE_GLOBALS(extractor, php_extractor_init_globals, NULL);
     99 	REGISTER_INI_ENTRIES();
    100 	*/
    101 	return SUCCESS;
    102 }
    103 /* }}} */
    104 
    105 /* {{{ PHP_MSHUTDOWN_FUNCTION
    106  */
    107 PHP_MSHUTDOWN_FUNCTION(extractor)
    108 {
    109 	/* uncomment this line if you have INI entries
    110 	UNREGISTER_INI_ENTRIES();
    111 	*/
    112 	return SUCCESS;
    113 }
    114 /* }}} */
    115 
    116 /* Remove if there's nothing to do at request start */
    117 /* {{{ PHP_RINIT_FUNCTION
    118  */
    119 PHP_RINIT_FUNCTION(extractor)
    120 {
    121 	return SUCCESS;
    122 }
    123 /* }}} */
    124 
    125 /* Remove if there's nothing to do at request end */
    126 /* {{{ PHP_RSHUTDOWN_FUNCTION
    127  */
    128 PHP_RSHUTDOWN_FUNCTION(extractor)
    129 {
    130 	return SUCCESS;
    131 }
    132 /* }}} */
    133 
    134 /* {{{ PHP_MINFO_FUNCTION
    135  */
    136 PHP_MINFO_FUNCTION(extractor)
    137 {
    138 	php_info_print_table_start();
    139 	php_info_print_table_header(2, "extractor support", "enabled");
    140 	php_info_print_table_end();
    141 
    142 	/* Remove comments if you have entries in php.ini
    143 	DISPLAY_INI_ENTRIES();
    144 	*/
    145 }
    146 /* }}} */
    147 
    148 /* The previous line is meant for vim and emacs, so it can correctly fold and 
    149    unfold functions in source code. See the corresponding marks just before 
    150    function definition, where the functions purpose is also documented. Please 
    151    follow this convention for the convenience of others editing your code.
    152 */
    153 
    154 /* {{{ proto array extractor_getkeywords(string filename)
    155    returns keywords */
    156 PHP_FUNCTION(extractor_getkeywords)
    157 {
    158         char *filename = NULL;
    159         int argc = ZEND_NUM_ARGS();
    160         int filename_len;
    161         EXTRACTOR_KeywordList *keywords;
    162         EXTRACTOR_ExtractorList *extractors;
    163 
    164         if (zend_parse_parameters(argc TSRMLS_CC, "s", &filename, &filename_len) == FAILURE)
    165                 return;
    166 
    167         extractors = EXTRACTOR_loadDefaultLibraries ();
    168         keywords = EXTRACTOR_getKeywords (extractors, filename);
    169         array_init(return_value);
    170         while (keywords != NULL)
    171         {
    172                 add_next_index_string(return_value,keywords->keyword,1);
    173                 keywords = keywords->next;
    174         }
    175         EXTRACTOR_freeKeywords (keywords);
    176         EXTRACTOR_removeAll (extractors);
    177         return;
    178 }
    179 /* }}} */
    180 
    181 
    182 /*
    183  * Local variables:
    184  * tab-width: 4
    185  * c-basic-offset: 4
    186  * End:
    187  * vim600: noet sw=4 ts=4 fdm=marker
    188  * vim<600: noet sw=4 ts=4
    189  */