|
version 1.1.1.1, 2012/02/21 23:47:54
|
version 1.1.1.4, 2014/06/15 20:03:42
|
|
Line 2
|
Line 2
|
| +----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| | PHP Version 5 | |
| PHP Version 5 | |
| +----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| | Copyright (c) 1997-2012 The PHP Group | | | Copyright (c) 1997-2014 The PHP Group | |
| +----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| | This source file is subject to version 3.01 of the PHP license, | |
| This source file is subject to version 3.01 of the PHP license, | |
| | that is bundled with this package in the file LICENSE, and is | |
| that is bundled with this package in the file LICENSE, and is | |
|
Line 74 static int reg_magic = 0;
|
Line 74 static int reg_magic = 0;
|
| /* }}} */ |
/* }}} */ |
| |
|
| ZEND_DECLARE_MODULE_GLOBALS(ereg) |
ZEND_DECLARE_MODULE_GLOBALS(ereg) |
| |
static PHP_GINIT_FUNCTION(ereg); |
| |
static PHP_GSHUTDOWN_FUNCTION(ereg); |
| |
|
| /* {{{ Module entry */ |
/* {{{ Module entry */ |
| zend_module_entry ereg_module_entry = { |
zend_module_entry ereg_module_entry = { |
| STANDARD_MODULE_HEADER, |
STANDARD_MODULE_HEADER, |
| "ereg", |
"ereg", |
| ereg_functions, |
ereg_functions, |
| PHP_MINIT(ereg), |
|
| PHP_MSHUTDOWN(ereg), |
|
| NULL, |
NULL, |
| NULL, |
NULL, |
| |
NULL, |
| |
NULL, |
| PHP_MINFO(ereg), |
PHP_MINFO(ereg), |
| NO_VERSION_YET, |
NO_VERSION_YET, |
| STANDARD_MODULE_PROPERTIES | PHP_MODULE_GLOBALS(ereg), |
| | PHP_GINIT(ereg), |
| | PHP_GSHUTDOWN(ereg), |
| | NULL, |
| | STANDARD_MODULE_PROPERTIES_EX |
| }; |
}; |
| /* }}} */ |
/* }}} */ |
| |
|
| |
/* {{{ COMPILE_DL_EREG */ |
| |
#ifdef COMPILE_DL_EREG |
| |
ZEND_GET_MODULE(ereg) |
| |
#endif |
| |
/* }}} */ |
| |
|
| /* {{{ ereg_lru_cmp */ |
/* {{{ ereg_lru_cmp */ |
| static int ereg_lru_cmp(const void *a, const void *b TSRMLS_DC) |
static int ereg_lru_cmp(const void *a, const void *b TSRMLS_DC) |
| { |
{ |
|
Line 124 static int ereg_clean_cache(void *data, void *arg TSRM
|
Line 136 static int ereg_clean_cache(void *data, void *arg TSRM
|
| |
|
| /* {{{ _php_regcomp |
/* {{{ _php_regcomp |
| */ |
*/ |
| static int _php_regcomp(regex_t *preg, const char *pattern, int cflags) | static int _php_regcomp(regex_t *preg, const char *pattern, int cflags TSRMLS_DC) |
| { |
{ |
| int r = 0; |
int r = 0; |
| int patlen = strlen(pattern); |
int patlen = strlen(pattern); |
| reg_cache *rc = NULL; |
reg_cache *rc = NULL; |
| TSRMLS_FETCH(); |
|
| |
|
| if (zend_hash_num_elements(&EREG(ht_rc)) >= EREG_CACHE_SIZE) { |
if (zend_hash_num_elements(&EREG(ht_rc)) >= EREG_CACHE_SIZE) { |
| /* easier than dealing with overflow as it happens */ |
/* easier than dealing with overflow as it happens */ |
|
Line 201 static void _free_ereg_cache(reg_cache *rc)
|
Line 212 static void _free_ereg_cache(reg_cache *rc)
|
| #undef regfree |
#undef regfree |
| #define regfree(a); |
#define regfree(a); |
| #undef regcomp |
#undef regcomp |
| #define regcomp(a, b, c) _php_regcomp(a, b, c) | #define regcomp(a, b, c) _php_regcomp(a, b, c TSRMLS_CC) |
| | |
| static void php_ereg_init_globals(zend_ereg_globals *ereg_globals TSRMLS_DC) | /* {{{ PHP_GINIT_FUNCTION |
| | */ |
| | static PHP_GINIT_FUNCTION(ereg) |
| { |
{ |
| zend_hash_init(&ereg_globals->ht_rc, 0, NULL, (void (*)(void *)) _free_ereg_cache, 1); |
zend_hash_init(&ereg_globals->ht_rc, 0, NULL, (void (*)(void *)) _free_ereg_cache, 1); |
| ereg_globals->lru_counter = 0; |
ereg_globals->lru_counter = 0; |
| } |
} |
| |
/* }}} */ |
| |
|
| static void php_ereg_destroy_globals(zend_ereg_globals *ereg_globals TSRMLS_DC) | /* {{{ PHP_GSHUTDOWN_FUNCTION |
| | */ |
| | static PHP_GSHUTDOWN_FUNCTION(ereg) |
| { |
{ |
| zend_hash_destroy(&ereg_globals->ht_rc); |
zend_hash_destroy(&ereg_globals->ht_rc); |
| } |
} |
| |
/* }}} */ |
| |
|
| PHP_MINIT_FUNCTION(ereg) |
|
| { |
|
| ZEND_INIT_MODULE_GLOBALS(ereg, php_ereg_init_globals, php_ereg_destroy_globals); |
|
| return SUCCESS; |
|
| } |
|
| |
|
| PHP_MSHUTDOWN_FUNCTION(ereg) |
|
| { |
|
| #ifndef ZTS |
|
| php_ereg_destroy_globals(&ereg_globals TSRMLS_CC); |
|
| #endif |
|
| |
|
| return SUCCESS; |
|
| } |
|
| |
|
| PHP_MINFO_FUNCTION(ereg) |
PHP_MINFO_FUNCTION(ereg) |
| { |
{ |
| php_info_print_table_start(); |
php_info_print_table_start(); |
|
Line 244 PHP_MINFO_FUNCTION(ereg)
|
Line 246 PHP_MINFO_FUNCTION(ereg)
|
| /* {{{ php_ereg_eprint |
/* {{{ php_ereg_eprint |
| * php_ereg_eprint - convert error number to name |
* php_ereg_eprint - convert error number to name |
| */ |
*/ |
| static void php_ereg_eprint(int err, regex_t *re) { | static void php_ereg_eprint(int err, regex_t *re TSRMLS_DC) { |
| char *buf = NULL, *message = NULL; |
char *buf = NULL, *message = NULL; |
| size_t len; |
size_t len; |
| size_t buf_len; |
size_t buf_len; |
|
Line 263 static void php_ereg_eprint(int err, regex_t *re) {
|
Line 265 static void php_ereg_eprint(int err, regex_t *re) {
|
| #endif |
#endif |
| len = regerror(err, re, NULL, 0); |
len = regerror(err, re, NULL, 0); |
| if (len) { |
if (len) { |
| TSRMLS_FETCH(); |
|
| |
|
| message = (char *)safe_emalloc((buf_len + len + 2), sizeof(char), 0); |
message = (char *)safe_emalloc((buf_len + len + 2), sizeof(char), 0); |
| if (!message) { |
if (!message) { |
| return; /* fail silently */ |
return; /* fail silently */ |
|
Line 328 static void php_ereg(INTERNAL_FUNCTION_PARAMETERS, int
|
Line 328 static void php_ereg(INTERNAL_FUNCTION_PARAMETERS, int
|
| } |
} |
| |
|
| if (err) { |
if (err) { |
| php_ereg_eprint(err, &re); | php_ereg_eprint(err, &re TSRMLS_CC); |
| RETURN_FALSE; |
RETURN_FALSE; |
| } |
} |
| |
|
|
Line 341 static void php_ereg(INTERNAL_FUNCTION_PARAMETERS, int
|
Line 341 static void php_ereg(INTERNAL_FUNCTION_PARAMETERS, int
|
| /* actually execute the regular expression */ |
/* actually execute the regular expression */ |
| err = regexec(&re, string, re.re_nsub+1, subs, 0); |
err = regexec(&re, string, re.re_nsub+1, subs, 0); |
| if (err && err != REG_NOMATCH) { |
if (err && err != REG_NOMATCH) { |
| php_ereg_eprint(err, &re); | php_ereg_eprint(err, &re TSRMLS_CC); |
| regfree(&re); |
regfree(&re); |
| efree(subs); |
efree(subs); |
| RETURN_FALSE; |
RETURN_FALSE; |
|
Line 400 PHP_FUNCTION(eregi)
|
Line 400 PHP_FUNCTION(eregi)
|
| |
|
| /* {{{ php_ereg_replace |
/* {{{ php_ereg_replace |
| * this is the meat and potatoes of regex replacement! */ |
* this is the meat and potatoes of regex replacement! */ |
| PHPAPI char *php_ereg_replace(const char *pattern, const char *replace, const char *string, int icase, int extended) | PHP_EREG_API char *php_ereg_replace(const char *pattern, const char *replace, const char *string, int icase, int extended TSRMLS_DC) |
| { |
{ |
| regex_t re; |
regex_t re; |
| regmatch_t *subs; |
regmatch_t *subs; |
|
Line 424 PHPAPI char *php_ereg_replace(const char *pattern, con
|
Line 424 PHPAPI char *php_ereg_replace(const char *pattern, con
|
| |
|
| err = regcomp(&re, pattern, copts); |
err = regcomp(&re, pattern, copts); |
| if (err) { |
if (err) { |
| php_ereg_eprint(err, &re); | php_ereg_eprint(err, &re TSRMLS_CC); |
| return ((char *) -1); |
return ((char *) -1); |
| } |
} |
| |
|
|
Line 443 PHPAPI char *php_ereg_replace(const char *pattern, con
|
Line 443 PHPAPI char *php_ereg_replace(const char *pattern, con
|
| err = regexec(&re, &string[pos], re.re_nsub+1, subs, (pos ? REG_NOTBOL : 0)); |
err = regexec(&re, &string[pos], re.re_nsub+1, subs, (pos ? REG_NOTBOL : 0)); |
| |
|
| if (err && err != REG_NOMATCH) { |
if (err && err != REG_NOMATCH) { |
| php_ereg_eprint(err, &re); | php_ereg_eprint(err, &re TSRMLS_CC); |
| efree(subs); |
efree(subs); |
| efree(buf); |
efree(buf); |
| regfree(&re); |
regfree(&re); |
|
Line 474 PHPAPI char *php_ereg_replace(const char *pattern, con
|
Line 474 PHPAPI char *php_ereg_replace(const char *pattern, con
|
| if (new_l + 1 > buf_len) { |
if (new_l + 1 > buf_len) { |
| buf_len = 1 + buf_len + 2 * new_l; |
buf_len = 1 + buf_len + 2 * new_l; |
| nbuf = emalloc(buf_len); |
nbuf = emalloc(buf_len); |
| strncpy(nbuf, buf, buf_len-1); | strncpy(nbuf, buf, buf_len - 1); |
| nbuf[buf_len - 1] = '\0'; |
nbuf[buf_len - 1] = '\0'; |
| efree(buf); |
efree(buf); |
| buf = nbuf; |
buf = nbuf; |
|
Line 487 PHPAPI char *php_ereg_replace(const char *pattern, con
|
Line 487 PHPAPI char *php_ereg_replace(const char *pattern, con
|
| walkbuf = &buf[tmp + subs[0].rm_so]; |
walkbuf = &buf[tmp + subs[0].rm_so]; |
| walk = replace; |
walk = replace; |
| while (*walk) { |
while (*walk) { |
| if ('\\' == *walk && isdigit((unsigned char)walk[1]) && ((unsigned char)walk[1]) - '0' <= (int)re.re_nsub) { | if ('\\' == *walk && isdigit((unsigned char)walk[1]) && (unsigned char)walk[1] - '0' <= (int)re.re_nsub) { |
| if (subs[walk[1] - '0'].rm_so > -1 && subs[walk[1] - '0'].rm_eo > -1 |
if (subs[walk[1] - '0'].rm_so > -1 && subs[walk[1] - '0'].rm_eo > -1 |
| /* this next case shouldn't happen. it does. */ |
/* this next case shouldn't happen. it does. */ |
| && subs[walk[1] - '0'].rm_so <= subs[walk[1] - '0'].rm_eo) { |
&& subs[walk[1] - '0'].rm_so <= subs[walk[1] - '0'].rm_eo) { |
|
Line 594 static void php_do_ereg_replace(INTERNAL_FUNCTION_PARA
|
Line 594 static void php_do_ereg_replace(INTERNAL_FUNCTION_PARA
|
| } |
} |
| |
|
| /* do the actual work */ |
/* do the actual work */ |
| ret = php_ereg_replace(pattern, replace, string, icase, 1); | ret = php_ereg_replace(pattern, replace, string, icase, 1 TSRMLS_CC); |
| if (ret == (char *) -1) { |
if (ret == (char *) -1) { |
| RETVAL_FALSE; |
RETVAL_FALSE; |
| } else { |
} else { |
|
Line 648 static void php_split(INTERNAL_FUNCTION_PARAMETERS, in
|
Line 648 static void php_split(INTERNAL_FUNCTION_PARAMETERS, in
|
| |
|
| err = regcomp(&re, spliton, REG_EXTENDED | copts); |
err = regcomp(&re, spliton, REG_EXTENDED | copts); |
| if (err) { |
if (err) { |
| php_ereg_eprint(err, &re); | php_ereg_eprint(err, &re TSRMLS_CC); |
| RETURN_FALSE; |
RETURN_FALSE; |
| } |
} |
| |
|
|
Line 692 static void php_split(INTERNAL_FUNCTION_PARAMETERS, in
|
Line 692 static void php_split(INTERNAL_FUNCTION_PARAMETERS, in
|
| |
|
| /* see if we encountered an error */ |
/* see if we encountered an error */ |
| if (err && err != REG_NOMATCH) { |
if (err && err != REG_NOMATCH) { |
| php_ereg_eprint(err, &re); | php_ereg_eprint(err, &re TSRMLS_CC); |
| regfree(&re); |
regfree(&re); |
| zend_hash_destroy(Z_ARRVAL_P(return_value)); |
zend_hash_destroy(Z_ARRVAL_P(return_value)); |
| efree(Z_ARRVAL_P(return_value)); |
efree(Z_ARRVAL_P(return_value)); |
|
Line 728 PHP_FUNCTION(spliti)
|
Line 728 PHP_FUNCTION(spliti)
|
| |
|
| /* {{{ proto string sql_regcase(string string) |
/* {{{ proto string sql_regcase(string string) |
| Make regular expression for case insensitive match */ |
Make regular expression for case insensitive match */ |
| PHPAPI PHP_FUNCTION(sql_regcase) | PHP_EREG_API PHP_FUNCTION(sql_regcase) |
| { |
{ |
| char *string, *tmp; |
char *string, *tmp; |
| int string_len; |
int string_len; |