cvs: php-src(PHP_5_3) / configure.in /ext/ereg .cvsignore CREDITS config.w32 config0.m4 ereg.c php_ereg.h php_regex.h /ext/ereg/regex .cvsignore
COPYRIGHT README WHATSNEW cclass.h cname.h debug.c debug.ih engine.c engine.ih main.c main.ih mkh regcomp.c regcomp.ih regerror.c regerror.ih regex.3
regex.7 regex.dsp regex.dsw regex.h regex.mak regex2.h regexec.c regfree.c split.c tests utils.h /ext/ereg/tests .cvsignore 001.phpt 002.phpt
003.phpt 004.phpt 005.phpt 006.phpt 007.phpt 008.phpt 009.phpt 010.phpt 011.phpt 012.phpt 013.phpt 014.phpt 015.phpt 016.phpt /ext/pgsql pgsql.c
/ext/standard basic_functions.c browscap.c config.m4 config.w32 html.c php_standard.h reg.c reg.h string.c /ext/standard/tests/reg .cvsignore
001.phpt 002.phpt 003.phpt 004.phpt 005.phpt 006.phpt 007.phpt 008.phpt 009.phpt 010.phpt 011.phpt 012.phpt 013.phpt 014.phpt 015.phpt 016.phpt /main
php.h php_regex.h /regex .cvsignore COPYRIGHT README WHATSNEW cclass.h cname.h debug.c debug.ih en! gine.c engine.ih main.c main.ih mkh regcomp.c
regcomp.ih regerror.c regerror.ih regex.3 regex.7 regex.dsp regex.dsw regex.h regex.mak regex2.h regex_extra.h regexec.c regfree.c split.c tests
utils.h /sapi/apache php_apache_http.h /sapi/apache_hooks php_apache_http.h /win32/build config.w32
| From: | Jani Taskinen | Date: | Fri, 05 Oct 2007 15:00:10 +0000 |
| Subject: | cvs: php-src(PHP_5_3) / configure.in /ext/ereg .cvsignore CREDITS config.w32 config0.m4 ereg.c php_ereg.h php_regex.h /ext/ereg/regex .cvsignore COPYRIGHT README WHATSNEW cclass.h cname.h debug.c debug.ih engine.c engine.ih main.c main.ih mkh regcomp.c regcomp.ih regerror.c regerror.ih regex.3 regex.7 regex.dsp regex.dsw regex.h regex.mak regex2.h regexec.c regfree.c split.c tests utils.h /ext/ereg/tests .cvsignore 001.phpt 002.phpt 003.phpt 004.phpt 005.phpt 006.phpt 007.phpt 008.phpt 009.phpt 010.phpt 011.phpt 012.phpt 013.phpt 014.phpt 015.phpt 016.phpt /ext/pgsql pgsql.c /ext/standard basic_functions.c browscap.c config.m4 config.w32 html.c php_standard.h reg.c reg.h string.c /ext/standard/tests/reg .cvsignore 001.phpt 002.phpt 003.phpt 004.phpt 005.phpt 006.phpt 007.phpt 008.phpt 009.phpt 010.phpt 011.phpt 012.phpt 013.phpt 014.phpt 015.phpt 016.phpt /main php.h php_regex.h /regex .cvsignore COPYRIGHT README WHATSNEW cclass.h cname.h debug.c debug.ih en! gine.c engine.ih main.c main.ih mkh regcomp.c regcomp.ih regerror.c regerror.ih regex.3 regex.7 regex.dsp regex.dsw regex.h regex.mak regex2.h regex_extra.h regexec.c regfree.c split.c tests utils.h /sapi/apache php_apache_http.h /sapi/apache_hooks php_apache_http.h /win32/build config.w32 |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-46467@lists.php.net to get a copy of this message | ||
jani Fri Oct 5 15:00:10 2007 UTC
Added files: (Branch: PHP_5_3)
/php-src/ext/ereg .cvsignore CREDITS config.w32 config0.m4 ereg.c
php_ereg.h php_regex.h
/php-src/ext/ereg/regex .cvsignore COPYRIGHT README WHATSNEW
cclass.h cname.h debug.c debug.ih engine.c
engine.ih main.c main.ih mkh regcomp.c
regcomp.ih regerror.c regerror.ih regex.3
regex.7 regex.dsp regex.dsw regex.h
regex.mak regex2.h regexec.c regfree.c
split.c tests utils.h
/php-src/ext/ereg/tests .cvsignore 001.phpt 002.phpt 003.phpt
004.phpt 005.phpt 006.phpt 007.phpt
008.phpt 009.phpt 010.phpt 011.phpt
012.phpt 013.phpt 014.phpt 015.phpt
016.phpt
Removed files:
/php-src/ext/standard reg.c reg.h
/php-src/ext/standard/tests/reg .cvsignore 001.phpt 002.phpt
003.phpt 004.phpt 005.phpt 006.phpt
007.phpt 008.phpt 009.phpt 010.phpt
011.phpt 012.phpt 013.phpt 014.phpt
015.phpt 016.phpt
/php-src/main php_regex.h
/php-src/regex .cvsignore COPYRIGHT README WHATSNEW cclass.h
cname.h debug.c debug.ih engine.c engine.ih main.c
main.ih mkh regcomp.c regcomp.ih regerror.c
regerror.ih regex.3 regex.7 regex.dsp regex.dsw
regex.h regex.mak regex2.h regex_extra.h regexec.c
regfree.c split.c tests utils.h
Modified files:
/php-src configure.in
/php-src/ext/pgsql pgsql.c
/php-src/ext/standard basic_functions.c browscap.c config.m4
config.w32 html.c php_standard.h string.c
/php-src/main php.h
/php-src/sapi/apache php_apache_http.h
/php-src/sapi/apache_hooks php_apache_http.h
/php-src/win32/build config.w32
Log:
MFH:- Moved the old regex functions to own extension: ereg
http://cvs.php.net/viewvc.cgi/php-src/configure.in?r1=1.579.2.52.2.77.2.4&r2=1.579.2.52.2.77.2.5&diff_format=u Index: php-src/configure.in diff -u php-src/configure.in:1.579.2.52.2.77.2.4 php-src/configure.in:1.579.2.52.2.77.2.5 --- php-src/configure.in:1.579.2.52.2.77.2.4 Fri Oct 5 14:48:32 2007 +++ php-src/configure.in Fri Oct 5 15:00:05 2007 @@ -1,4 +1,4 @@ -## $Id: configure.in,v 1.579.2.52.2.77.2.4 2007/10/05 14:48:32 nlopess Exp $ -*- autoconf -*- +## $Id: configure.in,v 1.579.2.52.2.77.2.5 2007/10/05 15:00:05 jani Exp $ -*- autoconf -*- dnl ## Process this file with autoconf to produce a configure script. divert(1) @@ -11,9 +11,9 @@ dnl ## libraries and so on. dnl ## In diversion 3 we check for compile-time options to the PHP -dnl ## core and how to deal with different system dependencies. This -dnl ## includes what regex library is used and whether debugging or short -dnl ## tags are enabled, and the default behaviour of php.ini options. +dnl ## core and how to deal with different system dependencies. +dnl ## This includes whether debugging or short tags are enabled +dnl ## and the default behaviour of php.ini options. dnl ## This is also where an SAPI interface is selected (choosing between dnl ## Apache module, CGI etc.) @@ -270,10 +270,9 @@ divert(3) dnl ## In diversion 3 we check for compile-time options to the PHP -dnl ## core and how to deal with different system dependencies. This -dnl ## includes what regex library is used and whether debugging or short -dnl ## tags are enabled, and the default behaviour of php.ini options. - +dnl ## core and how to deal with different system dependencies. +dnl ## This includes whether debugging or short tags are enabled +dnl ## and the default behaviour of php.ini options. dnl Starting system checks. dnl ------------------------------------------------------------------------- @@ -518,7 +517,6 @@ realpath \ random \ rand_r \ -regcomp \ res_search \ scandir \ setitimer \ @@ -1292,7 +1290,7 @@ PHP_SUBST(all_targets) PHP_SUBST(install_targets) -PHP_INSTALL_HEADERS([Zend/ TSRM/ include/ main/ main/streams/ regex/]) +PHP_INSTALL_HEADERS([Zend/ TSRM/ include/ main/ main/streams/]) PHP_ADD_SOURCES(TSRM, TSRM.c tsrm_strtok_r.c tsrm_virtual_cwd.c) @@ -1345,7 +1343,6 @@ PHP_ADD_SOURCES_X(Zend, zend_execute.c,,PHP_GLOBAL_OBJS,,$flag) PHP_ADD_BUILD_DIR(main main/streams) -PHP_ADD_BUILD_DIR(regex) PHP_ADD_BUILD_DIR(sapi/$PHP_SAPI sapi/cli) PHP_ADD_BUILD_DIR(TSRM) PHP_ADD_BUILD_DIR(Zend) http://cvs.php.net/viewvc.cgi/php-src/ext/pgsql/pgsql.c?r1=1.331.2.13.2.24.2.2&r2=1.331.2.13.2.24.2.3&diff_format=u Index: php-src/ext/pgsql/pgsql.c diff -u php-src/ext/pgsql/pgsql.c:1.331.2.13.2.24.2.2 php-src/ext/pgsql/pgsql.c:1.331.2.13.2.24.2.3 --- php-src/ext/pgsql/pgsql.c:1.331.2.13.2.24.2.2 Wed Oct 3 23:30:46 2007 +++ php-src/ext/pgsql/pgsql.c Fri Oct 5 15:00:08 2007 @@ -20,7 +20,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: pgsql.c,v 1.331.2.13.2.24.2.2 2007/10/03 23:30:46 iliaa Exp $ */ +/* $Id: pgsql.c,v 1.331.2.13.2.24.2.3 2007/10/05 15:00:08 jani Exp $ */ #include <stdlib.h> @@ -36,6 +36,7 @@ #include "php_ini.h" #include "ext/standard/php_standard.h" #include "ext/standard/php_smart_str.h" +#include "ext/ereg/php_regex.h" #undef PACKAGE_BUGREPORT #undef PACKAGE_NAME http://cvs.php.net/viewvc.cgi/php-src/ext/standard/basic_functions.c?r1=1.725.2.31.2.64.2.5&r2=1.725.2.31.2.64.2.6&diff_format=u Index: php-src/ext/standard/basic_functions.c diff -u php-src/ext/standard/basic_functions.c:1.725.2.31.2.64.2.5 php-src/ext/standard/basic_functions.c:1.725.2.31.2.64.2.6 --- php-src/ext/standard/basic_functions.c:1.725.2.31.2.64.2.5 Mon Oct 1 20:36:01 2007 +++ php-src/ext/standard/basic_functions.c Fri Oct 5 15:00:08 2007 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: basic_functions.c,v 1.725.2.31.2.64.2.5 2007/10/01 20:36:01 johannes Exp $ */ +/* $Id: basic_functions.c,v 1.725.2.31.2.64.2.6 2007/10/05 15:00:08 jani Exp $ */ #include "php.h" #include "php_streams.h" @@ -2203,54 +2203,6 @@ ZEND_BEGIN_ARG_INFO(arginfo_mt_getrandmax, 0) ZEND_END_ARG_INFO() /* }}} */ -/* {{{ reg.c */ -static -ZEND_BEGIN_ARG_INFO_EX(arginfo_ereg, 0, 0, 2) - ZEND_ARG_INFO(0, pattern) - ZEND_ARG_INFO(0, string) - ZEND_ARG_INFO(1, registers) /* ARRAY_INFO(1, registers, 1) */ -ZEND_END_ARG_INFO() - -static -ZEND_BEGIN_ARG_INFO_EX(arginfo_eregi, 0, 0, 2) - ZEND_ARG_INFO(0, pattern) - ZEND_ARG_INFO(0, string) - ZEND_ARG_INFO(1, registers) /* ARRAY_INFO(1, registers, 1) */ -ZEND_END_ARG_INFO() - -static -ZEND_BEGIN_ARG_INFO(arginfo_ereg_replace, 0) - ZEND_ARG_INFO(0, pattern) - ZEND_ARG_INFO(0, replacement) - ZEND_ARG_INFO(0, string) -ZEND_END_ARG_INFO() - -static -ZEND_BEGIN_ARG_INFO(arginfo_eregi_replace, 0) - ZEND_ARG_INFO(0, pattern) - ZEND_ARG_INFO(0, replacement) - ZEND_ARG_INFO(0, string) -ZEND_END_ARG_INFO() - -static -ZEND_BEGIN_ARG_INFO_EX(arginfo_split, 0, 0, 2) - ZEND_ARG_INFO(0, pattern) - ZEND_ARG_INFO(0, string) - ZEND_ARG_INFO(0, limit) -ZEND_END_ARG_INFO() - -static -ZEND_BEGIN_ARG_INFO_EX(arginfo_spliti, 0, 0, 2) - ZEND_ARG_INFO(0, pattern) - ZEND_ARG_INFO(0, string) - ZEND_ARG_INFO(0, limit) -ZEND_END_ARG_INFO() - -static -ZEND_BEGIN_ARG_INFO(arginfo_sql_regcase, 0) - ZEND_ARG_INFO(0, string) -ZEND_END_ARG_INFO() -/* }}} */ /* {{{ sha1.c */ static ZEND_BEGIN_ARG_INFO_EX(arginfo_sha1, 0, 0, 1) @@ -3202,6 +3154,7 @@ PHP_FE(similar_text, arginfo_similar_text) PHP_FE(explode, arginfo_explode) PHP_FE(implode, arginfo_implode) + PHP_FALIAS(join, implode, arginfo_implode) PHP_FE(setlocale, arginfo_setlocale) PHP_FE(localeconv, arginfo_localeconv) @@ -3478,16 +3431,6 @@ PHP_FE(is_scalar, arginfo_is_scalar) PHP_FE(is_callable, arginfo_is_callable) - /* functions from reg.c */ - PHP_FE(ereg, arginfo_ereg) - PHP_FE(ereg_replace, arginfo_ereg_replace) - PHP_FE(eregi, arginfo_eregi) - PHP_FE(eregi_replace, arginfo_eregi_replace) - PHP_FE(split, arginfo_split) - PHP_FE(spliti, arginfo_spliti) - PHP_FALIAS(join, implode, arginfo_implode) - PHP_FE(sql_regcase, arginfo_sql_regcase) - /* functions from dl.c */ PHP_FE(dl, arginfo_dl) @@ -4043,7 +3986,6 @@ register_html_constants(INIT_FUNC_ARGS_PASSTHRU); register_string_constants(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(regex)(INIT_FUNC_ARGS_PASSTHRU); PHP_MINIT(file)(INIT_FUNC_ARGS_PASSTHRU); PHP_MINIT(pack)(INIT_FUNC_ARGS_PASSTHRU); PHP_MINIT(browscap)(INIT_FUNC_ARGS_PASSTHRU); @@ -4121,7 +4063,6 @@ UNREGISTER_INI_ENTRIES(); - PHP_MSHUTDOWN(regex)(SHUTDOWN_FUNC_ARGS_PASSTHRU); PHP_MSHUTDOWN(browscap)(SHUTDOWN_FUNC_ARGS_PASSTHRU); PHP_MSHUTDOWN(array)(SHUTDOWN_FUNC_ARGS_PASSTHRU); PHP_MSHUTDOWN(assert)(SHUTDOWN_FUNC_ARGS_PASSTHRU); @@ -4234,7 +4175,6 @@ PHP_MINFO_FUNCTION(basic) /* {{{ */ { php_info_print_table_start(); - PHP_MINFO(regex)(ZEND_MODULE_INFO_FUNC_ARGS_PASSTHRU); PHP_MINFO(dl)(ZEND_MODULE_INFO_FUNC_ARGS_PASSTHRU); PHP_MINFO(mail)(ZEND_MODULE_INFO_FUNC_ARGS_PASSTHRU); php_info_print_table_end(); http://cvs.php.net/viewvc.cgi/php-src/ext/standard/browscap.c?r1=1.85.2.2.2.3.2.2&r2=1.85.2.2.2.3.2.3&diff_format=u Index: php-src/ext/standard/browscap.c diff -u php-src/ext/standard/browscap.c:1.85.2.2.2.3.2.2 php-src/ext/standard/browscap.c:1.85.2.2.2.3.2.3 --- php-src/ext/standard/browscap.c:1.85.2.2.2.3.2.2 Sun Sep 30 05:49:44 2007 +++ php-src/ext/standard/browscap.c Fri Oct 5 15:00:08 2007 @@ -16,10 +16,10 @@ +----------------------------------------------------------------------+ */ -/* $Id: browscap.c,v 1.85.2.2.2.3.2.2 2007/09/30 05:49:44 jani Exp $ */ +/* $Id: browscap.c,v 1.85.2.2.2.3.2.3 2007/10/05 15:00:08 jani Exp $ */ #include "php.h" -#include "php_regex.h" +#include "ext/ereg/php_regex.h" #include "php_browscap.h" #include "php_ini.h" #include "php_string.h" http://cvs.php.net/viewvc.cgi/php-src/ext/standard/config.m4?r1=1.80.2.3.2.3.2.1&r2=1.80.2.3.2.3.2.2&diff_format=u Index: php-src/ext/standard/config.m4 diff -u php-src/ext/standard/config.m4:1.80.2.3.2.3.2.1 php-src/ext/standard/config.m4:1.80.2.3.2.3.2.2 --- php-src/ext/standard/config.m4:1.80.2.3.2.3.2.1 Mon Oct 1 12:40:54 2007 +++ php-src/ext/standard/config.m4 Fri Oct 5 15:00:08 2007 @@ -1,4 +1,4 @@ -dnl $Id: config.m4,v 1.80.2.3.2.3.2.1 2007/10/01 12:40:54 jani Exp $ -*- autoconf -*- +dnl $Id: config.m4,v 1.80.2.3.2.3.2.2 2007/10/05 15:00:08 jani Exp $ -*- autoconf -*- divert(3)dnl @@ -208,52 +208,6 @@ divert(5)dnl dnl -dnl Check for regex library type -dnl -PHP_ARG_WITH(regex,, -[ --with-regex=TYPE regex library type: system, apache, php. [TYPE=php] - WARNING: Do NOT use unless you know what you are doing!], php, no) - -case $PHP_REGEX in - system) - if test "$PHP_SAPI" = "apache" || test "$PHP_SAPI" = "apache2filter" || test "$PHP_SAPI" = "apache2handler"; then - REGEX_TYPE=php - else - REGEX_TYPE=system - fi - ;; - apache) - REGEX_TYPE=apache - ;; - php) - REGEX_TYPE=php - ;; - *) - REGEX_TYPE=php - AC_MSG_WARN(Invalid regex library type selected. Using default value: php) - ;; -esac - -if test "$REGEX_TYPE" = "php"; then - AC_DEFINE(HAVE_REGEX_T_RE_MAGIC, 1, [ ]) - AC_DEFINE(HSREGEX,1,[ ]) - AC_DEFINE(REGEX,1,[ ]) - PHP_ADD_SOURCES(regex, regcomp.c regexec.c regerror.c regfree.c) -elif test "$REGEX_TYPE" = "system"; then - AC_DEFINE(REGEX,0,[ ]) - dnl Check if field re_magic exists in struct regex_t - AC_CACHE_CHECK([whether field re_magic exists in struct regex_t], ac_cv_regex_t_re_magic, [ - AC_TRY_COMPILE([#include <sys/types.h> -#include <regex.h>], [regex_t rt; rt.re_magic;], - [ac_cv_regex_t_re_magic=yes], [ac_cv_regex_t_re_magic=no])]) - if test "$ac_cv_regex_t_re_magic" = "yes"; then - AC_DEFINE([HAVE_REGEX_T_RE_MAGIC], [ ], 1) - fi -fi -AC_MSG_CHECKING([which regex library to use]) -AC_MSG_RESULT([$REGEX_TYPE]) - -dnl dnl round fuzz dnl AC_MSG_CHECKING([whether rounding works as expected]) @@ -502,7 +456,7 @@ flock_compat.c formatted_print.c fsock.c head.c html.c image.c \ info.c iptc.c lcg.c link.c mail.c math.c md5.c metaphone.c \ microtime.c pack.c pageinfo.c quot_print.c rand.c \ - reg.c soundex.c string.c scanf.c syslog.c type.c uniqid.c url.c \ + soundex.c string.c scanf.c syslog.c type.c uniqid.c url.c \ url_scanner.c var.c versioning.c assert.c strnatcmp.c levenshtein.c \ incomplete_class.c url_scanner_ex.c ftp_fopen_wrapper.c \ http_fopen_wrapper.c php_fopen_wrapper.c credits.c css.c \ http://cvs.php.net/viewvc.cgi/php-src/ext/standard/config.w32?r1=1.4.2.2.2.1&r2=1.4.2.2.2.1.2.1&diff_format=u Index: php-src/ext/standard/config.w32 diff -u php-src/ext/standard/config.w32:1.4.2.2.2.1 php-src/ext/standard/config.w32:1.4.2.2.2.1.2.1 --- php-src/ext/standard/config.w32:1.4.2.2.2.1 Wed Apr 18 09:38:54 2007 +++ php-src/ext/standard/config.w32 Fri Oct 5 15:00:08 2007 @@ -1,5 +1,5 @@ // vim:ft=javascript -// $Id: config.w32,v 1.4.2.2.2.1 2007/04/18 09:38:54 rrichards Exp $ +// $Id: config.w32,v 1.4.2.2.2.1.2.1 2007/10/05 15:00:08 jani Exp $ ARG_WITH("config-file-scan-dir", "Dir to check for additional php ini files", ""); AC_DEFINE("PHP_CONFIG_FILE_SCAN_DIR", PHP_CONFIG_FILE_SCAN_DIR); @@ -10,7 +10,7 @@ crc32.c crypt.c cyr_convert.c datetime.c dir.c dl.c dns.c exec.c \ file.c filestat.c formatted_print.c fsock.c head.c html.c image.c \ info.c iptc.c lcg.c link.c mail.c math.c md5.c metaphone.c microtime.c \ - pack.c pageinfo.c quot_print.c rand.c reg.c soundex.c \ + pack.c pageinfo.c quot_print.c rand.c soundex.c \ string.c scanf.c syslog.c type.c uniqid.c url.c url_scanner.c var.c \ versioning.c assert.c strnatcmp.c levenshtein.c incomplete_class.c \ url_scanner_ex.c ftp_fopen_wrapper.c http_fopen_wrapper.c \ http://cvs.php.net/viewvc.cgi/php-src/ext/standard/html.c?r1=1.111.2.2.2.14.2.1&r2=1.111.2.2.2.14.2.2&diff_format=u Index: php-src/ext/standard/html.c diff -u php-src/ext/standard/html.c:1.111.2.2.2.14.2.1 php-src/ext/standard/html.c:1.111.2.2.2.14.2.2 --- php-src/ext/standard/html.c:1.111.2.2.2.14.2.1 Wed Oct 3 05:05:08 2007 +++ php-src/ext/standard/html.c Fri Oct 5 15:00:08 2007 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: html.c,v 1.111.2.2.2.14.2.1 2007/10/03 05:05:08 stas Exp $ */ +/* $Id: html.c,v 1.111.2.2.2.14.2.2 2007/10/05 15:00:08 jani Exp $ */ /* * HTML entity resources: @@ -37,7 +37,6 @@ #else #include <php_config.h> #endif -#include "reg.h" #include "html.h" #include "php_string.h" #include "SAPI.h" http://cvs.php.net/viewvc.cgi/php-src/ext/standard/php_standard.h?r1=1.24.2.2.2.1&r2=1.24.2.2.2.1.2.1&diff_format=u Index: php-src/ext/standard/php_standard.h diff -u php-src/ext/standard/php_standard.h:1.24.2.2.2.1 php-src/ext/standard/php_standard.h:1.24.2.2.2.1.2.1 --- php-src/ext/standard/php_standard.h:1.24.2.2.2.1 Mon Jan 1 09:36:08 2007 +++ php-src/ext/standard/php_standard.h Fri Oct 5 15:00:08 2007 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_standard.h,v 1.24.2.2.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: php_standard.h,v 1.24.2.2.2.1.2.1 2007/10/05 15:00:08 jani Exp $ */ #include "basic_functions.h" #include "php_math.h" @@ -24,7 +24,6 @@ #include "base64.h" #include "php_dir.h" #include "dns.h" -#include "reg.h" #include "php_mail.h" #include "md5.h" #include "sha1.h" http://cvs.php.net/viewvc.cgi/php-src/ext/standard/string.c?r1=1.445.2.14.2.69.2.3&r2=1.445.2.14.2.69.2.4&diff_format=u Index: php-src/ext/standard/string.c diff -u php-src/ext/standard/string.c:1.445.2.14.2.69.2.3 php-src/ext/standard/string.c:1.445.2.14.2.69.2.4 --- php-src/ext/standard/string.c:1.445.2.14.2.69.2.3 Mon Oct 1 13:38:14 2007 +++ php-src/ext/standard/string.c Fri Oct 5 15:00:08 2007 @@ -18,13 +18,12 @@ +----------------------------------------------------------------------+ */ -/* $Id: string.c,v 1.445.2.14.2.69.2.3 2007/10/01 13:38:14 jani Exp $ */ +/* $Id: string.c,v 1.445.2.14.2.69.2.4 2007/10/05 15:00:08 jani Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ #include <stdio.h> #include "php.h" -#include "reg.h" #include "php_rand.h" #include "php_string.h" #include "php_variables.h" http://cvs.php.net/viewvc.cgi/php-src/main/php.h?r1=1.221.2.4.2.8&r2=1.221.2.4.2.8.2.1&diff_format=u Index: php-src/main/php.h diff -u php-src/main/php.h:1.221.2.4.2.8 php-src/main/php.h:1.221.2.4.2.8.2.1 --- php-src/main/php.h:1.221.2.4.2.8 Fri Aug 31 07:48:05 2007 +++ php-src/main/php.h Fri Oct 5 15:00:09 2007 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php.h,v 1.221.2.4.2.8 2007/08/31 07:48:05 jani Exp $ */ +/* $Id: php.h,v 1.221.2.4.2.8.2.1 2007/10/05 15:00:09 jani Exp $ */ #ifndef PHP_H #define PHP_H @@ -71,8 +71,6 @@ #define PHP_OS PHP_UNAME #endif -#include "php_regex.h" - #if HAVE_ASSERT_H #if PHP_DEBUG #undef NDEBUG @@ -193,10 +191,6 @@ char *strerror(int); #endif -#if (REGEX == 1 || REGEX == 0) && !defined(NO_REGEX_EXTRA_H) -#include "regex/regex_extra.h" -#endif - #if HAVE_PWD_H # ifdef PHP_WIN32 #include "win32/param.h" http://cvs.php.net/viewvc.cgi/php-src/sapi/apache/php_apache_http.h?r1=1.13.2.1.2.1&r2=1.13.2.1.2.1.2.1&diff_format=u Index: php-src/sapi/apache/php_apache_http.h diff -u php-src/sapi/apache/php_apache_http.h:1.13.2.1.2.1 php-src/sapi/apache/php_apache_http.h:1.13.2.1.2.1.2.1 --- php-src/sapi/apache/php_apache_http.h:1.13.2.1.2.1 Mon Jan 1 09:36:12 2007 +++ php-src/sapi/apache/php_apache_http.h Fri Oct 5 15:00:09 2007 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_apache_http.h,v 1.13.2.1.2.1 2007/01/01 09:36:12 sebastian Exp $ */ +/* $Id: php_apache_http.h,v 1.13.2.1.2.1.2.1 2007/10/05 15:00:09 jani Exp $ */ #define NO_REGEX_EXTRA_H @@ -31,7 +31,7 @@ #endif #include "zend.h" -#include "php_regex.h" +#include "ext/ereg/php_regex.h" #include "php_compat.h" #ifdef HAVE_OPENSSL_EXT http://cvs.php.net/viewvc.cgi/php-src/sapi/apache_hooks/php_apache_http.h?r1=1.3&r2=1.3.8.1&diff_format=u Index: php-src/sapi/apache_hooks/php_apache_http.h diff -u php-src/sapi/apache_hooks/php_apache_http.h:1.3 php-src/sapi/apache_hooks/php_apache_http.h:1.3.8.1 --- php-src/sapi/apache_hooks/php_apache_http.h:1.3 Sat Jan 17 13:00:09 2004 +++ php-src/sapi/apache_hooks/php_apache_http.h Fri Oct 5 15:00:09 2007 @@ -11,7 +11,7 @@ #include "zend.h" #include "zend_stack.h" -#include "php_regex.h" +#include "ext/ereg/php_regex.h" #include "httpd.h" #include "http_config.h" http://cvs.php.net/viewvc.cgi/php-src/win32/build/config.w32?r1=1.40.2.8.2.10.2.1&r2=1.40.2.8.2.10.2.2&diff_format=u Index: php-src/win32/build/config.w32 diff -u php-src/win32/build/config.w32:1.40.2.8.2.10.2.1 php-src/win32/build/config.w32:1.40.2.8.2.10.2.2 --- php-src/win32/build/config.w32:1.40.2.8.2.10.2.1 Mon Oct 1 12:40:54 2007 +++ php-src/win32/build/config.w32 Fri Oct 5 15:00:09 2007 @@ -1,5 +1,5 @@ // vim:ft=javascript -// $Id: config.w32,v 1.40.2.8.2.10.2.1 2007/10/01 12:40:54 jani Exp $ +// $Id: config.w32,v 1.40.2.8.2.10.2.2 2007/10/05 15:00:09 jani Exp $ // "Master" config file; think of it as a configure.in // equivalent. @@ -99,7 +99,7 @@ } DEFINE('PHP_PREFIX', PHP_PREFIX); -DEFINE("BASE_INCLUDES", "/I . /I main /I regex /I Zend /I TSRM /I ext "); +DEFINE("BASE_INCLUDES", "/I . /I main /I Zend /I TSRM /I ext "); // CFLAGS for building the PHP dll DEFINE("CFLAGS_PHP", "/D _USRDLL /D PHP5DLLTS_EXPORTS /D PHP_EXPORTS \ @@ -312,8 +312,6 @@ ADD_SOURCES("win32", "crypt_win32.c glob.c md5crypt.c readdir.c \ registry.c select.c sendmail.c time.c wfile.c winutil.c wsyslog.c globals.c"); -ADD_SOURCES("regex", "regcomp.c regerror.c regexec.c regfree.c"); - STDOUT.WriteBlankLines(1); /* Can we build with IPv6 support? */ http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/.cvsignore?view=markup&rev=1.1 Index: php-src/ext/ereg/.cvsignore +++ php-src/ext/ereg/.cvsignore #*# *.dsw *.la *.lo *.ncb *.opt *.plg *.tgz *~..#*..*.swp..deps..libs Debug Debug_TS Makefile Makefile.fragments Makefile.global Makefile.objects Release Release_TS Release_TSDbg Release_TS_inline Release_inline acinclude.m4 aclocal.m4 autom4te.cache build config.cache config.guess config.h config.h.in config.log config.nice config.status config.sub configure configure.in conftest conftest.c include install-sh libtool ltmain.sh missing mkinstalldirs modules scan_makefile_in.awk *.gcda *.gcno http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/config.w32?view=markup&rev=1.1 Index: php-src/ext/ereg/config.w32 +++ php-src/ext/ereg/config.w32 // $Id: config.w32,v 1.1 2007/07/15 19:50:06 jani Exp $ // vim:ft=javascript EXTENSION("ereg", "ereg.c", false /* never shared */, "-Iext/ereg/regex"); ADD_SOURCES("ext/ereg/regex", "regcomp.c regexec.c regerror.c regfree.c", "ereg"); AC_DEFINE('REGEX', 1, 'Bundled regex'); AC_DEFINE('HSREGEX', 1, 'Bundled regex'); http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/config0.m4?view=markup&rev=1.1 Index: php-src/ext/ereg/config0.m4 +++ php-src/ext/ereg/config0.m4 dnl $Id: config0.m4,v 1.1 2007/07/15 19:50:06 jani Exp $ dnl config.m4 for extension ereg dnl dnl Check for regex library type dnl PHP_ARG_WITH(regex,, [ --with-regex=TYPE regex library type: system, apache, php. [TYPE=php] WARNING: Do NOT use unless you know what you are doing!], php, no) case $PHP_REGEX in system) if test "$PHP_SAPI" = "apache" || test "$PHP_SAPI" = "apache2filter" || test "$PHP_SAPI" = "apache2handler"; then REGEX_TYPE=php else REGEX_TYPE=system fi ;; apache) REGEX_TYPE=apache ;; yes | php) REGEX_TYPE=php ;; *) REGEX_TYPE=php AC_MSG_WARN([Invalid regex library type selected. Using default value: php]) ;; esac AC_MSG_CHECKING([which regex library to use]) AC_MSG_RESULT([$REGEX_TYPE]) if test "$REGEX_TYPE" = "php"; then ereg_regex_sources="regex/regcomp.c regex/regexec.c regex/regerror.c regex/regfree.c" ereg_regex_headers="regex/" fi PHP_NEW_EXTENSION(ereg, ereg.c $ereg_regex_sources, no) PHP_INSTALL_HEADERS([ext/ereg], [php_ereg.h php_regex.h $ereg_regex_headers]) if test "$REGEX_TYPE" = "php"; then AC_DEFINE(HAVE_REGEX_T_RE_MAGIC, 1, [ ]) AC_DEFINE(HSREGEX,1,[ ]) AC_DEFINE(REGEX,1,[ ]) PHP_ADD_BUILD_DIR([$ext_builddir/regex], 1) PHP_ADD_INCLUDE([$ext_srcdir/regex]) elif test "$REGEX_TYPE" = "system"; then AC_DEFINE(REGEX,0,[ ]) dnl Check if field re_magic exists in struct regex_t AC_CACHE_CHECK([whether field re_magic exists in struct regex_t], ac_cv_regex_t_re_magic, [ AC_TRY_COMPILE([#include <sys/types.h> #include <regex.h>], [regex_t rt; rt.re_magic;], [ac_cv_regex_t_re_magic=yes], [ac_cv_regex_t_re_magic=no])]) if test "$ac_cv_regex_t_re_magic" = "yes"; then AC_DEFINE([HAVE_REGEX_T_RE_MAGIC], [ ], 1) fi fi http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/ereg.c?view=markup&rev=1.1 Index: php-src/ext/ereg/ereg.c +++ php-src/ext/ereg/ereg.c /* +----------------------------------------------------------------------+ | PHP HTML Embedded Scripting Language Version 3.0 | +----------------------------------------------------------------------+ | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | +----------------------------------------------------------------------+ | This program is free software; you can redistribute it and/or modify | | it under the terms of one of the following licenses: | | | | A) the GNU General Public License as published by the Free Software | | Foundation; either version 2 of the License, or (at your option) | | any later version. | | | | B) the PHP License as published by the PHP Development Team and | | included in the distribution in the file: LICENSE | | | | This program is distributed in the hope that it will be useful, | | but WITHOUT ANY WARRANTY; without even the implied warranty of | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | | GNU General Public License for more details. | | | | You should have received a copy of both licenses referred to here. | | If you did not, or have any questions about PHP licensing, please | | contact core@php.net. | +----------------------------------------------------------------------+ | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | | Jim Winstead <jimw@php.net> | | Jaakko Hyvätti <jaakko@hyvatti.iki.fi> | +----------------------------------------------------------------------+ */ /* $Id: ereg.c,v 1.1 1999/04/17 00:37:07 ssb Exp $ */ #ifdef THREAD_SAFE #include "tls.h" #endif #include <stdio.h> #include "php.h" #include "php3_string.h" #include "reg.h" unsigned char third_argument_force_ref[] = { 3, BYREF_NONE, BYREF_NONE, BYREF_FORCE }; function_entry reg_functions[] = { {"ereg", php3_ereg, third_argument_force_ref }, {"ereg_replace", php3_eregreplace, NULL }, {"eregi", php3_eregi, third_argument_force_ref }, {"eregi_replace", php3_eregireplace, NULL }, {"split", php3_split, NULL}, {"join", php3_implode, NULL}, {"sql_regcase", php3_sql_regcase, NULL}, {NULL, NULL, NULL} }; php3_module_entry regexp_module_entry = { "Regular Expressions", reg_functions, NULL, NULL, NULL, NULL, NULL, STANDARD_MODULE_PROPERTIES }; /* This is the maximum number of (..) constructs we'll generate from a call to ereg() or eregi() with the optional third argument. */ #define NS 10 /* * _php3_reg_eprint - convert error number to name */ static void _php3_reg_eprint(int err, regex_t *re) { char *buf = NULL, *message = NULL; size_t len; size_t buf_len; #ifdef REG_ITOA /* get the length of the message */ buf_len = regerror(REG_ITOA | err, re, NULL, 0); if (buf_len) { buf = (char *)emalloc(buf_len * sizeof(char)); if (!buf) return; /* fail silently */ /* finally, get the error message */ regerror(REG_ITOA | err, re, buf, buf_len); } #else buf_len = 0; #endif len = regerror(err, re, NULL, 0); if (len) { message = (char *)emalloc((buf_len + len + 2) * sizeof(char)); if (!message) { return; /* fail silently */ } if (buf_len) { snprintf(message, buf_len, "%s: ", buf); buf_len += 1; /* so pointer math below works */ } /* drop the message into place */ regerror(err, re, message + buf_len, len); php3_error(E_WARNING, "%s", message); } STR_FREE(buf); STR_FREE(message); } static void _php3_ereg(INTERNAL_FUNCTION_PARAMETERS, int icase) { pval *regex, /* Regular expression */ *findin, /* String to apply expression to */ *array = NULL; /* Optional register array */ regex_t re; regmatch_t subs[NS]; int err, i, match_len, string_len; int copts = 0; off_t start, end; char *buf = NULL; char *string = NULL; TLS_VARS; if (icase) copts |= REG_ICASE; switch(ARG_COUNT(ht)) { case 2: if (getParameters(ht, 2, ®ex, &findin) == FAILURE) { WRONG_PARAM_COUNT; } /* don't bother doing substring matching if we're not going to make use of the information */ copts |= REG_NOSUB; break; case 3: if (getParameters(ht, 3, ®ex, &findin, &array) == FAILURE) { WRONG_PARAM_COUNT; } if (!ParameterPassedByReference(ht, 3)) { php3_error(E_WARNING, "Array to be filled with values must be passed by reference."); RETURN_FALSE; } break; default: WRONG_PARAM_COUNT; } /* compile the regular expression from the supplied regex */ if (regex->type == IS_STRING) { err = regcomp(&re, regex->value.str.val, REG_EXTENDED | copts); } else { /* we convert numbers to integers and treat them as a string */ if (regex->type == IS_DOUBLE) convert_to_long(regex); /* get rid of decimal places */ convert_to_string(regex); /* don't bother doing an extended regex with just a number */ err = regcomp(&re, regex->value.str.val, copts); } if (err) { _php3_reg_eprint(err, &re); RETURN_FALSE; } /* make a copy of the string we're looking in */ convert_to_string(findin); string = estrndup(findin->value.str.val, findin->value.str.len); /* actually execute the regular expression */ err = regexec(&re, string, (size_t) NS, subs, 0); if (err && err != REG_NOMATCH) { _php3_reg_eprint(err, &re); regfree(&re); RETURN_FALSE; } match_len = 1; if (array && err != REG_NOMATCH) { match_len = (int) (subs[0].rm_eo - subs[0].rm_so); string_len = strlen(string) + 1; buf = emalloc(string_len); if (!buf) { php3_error(E_WARNING, "Unable to allocate memory in _php3_ereg"); RETURN_FALSE; } pval_destructor(array _INLINE_TLS); /* start with clean array */ array_init(array); for (i = 0; i < NS; i++) { start = subs[i].rm_so; end = subs[i].rm_eo; if (start != -1 && end > 0 && start < string_len && end < string_len && start < end) { add_index_stringl(array, i, string+start, end-start, 1); } } efree(buf); } efree(string); if (err == REG_NOMATCH) { RETVAL_FALSE; } else { if (match_len == 0) match_len = 1; RETVAL_LONG(match_len); } regfree(&re); } /* {{{ proto int ereg(string pattern, string string [, array registers]) Regular expression match */ void php3_ereg(INTERNAL_FUNCTION_PARAMETERS) { _php3_ereg(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); } /* }}} */ /* {{{ proto int eregi(string pattern, string string [, array registers]) Case-insensitive regular expression match */ void php3_eregi(INTERNAL_FUNCTION_PARAMETERS) { _php3_ereg(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); } /* }}} */ /* this is the meat and potatoes of regex replacement! */ char *_php3_regreplace(const char *pattern, const char *replace, const char *string, int icase, int extended) { regex_t re; regmatch_t subs[NS]; char *buf, /* buf is where we build the replaced string */ *nbuf, /* nbuf is used when we grow the buffer */ *walkbuf; /* used to walk buf when replacing backrefs */ const char *walk; /* used to walk replacement string for backrefs */ int buf_len; int pos, tmp, string_len, new_l; int err, copts = 0; string_len = strlen(string); if (!string_len) return (char *)string; if (icase) copts = REG_ICASE; if (extended) copts |= REG_EXTENDED; err = regcomp(&re, pattern, copts); if (err) { _php3_reg_eprint(err, &re); return ((char *) -1); } /* start with a buffer that is twice the size of the stringo we're doing replacements in */ buf_len = 2 * string_len + 1; buf = emalloc(buf_len * sizeof(char)); if (!buf) { php3_error(E_WARNING, "Unable to allocate memory in _php3_regreplace"); regfree(&re); return ((char *) -1); } err = pos = 0; buf[0] = '\0'; while (!err) { err = regexec(&re, &string[pos], (size_t) NS, subs, (pos ? REG_NOTBOL : 0)); if (err && err != REG_NOMATCH) { _php3_reg_eprint(err, &re); regfree(&re); return ((char *) -1); } if (!err) { /* backref replacement is done in two passes: 1) find out how long the string will be, and allocate buf 2) copy the part before match, replacement and backrefs to buf Jaakko Hyvätti <Jaakko.Hyvatti@iki.fi> */ new_l = strlen(buf) + subs[0].rm_so; /* part before the match */ walk = replace; while (*walk) if ('\\' == *walk && '0' <= walk[1] && '9' >= walk[1] && subs[walk[1] - '0'].rm_so > -1 && subs[walk[1] - '0'].rm_eo > -1) { new_l += subs[walk[1] - '0'].rm_eo - subs[walk[1] - '0'].rm_so; walk += 2; } else { new_l++; walk++; } if (new_l + 1 > buf_len) { buf_len = 1 + buf_len + 2 * new_l; nbuf = emalloc(buf_len); strcpy(nbuf, buf); efree(buf); buf = nbuf; } tmp = strlen(buf); /* copy the part of the string before the match */ strncat(buf, &string[pos], subs[0].rm_so); /* copy replacement and backrefs */ walkbuf = &buf[tmp + subs[0].rm_so]; walk = replace; while (*walk) if ('\\' == *walk && '0' <= walk[1] && '9' >= walk[1] && subs[walk[1] - '0'].rm_so > -1 && subs[walk[1] - '0'].rm_eo > -1) { tmp = subs[walk[1] - '0'].rm_eo - subs[walk[1] - '0'].rm_so; memcpy (walkbuf, &string[pos + subs[walk[1] - '0'].rm_so], tmp); walkbuf += tmp; walk += 2; } else *walkbuf++ = *walk++; *walkbuf = '\0'; /* and get ready to keep looking for replacements */ if (subs[0].rm_so == subs[0].rm_eo) { if (subs[0].rm_so + pos >= string_len) break; new_l = strlen (buf) + 1; if (new_l + 1 > buf_len) { buf_len = 1 + buf_len + 2 * new_l; nbuf = emalloc(buf_len * sizeof(char)); strcpy(nbuf, buf); efree(buf); buf = nbuf; } pos += subs[0].rm_eo + 1; buf [new_l-1] = string [pos-1]; buf [new_l] = '\0'; } else { pos += subs[0].rm_eo; } } else { /* REG_NOMATCH */ new_l = strlen(buf) + strlen(&string[pos]); if (new_l + 1 > buf_len) { buf_len = new_l + 1; /* now we know exactly how long it is */ nbuf = emalloc(buf_len * sizeof(char)); strcpy(nbuf, buf); efree(buf); buf = nbuf; } /* stick that last bit of string on our output */ strcat(buf, &string[pos]); } } /* don't want to leak memory .. */ regfree(&re); /* whew. */ return (buf); } static void _php3_eregreplace(INTERNAL_FUNCTION_PARAMETERS, int icase) { pval *arg_pattern, *arg_replace, *arg_string; char *pattern; char *string; char *replace; char *ret; TLS_VARS; if (ARG_COUNT(ht) != 3 || getParameters(ht, 3, &arg_pattern, &arg_replace, &arg_string) == FAILURE) { WRONG_PARAM_COUNT; } if (arg_pattern->type == IS_STRING) { if (arg_pattern->value.str.val && arg_pattern->value.str.len) pattern = estrndup(arg_pattern->value.str.val,arg_pattern->value.str.len); else pattern = empty_string; } else { convert_to_long(arg_pattern); pattern = emalloc(2); pattern[0] = (char) arg_pattern->value.lval; pattern[1] = '\0'; } if (arg_replace->type == IS_STRING) { if (arg_replace->value.str.val && arg_replace->value.str.len) replace = estrndup(arg_replace->value.str.val, arg_replace->value.str.len); else replace = empty_string; } else { convert_to_long(arg_replace); replace = emalloc(2); replace[0] = (char) arg_replace->value.lval; replace[1] = '\0'; } convert_to_string(arg_string); if (arg_string->value.str.val && arg_string->value.str.len) string = estrndup(arg_string->value.str.val, arg_string->value.str.len); else string = empty_string; /* do the actual work */ ret = _php3_regreplace(pattern, replace, string, icase, 1); if (ret == (char *) -1) { RETVAL_FALSE; } else { RETVAL_STRING(ret,1); STR_FREE(ret); } STR_FREE(string); STR_FREE(replace); STR_FREE(pattern); } /* {{{ proto string ereg_replace(string pattern, string string [, array registers]) Replace regular expression */ void php3_eregreplace(INTERNAL_FUNCTION_PARAMETERS) { _php3_eregreplace(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); } /* }}} */ /* {{{ proto string eregi_replace(string pattern, string string [, array registers]) Case insensitive replace regular expression */ void php3_eregireplace(INTERNAL_FUNCTION_PARAMETERS) { _php3_eregreplace(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); } /* }}} */ /* ("root", "passwd", "uid", "gid", "other:stuff:like:/bin/sh") = split(":", $passwd_file, 5); */ /* {{{ proto array split(string pattern, string string [, int limit]) split string into array by regular expression */ void php3_split(INTERNAL_FUNCTION_PARAMETERS) { pval *spliton, *str, *arg_count = NULL; regex_t re; regmatch_t subs[1]; char *strp, *endp; int err, size, count; TLS_VARS; switch (ARG_COUNT(ht)) { case 2: if (getParameters(ht, 2, &spliton, &str) == FAILURE) WRONG_PARAM_COUNT; count = -1; break; case 3: if (getParameters(ht, 3, &spliton, &str, &arg_count) == FAILURE) WRONG_PARAM_COUNT; convert_to_long(arg_count); count = arg_count->value.lval; break; default: WRONG_PARAM_COUNT; } convert_to_string(spliton); convert_to_string(str); strp = str->value.str.val; endp = str->value.str.val + strlen(str->value.str.val); err = regcomp(&re, spliton->value.str.val, REG_EXTENDED); if (err) { php3_error(E_WARNING, "unexpected regex error (%d)", err); RETURN_FALSE; } if (array_init(return_value) == FAILURE) { regfree(&re); RETURN_FALSE; } /* churn through str, generating array entries as we go */ while ((count == -1 || count > 1) && !(err = regexec(&re, strp, 1, subs, 0))) { if (subs[0].rm_so == 0 && subs[0].rm_eo) { /* match is at start of string, return empty string */ add_next_index_stringl(return_value, empty_string, 0, 1); /* skip ahead the length of the regex match */ strp+=subs[0].rm_eo; } else if (subs[0].rm_so==0 && subs[0].rm_eo==0) { /* No more matches */ regfree(&re); php3_error(E_WARNING, "bad regular expression for split()"); _php3_hash_destroy(return_value->value.ht); efree(return_value->value.ht); RETURN_FALSE; } else { /* On a real match */ /* make a copy of the substring */ size = subs[0].rm_so; /* add it to the array */ add_next_index_stringl(return_value, strp, size, 1); /* point at our new starting point */ strp = strp + subs[0].rm_eo; } /* if we're only looking for a certain number of points, stop looking once we hit it */ if (count != -1) count--; } /* see if we encountered an error */ if (err && err != REG_NOMATCH) { php3_error(E_WARNING, "unexpected regex error (%d)", err); regfree(&re); _php3_hash_destroy(return_value->value.ht); efree(return_value->value.ht); RETURN_FALSE; } /* otherwise we just have one last element to add to the array */ size = endp - strp; add_next_index_stringl(return_value, strp, size, 1); regfree(&re); return; } /* }}} */ /* {{{ proto string sql_regcase(string string) Make regular expression for case insensitive match */ PHPAPI void php3_sql_regcase(INTERNAL_FUNCTION_PARAMETERS) { pval *string; char *tmp; register int i; if (ARG_COUNT(ht)!=1 || getParameters(ht, 1, &string)==FAILURE) { WRONG_PARAM_COUNT; } convert_to_string(string); tmp = (char *) emalloc(string->value.str.len*4+1); for (i=0; i<string->value.str.len; i++) { tmp[i*4] = '['; tmp[i*4+1]=toupper((unsigned char)string->value.str.val[i]); tmp[i*4+2]=tolower((unsigned char)string->value.str.val[i]); tmp[i*4+3]=']'; } tmp[string->value.str.len*4]=0; return_value->value.str.val = tmp; return_value->value.str.len = string->value.str.len*4; return_value->type = IS_STRING; } /* }}} */ /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: */ http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/php_ereg.h?view=markup&rev=1.1 Index: php-src/ext/ereg/php_ereg.h +++ php-src/ext/ereg/php_ereg.h /* +----------------------------------------------------------------------+ | PHP HTML Embedded Scripting Language Version 3.0 | +----------------------------------------------------------------------+ | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | +----------------------------------------------------------------------+ | This program is free software; you can redistribute it and/or modify | | it under the terms of one of the following licenses: | | | | A) the GNU General Public License as published by the Free Software | | Foundation; either version 2 of the License, or (at your option) | | any later version. | | | | B) the PHP License as published by the PHP Development Team and | | included in the distribution in the file: LICENSE | | | | This program is distributed in the hope that it will be useful, | | but WITHOUT ANY WARRANTY; without even the implied warranty of | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | | GNU General Public License for more details. | | | | You should have received a copy of both licenses referred to here. | | If you did not, or have any questions about PHP licensing, please | | contact core@php.net. | +----------------------------------------------------------------------+ | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | +----------------------------------------------------------------------+ */ /* $Id: php_ereg.h,v 1.1 1999/04/17 00:37:07 ssb Exp $ */ #ifndef _REG_H #define _REG_H extern php3_module_entry regexp_module_entry; #define regexp_module_ptr ®exp_module_entry extern char *_php3_regreplace(const char *pattern, const char *replace, const char *string, int icase, int extended); extern void php3_ereg(INTERNAL_FUNCTION_PARAMETERS); extern void php3_eregi(INTERNAL_FUNCTION_PARAMETERS); extern void php3_eregireplace(INTERNAL_FUNCTION_PARAMETERS); extern void php3_eregreplace(INTERNAL_FUNCTION_PARAMETERS); extern void php3_split(INTERNAL_FUNCTION_PARAMETERS); extern PHPAPI void php3_sql_regcase(INTERNAL_FUNCTION_PARAMETERS); #endif /* _REG_H */ http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/php_regex.h?view=markup&rev=1.1 Index: php-src/ext/ereg/php_regex.h +++ php-src/ext/ereg/php_regex.h #ifndef _PHP_REGEX_H #define _PHP_REGEX_H #if REGEX #include "regex/regex.h" #define _REGEX_H 1 /* this should stop Apache from loading the system version of regex.h */ #define _RX_H 1 /* Try defining these for Linux to */ #define __REGEXP_LIBRARY_H__ 1 /* avoid Apache including regex.h */ #define _H_REGEX 1 /* This one is for AIX */ #else #include <regex.h> #endif #endif /* _PHP_REGEX_H */ http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/.cvsignore?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/.cvsignore +++ php-src/ext/ereg/regex/.cvsignore Makefile http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/cclass.h?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/cclass.h +++ php-src/ext/ereg/regex/cclass.h /* character-class table */ static struct cclass { char *name; char *chars; char *multis; } cclasses[] = { { "alnum", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\ 0123456789", "" }, { "alpha", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", "" }, { "blank", " \t", "" }, { "cntrl", "\007\b\t\n\v\f\r\1\2\3\4\5\6\16\17\20\21\22\23\24\ \25\26\27\30\31\32\33\34\35\36\37\177", "" }, { "digit", "0123456789", "" }, { "graph", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\ 0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", "" }, { "lower", "abcdefghijklmnopqrstuvwxyz", "" }, { "print", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\ 0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ ", "" }, { "punct", "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", "" }, { "space", "\t\n\v\f\r ", "" }, { "upper", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "" }, { "xdigit", "0123456789ABCDEFabcdef", "" }, { NULL, 0, "" } }; http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/cname.h?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/cname.h +++ php-src/ext/ereg/regex/cname.h /* character-name table */ static struct cname { char *name; char code; } cnames[] = { { "NUL", '\0' }, { "SOH", '\001' }, { "STX", '\002' }, { "ETX", '\003' }, { "EOT", '\004' }, { "ENQ", '\005' }, { "ACK", '\006' }, { "BEL", '\007' }, { "alert", '\007' }, { "BS", '\010' }, { "backspace", '\b' }, { "HT", '\011' }, { "tab", '\t' }, { "LF", '\012' }, { "newline", '\n' }, { "VT", '\013' }, { "vertical-tab", '\v' }, { "FF", '\014' }, { "form-feed", '\f' }, { "CR", '\015' }, { "carriage-return", '\r' }, { "SO", '\016' }, { "SI", '\017' }, { "DLE", '\020' }, { "DC1", '\021' }, { "DC2", '\022' }, { "DC3", '\023' }, { "DC4", '\024' }, { "NAK", '\025' }, { "SYN", '\026' }, { "ETB", '\027' }, { "CAN", '\030' }, { "EM", '\031' }, { "SUB", '\032' }, { "ESC", '\033' }, { "IS4", '\034' }, { "FS", '\034' }, { "IS3", '\035' }, { "GS", '\035' }, { "IS2", '\036' }, { "RS", '\036' }, { "IS1", '\037' }, { "US", '\037' }, { "space", ' ' }, { "exclamation-mark", '!' }, { "quotation-mark", '"' }, { "number-sign", '#' }, { "dollar-sign", '$' }, { "percent-sign", '%' }, { "ampersand", '&' }, { "apostrophe", '\'' }, { "left-parenthesis", '(' }, { "right-parenthesis", ')' }, { "asterisk", '*' }, { "plus-sign", '+' }, { "comma", ',' }, { "hyphen", '-' }, { "hyphen-minus", '-' }, { "period", '.' }, { "full-stop", '.' }, { "slash", '/' }, { "solidus", '/' }, { "zero", '0' }, { "one", '1' }, { "two", '2' }, { "three", '3' }, { "four", '4' }, { "five", '5' }, { "six", '6' }, { "seven", '7' }, { "eight", '8' }, { "nine", '9' }, { "colon", ':' }, { "semicolon", ';' }, { "less-than-sign", '<' }, { "equals-sign", '=' }, { "greater-than-sign", '>' }, { "question-mark", '?' }, { "commercial-at", '@' }, { "left-square-bracket", '[' }, { "backslash", '\\' }, { "reverse-solidus", '\\' }, { "right-square-bracket", ']' }, { "circumflex", '^' }, { "circumflex-accent", '^' }, { "underscore", '_' }, { "low-line", '_' }, { "grave-accent", '`' }, { "left-brace", '{' }, { "left-curly-bracket", '{' }, { "vertical-line", '|' }, { "right-brace", '}' }, { "right-curly-bracket", '}' }, { "tilde", '~' }, { "DEL", '\177' }, { NULL, 0 } }; http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/debug.c?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/debug.c +++ php-src/ext/ereg/regex/debug.c #include <stdio.h> #include <string.h> #include <ctype.h> #include <limits.h> #include <stdlib.h> #include <sys/types.h> #include <regex.h> #include "utils.h" #include "regex2.h" #include "debug.ih" /* - regprint - print a regexp for debugging == void regprint(regex_t *r, FILE *d); */ void regprint(r, d) regex_t *r; FILE *d; { register struct re_guts *g = r->re_g; register int i; register int c; register int last; int nincat[NC]; fprintf(d, "%ld states, %d categories", (long)g->nstates, g->ncategories); fprintf(d, ", first %ld last %ld", (long)g->firststate, (long)g->laststate); if (g->iflags&USEBOL) fprintf(d, ", USEBOL"); if (g->iflags&USEEOL) fprintf(d, ", USEEOL"); if (g->iflags&BAD) fprintf(d, ", BAD"); if (g->nsub > 0) fprintf(d, ", nsub=%ld", (long)g->nsub); if (g->must != NULL) fprintf(d, ", must(%ld) `%*s'", (long)g->mlen, (int)g->mlen, g->must); if (g->backrefs) fprintf(d, ", backrefs"); if (g->nplus > 0) fprintf(d, ", nplus %ld", (long)g->nplus); fprintf(d, "\n"); s_print(g, d); for (i = 0; i < g->ncategories; i++) { nincat[i] = 0; for (c = CHAR_MIN; c <= CHAR_MAX; c++) if (g->categories[c] == i) nincat[i]++; } fprintf(d, "cc0#%d", nincat[0]); for (i = 1; i < g->ncategories; i++) if (nincat[i] == 1) { for (c = CHAR_MIN; c <= CHAR_MAX; c++) if (g->categories[c] == i) break; fprintf(d, ", %d=%s", i, regchar(c)); } fprintf(d, "\n"); for (i = 1; i < g->ncategories; i++) if (nincat[i] != 1) { fprintf(d, "cc%d\t", i); last = -1; for (c = CHAR_MIN; c <= CHAR_MAX+1; c++) /* +1 does flush */ if (c <= CHAR_MAX && g->categories[c] == i) { if (last < 0) { fprintf(d, "%s", regchar(c)); last = c; } } else { if (last >= 0) { if (last != c-1) fprintf(d, "-%s", regchar(c-1)); last = -1; } } fprintf(d, "\n"); } } /* - s_print - print the strip for debugging == static void s_print(register struct re_guts *g, FILE *d); */ static void s_print(g, d) register struct re_guts *g; FILE *d; { register sop *s; register cset *cs; register int i; register int done = 0; register sop opnd; register int col = 0; register int last; register sopno offset = 2; # define GAP() { if (offset % 5 == 0) { \ if (col > 40) { \ fprintf(d, "\n\t"); \ col = 0; \ } else { \ fprintf(d, " "); \ col++; \ } \ } else \ col++; \ offset++; \ } if (OP(g->strip[0]) != OEND) fprintf(d, "missing initial OEND!\n"); for (s = &g->strip[1]; !done; s++) { opnd = OPND(*s); switch (OP(*s)) { case OEND: fprintf(d, "\n"); done = 1; break; case OCHAR: if (strchr("\\|()^$.[+*?{}!<> ", (char)opnd) != NULL) fprintf(d, "\\%c", (char)opnd); else fprintf(d, "%s", regchar((char)opnd)); break; case OBOL: fprintf(d, "^"); break; case OEOL: fprintf(d, "$"); break; case OBOW: fprintf(d, "\\{"); break; case OEOW: fprintf(d, "\\}"); break; case OANY: fprintf(d, "."); break; case OANYOF: fprintf(d, "[(%ld)", (long)opnd); cs = &g->sets[opnd]; last = -1; for (i = 0; i < g->csetsize+1; i++) /* +1 flushes */ if (CHIN(cs, i) && i < g->csetsize) { if (last < 0) { fprintf(d, "%s", regchar(i)); last = i; } } else { if (last >= 0) { if (last != i-1) fprintf(d, "-%s", regchar(i-1)); last = -1; } } fprintf(d, "]"); break; case OBACK_: fprintf(d, "(\\<%ld>", (long)opnd); break; case O_BACK: fprintf(d, "<%ld>\\)", (long)opnd); break; case OPLUS_: fprintf(d, "(+"); if (OP(*(s+opnd)) != O_PLUS) fprintf(d, "<%ld>", (long)opnd); break; case O_PLUS: if (OP(*(s-opnd)) != OPLUS_) fprintf(d, "<%ld>", (long)opnd); fprintf(d, "+)"); break; case OQUEST_: fprintf(d, "(?"); if (OP(*(s+opnd)) != O_QUEST) fprintf(d, "<%ld>", (long)opnd); break; case O_QUEST: if (OP(*(s-opnd)) != OQUEST_) fprintf(d, "<%ld>", (long)opnd); fprintf(d, "?)"); break; case OLPAREN: fprintf(d, "((<%ld>", (long)opnd); break; case ORPAREN: fprintf(d, "<%ld>))", (long)opnd); break; case OCH_: fprintf(d, "<"); if (OP(*(s+opnd)) != OOR2) fprintf(d, "<%ld>", (long)opnd); break; case OOR1: if (OP(*(s-opnd)) != OOR1 && OP(*(s-opnd)) != OCH_) fprintf(d, "<%ld>", (long)opnd); fprintf(d, "|"); break; case OOR2: fprintf(d, "|"); if (OP(*(s+opnd)) != OOR2 && OP(*(s+opnd)) != O_CH) fprintf(d, "<%ld>", (long)opnd); break; case O_CH: if (OP(*(s-opnd)) != OOR1) fprintf(d, "<%ld>", (long)opnd); fprintf(d, ">"); break; default: fprintf(d, "!%ld(%ld)!", OP(*s), opnd); break; } if (!done) GAP(); } } /* - regchar - make a character printable == static char *regchar(int ch); */ static char * /* -> representation */ regchar(ch) int ch; { static char buf[10]; if (isprint(ch) || ch == ' ') sprintf(buf, "%c", ch); else sprintf(buf, "\\%o", ch); return(buf); } http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/debug.ih?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/debug.ih +++ php-src/ext/ereg/regex/debug.ih /* ========= begin header generated by ./mkh ========= */ #ifdef __cplusplus extern "C" { #endif /* === debug.c === */ void regprint(regex_t *r, FILE *d); static void s_print(register struct re_guts *g, FILE *d); static char *regchar(int ch); #ifdef __cplusplus } #endif /* ========= end header generated by ./mkh ========= */ http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/engine.c?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/engine.c +++ php-src/ext/ereg/regex/engine.c /* * The matching engine and friends. This file is #included by regexec.c * after suitable #defines of a variety of macros used herein, so that * different state representations can be used without duplicating masses * of code. */ #ifdef SNAMES #define matcher smatcher #define fast sfast #define slow sslow #define dissect sdissect #define backref sbackref #define step sstep #define print sprint #define at sat #define match smat #endif #ifdef LNAMES #define matcher lmatcher #define fast lfast #define slow lslow #define dissect ldissect #define backref lbackref #define step lstep #define print lprint #define at lat #define match lmat #endif /* another structure passed up and down to avoid zillions of parameters */ struct match { struct re_guts *g; int eflags; regmatch_t *pmatch; /* [nsub+1] (0 element unused) */ char *offp; /* offsets work from here */ char *beginp; /* start of string -- virtual NUL precedes */ char *endp; /* end of string -- virtual NUL here */ char *coldp; /* can be no match starting before here */ char **lastpos; /* [nplus+1] */ STATEVARS; states st; /* current states */ states fresh; /* states for a fresh start */ states tmp; /* temporary */ states empty; /* empty set of states */ }; #include "engine.ih" #ifdef REDEBUG #define SP(t, s, c) print(m, t, s, c, stdout) #define AT(t, p1, p2, s1, s2) at(m, t, p1, p2, s1, s2) #define NOTE(str) { if (m->eflags®_TRACE) printf("=%s\n", (str)); } #else #define SP(t, s, c) /* nothing */ #define AT(t, p1, p2, s1, s2) /* nothing */ #define NOTE(s) /* nothing */ #endif /* - matcher - the actual matching engine == static int matcher(register struct re_guts *g, char *string, \ == size_t nmatch, regmatch_t pmatch[], int eflags); */ static int /* 0 success, REG_NOMATCH failure */ matcher(g, string, nmatch, pmatch, eflags) register struct re_guts *g; char *string; size_t nmatch; regmatch_t pmatch[]; int eflags; { register char *endp; register unsigned int i; struct match mv; register struct match *m = &mv; register char *dp; register const sopno gf = g->firststate+1; /* +1 for OEND */ register const sopno gl = g->laststate; char *start; char *stop; /* simplify the situation where possible */ if (g->cflags®_NOSUB) nmatch = 0; if (eflags®_STARTEND) { start = string + pmatch[0].rm_so; stop = string + pmatch[0].rm_eo; } else { start = string; stop = start + strlen(start); } if (stop < start) return(REG_INVARG); /* prescreening; this does wonders for this rather slow code */ if (g->must != NULL) { for (dp = start; dp < stop; dp++) if (*dp == g->must[0] && stop - dp >= g->mlen && memcmp(dp, g->must, (size_t)g->mlen) == 0) break; if (dp == stop) /* we didn't find g->must */ return(REG_NOMATCH); } /* match struct setup */ m->g = g; m->eflags = eflags; m->pmatch = NULL; m->lastpos = NULL; m->offp = string; m->beginp = start; m->endp = stop; STATESETUP(m, 4); SETUP(m->st); SETUP(m->fresh); SETUP(m->tmp); SETUP(m->empty); CLEAR(m->empty); /* this loop does only one repetition except for backrefs */ for (;;) { endp = fast(m, start, stop, gf, gl); if (endp == NULL) { /* a miss */ STATETEARDOWN(m); return(REG_NOMATCH); } if (nmatch == 0 && !g->backrefs) break; /* no further info needed */ /* where? */ assert(m->coldp != NULL); for (;;) { NOTE("finding start"); endp = slow(m, m->coldp, stop, gf, gl); if (endp != NULL) break; assert(m->coldp < m->endp); m->coldp++; } if (nmatch == 1 && !g->backrefs) break; /* no further info needed */ /* oh my, he wants the subexpressions... */ if (m->pmatch == NULL) m->pmatch = (regmatch_t *)malloc((m->g->nsub + 1) * sizeof(regmatch_t)); if (m->pmatch == NULL) { STATETEARDOWN(m); return(REG_ESPACE); } for (i = 1; i <= m->g->nsub; i++) m->pmatch[i].rm_so = m->pmatch[i].rm_eo = -1; if (!g->backrefs && !(m->eflags®_BACKR)) { NOTE("dissecting"); dp = dissect(m, m->coldp, endp, gf, gl); } else { if (g->nplus > 0 && m->lastpos == NULL) m->lastpos = (char **)malloc((g->nplus+1) * sizeof(char *)); if (g->nplus > 0 && m->lastpos == NULL) { free(m->pmatch); STATETEARDOWN(m); return(REG_ESPACE); } NOTE("backref dissect"); dp = backref(m, m->coldp, endp, gf, gl, (sopno)0); } if (dp != NULL) break; /* uh-oh... we couldn't find a subexpression-level match */ assert(g->backrefs); /* must be back references doing it */ assert(g->nplus == 0 || m->lastpos != NULL); for (;;) { if (dp != NULL || endp <= m->coldp) break; /* defeat */ NOTE("backoff"); endp = slow(m, m->coldp, endp-1, gf, gl); if (endp == NULL) break; /* defeat */ /* try it on a shorter possibility */ #ifndef NDEBUG for (i = 1; i <= m->g->nsub; i++) { assert(m->pmatch[i].rm_so == -1); assert(m->pmatch[i].rm_eo == -1); } #endif NOTE("backoff dissect"); dp = backref(m, m->coldp, endp, gf, gl, (sopno)0); } assert(dp == NULL || dp == endp); if (dp != NULL) /* found a shorter one */ break; /* despite initial appearances, there is no match here */ NOTE("false alarm"); start = m->coldp + 1; /* recycle starting later */ assert(start <= stop); } /* fill in the details if requested */ if (nmatch > 0) { pmatch[0].rm_so = m->coldp - m->offp; pmatch[0].rm_eo = endp - m->offp; } if (nmatch > 1) { assert(m->pmatch != NULL); for (i = 1; i < nmatch; i++) if (i <= m->g->nsub) pmatch[i] = m->pmatch[i]; else { pmatch[i].rm_so = -1; pmatch[i].rm_eo = -1; } } if (m->pmatch != NULL) free((char *)m->pmatch); if (m->lastpos != NULL) free((char *)m->lastpos); STATETEARDOWN(m); return(0); } /* - dissect - figure out what matched what, no back references == static char *dissect(register struct match *m, char *start, \ == char *stop, sopno startst, sopno stopst); */ static char * /* == stop (success) always */ dissect(m, start, stop, startst, stopst) register struct match *m; char *start; char *stop; sopno startst; sopno stopst; { register int i; register sopno ss; /* start sop of current subRE */ register sopno es; /* end sop of current subRE */ register char *sp; /* start of string matched by it */ register char *stp; /* string matched by it cannot pass here */ register char *rest; /* start of rest of string */ register char *tail; /* string unmatched by rest of RE */ register sopno ssub; /* start sop of subsubRE */ register sopno esub; /* end sop of subsubRE */ register char *ssp; /* start of string matched by subsubRE */ register char *sep; /* end of string matched by subsubRE */ register char *oldssp; /* previous ssp */ register char *dp; AT("diss", start, stop, startst, stopst); sp = start; for (ss = startst; ss < stopst; ss = es) { /* identify end of subRE */ es = ss; switch (OP(m->g->strip[es])) { case OPLUS_: case OQUEST_: es += OPND(m->g->strip[es]); break; case OCH_: while (OP(m->g->strip[es]) != O_CH) es += OPND(m->g->strip[es]); break; } es++; /* figure out what it matched */ switch (OP(m->g->strip[ss])) { case OEND: assert(nope); break; case OCHAR: sp++; break; case OBOL: case OEOL: case OBOW: case OEOW: break; case OANY: case OANYOF: sp++; break; case OBACK_: case O_BACK: assert(nope); break; /* cases where length of match is hard to find */ case OQUEST_: stp = stop; for (;;) { /* how long could this one be? */ rest = slow(m, sp, stp, ss, es); assert(rest != NULL); /* it did match */ /* could the rest match the rest? */ tail = slow(m, rest, stop, es, stopst); if (tail == stop) break; /* yes! */ /* no -- try a shorter match for this one */ stp = rest - 1; assert(stp >= sp); /* it did work */ } ssub = ss + 1; esub = es - 1; /* did innards match? */ if (slow(m, sp, rest, ssub, esub) != NULL) { dp = dissect(m, sp, rest, ssub, esub); assert(dp == rest); } else /* no */ assert(sp == rest); sp = rest; break; case OPLUS_: stp = stop; for (;;) { /* how long could this one be? */ rest = slow(m, sp, stp, ss, es); assert(rest != NULL); /* it did match */ /* could the rest match the rest? */ tail = slow(m, rest, stop, es, stopst); if (tail == stop) break; /* yes! */ /* no -- try a shorter match for this one */ stp = rest - 1; assert(stp >= sp); /* it did work */ } ssub = ss + 1; esub = es - 1; ssp = sp; oldssp = ssp; for (;;) { /* find last match of innards */ sep = slow(m, ssp, rest, ssub, esub); if (sep == NULL || sep == ssp) break; /* failed or matched null */ oldssp = ssp; /* on to next try */ ssp = sep; } if (sep == NULL) { /* last successful match */ sep = ssp; ssp = oldssp; } assert(sep == rest); /* must exhaust substring */ assert(slow(m, ssp, sep, ssub, esub) == rest); dp = dissect(m, ssp, sep, ssub, esub); assert(dp == sep); sp = rest; break; case OCH_: stp = stop; for (;;) { /* how long could this one be? */ rest = slow(m, sp, stp, ss, es); assert(rest != NULL); /* it did match */ /* could the rest match the rest? */ tail = slow(m, rest, stop, es, stopst); if (tail == stop) break; /* yes! */ /* no -- try a shorter match for this one */ stp = rest - 1; assert(stp >= sp); /* it did work */ } ssub = ss + 1; esub = ss + OPND(m->g->strip[ss]) - 1; assert(OP(m->g->strip[esub]) == OOR1); for (;;) { /* find first matching branch */ if (slow(m, sp, rest, ssub, esub) == rest) break; /* it matched all of it */ /* that one missed, try next one */ assert(OP(m->g->strip[esub]) == OOR1); esub++; assert(OP(m->g->strip[esub]) == OOR2); ssub = esub + 1; esub += OPND(m->g->strip[esub]); if (OP(m->g->strip[esub]) == OOR2) esub--; else assert(OP(m->g->strip[esub]) == O_CH); } dp = dissect(m, sp, rest, ssub, esub); assert(dp == rest); sp = rest; break; case O_PLUS: case O_QUEST: case OOR1: case OOR2: case O_CH: assert(nope); break; case OLPAREN: i = OPND(m->g->strip[ss]); assert(0 < i && i <= m->g->nsub); m->pmatch[i].rm_so = sp - m->offp; break; case ORPAREN: i = OPND(m->g->strip[ss]); assert(0 < i && i <= m->g->nsub); m->pmatch[i].rm_eo = sp - m->offp; break; default: /* uh oh */ assert(nope); break; } } assert(sp == stop); return(sp); } /* - backref - figure out what matched what, figuring in back references == static char *backref(register struct match *m, char *start, \ == char *stop, sopno startst, sopno stopst, sopno lev); */ static char * /* == stop (success) or NULL (failure) */ backref(m, start, stop, startst, stopst, lev) register struct match *m; char *start; char *stop; sopno startst; sopno stopst; sopno lev; /* PLUS nesting level */ { register int i; register sopno ss; /* start sop of current subRE */ register char *sp; /* start of string matched by it */ register sopno ssub; /* start sop of subsubRE */ register sopno esub; /* end sop of subsubRE */ register char *ssp; /* start of string matched by subsubRE */ register char *dp; register size_t len; register int hard; register sop s; register regoff_t offsave; register cset *cs; AT("back", start, stop, startst, stopst); sp = start; /* get as far as we can with easy stuff */ hard = 0; for (ss = startst; !hard && ss < stopst; ss++) switch (OP(s = m->g->strip[ss])) { case OCHAR: if (sp == stop || *sp++ != (char)OPND(s)) return(NULL); break; case OANY: if (sp == stop) return(NULL); sp++; break; case OANYOF: cs = &m->g->sets[OPND(s)]; if (sp == stop || !CHIN(cs, *sp++)) return(NULL); break; case OBOL: if ( (sp == m->beginp && !(m->eflags®_NOTBOL)) || (sp < m->endp && *(sp-1) == '\n' && (m->g->cflags®_NEWLINE)) ) { /* yes */ } else return(NULL); break; case OEOL: if ( (sp == m->endp && !(m->eflags®_NOTEOL)) || (sp < m->endp && *sp == '\n' && (m->g->cflags®_NEWLINE)) ) { /* yes */ } else return(NULL); break; case OBOW: if (( (sp == m->beginp && !(m->eflags®_NOTBOL)) || (sp < m->endp && *(sp-1) == '\n' && (m->g->cflags®_NEWLINE)) || (sp > m->beginp && !ISWORD(*(sp-1))) ) && (sp < m->endp && ISWORD(*sp)) ) { /* yes */ } else return(NULL); break; case OEOW: if (( (sp == m->endp && !(m->eflags®_NOTEOL)) || (sp < m->endp && *sp == '\n' && (m->g->cflags®_NEWLINE)) || (sp < m->endp && !ISWORD(*sp)) ) && (sp > m->beginp && ISWORD(*(sp-1))) ) { /* yes */ } else return(NULL); break; case O_QUEST: break; case OOR1: /* matches null but needs to skip */ ss++; s = m->g->strip[ss]; do { assert(OP(s) == OOR2); ss += OPND(s); } while (OP(s = m->g->strip[ss]) != O_CH); /* note that the ss++ gets us past the O_CH */ break; default: /* have to make a choice */ hard = 1; break; } if (!hard) { /* that was it! */ if (sp != stop) return(NULL); return(sp); } ss--; /* adjust for the for's final increment */ /* the hard stuff */ AT("hard", sp, stop, ss, stopst); s = m->g->strip[ss]; switch (OP(s)) { case OBACK_: /* the vilest depths */ i = OPND(s); assert(0 < i && i <= m->g->nsub); if (m->pmatch[i].rm_eo == -1) return(NULL); assert(m->pmatch[i].rm_so != -1); len = m->pmatch[i].rm_eo - m->pmatch[i].rm_so; assert(stop - m->beginp >= len); if (sp > stop - len) return(NULL); /* not enough left to match */ ssp = m->offp + m->pmatch[i].rm_so; if (memcmp(sp, ssp, len) != 0) return(NULL); while (m->g->strip[ss] != SOP(O_BACK, i)) ss++; return(backref(m, sp+len, stop, ss+1, stopst, lev)); break; case OQUEST_: /* to null or not */ dp = backref(m, sp, stop, ss+1, stopst, lev); if (dp != NULL) return(dp); /* not */ return(backref(m, sp, stop, ss+OPND(s)+1, stopst, lev)); break; case OPLUS_: assert(m->lastpos != NULL); assert(lev+1 <= m->g->nplus); m->lastpos[lev+1] = sp; return(backref(m, sp, stop, ss+1, stopst, lev+1)); break; case O_PLUS: if (sp == m->lastpos[lev]) /* last pass matched null */ return(backref(m, sp, stop, ss+1, stopst, lev-1)); /* try another pass */ m->lastpos[lev] = sp; dp = backref(m, sp, stop, ss-OPND(s)+1, stopst, lev); if (dp == NULL) return(backref(m, sp, stop, ss+1, stopst, lev-1)); else return(dp); break; case OCH_: /* find the right one, if any */ ssub = ss + 1; esub = ss + OPND(s) - 1; assert(OP(m->g->strip[esub]) == OOR1); for (;;) { /* find first matching branch */ dp = backref(m, sp, stop, ssub, esub, lev); if (dp != NULL) return(dp); /* that one missed, try next one */ if (OP(m->g->strip[esub]) == O_CH) return(NULL); /* there is none */ esub++; assert(OP(m->g->strip[esub]) == OOR2); ssub = esub + 1; esub += OPND(m->g->strip[esub]); if (OP(m->g->strip[esub]) == OOR2) esub--; else assert(OP(m->g->strip[esub]) == O_CH); } break; case OLPAREN: /* must undo assignment if rest fails */ i = OPND(s); assert(0 < i && i <= m->g->nsub); offsave = m->pmatch[i].rm_so; m->pmatch[i].rm_so = sp - m->offp; dp = backref(m, sp, stop, ss+1, stopst, lev); if (dp != NULL) return(dp); m->pmatch[i].rm_so = offsave; return(NULL); break; case ORPAREN: /* must undo assignment if rest fails */ i = OPND(s); assert(0 < i && i <= m->g->nsub); offsave = m->pmatch[i].rm_eo; m->pmatch[i].rm_eo = sp - m->offp; dp = backref(m, sp, stop, ss+1, stopst, lev); if (dp != NULL) return(dp); m->pmatch[i].rm_eo = offsave; return(NULL); break; default: /* uh oh */ assert(nope); break; } /* "can't happen" */ assert(nope); /* NOTREACHED */ return( NULL ); } /* - fast - step through the string at top speed == static char *fast(register struct match *m, char *start, \ == char *stop, sopno startst, sopno stopst); */ static char * /* where tentative match ended, or NULL */ fast(m, start, stop, startst, stopst) register struct match *m; char *start; char *stop; sopno startst; sopno stopst; { register states st = m->st; register states fresh = m->fresh; register states tmp = m->tmp; register char *p = start; register int c = (start == m->beginp) ? OUT : *(start-1); register int lastc; /* previous c */ register int flagch; register int i; register char *coldp; /* last p after which no match was underway */ CLEAR(st); SET1(st, startst); st = step(m->g, startst, stopst, st, NOTHING, st); ASSIGN(fresh, st); SP("start", st, *p); coldp = NULL; for (;;) { /* next character */ lastc = c; c = (p == m->endp) ? OUT : *p; if (EQ(st, fresh)) coldp = p; /* is there an EOL and/or BOL between lastc and c? */ flagch = '\0'; i = 0; if ( (lastc == '\n' && m->g->cflags®_NEWLINE) || (lastc == OUT && !(m->eflags®_NOTBOL)) ) { flagch = BOL; i = m->g->nbol; } if ( (c == '\n' && m->g->cflags®_NEWLINE) || (c == OUT && !(m->eflags®_NOTEOL)) ) { flagch = (flagch == BOL) ? BOLEOL : EOL; i += m->g->neol; } if (i != 0) { for (; i > 0; i--) st = step(m->g, startst, stopst, st, flagch, st); SP("boleol", st, c); } /* how about a word boundary? */ if ( (flagch == BOL || (lastc != OUT && !ISWORD(lastc))) && (c != OUT && ISWORD(c)) ) { flagch = BOW; } if ( (lastc != OUT && ISWORD(lastc)) && (flagch == EOL || (c != OUT && !ISWORD(c))) ) { flagch = EOW; } if (flagch == BOW || flagch == EOW) { st = step(m->g, startst, stopst, st, flagch, st); SP("boweow", st, c); } /* are we done? */ if (ISSET(st, stopst) || p == stop) break; /* NOTE BREAK OUT */ /* no, we must deal with this character */ ASSIGN(tmp, st); ASSIGN(st, fresh); assert(c != OUT); st = step(m->g, startst, stopst, tmp, c, st); SP("aft", st, c); assert(EQ(step(m->g, startst, stopst, st, NOTHING, st), st)); p++; } assert(coldp != NULL); m->coldp = coldp; if (ISSET(st, stopst)) return(p+1); else return(NULL); } /* - slow - step through the string more deliberately == static char *slow(register struct match *m, char *start, \ == char *stop, sopno startst, sopno stopst); */ static char * /* where it ended */ slow(m, start, stop, startst, stopst) register struct match *m; char *start; char *stop; sopno startst; sopno stopst; { register states st = m->st; register states empty = m->empty; register states tmp = m->tmp; register char *p = start; register int c = (start == m->beginp) ? OUT : *(start-1); register int lastc; /* previous c */ register int flagch; register int i; register char *matchp; /* last p at which a match ended */ AT("slow", start, stop, startst, stopst); CLEAR(st); SET1(st, startst); SP("sstart", st, *p); st = step(m->g, startst, stopst, st, NOTHING, st); matchp = NULL; for (;;) { /* next character */ lastc = c; c = (p == m->endp) ? OUT : *p; /* is there an EOL and/or BOL between lastc and c? */ flagch = '\0'; i = 0; if ( (lastc == '\n' && m->g->cflags®_NEWLINE) || (lastc == OUT && !(m->eflags®_NOTBOL)) ) { flagch = BOL; i = m->g->nbol; } if ( (c == '\n' && m->g->cflags®_NEWLINE) || (c == OUT && !(m->eflags®_NOTEOL)) ) { flagch = (flagch == BOL) ? BOLEOL : EOL; i += m->g->neol; } if (i != 0) { for (; i > 0; i--) st = step(m->g, startst, stopst, st, flagch, st); SP("sboleol", st, c); } /* how about a word boundary? */ if ( (flagch == BOL || (lastc != OUT && !ISWORD(lastc))) && (c != OUT && ISWORD(c)) ) { flagch = BOW; } if ( (lastc != OUT && ISWORD(lastc)) && (flagch == EOL || (c != OUT && !ISWORD(c))) ) { flagch = EOW; } if (flagch == BOW || flagch == EOW) { st = step(m->g, startst, stopst, st, flagch, st); SP("sboweow", st, c); } /* are we done? */ if (ISSET(st, stopst)) matchp = p; if (EQ(st, empty) || p == stop) break; /* NOTE BREAK OUT */ /* no, we must deal with this character */ ASSIGN(tmp, st); ASSIGN(st, empty); assert(c != OUT); st = step(m->g, startst, stopst, tmp, c, st); SP("saft", st, c); assert(EQ(step(m->g, startst, stopst, st, NOTHING, st), st)); p++; } return(matchp); } /* - step - map set of states reachable before char to set reachable after == static states step(register struct re_guts *g, sopno start, sopno stop, \ == register states bef, int ch, register states aft); == #define BOL (OUT+1) == #define EOL (BOL+1) == #define BOLEOL (BOL+2) == #define NOTHING (BOL+3) == #define BOW (BOL+4) == #define EOW (BOL+5) == #define CODEMAX (BOL+5) // highest code used == #define NONCHAR(c) ((c) > CHAR_MAX) == #define NNONCHAR (CODEMAX-CHAR_MAX) */ static states step(g, start, stop, bef, ch, aft) register struct re_guts *g; sopno start; /* start state within strip */ sopno stop; /* state after stop state within strip */ register states bef; /* states reachable before */ int ch; /* character or NONCHAR code */ register states aft; /* states already known reachable after */ { register cset *cs; register sop s; register sopno pc; register onestate here; /* note, macros know this name */ register sopno look; register int i; for (pc = start, INIT(here, pc); pc != stop; pc++, INC(here)) { s = g->strip[pc]; switch (OP(s)) { case OEND: assert(pc == stop-1); break; case OCHAR: /* only characters can match */ assert(!NONCHAR(ch) || ch != (char)OPND(s)); if (ch == (char)OPND(s)) FWD(aft, bef, 1); break; case OBOL: if (ch == BOL || ch == BOLEOL) FWD(aft, bef, 1); break; case OEOL: if (ch == EOL || ch == BOLEOL) FWD(aft, bef, 1); break; case OBOW: if (ch == BOW) FWD(aft, bef, 1); break; case OEOW: if (ch == EOW) FWD(aft, bef, 1); break; case OANY: if (!NONCHAR(ch)) FWD(aft, bef, 1); break; case OANYOF: cs = &g->sets[OPND(s)]; if (!NONCHAR(ch) && CHIN(cs, ch)) FWD(aft, bef, 1); break; case OBACK_: /* ignored here */ case O_BACK: FWD(aft, aft, 1); break; case OPLUS_: /* forward, this is just an empty */ FWD(aft, aft, 1); break; case O_PLUS: /* both forward and back */ FWD(aft, aft, 1); i = ISSETBACK(aft, OPND(s)); BACK(aft, aft, OPND(s)); if (!i && ISSETBACK(aft, OPND(s))) { /* oho, must reconsider loop body */ pc -= OPND(s) + 1; INIT(here, pc); } break; case OQUEST_: /* two branches, both forward */ FWD(aft, aft, 1); FWD(aft, aft, OPND(s)); break; case O_QUEST: /* just an empty */ FWD(aft, aft, 1); break; case OLPAREN: /* not significant here */ case ORPAREN: FWD(aft, aft, 1); break; case OCH_: /* mark the first two branches */ FWD(aft, aft, 1); assert(OP(g->strip[pc+OPND(s)]) == OOR2); FWD(aft, aft, OPND(s)); break; case OOR1: /* done a branch, find the O_CH */ if (ISSTATEIN(aft, here)) { for (look = 1; OP(s = g->strip[pc+look]) != O_CH; look += OPND(s)) assert(OP(s) == OOR2); FWD(aft, aft, look); } break; case OOR2: /* propagate OCH_'s marking */ FWD(aft, aft, 1); if (OP(g->strip[pc+OPND(s)]) != O_CH) { assert(OP(g->strip[pc+OPND(s)]) == OOR2); FWD(aft, aft, OPND(s)); } break; case O_CH: /* just empty */ FWD(aft, aft, 1); break; default: /* ooooops... */ assert(nope); break; } } return(aft); } #ifdef REDEBUG /* - print - print a set of states == #ifdef REDEBUG == static void print(struct match *m, char *caption, states st, \ == int ch, FILE *d); == #endif */ static void print(m, caption, st, ch, d) struct match *m; char *caption; states st; int ch; FILE *d; { register struct re_guts *g = m->g; register int i; register int first = 1; if (!(m->eflags®_TRACE)) return; fprintf(d, "%s", caption); if (ch != '\0') fprintf(d, " %s", pchar(ch)); for (i = 0; i < g->nstates; i++) if (ISSET(st, i)) { fprintf(d, "%s%d", (first) ? "\t" : ", ", i); first = 0; } fprintf(d, "\n"); } /* - at - print current situation == #ifdef REDEBUG == static void at(struct match *m, char *title, char *start, char *stop, \ == sopno startst, sopno stopst); == #endif */ static void at(m, title, start, stop, startst, stopst) struct match *m; char *title; char *start; char *stop; sopno startst; sopno stopst; { if (!(m->eflags®_TRACE)) return; printf("%s %s-", title, pchar(*start)); printf("%s ", pchar(*stop)); printf("%ld-%ld\n", (long)startst, (long)stopst); } #ifndef PCHARDONE #define PCHARDONE /* never again */ /* - pchar - make a character printable == #ifdef REDEBUG == static char *pchar(int ch); == #endif * * Is this identical to regchar() over in debug.c? Well, yes. But a * duplicate here avoids having a debugging-capable regexec.o tied to * a matching debug.o, and this is convenient. It all disappears in * the non-debug compilation anyway, so it doesn't matter much. */ static char * /* -> representation */ pchar(ch) int ch; { static char pbuf[10]; if (isprint(ch) || ch == ' ') sprintf(pbuf, "%c", ch); else sprintf(pbuf, "\\%o", ch); return(pbuf); } #endif #endif #undef matcher #undef fast #undef slow #undef dissect #undef backref #undef step #undef print #undef at #undef match http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/engine.ih?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/engine.ih +++ php-src/ext/ereg/regex/engine.ih /* ========= begin header generated by ../../regex/mkh ========= */ #ifdef __cplusplus extern "C" { #endif /* === ../../regex/engine.c === */ static int matcher(register struct re_guts *g, char *string, size_t nmatch, regmatch_t pmatch[], int eflags); static char *dissect(register struct match *m, char *start, char *stop, sopno startst, sopno stopst); static char *backref(register struct match *m, char *start, char *stop, sopno startst, sopno stopst, sopno lev); static char *fast(register struct match *m, char *start, char *stop, sopno startst, sopno stopst); static char *slow(register struct match *m, char *start, char *stop, sopno startst, sopno stopst); static states step(register struct re_guts *g, sopno start, sopno stop, register states bef, int ch, register states aft); #define BOL (OUT+1) #define EOL (BOL+1) #define BOLEOL (BOL+2) #define NOTHING (BOL+3) #define BOW (BOL+4) #define EOW (BOL+5) #define CODEMAX (BOL+5) /* highest code used */ #define NONCHAR(c) ((c) > CHAR_MAX) #define NNONCHAR (CODEMAX-CHAR_MAX) #ifdef REDEBUG static void print(struct match *m, char *caption, states st, int ch, FILE *d); #endif #ifdef REDEBUG static void at(struct match *m, char *title, char *start, char *stop, sopno startst, sopno stopst); #endif #ifdef REDEBUG static char *pchar(int ch); #endif #ifdef __cplusplus } #endif /* ========= end header generated by ../../regex/mkh ========= */ http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/main.c?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/main.c +++ php-src/ext/ereg/regex/main.c #include <stdio.h> #include <string.h> #include <sys/types.h> #include <regex.h> #include <assert.h> #include <stdlib.h> #include "main.ih" char *progname; int debug = 0; int line = 0; int status = 0; int copts = REG_EXTENDED; int eopts = 0; regoff_t startoff = 0; regoff_t endoff = 0; extern int split(); extern void regprint(); /* - main - do the simple case, hand off to regress() for regression */ int main(argc, argv) int argc; char *argv[]; { regex_t re; # define NS 10 regmatch_t subs[NS]; char erbuf[100]; int err; size_t len; int c; int errflg = 0; register int i; extern int optind; extern char *optarg; progname = argv[0]; while ((c = getopt(argc, argv, "c:e:S:E:x")) != EOF) switch (c) { case 'c': /* compile options */ copts = options('c', optarg); break; case 'e': /* execute options */ eopts = options('e', optarg); break; case 'S': /* start offset */ startoff = (regoff_t)atoi(optarg); break; case 'E': /* end offset */ endoff = (regoff_t)atoi(optarg); break; case 'x': /* Debugging. */ debug++; break; case '?': default: errflg++; break; } if (errflg) { fprintf(stderr, "usage: %s ", progname); fprintf(stderr, "[-c copt][-C][-d] [re]\n"); exit(2); } if (optind >= argc) { regress(stdin); exit(status); } err = regcomp(&re, argv[optind++], copts); if (err) { len = regerror(err, &re, erbuf, sizeof(erbuf)); fprintf(stderr, "error %s, %d/%d `%s'\n", eprint(err), len, sizeof(erbuf), erbuf); exit(status); } regprint(&re, stdout); if (optind >= argc) { regfree(&re); exit(status); } if (eopts®_STARTEND) { subs[0].rm_so = startoff; subs[0].rm_eo = strlen(argv[optind]) - endoff; } err = regexec(&re, argv[optind], (size_t)NS, subs, eopts); if (err) { len = regerror(err, &re, erbuf, sizeof(erbuf)); fprintf(stderr, "error %s, %d/%d `%s'\n", eprint(err), len, sizeof(erbuf), erbuf); exit(status); } if (!(copts®_NOSUB)) { len = (int)(subs[0].rm_eo - subs[0].rm_so); if (subs[0].rm_so != -1) { if (len != 0) printf("match `%.*s'\n", (int)len, argv[optind] + subs[0].rm_so); else printf("match `'@%.1s\n", argv[optind] + subs[0].rm_so); } for (i = 1; i < NS; i++) if (subs[i].rm_so != -1) printf("(%d) `%.*s'\n", i, (int)(subs[i].rm_eo - subs[i].rm_so), argv[optind] + subs[i].rm_so); } exit(status); } /* - regress - main loop of regression test == void regress(FILE *in); */ void regress(in) FILE *in; { char inbuf[1000]; # define MAXF 10 char *f[MAXF]; int nf; int i; char erbuf[100]; size_t ne; char *badpat = "invalid regular expression"; # define SHORT 10 char *bpname = "REG_BADPAT"; regex_t re; while (fgets(inbuf, sizeof(inbuf), in) != NULL) { line++; if (inbuf[0] == '#' || inbuf[0] == '\n') continue; /* NOTE CONTINUE */ inbuf[strlen(inbuf)-1] = '\0'; /* get rid of stupid \n */ if (debug) fprintf(stdout, "%d:\n", line); nf = split(inbuf, f, MAXF, "\t\t"); if (nf < 3) { fprintf(stderr, "bad input, line %d\n", line); exit(1); } for (i = 0; i < nf; i++) if (strcmp(f[i], "\"\"") == 0) f[i] = ""; if (nf <= 3) f[3] = NULL; if (nf <= 4) f[4] = NULL; try(f[0], f[1], f[2], f[3], f[4], options('c', f[1])); if (opt('&', f[1])) /* try with either type of RE */ try(f[0], f[1], f[2], f[3], f[4], options('c', f[1]) &~ REG_EXTENDED); } ne = regerror(REG_BADPAT, (regex_t *)NULL, erbuf, sizeof(erbuf)); if (strcmp(erbuf, badpat) != 0 || ne != strlen(badpat)+1) { fprintf(stderr, "end: regerror() test gave `%s' not `%s'\n", erbuf, badpat); status = 1; } ne = regerror(REG_BADPAT, (regex_t *)NULL, erbuf, (size_t)SHORT); if (strncmp(erbuf, badpat, SHORT-1) != 0 || erbuf[SHORT-1] != '\0' || ne != strlen(badpat)+1) { fprintf(stderr, "end: regerror() short test gave `%s' not `%.*s'\n", erbuf, SHORT-1, badpat); status = 1; } ne = regerror(REG_ITOA|REG_BADPAT, (regex_t *)NULL, erbuf, sizeof(erbuf)); if (strcmp(erbuf, bpname) != 0 || ne != strlen(bpname)+1) { fprintf(stderr, "end: regerror() ITOA test gave `%s' not `%s'\n", erbuf, bpname); status = 1; } re.re_endp = bpname; ne = regerror(REG_ATOI, &re, erbuf, sizeof(erbuf)); if (atoi(erbuf) != (int)REG_BADPAT) { fprintf(stderr, "end: regerror() ATOI test gave `%s' not `%ld'\n", erbuf, (long)REG_BADPAT); status = 1; } else if (ne != strlen(erbuf)+1) { fprintf(stderr, "end: regerror() ATOI test len(`%s') = %ld\n", erbuf, (long)REG_BADPAT); status = 1; } } /* - try - try it, and report on problems == void try(char *f0, char *f1, char *f2, char *f3, char *f4, int opts); */ void try(f0, f1, f2, f3, f4, opts) char *f0; char *f1; char *f2; char *f3; char *f4; int opts; /* may not match f1 */ { regex_t re; # define NSUBS 10 regmatch_t subs[NSUBS]; # define NSHOULD 15 char *should[NSHOULD]; int nshould; char erbuf[100]; int err; int len; char *type = (opts & REG_EXTENDED) ? "ERE" : "BRE"; register int i; char *grump; char f0copy[1000]; char f2copy[1000]; strcpy(f0copy, f0); re.re_endp = (opts®_PEND) ? f0copy + strlen(f0copy) : NULL; fixstr(f0copy); err = regcomp(&re, f0copy, opts); if (err != 0 && (!opt('C', f1) || err != efind(f2))) { /* unexpected error or wrong error */ len = regerror(err, &re, erbuf, sizeof(erbuf)); fprintf(stderr, "%d: %s error %s, %d/%d `%s'\n", line, type, eprint(err), len, sizeof(erbuf), erbuf); status = 1; } else if (err == 0 && opt('C', f1)) { /* unexpected success */ fprintf(stderr, "%d: %s should have given REG_%s\n", line, type, f2); status = 1; err = 1; /* so we won't try regexec */ } if (err != 0) { regfree(&re); return; } strcpy(f2copy, f2); fixstr(f2copy); if (options('e', f1)®_STARTEND) { if (strchr(f2, '(') == NULL || strchr(f2, ')') == NULL) fprintf(stderr, "%d: bad STARTEND syntax\n", line); subs[0].rm_so = strchr(f2, '(') - f2 + 1; subs[0].rm_eo = strchr(f2, ')') - f2; } err = regexec(&re, f2copy, NSUBS, subs, options('e', f1)); if (err != 0 && (f3 != NULL || err != REG_NOMATCH)) { /* unexpected error or wrong error */ len = regerror(err, &re, erbuf, sizeof(erbuf)); fprintf(stderr, "%d: %s exec error %s, %d/%d `%s'\n", line, type, eprint(err), len, sizeof(erbuf), erbuf); status = 1; } else if (err != 0) { /* nothing more to check */ } else if (f3 == NULL) { /* unexpected success */ fprintf(stderr, "%d: %s exec should have failed\n", line, type); status = 1; err = 1; /* just on principle */ } else if (opts®_NOSUB) { /* nothing more to check */ } else if ((grump = check(f2, subs[0], f3)) != NULL) { fprintf(stderr, "%d: %s %s\n", line, type, grump); status = 1; err = 1; } if (err != 0 || f4 == NULL) { regfree(&re); return; } for (i = 1; i < NSHOULD; i++) should[i] = NULL; nshould = split(f4, should+1, NSHOULD-1, ","); if (nshould == 0) { nshould = 1; should[1] = ""; } for (i = 1; i < NSUBS; i++) { grump = check(f2, subs[i], should[i]); if (grump != NULL) { fprintf(stderr, "%d: %s $%d %s\n", line, type, i, grump); status = 1; err = 1; } } regfree(&re); } /* - options - pick options out of a regression-test string == int options(int type, char *s); */ int options(type, s) int type; /* 'c' compile, 'e' exec */ char *s; { register char *p; register int o = (type == 'c') ? copts : eopts; register char *legal = (type == 'c') ? "bisnmp" : "^$#tl"; for (p = s; *p != '\0'; p++) if (strchr(legal, *p) != NULL) switch (*p) { case 'b': o &= ~REG_EXTENDED; break; case 'i': o |= REG_ICASE; break; case 's': o |= REG_NOSUB; break; case 'n': o |= REG_NEWLINE; break; case 'm': o &= ~REG_EXTENDED; o |= REG_NOSPEC; break; case 'p': o |= REG_PEND; break; case '^': o |= REG_NOTBOL; break; case '$': o |= REG_NOTEOL; break; case '#': o |= REG_STARTEND; break; case 't': /* trace */ o |= REG_TRACE; break; case 'l': /* force long representation */ o |= REG_LARGE; break; case 'r': /* force backref use */ o |= REG_BACKR; break; } return(o); } /* - opt - is a particular option in a regression string? == int opt(int c, char *s); */ int /* predicate */ opt(c, s) int c; char *s; { return(strchr(s, c) != NULL); } /* - fixstr - transform magic characters in strings == void fixstr(register char *p); */ void fixstr(p) register char *p; { if (p == NULL) return; for (; *p != '\0'; p++) if (*p == 'N') *p = '\n'; else if (*p == 'T') *p = '\t'; else if (*p == 'S') *p = ' '; else if (*p == 'Z') *p = '\0'; } /* - check - check a substring match == char *check(char *str, regmatch_t sub, char *should); */ char * /* NULL or complaint */ check(str, sub, should) char *str; regmatch_t sub; char *should; { register int len; register int shlen; register char *p; static char grump[500]; register char *at = NULL; if (should != NULL && strcmp(should, "-") == 0) should = NULL; if (should != NULL && should[0] == '@') { at = should + 1; should = ""; } /* check rm_so and rm_eo for consistency */ if (sub.rm_so > sub.rm_eo || (sub.rm_so == -1 && sub.rm_eo != -1) || (sub.rm_so != -1 && sub.rm_eo == -1) || (sub.rm_so != -1 && sub.rm_so < 0) || (sub.rm_eo != -1 && sub.rm_eo < 0) ) { sprintf(grump, "start %ld end %ld", (long)sub.rm_so, (long)sub.rm_eo); return(grump); } /* check for no match */ if (sub.rm_so == -1 && should == NULL) return(NULL); if (sub.rm_so == -1) return("did not match"); /* check for in range */ if (sub.rm_eo > strlen(str)) { sprintf(grump, "start %ld end %ld, past end of string", (long)sub.rm_so, (long)sub.rm_eo); return(grump); } len = (int)(sub.rm_eo - sub.rm_so); shlen = (int)strlen(should); p = str + sub.rm_so; /* check for not supposed to match */ if (should == NULL) { sprintf(grump, "matched `%.*s'", len, p); return(grump); } /* check for wrong match */ if (len != shlen || strncmp(p, should, (size_t)shlen) != 0) { sprintf(grump, "matched `%.*s' instead", len, p); return(grump); } if (shlen > 0) return(NULL); /* check null match in right place */ if (at == NULL) return(NULL); shlen = strlen(at); if (shlen == 0) shlen = 1; /* force check for end-of-string */ if (strncmp(p, at, shlen) != 0) { sprintf(grump, "matched null at `%.20s'", p); return(grump); } return(NULL); } /* - eprint - convert error number to name == static char *eprint(int err); */ static char * eprint(err) int err; { static char epbuf[100]; size_t len; len = regerror(REG_ITOA|err, (regex_t *)NULL, epbuf, sizeof(epbuf)); assert(len <= sizeof(epbuf)); return(epbuf); } /* - efind - convert error name to number == static int efind(char *name); */ static int efind(name) char *name; { static char efbuf[100]; regex_t re; sprintf(efbuf, "REG_%s", name); assert(strlen(efbuf) < sizeof(efbuf)); re.re_endp = efbuf; (void) regerror(REG_ATOI, &re, efbuf, sizeof(efbuf)); return(atoi(efbuf)); } http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/main.ih?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/main.ih +++ php-src/ext/ereg/regex/main.ih /* ========= begin header generated by ./mkh ========= */ #ifdef __cplusplus extern "C" { #endif /* === main.c === */ void regress(FILE *in); void try(char *f0, char *f1, char *f2, char *f3, char *f4, int opts); int options(int type, char *s); int opt(int c, char *s); void fixstr(register char *p); char *check(char *str, regmatch_t sub, char *should); static char *eprint(int err); static int efind(char *name); #ifdef __cplusplus } #endif /* ========= end header generated by ./mkh ========= */ http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/regcomp.c?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/regcomp.c +++ php-src/ext/ereg/regex/regcomp.c #include <sys/types.h> #include <stdio.h> #include <string.h> #include <ctype.h> #include <limits.h> #include <stdlib.h> #include <regex.h> #include "utils.h" #include "regex2.h" #include "cclass.h" #include "cname.h" /* * parse structure, passed up and down to avoid global variables and * other clumsinesses */ struct parse { char *next; /* next character in RE */ char *end; /* end of string (-> NUL normally) */ int error; /* has an error been seen? */ sop *strip; /* malloced strip */ sopno ssize; /* malloced strip size (allocated) */ sopno slen; /* malloced strip length (used) */ int ncsalloc; /* number of csets allocated */ struct re_guts *g; # define NPAREN 10 /* we need to remember () 1-9 for back refs */ sopno pbegin[NPAREN]; /* -> ( ([0] unused) */ sopno pend[NPAREN]; /* -> ) ([0] unused) */ }; #include "regcomp.ih" static char nuls[10]; /* place to point scanner in event of error */ /* * macros for use with parse structure * BEWARE: these know that the parse structure is named `p' !!! */ #define PEEK() (*p->next) #define PEEK2() (*(p->next+1)) #define MORE() (p->next < p->end) #define MORE2() (p->next+1 < p->end) #define SEE(c) (MORE() && PEEK() == (c)) #define SEETWO(a, b) (MORE() && MORE2() && PEEK() == (a) && PEEK2() == (b)) #define EAT(c) ((SEE(c)) ? (NEXT1(), 1) : 0) #define EATTWO(a, b) ((SEETWO(a, b)) ? (NEXT2(), 1) : 0) #define NEXT1() (p->next++) #define NEXT2() (p->next += 2) #define NEXTn(n) (p->next += (n)) #define GETNEXT() (*p->next++) #define SETERROR(e) seterr(p, (e)) #define REQUIRE(co, e) ((void)((co) || SETERROR(e))) #define MUSTSEE(c, e) (REQUIRE(MORE() && PEEK() == (c), e)) #define MUSTEAT(c, e) (REQUIRE(MORE() && GETNEXT() == (c), e)) #define MUSTNOTSEE(c, e) (REQUIRE(!MORE() || PEEK() != (c), e)) #define EMIT(op, sopnd) doemit(p, (sop)(op), (size_t)(sopnd)) #define INSERT(op, pos) doinsert(p, (sop)(op), HERE()-(pos)+1, pos) #define AHEAD(pos) dofwd(p, pos, HERE()-(pos)) #define ASTERN(sop, pos) EMIT(sop, HERE()-pos) #define HERE() (p->slen) #define THERE() (p->slen - 1) #define THERETHERE() (p->slen - 2) #define DROP(n) (p->slen -= (n)) #ifndef NDEBUG static int never = 0; /* for use in asserts; shuts lint up */ #else #define never 0 /* some <assert.h>s have bugs too */ #endif /* - regcomp - interface for parser and compilation = API_EXPORT(int) regcomp(regex_t *, const char *, int); = #define REG_BASIC 0000 = #define REG_EXTENDED 0001 = #define REG_ICASE 0002 = #define REG_NOSUB 0004 = #define REG_NEWLINE 0010 = #define REG_NOSPEC 0020 = #define REG_PEND 0040 = #define REG_DUMP 0200 */ API_EXPORT(int) /* 0 success, otherwise REG_something */ regcomp(preg, pattern, cflags) regex_t *preg; const char *pattern; int cflags; { struct parse pa; register struct re_guts *g; register struct parse *p = &pa; register int i; register size_t len; #ifdef REDEBUG # define GOODFLAGS(f) (f) #else # define GOODFLAGS(f) ((f)&~REG_DUMP) #endif cflags = GOODFLAGS(cflags); if ((cflags®_EXTENDED) && (cflags®_NOSPEC)) return(REG_INVARG); if (cflags®_PEND) { if (preg->re_endp < pattern) return(REG_INVARG); len = preg->re_endp - pattern; } else len = strlen((char *)pattern); /* do the mallocs early so failure handling is easy */ g = (struct re_guts *)malloc(sizeof(struct re_guts) + (NC-1)*sizeof(cat_t)); if (g == NULL) return(REG_ESPACE); p->ssize = len/(size_t)2*(size_t)3 + (size_t)1; /* ugh */ p->strip = (sop *)malloc(p->ssize * sizeof(sop)); p->slen = 0; if (p->strip == NULL) { free((char *)g); return(REG_ESPACE); } /* set things up */ p->g = g; p->next = (char *)pattern; /* convenience; we do not modify it */ p->end = p->next + len; p->error = 0; p->ncsalloc = 0; for (i = 0; i < NPAREN; i++) { p->pbegin[i] = 0; p->pend[i] = 0; } g->csetsize = NC; g->sets = NULL; g->setbits = NULL; g->ncsets = 0; g->cflags = cflags; g->iflags = 0; g->nbol = 0; g->neol = 0; g->must = NULL; g->mlen = 0; g->nsub = 0; g->ncategories = 1; /* category 0 is "everything else" */ g->categories = &g->catspace[-(CHAR_MIN)]; (void) memset((char *)g->catspace, 0, NC*sizeof(cat_t)); g->backrefs = 0; /* do it */ EMIT(OEND, 0); g->firststate = THERE(); if (cflags®_EXTENDED) p_ere(p, OUT); else if (cflags®_NOSPEC) p_str(p); else p_bre(p, OUT, OUT); EMIT(OEND, 0); g->laststate = THERE(); /* tidy up loose ends and fill things in */ categorize(p, g); stripsnug(p, g); findmust(p, g); g->nplus = pluscount(p, g); g->magic = MAGIC2; preg->re_nsub = g->nsub; preg->re_g = g; preg->re_magic = MAGIC1; #ifndef REDEBUG /* not debugging, so can't rely on the assert() in regexec() */ if (g->iflags&BAD) SETERROR(REG_ASSERT); #endif /* win or lose, we're done */ if (p->error != 0) /* lose */ regfree(preg); return(p->error); } /* - p_ere - ERE parser top level, concatenation and alternation == static void p_ere(register struct parse *p, int stop); */ static void p_ere(p, stop) register struct parse *p; int stop; /* character this ERE should end at */ { register char c; register sopno prevback = 0; register sopno prevfwd = 0; register sopno conc; register int first = 1; /* is this the first alternative? */ for (;;) { /* do a bunch of concatenated expressions */ conc = HERE(); while (MORE() && (c = PEEK()) != '|' && c != stop) p_ere_exp(p); REQUIRE(HERE() != conc, REG_EMPTY); /* require nonempty */ if (!EAT('|')) break; /* NOTE BREAK OUT */ if (first) { INSERT(OCH_, conc); /* offset is wrong */ prevfwd = conc; prevback = conc; first = 0; } ASTERN(OOR1, prevback); prevback = THERE(); AHEAD(prevfwd); /* fix previous offset */ prevfwd = HERE(); EMIT(OOR2, 0); /* offset is very wrong */ } if (!first) { /* tail-end fixups */ AHEAD(prevfwd); ASTERN(O_CH, prevback); } assert(!MORE() || SEE(stop)); } /* - p_ere_exp - parse one subERE, an atom possibly followed by a repetition op == static void p_ere_exp(register struct parse *p); */ static void p_ere_exp(p) register struct parse *p; { register char c; register sopno pos; register int count; register int count2; register sopno subno; int wascaret = 0; assert(MORE()); /* caller should have ensured this */ c = GETNEXT(); pos = HERE(); switch (c) { case '(': REQUIRE(MORE(), REG_EPAREN); p->g->nsub++; subno = p->g->nsub; if (subno < NPAREN) p->pbegin[subno] = HERE(); EMIT(OLPAREN, subno); if (!SEE(')')) p_ere(p, ')'); if (subno < NPAREN) { p->pend[subno] = HERE(); assert(p->pend[subno] != 0); } EMIT(ORPAREN, subno); MUSTEAT(')', REG_EPAREN); break; #ifndef POSIX_MISTAKE case ')': /* happens only if no current unmatched ( */ /* * You may ask, why the ifndef? Because I didn't notice * this until slightly too late for 1003.2, and none of the * other 1003.2 regular-expression reviewers noticed it at * all. So an unmatched ) is legal POSIX, at least until * we can get it fixed. */ SETERROR(REG_EPAREN); break; #endif case '^': EMIT(OBOL, 0); p->g->iflags |= USEBOL; p->g->nbol++; wascaret = 1; break; case '$': EMIT(OEOL, 0); p->g->iflags |= USEEOL; p->g->neol++; break; case '|': SETERROR(REG_EMPTY); break; case '*': case '+': case '?': SETERROR(REG_BADRPT); break; case '.': if (p->g->cflags®_NEWLINE) nonnewline(p); else EMIT(OANY, 0); break; case '[': p_bracket(p); break; case '\\': REQUIRE(MORE(), REG_EESCAPE); c = GETNEXT(); ordinary(p, c); break; case '{': /* okay as ordinary except if digit follows */ REQUIRE(!MORE() || !isdigit(PEEK()), REG_BADRPT); /* FALLTHROUGH */ default: ordinary(p, c); break; } if (!MORE()) return; c = PEEK(); /* we call { a repetition if followed by a digit */ if (!( c == '*' || c == '+' || c == '?' || (c == '{' && MORE2() && isdigit(PEEK2())) )) return; /* no repetition, we're done */ NEXT1(); REQUIRE(!wascaret, REG_BADRPT); switch (c) { case '*': /* implemented as +? */ /* this case does not require the (y|) trick, noKLUDGE */ INSERT(OPLUS_, pos); ASTERN(O_PLUS, pos); INSERT(OQUEST_, pos); ASTERN(O_QUEST, pos); break; case '+': INSERT(OPLUS_, pos); ASTERN(O_PLUS, pos); break; case '?': /* KLUDGE: emit y? as (y|) until subtle bug gets fixed */ INSERT(OCH_, pos); /* offset slightly wrong */ ASTERN(OOR1, pos); /* this one's right */ AHEAD(pos); /* fix the OCH_ */ EMIT(OOR2, 0); /* offset very wrong... */ AHEAD(THERE()); /* ...so fix it */ ASTERN(O_CH, THERETHERE()); break; case '{': count = p_count(p); if (EAT(',')) { if (isdigit(PEEK())) { count2 = p_count(p); REQUIRE(count <= count2, REG_BADBR); } else /* single number with comma */ count2 = INFINITY; } else /* just a single number */ count2 = count; repeat(p, pos, count, count2); if (!EAT('}')) { /* error heuristics */ while (MORE() && PEEK() != '}') NEXT1(); REQUIRE(MORE(), REG_EBRACE); SETERROR(REG_BADBR); } break; } if (!MORE()) return; c = PEEK(); if (!( c == '*' || c == '+' || c == '?' || (c == '{' && MORE2() && isdigit(PEEK2())) ) ) return; SETERROR(REG_BADRPT); } /* - p_str - string (no metacharacters) "parser" == static void p_str(register struct parse *p); */ static void p_str(p) register struct parse *p; { REQUIRE(MORE(), REG_EMPTY); while (MORE()) ordinary(p, GETNEXT()); } /* - p_bre - BRE parser top level, anchoring and concatenation == static void p_bre(register struct parse *p, register int end1, \ == register int end2); * Giving end1 as OUT essentially eliminates the end1/end2 check. * * This implementation is a bit of a kludge, in that a trailing $ is first * taken as an ordinary character and then revised to be an anchor. The * only undesirable side effect is that '$' gets included as a character * category in such cases. This is fairly harmless; not worth fixing. * The amount of lookahead needed to avoid this kludge is excessive. */ static void p_bre(p, end1, end2) register struct parse *p; register int end1; /* first terminating character */ register int end2; /* second terminating character */ { register sopno start = HERE(); register int first = 1; /* first subexpression? */ register int wasdollar = 0; if (EAT('^')) { EMIT(OBOL, 0); p->g->iflags |= USEBOL; p->g->nbol++; } while (MORE() && !SEETWO(end1, end2)) { wasdollar = p_simp_re(p, first); first = 0; } if (wasdollar) { /* oops, that was a trailing anchor */ DROP(1); EMIT(OEOL, 0); p->g->iflags |= USEEOL; p->g->neol++; } REQUIRE(HERE() != start, REG_EMPTY); /* require nonempty */ } /* - p_simp_re - parse a simple RE, an atom possibly followed by a repetition == static int p_simp_re(register struct parse *p, int starordinary); */ static int /* was the simple RE an unbackslashed $? */ p_simp_re(p, starordinary) register struct parse *p; int starordinary; /* is a leading * an ordinary character? */ { register int c; register int count; register int count2; register sopno pos; register int i; register sopno subno; # define BACKSL (1<<CHAR_BIT) pos = HERE(); /* repetion op, if any, covers from here */ assert(MORE()); /* caller should have ensured this */ c = GETNEXT(); if (c == '\\') { REQUIRE(MORE(), REG_EESCAPE); c = BACKSL | (unsigned char)GETNEXT(); } switch (c) { case '.': if (p->g->cflags®_NEWLINE) nonnewline(p); else EMIT(OANY, 0); break; case '[': p_bracket(p); break; case BACKSL|'{': SETERROR(REG_BADRPT); break; case BACKSL|'(': p->g->nsub++; subno = p->g->nsub; if (subno < NPAREN) p->pbegin[subno] = HERE(); EMIT(OLPAREN, subno); /* the MORE here is an error heuristic */ if (MORE() && !SEETWO('\\', ')')) p_bre(p, '\\', ')'); if (subno < NPAREN) { p->pend[subno] = HERE(); assert(p->pend[subno] != 0); } EMIT(ORPAREN, subno); REQUIRE(EATTWO('\\', ')'), REG_EPAREN); break; case BACKSL|')': /* should not get here -- must be user */ case BACKSL|'}': SETERROR(REG_EPAREN); break; case BACKSL|'1': case BACKSL|'2': case BACKSL|'3': case BACKSL|'4': case BACKSL|'5': case BACKSL|'6': case BACKSL|'7': case BACKSL|'8': case BACKSL|'9': i = (c&~BACKSL) - '0'; assert(i < NPAREN); if (p->pend[i] != 0) { assert(i <= p->g->nsub); EMIT(OBACK_, i); assert(p->pbegin[i] != 0); assert(OP(p->strip[p->pbegin[i]]) == OLPAREN); assert(OP(p->strip[p->pend[i]]) == ORPAREN); (void) dupl(p, p->pbegin[i]+1, p->pend[i]); EMIT(O_BACK, i); } else SETERROR(REG_ESUBREG); p->g->backrefs = 1; break; case '*': REQUIRE(starordinary, REG_BADRPT); /* FALLTHROUGH */ default: ordinary(p, c &~ BACKSL); break; } if (EAT('*')) { /* implemented as +? */ /* this case does not require the (y|) trick, noKLUDGE */ INSERT(OPLUS_, pos); ASTERN(O_PLUS, pos); INSERT(OQUEST_, pos); ASTERN(O_QUEST, pos); } else if (EATTWO('\\', '{')) { count = p_count(p); if (EAT(',')) { if (MORE() && isdigit(PEEK())) { count2 = p_count(p); REQUIRE(count <= count2, REG_BADBR); } else /* single number with comma */ count2 = INFINITY; } else /* just a single number */ count2 = count; repeat(p, pos, count, count2); if (!EATTWO('\\', '}')) { /* error heuristics */ while (MORE() && !SEETWO('\\', '}')) NEXT1(); REQUIRE(MORE(), REG_EBRACE); SETERROR(REG_BADBR); } } else if (c == (unsigned char)'$') /* $ (but not \$) ends it */ return(1); return(0); } /* - p_count - parse a repetition count == static int p_count(register struct parse *p); */ static int /* the value */ p_count(p) register struct parse *p; { register int count = 0; register int ndigits = 0; while (MORE() && isdigit(PEEK()) && count <= DUPMAX) { count = count*10 + (GETNEXT() - '0'); ndigits++; } REQUIRE(ndigits > 0 && count <= DUPMAX, REG_BADBR); return(count); } /* - p_bracket - parse a bracketed character list == static void p_bracket(register struct parse *p); * * Note a significant property of this code: if the allocset() did SETERROR, * no set operations are done. */ static void p_bracket(p) register struct parse *p; { register cset *cs = allocset(p); register int invert = 0; /* Dept of Truly Sickening Special-Case Kludges */ if (p->next + 5 < p->end && strncmp(p->next, "[:<:]]", 6) == 0) { EMIT(OBOW, 0); NEXTn(6); return; } if (p->next + 5 < p->end && strncmp(p->next, "[:>:]]", 6) == 0) { EMIT(OEOW, 0); NEXTn(6); return; } if (EAT('^')) invert++; /* make note to invert set at end */ if (EAT(']')) CHadd(cs, ']'); else if (EAT('-')) CHadd(cs, '-'); while (MORE() && PEEK() != ']' && !SEETWO('-', ']')) p_b_term(p, cs); if (EAT('-')) CHadd(cs, '-'); MUSTEAT(']', REG_EBRACK); if (p->error != 0) /* don't mess things up further */ return; if (p->g->cflags®_ICASE) { register int i; register int ci; for (i = p->g->csetsize - 1; i >= 0; i--) if (CHIN(cs, i) && isalpha(i)) { ci = othercase(i); if (ci != i) CHadd(cs, ci); } if (cs->multis != NULL) mccase(p, cs); } if (invert) { register int i; for (i = p->g->csetsize - 1; i >= 0; i--) if (CHIN(cs, i)) CHsub(cs, i); else CHadd(cs, i); if (p->g->cflags®_NEWLINE) CHsub(cs, '\n'); if (cs->multis != NULL) mcinvert(p, cs); } assert(cs->multis == NULL); /* xxx */ if (nch(p, cs) == 1) { /* optimize singleton sets */ ordinary(p, firstch(p, cs)); freeset(p, cs); } else EMIT(OANYOF, freezeset(p, cs)); } /* - p_b_term - parse one term of a bracketed character list == static void p_b_term(register struct parse *p, register cset *cs); */ static void p_b_term(p, cs) register struct parse *p; register cset *cs; { register char c; register char start, finish; register int i; /* classify what we've got */ switch ((MORE()) ? PEEK() : '\0') { case '[': c = (MORE2()) ? PEEK2() : '\0'; break; case '-': SETERROR(REG_ERANGE); return; /* NOTE RETURN */ break; default: c = '\0'; break; } switch (c) { case ':': /* character class */ NEXT2(); REQUIRE(MORE(), REG_EBRACK); c = PEEK(); REQUIRE(c != '-' && c != ']', REG_ECTYPE); p_b_cclass(p, cs); REQUIRE(MORE(), REG_EBRACK); REQUIRE(EATTWO(':', ']'), REG_ECTYPE); break; case '=': /* equivalence class */ NEXT2(); REQUIRE(MORE(), REG_EBRACK); c = PEEK(); REQUIRE(c != '-' && c != ']', REG_ECOLLATE); p_b_eclass(p, cs); REQUIRE(MORE(), REG_EBRACK); REQUIRE(EATTWO('=', ']'), REG_ECOLLATE); break; default: /* symbol, ordinary character, or range */ /* xxx revision needed for multichar stuff */ start = p_b_symbol(p); if (SEE('-') && MORE2() && PEEK2() != ']') { /* range */ NEXT1(); if (EAT('-')) finish = '-'; else finish = p_b_symbol(p); } else finish = start; /* xxx what about signed chars here... */ REQUIRE(start <= finish, REG_ERANGE); for (i = start; i <= finish; i++) CHadd(cs, i); break; } } /* - p_b_cclass - parse a character-class name and deal with it == static void p_b_cclass(register struct parse *p, register cset *cs); */ static void p_b_cclass(p, cs) register struct parse *p; register cset *cs; { register char *sp = p->next; register struct cclass *cp; register size_t len; register char *u; register char c; while (MORE() && isalpha(PEEK())) NEXT1(); len = p->next - sp; for (cp = cclasses; cp->name != NULL; cp++) if (strncmp(cp->name, sp, len) == 0 && cp->name[len] == '\0') break; if (cp->name == NULL) { /* oops, didn't find it */ SETERROR(REG_ECTYPE); return; } u = cp->chars; while ((c = *u++) != '\0') CHadd(cs, c); for (u = cp->multis; *u != '\0'; u += strlen(u) + 1) MCadd(p, cs, u); } /* - p_b_eclass - parse an equivalence-class name and deal with it == static void p_b_eclass(register struct parse *p, register cset *cs); * * This implementation is incomplete. xxx */ static void p_b_eclass(p, cs) register struct parse *p; register cset *cs; { register char c; c = p_b_coll_elem(p, '='); CHadd(cs, c); } /* - p_b_symbol - parse a character or [..]ed multicharacter collating symbol == static char p_b_symbol(register struct parse *p); */ static char /* value of symbol */ p_b_symbol(p) register struct parse *p; { register char value; REQUIRE(MORE(), REG_EBRACK); if (!EATTWO('[', '.')) return(GETNEXT()); /* collating symbol */ value = p_b_coll_elem(p, '.'); REQUIRE(EATTWO('.', ']'), REG_ECOLLATE); return(value); } /* - p_b_coll_elem - parse a collating-element name and look it up == static char p_b_coll_elem(register struct parse *p, int endc); */ static char /* value of collating element */ p_b_coll_elem(p, endc) register struct parse *p; int endc; /* name ended by endc,']' */ { register char *sp = p->next; register struct cname *cp; register int len; while (MORE() && !SEETWO(endc, ']')) NEXT1(); if (!MORE()) { SETERROR(REG_EBRACK); return(0); } len = p->next - sp; for (cp = cnames; cp->name != NULL; cp++) if (strncmp(cp->name, sp, len) == 0 && cp->name[len] == '\0') return(cp->code); /* known name */ if (len == 1) return(*sp); /* single character */ SETERROR(REG_ECOLLATE); /* neither */ return(0); } /* - othercase - return the case counterpart of an alphabetic == static char othercase(int ch); */ static char /* if no counterpart, return ch */ othercase(ch) int ch; { assert(isalpha(ch)); if (isupper(ch)) return(tolower(ch)); else if (islower(ch)) return(toupper(ch)); else /* peculiar, but could happen */ return(ch); } /* - bothcases - emit a dualcase version of a two-case character == static void bothcases(register struct parse *p, int ch); * * Boy, is this implementation ever a kludge... */ static void bothcases(p, ch) register struct parse *p; int ch; { register char *oldnext = p->next; register char *oldend = p->end; char bracket[3]; assert(othercase(ch) != ch); /* p_bracket() would recurse */ p->next = bracket; p->end = bracket+2; bracket[0] = ch; bracket[1] = ']'; bracket[2] = '\0'; p_bracket(p); assert(p->next == bracket+2); p->next = oldnext; p->end = oldend; } /* - ordinary - emit an ordinary character == static void ordinary(register struct parse *p, register int ch); */ static void ordinary(p, ch) register struct parse *p; register int ch; { register cat_t *cap = p->g->categories; if ((p->g->cflags®_ICASE) && isalpha(ch) && othercase(ch) != ch) bothcases(p, ch); else { EMIT(OCHAR, (unsigned char)ch); if (cap[ch] == 0) cap[ch] = p->g->ncategories++; } } /* - nonnewline - emit REG_NEWLINE version of OANY == static void nonnewline(register struct parse *p); * * Boy, is this implementation ever a kludge... */ static void nonnewline(p) register struct parse *p; { register char *oldnext = p->next; register char *oldend = p->end; char bracket[4]; p->next = bracket; p->end = bracket+3; bracket[0] = '^'; bracket[1] = '\n'; bracket[2] = ']'; bracket[3] = '\0'; p_bracket(p); assert(p->next == bracket+3); p->next = oldnext; p->end = oldend; } /* - repeat - generate code for a bounded repetition, recursively if needed == static void repeat(register struct parse *p, sopno start, int from, int to); */ static void repeat(p, start, from, to) register struct parse *p; sopno start; /* operand from here to end of strip */ int from; /* repeated from this number */ int to; /* to this number of times (maybe INFINITY) */ { register sopno finish = HERE(); # define N 2 # define INF 3 # define REP(f, t) ((f)*8 + (t)) # define MAP(n) (((n) <= 1) ? (n) : ((n) == INFINITY) ? INF : N) register sopno copy; if (p->error != 0) /* head off possible runaway recursion */ return; assert(from <= to); switch (REP(MAP(from), MAP(to))) { case REP(0, 0): /* must be user doing this */ DROP(finish-start); /* drop the operand */ break; case REP(0, 1): /* as x{1,1}? */ case REP(0, N): /* as x{1,n}? */ case REP(0, INF): /* as x{1,}? */ /* KLUDGE: emit y? as (y|) until subtle bug gets fixed */ INSERT(OCH_, start); /* offset is wrong... */ repeat(p, start+1, 1, to); ASTERN(OOR1, start); AHEAD(start); /* ... fix it */ EMIT(OOR2, 0); AHEAD(THERE()); ASTERN(O_CH, THERETHERE()); break; case REP(1, 1): /* trivial case */ /* done */ break; case REP(1, N): /* as x?x{1,n-1} */ /* KLUDGE: emit y? as (y|) until subtle bug gets fixed */ INSERT(OCH_, start); ASTERN(OOR1, start); AHEAD(start); EMIT(OOR2, 0); /* offset very wrong... */ AHEAD(THERE()); /* ...so fix it */ ASTERN(O_CH, THERETHERE()); copy = dupl(p, start+1, finish+1); assert(copy == finish+4); repeat(p, copy, 1, to-1); break; case REP(1, INF): /* as x+ */ INSERT(OPLUS_, start); ASTERN(O_PLUS, start); break; case REP(N, N): /* as xx{m-1,n-1} */ copy = dupl(p, start, finish); repeat(p, copy, from-1, to-1); break; case REP(N, INF): /* as xx{n-1,INF} */ copy = dupl(p, start, finish); repeat(p, copy, from-1, to); break; default: /* "can't happen" */ SETERROR(REG_ASSERT); /* just in case */ break; } } /* - seterr - set an error condition == static int seterr(register struct parse *p, int e); */ static int /* useless but makes type checking happy */ seterr(p, e) register struct parse *p; int e; { if (p->error == 0) /* keep earliest error condition */ p->error = e; p->next = nuls; /* try to bring things to a halt */ p->end = nuls; return(0); /* make the return value well-defined */ } /* - allocset - allocate a set of characters for [] == static cset *allocset(register struct parse *p); */ static cset * allocset(p) register struct parse *p; { register int no = p->g->ncsets++; register size_t nc; register size_t nbytes; register cset *cs; register size_t css = (size_t)p->g->csetsize; register int i; if (no >= p->ncsalloc) { /* need another column of space */ p->ncsalloc += CHAR_BIT; nc = p->ncsalloc; assert(nc % CHAR_BIT == 0); nbytes = nc / CHAR_BIT * css; if (p->g->sets == NULL) p->g->sets = (cset *)malloc(nc * sizeof(cset)); else p->g->sets = (cset *)realloc((char *)p->g->sets, nc * sizeof(cset)); if (p->g->setbits == NULL) p->g->setbits = (uch *)malloc(nbytes); else { p->g->setbits = (uch *)realloc((char *)p->g->setbits, nbytes); /* xxx this isn't right if setbits is now NULL */ for (i = 0; i < no; i++) p->g->sets[i].ptr = p->g->setbits + css*(i/CHAR_BIT); } if (p->g->sets != NULL && p->g->setbits != NULL) (void) memset((char *)p->g->setbits + (nbytes - css), 0, css); else { no = 0; SETERROR(REG_ESPACE); /* caller's responsibility not to do set ops */ } } assert(p->g->sets != NULL); /* xxx */ cs = &p->g->sets[no]; cs->ptr = p->g->setbits + css*((no)/CHAR_BIT); cs->mask = 1 << ((no) % CHAR_BIT); cs->hash = 0; cs->smultis = 0; cs->multis = NULL; return(cs); } /* - freeset - free a now-unused set == static void freeset(register struct parse *p, register cset *cs); */ static void freeset(p, cs) register struct parse *p; register cset *cs; { register unsigned int i; register cset *top = &p->g->sets[p->g->ncsets]; register size_t css = (size_t)p->g->csetsize; for (i = 0; i < css; i++) CHsub(cs, i); if (cs == top-1) /* recover only the easy case */ p->g->ncsets--; } /* - freezeset - final processing on a set of characters == static int freezeset(register struct parse *p, register cset *cs); * * The main task here is merging identical sets. This is usually a waste * of time (although the hash code minimizes the overhead), but can win * big if REG_ICASE is being used. REG_ICASE, by the way, is why the hash * is done using addition rather than xor -- all ASCII [aA] sets xor to * the same value! */ static int /* set number */ freezeset(p, cs) register struct parse *p; register cset *cs; { register uch h = cs->hash; register unsigned int i; register cset *top = &p->g->sets[p->g->ncsets]; register cset *cs2; register size_t css = (size_t)p->g->csetsize; /* look for an earlier one which is the same */ for (cs2 = &p->g->sets[0]; cs2 < top; cs2++) if (cs2->hash == h && cs2 != cs) { /* maybe */ for (i = 0; i < css; i++) if (!!CHIN(cs2, i) != !!CHIN(cs, i)) break; /* no */ if (i == css) break; /* yes */ } if (cs2 < top) { /* found one */ freeset(p, cs); cs = cs2; } return((int)(cs - p->g->sets)); } /* - firstch - return first character in a set (which must have at least one) == static int firstch(register struct parse *p, register cset *cs); */ static int /* character; there is no "none" value */ firstch(p, cs) register struct parse *p; register cset *cs; { register unsigned int i; register size_t css = (size_t)p->g->csetsize; for (i = 0; i < css; i++) if (CHIN(cs, i)) return((char)i); assert(never); return(0); /* arbitrary */ } /* - nch - number of characters in a set == static int nch(register struct parse *p, register cset *cs); */ static int nch(p, cs) register struct parse *p; register cset *cs; { register unsigned int i; register size_t css = (size_t)p->g->csetsize; register int n = 0; for (i = 0; i < css; i++) if (CHIN(cs, i)) n++; return(n); } /* - mcadd - add a collating element to a cset == static void mcadd(register struct parse *p, register cset *cs, \ == register char *cp); */ static void mcadd(p, cs, cp) register struct parse *p; register cset *cs; register char *cp; { register size_t oldend = cs->smultis; cs->smultis += strlen(cp) + 1; if (cs->multis == NULL) cs->multis = malloc(cs->smultis); else cs->multis = realloc(cs->multis, cs->smultis); if (cs->multis == NULL) { SETERROR(REG_ESPACE); return; } (void) strcpy(cs->multis + oldend - 1, cp); cs->multis[cs->smultis - 1] = '\0'; } /* - mcinvert - invert the list of collating elements in a cset == static void mcinvert(register struct parse *p, register cset *cs); * * This would have to know the set of possibilities. Implementation * is deferred. */ static void mcinvert(p, cs) register struct parse *p; register cset *cs; { assert(cs->multis == NULL); /* xxx */ } /* - mccase - add case counterparts of the list of collating elements in a cset == static void mccase(register struct parse *p, register cset *cs); * * This would have to know the set of possibilities. Implementation * is deferred. */ static void mccase(p, cs) register struct parse *p; register cset *cs; { assert(cs->multis == NULL); /* xxx */ } /* - isinsets - is this character in any sets? == static int isinsets(register struct re_guts *g, int c); */ static int /* predicate */ isinsets(g, c) register struct re_guts *g; int c; { register uch *col; register int i; register int ncols = (g->ncsets+(CHAR_BIT-1)) / CHAR_BIT; register unsigned uc = (unsigned char)c; for (i = 0, col = g->setbits; i < ncols; i++, col += g->csetsize) if (col[uc] != 0) return(1); return(0); } /* - samesets - are these two characters in exactly the same sets? == static int samesets(register struct re_guts *g, int c1, int c2); */ static int /* predicate */ samesets(g, c1, c2) register struct re_guts *g; int c1; int c2; { register uch *col; register int i; register int ncols = (g->ncsets+(CHAR_BIT-1)) / CHAR_BIT; register unsigned uc1 = (unsigned char)c1; register unsigned uc2 = (unsigned char)c2; for (i = 0, col = g->setbits; i < ncols; i++, col += g->csetsize) if (col[uc1] != col[uc2]) return(0); return(1); } /* - categorize - sort out character categories == static void categorize(struct parse *p, register struct re_guts *g); */ static void categorize(p, g) struct parse *p; register struct re_guts *g; { register cat_t *cats = g->categories; register int c; register int c2; register cat_t cat; /* avoid making error situations worse */ if (p->error != 0) return; for (c = CHAR_MIN; c <= CHAR_MAX; c++) if (cats[c] == 0 && isinsets(g, c)) { cat = g->ncategories++; cats[c] = cat; for (c2 = c+1; c2 <= CHAR_MAX; c2++) if (cats[c2] == 0 && samesets(g, c, c2)) cats[c2] = cat; } } /* - dupl - emit a duplicate of a bunch of sops == static sopno dupl(register struct parse *p, sopno start, sopno finish); */ static sopno /* start of duplicate */ dupl(p, start, finish) register struct parse *p; sopno start; /* from here */ sopno finish; /* to this less one */ { register sopno ret = HERE(); register sopno len = finish - start; assert(finish >= start); if (len == 0) return(ret); enlarge(p, p->ssize + len); /* this many unexpected additions */ assert(p->ssize >= p->slen + len); (void) memcpy((char *)(p->strip + p->slen), (char *)(p->strip + start), (size_t)len*sizeof(sop)); p->slen += len; return(ret); } /* - doemit - emit a strip operator == static void doemit(register struct parse *p, sop op, size_t opnd); * * It might seem better to implement this as a macro with a function as * hard-case backup, but it's just too big and messy unless there are * some changes to the data structures. Maybe later. */ static void doemit(p, op, opnd) register struct parse *p; sop op; size_t opnd; { /* avoid making error situations worse */ if (p->error != 0) return; /* deal with oversize operands ("can't happen", more or less) */ assert(opnd < 1<<OPSHIFT); /* deal with undersized strip */ if (p->slen >= p->ssize) enlarge(p, (p->ssize+1) / 2 * 3); /* +50% */ assert(p->slen < p->ssize); /* finally, it's all reduced to the easy case */ p->strip[p->slen++] = SOP(op, opnd); } /* - doinsert - insert a sop into the strip == static void doinsert(register struct parse *p, sop op, size_t opnd, sopno pos); */ static void doinsert(p, op, opnd, pos) register struct parse *p; sop op; size_t opnd; sopno pos; { register sopno sn; register sop s; register int i; /* avoid making error situations worse */ if (p->error != 0) return; sn = HERE(); EMIT(op, opnd); /* do checks, ensure space */ assert(HERE() == sn+1); s = p->strip[sn]; /* adjust paren pointers */ assert(pos > 0); for (i = 1; i < NPAREN; i++) { if (p->pbegin[i] >= pos) { p->pbegin[i]++; } if (p->pend[i] >= pos) { p->pend[i]++; } } memmove((char *)&p->strip[pos+1], (char *)&p->strip[pos], (HERE()-pos-1)*sizeof(sop)); p->strip[pos] = s; } /* - dofwd - complete a forward reference == static void dofwd(register struct parse *p, sopno pos, sop value); */ static void dofwd(p, pos, value) register struct parse *p; register sopno pos; sop value; { /* avoid making error situations worse */ if (p->error != 0) return; assert(value < 1<<OPSHIFT); p->strip[pos] = OP(p->strip[pos]) | value; } /* - enlarge - enlarge the strip == static void enlarge(register struct parse *p, sopno size); */ static void enlarge(p, size) register struct parse *p; register sopno size; { register sop *sp; if (p->ssize >= size) return; sp = (sop *)realloc(p->strip, size*sizeof(sop)); if (sp == NULL) { SETERROR(REG_ESPACE); return; } p->strip = sp; p->ssize = size; } /* - stripsnug - compact the strip == static void stripsnug(register struct parse *p, register struct re_guts *g); */ static void stripsnug(p, g) register struct parse *p; register struct re_guts *g; { g->nstates = p->slen; g->strip = (sop *)realloc((char *)p->strip, p->slen * sizeof(sop)); if (g->strip == NULL) { SETERROR(REG_ESPACE); g->strip = p->strip; } } /* - findmust - fill in must and mlen with longest mandatory literal string == static void findmust(register struct parse *p, register struct re_guts *g); * * This algorithm could do fancy things like analyzing the operands of | * for common subsequences. Someday. This code is simple and finds most * of the interesting cases. * * Note that must and mlen got initialized during setup. */ static void findmust(p, g) struct parse *p; register struct re_guts *g; { register sop *scan; sop *start = NULL; register sop *newstart = NULL; register sopno newlen; register sop s; register char *cp; register sopno i; /* avoid making error situations worse */ if (p->error != 0) return; /* find the longest OCHAR sequence in strip */ newlen = 0; scan = g->strip + 1; do { s = *scan++; switch (OP(s)) { case OCHAR: /* sequence member */ if (newlen == 0) /* new sequence */ newstart = scan - 1; newlen++; break; case OPLUS_: /* things that don't break one */ case OLPAREN: case ORPAREN: break; case OQUEST_: /* things that must be skipped */ case OCH_: scan--; do { scan += OPND(s); s = *scan; /* assert() interferes w debug printouts */ if (OP(s) != O_QUEST && OP(s) != O_CH && OP(s) != OOR2) { g->iflags |= BAD; return; } } while (OP(s) != O_QUEST && OP(s) != O_CH); /* fallthrough */ default: /* things that break a sequence */ if (newlen > g->mlen) { /* ends one */ start = newstart; g->mlen = newlen; } newlen = 0; break; } } while (OP(s) != OEND); if (g->mlen == 0) /* there isn't one */ return; /* turn it into a character string */ g->must = malloc((size_t)g->mlen + 1); if (g->must == NULL) { /* argh; just forget it */ g->mlen = 0; return; } cp = g->must; scan = start; for (i = g->mlen; i > 0; i--) { while (OP(s = *scan++) != OCHAR) continue; assert(cp < g->must + g->mlen); *cp++ = (char)OPND(s); } assert(cp == g->must + g->mlen); *cp++ = '\0'; /* just on general principles */ } /* - pluscount - count + nesting == static sopno pluscount(register struct parse *p, register struct re_guts *g); */ static sopno /* nesting depth */ pluscount(p, g) struct parse *p; register struct re_guts *g; { register sop *scan; register sop s; register sopno plusnest = 0; register sopno maxnest = 0; if (p->error != 0) return(0); /* there may not be an OEND */ scan = g->strip + 1; do { s = *scan++; switch (OP(s)) { case OPLUS_: plusnest++; break; case O_PLUS: if (plusnest > maxnest) maxnest = plusnest; plusnest--; break; } } while (OP(s) != OEND); if (plusnest != 0) g->iflags |= BAD; return(maxnest); } http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/regcomp.ih?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/regcomp.ih +++ php-src/ext/ereg/regex/regcomp.ih /* ========= begin header generated by ../../regex/mkh ========= */ #ifdef __cplusplus extern "C" { #endif /* === ../../regex/regcomp.c === */ static void p_ere(register struct parse *p, int stop); static void p_ere_exp(register struct parse *p); static void p_str(register struct parse *p); static void p_bre(register struct parse *p, register int end1, register int end2); static int p_simp_re(register struct parse *p, int starordinary); static int p_count(register struct parse *p); static void p_bracket(register struct parse *p); static void p_b_term(register struct parse *p, register cset *cs); static void p_b_cclass(register struct parse *p, register cset *cs); static void p_b_eclass(register struct parse *p, register cset *cs); static char p_b_symbol(register struct parse *p); static char p_b_coll_elem(register struct parse *p, int endc); static char othercase(int ch); static void bothcases(register struct parse *p, int ch); static void ordinary(register struct parse *p, register int ch); static void nonnewline(register struct parse *p); static void repeat(register struct parse *p, sopno start, int from, int to); static int seterr(register struct parse *p, int e); static cset *allocset(register struct parse *p); static void freeset(register struct parse *p, register cset *cs); static int freezeset(register struct parse *p, register cset *cs); static int firstch(register struct parse *p, register cset *cs); static int nch(register struct parse *p, register cset *cs); static void mcadd(register struct parse *p, register cset *cs, register char *cp); static void mcinvert(register struct parse *p, register cset *cs); static void mccase(register struct parse *p, register cset *cs); static int isinsets(register struct re_guts *g, int c); static int samesets(register struct re_guts *g, int c1, int c2); static void categorize(struct parse *p, register struct re_guts *g); static sopno dupl(register struct parse *p, sopno start, sopno finish); static void doemit(register struct parse *p, sop op, size_t opnd); static void doinsert(register struct parse *p, sop op, size_t opnd, sopno pos); static void dofwd(register struct parse *p, sopno pos, sop value); static void enlarge(register struct parse *p, sopno size); static void stripsnug(register struct parse *p, register struct re_guts *g); static void findmust(register struct parse *p, register struct re_guts *g); static sopno pluscount(register struct parse *p, register struct re_guts *g); #ifdef __cplusplus } #endif /* ========= end header generated by ../../regex/mkh ========= */ http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/regerror.c?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/regerror.c +++ php-src/ext/ereg/regex/regerror.c #include <sys/types.h> #include <stdio.h> #include <string.h> #include <ctype.h> #include <limits.h> #include <stdlib.h> #include <regex.h> #include "utils.h" #include "regerror.ih" /* = #define REG_NOMATCH 1 = #define REG_BADPAT 2 = #define REG_ECOLLATE 3 = #define REG_ECTYPE 4 = #define REG_EESCAPE 5 = #define REG_ESUBREG 6 = #define REG_EBRACK 7 = #define REG_EPAREN 8 = #define REG_EBRACE 9 = #define REG_BADBR 10 = #define REG_ERANGE 11 = #define REG_ESPACE 12 = #define REG_BADRPT 13 = #define REG_EMPTY 14 = #define REG_ASSERT 15 = #define REG_INVARG 16 = #define REG_ATOI 255 // convert name to number (!) = #define REG_ITOA 0400 // convert number to name (!) */ static struct rerr { int code; char *name; char *explain; } rerrs[] = { { REG_NOMATCH, "REG_NOMATCH", "regexec() failed to match" }, { REG_BADPAT, "REG_BADPAT", "invalid regular expression" }, { REG_ECOLLATE, "REG_ECOLLATE", "invalid collating element" }, { REG_ECTYPE, "REG_ECTYPE", "invalid character class" }, { REG_EESCAPE, "REG_EESCAPE", "trailing backslash (\\)" }, { REG_ESUBREG, "REG_ESUBREG", "invalid backreference number" }, { REG_EBRACK, "REG_EBRACK", "brackets ([ ]) not balanced" }, { REG_EPAREN, "REG_EPAREN", "parentheses not balanced" }, { REG_EBRACE, "REG_EBRACE", "braces not balanced" }, { REG_BADBR, "REG_BADBR", "invalid repetition count(s)" }, { REG_ERANGE, "REG_ERANGE", "invalid character range" }, { REG_ESPACE, "REG_ESPACE", "out of memory" }, { REG_BADRPT, "REG_BADRPT", "repetition-operator operand invalid" }, { REG_EMPTY, "REG_EMPTY", "empty (sub)expression" }, { REG_ASSERT, "REG_ASSERT", "\"can't happen\" -- you found a bug" }, { REG_INVARG, "REG_INVARG", "invalid argument to regex routine" }, { 0, "", "*** unknown regexp error code ***" } }; /* - regerror - the interface to error numbers = API_EXPORT(size_t) regerror(int, const regex_t *, char *, size_t); */ /* ARGSUSED */ API_EXPORT(size_t) regerror(errcode, preg, errbuf, errbuf_size) int errcode; const regex_t *preg; char *errbuf; size_t errbuf_size; { register struct rerr *r; register size_t len; register int target = errcode &~ REG_ITOA; register char *s; char convbuf[50]; if (errcode == REG_ATOI) s = regatoi(preg, convbuf); else { for (r = rerrs; r->code != 0; r++) if (r->code == target) break; if (errcode®_ITOA) { if (r->code != 0) (void) strcpy(convbuf, r->name); else sprintf(convbuf, "REG_0x%x", target); assert(strlen(convbuf) < sizeof(convbuf)); s = convbuf; } else s = r->explain; } len = strlen(s) + 1; if (errbuf_size > 0) { if (errbuf_size > len) (void) strcpy(errbuf, s); else { (void) strncpy(errbuf, s, errbuf_size-1); errbuf[errbuf_size-1] = '\0'; } } return(len); } /* - regatoi - internal routine to implement REG_ATOI == static char *regatoi(const regex_t *preg, char *localbuf); */ static char * regatoi(preg, localbuf) const regex_t *preg; char *localbuf; { register struct rerr *r; for (r = rerrs; r->code != 0; r++) if (strcmp(r->name, preg->re_endp) == 0) break; if (r->code == 0) return("0"); sprintf(localbuf, "%d", r->code); return(localbuf); } http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/regerror.ih?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/regerror.ih +++ php-src/ext/ereg/regex/regerror.ih /* ========= begin header generated by ../../regex/mkh ========= */ #ifdef __cplusplus extern "C" { #endif /* === ../../regex/regerror.c === */ static char *regatoi(const regex_t *preg, char *localbuf); #ifdef __cplusplus } #endif /* ========= end header generated by ../../regex/mkh ========= */ http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/regex.3?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/regex.3 +++ php-src/ext/ereg/regex/regex.3..TH REGEX 3 "17 May 1993"..BY "Henry Spencer"..de ZR..\" one other place knows this name: the SEE ALSO section..IR regex (7) \\$1.....SH NAME regcomp, regexec, regerror, regfree \- regular-expression library..SH SYNOPSIS..ft B..\".na #include <sys/types.h>..br #include <regex.h>..HP 10 int regcomp(regex_t\ *preg, const\ char\ *pattern, int\ cflags);..HP int\ regexec(const\ regex_t\ *preg, const\ char\ *string, size_t\ nmatch, regmatch_t\ pmatch[], int\ eflags);..HP size_t\ regerror(int\ errcode, const\ regex_t\ *preg, char\ *errbuf, size_t\ errbuf_size);..HP void\ regfree(regex_t\ *preg);..\".ad..ft..SH DESCRIPTION These routines implement POSIX 1003.2 regular expressions (``RE''s); see..ZR ...I Regcomp compiles an RE written as a string into an internal form,..I regexec matches that internal form against a string and reports results,..I regerror transforms error codes from either into human-readable messages, and..I regfree frees any dynamically-allocated storage used by the internal form of an RE...PP The header..I <regex.h> declares two structure types,..I regex_t and..IR regmatch_t , the former for compiled internal forms and the latter for match reporting. It also declares the four functions, a type..IR regoff_t , and a number of constants with names starting with ``REG_''...PP..I Regcomp compiles the regular expression contained in the..I pattern string, subject to the flags in..IR cflags , and places the results in the..I regex_t structure pointed to by..IR preg ...I Cflags is the bitwise OR of zero or more of the following flags:..IP REG_EXTENDED \w'REG_EXTENDED'u+2n Compile modern (``extended'') REs, rather than the obsolete (``basic'') REs that are the default...IP REG_BASIC This is a synonym for 0, provided as a counterpart to REG_EXTENDED to improve readability...IP REG_NOSPEC Compile with recognition of all special characters turned off. All characters are thus considered ordinary, so the ``RE'' is a literal string. This is an extension, compatible with but not specified by POSIX 1003.2, and should be used with caution in software intended to be portable to other systems. REG_EXTENDED and REG_NOSPEC may not be used in the same call to..IR regcomp ...IP REG_ICASE Compile for matching that ignores upper/lower case distinctions. See..ZR ...IP REG_NOSUB Compile for matching that need only report success or failure, not what was matched...IP REG_NEWLINE Compile for newline-sensitive matching. By default, newline is a completely ordinary character with no special meaning in either REs or strings. With this flag, `[^' bracket expressions and `.' never match newline, a `^' anchor matches the null string after any newline in the string in addition to its normal function, and the `$' anchor matches the null string before any newline in the string in addition to its normal function...IP REG_PEND The regular expression ends, not at the first NUL, but just before the character pointed to by the..I re_endp member of the structure pointed to by..IR preg . The..I re_endp member is of type..IR const\ char\ * . This flag permits inclusion of NULs in the RE; they are considered ordinary characters. This is an extension, compatible with but not specified by POSIX 1003.2, and should be used with caution in software intended to be portable to other systems...PP When successful,..I regcomp returns 0 and fills in the structure pointed to by..IR preg . One member of that structure (other than..IR re_endp ) is publicized:..IR re_nsub , of type..IR size_t , contains the number of parenthesized subexpressions within the RE (except that the value of this member is undefined if the REG_NOSUB flag was used). If..I regcomp fails, it returns a non-zero error code; see DIAGNOSTICS...PP..I Regexec matches the compiled RE pointed to by..I preg against the..IR string , subject to the flags in..IR eflags , and reports results using..IR nmatch ,..IR pmatch , and the returned value. The RE must have been compiled by a previous invocation of..IR regcomp . The compiled form is not altered during execution of..IR regexec , so a single compiled RE can be used simultaneously by multiple threads...PP By default, the NUL-terminated string pointed to by..I string is considered to be the text of an entire line, minus any terminating newline. The..I eflags argument is the bitwise OR of zero or more of the following flags:..IP REG_NOTBOL \w'REG_STARTEND'u+2n The first character of the string is not the beginning of a line, so the `^' anchor should not match before it. This does not affect the behavior of newlines under REG_NEWLINE...IP REG_NOTEOL The NUL terminating the string does not end a line, so the `$' anchor should not match before it. This does not affect the behavior of newlines under REG_NEWLINE...IP REG_STARTEND The string is considered to start at \fIstring\fR\ + \fIpmatch\fR[0].\fIrm_so\fR and to have a terminating NUL located at \fIstring\fR\ + \fIpmatch\fR[0].\fIrm_eo\fR (there need not actually be a NUL at that location), regardless of the value of..IR nmatch . See below for the definition of..IR pmatch and..IR nmatch . This is an extension, compatible with but not specified by POSIX 1003.2, and should be used with caution in software intended to be portable to other systems. Note that a non-zero \fIrm_so\fR does not imply REG_NOTBOL; REG_STARTEND affects only the location of the string, not how it is matched...PP See..ZR for a discussion of what is matched in situations where an RE or a portion thereof could match any of several substrings of..IR string ...PP Normally,..I regexec returns 0 for success and the non-zero code REG_NOMATCH for failure. Other non-zero error codes may be returned in exceptional situations; see DIAGNOSTICS...PP If REG_NOSUB was specified in the compilation of the RE, or if..I nmatch is 0,..I regexec ignores the..I pmatch argument (but see below for the case where REG_STARTEND is specified). Otherwise,..I pmatch points to an array of..I nmatch structures of type..IR regmatch_t . Such a structure has at least the members..I rm_so and..IR rm_eo , both of type..I regoff_t (a signed arithmetic type at least as large as an..I off_t and a..IR ssize_t ), containing respectively the offset of the first character of a substring and the offset of the first character after the end of the substring. Offsets are measured from the beginning of the..I string argument given to..IR regexec . An empty substring is denoted by equal offsets, both indicating the character following the empty substring...PP The 0th member of the..I pmatch array is filled in to indicate what substring of..I string was matched by the entire RE. Remaining members report what substring was matched by parenthesized subexpressions within the RE; member..I i reports subexpression..IR i , with subexpressions counted (starting at 1) by the order of their opening parentheses in the RE, left to right. Unused entries in the array\(emcorresponding either to subexpressions that did not participate in the match at all, or to subexpressions that do not exist in the RE (that is, \fIi\fR\ > \fIpreg\fR\->\fIre_nsub\fR)\(emhave both..I rm_so and..I rm_eo set to \-1. If a subexpression participated in the match several times, the reported substring is the last one it matched. (Note, as an example in particular, that when the RE `(b*)+' matches `bbb', the parenthesized subexpression matches each of the three `b's and then an infinite number of empty strings following the last `b', so the reported substring is one of the empties.)..PP If REG_STARTEND is specified,..I pmatch must point to at least one..I regmatch_t (even if..I nmatch is 0 or REG_NOSUB was specified), to hold the input offsets for REG_STARTEND. Use for output is still entirely controlled by..IR nmatch ; if..I nmatch is 0 or REG_NOSUB was specified, the value of..IR pmatch [0] will not be changed by a successful..IR regexec ...PP..I Regerror maps a non-zero..I errcode from either..I regcomp or..I regexec to a human-readable, printable message. If..I preg is non-NULL, the error code should have arisen from use of the..I regex_t pointed to by..IR preg , and if the error code came from..IR regcomp , it should have been the result from the most recent..I regcomp using that..IR regex_t ...RI ( Regerror may be able to supply a more detailed message using information from the..IR regex_t .)..I Regerror places the NUL-terminated message into the buffer pointed to by..IR errbuf , limiting the length (including the NUL) to at most..I errbuf_size bytes. If the whole message won't fit, as much of it as will fit before the terminating NUL is supplied. In any case, the returned value is the size of buffer needed to hold the whole message (including terminating NUL). If..I errbuf_size is 0,..I errbuf is ignored but the return value is still correct...PP If the..I errcode given to..I regerror is first ORed with REG_ITOA, the ``message'' that results is the printable name of the error code, e.g. ``REG_NOMATCH'', rather than an explanation thereof. If..I errcode is REG_ATOI, then..I preg shall be non-NULL and the..I re_endp member of the structure it points to must point to the printable name of an error code; in this case, the result in..I errbuf is the decimal digits of the numeric value of the error code (0 if the name is not recognized). REG_ITOA and REG_ATOI are intended primarily as debugging facilities; they are extensions, compatible with but not specified by POSIX 1003.2, and should be used with caution in software intended to be portable to other systems. Be warned also that they are considered experimental and changes are possible...PP..I Regfree frees any dynamically-allocated storage associated with the compiled RE pointed to by..IR preg . The remaining..I regex_t is no longer a valid compiled RE and the effect of supplying it to..I regexec or..I regerror is undefined...PP None of these functions references global variables except for tables of constants; all are safe for use from multiple threads if the arguments are safe...SH IMPLEMENTATION CHOICES There are a number of decisions that 1003.2 leaves up to the implementor, either by explicitly saying ``undefined'' or by virtue of them being forbidden by the RE grammar. This implementation treats them as follows...PP See..ZR for a discussion of the definition of case-independent matching...PP There is no particular limit on the length of REs, except insofar as memory is limited. Memory usage is approximately linear in RE size, and largely insensitive to RE complexity, except for bounded repetitions. See BUGS for one short RE using them that will run almost any system out of memory...PP A backslashed character other than one specifically given a magic meaning by 1003.2 (such magic meanings occur only in obsolete [``basic''] REs) is taken as an ordinary character...PP Any unmatched [ is a REG_EBRACK error...PP Equivalence classes cannot begin or end bracket-expression ranges. The endpoint of one range cannot begin another...PP RE_DUP_MAX, the limit on repetition counts in bounded repetitions, is 255...PP A repetition operator (?, *, +, or bounds) cannot follow another repetition operator. A repetition operator cannot begin an expression or subexpression or follow `^' or `|'...PP `|' cannot appear first or last in a (sub)expression or after another `|', i.e. an operand of `|' cannot be an empty subexpression. An empty parenthesized subexpression, `()', is legal and matches an empty (sub)string. An empty string is not a legal RE...PP A `{' followed by a digit is considered the beginning of bounds for a bounded repetition, which must then follow the syntax for bounds. A `{' \fInot\fR followed by a digit is considered an ordinary character...PP `^' and `$' beginning and ending subexpressions in obsolete (``basic'') REs are anchors, not ordinary characters...SH SEE ALSO grep(1), regex(7)..PP POSIX 1003.2, sections 2.8 (Regular Expression Notation) and B.5 (C Binding for Regular Expression Matching)...SH DIAGNOSTICS Non-zero error codes from..I regcomp and..I regexec include the following:..PP..nf..ta \w'REG_ECOLLATE'u+3n REG_NOMATCH regexec() failed to match REG_BADPAT invalid regular expression REG_ECOLLATE invalid collating element REG_ECTYPE invalid character class REG_EESCAPE \e applied to unescapable character REG_ESUBREG invalid backreference number REG_EBRACK brackets [ ] not balanced REG_EPAREN parentheses ( ) not balanced REG_EBRACE braces { } not balanced REG_BADBR invalid repetition count(s) in { } REG_ERANGE invalid character range in [ ] REG_ESPACE ran out of memory REG_BADRPT ?, *, or + operand invalid REG_EMPTY empty (sub)expression REG_ASSERT ``can't happen''\(emyou found a bug REG_INVARG invalid argument, e.g. negative-length string..fi..SH HISTORY Written by Henry Spencer at University of Toronto, henry@zoo.toronto.edu...SH BUGS This is an alpha release with known defects. Please report problems...PP There is one known functionality bug. The implementation of internationalization is incomplete: the locale is always assumed to be the default one of 1003.2, and only the collating elements etc. of that locale are available...PP The back-reference code is subtle and doubts linger about its correctness in complex cases...PP..I Regexec performance is poor. This will improve with later releases...I Nmatch exceeding 0 is expensive;..I nmatch exceeding 1 is worse...I Regexec is largely insensitive to RE complexity \fIexcept\fR that back references are massively expensive. RE length does matter; in particular, there is a strong speed bonus for keeping RE length under about 30 characters, with most special characters counting roughly double...PP..I Regcomp implements bounded repetitions by macro expansion, which is costly in time and space if counts are large or bounded repetitions are nested. An RE like, say, `((((a{1,100}){1,100}){1,100}){1,100}){1,100}' will (eventually) run almost any existing machine out of swap space...PP There are suspected problems with response to obscure error conditions. Notably, certain kinds of internal overflow, produced only by truly enormous REs or by multiply nested bounded repetitions, are probably not handled well...PP Due to a mistake in 1003.2, things like `a)b' are legal REs because `)' is a special character only in the presence of a previous unmatched `('. This can't be fixed until the spec is fixed...PP The standard's definition of back references is vague. For example, does `a\e(\e(b\e)*\e2\e)*d' match `abbbd'? Until the standard is clarified, behavior in such cases should not be relied on...PP The implementation of word-boundary matching is a bit of a kludge, and bugs may lurk in combinations of word-boundary matching and anchoring. http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/regex.7?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/regex.7 +++ php-src/ext/ereg/regex/regex.7..TH REGEX 7 "7 Feb 1994"..BY "Henry Spencer"..SH NAME regex \- POSIX 1003.2 regular expressions..SH DESCRIPTION Regular expressions (``RE''s), as defined in POSIX 1003.2, come in two forms: modern REs (roughly those of..IR egrep ; 1003.2 calls these ``extended'' REs) and obsolete REs (roughly those of..IR ed ; 1003.2 ``basic'' REs). Obsolete REs mostly exist for backward compatibility in some old programs; they will be discussed at the end. 1003.2 leaves some aspects of RE syntax and semantics open; `\(dg' marks decisions on these aspects that may not be fully portable to other 1003.2 implementations...PP A (modern) RE is one\(dg or more non-empty\(dg \fIbranches\fR, separated by `|'. It matches anything that matches one of the branches...PP A branch is one\(dg or more \fIpieces\fR, concatenated. It matches a match for the first, followed by a match for the second, etc...PP A piece is an \fIatom\fR possibly followed by a single\(dg `*', `+', `?', or \fIbound\fR. An atom followed by `*' matches a sequence of 0 or more matches of the atom. An atom followed by `+' matches a sequence of 1 or more matches of the atom. An atom followed by `?' matches a sequence of 0 or 1 matches of the atom...PP A \fIbound\fR is `{' followed by an unsigned decimal integer, possibly followed by `,' possibly followed by another unsigned decimal integer, always followed by `}'. The integers must lie between 0 and RE_DUP_MAX (255\(dg) inclusive, and if there are two of them, the first may not exceed the second. An atom followed by a bound containing one integer \fIi\fR and no comma matches a sequence of exactly \fIi\fR matches of the atom. An atom followed by a bound containing one integer \fIi\fR and a comma matches a sequence of \fIi\fR or more matches of the atom. An atom followed by a bound containing two integers \fIi\fR and \fIj\fR matches a sequence of \fIi\fR through \fIj\fR (inclusive) matches of the atom...PP An atom is a regular expression enclosed in `()' (matching a match for the regular expression), an empty set of `()' (matching the null string)\(dg, a \fIbracket expression\fR (see below), `.' (matching any single character), `^' (matching the null string at the beginning of a line), `$' (matching the null string at the end of a line), a `\e' followed by one of the characters `^.[$()|*+?{\e' (matching that character taken as an ordinary character), a `\e' followed by any other character\(dg (matching that character taken as an ordinary character, as if the `\e' had not been present\(dg), or a single character with no other significance (matching that character). A `{' followed by a character other than a digit is an ordinary character, not the beginning of a bound\(dg. It is illegal to end an RE with `\e'...PP A \fIbracket expression\fR is a list of characters enclosed in `[]'. It normally matches any single character from the list (but see below). If the list begins with `^', it matches any single character (but see below) \fInot\fR from the rest of the list. If two characters in the list are separated by `\-', this is shorthand for the full \fIrange\fR of characters between those two (inclusive) in the collating sequence, e.g. `[0-9]' in ASCII matches any decimal digit. It is illegal\(dg for two ranges to share an endpoint, e.g. `a-c-e'. Ranges are very collating-sequence-dependent, and portable programs should avoid relying on them...PP To include a literal `]' in the list, make it the first character (following a possible `^'). To include a literal `\-', make it the first or last character, or the second endpoint of a range. To use a literal `\-' as the first endpoint of a range, enclose it in `[.' and `.]' to make it a collating element (see below). With the exception of these and some combinations using `[' (see next paragraphs), all other special characters, including `\e', lose their special significance within a bracket expression...PP Within a bracket expression, a collating element (a character, a multi-character sequence that collates as if it were a single character, or a collating-sequence name for either) enclosed in `[.' and `.]' stands for the sequence of characters of that collating element. The sequence is a single element of the bracket expression's list. A bracket expression containing a multi-character collating element can thus match more than one character, e.g. if the collating sequence includes a `ch' collating element, then the RE `[[.ch.]]*c' matches the first five characters of `chchcc'...PP Within a bracket expression, a collating element enclosed in `[=' and `=]' is an equivalence class, standing for the sequences of characters of all collating elements equivalent to that one, including itself. (If there are no other equivalent collating elements, the treatment is as if the enclosing delimiters were `[.' and `.]'.) For example, if o and \o'o^' are the members of an equivalence class, then `[[=o=]]', `[[=\o'o^'=]]', and `[o\o'o^']' are all synonymous. An equivalence class may not\(dg be an endpoint of a range...PP Within a bracket expression, the name of a \fIcharacter class\fR enclosed in `[:' and `:]' stands for the list of all characters belonging to that class. Standard character class names are:..PP..RS..nf..ta 3c 6c 9c alnum digit punct alpha graph space blank lower upper cntrl print xdigit..fi..RE..PP These stand for the character classes defined in..IR ctype (3). A locale may provide others. A character class may not be used as an endpoint of a range...PP There are two special cases\(dg of bracket expressions: the bracket expressions `[[:<:]]' and `[[:>:]]' match the null string at the beginning and end of a word respectively. A word is defined as a sequence of word characters which is neither preceded nor followed by word characters. A word character is an..I alnum character (as defined by..IR ctype (3)) or an underscore. This is an extension, compatible with but not specified by POSIX 1003.2, and should be used with caution in software intended to be portable to other systems...PP In the event that an RE could match more than one substring of a given string, the RE matches the one starting earliest in the string. If the RE could match more than one substring starting at that point, it matches the longest. Subexpressions also match the longest possible substrings, subject to the constraint that the whole match be as long as possible, with subexpressions starting earlier in the RE taking priority over ones starting later. Note that higher-level subexpressions thus take priority over their lower-level component subexpressions...PP Match lengths are measured in characters, not collating elements. A null string is considered longer than no match at all. For example, `bb*' matches the three middle characters of `abbbc', `(wee|week)(knights|nights)' matches all ten characters of `weeknights', when `(.*).*' is matched against `abc' the parenthesized subexpression matches all three characters, and when `(a*)*' is matched against `bc' both the whole RE and the parenthesized subexpression match the null string...PP If case-independent matching is specified, the effect is much as if all case distinctions had vanished from the alphabet. When an alphabetic that exists in multiple cases appears as an ordinary character outside a bracket expression, it is effectively transformed into a bracket expression containing both cases, e.g. `x' becomes `[xX]'. When it appears inside a bracket expression, all case counterparts of it are added to the bracket expression, so that (e.g.) `[x]' becomes `[xX]' and `[^x]' becomes `[^xX]'...PP No particular limit is imposed on the length of REs\(dg. Programs intended to be portable should not employ REs longer than 256 bytes, as an implementation can refuse to accept such REs and remain POSIX-compliant...PP Obsolete (``basic'') regular expressions differ in several respects. `|', `+', and `?' are ordinary characters and there is no equivalent for their functionality. The delimiters for bounds are `\e{' and `\e}', with `{' and `}' by themselves ordinary characters. The parentheses for nested subexpressions are `\e(' and `\e)', with `(' and `)' by themselves ordinary characters. `^' is an ordinary character except at the beginning of the RE or\(dg the beginning of a parenthesized subexpression, `$' is an ordinary character except at the end of the RE or\(dg the end of a parenthesized subexpression, and `*' is an ordinary character if it appears at the beginning of the RE or the beginning of a parenthesized subexpression (after a possible leading `^'). Finally, there is one new type of atom, a \fIback reference\fR: `\e' followed by a non-zero decimal digit \fId\fR matches the same sequence of characters matched by the \fId\fRth parenthesized subexpression (numbering subexpressions by the positions of their opening parentheses, left to right), so that (e.g.) `\e([bc]\e)\e1' matches `bb' or `cc' but not `bc'...SH SEE ALSO regex(3)..PP POSIX 1003.2, section 2.8 (Regular Expression Notation)...SH BUGS Having two kinds of REs is a botch...PP The current 1003.2 spec says that `)' is an ordinary character in the absence of an unmatched `('; this was an unintentional result of a wording error, and change is likely. Avoid relying on it...PP Back references are a dreadful botch, posing major problems for efficient implementations. They are also somewhat vaguely defined (does `a\e(\e(b\e)*\e2\e)*d' match `abbbd'?). Avoid using them...PP 1003.2's specification of case-independent matching is vague. The ``one case implies all cases'' definition given above is current consensus among implementors as to the right interpretation...PP The syntax for word boundaries is incredibly ugly. http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/regex.dsp?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/regex.dsp +++ php-src/ext/ereg/regex/regex.dsp # Microsoft Developer Studio Project File - Name="regex" - Package Owner=<4> # Microsoft Developer Studio Generated Build File, Format Version 5.00 # ** DO NOT EDIT ** # TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 CFG=regex - Win32 Debug !MESSAGE This is not a valid makefile. To build this project using NMAKE, !MESSAGE use the Export Makefile command and run !MESSAGE !MESSAGE NMAKE /f "regex.mak". !MESSAGE !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: !MESSAGE !MESSAGE NMAKE /f "regex.mak" CFG="regex - Win32 Debug" !MESSAGE !MESSAGE Possible choices for configuration are: !MESSAGE !MESSAGE "regex - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") !MESSAGE "regex - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") !MESSAGE # Begin Project # PROP Scc_ProjName "" # PROP Scc_LocalPath "" CPP=cl.exe MTL=midl.exe RSC=rc.exe !IF "$(CFG)" == "regex - Win32 Release" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 0 # PROP BASE Output_Dir "Release" # PROP BASE Intermediate_Dir "Release" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 0 # PROP Output_Dir "Release" # PROP Intermediate_Dir "Release" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c # ADD CPP /nologo /MT /W3 /GX /O2 /I "." /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32 # ADD BASE RSC /l 0x409 /d "NDEBUG" # ADD RSC /l 0x409 /d "NDEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 !ELSEIF "$(CFG)" == "regex - Win32 Debug" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 1 # PROP BASE Output_Dir "Debug" # PROP BASE Intermediate_Dir "Debug" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 1 # PROP Output_Dir "Debug" # PROP Intermediate_Dir "Debug" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c # ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /I "." /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32 # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept !ENDIF # Begin Target # Name "regex - Win32 Release" # Name "regex - Win32 Debug" # Begin Source File SOURCE=.\regcomp.c # End Source File # Begin Source File SOURCE=.\regerror.c # End Source File # Begin Source File SOURCE=.\regexec.c # End Source File # Begin Source File SOURCE=.\regfree.c # End Source File # End Target # End Project http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/regex.dsw?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/regex.dsw +++ php-src/ext/ereg/regex/regex.dsw Microsoft Developer Studio Workspace File, Format Version 5.00 # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! ############################################################################### Project: "regex"=.\regex.dsp - Package Owner=<4> Package=<5> {{{ }}} Package=<4> {{{ }}} ############################################################################### Global: Package=<5> {{{ }}} Package=<3> {{{ }}} ############################################################################### http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/regex.h?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/regex.h +++ php-src/ext/ereg/regex/regex.h #ifndef _REGEX_H_ #define _REGEX_H_ /* never again */ /* ========= begin header generated by ./mkh ========= */ #ifdef __cplusplus extern "C" { #endif /* === regex2.h === */ #ifdef WIN32 #define API_EXPORT(type) __declspec(dllexport) type __stdcall #else #define API_EXPORT(type) type #endif typedef off_t regoff_t; typedef struct { int re_magic; size_t re_nsub; /* number of parenthesized subexpressions */ const char *re_endp; /* end pointer for REG_PEND */ struct re_guts *re_g; /* none of your business :-) */ } regex_t; typedef struct { regoff_t rm_so; /* start of match */ regoff_t rm_eo; /* end of match */ } regmatch_t; /* === regcomp.c === */ API_EXPORT(int) regcomp(regex_t *, const char *, int); #define REG_BASIC 0000 #define REG_EXTENDED 0001 #define REG_ICASE 0002 #define REG_NOSUB 0004 #define REG_NEWLINE 0010 #define REG_NOSPEC 0020 #define REG_PEND 0040 #define REG_DUMP 0200 /* === regerror.c === */ #define REG_NOMATCH 1 #define REG_BADPAT 2 #define REG_ECOLLATE 3 #define REG_ECTYPE 4 #define REG_EESCAPE 5 #define REG_ESUBREG 6 #define REG_EBRACK 7 #define REG_EPAREN 8 #define REG_EBRACE 9 #define REG_BADBR 10 #define REG_ERANGE 11 #define REG_ESPACE 12 #define REG_BADRPT 13 #define REG_EMPTY 14 #define REG_ASSERT 15 #define REG_INVARG 16 #define REG_ATOI 255 /* convert name to number (!) */ #define REG_ITOA 0400 /* convert number to name (!) */ API_EXPORT(size_t) regerror(int, const regex_t *, char *, size_t); /* === regexec.c === */ API_EXPORT(int) regexec(const regex_t *, const char *, size_t, regmatch_t [], int); #define REG_NOTBOL 00001 #define REG_NOTEOL 00002 #define REG_STARTEND 00004 #define REG_TRACE 00400 /* tracing of execution */ #define REG_LARGE 01000 /* force large representation */ #define REG_BACKR 02000 /* force use of backref code */ /* === regfree.c === */ API_EXPORT(void) regfree(regex_t *); #ifdef __cplusplus } #endif /* ========= end header generated by ./mkh ========= */ #endif http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/regex.mak?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/regex.mak +++ php-src/ext/ereg/regex/regex.mak # Microsoft Developer Studio Generated NMAKE File, Based on regex.dsp !IF "$(CFG)" == "" CFG=regex - Win32 Release !MESSAGE No configuration specified. Defaulting to regex - Win32 Release. !ENDIF !IF "$(CFG)" != "regex - Win32 Release" && "$(CFG)" != "regex - Win32 Debug" !MESSAGE Invalid configuration "$(CFG)" specified. !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: !MESSAGE !MESSAGE NMAKE /f "regex.mak" CFG="regex - Win32 Release" !MESSAGE !MESSAGE Possible choices for configuration are: !MESSAGE !MESSAGE "regex - Win32 Release" (based on "Win32 (x86) Static Library") !MESSAGE "regex - Win32 Debug" (based on "Win32 (x86) Static Library") !MESSAGE !ERROR An invalid configuration is specified. !ENDIF !IF "$(OS)" == "Windows_NT" NULL= !ELSE NULL=nul !ENDIF CPP=cl.exe !IF "$(CFG)" == "regex - Win32 Release" OUTDIR=.\Release INTDIR=.\Release # Begin Custom Macros OutDir=.\.\Release # End Custom Macros !IF "$(RECURSE)" == "0" ALL : "$(OUTDIR)\regex.lib" !ELSE ALL : "$(OUTDIR)\regex.lib" !ENDIF CLEAN : -@erase "$(INTDIR)\regcomp.obj" -@erase "$(INTDIR)\regerror.obj" -@erase "$(INTDIR)\regexec.obj" -@erase "$(INTDIR)\regfree.obj" -@erase "$(INTDIR)\vc50.idb" -@erase "$(OUTDIR)\regex.lib" "$(OUTDIR)" : if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)" CPP_PROJ=/nologo /MD /W3 /GX /O2 /I "." /D "WIN32" /D "NDEBUG" /D "_WINDOWS"\ /Fp"$(INTDIR)\regex.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c CPP_OBJS=.\Release/ CPP_SBRS=. BSC32=bscmake.exe BSC32_FLAGS=/nologo /o"$(OUTDIR)\regex.bsc" BSC32_SBRS= \ LIB32=link.exe -lib LIB32_FLAGS=/nologo /out:"$(OUTDIR)\regex.lib" LIB32_OBJS= \ "$(INTDIR)\regcomp.obj" \ "$(INTDIR)\regerror.obj" \ "$(INTDIR)\regexec.obj" \ "$(INTDIR)\regfree.obj" "$(OUTDIR)\regex.lib" : "$(OUTDIR)" $(DEF_FILE) $(LIB32_OBJS) $(LIB32) @<< $(LIB32_FLAGS) $(DEF_FLAGS) $(LIB32_OBJS) << !ELSEIF "$(CFG)" == "regex - Win32 Debug" OUTDIR=.\Debug INTDIR=.\Debug # Begin Custom Macros OutDir=.\.\Debug # End Custom Macros !IF "$(RECURSE)" == "0" ALL : "$(OUTDIR)\regex.lib" "$(OUTDIR)\regex.bsc" !ELSE ALL : "$(OUTDIR)\regex.lib" "$(OUTDIR)\regex.bsc" !ENDIF CLEAN : -@erase "$(INTDIR)\regcomp.obj" -@erase "$(INTDIR)\regcomp.sbr" -@erase "$(INTDIR)\regerror.obj" -@erase "$(INTDIR)\regerror.sbr" -@erase "$(INTDIR)\regexec.obj" -@erase "$(INTDIR)\regexec.sbr" -@erase "$(INTDIR)\regfree.obj" -@erase "$(INTDIR)\regfree.sbr" -@erase "$(INTDIR)\vc50.idb" -@erase "$(OUTDIR)\regex.bsc" -@erase "$(OUTDIR)\regex.lib" "$(OUTDIR)" : if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)" CPP_PROJ=/nologo /MDd /W3 /GX /Z7 /Od /I "." /D "WIN32" /D "_DEBUG" /D\ "_WINDOWS" /FR"$(INTDIR)\\" /Fp"$(INTDIR)\regex.pch" /YX /Fo"$(INTDIR)\\"\ /Fd"$(INTDIR)\\" /FD /c CPP_OBJS=.\Debug/ CPP_SBRS=.\Debug/ BSC32=bscmake.exe BSC32_FLAGS=/nologo /o"$(OUTDIR)\regex.bsc" BSC32_SBRS= \ "$(INTDIR)\regcomp.sbr" \ "$(INTDIR)\regerror.sbr" \ "$(INTDIR)\regexec.sbr" \ "$(INTDIR)\regfree.sbr" "$(OUTDIR)\regex.bsc" : "$(OUTDIR)" $(BSC32_SBRS) $(BSC32) @<< $(BSC32_FLAGS) $(BSC32_SBRS) << LIB32=link.exe -lib LIB32_FLAGS=/nologo /out:"$(OUTDIR)\regex.lib" LIB32_OBJS= \ "$(INTDIR)\regcomp.obj" \ "$(INTDIR)\regerror.obj" \ "$(INTDIR)\regexec.obj" \ "$(INTDIR)\regfree.obj" "$(OUTDIR)\regex.lib" : "$(OUTDIR)" $(DEF_FILE) $(LIB32_OBJS) $(LIB32) @<< $(LIB32_FLAGS) $(DEF_FLAGS) $(LIB32_OBJS) << !ENDIF ..c{$(CPP_OBJS)}.obj:: $(CPP) @<< $(CPP_PROJ) $< << ..cpp{$(CPP_OBJS)}.obj:: $(CPP) @<< $(CPP_PROJ) $< << ..cxx{$(CPP_OBJS)}.obj:: $(CPP) @<< $(CPP_PROJ) $< << ..c{$(CPP_SBRS)}.sbr:: $(CPP) @<< $(CPP_PROJ) $< << ..cpp{$(CPP_SBRS)}.sbr:: $(CPP) @<< $(CPP_PROJ) $< << ..cxx{$(CPP_SBRS)}.sbr:: $(CPP) @<< $(CPP_PROJ) $< << !IF "$(CFG)" == "regex - Win32 Release" || "$(CFG)" == "regex - Win32 Debug" SOURCE=.\regcomp.c !IF "$(CFG)" == "regex - Win32 Release" DEP_CPP_REGCO=\ ".\cclass.h"\ ".\cname.h"\ ".\regcomp.ih"\ ".\regex.h"\ ".\regex2.h"\ ".\utils.h"\ "$(INTDIR)\regcomp.obj" : $(SOURCE) $(DEP_CPP_REGCO) "$(INTDIR)" !ELSEIF "$(CFG)" == "regex - Win32 Debug" DEP_CPP_REGCO=\ ".\cclass.h"\ ".\cname.h"\ ".\regcomp.ih"\ ".\regex.h"\ ".\regex2.h"\ ".\utils.h"\ {$(INCLUDE)}"sys\types.h"\ "$(INTDIR)\regcomp.obj" "$(INTDIR)\regcomp.sbr" : $(SOURCE) $(DEP_CPP_REGCO)\ "$(INTDIR)" !ENDIF SOURCE=.\regerror.c !IF "$(CFG)" == "regex - Win32 Release" DEP_CPP_REGER=\ ".\regerror.ih"\ ".\regex.h"\ ".\utils.h"\ "$(INTDIR)\regerror.obj" : $(SOURCE) $(DEP_CPP_REGER) "$(INTDIR)" !ELSEIF "$(CFG)" == "regex - Win32 Debug" DEP_CPP_REGER=\ ".\regerror.ih"\ ".\regex.h"\ ".\utils.h"\ {$(INCLUDE)}"sys\types.h"\ "$(INTDIR)\regerror.obj" "$(INTDIR)\regerror.sbr" : $(SOURCE) $(DEP_CPP_REGER)\ "$(INTDIR)" !ENDIF SOURCE=.\regexec.c !IF "$(CFG)" == "regex - Win32 Release" DEP_CPP_REGEX=\ ".\engine.c"\ ".\engine.ih"\ ".\regex.h"\ ".\regex2.h"\ ".\utils.h"\ "$(INTDIR)\regexec.obj" : $(SOURCE) $(DEP_CPP_REGEX) "$(INTDIR)" !ELSEIF "$(CFG)" == "regex - Win32 Debug" DEP_CPP_REGEX=\ ".\engine.c"\ ".\engine.ih"\ ".\regex.h"\ ".\regex2.h"\ ".\utils.h"\ {$(INCLUDE)}"sys\types.h"\ "$(INTDIR)\regexec.obj" "$(INTDIR)\regexec.sbr" : $(SOURCE) $(DEP_CPP_REGEX)\ "$(INTDIR)" !ENDIF SOURCE=.\regfree.c !IF "$(CFG)" == "regex - Win32 Release" DEP_CPP_REGFR=\ ".\regex.h"\ ".\regex2.h"\ ".\utils.h"\ "$(INTDIR)\regfree.obj" : $(SOURCE) $(DEP_CPP_REGFR) "$(INTDIR)" !ELSEIF "$(CFG)" == "regex - Win32 Debug" DEP_CPP_REGFR=\ ".\regex.h"\ ".\regex2.h"\ ".\utils.h"\ {$(INCLUDE)}"sys\types.h"\ "$(INTDIR)\regfree.obj" "$(INTDIR)\regfree.sbr" : $(SOURCE) $(DEP_CPP_REGFR)\ "$(INTDIR)" !ENDIF SOURCE=.\engine.c !ENDIF http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/regex2.h?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/regex2.h +++ php-src/ext/ereg/regex/regex2.h /* * First, the stuff that ends up in the outside-world include file = #ifdef WIN32 = #define API_EXPORT(type) __declspec(dllexport) type __stdcall = #else = #define API_EXPORT(type) type = #endif = = typedef off_t regoff_t; = typedef struct { = int re_magic; = size_t re_nsub; // number of parenthesized subexpressions = const char *re_endp; // end pointer for REG_PEND = struct re_guts *re_g; // none of your business :-) = } regex_t; = typedef struct { = regoff_t rm_so; // start of match = regoff_t rm_eo; // end of match = } regmatch_t; */ /* * internals of regex_t */ #define MAGIC1 ((('r'^0200)<<8) | 'e') /* * The internal representation is a *strip*, a sequence of * operators ending with an endmarker. (Some terminology etc. is a * historical relic of earlier versions which used multiple strips.) * Certain oddities in the representation are there to permit running * the machinery backwards; in particular, any deviation from sequential * flow must be marked at both its source and its destination. Some * fine points: * * - OPLUS_ and O_PLUS are *inside* the loop they create. * - OQUEST_ and O_QUEST are *outside* the bypass they create. * - OCH_ and O_CH are *outside* the multi-way branch they create, while * OOR1 and OOR2 are respectively the end and the beginning of one of * the branches. Note that there is an implicit OOR2 following OCH_ * and an implicit OOR1 preceding O_CH. * * In state representations, an operator's bit is on to signify a state * immediately *preceding* "execution" of that operator. */ typedef unsigned long sop; /* strip operator */ typedef long sopno; #define OPRMASK 0xf8000000 #define OPDMASK 0x07ffffff #define OPSHIFT ((unsigned)27) #define OP(n) ((n)&OPRMASK) #define OPND(n) ((n)&OPDMASK) #define SOP(op, opnd) ((op)|(opnd)) /* operators meaning operand */ /* (back, fwd are offsets) */ #define OEND (1<<OPSHIFT) /* endmarker - */ #define OCHAR (2<<OPSHIFT) /* character unsigned char */ #define OBOL (3<<OPSHIFT) /* left anchor - */ #define OEOL (4<<OPSHIFT) /* right anchor - */ #define OANY (5<<OPSHIFT) /* . - */ #define OANYOF (6<<OPSHIFT) /* [...] set number */ #define OBACK_ (7<<OPSHIFT) /* begin \d paren number */ #define O_BACK (8<<OPSHIFT) /* end \d paren number */ #define OPLUS_ (9<<OPSHIFT) /* + prefix fwd to suffix */ #define O_PLUS (10<<OPSHIFT) /* + suffix back to prefix */ #define OQUEST_ (11<<OPSHIFT) /* ? prefix fwd to suffix */ #define O_QUEST (12<<OPSHIFT) /* ? suffix back to prefix */ #define OLPAREN (13<<OPSHIFT) /* ( fwd to ) */ #define ORPAREN (14<<OPSHIFT) /* ) back to ( */ #define OCH_ (15<<OPSHIFT) /* begin choice fwd to OOR2 */ #define OOR1 (16u<<OPSHIFT) /* | pt. 1 back to OOR1 or OCH_ */ #define OOR2 (17u<<OPSHIFT) /* | pt. 2 fwd to OOR2 or O_CH */ #define O_CH (18u<<OPSHIFT) /* end choice back to OOR1 */ #define OBOW (19u<<OPSHIFT) /* begin word - */ #define OEOW (20u<<OPSHIFT) /* end word - */ /* * Structure for [] character-set representation. Character sets are * done as bit vectors, grouped 8 to a byte vector for compactness. * The individual set therefore has both a pointer to the byte vector * and a mask to pick out the relevant bit of each byte. A hash code * simplifies testing whether two sets could be identical. * * This will get trickier for multicharacter collating elements. As * preliminary hooks for dealing with such things, we also carry along * a string of multi-character elements, and decide the size of the * vectors at run time. */ typedef struct { uch *ptr; /* -> uch [csetsize] */ uch mask; /* bit within array */ uch hash; /* hash code */ size_t smultis; char *multis; /* -> char[smulti] ab\0cd\0ef\0\0 */ } cset; /* note that CHadd and CHsub are unsafe, and CHIN doesn't yield 0/1 */ #define CHadd(cs, c) ((cs)->ptr[(uch)(c)] |= (cs)->mask, (cs)->hash += (c)) #define CHsub(cs, c) ((cs)->ptr[(uch)(c)] &= ~(cs)->mask, (cs)->hash -= (c)) #define CHIN(cs, c) ((cs)->ptr[(uch)(c)] & (cs)->mask) #define MCadd(p, cs, cp) mcadd(p, cs, cp) /* regcomp() internal fns */ /* stuff for character categories */ typedef unsigned char cat_t; /* * main compiled-expression structure */ struct re_guts { int magic; # define MAGIC2 ((('R'^0200)<<8)|'E') sop *strip; /* malloced area for strip */ int csetsize; /* number of bits in a cset vector */ int ncsets; /* number of csets in use */ cset *sets; /* -> cset [ncsets] */ uch *setbits; /* -> uch[csetsize][ncsets/CHAR_BIT] */ int cflags; /* copy of regcomp() cflags argument */ sopno nstates; /* = number of sops */ sopno firststate; /* the initial OEND (normally 0) */ sopno laststate; /* the final OEND */ int iflags; /* internal flags */ # define USEBOL 01 /* used ^ */ # define USEEOL 02 /* used $ */ # define BAD 04 /* something wrong */ int nbol; /* number of ^ used */ int neol; /* number of $ used */ int ncategories; /* how many character categories */ cat_t *categories; /* ->catspace[-CHAR_MIN] */ char *must; /* match must contain this string */ int mlen; /* length of must */ size_t nsub; /* copy of re_nsub */ int backrefs; /* does it use back references? */ sopno nplus; /* how deep does it nest +s? */ /* catspace must be last */ cat_t catspace[1]; /* actually [NC] */ }; /* misc utilities */ #define OUT (CHAR_MAX+1) /* a non-character value */ #define ISWORD(c) (isalnum(c) || (c) == '_') http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/regexec.c?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/regexec.c +++ php-src/ext/ereg/regex/regexec.c /* * the outer shell of regexec() * * This file includes engine.c *twice*, after muchos fiddling with the * macros that code uses. This lets the same code operate on two different * representations for state sets. */ #include <sys/types.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <limits.h> #include <ctype.h> #include <regex.h> #include "utils.h" #include "regex2.h" #ifndef NDEBUG static int nope = 0; /* for use in asserts; shuts lint up */ #endif /* macros for manipulating states, small version */ #define states long #define states1 states /* for later use in regexec() decision */ #define CLEAR(v) ((v) = 0) #define SET0(v, n) ((v) &= ~(1 << (n))) #define SET1(v, n) ((v) |= 1 << (n)) #define ISSET(v, n) ((v) & (1 << (n))) #define ASSIGN(d, s) ((d) = (s)) #define EQ(a, b) ((a) == (b)) #define STATEVARS int dummy /* dummy version */ #define STATESETUP(m, n) /* nothing */ #define STATETEARDOWN(m) /* nothing */ #define SETUP(v) ((v) = 0) #define onestate int #define INIT(o, n) ((o) = (unsigned)1 << (n)) #define INC(o) ((o) <<= 1) #define ISSTATEIN(v, o) ((v) & (o)) /* some abbreviations; note that some of these know variable names! */ /* do "if I'm here, I can also be there" etc without branches */ #define FWD(dst, src, n) ((dst) |= ((unsigned)(src)&(here)) << (n)) #define BACK(dst, src, n) ((dst) |= ((unsigned)(src)&(here)) >> (n)) #define ISSETBACK(v, n) ((v) & ((unsigned)here >> (n))) /* function names */ #define SNAMES /* engine.c looks after details */ #include "engine.c" /* now undo things */ #undef states #undef CLEAR #undef SET0 #undef SET1 #undef ISSET #undef ASSIGN #undef EQ #undef STATEVARS #undef STATESETUP #undef STATETEARDOWN #undef SETUP #undef onestate #undef INIT #undef INC #undef ISSTATEIN #undef FWD #undef BACK #undef ISSETBACK #undef SNAMES /* macros for manipulating states, large version */ #define states char * #define CLEAR(v) memset(v, 0, m->g->nstates) #define SET0(v, n) ((v)[n] = 0) #define SET1(v, n) ((v)[n] = 1) #define ISSET(v, n) ((v)[n]) #define ASSIGN(d, s) memcpy(d, s, m->g->nstates) #define EQ(a, b) (memcmp(a, b, m->g->nstates) == 0) #define STATEVARS int vn; char *space #define STATESETUP(m, nv) { (m)->space = malloc((nv)*(m)->g->nstates); \ if ((m)->space == NULL) return(REG_ESPACE); \ (m)->vn = 0; } #define STATETEARDOWN(m) { free((m)->space); } #define SETUP(v) ((v) = &m->space[m->vn++ * m->g->nstates]) #define onestate int #define INIT(o, n) ((o) = (n)) #define INC(o) ((o)++) #define ISSTATEIN(v, o) ((v)[o]) /* some abbreviations; note that some of these know variable names! */ /* do "if I'm here, I can also be there" etc without branches */ #define FWD(dst, src, n) ((dst)[here+(n)] |= (src)[here]) #define BACK(dst, src, n) ((dst)[here-(n)] |= (src)[here]) #define ISSETBACK(v, n) ((v)[here - (n)]) /* function names */ #define LNAMES /* flag */ #include "engine.c" /* - regexec - interface for matching = API_EXPORT(int) regexec(const regex_t *, const char *, size_t, \ = regmatch_t [], int); = #define REG_NOTBOL 00001 = #define REG_NOTEOL 00002 = #define REG_STARTEND 00004 = #define REG_TRACE 00400 // tracing of execution = #define REG_LARGE 01000 // force large representation = #define REG_BACKR 02000 // force use of backref code * * We put this here so we can exploit knowledge of the state representation * when choosing which matcher to call. Also, by this point the matchers * have been prototyped. */ API_EXPORT(int) /* 0 success, REG_NOMATCH failure */ regexec(preg, string, nmatch, pmatch, eflags) const regex_t *preg; const char *string; size_t nmatch; regmatch_t pmatch[]; int eflags; { register struct re_guts *g = preg->re_g; #ifdef REDEBUG # define GOODFLAGS(f) (f) #else # define GOODFLAGS(f) ((f)&(REG_NOTBOL|REG_NOTEOL|REG_STARTEND)) #endif if (preg->re_magic != MAGIC1 || g->magic != MAGIC2) return(REG_BADPAT); assert(!(g->iflags&BAD)); if (g->iflags&BAD) /* backstop for no-debug case */ return(REG_BADPAT); eflags = GOODFLAGS(eflags); if (g->nstates <= CHAR_BIT*sizeof(states1) && !(eflags®_LARGE)) return(smatcher(g, (char *)string, nmatch, pmatch, eflags)); else return(lmatcher(g, (char *)string, nmatch, pmatch, eflags)); } http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/regfree.c?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/regfree.c +++ php-src/ext/ereg/regex/regfree.c #include <sys/types.h> #include <stdio.h> #include <stdlib.h> #include <regex.h> #include "utils.h" #include "regex2.h" /* - regfree - free everything = API_EXPORT(void) regfree(regex_t *); */ API_EXPORT(void) regfree(preg) regex_t *preg; { register struct re_guts *g; if (preg->re_magic != MAGIC1) /* oops */ return; /* nice to complain, but hard */ g = preg->re_g; if (g == NULL || g->magic != MAGIC2) /* oops again */ return; preg->re_magic = 0; /* mark it invalid */ g->magic = 0; /* mark it invalid */ if (g->strip != NULL) free((char *)g->strip); if (g->sets != NULL) free((char *)g->sets); if (g->setbits != NULL) free((char *)g->setbits); if (g->must != NULL) free(g->must); free((char *)g); } http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/split.c?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/split.c +++ php-src/ext/ereg/regex/split.c #include <stdio.h> #include <string.h> /* - split - divide a string into fields, like awk split() = int split(char *string, char *fields[], int nfields, char *sep); */ int /* number of fields, including overflow */ split(string, fields, nfields, sep) char *string; char *fields[]; /* list is not NULL-terminated */ int nfields; /* number of entries available in fields[] */ char *sep; /* "" white, "c" single char, "ab" [ab]+ */ { register char *p = string; register char c; /* latest character */ register char sepc = sep[0]; register char sepc2; register int fn; register char **fp = fields; register char *sepp; register int trimtrail; /* white space */ if (sepc == '\0') { while ((c = *p++) == ' ' || c == '\t') continue; p--; trimtrail = 1; sep = " \t"; /* note, code below knows this is 2 long */ sepc = ' '; } else trimtrail = 0; sepc2 = sep[1]; /* now we can safely pick this up */ /* catch empties */ if (*p == '\0') return(0); /* single separator */ if (sepc2 == '\0') { fn = nfields; for (;;) { *fp++ = p; fn--; if (fn == 0) break; while ((c = *p++) != sepc) if (c == '\0') return(nfields - fn); *(p-1) = '\0'; } /* we have overflowed the fields vector -- just count them */ fn = nfields; for (;;) { while ((c = *p++) != sepc) if (c == '\0') return(fn); fn++; } /* not reached */ } /* two separators */ if (sep[2] == '\0') { fn = nfields; for (;;) { *fp++ = p; fn--; while ((c = *p++) != sepc && c != sepc2) if (c == '\0') { if (trimtrail && **(fp-1) == '\0') fn++; return(nfields - fn); } if (fn == 0) break; *(p-1) = '\0'; while ((c = *p++) == sepc || c == sepc2) continue; p--; } /* we have overflowed the fields vector -- just count them */ fn = nfields; while (c != '\0') { while ((c = *p++) == sepc || c == sepc2) continue; p--; fn++; while ((c = *p++) != '\0' && c != sepc && c != sepc2) continue; } /* might have to trim trailing white space */ if (trimtrail) { p--; while ((c = *--p) == sepc || c == sepc2) continue; p++; if (*p != '\0') { if (fn == nfields+1) *p = '\0'; fn--; } } return(fn); } /* n separators */ fn = 0; for (;;) { if (fn < nfields) *fp++ = p; fn++; for (;;) { c = *p++; if (c == '\0') return(fn); sepp = sep; while ((sepc = *sepp++) != '\0' && sepc != c) continue; if (sepc != '\0') /* it was a separator */ break; } if (fn < nfields) *(p-1) = '\0'; for (;;) { c = *p++; sepp = sep; while ((sepc = *sepp++) != '\0' && sepc != c) continue; if (sepc == '\0') /* it wasn't a separator */ break; } p--; } /* not reached */ } #ifdef TEST_SPLIT /* * test program * pgm runs regression * pgm sep splits stdin lines by sep * pgm str sep splits str by sep * pgm str sep n splits str by sep n times */ int main(argc, argv) int argc; char *argv[]; { char buf[512]; register int n; # define MNF 10 char *fields[MNF]; if (argc > 4) for (n = atoi(argv[3]); n > 0; n--) { (void) strcpy(buf, argv[1]); } else if (argc > 3) for (n = atoi(argv[3]); n > 0; n--) { (void) strcpy(buf, argv[1]); (void) split(buf, fields, MNF, argv[2]); } else if (argc > 2) dosplit(argv[1], argv[2]); else if (argc > 1) while (fgets(buf, sizeof(buf), stdin) != NULL) { buf[strlen(buf)-1] = '\0'; /* stomp newline */ dosplit(buf, argv[1]); } else regress(); exit(0); } dosplit(string, seps) char *string; char *seps; { # define NF 5 char *fields[NF]; register int nf; nf = split(string, fields, NF, seps); print(nf, NF, fields); } print(nf, nfp, fields) int nf; int nfp; char *fields[]; { register int fn; register int bound; bound = (nf > nfp) ? nfp : nf; printf("%d:\t", nf); for (fn = 0; fn < bound; fn++) printf("\"%s\"%s", fields[fn], (fn+1 < nf) ? ", " : "\n"); } #define RNF 5 /* some table entries know this */ struct { char *str; char *seps; int nf; char *fi[RNF]; } tests[] = { "", " ", 0, { "" }, " ", " ", 2, { "", "" }, "x", " ", 1, { "x" }, "xy", " ", 1, { "xy" }, "x y", " ", 2, { "x", "y" }, "abc def g ", " ", 5, { "abc", "def", "", "g", "" }, " a bcd", " ", 4, { "", "", "a", "bcd" }, "a b c d e f", " ", 6, { "a", "b", "c", "d", "e f" }, " a b c d ", " ", 6, { "", "a", "b", "c", "d " }, "", " _", 0, { "" }, " ", " _", 2, { "", "" }, "x", " _", 1, { "x" }, "x y", " _", 2, { "x", "y" }, "ab _ cd", " _", 2, { "ab", "cd" }, " a_b c ", " _", 5, { "", "a", "b", "c", "" }, "a b c_d e f", " _", 6, { "a", "b", "c", "d", "e f" }, " a b c d ", " _", 6, { "", "a", "b", "c", "d " }, "", " _~", 0, { "" }, " ", " _~", 2, { "", "" }, "x", " _~", 1, { "x" }, "x y", " _~", 2, { "x", "y" }, "ab _~ cd", " _~", 2, { "ab", "cd" }, " a_b c~", " _~", 5, { "", "a", "b", "c", "" }, "a b_c d~e f", " _~", 6, { "a", "b", "c", "d", "e f" }, "~a b c d ", " _~", 6, { "", "a", "b", "c", "d " }, "", " _~-", 0, { "" }, " ", " _~-", 2, { "", "" }, "x", " _~-", 1, { "x" }, "x y", " _~-", 2, { "x", "y" }, "ab _~- cd", " _~-", 2, { "ab", "cd" }, " a_b c~", " _~-", 5, { "", "a", "b", "c", "" }, "a b_c-d~e f", " _~-", 6, { "a", "b", "c", "d", "e f" }, "~a-b c d ", " _~-", 6, { "", "a", "b", "c", "d " }, "", " ", 0, { "" }, " ", " ", 2, { "", "" }, "x", " ", 1, { "x" }, "xy", " ", 1, { "xy" }, "x y", " ", 2, { "x", "y" }, "abc def g ", " ", 4, { "abc", "def", "g", "" }, " a bcd", " ", 3, { "", "a", "bcd" }, "a b c d e f", " ", 6, { "a", "b", "c", "d", "e f" }, " a b c d ", " ", 6, { "", "a", "b", "c", "d " }, "", "", 0, { "" }, " ", "", 0, { "" }, "x", "", 1, { "x" }, "xy", "", 1, { "xy" }, "x y", "", 2, { "x", "y" }, "abc def g ", "", 3, { "abc", "def", "g" }, "\t a bcd", "", 2, { "a", "bcd" }, " a \tb\t c ", "", 3, { "a", "b", "c" }, "a b c d e ", "", 5, { "a", "b", "c", "d", "e" }, "a b\tc d e f", "", 6, { "a", "b", "c", "d", "e f" }, " a b c d e f ", "", 6, { "a", "b", "c", "d", "e f " }, NULL, NULL, 0, { NULL }, }; regress() { char buf[512]; register int n; char *fields[RNF+1]; register int nf; register int i; register int printit; register char *f; for (n = 0; tests[n].str != NULL; n++) { (void) strcpy(buf, tests[n].str); fields[RNF] = NULL; nf = split(buf, fields, RNF, tests[n].seps); printit = 0; if (nf != tests[n].nf) { printf("split `%s' by `%s' gave %d fields, not %d\n", tests[n].str, tests[n].seps, nf, tests[n].nf); printit = 1; } else if (fields[RNF] != NULL) { printf("split() went beyond array end\n"); printit = 1; } else { for (i = 0; i < nf && i < RNF; i++) { f = fields[i]; if (f == NULL) f = "(NULL)"; if (strcmp(f, tests[n].fi[i]) != 0) { printf("split `%s' by `%s', field %d is `%s', not `%s'\n", tests[n].str, tests[n].seps, i, fields[i], tests[n].fi[i]); printit = 1; } } } if (printit) print(nf, RNF, fields); } } #endif http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/utils.h?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/utils.h +++ php-src/ext/ereg/regex/utils.h /* utility definitions */ #ifndef _POSIX2_RE_DUP_MAX #define _POSIX2_RE_DUP_MAX 255 #endif #define DUPMAX _POSIX2_RE_DUP_MAX /* xxx is this right? */ #define INFINITY (DUPMAX + 1) #define NC (CHAR_MAX - CHAR_MIN + 1) typedef unsigned char uch; /* switch off assertions (if not already off) if no REDEBUG */ #ifndef REDEBUG #ifndef NDEBUG #define NDEBUG /* no assertions please */ #endif #endif #include <assert.h> /* for old systems with bcopy() but no memmove() */ #ifdef USEBCOPY #define memmove(d, s, c) bcopy(s, d, c) #endif http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/tests/.cvsignore?view=markup&rev=1.1 Index: php-src/ext/ereg/tests/.cvsignore +++ php-src/ext/ereg/tests/.cvsignore *.exp *.out *.php phpt.* http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/tests/001.phpt?view=markup&rev=1.1 Index: php-src/ext/ereg/tests/001.phpt +++ php-src/ext/ereg/tests/001.phpt --TEST-- RegReplace test 1 --POST-- --GET-- --FILE-- <?php $a="abc123"; echo ereg_replace("123","def",$a)?> --EXPECT-- abcdef http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/tests/002.phpt?view=markup&rev=1.1 Index: php-src/ext/ereg/tests/002.phpt +++ php-src/ext/ereg/tests/002.phpt --TEST-- RegReplace test 2 --POST-- --GET-- --FILE-- <?php $a="abc123"; echo ereg_replace("123","",$a)?> --EXPECT-- abc http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/tests/003.phpt?view=markup&rev=1.1 Index: php-src/ext/ereg/tests/003.phpt +++ php-src/ext/ereg/tests/003.phpt --TEST-- ereg_replace single-quote test --POST-- --GET-- --FILE-- <?php $a="\\'test"; echo ereg_replace("\\\\'","'",$a) ?> --EXPECT-- 'test http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/tests/004.phpt?view=markup&rev=1.1 Index: php-src/ext/ereg/tests/004.phpt +++ php-src/ext/ereg/tests/004.phpt --TEST-- simple ereg test --POST-- --GET-- --FILE-- <?php $a="This is a nice and simple string"; if (ereg(".*nice and simple.*",$a)) { echo "ok\n"; } if (!ereg(".*doesn't exist.*",$a)) { echo "ok\n"; } ?> --EXPECT-- ok ok http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/tests/005.phpt?view=markup&rev=1.1 Index: php-src/ext/ereg/tests/005.phpt +++ php-src/ext/ereg/tests/005.phpt --TEST-- Test Regular expression register support in ereg --POST-- --GET-- --FILE-- <?php $a="This is a nice and simple string"; echo ereg(".*(is).*(is).*",$a,$registers); echo "\n"; echo $registers[0]; echo "\n"; echo $registers[1]; echo "\n"; echo $registers[2]; echo "\n"; ?> --EXPECT-- 32 This is a nice and simple string is is http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/tests/006.phpt?view=markup&rev=1.1 Index: php-src/ext/ereg/tests/006.phpt +++ php-src/ext/ereg/tests/006.phpt --TEST-- Test ereg_replace of start-of-line --POST-- --GET-- --FILE-- <?php $a="This is a nice and simple string"; echo ereg_replace("^This","That",$a); ?> --EXPECT-- That is a nice and simple string http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/tests/007.phpt?view=markup&rev=1.1 Index: php-src/ext/ereg/tests/007.phpt +++ php-src/ext/ereg/tests/007.phpt --TEST-- Test empty result buffer in reg_replace --POST-- --GET-- --FILE-- <?php $a="abcd"; $b=ereg_replace("abcd","",$a); echo strlen($b); ?> --EXPECT-- 0 http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/tests/008.phpt?view=markup&rev=1.1 Index: php-src/ext/ereg/tests/008.phpt +++ php-src/ext/ereg/tests/008.phpt --TEST-- Test back-references in regular expressions --POST-- --GET-- --FILE-- <?php echo ereg_replace("([a-z]*)([-=+|]*)([0-9]+)","\\3 \\1 \\2\n","abc+-|=123"); ?> --EXPECT-- 123 abc +-|= http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/tests/009.phpt?view=markup&rev=1.1 Index: php-src/ext/ereg/tests/009.phpt +++ php-src/ext/ereg/tests/009.phpt --TEST-- Test split() --POST-- --GET-- --FILE-- <?php $a=split("[[:space:]]","this is a test"); echo count($a) . "\n"; for ($i = 0; $i < count($a); $i++) { echo $a[$i] . "\n"; } ?> --EXPECT-- 4 this is a test http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/tests/010.phpt?view=markup&rev=1.1 Index: php-src/ext/ereg/tests/010.phpt +++ php-src/ext/ereg/tests/010.phpt --TEST-- Long back references --POST-- --GET-- --FILE-- <?php $a="abc122222222223"; echo ereg_replace("1(2*)3","\\1def\\1",$a)?> --EXPECT-- abc2222222222def2222222222 http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/tests/011.phpt?view=markup&rev=1.1 Index: php-src/ext/ereg/tests/011.phpt +++ php-src/ext/ereg/tests/011.phpt --TEST-- \0 back reference --POST-- --GET-- --FILE-- <?php $a="abc123"; echo ereg_replace("123","def\\0ghi",$a)?> --EXPECT-- abcdef123ghi http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/tests/012.phpt?view=markup&rev=1.1 Index: php-src/ext/ereg/tests/012.phpt +++ php-src/ext/ereg/tests/012.phpt --TEST-- nonexisting back reference --POST-- --GET-- --FILE-- <?php $a="abc123"; echo ereg_replace("123",'def\1ghi',$a)?> --EXPECT-- abcdef\1ghi http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/tests/013.phpt?view=markup&rev=1.1 Index: php-src/ext/ereg/tests/013.phpt +++ php-src/ext/ereg/tests/013.phpt --TEST-- escapes in replace string --POST-- --GET-- --FILE-- <?php $a="abc123"; echo ereg_replace("123","def\\g\\\\hi\\",$a)?> --EXPECT-- abcdef\g\\hi\ http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/tests/014.phpt?view=markup&rev=1.1 Index: php-src/ext/ereg/tests/014.phpt +++ php-src/ext/ereg/tests/014.phpt --TEST-- backreferences not replaced recursively --POST-- --GET-- --FILE-- <?php $a="a\\2bxc"; echo ereg_replace("a(.*)b(.*)c","\\1",$a)?> --EXPECT-- \2 http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/tests/015.phpt?view=markup&rev=1.1 Index: php-src/ext/ereg/tests/015.phpt +++ php-src/ext/ereg/tests/015.phpt --TEST-- replace empty matches --POST-- --GET-- --FILE-- <?php echo ereg_replace("^","z","abc123")?> --EXPECT-- zabc123 http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/tests/016.phpt?view=markup&rev=1.1 Index: php-src/ext/ereg/tests/016.phpt +++ php-src/ext/ereg/tests/016.phpt --TEST-- test backslash handling in regular expressions --POST-- --GET-- --FILE-- <?php echo ereg_replace('\?',"abc","?123?")?> --EXPECT-- abc123abc
http://cvs.php.net/viewvc.cgi/php-src/configure.in?r1=1.579.2.52.2.77.2.4&r2=1.579.2.52.2.77.2.5&diff_format=u Index: php-src/configure.in diff -u php-src/configure.in:1.579.2.52.2.77.2.4 php-src/configure.in:1.579.2.52.2.77.2.5 --- php-src/configure.in:1.579.2.52.2.77.2.4 Fri Oct 5 14:48:32 2007 +++ php-src/configure.in Fri Oct 5 15:00:05 2007 @@ -1,4 +1,4 @@ -## $Id: configure.in,v 1.579.2.52.2.77.2.4 2007/10/05 14:48:32 nlopess Exp $ -*- autoconf -*- +## $Id: configure.in,v 1.579.2.52.2.77.2.5 2007/10/05 15:00:05 jani Exp $ -*- autoconf -*- dnl ## Process this file with autoconf to produce a configure script. divert(1) @@ -11,9 +11,9 @@ dnl ## libraries and so on. dnl ## In diversion 3 we check for compile-time options to the PHP -dnl ## core and how to deal with different system dependencies. This -dnl ## includes what regex library is used and whether debugging or short -dnl ## tags are enabled, and the default behaviour of php.ini options. +dnl ## core and how to deal with different system dependencies. +dnl ## This includes whether debugging or short tags are enabled +dnl ## and the default behaviour of php.ini options. dnl ## This is also where an SAPI interface is selected (choosing between dnl ## Apache module, CGI etc.) @@ -270,10 +270,9 @@ divert(3) dnl ## In diversion 3 we check for compile-time options to the PHP -dnl ## core and how to deal with different system dependencies. This -dnl ## includes what regex library is used and whether debugging or short -dnl ## tags are enabled, and the default behaviour of php.ini options. - +dnl ## core and how to deal with different system dependencies. +dnl ## This includes whether debugging or short tags are enabled +dnl ## and the default behaviour of php.ini options. dnl Starting system checks. dnl ------------------------------------------------------------------------- @@ -518,7 +517,6 @@ realpath \ random \ rand_r \ -regcomp \ res_search \ scandir \ setitimer \ @@ -1292,7 +1290,7 @@ PHP_SUBST(all_targets) PHP_SUBST(install_targets) -PHP_INSTALL_HEADERS([Zend/ TSRM/ include/ main/ main/streams/ regex/]) +PHP_INSTALL_HEADERS([Zend/ TSRM/ include/ main/ main/streams/]) PHP_ADD_SOURCES(TSRM, TSRM.c tsrm_strtok_r.c tsrm_virtual_cwd.c) @@ -1345,7 +1343,6 @@ PHP_ADD_SOURCES_X(Zend, zend_execute.c,,PHP_GLOBAL_OBJS,,$flag) PHP_ADD_BUILD_DIR(main main/streams) -PHP_ADD_BUILD_DIR(regex) PHP_ADD_BUILD_DIR(sapi/$PHP_SAPI sapi/cli) PHP_ADD_BUILD_DIR(TSRM) PHP_ADD_BUILD_DIR(Zend) http://cvs.php.net/viewvc.cgi/php-src/ext/pgsql/pgsql.c?r1=1.331.2.13.2.24.2.2&r2=1.331.2.13.2.24.2.3&diff_format=u Index: php-src/ext/pgsql/pgsql.c diff -u php-src/ext/pgsql/pgsql.c:1.331.2.13.2.24.2.2 php-src/ext/pgsql/pgsql.c:1.331.2.13.2.24.2.3 --- php-src/ext/pgsql/pgsql.c:1.331.2.13.2.24.2.2 Wed Oct 3 23:30:46 2007 +++ php-src/ext/pgsql/pgsql.c Fri Oct 5 15:00:08 2007 @@ -20,7 +20,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: pgsql.c,v 1.331.2.13.2.24.2.2 2007/10/03 23:30:46 iliaa Exp $ */ +/* $Id: pgsql.c,v 1.331.2.13.2.24.2.3 2007/10/05 15:00:08 jani Exp $ */ #include <stdlib.h> @@ -36,6 +36,7 @@ #include "php_ini.h" #include "ext/standard/php_standard.h" #include "ext/standard/php_smart_str.h" +#include "ext/ereg/php_regex.h" #undef PACKAGE_BUGREPORT #undef PACKAGE_NAME http://cvs.php.net/viewvc.cgi/php-src/ext/standard/basic_functions.c?r1=1.725.2.31.2.64.2.5&r2=1.725.2.31.2.64.2.6&diff_format=u Index: php-src/ext/standard/basic_functions.c diff -u php-src/ext/standard/basic_functions.c:1.725.2.31.2.64.2.5 php-src/ext/standard/basic_functions.c:1.725.2.31.2.64.2.6 --- php-src/ext/standard/basic_functions.c:1.725.2.31.2.64.2.5 Mon Oct 1 20:36:01 2007 +++ php-src/ext/standard/basic_functions.c Fri Oct 5 15:00:08 2007 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: basic_functions.c,v 1.725.2.31.2.64.2.5 2007/10/01 20:36:01 johannes Exp $ */ +/* $Id: basic_functions.c,v 1.725.2.31.2.64.2.6 2007/10/05 15:00:08 jani Exp $ */ #include "php.h" #include "php_streams.h" @@ -2203,54 +2203,6 @@ ZEND_BEGIN_ARG_INFO(arginfo_mt_getrandmax, 0) ZEND_END_ARG_INFO() /* }}} */ -/* {{{ reg.c */ -static -ZEND_BEGIN_ARG_INFO_EX(arginfo_ereg, 0, 0, 2) - ZEND_ARG_INFO(0, pattern) - ZEND_ARG_INFO(0, string) - ZEND_ARG_INFO(1, registers) /* ARRAY_INFO(1, registers, 1) */ -ZEND_END_ARG_INFO() - -static -ZEND_BEGIN_ARG_INFO_EX(arginfo_eregi, 0, 0, 2) - ZEND_ARG_INFO(0, pattern) - ZEND_ARG_INFO(0, string) - ZEND_ARG_INFO(1, registers) /* ARRAY_INFO(1, registers, 1) */ -ZEND_END_ARG_INFO() - -static -ZEND_BEGIN_ARG_INFO(arginfo_ereg_replace, 0) - ZEND_ARG_INFO(0, pattern) - ZEND_ARG_INFO(0, replacement) - ZEND_ARG_INFO(0, string) -ZEND_END_ARG_INFO() - -static -ZEND_BEGIN_ARG_INFO(arginfo_eregi_replace, 0) - ZEND_ARG_INFO(0, pattern) - ZEND_ARG_INFO(0, replacement) - ZEND_ARG_INFO(0, string) -ZEND_END_ARG_INFO() - -static -ZEND_BEGIN_ARG_INFO_EX(arginfo_split, 0, 0, 2) - ZEND_ARG_INFO(0, pattern) - ZEND_ARG_INFO(0, string) - ZEND_ARG_INFO(0, limit) -ZEND_END_ARG_INFO() - -static -ZEND_BEGIN_ARG_INFO_EX(arginfo_spliti, 0, 0, 2) - ZEND_ARG_INFO(0, pattern) - ZEND_ARG_INFO(0, string) - ZEND_ARG_INFO(0, limit) -ZEND_END_ARG_INFO() - -static -ZEND_BEGIN_ARG_INFO(arginfo_sql_regcase, 0) - ZEND_ARG_INFO(0, string) -ZEND_END_ARG_INFO() -/* }}} */ /* {{{ sha1.c */ static ZEND_BEGIN_ARG_INFO_EX(arginfo_sha1, 0, 0, 1) @@ -3202,6 +3154,7 @@ PHP_FE(similar_text, arginfo_similar_text) PHP_FE(explode, arginfo_explode) PHP_FE(implode, arginfo_implode) + PHP_FALIAS(join, implode, arginfo_implode) PHP_FE(setlocale, arginfo_setlocale) PHP_FE(localeconv, arginfo_localeconv) @@ -3478,16 +3431,6 @@ PHP_FE(is_scalar, arginfo_is_scalar) PHP_FE(is_callable, arginfo_is_callable) - /* functions from reg.c */ - PHP_FE(ereg, arginfo_ereg) - PHP_FE(ereg_replace, arginfo_ereg_replace) - PHP_FE(eregi, arginfo_eregi) - PHP_FE(eregi_replace, arginfo_eregi_replace) - PHP_FE(split, arginfo_split) - PHP_FE(spliti, arginfo_spliti) - PHP_FALIAS(join, implode, arginfo_implode) - PHP_FE(sql_regcase, arginfo_sql_regcase) - /* functions from dl.c */ PHP_FE(dl, arginfo_dl) @@ -4043,7 +3986,6 @@ register_html_constants(INIT_FUNC_ARGS_PASSTHRU); register_string_constants(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(regex)(INIT_FUNC_ARGS_PASSTHRU); PHP_MINIT(file)(INIT_FUNC_ARGS_PASSTHRU); PHP_MINIT(pack)(INIT_FUNC_ARGS_PASSTHRU); PHP_MINIT(browscap)(INIT_FUNC_ARGS_PASSTHRU); @@ -4121,7 +4063,6 @@ UNREGISTER_INI_ENTRIES(); - PHP_MSHUTDOWN(regex)(SHUTDOWN_FUNC_ARGS_PASSTHRU); PHP_MSHUTDOWN(browscap)(SHUTDOWN_FUNC_ARGS_PASSTHRU); PHP_MSHUTDOWN(array)(SHUTDOWN_FUNC_ARGS_PASSTHRU); PHP_MSHUTDOWN(assert)(SHUTDOWN_FUNC_ARGS_PASSTHRU); @@ -4234,7 +4175,6 @@ PHP_MINFO_FUNCTION(basic) /* {{{ */ { php_info_print_table_start(); - PHP_MINFO(regex)(ZEND_MODULE_INFO_FUNC_ARGS_PASSTHRU); PHP_MINFO(dl)(ZEND_MODULE_INFO_FUNC_ARGS_PASSTHRU); PHP_MINFO(mail)(ZEND_MODULE_INFO_FUNC_ARGS_PASSTHRU); php_info_print_table_end(); http://cvs.php.net/viewvc.cgi/php-src/ext/standard/browscap.c?r1=1.85.2.2.2.3.2.2&r2=1.85.2.2.2.3.2.3&diff_format=u Index: php-src/ext/standard/browscap.c diff -u php-src/ext/standard/browscap.c:1.85.2.2.2.3.2.2 php-src/ext/standard/browscap.c:1.85.2.2.2.3.2.3 --- php-src/ext/standard/browscap.c:1.85.2.2.2.3.2.2 Sun Sep 30 05:49:44 2007 +++ php-src/ext/standard/browscap.c Fri Oct 5 15:00:08 2007 @@ -16,10 +16,10 @@ +----------------------------------------------------------------------+ */ -/* $Id: browscap.c,v 1.85.2.2.2.3.2.2 2007/09/30 05:49:44 jani Exp $ */ +/* $Id: browscap.c,v 1.85.2.2.2.3.2.3 2007/10/05 15:00:08 jani Exp $ */ #include "php.h" -#include "php_regex.h" +#include "ext/ereg/php_regex.h" #include "php_browscap.h" #include "php_ini.h" #include "php_string.h" http://cvs.php.net/viewvc.cgi/php-src/ext/standard/config.m4?r1=1.80.2.3.2.3.2.1&r2=1.80.2.3.2.3.2.2&diff_format=u Index: php-src/ext/standard/config.m4 diff -u php-src/ext/standard/config.m4:1.80.2.3.2.3.2.1 php-src/ext/standard/config.m4:1.80.2.3.2.3.2.2 --- php-src/ext/standard/config.m4:1.80.2.3.2.3.2.1 Mon Oct 1 12:40:54 2007 +++ php-src/ext/standard/config.m4 Fri Oct 5 15:00:08 2007 @@ -1,4 +1,4 @@ -dnl $Id: config.m4,v 1.80.2.3.2.3.2.1 2007/10/01 12:40:54 jani Exp $ -*- autoconf -*- +dnl $Id: config.m4,v 1.80.2.3.2.3.2.2 2007/10/05 15:00:08 jani Exp $ -*- autoconf -*- divert(3)dnl @@ -208,52 +208,6 @@ divert(5)dnl dnl -dnl Check for regex library type -dnl -PHP_ARG_WITH(regex,, -[ --with-regex=TYPE regex library type: system, apache, php. [TYPE=php] - WARNING: Do NOT use unless you know what you are doing!], php, no) - -case $PHP_REGEX in - system) - if test "$PHP_SAPI" = "apache" || test "$PHP_SAPI" = "apache2filter" || test "$PHP_SAPI" = "apache2handler"; then - REGEX_TYPE=php - else - REGEX_TYPE=system - fi - ;; - apache) - REGEX_TYPE=apache - ;; - php) - REGEX_TYPE=php - ;; - *) - REGEX_TYPE=php - AC_MSG_WARN(Invalid regex library type selected. Using default value: php) - ;; -esac - -if test "$REGEX_TYPE" = "php"; then - AC_DEFINE(HAVE_REGEX_T_RE_MAGIC, 1, [ ]) - AC_DEFINE(HSREGEX,1,[ ]) - AC_DEFINE(REGEX,1,[ ]) - PHP_ADD_SOURCES(regex, regcomp.c regexec.c regerror.c regfree.c) -elif test "$REGEX_TYPE" = "system"; then - AC_DEFINE(REGEX,0,[ ]) - dnl Check if field re_magic exists in struct regex_t - AC_CACHE_CHECK([whether field re_magic exists in struct regex_t], ac_cv_regex_t_re_magic, [ - AC_TRY_COMPILE([#include <sys/types.h> -#include <regex.h>], [regex_t rt; rt.re_magic;], - [ac_cv_regex_t_re_magic=yes], [ac_cv_regex_t_re_magic=no])]) - if test "$ac_cv_regex_t_re_magic" = "yes"; then - AC_DEFINE([HAVE_REGEX_T_RE_MAGIC], [ ], 1) - fi -fi -AC_MSG_CHECKING([which regex library to use]) -AC_MSG_RESULT([$REGEX_TYPE]) - -dnl dnl round fuzz dnl AC_MSG_CHECKING([whether rounding works as expected]) @@ -502,7 +456,7 @@ flock_compat.c formatted_print.c fsock.c head.c html.c image.c \ info.c iptc.c lcg.c link.c mail.c math.c md5.c metaphone.c \ microtime.c pack.c pageinfo.c quot_print.c rand.c \ - reg.c soundex.c string.c scanf.c syslog.c type.c uniqid.c url.c \ + soundex.c string.c scanf.c syslog.c type.c uniqid.c url.c \ url_scanner.c var.c versioning.c assert.c strnatcmp.c levenshtein.c \ incomplete_class.c url_scanner_ex.c ftp_fopen_wrapper.c \ http_fopen_wrapper.c php_fopen_wrapper.c credits.c css.c \ http://cvs.php.net/viewvc.cgi/php-src/ext/standard/config.w32?r1=1.4.2.2.2.1&r2=1.4.2.2.2.1.2.1&diff_format=u Index: php-src/ext/standard/config.w32 diff -u php-src/ext/standard/config.w32:1.4.2.2.2.1 php-src/ext/standard/config.w32:1.4.2.2.2.1.2.1 --- php-src/ext/standard/config.w32:1.4.2.2.2.1 Wed Apr 18 09:38:54 2007 +++ php-src/ext/standard/config.w32 Fri Oct 5 15:00:08 2007 @@ -1,5 +1,5 @@ // vim:ft=javascript -// $Id: config.w32,v 1.4.2.2.2.1 2007/04/18 09:38:54 rrichards Exp $ +// $Id: config.w32,v 1.4.2.2.2.1.2.1 2007/10/05 15:00:08 jani Exp $ ARG_WITH("config-file-scan-dir", "Dir to check for additional php ini files", ""); AC_DEFINE("PHP_CONFIG_FILE_SCAN_DIR", PHP_CONFIG_FILE_SCAN_DIR); @@ -10,7 +10,7 @@ crc32.c crypt.c cyr_convert.c datetime.c dir.c dl.c dns.c exec.c \ file.c filestat.c formatted_print.c fsock.c head.c html.c image.c \ info.c iptc.c lcg.c link.c mail.c math.c md5.c metaphone.c microtime.c \ - pack.c pageinfo.c quot_print.c rand.c reg.c soundex.c \ + pack.c pageinfo.c quot_print.c rand.c soundex.c \ string.c scanf.c syslog.c type.c uniqid.c url.c url_scanner.c var.c \ versioning.c assert.c strnatcmp.c levenshtein.c incomplete_class.c \ url_scanner_ex.c ftp_fopen_wrapper.c http_fopen_wrapper.c \ http://cvs.php.net/viewvc.cgi/php-src/ext/standard/html.c?r1=1.111.2.2.2.14.2.1&r2=1.111.2.2.2.14.2.2&diff_format=u Index: php-src/ext/standard/html.c diff -u php-src/ext/standard/html.c:1.111.2.2.2.14.2.1 php-src/ext/standard/html.c:1.111.2.2.2.14.2.2 --- php-src/ext/standard/html.c:1.111.2.2.2.14.2.1 Wed Oct 3 05:05:08 2007 +++ php-src/ext/standard/html.c Fri Oct 5 15:00:08 2007 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: html.c,v 1.111.2.2.2.14.2.1 2007/10/03 05:05:08 stas Exp $ */ +/* $Id: html.c,v 1.111.2.2.2.14.2.2 2007/10/05 15:00:08 jani Exp $ */ /* * HTML entity resources: @@ -37,7 +37,6 @@ #else #include <php_config.h> #endif -#include "reg.h" #include "html.h" #include "php_string.h" #include "SAPI.h" http://cvs.php.net/viewvc.cgi/php-src/ext/standard/php_standard.h?r1=1.24.2.2.2.1&r2=1.24.2.2.2.1.2.1&diff_format=u Index: php-src/ext/standard/php_standard.h diff -u php-src/ext/standard/php_standard.h:1.24.2.2.2.1 php-src/ext/standard/php_standard.h:1.24.2.2.2.1.2.1 --- php-src/ext/standard/php_standard.h:1.24.2.2.2.1 Mon Jan 1 09:36:08 2007 +++ php-src/ext/standard/php_standard.h Fri Oct 5 15:00:08 2007 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_standard.h,v 1.24.2.2.2.1 2007/01/01 09:36:08 sebastian Exp $ */ +/* $Id: php_standard.h,v 1.24.2.2.2.1.2.1 2007/10/05 15:00:08 jani Exp $ */ #include "basic_functions.h" #include "php_math.h" @@ -24,7 +24,6 @@ #include "base64.h" #include "php_dir.h" #include "dns.h" -#include "reg.h" #include "php_mail.h" #include "md5.h" #include "sha1.h" http://cvs.php.net/viewvc.cgi/php-src/ext/standard/string.c?r1=1.445.2.14.2.69.2.3&r2=1.445.2.14.2.69.2.4&diff_format=u Index: php-src/ext/standard/string.c diff -u php-src/ext/standard/string.c:1.445.2.14.2.69.2.3 php-src/ext/standard/string.c:1.445.2.14.2.69.2.4 --- php-src/ext/standard/string.c:1.445.2.14.2.69.2.3 Mon Oct 1 13:38:14 2007 +++ php-src/ext/standard/string.c Fri Oct 5 15:00:08 2007 @@ -18,13 +18,12 @@ +----------------------------------------------------------------------+ */ -/* $Id: string.c,v 1.445.2.14.2.69.2.3 2007/10/01 13:38:14 jani Exp $ */ +/* $Id: string.c,v 1.445.2.14.2.69.2.4 2007/10/05 15:00:08 jani Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ #include <stdio.h> #include "php.h" -#include "reg.h" #include "php_rand.h" #include "php_string.h" #include "php_variables.h" http://cvs.php.net/viewvc.cgi/php-src/main/php.h?r1=1.221.2.4.2.8&r2=1.221.2.4.2.8.2.1&diff_format=u Index: php-src/main/php.h diff -u php-src/main/php.h:1.221.2.4.2.8 php-src/main/php.h:1.221.2.4.2.8.2.1 --- php-src/main/php.h:1.221.2.4.2.8 Fri Aug 31 07:48:05 2007 +++ php-src/main/php.h Fri Oct 5 15:00:09 2007 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php.h,v 1.221.2.4.2.8 2007/08/31 07:48:05 jani Exp $ */ +/* $Id: php.h,v 1.221.2.4.2.8.2.1 2007/10/05 15:00:09 jani Exp $ */ #ifndef PHP_H #define PHP_H @@ -71,8 +71,6 @@ #define PHP_OS PHP_UNAME #endif -#include "php_regex.h" - #if HAVE_ASSERT_H #if PHP_DEBUG #undef NDEBUG @@ -193,10 +191,6 @@ char *strerror(int); #endif -#if (REGEX == 1 || REGEX == 0) && !defined(NO_REGEX_EXTRA_H) -#include "regex/regex_extra.h" -#endif - #if HAVE_PWD_H # ifdef PHP_WIN32 #include "win32/param.h" http://cvs.php.net/viewvc.cgi/php-src/sapi/apache/php_apache_http.h?r1=1.13.2.1.2.1&r2=1.13.2.1.2.1.2.1&diff_format=u Index: php-src/sapi/apache/php_apache_http.h diff -u php-src/sapi/apache/php_apache_http.h:1.13.2.1.2.1 php-src/sapi/apache/php_apache_http.h:1.13.2.1.2.1.2.1 --- php-src/sapi/apache/php_apache_http.h:1.13.2.1.2.1 Mon Jan 1 09:36:12 2007 +++ php-src/sapi/apache/php_apache_http.h Fri Oct 5 15:00:09 2007 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_apache_http.h,v 1.13.2.1.2.1 2007/01/01 09:36:12 sebastian Exp $ */ +/* $Id: php_apache_http.h,v 1.13.2.1.2.1.2.1 2007/10/05 15:00:09 jani Exp $ */ #define NO_REGEX_EXTRA_H @@ -31,7 +31,7 @@ #endif #include "zend.h" -#include "php_regex.h" +#include "ext/ereg/php_regex.h" #include "php_compat.h" #ifdef HAVE_OPENSSL_EXT http://cvs.php.net/viewvc.cgi/php-src/sapi/apache_hooks/php_apache_http.h?r1=1.3&r2=1.3.8.1&diff_format=u Index: php-src/sapi/apache_hooks/php_apache_http.h diff -u php-src/sapi/apache_hooks/php_apache_http.h:1.3 php-src/sapi/apache_hooks/php_apache_http.h:1.3.8.1 --- php-src/sapi/apache_hooks/php_apache_http.h:1.3 Sat Jan 17 13:00:09 2004 +++ php-src/sapi/apache_hooks/php_apache_http.h Fri Oct 5 15:00:09 2007 @@ -11,7 +11,7 @@ #include "zend.h" #include "zend_stack.h" -#include "php_regex.h" +#include "ext/ereg/php_regex.h" #include "httpd.h" #include "http_config.h" http://cvs.php.net/viewvc.cgi/php-src/win32/build/config.w32?r1=1.40.2.8.2.10.2.1&r2=1.40.2.8.2.10.2.2&diff_format=u Index: php-src/win32/build/config.w32 diff -u php-src/win32/build/config.w32:1.40.2.8.2.10.2.1 php-src/win32/build/config.w32:1.40.2.8.2.10.2.2 --- php-src/win32/build/config.w32:1.40.2.8.2.10.2.1 Mon Oct 1 12:40:54 2007 +++ php-src/win32/build/config.w32 Fri Oct 5 15:00:09 2007 @@ -1,5 +1,5 @@ // vim:ft=javascript -// $Id: config.w32,v 1.40.2.8.2.10.2.1 2007/10/01 12:40:54 jani Exp $ +// $Id: config.w32,v 1.40.2.8.2.10.2.2 2007/10/05 15:00:09 jani Exp $ // "Master" config file; think of it as a configure.in // equivalent. @@ -99,7 +99,7 @@ } DEFINE('PHP_PREFIX', PHP_PREFIX); -DEFINE("BASE_INCLUDES", "/I . /I main /I regex /I Zend /I TSRM /I ext "); +DEFINE("BASE_INCLUDES", "/I . /I main /I Zend /I TSRM /I ext "); // CFLAGS for building the PHP dll DEFINE("CFLAGS_PHP", "/D _USRDLL /D PHP5DLLTS_EXPORTS /D PHP_EXPORTS \ @@ -312,8 +312,6 @@ ADD_SOURCES("win32", "crypt_win32.c glob.c md5crypt.c readdir.c \ registry.c select.c sendmail.c time.c wfile.c winutil.c wsyslog.c globals.c"); -ADD_SOURCES("regex", "regcomp.c regerror.c regexec.c regfree.c"); - STDOUT.WriteBlankLines(1); /* Can we build with IPv6 support? */ http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/.cvsignore?view=markup&rev=1.1 Index: php-src/ext/ereg/.cvsignore +++ php-src/ext/ereg/.cvsignore #*# *.dsw *.la *.lo *.ncb *.opt *.plg *.tgz *~..#*..*.swp..deps..libs Debug Debug_TS Makefile Makefile.fragments Makefile.global Makefile.objects Release Release_TS Release_TSDbg Release_TS_inline Release_inline acinclude.m4 aclocal.m4 autom4te.cache build config.cache config.guess config.h config.h.in config.log config.nice config.status config.sub configure configure.in conftest conftest.c include install-sh libtool ltmain.sh missing mkinstalldirs modules scan_makefile_in.awk *.gcda *.gcno http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/config.w32?view=markup&rev=1.1 Index: php-src/ext/ereg/config.w32 +++ php-src/ext/ereg/config.w32 // $Id: config.w32,v 1.1 2007/07/15 19:50:06 jani Exp $ // vim:ft=javascript EXTENSION("ereg", "ereg.c", false /* never shared */, "-Iext/ereg/regex"); ADD_SOURCES("ext/ereg/regex", "regcomp.c regexec.c regerror.c regfree.c", "ereg"); AC_DEFINE('REGEX', 1, 'Bundled regex'); AC_DEFINE('HSREGEX', 1, 'Bundled regex'); http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/config0.m4?view=markup&rev=1.1 Index: php-src/ext/ereg/config0.m4 +++ php-src/ext/ereg/config0.m4 dnl $Id: config0.m4,v 1.1 2007/07/15 19:50:06 jani Exp $ dnl config.m4 for extension ereg dnl dnl Check for regex library type dnl PHP_ARG_WITH(regex,, [ --with-regex=TYPE regex library type: system, apache, php. [TYPE=php] WARNING: Do NOT use unless you know what you are doing!], php, no) case $PHP_REGEX in system) if test "$PHP_SAPI" = "apache" || test "$PHP_SAPI" = "apache2filter" || test "$PHP_SAPI" = "apache2handler"; then REGEX_TYPE=php else REGEX_TYPE=system fi ;; apache) REGEX_TYPE=apache ;; yes | php) REGEX_TYPE=php ;; *) REGEX_TYPE=php AC_MSG_WARN([Invalid regex library type selected. Using default value: php]) ;; esac AC_MSG_CHECKING([which regex library to use]) AC_MSG_RESULT([$REGEX_TYPE]) if test "$REGEX_TYPE" = "php"; then ereg_regex_sources="regex/regcomp.c regex/regexec.c regex/regerror.c regex/regfree.c" ereg_regex_headers="regex/" fi PHP_NEW_EXTENSION(ereg, ereg.c $ereg_regex_sources, no) PHP_INSTALL_HEADERS([ext/ereg], [php_ereg.h php_regex.h $ereg_regex_headers]) if test "$REGEX_TYPE" = "php"; then AC_DEFINE(HAVE_REGEX_T_RE_MAGIC, 1, [ ]) AC_DEFINE(HSREGEX,1,[ ]) AC_DEFINE(REGEX,1,[ ]) PHP_ADD_BUILD_DIR([$ext_builddir/regex], 1) PHP_ADD_INCLUDE([$ext_srcdir/regex]) elif test "$REGEX_TYPE" = "system"; then AC_DEFINE(REGEX,0,[ ]) dnl Check if field re_magic exists in struct regex_t AC_CACHE_CHECK([whether field re_magic exists in struct regex_t], ac_cv_regex_t_re_magic, [ AC_TRY_COMPILE([#include <sys/types.h> #include <regex.h>], [regex_t rt; rt.re_magic;], [ac_cv_regex_t_re_magic=yes], [ac_cv_regex_t_re_magic=no])]) if test "$ac_cv_regex_t_re_magic" = "yes"; then AC_DEFINE([HAVE_REGEX_T_RE_MAGIC], [ ], 1) fi fi http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/ereg.c?view=markup&rev=1.1 Index: php-src/ext/ereg/ereg.c +++ php-src/ext/ereg/ereg.c /* +----------------------------------------------------------------------+ | PHP HTML Embedded Scripting Language Version 3.0 | +----------------------------------------------------------------------+ | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | +----------------------------------------------------------------------+ | This program is free software; you can redistribute it and/or modify | | it under the terms of one of the following licenses: | | | | A) the GNU General Public License as published by the Free Software | | Foundation; either version 2 of the License, or (at your option) | | any later version. | | | | B) the PHP License as published by the PHP Development Team and | | included in the distribution in the file: LICENSE | | | | This program is distributed in the hope that it will be useful, | | but WITHOUT ANY WARRANTY; without even the implied warranty of | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | | GNU General Public License for more details. | | | | You should have received a copy of both licenses referred to here. | | If you did not, or have any questions about PHP licensing, please | | contact core@php.net. | +----------------------------------------------------------------------+ | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | | Jim Winstead <jimw@php.net> | | Jaakko Hyvätti <jaakko@hyvatti.iki.fi> | +----------------------------------------------------------------------+ */ /* $Id: ereg.c,v 1.1 1999/04/17 00:37:07 ssb Exp $ */ #ifdef THREAD_SAFE #include "tls.h" #endif #include <stdio.h> #include "php.h" #include "php3_string.h" #include "reg.h" unsigned char third_argument_force_ref[] = { 3, BYREF_NONE, BYREF_NONE, BYREF_FORCE }; function_entry reg_functions[] = { {"ereg", php3_ereg, third_argument_force_ref }, {"ereg_replace", php3_eregreplace, NULL }, {"eregi", php3_eregi, third_argument_force_ref }, {"eregi_replace", php3_eregireplace, NULL }, {"split", php3_split, NULL}, {"join", php3_implode, NULL}, {"sql_regcase", php3_sql_regcase, NULL}, {NULL, NULL, NULL} }; php3_module_entry regexp_module_entry = { "Regular Expressions", reg_functions, NULL, NULL, NULL, NULL, NULL, STANDARD_MODULE_PROPERTIES }; /* This is the maximum number of (..) constructs we'll generate from a call to ereg() or eregi() with the optional third argument. */ #define NS 10 /* * _php3_reg_eprint - convert error number to name */ static void _php3_reg_eprint(int err, regex_t *re) { char *buf = NULL, *message = NULL; size_t len; size_t buf_len; #ifdef REG_ITOA /* get the length of the message */ buf_len = regerror(REG_ITOA | err, re, NULL, 0); if (buf_len) { buf = (char *)emalloc(buf_len * sizeof(char)); if (!buf) return; /* fail silently */ /* finally, get the error message */ regerror(REG_ITOA | err, re, buf, buf_len); } #else buf_len = 0; #endif len = regerror(err, re, NULL, 0); if (len) { message = (char *)emalloc((buf_len + len + 2) * sizeof(char)); if (!message) { return; /* fail silently */ } if (buf_len) { snprintf(message, buf_len, "%s: ", buf); buf_len += 1; /* so pointer math below works */ } /* drop the message into place */ regerror(err, re, message + buf_len, len); php3_error(E_WARNING, "%s", message); } STR_FREE(buf); STR_FREE(message); } static void _php3_ereg(INTERNAL_FUNCTION_PARAMETERS, int icase) { pval *regex, /* Regular expression */ *findin, /* String to apply expression to */ *array = NULL; /* Optional register array */ regex_t re; regmatch_t subs[NS]; int err, i, match_len, string_len; int copts = 0; off_t start, end; char *buf = NULL; char *string = NULL; TLS_VARS; if (icase) copts |= REG_ICASE; switch(ARG_COUNT(ht)) { case 2: if (getParameters(ht, 2, ®ex, &findin) == FAILURE) { WRONG_PARAM_COUNT; } /* don't bother doing substring matching if we're not going to make use of the information */ copts |= REG_NOSUB; break; case 3: if (getParameters(ht, 3, ®ex, &findin, &array) == FAILURE) { WRONG_PARAM_COUNT; } if (!ParameterPassedByReference(ht, 3)) { php3_error(E_WARNING, "Array to be filled with values must be passed by reference."); RETURN_FALSE; } break; default: WRONG_PARAM_COUNT; } /* compile the regular expression from the supplied regex */ if (regex->type == IS_STRING) { err = regcomp(&re, regex->value.str.val, REG_EXTENDED | copts); } else { /* we convert numbers to integers and treat them as a string */ if (regex->type == IS_DOUBLE) convert_to_long(regex); /* get rid of decimal places */ convert_to_string(regex); /* don't bother doing an extended regex with just a number */ err = regcomp(&re, regex->value.str.val, copts); } if (err) { _php3_reg_eprint(err, &re); RETURN_FALSE; } /* make a copy of the string we're looking in */ convert_to_string(findin); string = estrndup(findin->value.str.val, findin->value.str.len); /* actually execute the regular expression */ err = regexec(&re, string, (size_t) NS, subs, 0); if (err && err != REG_NOMATCH) { _php3_reg_eprint(err, &re); regfree(&re); RETURN_FALSE; } match_len = 1; if (array && err != REG_NOMATCH) { match_len = (int) (subs[0].rm_eo - subs[0].rm_so); string_len = strlen(string) + 1; buf = emalloc(string_len); if (!buf) { php3_error(E_WARNING, "Unable to allocate memory in _php3_ereg"); RETURN_FALSE; } pval_destructor(array _INLINE_TLS); /* start with clean array */ array_init(array); for (i = 0; i < NS; i++) { start = subs[i].rm_so; end = subs[i].rm_eo; if (start != -1 && end > 0 && start < string_len && end < string_len && start < end) { add_index_stringl(array, i, string+start, end-start, 1); } } efree(buf); } efree(string); if (err == REG_NOMATCH) { RETVAL_FALSE; } else { if (match_len == 0) match_len = 1; RETVAL_LONG(match_len); } regfree(&re); } /* {{{ proto int ereg(string pattern, string string [, array registers]) Regular expression match */ void php3_ereg(INTERNAL_FUNCTION_PARAMETERS) { _php3_ereg(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); } /* }}} */ /* {{{ proto int eregi(string pattern, string string [, array registers]) Case-insensitive regular expression match */ void php3_eregi(INTERNAL_FUNCTION_PARAMETERS) { _php3_ereg(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); } /* }}} */ /* this is the meat and potatoes of regex replacement! */ char *_php3_regreplace(const char *pattern, const char *replace, const char *string, int icase, int extended) { regex_t re; regmatch_t subs[NS]; char *buf, /* buf is where we build the replaced string */ *nbuf, /* nbuf is used when we grow the buffer */ *walkbuf; /* used to walk buf when replacing backrefs */ const char *walk; /* used to walk replacement string for backrefs */ int buf_len; int pos, tmp, string_len, new_l; int err, copts = 0; string_len = strlen(string); if (!string_len) return (char *)string; if (icase) copts = REG_ICASE; if (extended) copts |= REG_EXTENDED; err = regcomp(&re, pattern, copts); if (err) { _php3_reg_eprint(err, &re); return ((char *) -1); } /* start with a buffer that is twice the size of the stringo we're doing replacements in */ buf_len = 2 * string_len + 1; buf = emalloc(buf_len * sizeof(char)); if (!buf) { php3_error(E_WARNING, "Unable to allocate memory in _php3_regreplace"); regfree(&re); return ((char *) -1); } err = pos = 0; buf[0] = '\0'; while (!err) { err = regexec(&re, &string[pos], (size_t) NS, subs, (pos ? REG_NOTBOL : 0)); if (err && err != REG_NOMATCH) { _php3_reg_eprint(err, &re); regfree(&re); return ((char *) -1); } if (!err) { /* backref replacement is done in two passes: 1) find out how long the string will be, and allocate buf 2) copy the part before match, replacement and backrefs to buf Jaakko Hyvätti <Jaakko.Hyvatti@iki.fi> */ new_l = strlen(buf) + subs[0].rm_so; /* part before the match */ walk = replace; while (*walk) if ('\\' == *walk && '0' <= walk[1] && '9' >= walk[1] && subs[walk[1] - '0'].rm_so > -1 && subs[walk[1] - '0'].rm_eo > -1) { new_l += subs[walk[1] - '0'].rm_eo - subs[walk[1] - '0'].rm_so; walk += 2; } else { new_l++; walk++; } if (new_l + 1 > buf_len) { buf_len = 1 + buf_len + 2 * new_l; nbuf = emalloc(buf_len); strcpy(nbuf, buf); efree(buf); buf = nbuf; } tmp = strlen(buf); /* copy the part of the string before the match */ strncat(buf, &string[pos], subs[0].rm_so); /* copy replacement and backrefs */ walkbuf = &buf[tmp + subs[0].rm_so]; walk = replace; while (*walk) if ('\\' == *walk && '0' <= walk[1] && '9' >= walk[1] && subs[walk[1] - '0'].rm_so > -1 && subs[walk[1] - '0'].rm_eo > -1) { tmp = subs[walk[1] - '0'].rm_eo - subs[walk[1] - '0'].rm_so; memcpy (walkbuf, &string[pos + subs[walk[1] - '0'].rm_so], tmp); walkbuf += tmp; walk += 2; } else *walkbuf++ = *walk++; *walkbuf = '\0'; /* and get ready to keep looking for replacements */ if (subs[0].rm_so == subs[0].rm_eo) { if (subs[0].rm_so + pos >= string_len) break; new_l = strlen (buf) + 1; if (new_l + 1 > buf_len) { buf_len = 1 + buf_len + 2 * new_l; nbuf = emalloc(buf_len * sizeof(char)); strcpy(nbuf, buf); efree(buf); buf = nbuf; } pos += subs[0].rm_eo + 1; buf [new_l-1] = string [pos-1]; buf [new_l] = '\0'; } else { pos += subs[0].rm_eo; } } else { /* REG_NOMATCH */ new_l = strlen(buf) + strlen(&string[pos]); if (new_l + 1 > buf_len) { buf_len = new_l + 1; /* now we know exactly how long it is */ nbuf = emalloc(buf_len * sizeof(char)); strcpy(nbuf, buf); efree(buf); buf = nbuf; } /* stick that last bit of string on our output */ strcat(buf, &string[pos]); } } /* don't want to leak memory .. */ regfree(&re); /* whew. */ return (buf); } static void _php3_eregreplace(INTERNAL_FUNCTION_PARAMETERS, int icase) { pval *arg_pattern, *arg_replace, *arg_string; char *pattern; char *string; char *replace; char *ret; TLS_VARS; if (ARG_COUNT(ht) != 3 || getParameters(ht, 3, &arg_pattern, &arg_replace, &arg_string) == FAILURE) { WRONG_PARAM_COUNT; } if (arg_pattern->type == IS_STRING) { if (arg_pattern->value.str.val && arg_pattern->value.str.len) pattern = estrndup(arg_pattern->value.str.val,arg_pattern->value.str.len); else pattern = empty_string; } else { convert_to_long(arg_pattern); pattern = emalloc(2); pattern[0] = (char) arg_pattern->value.lval; pattern[1] = '\0'; } if (arg_replace->type == IS_STRING) { if (arg_replace->value.str.val && arg_replace->value.str.len) replace = estrndup(arg_replace->value.str.val, arg_replace->value.str.len); else replace = empty_string; } else { convert_to_long(arg_replace); replace = emalloc(2); replace[0] = (char) arg_replace->value.lval; replace[1] = '\0'; } convert_to_string(arg_string); if (arg_string->value.str.val && arg_string->value.str.len) string = estrndup(arg_string->value.str.val, arg_string->value.str.len); else string = empty_string; /* do the actual work */ ret = _php3_regreplace(pattern, replace, string, icase, 1); if (ret == (char *) -1) { RETVAL_FALSE; } else { RETVAL_STRING(ret,1); STR_FREE(ret); } STR_FREE(string); STR_FREE(replace); STR_FREE(pattern); } /* {{{ proto string ereg_replace(string pattern, string string [, array registers]) Replace regular expression */ void php3_eregreplace(INTERNAL_FUNCTION_PARAMETERS) { _php3_eregreplace(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); } /* }}} */ /* {{{ proto string eregi_replace(string pattern, string string [, array registers]) Case insensitive replace regular expression */ void php3_eregireplace(INTERNAL_FUNCTION_PARAMETERS) { _php3_eregreplace(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); } /* }}} */ /* ("root", "passwd", "uid", "gid", "other:stuff:like:/bin/sh") = split(":", $passwd_file, 5); */ /* {{{ proto array split(string pattern, string string [, int limit]) split string into array by regular expression */ void php3_split(INTERNAL_FUNCTION_PARAMETERS) { pval *spliton, *str, *arg_count = NULL; regex_t re; regmatch_t subs[1]; char *strp, *endp; int err, size, count; TLS_VARS; switch (ARG_COUNT(ht)) { case 2: if (getParameters(ht, 2, &spliton, &str) == FAILURE) WRONG_PARAM_COUNT; count = -1; break; case 3: if (getParameters(ht, 3, &spliton, &str, &arg_count) == FAILURE) WRONG_PARAM_COUNT; convert_to_long(arg_count); count = arg_count->value.lval; break; default: WRONG_PARAM_COUNT; } convert_to_string(spliton); convert_to_string(str); strp = str->value.str.val; endp = str->value.str.val + strlen(str->value.str.val); err = regcomp(&re, spliton->value.str.val, REG_EXTENDED); if (err) { php3_error(E_WARNING, "unexpected regex error (%d)", err); RETURN_FALSE; } if (array_init(return_value) == FAILURE) { regfree(&re); RETURN_FALSE; } /* churn through str, generating array entries as we go */ while ((count == -1 || count > 1) && !(err = regexec(&re, strp, 1, subs, 0))) { if (subs[0].rm_so == 0 && subs[0].rm_eo) { /* match is at start of string, return empty string */ add_next_index_stringl(return_value, empty_string, 0, 1); /* skip ahead the length of the regex match */ strp+=subs[0].rm_eo; } else if (subs[0].rm_so==0 && subs[0].rm_eo==0) { /* No more matches */ regfree(&re); php3_error(E_WARNING, "bad regular expression for split()"); _php3_hash_destroy(return_value->value.ht); efree(return_value->value.ht); RETURN_FALSE; } else { /* On a real match */ /* make a copy of the substring */ size = subs[0].rm_so; /* add it to the array */ add_next_index_stringl(return_value, strp, size, 1); /* point at our new starting point */ strp = strp + subs[0].rm_eo; } /* if we're only looking for a certain number of points, stop looking once we hit it */ if (count != -1) count--; } /* see if we encountered an error */ if (err && err != REG_NOMATCH) { php3_error(E_WARNING, "unexpected regex error (%d)", err); regfree(&re); _php3_hash_destroy(return_value->value.ht); efree(return_value->value.ht); RETURN_FALSE; } /* otherwise we just have one last element to add to the array */ size = endp - strp; add_next_index_stringl(return_value, strp, size, 1); regfree(&re); return; } /* }}} */ /* {{{ proto string sql_regcase(string string) Make regular expression for case insensitive match */ PHPAPI void php3_sql_regcase(INTERNAL_FUNCTION_PARAMETERS) { pval *string; char *tmp; register int i; if (ARG_COUNT(ht)!=1 || getParameters(ht, 1, &string)==FAILURE) { WRONG_PARAM_COUNT; } convert_to_string(string); tmp = (char *) emalloc(string->value.str.len*4+1); for (i=0; i<string->value.str.len; i++) { tmp[i*4] = '['; tmp[i*4+1]=toupper((unsigned char)string->value.str.val[i]); tmp[i*4+2]=tolower((unsigned char)string->value.str.val[i]); tmp[i*4+3]=']'; } tmp[string->value.str.len*4]=0; return_value->value.str.val = tmp; return_value->value.str.len = string->value.str.len*4; return_value->type = IS_STRING; } /* }}} */ /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: */ http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/php_ereg.h?view=markup&rev=1.1 Index: php-src/ext/ereg/php_ereg.h +++ php-src/ext/ereg/php_ereg.h /* +----------------------------------------------------------------------+ | PHP HTML Embedded Scripting Language Version 3.0 | +----------------------------------------------------------------------+ | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | +----------------------------------------------------------------------+ | This program is free software; you can redistribute it and/or modify | | it under the terms of one of the following licenses: | | | | A) the GNU General Public License as published by the Free Software | | Foundation; either version 2 of the License, or (at your option) | | any later version. | | | | B) the PHP License as published by the PHP Development Team and | | included in the distribution in the file: LICENSE | | | | This program is distributed in the hope that it will be useful, | | but WITHOUT ANY WARRANTY; without even the implied warranty of | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | | GNU General Public License for more details. | | | | You should have received a copy of both licenses referred to here. | | If you did not, or have any questions about PHP licensing, please | | contact core@php.net. | +----------------------------------------------------------------------+ | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | +----------------------------------------------------------------------+ */ /* $Id: php_ereg.h,v 1.1 1999/04/17 00:37:07 ssb Exp $ */ #ifndef _REG_H #define _REG_H extern php3_module_entry regexp_module_entry; #define regexp_module_ptr ®exp_module_entry extern char *_php3_regreplace(const char *pattern, const char *replace, const char *string, int icase, int extended); extern void php3_ereg(INTERNAL_FUNCTION_PARAMETERS); extern void php3_eregi(INTERNAL_FUNCTION_PARAMETERS); extern void php3_eregireplace(INTERNAL_FUNCTION_PARAMETERS); extern void php3_eregreplace(INTERNAL_FUNCTION_PARAMETERS); extern void php3_split(INTERNAL_FUNCTION_PARAMETERS); extern PHPAPI void php3_sql_regcase(INTERNAL_FUNCTION_PARAMETERS); #endif /* _REG_H */ http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/php_regex.h?view=markup&rev=1.1 Index: php-src/ext/ereg/php_regex.h +++ php-src/ext/ereg/php_regex.h #ifndef _PHP_REGEX_H #define _PHP_REGEX_H #if REGEX #include "regex/regex.h" #define _REGEX_H 1 /* this should stop Apache from loading the system version of regex.h */ #define _RX_H 1 /* Try defining these for Linux to */ #define __REGEXP_LIBRARY_H__ 1 /* avoid Apache including regex.h */ #define _H_REGEX 1 /* This one is for AIX */ #else #include <regex.h> #endif #endif /* _PHP_REGEX_H */ http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/.cvsignore?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/.cvsignore +++ php-src/ext/ereg/regex/.cvsignore Makefile http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/cclass.h?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/cclass.h +++ php-src/ext/ereg/regex/cclass.h /* character-class table */ static struct cclass { char *name; char *chars; char *multis; } cclasses[] = { { "alnum", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\ 0123456789", "" }, { "alpha", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", "" }, { "blank", " \t", "" }, { "cntrl", "\007\b\t\n\v\f\r\1\2\3\4\5\6\16\17\20\21\22\23\24\ \25\26\27\30\31\32\33\34\35\36\37\177", "" }, { "digit", "0123456789", "" }, { "graph", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\ 0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", "" }, { "lower", "abcdefghijklmnopqrstuvwxyz", "" }, { "print", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\ 0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ ", "" }, { "punct", "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", "" }, { "space", "\t\n\v\f\r ", "" }, { "upper", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "" }, { "xdigit", "0123456789ABCDEFabcdef", "" }, { NULL, 0, "" } }; http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/cname.h?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/cname.h +++ php-src/ext/ereg/regex/cname.h /* character-name table */ static struct cname { char *name; char code; } cnames[] = { { "NUL", '\0' }, { "SOH", '\001' }, { "STX", '\002' }, { "ETX", '\003' }, { "EOT", '\004' }, { "ENQ", '\005' }, { "ACK", '\006' }, { "BEL", '\007' }, { "alert", '\007' }, { "BS", '\010' }, { "backspace", '\b' }, { "HT", '\011' }, { "tab", '\t' }, { "LF", '\012' }, { "newline", '\n' }, { "VT", '\013' }, { "vertical-tab", '\v' }, { "FF", '\014' }, { "form-feed", '\f' }, { "CR", '\015' }, { "carriage-return", '\r' }, { "SO", '\016' }, { "SI", '\017' }, { "DLE", '\020' }, { "DC1", '\021' }, { "DC2", '\022' }, { "DC3", '\023' }, { "DC4", '\024' }, { "NAK", '\025' }, { "SYN", '\026' }, { "ETB", '\027' }, { "CAN", '\030' }, { "EM", '\031' }, { "SUB", '\032' }, { "ESC", '\033' }, { "IS4", '\034' }, { "FS", '\034' }, { "IS3", '\035' }, { "GS", '\035' }, { "IS2", '\036' }, { "RS", '\036' }, { "IS1", '\037' }, { "US", '\037' }, { "space", ' ' }, { "exclamation-mark", '!' }, { "quotation-mark", '"' }, { "number-sign", '#' }, { "dollar-sign", '$' }, { "percent-sign", '%' }, { "ampersand", '&' }, { "apostrophe", '\'' }, { "left-parenthesis", '(' }, { "right-parenthesis", ')' }, { "asterisk", '*' }, { "plus-sign", '+' }, { "comma", ',' }, { "hyphen", '-' }, { "hyphen-minus", '-' }, { "period", '.' }, { "full-stop", '.' }, { "slash", '/' }, { "solidus", '/' }, { "zero", '0' }, { "one", '1' }, { "two", '2' }, { "three", '3' }, { "four", '4' }, { "five", '5' }, { "six", '6' }, { "seven", '7' }, { "eight", '8' }, { "nine", '9' }, { "colon", ':' }, { "semicolon", ';' }, { "less-than-sign", '<' }, { "equals-sign", '=' }, { "greater-than-sign", '>' }, { "question-mark", '?' }, { "commercial-at", '@' }, { "left-square-bracket", '[' }, { "backslash", '\\' }, { "reverse-solidus", '\\' }, { "right-square-bracket", ']' }, { "circumflex", '^' }, { "circumflex-accent", '^' }, { "underscore", '_' }, { "low-line", '_' }, { "grave-accent", '`' }, { "left-brace", '{' }, { "left-curly-bracket", '{' }, { "vertical-line", '|' }, { "right-brace", '}' }, { "right-curly-bracket", '}' }, { "tilde", '~' }, { "DEL", '\177' }, { NULL, 0 } }; http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/debug.c?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/debug.c +++ php-src/ext/ereg/regex/debug.c #include <stdio.h> #include <string.h> #include <ctype.h> #include <limits.h> #include <stdlib.h> #include <sys/types.h> #include <regex.h> #include "utils.h" #include "regex2.h" #include "debug.ih" /* - regprint - print a regexp for debugging == void regprint(regex_t *r, FILE *d); */ void regprint(r, d) regex_t *r; FILE *d; { register struct re_guts *g = r->re_g; register int i; register int c; register int last; int nincat[NC]; fprintf(d, "%ld states, %d categories", (long)g->nstates, g->ncategories); fprintf(d, ", first %ld last %ld", (long)g->firststate, (long)g->laststate); if (g->iflags&USEBOL) fprintf(d, ", USEBOL"); if (g->iflags&USEEOL) fprintf(d, ", USEEOL"); if (g->iflags&BAD) fprintf(d, ", BAD"); if (g->nsub > 0) fprintf(d, ", nsub=%ld", (long)g->nsub); if (g->must != NULL) fprintf(d, ", must(%ld) `%*s'", (long)g->mlen, (int)g->mlen, g->must); if (g->backrefs) fprintf(d, ", backrefs"); if (g->nplus > 0) fprintf(d, ", nplus %ld", (long)g->nplus); fprintf(d, "\n"); s_print(g, d); for (i = 0; i < g->ncategories; i++) { nincat[i] = 0; for (c = CHAR_MIN; c <= CHAR_MAX; c++) if (g->categories[c] == i) nincat[i]++; } fprintf(d, "cc0#%d", nincat[0]); for (i = 1; i < g->ncategories; i++) if (nincat[i] == 1) { for (c = CHAR_MIN; c <= CHAR_MAX; c++) if (g->categories[c] == i) break; fprintf(d, ", %d=%s", i, regchar(c)); } fprintf(d, "\n"); for (i = 1; i < g->ncategories; i++) if (nincat[i] != 1) { fprintf(d, "cc%d\t", i); last = -1; for (c = CHAR_MIN; c <= CHAR_MAX+1; c++) /* +1 does flush */ if (c <= CHAR_MAX && g->categories[c] == i) { if (last < 0) { fprintf(d, "%s", regchar(c)); last = c; } } else { if (last >= 0) { if (last != c-1) fprintf(d, "-%s", regchar(c-1)); last = -1; } } fprintf(d, "\n"); } } /* - s_print - print the strip for debugging == static void s_print(register struct re_guts *g, FILE *d); */ static void s_print(g, d) register struct re_guts *g; FILE *d; { register sop *s; register cset *cs; register int i; register int done = 0; register sop opnd; register int col = 0; register int last; register sopno offset = 2; # define GAP() { if (offset % 5 == 0) { \ if (col > 40) { \ fprintf(d, "\n\t"); \ col = 0; \ } else { \ fprintf(d, " "); \ col++; \ } \ } else \ col++; \ offset++; \ } if (OP(g->strip[0]) != OEND) fprintf(d, "missing initial OEND!\n"); for (s = &g->strip[1]; !done; s++) { opnd = OPND(*s); switch (OP(*s)) { case OEND: fprintf(d, "\n"); done = 1; break; case OCHAR: if (strchr("\\|()^$.[+*?{}!<> ", (char)opnd) != NULL) fprintf(d, "\\%c", (char)opnd); else fprintf(d, "%s", regchar((char)opnd)); break; case OBOL: fprintf(d, "^"); break; case OEOL: fprintf(d, "$"); break; case OBOW: fprintf(d, "\\{"); break; case OEOW: fprintf(d, "\\}"); break; case OANY: fprintf(d, "."); break; case OANYOF: fprintf(d, "[(%ld)", (long)opnd); cs = &g->sets[opnd]; last = -1; for (i = 0; i < g->csetsize+1; i++) /* +1 flushes */ if (CHIN(cs, i) && i < g->csetsize) { if (last < 0) { fprintf(d, "%s", regchar(i)); last = i; } } else { if (last >= 0) { if (last != i-1) fprintf(d, "-%s", regchar(i-1)); last = -1; } } fprintf(d, "]"); break; case OBACK_: fprintf(d, "(\\<%ld>", (long)opnd); break; case O_BACK: fprintf(d, "<%ld>\\)", (long)opnd); break; case OPLUS_: fprintf(d, "(+"); if (OP(*(s+opnd)) != O_PLUS) fprintf(d, "<%ld>", (long)opnd); break; case O_PLUS: if (OP(*(s-opnd)) != OPLUS_) fprintf(d, "<%ld>", (long)opnd); fprintf(d, "+)"); break; case OQUEST_: fprintf(d, "(?"); if (OP(*(s+opnd)) != O_QUEST) fprintf(d, "<%ld>", (long)opnd); break; case O_QUEST: if (OP(*(s-opnd)) != OQUEST_) fprintf(d, "<%ld>", (long)opnd); fprintf(d, "?)"); break; case OLPAREN: fprintf(d, "((<%ld>", (long)opnd); break; case ORPAREN: fprintf(d, "<%ld>))", (long)opnd); break; case OCH_: fprintf(d, "<"); if (OP(*(s+opnd)) != OOR2) fprintf(d, "<%ld>", (long)opnd); break; case OOR1: if (OP(*(s-opnd)) != OOR1 && OP(*(s-opnd)) != OCH_) fprintf(d, "<%ld>", (long)opnd); fprintf(d, "|"); break; case OOR2: fprintf(d, "|"); if (OP(*(s+opnd)) != OOR2 && OP(*(s+opnd)) != O_CH) fprintf(d, "<%ld>", (long)opnd); break; case O_CH: if (OP(*(s-opnd)) != OOR1) fprintf(d, "<%ld>", (long)opnd); fprintf(d, ">"); break; default: fprintf(d, "!%ld(%ld)!", OP(*s), opnd); break; } if (!done) GAP(); } } /* - regchar - make a character printable == static char *regchar(int ch); */ static char * /* -> representation */ regchar(ch) int ch; { static char buf[10]; if (isprint(ch) || ch == ' ') sprintf(buf, "%c", ch); else sprintf(buf, "\\%o", ch); return(buf); } http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/debug.ih?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/debug.ih +++ php-src/ext/ereg/regex/debug.ih /* ========= begin header generated by ./mkh ========= */ #ifdef __cplusplus extern "C" { #endif /* === debug.c === */ void regprint(regex_t *r, FILE *d); static void s_print(register struct re_guts *g, FILE *d); static char *regchar(int ch); #ifdef __cplusplus } #endif /* ========= end header generated by ./mkh ========= */ http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/engine.c?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/engine.c +++ php-src/ext/ereg/regex/engine.c /* * The matching engine and friends. This file is #included by regexec.c * after suitable #defines of a variety of macros used herein, so that * different state representations can be used without duplicating masses * of code. */ #ifdef SNAMES #define matcher smatcher #define fast sfast #define slow sslow #define dissect sdissect #define backref sbackref #define step sstep #define print sprint #define at sat #define match smat #endif #ifdef LNAMES #define matcher lmatcher #define fast lfast #define slow lslow #define dissect ldissect #define backref lbackref #define step lstep #define print lprint #define at lat #define match lmat #endif /* another structure passed up and down to avoid zillions of parameters */ struct match { struct re_guts *g; int eflags; regmatch_t *pmatch; /* [nsub+1] (0 element unused) */ char *offp; /* offsets work from here */ char *beginp; /* start of string -- virtual NUL precedes */ char *endp; /* end of string -- virtual NUL here */ char *coldp; /* can be no match starting before here */ char **lastpos; /* [nplus+1] */ STATEVARS; states st; /* current states */ states fresh; /* states for a fresh start */ states tmp; /* temporary */ states empty; /* empty set of states */ }; #include "engine.ih" #ifdef REDEBUG #define SP(t, s, c) print(m, t, s, c, stdout) #define AT(t, p1, p2, s1, s2) at(m, t, p1, p2, s1, s2) #define NOTE(str) { if (m->eflags®_TRACE) printf("=%s\n", (str)); } #else #define SP(t, s, c) /* nothing */ #define AT(t, p1, p2, s1, s2) /* nothing */ #define NOTE(s) /* nothing */ #endif /* - matcher - the actual matching engine == static int matcher(register struct re_guts *g, char *string, \ == size_t nmatch, regmatch_t pmatch[], int eflags); */ static int /* 0 success, REG_NOMATCH failure */ matcher(g, string, nmatch, pmatch, eflags) register struct re_guts *g; char *string; size_t nmatch; regmatch_t pmatch[]; int eflags; { register char *endp; register unsigned int i; struct match mv; register struct match *m = &mv; register char *dp; register const sopno gf = g->firststate+1; /* +1 for OEND */ register const sopno gl = g->laststate; char *start; char *stop; /* simplify the situation where possible */ if (g->cflags®_NOSUB) nmatch = 0; if (eflags®_STARTEND) { start = string + pmatch[0].rm_so; stop = string + pmatch[0].rm_eo; } else { start = string; stop = start + strlen(start); } if (stop < start) return(REG_INVARG); /* prescreening; this does wonders for this rather slow code */ if (g->must != NULL) { for (dp = start; dp < stop; dp++) if (*dp == g->must[0] && stop - dp >= g->mlen && memcmp(dp, g->must, (size_t)g->mlen) == 0) break; if (dp == stop) /* we didn't find g->must */ return(REG_NOMATCH); } /* match struct setup */ m->g = g; m->eflags = eflags; m->pmatch = NULL; m->lastpos = NULL; m->offp = string; m->beginp = start; m->endp = stop; STATESETUP(m, 4); SETUP(m->st); SETUP(m->fresh); SETUP(m->tmp); SETUP(m->empty); CLEAR(m->empty); /* this loop does only one repetition except for backrefs */ for (;;) { endp = fast(m, start, stop, gf, gl); if (endp == NULL) { /* a miss */ STATETEARDOWN(m); return(REG_NOMATCH); } if (nmatch == 0 && !g->backrefs) break; /* no further info needed */ /* where? */ assert(m->coldp != NULL); for (;;) { NOTE("finding start"); endp = slow(m, m->coldp, stop, gf, gl); if (endp != NULL) break; assert(m->coldp < m->endp); m->coldp++; } if (nmatch == 1 && !g->backrefs) break; /* no further info needed */ /* oh my, he wants the subexpressions... */ if (m->pmatch == NULL) m->pmatch = (regmatch_t *)malloc((m->g->nsub + 1) * sizeof(regmatch_t)); if (m->pmatch == NULL) { STATETEARDOWN(m); return(REG_ESPACE); } for (i = 1; i <= m->g->nsub; i++) m->pmatch[i].rm_so = m->pmatch[i].rm_eo = -1; if (!g->backrefs && !(m->eflags®_BACKR)) { NOTE("dissecting"); dp = dissect(m, m->coldp, endp, gf, gl); } else { if (g->nplus > 0 && m->lastpos == NULL) m->lastpos = (char **)malloc((g->nplus+1) * sizeof(char *)); if (g->nplus > 0 && m->lastpos == NULL) { free(m->pmatch); STATETEARDOWN(m); return(REG_ESPACE); } NOTE("backref dissect"); dp = backref(m, m->coldp, endp, gf, gl, (sopno)0); } if (dp != NULL) break; /* uh-oh... we couldn't find a subexpression-level match */ assert(g->backrefs); /* must be back references doing it */ assert(g->nplus == 0 || m->lastpos != NULL); for (;;) { if (dp != NULL || endp <= m->coldp) break; /* defeat */ NOTE("backoff"); endp = slow(m, m->coldp, endp-1, gf, gl); if (endp == NULL) break; /* defeat */ /* try it on a shorter possibility */ #ifndef NDEBUG for (i = 1; i <= m->g->nsub; i++) { assert(m->pmatch[i].rm_so == -1); assert(m->pmatch[i].rm_eo == -1); } #endif NOTE("backoff dissect"); dp = backref(m, m->coldp, endp, gf, gl, (sopno)0); } assert(dp == NULL || dp == endp); if (dp != NULL) /* found a shorter one */ break; /* despite initial appearances, there is no match here */ NOTE("false alarm"); start = m->coldp + 1; /* recycle starting later */ assert(start <= stop); } /* fill in the details if requested */ if (nmatch > 0) { pmatch[0].rm_so = m->coldp - m->offp; pmatch[0].rm_eo = endp - m->offp; } if (nmatch > 1) { assert(m->pmatch != NULL); for (i = 1; i < nmatch; i++) if (i <= m->g->nsub) pmatch[i] = m->pmatch[i]; else { pmatch[i].rm_so = -1; pmatch[i].rm_eo = -1; } } if (m->pmatch != NULL) free((char *)m->pmatch); if (m->lastpos != NULL) free((char *)m->lastpos); STATETEARDOWN(m); return(0); } /* - dissect - figure out what matched what, no back references == static char *dissect(register struct match *m, char *start, \ == char *stop, sopno startst, sopno stopst); */ static char * /* == stop (success) always */ dissect(m, start, stop, startst, stopst) register struct match *m; char *start; char *stop; sopno startst; sopno stopst; { register int i; register sopno ss; /* start sop of current subRE */ register sopno es; /* end sop of current subRE */ register char *sp; /* start of string matched by it */ register char *stp; /* string matched by it cannot pass here */ register char *rest; /* start of rest of string */ register char *tail; /* string unmatched by rest of RE */ register sopno ssub; /* start sop of subsubRE */ register sopno esub; /* end sop of subsubRE */ register char *ssp; /* start of string matched by subsubRE */ register char *sep; /* end of string matched by subsubRE */ register char *oldssp; /* previous ssp */ register char *dp; AT("diss", start, stop, startst, stopst); sp = start; for (ss = startst; ss < stopst; ss = es) { /* identify end of subRE */ es = ss; switch (OP(m->g->strip[es])) { case OPLUS_: case OQUEST_: es += OPND(m->g->strip[es]); break; case OCH_: while (OP(m->g->strip[es]) != O_CH) es += OPND(m->g->strip[es]); break; } es++; /* figure out what it matched */ switch (OP(m->g->strip[ss])) { case OEND: assert(nope); break; case OCHAR: sp++; break; case OBOL: case OEOL: case OBOW: case OEOW: break; case OANY: case OANYOF: sp++; break; case OBACK_: case O_BACK: assert(nope); break; /* cases where length of match is hard to find */ case OQUEST_: stp = stop; for (;;) { /* how long could this one be? */ rest = slow(m, sp, stp, ss, es); assert(rest != NULL); /* it did match */ /* could the rest match the rest? */ tail = slow(m, rest, stop, es, stopst); if (tail == stop) break; /* yes! */ /* no -- try a shorter match for this one */ stp = rest - 1; assert(stp >= sp); /* it did work */ } ssub = ss + 1; esub = es - 1; /* did innards match? */ if (slow(m, sp, rest, ssub, esub) != NULL) { dp = dissect(m, sp, rest, ssub, esub); assert(dp == rest); } else /* no */ assert(sp == rest); sp = rest; break; case OPLUS_: stp = stop; for (;;) { /* how long could this one be? */ rest = slow(m, sp, stp, ss, es); assert(rest != NULL); /* it did match */ /* could the rest match the rest? */ tail = slow(m, rest, stop, es, stopst); if (tail == stop) break; /* yes! */ /* no -- try a shorter match for this one */ stp = rest - 1; assert(stp >= sp); /* it did work */ } ssub = ss + 1; esub = es - 1; ssp = sp; oldssp = ssp; for (;;) { /* find last match of innards */ sep = slow(m, ssp, rest, ssub, esub); if (sep == NULL || sep == ssp) break; /* failed or matched null */ oldssp = ssp; /* on to next try */ ssp = sep; } if (sep == NULL) { /* last successful match */ sep = ssp; ssp = oldssp; } assert(sep == rest); /* must exhaust substring */ assert(slow(m, ssp, sep, ssub, esub) == rest); dp = dissect(m, ssp, sep, ssub, esub); assert(dp == sep); sp = rest; break; case OCH_: stp = stop; for (;;) { /* how long could this one be? */ rest = slow(m, sp, stp, ss, es); assert(rest != NULL); /* it did match */ /* could the rest match the rest? */ tail = slow(m, rest, stop, es, stopst); if (tail == stop) break; /* yes! */ /* no -- try a shorter match for this one */ stp = rest - 1; assert(stp >= sp); /* it did work */ } ssub = ss + 1; esub = ss + OPND(m->g->strip[ss]) - 1; assert(OP(m->g->strip[esub]) == OOR1); for (;;) { /* find first matching branch */ if (slow(m, sp, rest, ssub, esub) == rest) break; /* it matched all of it */ /* that one missed, try next one */ assert(OP(m->g->strip[esub]) == OOR1); esub++; assert(OP(m->g->strip[esub]) == OOR2); ssub = esub + 1; esub += OPND(m->g->strip[esub]); if (OP(m->g->strip[esub]) == OOR2) esub--; else assert(OP(m->g->strip[esub]) == O_CH); } dp = dissect(m, sp, rest, ssub, esub); assert(dp == rest); sp = rest; break; case O_PLUS: case O_QUEST: case OOR1: case OOR2: case O_CH: assert(nope); break; case OLPAREN: i = OPND(m->g->strip[ss]); assert(0 < i && i <= m->g->nsub); m->pmatch[i].rm_so = sp - m->offp; break; case ORPAREN: i = OPND(m->g->strip[ss]); assert(0 < i && i <= m->g->nsub); m->pmatch[i].rm_eo = sp - m->offp; break; default: /* uh oh */ assert(nope); break; } } assert(sp == stop); return(sp); } /* - backref - figure out what matched what, figuring in back references == static char *backref(register struct match *m, char *start, \ == char *stop, sopno startst, sopno stopst, sopno lev); */ static char * /* == stop (success) or NULL (failure) */ backref(m, start, stop, startst, stopst, lev) register struct match *m; char *start; char *stop; sopno startst; sopno stopst; sopno lev; /* PLUS nesting level */ { register int i; register sopno ss; /* start sop of current subRE */ register char *sp; /* start of string matched by it */ register sopno ssub; /* start sop of subsubRE */ register sopno esub; /* end sop of subsubRE */ register char *ssp; /* start of string matched by subsubRE */ register char *dp; register size_t len; register int hard; register sop s; register regoff_t offsave; register cset *cs; AT("back", start, stop, startst, stopst); sp = start; /* get as far as we can with easy stuff */ hard = 0; for (ss = startst; !hard && ss < stopst; ss++) switch (OP(s = m->g->strip[ss])) { case OCHAR: if (sp == stop || *sp++ != (char)OPND(s)) return(NULL); break; case OANY: if (sp == stop) return(NULL); sp++; break; case OANYOF: cs = &m->g->sets[OPND(s)]; if (sp == stop || !CHIN(cs, *sp++)) return(NULL); break; case OBOL: if ( (sp == m->beginp && !(m->eflags®_NOTBOL)) || (sp < m->endp && *(sp-1) == '\n' && (m->g->cflags®_NEWLINE)) ) { /* yes */ } else return(NULL); break; case OEOL: if ( (sp == m->endp && !(m->eflags®_NOTEOL)) || (sp < m->endp && *sp == '\n' && (m->g->cflags®_NEWLINE)) ) { /* yes */ } else return(NULL); break; case OBOW: if (( (sp == m->beginp && !(m->eflags®_NOTBOL)) || (sp < m->endp && *(sp-1) == '\n' && (m->g->cflags®_NEWLINE)) || (sp > m->beginp && !ISWORD(*(sp-1))) ) && (sp < m->endp && ISWORD(*sp)) ) { /* yes */ } else return(NULL); break; case OEOW: if (( (sp == m->endp && !(m->eflags®_NOTEOL)) || (sp < m->endp && *sp == '\n' && (m->g->cflags®_NEWLINE)) || (sp < m->endp && !ISWORD(*sp)) ) && (sp > m->beginp && ISWORD(*(sp-1))) ) { /* yes */ } else return(NULL); break; case O_QUEST: break; case OOR1: /* matches null but needs to skip */ ss++; s = m->g->strip[ss]; do { assert(OP(s) == OOR2); ss += OPND(s); } while (OP(s = m->g->strip[ss]) != O_CH); /* note that the ss++ gets us past the O_CH */ break; default: /* have to make a choice */ hard = 1; break; } if (!hard) { /* that was it! */ if (sp != stop) return(NULL); return(sp); } ss--; /* adjust for the for's final increment */ /* the hard stuff */ AT("hard", sp, stop, ss, stopst); s = m->g->strip[ss]; switch (OP(s)) { case OBACK_: /* the vilest depths */ i = OPND(s); assert(0 < i && i <= m->g->nsub); if (m->pmatch[i].rm_eo == -1) return(NULL); assert(m->pmatch[i].rm_so != -1); len = m->pmatch[i].rm_eo - m->pmatch[i].rm_so; assert(stop - m->beginp >= len); if (sp > stop - len) return(NULL); /* not enough left to match */ ssp = m->offp + m->pmatch[i].rm_so; if (memcmp(sp, ssp, len) != 0) return(NULL); while (m->g->strip[ss] != SOP(O_BACK, i)) ss++; return(backref(m, sp+len, stop, ss+1, stopst, lev)); break; case OQUEST_: /* to null or not */ dp = backref(m, sp, stop, ss+1, stopst, lev); if (dp != NULL) return(dp); /* not */ return(backref(m, sp, stop, ss+OPND(s)+1, stopst, lev)); break; case OPLUS_: assert(m->lastpos != NULL); assert(lev+1 <= m->g->nplus); m->lastpos[lev+1] = sp; return(backref(m, sp, stop, ss+1, stopst, lev+1)); break; case O_PLUS: if (sp == m->lastpos[lev]) /* last pass matched null */ return(backref(m, sp, stop, ss+1, stopst, lev-1)); /* try another pass */ m->lastpos[lev] = sp; dp = backref(m, sp, stop, ss-OPND(s)+1, stopst, lev); if (dp == NULL) return(backref(m, sp, stop, ss+1, stopst, lev-1)); else return(dp); break; case OCH_: /* find the right one, if any */ ssub = ss + 1; esub = ss + OPND(s) - 1; assert(OP(m->g->strip[esub]) == OOR1); for (;;) { /* find first matching branch */ dp = backref(m, sp, stop, ssub, esub, lev); if (dp != NULL) return(dp); /* that one missed, try next one */ if (OP(m->g->strip[esub]) == O_CH) return(NULL); /* there is none */ esub++; assert(OP(m->g->strip[esub]) == OOR2); ssub = esub + 1; esub += OPND(m->g->strip[esub]); if (OP(m->g->strip[esub]) == OOR2) esub--; else assert(OP(m->g->strip[esub]) == O_CH); } break; case OLPAREN: /* must undo assignment if rest fails */ i = OPND(s); assert(0 < i && i <= m->g->nsub); offsave = m->pmatch[i].rm_so; m->pmatch[i].rm_so = sp - m->offp; dp = backref(m, sp, stop, ss+1, stopst, lev); if (dp != NULL) return(dp); m->pmatch[i].rm_so = offsave; return(NULL); break; case ORPAREN: /* must undo assignment if rest fails */ i = OPND(s); assert(0 < i && i <= m->g->nsub); offsave = m->pmatch[i].rm_eo; m->pmatch[i].rm_eo = sp - m->offp; dp = backref(m, sp, stop, ss+1, stopst, lev); if (dp != NULL) return(dp); m->pmatch[i].rm_eo = offsave; return(NULL); break; default: /* uh oh */ assert(nope); break; } /* "can't happen" */ assert(nope); /* NOTREACHED */ return( NULL ); } /* - fast - step through the string at top speed == static char *fast(register struct match *m, char *start, \ == char *stop, sopno startst, sopno stopst); */ static char * /* where tentative match ended, or NULL */ fast(m, start, stop, startst, stopst) register struct match *m; char *start; char *stop; sopno startst; sopno stopst; { register states st = m->st; register states fresh = m->fresh; register states tmp = m->tmp; register char *p = start; register int c = (start == m->beginp) ? OUT : *(start-1); register int lastc; /* previous c */ register int flagch; register int i; register char *coldp; /* last p after which no match was underway */ CLEAR(st); SET1(st, startst); st = step(m->g, startst, stopst, st, NOTHING, st); ASSIGN(fresh, st); SP("start", st, *p); coldp = NULL; for (;;) { /* next character */ lastc = c; c = (p == m->endp) ? OUT : *p; if (EQ(st, fresh)) coldp = p; /* is there an EOL and/or BOL between lastc and c? */ flagch = '\0'; i = 0; if ( (lastc == '\n' && m->g->cflags®_NEWLINE) || (lastc == OUT && !(m->eflags®_NOTBOL)) ) { flagch = BOL; i = m->g->nbol; } if ( (c == '\n' && m->g->cflags®_NEWLINE) || (c == OUT && !(m->eflags®_NOTEOL)) ) { flagch = (flagch == BOL) ? BOLEOL : EOL; i += m->g->neol; } if (i != 0) { for (; i > 0; i--) st = step(m->g, startst, stopst, st, flagch, st); SP("boleol", st, c); } /* how about a word boundary? */ if ( (flagch == BOL || (lastc != OUT && !ISWORD(lastc))) && (c != OUT && ISWORD(c)) ) { flagch = BOW; } if ( (lastc != OUT && ISWORD(lastc)) && (flagch == EOL || (c != OUT && !ISWORD(c))) ) { flagch = EOW; } if (flagch == BOW || flagch == EOW) { st = step(m->g, startst, stopst, st, flagch, st); SP("boweow", st, c); } /* are we done? */ if (ISSET(st, stopst) || p == stop) break; /* NOTE BREAK OUT */ /* no, we must deal with this character */ ASSIGN(tmp, st); ASSIGN(st, fresh); assert(c != OUT); st = step(m->g, startst, stopst, tmp, c, st); SP("aft", st, c); assert(EQ(step(m->g, startst, stopst, st, NOTHING, st), st)); p++; } assert(coldp != NULL); m->coldp = coldp; if (ISSET(st, stopst)) return(p+1); else return(NULL); } /* - slow - step through the string more deliberately == static char *slow(register struct match *m, char *start, \ == char *stop, sopno startst, sopno stopst); */ static char * /* where it ended */ slow(m, start, stop, startst, stopst) register struct match *m; char *start; char *stop; sopno startst; sopno stopst; { register states st = m->st; register states empty = m->empty; register states tmp = m->tmp; register char *p = start; register int c = (start == m->beginp) ? OUT : *(start-1); register int lastc; /* previous c */ register int flagch; register int i; register char *matchp; /* last p at which a match ended */ AT("slow", start, stop, startst, stopst); CLEAR(st); SET1(st, startst); SP("sstart", st, *p); st = step(m->g, startst, stopst, st, NOTHING, st); matchp = NULL; for (;;) { /* next character */ lastc = c; c = (p == m->endp) ? OUT : *p; /* is there an EOL and/or BOL between lastc and c? */ flagch = '\0'; i = 0; if ( (lastc == '\n' && m->g->cflags®_NEWLINE) || (lastc == OUT && !(m->eflags®_NOTBOL)) ) { flagch = BOL; i = m->g->nbol; } if ( (c == '\n' && m->g->cflags®_NEWLINE) || (c == OUT && !(m->eflags®_NOTEOL)) ) { flagch = (flagch == BOL) ? BOLEOL : EOL; i += m->g->neol; } if (i != 0) { for (; i > 0; i--) st = step(m->g, startst, stopst, st, flagch, st); SP("sboleol", st, c); } /* how about a word boundary? */ if ( (flagch == BOL || (lastc != OUT && !ISWORD(lastc))) && (c != OUT && ISWORD(c)) ) { flagch = BOW; } if ( (lastc != OUT && ISWORD(lastc)) && (flagch == EOL || (c != OUT && !ISWORD(c))) ) { flagch = EOW; } if (flagch == BOW || flagch == EOW) { st = step(m->g, startst, stopst, st, flagch, st); SP("sboweow", st, c); } /* are we done? */ if (ISSET(st, stopst)) matchp = p; if (EQ(st, empty) || p == stop) break; /* NOTE BREAK OUT */ /* no, we must deal with this character */ ASSIGN(tmp, st); ASSIGN(st, empty); assert(c != OUT); st = step(m->g, startst, stopst, tmp, c, st); SP("saft", st, c); assert(EQ(step(m->g, startst, stopst, st, NOTHING, st), st)); p++; } return(matchp); } /* - step - map set of states reachable before char to set reachable after == static states step(register struct re_guts *g, sopno start, sopno stop, \ == register states bef, int ch, register states aft); == #define BOL (OUT+1) == #define EOL (BOL+1) == #define BOLEOL (BOL+2) == #define NOTHING (BOL+3) == #define BOW (BOL+4) == #define EOW (BOL+5) == #define CODEMAX (BOL+5) // highest code used == #define NONCHAR(c) ((c) > CHAR_MAX) == #define NNONCHAR (CODEMAX-CHAR_MAX) */ static states step(g, start, stop, bef, ch, aft) register struct re_guts *g; sopno start; /* start state within strip */ sopno stop; /* state after stop state within strip */ register states bef; /* states reachable before */ int ch; /* character or NONCHAR code */ register states aft; /* states already known reachable after */ { register cset *cs; register sop s; register sopno pc; register onestate here; /* note, macros know this name */ register sopno look; register int i; for (pc = start, INIT(here, pc); pc != stop; pc++, INC(here)) { s = g->strip[pc]; switch (OP(s)) { case OEND: assert(pc == stop-1); break; case OCHAR: /* only characters can match */ assert(!NONCHAR(ch) || ch != (char)OPND(s)); if (ch == (char)OPND(s)) FWD(aft, bef, 1); break; case OBOL: if (ch == BOL || ch == BOLEOL) FWD(aft, bef, 1); break; case OEOL: if (ch == EOL || ch == BOLEOL) FWD(aft, bef, 1); break; case OBOW: if (ch == BOW) FWD(aft, bef, 1); break; case OEOW: if (ch == EOW) FWD(aft, bef, 1); break; case OANY: if (!NONCHAR(ch)) FWD(aft, bef, 1); break; case OANYOF: cs = &g->sets[OPND(s)]; if (!NONCHAR(ch) && CHIN(cs, ch)) FWD(aft, bef, 1); break; case OBACK_: /* ignored here */ case O_BACK: FWD(aft, aft, 1); break; case OPLUS_: /* forward, this is just an empty */ FWD(aft, aft, 1); break; case O_PLUS: /* both forward and back */ FWD(aft, aft, 1); i = ISSETBACK(aft, OPND(s)); BACK(aft, aft, OPND(s)); if (!i && ISSETBACK(aft, OPND(s))) { /* oho, must reconsider loop body */ pc -= OPND(s) + 1; INIT(here, pc); } break; case OQUEST_: /* two branches, both forward */ FWD(aft, aft, 1); FWD(aft, aft, OPND(s)); break; case O_QUEST: /* just an empty */ FWD(aft, aft, 1); break; case OLPAREN: /* not significant here */ case ORPAREN: FWD(aft, aft, 1); break; case OCH_: /* mark the first two branches */ FWD(aft, aft, 1); assert(OP(g->strip[pc+OPND(s)]) == OOR2); FWD(aft, aft, OPND(s)); break; case OOR1: /* done a branch, find the O_CH */ if (ISSTATEIN(aft, here)) { for (look = 1; OP(s = g->strip[pc+look]) != O_CH; look += OPND(s)) assert(OP(s) == OOR2); FWD(aft, aft, look); } break; case OOR2: /* propagate OCH_'s marking */ FWD(aft, aft, 1); if (OP(g->strip[pc+OPND(s)]) != O_CH) { assert(OP(g->strip[pc+OPND(s)]) == OOR2); FWD(aft, aft, OPND(s)); } break; case O_CH: /* just empty */ FWD(aft, aft, 1); break; default: /* ooooops... */ assert(nope); break; } } return(aft); } #ifdef REDEBUG /* - print - print a set of states == #ifdef REDEBUG == static void print(struct match *m, char *caption, states st, \ == int ch, FILE *d); == #endif */ static void print(m, caption, st, ch, d) struct match *m; char *caption; states st; int ch; FILE *d; { register struct re_guts *g = m->g; register int i; register int first = 1; if (!(m->eflags®_TRACE)) return; fprintf(d, "%s", caption); if (ch != '\0') fprintf(d, " %s", pchar(ch)); for (i = 0; i < g->nstates; i++) if (ISSET(st, i)) { fprintf(d, "%s%d", (first) ? "\t" : ", ", i); first = 0; } fprintf(d, "\n"); } /* - at - print current situation == #ifdef REDEBUG == static void at(struct match *m, char *title, char *start, char *stop, \ == sopno startst, sopno stopst); == #endif */ static void at(m, title, start, stop, startst, stopst) struct match *m; char *title; char *start; char *stop; sopno startst; sopno stopst; { if (!(m->eflags®_TRACE)) return; printf("%s %s-", title, pchar(*start)); printf("%s ", pchar(*stop)); printf("%ld-%ld\n", (long)startst, (long)stopst); } #ifndef PCHARDONE #define PCHARDONE /* never again */ /* - pchar - make a character printable == #ifdef REDEBUG == static char *pchar(int ch); == #endif * * Is this identical to regchar() over in debug.c? Well, yes. But a * duplicate here avoids having a debugging-capable regexec.o tied to * a matching debug.o, and this is convenient. It all disappears in * the non-debug compilation anyway, so it doesn't matter much. */ static char * /* -> representation */ pchar(ch) int ch; { static char pbuf[10]; if (isprint(ch) || ch == ' ') sprintf(pbuf, "%c", ch); else sprintf(pbuf, "\\%o", ch); return(pbuf); } #endif #endif #undef matcher #undef fast #undef slow #undef dissect #undef backref #undef step #undef print #undef at #undef match http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/engine.ih?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/engine.ih +++ php-src/ext/ereg/regex/engine.ih /* ========= begin header generated by ../../regex/mkh ========= */ #ifdef __cplusplus extern "C" { #endif /* === ../../regex/engine.c === */ static int matcher(register struct re_guts *g, char *string, size_t nmatch, regmatch_t pmatch[], int eflags); static char *dissect(register struct match *m, char *start, char *stop, sopno startst, sopno stopst); static char *backref(register struct match *m, char *start, char *stop, sopno startst, sopno stopst, sopno lev); static char *fast(register struct match *m, char *start, char *stop, sopno startst, sopno stopst); static char *slow(register struct match *m, char *start, char *stop, sopno startst, sopno stopst); static states step(register struct re_guts *g, sopno start, sopno stop, register states bef, int ch, register states aft); #define BOL (OUT+1) #define EOL (BOL+1) #define BOLEOL (BOL+2) #define NOTHING (BOL+3) #define BOW (BOL+4) #define EOW (BOL+5) #define CODEMAX (BOL+5) /* highest code used */ #define NONCHAR(c) ((c) > CHAR_MAX) #define NNONCHAR (CODEMAX-CHAR_MAX) #ifdef REDEBUG static void print(struct match *m, char *caption, states st, int ch, FILE *d); #endif #ifdef REDEBUG static void at(struct match *m, char *title, char *start, char *stop, sopno startst, sopno stopst); #endif #ifdef REDEBUG static char *pchar(int ch); #endif #ifdef __cplusplus } #endif /* ========= end header generated by ../../regex/mkh ========= */ http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/main.c?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/main.c +++ php-src/ext/ereg/regex/main.c #include <stdio.h> #include <string.h> #include <sys/types.h> #include <regex.h> #include <assert.h> #include <stdlib.h> #include "main.ih" char *progname; int debug = 0; int line = 0; int status = 0; int copts = REG_EXTENDED; int eopts = 0; regoff_t startoff = 0; regoff_t endoff = 0; extern int split(); extern void regprint(); /* - main - do the simple case, hand off to regress() for regression */ int main(argc, argv) int argc; char *argv[]; { regex_t re; # define NS 10 regmatch_t subs[NS]; char erbuf[100]; int err; size_t len; int c; int errflg = 0; register int i; extern int optind; extern char *optarg; progname = argv[0]; while ((c = getopt(argc, argv, "c:e:S:E:x")) != EOF) switch (c) { case 'c': /* compile options */ copts = options('c', optarg); break; case 'e': /* execute options */ eopts = options('e', optarg); break; case 'S': /* start offset */ startoff = (regoff_t)atoi(optarg); break; case 'E': /* end offset */ endoff = (regoff_t)atoi(optarg); break; case 'x': /* Debugging. */ debug++; break; case '?': default: errflg++; break; } if (errflg) { fprintf(stderr, "usage: %s ", progname); fprintf(stderr, "[-c copt][-C][-d] [re]\n"); exit(2); } if (optind >= argc) { regress(stdin); exit(status); } err = regcomp(&re, argv[optind++], copts); if (err) { len = regerror(err, &re, erbuf, sizeof(erbuf)); fprintf(stderr, "error %s, %d/%d `%s'\n", eprint(err), len, sizeof(erbuf), erbuf); exit(status); } regprint(&re, stdout); if (optind >= argc) { regfree(&re); exit(status); } if (eopts®_STARTEND) { subs[0].rm_so = startoff; subs[0].rm_eo = strlen(argv[optind]) - endoff; } err = regexec(&re, argv[optind], (size_t)NS, subs, eopts); if (err) { len = regerror(err, &re, erbuf, sizeof(erbuf)); fprintf(stderr, "error %s, %d/%d `%s'\n", eprint(err), len, sizeof(erbuf), erbuf); exit(status); } if (!(copts®_NOSUB)) { len = (int)(subs[0].rm_eo - subs[0].rm_so); if (subs[0].rm_so != -1) { if (len != 0) printf("match `%.*s'\n", (int)len, argv[optind] + subs[0].rm_so); else printf("match `'@%.1s\n", argv[optind] + subs[0].rm_so); } for (i = 1; i < NS; i++) if (subs[i].rm_so != -1) printf("(%d) `%.*s'\n", i, (int)(subs[i].rm_eo - subs[i].rm_so), argv[optind] + subs[i].rm_so); } exit(status); } /* - regress - main loop of regression test == void regress(FILE *in); */ void regress(in) FILE *in; { char inbuf[1000]; # define MAXF 10 char *f[MAXF]; int nf; int i; char erbuf[100]; size_t ne; char *badpat = "invalid regular expression"; # define SHORT 10 char *bpname = "REG_BADPAT"; regex_t re; while (fgets(inbuf, sizeof(inbuf), in) != NULL) { line++; if (inbuf[0] == '#' || inbuf[0] == '\n') continue; /* NOTE CONTINUE */ inbuf[strlen(inbuf)-1] = '\0'; /* get rid of stupid \n */ if (debug) fprintf(stdout, "%d:\n", line); nf = split(inbuf, f, MAXF, "\t\t"); if (nf < 3) { fprintf(stderr, "bad input, line %d\n", line); exit(1); } for (i = 0; i < nf; i++) if (strcmp(f[i], "\"\"") == 0) f[i] = ""; if (nf <= 3) f[3] = NULL; if (nf <= 4) f[4] = NULL; try(f[0], f[1], f[2], f[3], f[4], options('c', f[1])); if (opt('&', f[1])) /* try with either type of RE */ try(f[0], f[1], f[2], f[3], f[4], options('c', f[1]) &~ REG_EXTENDED); } ne = regerror(REG_BADPAT, (regex_t *)NULL, erbuf, sizeof(erbuf)); if (strcmp(erbuf, badpat) != 0 || ne != strlen(badpat)+1) { fprintf(stderr, "end: regerror() test gave `%s' not `%s'\n", erbuf, badpat); status = 1; } ne = regerror(REG_BADPAT, (regex_t *)NULL, erbuf, (size_t)SHORT); if (strncmp(erbuf, badpat, SHORT-1) != 0 || erbuf[SHORT-1] != '\0' || ne != strlen(badpat)+1) { fprintf(stderr, "end: regerror() short test gave `%s' not `%.*s'\n", erbuf, SHORT-1, badpat); status = 1; } ne = regerror(REG_ITOA|REG_BADPAT, (regex_t *)NULL, erbuf, sizeof(erbuf)); if (strcmp(erbuf, bpname) != 0 || ne != strlen(bpname)+1) { fprintf(stderr, "end: regerror() ITOA test gave `%s' not `%s'\n", erbuf, bpname); status = 1; } re.re_endp = bpname; ne = regerror(REG_ATOI, &re, erbuf, sizeof(erbuf)); if (atoi(erbuf) != (int)REG_BADPAT) { fprintf(stderr, "end: regerror() ATOI test gave `%s' not `%ld'\n", erbuf, (long)REG_BADPAT); status = 1; } else if (ne != strlen(erbuf)+1) { fprintf(stderr, "end: regerror() ATOI test len(`%s') = %ld\n", erbuf, (long)REG_BADPAT); status = 1; } } /* - try - try it, and report on problems == void try(char *f0, char *f1, char *f2, char *f3, char *f4, int opts); */ void try(f0, f1, f2, f3, f4, opts) char *f0; char *f1; char *f2; char *f3; char *f4; int opts; /* may not match f1 */ { regex_t re; # define NSUBS 10 regmatch_t subs[NSUBS]; # define NSHOULD 15 char *should[NSHOULD]; int nshould; char erbuf[100]; int err; int len; char *type = (opts & REG_EXTENDED) ? "ERE" : "BRE"; register int i; char *grump; char f0copy[1000]; char f2copy[1000]; strcpy(f0copy, f0); re.re_endp = (opts®_PEND) ? f0copy + strlen(f0copy) : NULL; fixstr(f0copy); err = regcomp(&re, f0copy, opts); if (err != 0 && (!opt('C', f1) || err != efind(f2))) { /* unexpected error or wrong error */ len = regerror(err, &re, erbuf, sizeof(erbuf)); fprintf(stderr, "%d: %s error %s, %d/%d `%s'\n", line, type, eprint(err), len, sizeof(erbuf), erbuf); status = 1; } else if (err == 0 && opt('C', f1)) { /* unexpected success */ fprintf(stderr, "%d: %s should have given REG_%s\n", line, type, f2); status = 1; err = 1; /* so we won't try regexec */ } if (err != 0) { regfree(&re); return; } strcpy(f2copy, f2); fixstr(f2copy); if (options('e', f1)®_STARTEND) { if (strchr(f2, '(') == NULL || strchr(f2, ')') == NULL) fprintf(stderr, "%d: bad STARTEND syntax\n", line); subs[0].rm_so = strchr(f2, '(') - f2 + 1; subs[0].rm_eo = strchr(f2, ')') - f2; } err = regexec(&re, f2copy, NSUBS, subs, options('e', f1)); if (err != 0 && (f3 != NULL || err != REG_NOMATCH)) { /* unexpected error or wrong error */ len = regerror(err, &re, erbuf, sizeof(erbuf)); fprintf(stderr, "%d: %s exec error %s, %d/%d `%s'\n", line, type, eprint(err), len, sizeof(erbuf), erbuf); status = 1; } else if (err != 0) { /* nothing more to check */ } else if (f3 == NULL) { /* unexpected success */ fprintf(stderr, "%d: %s exec should have failed\n", line, type); status = 1; err = 1; /* just on principle */ } else if (opts®_NOSUB) { /* nothing more to check */ } else if ((grump = check(f2, subs[0], f3)) != NULL) { fprintf(stderr, "%d: %s %s\n", line, type, grump); status = 1; err = 1; } if (err != 0 || f4 == NULL) { regfree(&re); return; } for (i = 1; i < NSHOULD; i++) should[i] = NULL; nshould = split(f4, should+1, NSHOULD-1, ","); if (nshould == 0) { nshould = 1; should[1] = ""; } for (i = 1; i < NSUBS; i++) { grump = check(f2, subs[i], should[i]); if (grump != NULL) { fprintf(stderr, "%d: %s $%d %s\n", line, type, i, grump); status = 1; err = 1; } } regfree(&re); } /* - options - pick options out of a regression-test string == int options(int type, char *s); */ int options(type, s) int type; /* 'c' compile, 'e' exec */ char *s; { register char *p; register int o = (type == 'c') ? copts : eopts; register char *legal = (type == 'c') ? "bisnmp" : "^$#tl"; for (p = s; *p != '\0'; p++) if (strchr(legal, *p) != NULL) switch (*p) { case 'b': o &= ~REG_EXTENDED; break; case 'i': o |= REG_ICASE; break; case 's': o |= REG_NOSUB; break; case 'n': o |= REG_NEWLINE; break; case 'm': o &= ~REG_EXTENDED; o |= REG_NOSPEC; break; case 'p': o |= REG_PEND; break; case '^': o |= REG_NOTBOL; break; case '$': o |= REG_NOTEOL; break; case '#': o |= REG_STARTEND; break; case 't': /* trace */ o |= REG_TRACE; break; case 'l': /* force long representation */ o |= REG_LARGE; break; case 'r': /* force backref use */ o |= REG_BACKR; break; } return(o); } /* - opt - is a particular option in a regression string? == int opt(int c, char *s); */ int /* predicate */ opt(c, s) int c; char *s; { return(strchr(s, c) != NULL); } /* - fixstr - transform magic characters in strings == void fixstr(register char *p); */ void fixstr(p) register char *p; { if (p == NULL) return; for (; *p != '\0'; p++) if (*p == 'N') *p = '\n'; else if (*p == 'T') *p = '\t'; else if (*p == 'S') *p = ' '; else if (*p == 'Z') *p = '\0'; } /* - check - check a substring match == char *check(char *str, regmatch_t sub, char *should); */ char * /* NULL or complaint */ check(str, sub, should) char *str; regmatch_t sub; char *should; { register int len; register int shlen; register char *p; static char grump[500]; register char *at = NULL; if (should != NULL && strcmp(should, "-") == 0) should = NULL; if (should != NULL && should[0] == '@') { at = should + 1; should = ""; } /* check rm_so and rm_eo for consistency */ if (sub.rm_so > sub.rm_eo || (sub.rm_so == -1 && sub.rm_eo != -1) || (sub.rm_so != -1 && sub.rm_eo == -1) || (sub.rm_so != -1 && sub.rm_so < 0) || (sub.rm_eo != -1 && sub.rm_eo < 0) ) { sprintf(grump, "start %ld end %ld", (long)sub.rm_so, (long)sub.rm_eo); return(grump); } /* check for no match */ if (sub.rm_so == -1 && should == NULL) return(NULL); if (sub.rm_so == -1) return("did not match"); /* check for in range */ if (sub.rm_eo > strlen(str)) { sprintf(grump, "start %ld end %ld, past end of string", (long)sub.rm_so, (long)sub.rm_eo); return(grump); } len = (int)(sub.rm_eo - sub.rm_so); shlen = (int)strlen(should); p = str + sub.rm_so; /* check for not supposed to match */ if (should == NULL) { sprintf(grump, "matched `%.*s'", len, p); return(grump); } /* check for wrong match */ if (len != shlen || strncmp(p, should, (size_t)shlen) != 0) { sprintf(grump, "matched `%.*s' instead", len, p); return(grump); } if (shlen > 0) return(NULL); /* check null match in right place */ if (at == NULL) return(NULL); shlen = strlen(at); if (shlen == 0) shlen = 1; /* force check for end-of-string */ if (strncmp(p, at, shlen) != 0) { sprintf(grump, "matched null at `%.20s'", p); return(grump); } return(NULL); } /* - eprint - convert error number to name == static char *eprint(int err); */ static char * eprint(err) int err; { static char epbuf[100]; size_t len; len = regerror(REG_ITOA|err, (regex_t *)NULL, epbuf, sizeof(epbuf)); assert(len <= sizeof(epbuf)); return(epbuf); } /* - efind - convert error name to number == static int efind(char *name); */ static int efind(name) char *name; { static char efbuf[100]; regex_t re; sprintf(efbuf, "REG_%s", name); assert(strlen(efbuf) < sizeof(efbuf)); re.re_endp = efbuf; (void) regerror(REG_ATOI, &re, efbuf, sizeof(efbuf)); return(atoi(efbuf)); } http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/main.ih?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/main.ih +++ php-src/ext/ereg/regex/main.ih /* ========= begin header generated by ./mkh ========= */ #ifdef __cplusplus extern "C" { #endif /* === main.c === */ void regress(FILE *in); void try(char *f0, char *f1, char *f2, char *f3, char *f4, int opts); int options(int type, char *s); int opt(int c, char *s); void fixstr(register char *p); char *check(char *str, regmatch_t sub, char *should); static char *eprint(int err); static int efind(char *name); #ifdef __cplusplus } #endif /* ========= end header generated by ./mkh ========= */ http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/regcomp.c?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/regcomp.c +++ php-src/ext/ereg/regex/regcomp.c #include <sys/types.h> #include <stdio.h> #include <string.h> #include <ctype.h> #include <limits.h> #include <stdlib.h> #include <regex.h> #include "utils.h" #include "regex2.h" #include "cclass.h" #include "cname.h" /* * parse structure, passed up and down to avoid global variables and * other clumsinesses */ struct parse { char *next; /* next character in RE */ char *end; /* end of string (-> NUL normally) */ int error; /* has an error been seen? */ sop *strip; /* malloced strip */ sopno ssize; /* malloced strip size (allocated) */ sopno slen; /* malloced strip length (used) */ int ncsalloc; /* number of csets allocated */ struct re_guts *g; # define NPAREN 10 /* we need to remember () 1-9 for back refs */ sopno pbegin[NPAREN]; /* -> ( ([0] unused) */ sopno pend[NPAREN]; /* -> ) ([0] unused) */ }; #include "regcomp.ih" static char nuls[10]; /* place to point scanner in event of error */ /* * macros for use with parse structure * BEWARE: these know that the parse structure is named `p' !!! */ #define PEEK() (*p->next) #define PEEK2() (*(p->next+1)) #define MORE() (p->next < p->end) #define MORE2() (p->next+1 < p->end) #define SEE(c) (MORE() && PEEK() == (c)) #define SEETWO(a, b) (MORE() && MORE2() && PEEK() == (a) && PEEK2() == (b)) #define EAT(c) ((SEE(c)) ? (NEXT1(), 1) : 0) #define EATTWO(a, b) ((SEETWO(a, b)) ? (NEXT2(), 1) : 0) #define NEXT1() (p->next++) #define NEXT2() (p->next += 2) #define NEXTn(n) (p->next += (n)) #define GETNEXT() (*p->next++) #define SETERROR(e) seterr(p, (e)) #define REQUIRE(co, e) ((void)((co) || SETERROR(e))) #define MUSTSEE(c, e) (REQUIRE(MORE() && PEEK() == (c), e)) #define MUSTEAT(c, e) (REQUIRE(MORE() && GETNEXT() == (c), e)) #define MUSTNOTSEE(c, e) (REQUIRE(!MORE() || PEEK() != (c), e)) #define EMIT(op, sopnd) doemit(p, (sop)(op), (size_t)(sopnd)) #define INSERT(op, pos) doinsert(p, (sop)(op), HERE()-(pos)+1, pos) #define AHEAD(pos) dofwd(p, pos, HERE()-(pos)) #define ASTERN(sop, pos) EMIT(sop, HERE()-pos) #define HERE() (p->slen) #define THERE() (p->slen - 1) #define THERETHERE() (p->slen - 2) #define DROP(n) (p->slen -= (n)) #ifndef NDEBUG static int never = 0; /* for use in asserts; shuts lint up */ #else #define never 0 /* some <assert.h>s have bugs too */ #endif /* - regcomp - interface for parser and compilation = API_EXPORT(int) regcomp(regex_t *, const char *, int); = #define REG_BASIC 0000 = #define REG_EXTENDED 0001 = #define REG_ICASE 0002 = #define REG_NOSUB 0004 = #define REG_NEWLINE 0010 = #define REG_NOSPEC 0020 = #define REG_PEND 0040 = #define REG_DUMP 0200 */ API_EXPORT(int) /* 0 success, otherwise REG_something */ regcomp(preg, pattern, cflags) regex_t *preg; const char *pattern; int cflags; { struct parse pa; register struct re_guts *g; register struct parse *p = &pa; register int i; register size_t len; #ifdef REDEBUG # define GOODFLAGS(f) (f) #else # define GOODFLAGS(f) ((f)&~REG_DUMP) #endif cflags = GOODFLAGS(cflags); if ((cflags®_EXTENDED) && (cflags®_NOSPEC)) return(REG_INVARG); if (cflags®_PEND) { if (preg->re_endp < pattern) return(REG_INVARG); len = preg->re_endp - pattern; } else len = strlen((char *)pattern); /* do the mallocs early so failure handling is easy */ g = (struct re_guts *)malloc(sizeof(struct re_guts) + (NC-1)*sizeof(cat_t)); if (g == NULL) return(REG_ESPACE); p->ssize = len/(size_t)2*(size_t)3 + (size_t)1; /* ugh */ p->strip = (sop *)malloc(p->ssize * sizeof(sop)); p->slen = 0; if (p->strip == NULL) { free((char *)g); return(REG_ESPACE); } /* set things up */ p->g = g; p->next = (char *)pattern; /* convenience; we do not modify it */ p->end = p->next + len; p->error = 0; p->ncsalloc = 0; for (i = 0; i < NPAREN; i++) { p->pbegin[i] = 0; p->pend[i] = 0; } g->csetsize = NC; g->sets = NULL; g->setbits = NULL; g->ncsets = 0; g->cflags = cflags; g->iflags = 0; g->nbol = 0; g->neol = 0; g->must = NULL; g->mlen = 0; g->nsub = 0; g->ncategories = 1; /* category 0 is "everything else" */ g->categories = &g->catspace[-(CHAR_MIN)]; (void) memset((char *)g->catspace, 0, NC*sizeof(cat_t)); g->backrefs = 0; /* do it */ EMIT(OEND, 0); g->firststate = THERE(); if (cflags®_EXTENDED) p_ere(p, OUT); else if (cflags®_NOSPEC) p_str(p); else p_bre(p, OUT, OUT); EMIT(OEND, 0); g->laststate = THERE(); /* tidy up loose ends and fill things in */ categorize(p, g); stripsnug(p, g); findmust(p, g); g->nplus = pluscount(p, g); g->magic = MAGIC2; preg->re_nsub = g->nsub; preg->re_g = g; preg->re_magic = MAGIC1; #ifndef REDEBUG /* not debugging, so can't rely on the assert() in regexec() */ if (g->iflags&BAD) SETERROR(REG_ASSERT); #endif /* win or lose, we're done */ if (p->error != 0) /* lose */ regfree(preg); return(p->error); } /* - p_ere - ERE parser top level, concatenation and alternation == static void p_ere(register struct parse *p, int stop); */ static void p_ere(p, stop) register struct parse *p; int stop; /* character this ERE should end at */ { register char c; register sopno prevback = 0; register sopno prevfwd = 0; register sopno conc; register int first = 1; /* is this the first alternative? */ for (;;) { /* do a bunch of concatenated expressions */ conc = HERE(); while (MORE() && (c = PEEK()) != '|' && c != stop) p_ere_exp(p); REQUIRE(HERE() != conc, REG_EMPTY); /* require nonempty */ if (!EAT('|')) break; /* NOTE BREAK OUT */ if (first) { INSERT(OCH_, conc); /* offset is wrong */ prevfwd = conc; prevback = conc; first = 0; } ASTERN(OOR1, prevback); prevback = THERE(); AHEAD(prevfwd); /* fix previous offset */ prevfwd = HERE(); EMIT(OOR2, 0); /* offset is very wrong */ } if (!first) { /* tail-end fixups */ AHEAD(prevfwd); ASTERN(O_CH, prevback); } assert(!MORE() || SEE(stop)); } /* - p_ere_exp - parse one subERE, an atom possibly followed by a repetition op == static void p_ere_exp(register struct parse *p); */ static void p_ere_exp(p) register struct parse *p; { register char c; register sopno pos; register int count; register int count2; register sopno subno; int wascaret = 0; assert(MORE()); /* caller should have ensured this */ c = GETNEXT(); pos = HERE(); switch (c) { case '(': REQUIRE(MORE(), REG_EPAREN); p->g->nsub++; subno = p->g->nsub; if (subno < NPAREN) p->pbegin[subno] = HERE(); EMIT(OLPAREN, subno); if (!SEE(')')) p_ere(p, ')'); if (subno < NPAREN) { p->pend[subno] = HERE(); assert(p->pend[subno] != 0); } EMIT(ORPAREN, subno); MUSTEAT(')', REG_EPAREN); break; #ifndef POSIX_MISTAKE case ')': /* happens only if no current unmatched ( */ /* * You may ask, why the ifndef? Because I didn't notice * this until slightly too late for 1003.2, and none of the * other 1003.2 regular-expression reviewers noticed it at * all. So an unmatched ) is legal POSIX, at least until * we can get it fixed. */ SETERROR(REG_EPAREN); break; #endif case '^': EMIT(OBOL, 0); p->g->iflags |= USEBOL; p->g->nbol++; wascaret = 1; break; case '$': EMIT(OEOL, 0); p->g->iflags |= USEEOL; p->g->neol++; break; case '|': SETERROR(REG_EMPTY); break; case '*': case '+': case '?': SETERROR(REG_BADRPT); break; case '.': if (p->g->cflags®_NEWLINE) nonnewline(p); else EMIT(OANY, 0); break; case '[': p_bracket(p); break; case '\\': REQUIRE(MORE(), REG_EESCAPE); c = GETNEXT(); ordinary(p, c); break; case '{': /* okay as ordinary except if digit follows */ REQUIRE(!MORE() || !isdigit(PEEK()), REG_BADRPT); /* FALLTHROUGH */ default: ordinary(p, c); break; } if (!MORE()) return; c = PEEK(); /* we call { a repetition if followed by a digit */ if (!( c == '*' || c == '+' || c == '?' || (c == '{' && MORE2() && isdigit(PEEK2())) )) return; /* no repetition, we're done */ NEXT1(); REQUIRE(!wascaret, REG_BADRPT); switch (c) { case '*': /* implemented as +? */ /* this case does not require the (y|) trick, noKLUDGE */ INSERT(OPLUS_, pos); ASTERN(O_PLUS, pos); INSERT(OQUEST_, pos); ASTERN(O_QUEST, pos); break; case '+': INSERT(OPLUS_, pos); ASTERN(O_PLUS, pos); break; case '?': /* KLUDGE: emit y? as (y|) until subtle bug gets fixed */ INSERT(OCH_, pos); /* offset slightly wrong */ ASTERN(OOR1, pos); /* this one's right */ AHEAD(pos); /* fix the OCH_ */ EMIT(OOR2, 0); /* offset very wrong... */ AHEAD(THERE()); /* ...so fix it */ ASTERN(O_CH, THERETHERE()); break; case '{': count = p_count(p); if (EAT(',')) { if (isdigit(PEEK())) { count2 = p_count(p); REQUIRE(count <= count2, REG_BADBR); } else /* single number with comma */ count2 = INFINITY; } else /* just a single number */ count2 = count; repeat(p, pos, count, count2); if (!EAT('}')) { /* error heuristics */ while (MORE() && PEEK() != '}') NEXT1(); REQUIRE(MORE(), REG_EBRACE); SETERROR(REG_BADBR); } break; } if (!MORE()) return; c = PEEK(); if (!( c == '*' || c == '+' || c == '?' || (c == '{' && MORE2() && isdigit(PEEK2())) ) ) return; SETERROR(REG_BADRPT); } /* - p_str - string (no metacharacters) "parser" == static void p_str(register struct parse *p); */ static void p_str(p) register struct parse *p; { REQUIRE(MORE(), REG_EMPTY); while (MORE()) ordinary(p, GETNEXT()); } /* - p_bre - BRE parser top level, anchoring and concatenation == static void p_bre(register struct parse *p, register int end1, \ == register int end2); * Giving end1 as OUT essentially eliminates the end1/end2 check. * * This implementation is a bit of a kludge, in that a trailing $ is first * taken as an ordinary character and then revised to be an anchor. The * only undesirable side effect is that '$' gets included as a character * category in such cases. This is fairly harmless; not worth fixing. * The amount of lookahead needed to avoid this kludge is excessive. */ static void p_bre(p, end1, end2) register struct parse *p; register int end1; /* first terminating character */ register int end2; /* second terminating character */ { register sopno start = HERE(); register int first = 1; /* first subexpression? */ register int wasdollar = 0; if (EAT('^')) { EMIT(OBOL, 0); p->g->iflags |= USEBOL; p->g->nbol++; } while (MORE() && !SEETWO(end1, end2)) { wasdollar = p_simp_re(p, first); first = 0; } if (wasdollar) { /* oops, that was a trailing anchor */ DROP(1); EMIT(OEOL, 0); p->g->iflags |= USEEOL; p->g->neol++; } REQUIRE(HERE() != start, REG_EMPTY); /* require nonempty */ } /* - p_simp_re - parse a simple RE, an atom possibly followed by a repetition == static int p_simp_re(register struct parse *p, int starordinary); */ static int /* was the simple RE an unbackslashed $? */ p_simp_re(p, starordinary) register struct parse *p; int starordinary; /* is a leading * an ordinary character? */ { register int c; register int count; register int count2; register sopno pos; register int i; register sopno subno; # define BACKSL (1<<CHAR_BIT) pos = HERE(); /* repetion op, if any, covers from here */ assert(MORE()); /* caller should have ensured this */ c = GETNEXT(); if (c == '\\') { REQUIRE(MORE(), REG_EESCAPE); c = BACKSL | (unsigned char)GETNEXT(); } switch (c) { case '.': if (p->g->cflags®_NEWLINE) nonnewline(p); else EMIT(OANY, 0); break; case '[': p_bracket(p); break; case BACKSL|'{': SETERROR(REG_BADRPT); break; case BACKSL|'(': p->g->nsub++; subno = p->g->nsub; if (subno < NPAREN) p->pbegin[subno] = HERE(); EMIT(OLPAREN, subno); /* the MORE here is an error heuristic */ if (MORE() && !SEETWO('\\', ')')) p_bre(p, '\\', ')'); if (subno < NPAREN) { p->pend[subno] = HERE(); assert(p->pend[subno] != 0); } EMIT(ORPAREN, subno); REQUIRE(EATTWO('\\', ')'), REG_EPAREN); break; case BACKSL|')': /* should not get here -- must be user */ case BACKSL|'}': SETERROR(REG_EPAREN); break; case BACKSL|'1': case BACKSL|'2': case BACKSL|'3': case BACKSL|'4': case BACKSL|'5': case BACKSL|'6': case BACKSL|'7': case BACKSL|'8': case BACKSL|'9': i = (c&~BACKSL) - '0'; assert(i < NPAREN); if (p->pend[i] != 0) { assert(i <= p->g->nsub); EMIT(OBACK_, i); assert(p->pbegin[i] != 0); assert(OP(p->strip[p->pbegin[i]]) == OLPAREN); assert(OP(p->strip[p->pend[i]]) == ORPAREN); (void) dupl(p, p->pbegin[i]+1, p->pend[i]); EMIT(O_BACK, i); } else SETERROR(REG_ESUBREG); p->g->backrefs = 1; break; case '*': REQUIRE(starordinary, REG_BADRPT); /* FALLTHROUGH */ default: ordinary(p, c &~ BACKSL); break; } if (EAT('*')) { /* implemented as +? */ /* this case does not require the (y|) trick, noKLUDGE */ INSERT(OPLUS_, pos); ASTERN(O_PLUS, pos); INSERT(OQUEST_, pos); ASTERN(O_QUEST, pos); } else if (EATTWO('\\', '{')) { count = p_count(p); if (EAT(',')) { if (MORE() && isdigit(PEEK())) { count2 = p_count(p); REQUIRE(count <= count2, REG_BADBR); } else /* single number with comma */ count2 = INFINITY; } else /* just a single number */ count2 = count; repeat(p, pos, count, count2); if (!EATTWO('\\', '}')) { /* error heuristics */ while (MORE() && !SEETWO('\\', '}')) NEXT1(); REQUIRE(MORE(), REG_EBRACE); SETERROR(REG_BADBR); } } else if (c == (unsigned char)'$') /* $ (but not \$) ends it */ return(1); return(0); } /* - p_count - parse a repetition count == static int p_count(register struct parse *p); */ static int /* the value */ p_count(p) register struct parse *p; { register int count = 0; register int ndigits = 0; while (MORE() && isdigit(PEEK()) && count <= DUPMAX) { count = count*10 + (GETNEXT() - '0'); ndigits++; } REQUIRE(ndigits > 0 && count <= DUPMAX, REG_BADBR); return(count); } /* - p_bracket - parse a bracketed character list == static void p_bracket(register struct parse *p); * * Note a significant property of this code: if the allocset() did SETERROR, * no set operations are done. */ static void p_bracket(p) register struct parse *p; { register cset *cs = allocset(p); register int invert = 0; /* Dept of Truly Sickening Special-Case Kludges */ if (p->next + 5 < p->end && strncmp(p->next, "[:<:]]", 6) == 0) { EMIT(OBOW, 0); NEXTn(6); return; } if (p->next + 5 < p->end && strncmp(p->next, "[:>:]]", 6) == 0) { EMIT(OEOW, 0); NEXTn(6); return; } if (EAT('^')) invert++; /* make note to invert set at end */ if (EAT(']')) CHadd(cs, ']'); else if (EAT('-')) CHadd(cs, '-'); while (MORE() && PEEK() != ']' && !SEETWO('-', ']')) p_b_term(p, cs); if (EAT('-')) CHadd(cs, '-'); MUSTEAT(']', REG_EBRACK); if (p->error != 0) /* don't mess things up further */ return; if (p->g->cflags®_ICASE) { register int i; register int ci; for (i = p->g->csetsize - 1; i >= 0; i--) if (CHIN(cs, i) && isalpha(i)) { ci = othercase(i); if (ci != i) CHadd(cs, ci); } if (cs->multis != NULL) mccase(p, cs); } if (invert) { register int i; for (i = p->g->csetsize - 1; i >= 0; i--) if (CHIN(cs, i)) CHsub(cs, i); else CHadd(cs, i); if (p->g->cflags®_NEWLINE) CHsub(cs, '\n'); if (cs->multis != NULL) mcinvert(p, cs); } assert(cs->multis == NULL); /* xxx */ if (nch(p, cs) == 1) { /* optimize singleton sets */ ordinary(p, firstch(p, cs)); freeset(p, cs); } else EMIT(OANYOF, freezeset(p, cs)); } /* - p_b_term - parse one term of a bracketed character list == static void p_b_term(register struct parse *p, register cset *cs); */ static void p_b_term(p, cs) register struct parse *p; register cset *cs; { register char c; register char start, finish; register int i; /* classify what we've got */ switch ((MORE()) ? PEEK() : '\0') { case '[': c = (MORE2()) ? PEEK2() : '\0'; break; case '-': SETERROR(REG_ERANGE); return; /* NOTE RETURN */ break; default: c = '\0'; break; } switch (c) { case ':': /* character class */ NEXT2(); REQUIRE(MORE(), REG_EBRACK); c = PEEK(); REQUIRE(c != '-' && c != ']', REG_ECTYPE); p_b_cclass(p, cs); REQUIRE(MORE(), REG_EBRACK); REQUIRE(EATTWO(':', ']'), REG_ECTYPE); break; case '=': /* equivalence class */ NEXT2(); REQUIRE(MORE(), REG_EBRACK); c = PEEK(); REQUIRE(c != '-' && c != ']', REG_ECOLLATE); p_b_eclass(p, cs); REQUIRE(MORE(), REG_EBRACK); REQUIRE(EATTWO('=', ']'), REG_ECOLLATE); break; default: /* symbol, ordinary character, or range */ /* xxx revision needed for multichar stuff */ start = p_b_symbol(p); if (SEE('-') && MORE2() && PEEK2() != ']') { /* range */ NEXT1(); if (EAT('-')) finish = '-'; else finish = p_b_symbol(p); } else finish = start; /* xxx what about signed chars here... */ REQUIRE(start <= finish, REG_ERANGE); for (i = start; i <= finish; i++) CHadd(cs, i); break; } } /* - p_b_cclass - parse a character-class name and deal with it == static void p_b_cclass(register struct parse *p, register cset *cs); */ static void p_b_cclass(p, cs) register struct parse *p; register cset *cs; { register char *sp = p->next; register struct cclass *cp; register size_t len; register char *u; register char c; while (MORE() && isalpha(PEEK())) NEXT1(); len = p->next - sp; for (cp = cclasses; cp->name != NULL; cp++) if (strncmp(cp->name, sp, len) == 0 && cp->name[len] == '\0') break; if (cp->name == NULL) { /* oops, didn't find it */ SETERROR(REG_ECTYPE); return; } u = cp->chars; while ((c = *u++) != '\0') CHadd(cs, c); for (u = cp->multis; *u != '\0'; u += strlen(u) + 1) MCadd(p, cs, u); } /* - p_b_eclass - parse an equivalence-class name and deal with it == static void p_b_eclass(register struct parse *p, register cset *cs); * * This implementation is incomplete. xxx */ static void p_b_eclass(p, cs) register struct parse *p; register cset *cs; { register char c; c = p_b_coll_elem(p, '='); CHadd(cs, c); } /* - p_b_symbol - parse a character or [..]ed multicharacter collating symbol == static char p_b_symbol(register struct parse *p); */ static char /* value of symbol */ p_b_symbol(p) register struct parse *p; { register char value; REQUIRE(MORE(), REG_EBRACK); if (!EATTWO('[', '.')) return(GETNEXT()); /* collating symbol */ value = p_b_coll_elem(p, '.'); REQUIRE(EATTWO('.', ']'), REG_ECOLLATE); return(value); } /* - p_b_coll_elem - parse a collating-element name and look it up == static char p_b_coll_elem(register struct parse *p, int endc); */ static char /* value of collating element */ p_b_coll_elem(p, endc) register struct parse *p; int endc; /* name ended by endc,']' */ { register char *sp = p->next; register struct cname *cp; register int len; while (MORE() && !SEETWO(endc, ']')) NEXT1(); if (!MORE()) { SETERROR(REG_EBRACK); return(0); } len = p->next - sp; for (cp = cnames; cp->name != NULL; cp++) if (strncmp(cp->name, sp, len) == 0 && cp->name[len] == '\0') return(cp->code); /* known name */ if (len == 1) return(*sp); /* single character */ SETERROR(REG_ECOLLATE); /* neither */ return(0); } /* - othercase - return the case counterpart of an alphabetic == static char othercase(int ch); */ static char /* if no counterpart, return ch */ othercase(ch) int ch; { assert(isalpha(ch)); if (isupper(ch)) return(tolower(ch)); else if (islower(ch)) return(toupper(ch)); else /* peculiar, but could happen */ return(ch); } /* - bothcases - emit a dualcase version of a two-case character == static void bothcases(register struct parse *p, int ch); * * Boy, is this implementation ever a kludge... */ static void bothcases(p, ch) register struct parse *p; int ch; { register char *oldnext = p->next; register char *oldend = p->end; char bracket[3]; assert(othercase(ch) != ch); /* p_bracket() would recurse */ p->next = bracket; p->end = bracket+2; bracket[0] = ch; bracket[1] = ']'; bracket[2] = '\0'; p_bracket(p); assert(p->next == bracket+2); p->next = oldnext; p->end = oldend; } /* - ordinary - emit an ordinary character == static void ordinary(register struct parse *p, register int ch); */ static void ordinary(p, ch) register struct parse *p; register int ch; { register cat_t *cap = p->g->categories; if ((p->g->cflags®_ICASE) && isalpha(ch) && othercase(ch) != ch) bothcases(p, ch); else { EMIT(OCHAR, (unsigned char)ch); if (cap[ch] == 0) cap[ch] = p->g->ncategories++; } } /* - nonnewline - emit REG_NEWLINE version of OANY == static void nonnewline(register struct parse *p); * * Boy, is this implementation ever a kludge... */ static void nonnewline(p) register struct parse *p; { register char *oldnext = p->next; register char *oldend = p->end; char bracket[4]; p->next = bracket; p->end = bracket+3; bracket[0] = '^'; bracket[1] = '\n'; bracket[2] = ']'; bracket[3] = '\0'; p_bracket(p); assert(p->next == bracket+3); p->next = oldnext; p->end = oldend; } /* - repeat - generate code for a bounded repetition, recursively if needed == static void repeat(register struct parse *p, sopno start, int from, int to); */ static void repeat(p, start, from, to) register struct parse *p; sopno start; /* operand from here to end of strip */ int from; /* repeated from this number */ int to; /* to this number of times (maybe INFINITY) */ { register sopno finish = HERE(); # define N 2 # define INF 3 # define REP(f, t) ((f)*8 + (t)) # define MAP(n) (((n) <= 1) ? (n) : ((n) == INFINITY) ? INF : N) register sopno copy; if (p->error != 0) /* head off possible runaway recursion */ return; assert(from <= to); switch (REP(MAP(from), MAP(to))) { case REP(0, 0): /* must be user doing this */ DROP(finish-start); /* drop the operand */ break; case REP(0, 1): /* as x{1,1}? */ case REP(0, N): /* as x{1,n}? */ case REP(0, INF): /* as x{1,}? */ /* KLUDGE: emit y? as (y|) until subtle bug gets fixed */ INSERT(OCH_, start); /* offset is wrong... */ repeat(p, start+1, 1, to); ASTERN(OOR1, start); AHEAD(start); /* ... fix it */ EMIT(OOR2, 0); AHEAD(THERE()); ASTERN(O_CH, THERETHERE()); break; case REP(1, 1): /* trivial case */ /* done */ break; case REP(1, N): /* as x?x{1,n-1} */ /* KLUDGE: emit y? as (y|) until subtle bug gets fixed */ INSERT(OCH_, start); ASTERN(OOR1, start); AHEAD(start); EMIT(OOR2, 0); /* offset very wrong... */ AHEAD(THERE()); /* ...so fix it */ ASTERN(O_CH, THERETHERE()); copy = dupl(p, start+1, finish+1); assert(copy == finish+4); repeat(p, copy, 1, to-1); break; case REP(1, INF): /* as x+ */ INSERT(OPLUS_, start); ASTERN(O_PLUS, start); break; case REP(N, N): /* as xx{m-1,n-1} */ copy = dupl(p, start, finish); repeat(p, copy, from-1, to-1); break; case REP(N, INF): /* as xx{n-1,INF} */ copy = dupl(p, start, finish); repeat(p, copy, from-1, to); break; default: /* "can't happen" */ SETERROR(REG_ASSERT); /* just in case */ break; } } /* - seterr - set an error condition == static int seterr(register struct parse *p, int e); */ static int /* useless but makes type checking happy */ seterr(p, e) register struct parse *p; int e; { if (p->error == 0) /* keep earliest error condition */ p->error = e; p->next = nuls; /* try to bring things to a halt */ p->end = nuls; return(0); /* make the return value well-defined */ } /* - allocset - allocate a set of characters for [] == static cset *allocset(register struct parse *p); */ static cset * allocset(p) register struct parse *p; { register int no = p->g->ncsets++; register size_t nc; register size_t nbytes; register cset *cs; register size_t css = (size_t)p->g->csetsize; register int i; if (no >= p->ncsalloc) { /* need another column of space */ p->ncsalloc += CHAR_BIT; nc = p->ncsalloc; assert(nc % CHAR_BIT == 0); nbytes = nc / CHAR_BIT * css; if (p->g->sets == NULL) p->g->sets = (cset *)malloc(nc * sizeof(cset)); else p->g->sets = (cset *)realloc((char *)p->g->sets, nc * sizeof(cset)); if (p->g->setbits == NULL) p->g->setbits = (uch *)malloc(nbytes); else { p->g->setbits = (uch *)realloc((char *)p->g->setbits, nbytes); /* xxx this isn't right if setbits is now NULL */ for (i = 0; i < no; i++) p->g->sets[i].ptr = p->g->setbits + css*(i/CHAR_BIT); } if (p->g->sets != NULL && p->g->setbits != NULL) (void) memset((char *)p->g->setbits + (nbytes - css), 0, css); else { no = 0; SETERROR(REG_ESPACE); /* caller's responsibility not to do set ops */ } } assert(p->g->sets != NULL); /* xxx */ cs = &p->g->sets[no]; cs->ptr = p->g->setbits + css*((no)/CHAR_BIT); cs->mask = 1 << ((no) % CHAR_BIT); cs->hash = 0; cs->smultis = 0; cs->multis = NULL; return(cs); } /* - freeset - free a now-unused set == static void freeset(register struct parse *p, register cset *cs); */ static void freeset(p, cs) register struct parse *p; register cset *cs; { register unsigned int i; register cset *top = &p->g->sets[p->g->ncsets]; register size_t css = (size_t)p->g->csetsize; for (i = 0; i < css; i++) CHsub(cs, i); if (cs == top-1) /* recover only the easy case */ p->g->ncsets--; } /* - freezeset - final processing on a set of characters == static int freezeset(register struct parse *p, register cset *cs); * * The main task here is merging identical sets. This is usually a waste * of time (although the hash code minimizes the overhead), but can win * big if REG_ICASE is being used. REG_ICASE, by the way, is why the hash * is done using addition rather than xor -- all ASCII [aA] sets xor to * the same value! */ static int /* set number */ freezeset(p, cs) register struct parse *p; register cset *cs; { register uch h = cs->hash; register unsigned int i; register cset *top = &p->g->sets[p->g->ncsets]; register cset *cs2; register size_t css = (size_t)p->g->csetsize; /* look for an earlier one which is the same */ for (cs2 = &p->g->sets[0]; cs2 < top; cs2++) if (cs2->hash == h && cs2 != cs) { /* maybe */ for (i = 0; i < css; i++) if (!!CHIN(cs2, i) != !!CHIN(cs, i)) break; /* no */ if (i == css) break; /* yes */ } if (cs2 < top) { /* found one */ freeset(p, cs); cs = cs2; } return((int)(cs - p->g->sets)); } /* - firstch - return first character in a set (which must have at least one) == static int firstch(register struct parse *p, register cset *cs); */ static int /* character; there is no "none" value */ firstch(p, cs) register struct parse *p; register cset *cs; { register unsigned int i; register size_t css = (size_t)p->g->csetsize; for (i = 0; i < css; i++) if (CHIN(cs, i)) return((char)i); assert(never); return(0); /* arbitrary */ } /* - nch - number of characters in a set == static int nch(register struct parse *p, register cset *cs); */ static int nch(p, cs) register struct parse *p; register cset *cs; { register unsigned int i; register size_t css = (size_t)p->g->csetsize; register int n = 0; for (i = 0; i < css; i++) if (CHIN(cs, i)) n++; return(n); } /* - mcadd - add a collating element to a cset == static void mcadd(register struct parse *p, register cset *cs, \ == register char *cp); */ static void mcadd(p, cs, cp) register struct parse *p; register cset *cs; register char *cp; { register size_t oldend = cs->smultis; cs->smultis += strlen(cp) + 1; if (cs->multis == NULL) cs->multis = malloc(cs->smultis); else cs->multis = realloc(cs->multis, cs->smultis); if (cs->multis == NULL) { SETERROR(REG_ESPACE); return; } (void) strcpy(cs->multis + oldend - 1, cp); cs->multis[cs->smultis - 1] = '\0'; } /* - mcinvert - invert the list of collating elements in a cset == static void mcinvert(register struct parse *p, register cset *cs); * * This would have to know the set of possibilities. Implementation * is deferred. */ static void mcinvert(p, cs) register struct parse *p; register cset *cs; { assert(cs->multis == NULL); /* xxx */ } /* - mccase - add case counterparts of the list of collating elements in a cset == static void mccase(register struct parse *p, register cset *cs); * * This would have to know the set of possibilities. Implementation * is deferred. */ static void mccase(p, cs) register struct parse *p; register cset *cs; { assert(cs->multis == NULL); /* xxx */ } /* - isinsets - is this character in any sets? == static int isinsets(register struct re_guts *g, int c); */ static int /* predicate */ isinsets(g, c) register struct re_guts *g; int c; { register uch *col; register int i; register int ncols = (g->ncsets+(CHAR_BIT-1)) / CHAR_BIT; register unsigned uc = (unsigned char)c; for (i = 0, col = g->setbits; i < ncols; i++, col += g->csetsize) if (col[uc] != 0) return(1); return(0); } /* - samesets - are these two characters in exactly the same sets? == static int samesets(register struct re_guts *g, int c1, int c2); */ static int /* predicate */ samesets(g, c1, c2) register struct re_guts *g; int c1; int c2; { register uch *col; register int i; register int ncols = (g->ncsets+(CHAR_BIT-1)) / CHAR_BIT; register unsigned uc1 = (unsigned char)c1; register unsigned uc2 = (unsigned char)c2; for (i = 0, col = g->setbits; i < ncols; i++, col += g->csetsize) if (col[uc1] != col[uc2]) return(0); return(1); } /* - categorize - sort out character categories == static void categorize(struct parse *p, register struct re_guts *g); */ static void categorize(p, g) struct parse *p; register struct re_guts *g; { register cat_t *cats = g->categories; register int c; register int c2; register cat_t cat; /* avoid making error situations worse */ if (p->error != 0) return; for (c = CHAR_MIN; c <= CHAR_MAX; c++) if (cats[c] == 0 && isinsets(g, c)) { cat = g->ncategories++; cats[c] = cat; for (c2 = c+1; c2 <= CHAR_MAX; c2++) if (cats[c2] == 0 && samesets(g, c, c2)) cats[c2] = cat; } } /* - dupl - emit a duplicate of a bunch of sops == static sopno dupl(register struct parse *p, sopno start, sopno finish); */ static sopno /* start of duplicate */ dupl(p, start, finish) register struct parse *p; sopno start; /* from here */ sopno finish; /* to this less one */ { register sopno ret = HERE(); register sopno len = finish - start; assert(finish >= start); if (len == 0) return(ret); enlarge(p, p->ssize + len); /* this many unexpected additions */ assert(p->ssize >= p->slen + len); (void) memcpy((char *)(p->strip + p->slen), (char *)(p->strip + start), (size_t)len*sizeof(sop)); p->slen += len; return(ret); } /* - doemit - emit a strip operator == static void doemit(register struct parse *p, sop op, size_t opnd); * * It might seem better to implement this as a macro with a function as * hard-case backup, but it's just too big and messy unless there are * some changes to the data structures. Maybe later. */ static void doemit(p, op, opnd) register struct parse *p; sop op; size_t opnd; { /* avoid making error situations worse */ if (p->error != 0) return; /* deal with oversize operands ("can't happen", more or less) */ assert(opnd < 1<<OPSHIFT); /* deal with undersized strip */ if (p->slen >= p->ssize) enlarge(p, (p->ssize+1) / 2 * 3); /* +50% */ assert(p->slen < p->ssize); /* finally, it's all reduced to the easy case */ p->strip[p->slen++] = SOP(op, opnd); } /* - doinsert - insert a sop into the strip == static void doinsert(register struct parse *p, sop op, size_t opnd, sopno pos); */ static void doinsert(p, op, opnd, pos) register struct parse *p; sop op; size_t opnd; sopno pos; { register sopno sn; register sop s; register int i; /* avoid making error situations worse */ if (p->error != 0) return; sn = HERE(); EMIT(op, opnd); /* do checks, ensure space */ assert(HERE() == sn+1); s = p->strip[sn]; /* adjust paren pointers */ assert(pos > 0); for (i = 1; i < NPAREN; i++) { if (p->pbegin[i] >= pos) { p->pbegin[i]++; } if (p->pend[i] >= pos) { p->pend[i]++; } } memmove((char *)&p->strip[pos+1], (char *)&p->strip[pos], (HERE()-pos-1)*sizeof(sop)); p->strip[pos] = s; } /* - dofwd - complete a forward reference == static void dofwd(register struct parse *p, sopno pos, sop value); */ static void dofwd(p, pos, value) register struct parse *p; register sopno pos; sop value; { /* avoid making error situations worse */ if (p->error != 0) return; assert(value < 1<<OPSHIFT); p->strip[pos] = OP(p->strip[pos]) | value; } /* - enlarge - enlarge the strip == static void enlarge(register struct parse *p, sopno size); */ static void enlarge(p, size) register struct parse *p; register sopno size; { register sop *sp; if (p->ssize >= size) return; sp = (sop *)realloc(p->strip, size*sizeof(sop)); if (sp == NULL) { SETERROR(REG_ESPACE); return; } p->strip = sp; p->ssize = size; } /* - stripsnug - compact the strip == static void stripsnug(register struct parse *p, register struct re_guts *g); */ static void stripsnug(p, g) register struct parse *p; register struct re_guts *g; { g->nstates = p->slen; g->strip = (sop *)realloc((char *)p->strip, p->slen * sizeof(sop)); if (g->strip == NULL) { SETERROR(REG_ESPACE); g->strip = p->strip; } } /* - findmust - fill in must and mlen with longest mandatory literal string == static void findmust(register struct parse *p, register struct re_guts *g); * * This algorithm could do fancy things like analyzing the operands of | * for common subsequences. Someday. This code is simple and finds most * of the interesting cases. * * Note that must and mlen got initialized during setup. */ static void findmust(p, g) struct parse *p; register struct re_guts *g; { register sop *scan; sop *start = NULL; register sop *newstart = NULL; register sopno newlen; register sop s; register char *cp; register sopno i; /* avoid making error situations worse */ if (p->error != 0) return; /* find the longest OCHAR sequence in strip */ newlen = 0; scan = g->strip + 1; do { s = *scan++; switch (OP(s)) { case OCHAR: /* sequence member */ if (newlen == 0) /* new sequence */ newstart = scan - 1; newlen++; break; case OPLUS_: /* things that don't break one */ case OLPAREN: case ORPAREN: break; case OQUEST_: /* things that must be skipped */ case OCH_: scan--; do { scan += OPND(s); s = *scan; /* assert() interferes w debug printouts */ if (OP(s) != O_QUEST && OP(s) != O_CH && OP(s) != OOR2) { g->iflags |= BAD; return; } } while (OP(s) != O_QUEST && OP(s) != O_CH); /* fallthrough */ default: /* things that break a sequence */ if (newlen > g->mlen) { /* ends one */ start = newstart; g->mlen = newlen; } newlen = 0; break; } } while (OP(s) != OEND); if (g->mlen == 0) /* there isn't one */ return; /* turn it into a character string */ g->must = malloc((size_t)g->mlen + 1); if (g->must == NULL) { /* argh; just forget it */ g->mlen = 0; return; } cp = g->must; scan = start; for (i = g->mlen; i > 0; i--) { while (OP(s = *scan++) != OCHAR) continue; assert(cp < g->must + g->mlen); *cp++ = (char)OPND(s); } assert(cp == g->must + g->mlen); *cp++ = '\0'; /* just on general principles */ } /* - pluscount - count + nesting == static sopno pluscount(register struct parse *p, register struct re_guts *g); */ static sopno /* nesting depth */ pluscount(p, g) struct parse *p; register struct re_guts *g; { register sop *scan; register sop s; register sopno plusnest = 0; register sopno maxnest = 0; if (p->error != 0) return(0); /* there may not be an OEND */ scan = g->strip + 1; do { s = *scan++; switch (OP(s)) { case OPLUS_: plusnest++; break; case O_PLUS: if (plusnest > maxnest) maxnest = plusnest; plusnest--; break; } } while (OP(s) != OEND); if (plusnest != 0) g->iflags |= BAD; return(maxnest); } http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/regcomp.ih?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/regcomp.ih +++ php-src/ext/ereg/regex/regcomp.ih /* ========= begin header generated by ../../regex/mkh ========= */ #ifdef __cplusplus extern "C" { #endif /* === ../../regex/regcomp.c === */ static void p_ere(register struct parse *p, int stop); static void p_ere_exp(register struct parse *p); static void p_str(register struct parse *p); static void p_bre(register struct parse *p, register int end1, register int end2); static int p_simp_re(register struct parse *p, int starordinary); static int p_count(register struct parse *p); static void p_bracket(register struct parse *p); static void p_b_term(register struct parse *p, register cset *cs); static void p_b_cclass(register struct parse *p, register cset *cs); static void p_b_eclass(register struct parse *p, register cset *cs); static char p_b_symbol(register struct parse *p); static char p_b_coll_elem(register struct parse *p, int endc); static char othercase(int ch); static void bothcases(register struct parse *p, int ch); static void ordinary(register struct parse *p, register int ch); static void nonnewline(register struct parse *p); static void repeat(register struct parse *p, sopno start, int from, int to); static int seterr(register struct parse *p, int e); static cset *allocset(register struct parse *p); static void freeset(register struct parse *p, register cset *cs); static int freezeset(register struct parse *p, register cset *cs); static int firstch(register struct parse *p, register cset *cs); static int nch(register struct parse *p, register cset *cs); static void mcadd(register struct parse *p, register cset *cs, register char *cp); static void mcinvert(register struct parse *p, register cset *cs); static void mccase(register struct parse *p, register cset *cs); static int isinsets(register struct re_guts *g, int c); static int samesets(register struct re_guts *g, int c1, int c2); static void categorize(struct parse *p, register struct re_guts *g); static sopno dupl(register struct parse *p, sopno start, sopno finish); static void doemit(register struct parse *p, sop op, size_t opnd); static void doinsert(register struct parse *p, sop op, size_t opnd, sopno pos); static void dofwd(register struct parse *p, sopno pos, sop value); static void enlarge(register struct parse *p, sopno size); static void stripsnug(register struct parse *p, register struct re_guts *g); static void findmust(register struct parse *p, register struct re_guts *g); static sopno pluscount(register struct parse *p, register struct re_guts *g); #ifdef __cplusplus } #endif /* ========= end header generated by ../../regex/mkh ========= */ http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/regerror.c?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/regerror.c +++ php-src/ext/ereg/regex/regerror.c #include <sys/types.h> #include <stdio.h> #include <string.h> #include <ctype.h> #include <limits.h> #include <stdlib.h> #include <regex.h> #include "utils.h" #include "regerror.ih" /* = #define REG_NOMATCH 1 = #define REG_BADPAT 2 = #define REG_ECOLLATE 3 = #define REG_ECTYPE 4 = #define REG_EESCAPE 5 = #define REG_ESUBREG 6 = #define REG_EBRACK 7 = #define REG_EPAREN 8 = #define REG_EBRACE 9 = #define REG_BADBR 10 = #define REG_ERANGE 11 = #define REG_ESPACE 12 = #define REG_BADRPT 13 = #define REG_EMPTY 14 = #define REG_ASSERT 15 = #define REG_INVARG 16 = #define REG_ATOI 255 // convert name to number (!) = #define REG_ITOA 0400 // convert number to name (!) */ static struct rerr { int code; char *name; char *explain; } rerrs[] = { { REG_NOMATCH, "REG_NOMATCH", "regexec() failed to match" }, { REG_BADPAT, "REG_BADPAT", "invalid regular expression" }, { REG_ECOLLATE, "REG_ECOLLATE", "invalid collating element" }, { REG_ECTYPE, "REG_ECTYPE", "invalid character class" }, { REG_EESCAPE, "REG_EESCAPE", "trailing backslash (\\)" }, { REG_ESUBREG, "REG_ESUBREG", "invalid backreference number" }, { REG_EBRACK, "REG_EBRACK", "brackets ([ ]) not balanced" }, { REG_EPAREN, "REG_EPAREN", "parentheses not balanced" }, { REG_EBRACE, "REG_EBRACE", "braces not balanced" }, { REG_BADBR, "REG_BADBR", "invalid repetition count(s)" }, { REG_ERANGE, "REG_ERANGE", "invalid character range" }, { REG_ESPACE, "REG_ESPACE", "out of memory" }, { REG_BADRPT, "REG_BADRPT", "repetition-operator operand invalid" }, { REG_EMPTY, "REG_EMPTY", "empty (sub)expression" }, { REG_ASSERT, "REG_ASSERT", "\"can't happen\" -- you found a bug" }, { REG_INVARG, "REG_INVARG", "invalid argument to regex routine" }, { 0, "", "*** unknown regexp error code ***" } }; /* - regerror - the interface to error numbers = API_EXPORT(size_t) regerror(int, const regex_t *, char *, size_t); */ /* ARGSUSED */ API_EXPORT(size_t) regerror(errcode, preg, errbuf, errbuf_size) int errcode; const regex_t *preg; char *errbuf; size_t errbuf_size; { register struct rerr *r; register size_t len; register int target = errcode &~ REG_ITOA; register char *s; char convbuf[50]; if (errcode == REG_ATOI) s = regatoi(preg, convbuf); else { for (r = rerrs; r->code != 0; r++) if (r->code == target) break; if (errcode®_ITOA) { if (r->code != 0) (void) strcpy(convbuf, r->name); else sprintf(convbuf, "REG_0x%x", target); assert(strlen(convbuf) < sizeof(convbuf)); s = convbuf; } else s = r->explain; } len = strlen(s) + 1; if (errbuf_size > 0) { if (errbuf_size > len) (void) strcpy(errbuf, s); else { (void) strncpy(errbuf, s, errbuf_size-1); errbuf[errbuf_size-1] = '\0'; } } return(len); } /* - regatoi - internal routine to implement REG_ATOI == static char *regatoi(const regex_t *preg, char *localbuf); */ static char * regatoi(preg, localbuf) const regex_t *preg; char *localbuf; { register struct rerr *r; for (r = rerrs; r->code != 0; r++) if (strcmp(r->name, preg->re_endp) == 0) break; if (r->code == 0) return("0"); sprintf(localbuf, "%d", r->code); return(localbuf); } http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/regerror.ih?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/regerror.ih +++ php-src/ext/ereg/regex/regerror.ih /* ========= begin header generated by ../../regex/mkh ========= */ #ifdef __cplusplus extern "C" { #endif /* === ../../regex/regerror.c === */ static char *regatoi(const regex_t *preg, char *localbuf); #ifdef __cplusplus } #endif /* ========= end header generated by ../../regex/mkh ========= */ http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/regex.3?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/regex.3 +++ php-src/ext/ereg/regex/regex.3..TH REGEX 3 "17 May 1993"..BY "Henry Spencer"..de ZR..\" one other place knows this name: the SEE ALSO section..IR regex (7) \\$1.....SH NAME regcomp, regexec, regerror, regfree \- regular-expression library..SH SYNOPSIS..ft B..\".na #include <sys/types.h>..br #include <regex.h>..HP 10 int regcomp(regex_t\ *preg, const\ char\ *pattern, int\ cflags);..HP int\ regexec(const\ regex_t\ *preg, const\ char\ *string, size_t\ nmatch, regmatch_t\ pmatch[], int\ eflags);..HP size_t\ regerror(int\ errcode, const\ regex_t\ *preg, char\ *errbuf, size_t\ errbuf_size);..HP void\ regfree(regex_t\ *preg);..\".ad..ft..SH DESCRIPTION These routines implement POSIX 1003.2 regular expressions (``RE''s); see..ZR ...I Regcomp compiles an RE written as a string into an internal form,..I regexec matches that internal form against a string and reports results,..I regerror transforms error codes from either into human-readable messages, and..I regfree frees any dynamically-allocated storage used by the internal form of an RE...PP The header..I <regex.h> declares two structure types,..I regex_t and..IR regmatch_t , the former for compiled internal forms and the latter for match reporting. It also declares the four functions, a type..IR regoff_t , and a number of constants with names starting with ``REG_''...PP..I Regcomp compiles the regular expression contained in the..I pattern string, subject to the flags in..IR cflags , and places the results in the..I regex_t structure pointed to by..IR preg ...I Cflags is the bitwise OR of zero or more of the following flags:..IP REG_EXTENDED \w'REG_EXTENDED'u+2n Compile modern (``extended'') REs, rather than the obsolete (``basic'') REs that are the default...IP REG_BASIC This is a synonym for 0, provided as a counterpart to REG_EXTENDED to improve readability...IP REG_NOSPEC Compile with recognition of all special characters turned off. All characters are thus considered ordinary, so the ``RE'' is a literal string. This is an extension, compatible with but not specified by POSIX 1003.2, and should be used with caution in software intended to be portable to other systems. REG_EXTENDED and REG_NOSPEC may not be used in the same call to..IR regcomp ...IP REG_ICASE Compile for matching that ignores upper/lower case distinctions. See..ZR ...IP REG_NOSUB Compile for matching that need only report success or failure, not what was matched...IP REG_NEWLINE Compile for newline-sensitive matching. By default, newline is a completely ordinary character with no special meaning in either REs or strings. With this flag, `[^' bracket expressions and `.' never match newline, a `^' anchor matches the null string after any newline in the string in addition to its normal function, and the `$' anchor matches the null string before any newline in the string in addition to its normal function...IP REG_PEND The regular expression ends, not at the first NUL, but just before the character pointed to by the..I re_endp member of the structure pointed to by..IR preg . The..I re_endp member is of type..IR const\ char\ * . This flag permits inclusion of NULs in the RE; they are considered ordinary characters. This is an extension, compatible with but not specified by POSIX 1003.2, and should be used with caution in software intended to be portable to other systems...PP When successful,..I regcomp returns 0 and fills in the structure pointed to by..IR preg . One member of that structure (other than..IR re_endp ) is publicized:..IR re_nsub , of type..IR size_t , contains the number of parenthesized subexpressions within the RE (except that the value of this member is undefined if the REG_NOSUB flag was used). If..I regcomp fails, it returns a non-zero error code; see DIAGNOSTICS...PP..I Regexec matches the compiled RE pointed to by..I preg against the..IR string , subject to the flags in..IR eflags , and reports results using..IR nmatch ,..IR pmatch , and the returned value. The RE must have been compiled by a previous invocation of..IR regcomp . The compiled form is not altered during execution of..IR regexec , so a single compiled RE can be used simultaneously by multiple threads...PP By default, the NUL-terminated string pointed to by..I string is considered to be the text of an entire line, minus any terminating newline. The..I eflags argument is the bitwise OR of zero or more of the following flags:..IP REG_NOTBOL \w'REG_STARTEND'u+2n The first character of the string is not the beginning of a line, so the `^' anchor should not match before it. This does not affect the behavior of newlines under REG_NEWLINE...IP REG_NOTEOL The NUL terminating the string does not end a line, so the `$' anchor should not match before it. This does not affect the behavior of newlines under REG_NEWLINE...IP REG_STARTEND The string is considered to start at \fIstring\fR\ + \fIpmatch\fR[0].\fIrm_so\fR and to have a terminating NUL located at \fIstring\fR\ + \fIpmatch\fR[0].\fIrm_eo\fR (there need not actually be a NUL at that location), regardless of the value of..IR nmatch . See below for the definition of..IR pmatch and..IR nmatch . This is an extension, compatible with but not specified by POSIX 1003.2, and should be used with caution in software intended to be portable to other systems. Note that a non-zero \fIrm_so\fR does not imply REG_NOTBOL; REG_STARTEND affects only the location of the string, not how it is matched...PP See..ZR for a discussion of what is matched in situations where an RE or a portion thereof could match any of several substrings of..IR string ...PP Normally,..I regexec returns 0 for success and the non-zero code REG_NOMATCH for failure. Other non-zero error codes may be returned in exceptional situations; see DIAGNOSTICS...PP If REG_NOSUB was specified in the compilation of the RE, or if..I nmatch is 0,..I regexec ignores the..I pmatch argument (but see below for the case where REG_STARTEND is specified). Otherwise,..I pmatch points to an array of..I nmatch structures of type..IR regmatch_t . Such a structure has at least the members..I rm_so and..IR rm_eo , both of type..I regoff_t (a signed arithmetic type at least as large as an..I off_t and a..IR ssize_t ), containing respectively the offset of the first character of a substring and the offset of the first character after the end of the substring. Offsets are measured from the beginning of the..I string argument given to..IR regexec . An empty substring is denoted by equal offsets, both indicating the character following the empty substring...PP The 0th member of the..I pmatch array is filled in to indicate what substring of..I string was matched by the entire RE. Remaining members report what substring was matched by parenthesized subexpressions within the RE; member..I i reports subexpression..IR i , with subexpressions counted (starting at 1) by the order of their opening parentheses in the RE, left to right. Unused entries in the array\(emcorresponding either to subexpressions that did not participate in the match at all, or to subexpressions that do not exist in the RE (that is, \fIi\fR\ > \fIpreg\fR\->\fIre_nsub\fR)\(emhave both..I rm_so and..I rm_eo set to \-1. If a subexpression participated in the match several times, the reported substring is the last one it matched. (Note, as an example in particular, that when the RE `(b*)+' matches `bbb', the parenthesized subexpression matches each of the three `b's and then an infinite number of empty strings following the last `b', so the reported substring is one of the empties.)..PP If REG_STARTEND is specified,..I pmatch must point to at least one..I regmatch_t (even if..I nmatch is 0 or REG_NOSUB was specified), to hold the input offsets for REG_STARTEND. Use for output is still entirely controlled by..IR nmatch ; if..I nmatch is 0 or REG_NOSUB was specified, the value of..IR pmatch [0] will not be changed by a successful..IR regexec ...PP..I Regerror maps a non-zero..I errcode from either..I regcomp or..I regexec to a human-readable, printable message. If..I preg is non-NULL, the error code should have arisen from use of the..I regex_t pointed to by..IR preg , and if the error code came from..IR regcomp , it should have been the result from the most recent..I regcomp using that..IR regex_t ...RI ( Regerror may be able to supply a more detailed message using information from the..IR regex_t .)..I Regerror places the NUL-terminated message into the buffer pointed to by..IR errbuf , limiting the length (including the NUL) to at most..I errbuf_size bytes. If the whole message won't fit, as much of it as will fit before the terminating NUL is supplied. In any case, the returned value is the size of buffer needed to hold the whole message (including terminating NUL). If..I errbuf_size is 0,..I errbuf is ignored but the return value is still correct...PP If the..I errcode given to..I regerror is first ORed with REG_ITOA, the ``message'' that results is the printable name of the error code, e.g. ``REG_NOMATCH'', rather than an explanation thereof. If..I errcode is REG_ATOI, then..I preg shall be non-NULL and the..I re_endp member of the structure it points to must point to the printable name of an error code; in this case, the result in..I errbuf is the decimal digits of the numeric value of the error code (0 if the name is not recognized). REG_ITOA and REG_ATOI are intended primarily as debugging facilities; they are extensions, compatible with but not specified by POSIX 1003.2, and should be used with caution in software intended to be portable to other systems. Be warned also that they are considered experimental and changes are possible...PP..I Regfree frees any dynamically-allocated storage associated with the compiled RE pointed to by..IR preg . The remaining..I regex_t is no longer a valid compiled RE and the effect of supplying it to..I regexec or..I regerror is undefined...PP None of these functions references global variables except for tables of constants; all are safe for use from multiple threads if the arguments are safe...SH IMPLEMENTATION CHOICES There are a number of decisions that 1003.2 leaves up to the implementor, either by explicitly saying ``undefined'' or by virtue of them being forbidden by the RE grammar. This implementation treats them as follows...PP See..ZR for a discussion of the definition of case-independent matching...PP There is no particular limit on the length of REs, except insofar as memory is limited. Memory usage is approximately linear in RE size, and largely insensitive to RE complexity, except for bounded repetitions. See BUGS for one short RE using them that will run almost any system out of memory...PP A backslashed character other than one specifically given a magic meaning by 1003.2 (such magic meanings occur only in obsolete [``basic''] REs) is taken as an ordinary character...PP Any unmatched [ is a REG_EBRACK error...PP Equivalence classes cannot begin or end bracket-expression ranges. The endpoint of one range cannot begin another...PP RE_DUP_MAX, the limit on repetition counts in bounded repetitions, is 255...PP A repetition operator (?, *, +, or bounds) cannot follow another repetition operator. A repetition operator cannot begin an expression or subexpression or follow `^' or `|'...PP `|' cannot appear first or last in a (sub)expression or after another `|', i.e. an operand of `|' cannot be an empty subexpression. An empty parenthesized subexpression, `()', is legal and matches an empty (sub)string. An empty string is not a legal RE...PP A `{' followed by a digit is considered the beginning of bounds for a bounded repetition, which must then follow the syntax for bounds. A `{' \fInot\fR followed by a digit is considered an ordinary character...PP `^' and `$' beginning and ending subexpressions in obsolete (``basic'') REs are anchors, not ordinary characters...SH SEE ALSO grep(1), regex(7)..PP POSIX 1003.2, sections 2.8 (Regular Expression Notation) and B.5 (C Binding for Regular Expression Matching)...SH DIAGNOSTICS Non-zero error codes from..I regcomp and..I regexec include the following:..PP..nf..ta \w'REG_ECOLLATE'u+3n REG_NOMATCH regexec() failed to match REG_BADPAT invalid regular expression REG_ECOLLATE invalid collating element REG_ECTYPE invalid character class REG_EESCAPE \e applied to unescapable character REG_ESUBREG invalid backreference number REG_EBRACK brackets [ ] not balanced REG_EPAREN parentheses ( ) not balanced REG_EBRACE braces { } not balanced REG_BADBR invalid repetition count(s) in { } REG_ERANGE invalid character range in [ ] REG_ESPACE ran out of memory REG_BADRPT ?, *, or + operand invalid REG_EMPTY empty (sub)expression REG_ASSERT ``can't happen''\(emyou found a bug REG_INVARG invalid argument, e.g. negative-length string..fi..SH HISTORY Written by Henry Spencer at University of Toronto, henry@zoo.toronto.edu...SH BUGS This is an alpha release with known defects. Please report problems...PP There is one known functionality bug. The implementation of internationalization is incomplete: the locale is always assumed to be the default one of 1003.2, and only the collating elements etc. of that locale are available...PP The back-reference code is subtle and doubts linger about its correctness in complex cases...PP..I Regexec performance is poor. This will improve with later releases...I Nmatch exceeding 0 is expensive;..I nmatch exceeding 1 is worse...I Regexec is largely insensitive to RE complexity \fIexcept\fR that back references are massively expensive. RE length does matter; in particular, there is a strong speed bonus for keeping RE length under about 30 characters, with most special characters counting roughly double...PP..I Regcomp implements bounded repetitions by macro expansion, which is costly in time and space if counts are large or bounded repetitions are nested. An RE like, say, `((((a{1,100}){1,100}){1,100}){1,100}){1,100}' will (eventually) run almost any existing machine out of swap space...PP There are suspected problems with response to obscure error conditions. Notably, certain kinds of internal overflow, produced only by truly enormous REs or by multiply nested bounded repetitions, are probably not handled well...PP Due to a mistake in 1003.2, things like `a)b' are legal REs because `)' is a special character only in the presence of a previous unmatched `('. This can't be fixed until the spec is fixed...PP The standard's definition of back references is vague. For example, does `a\e(\e(b\e)*\e2\e)*d' match `abbbd'? Until the standard is clarified, behavior in such cases should not be relied on...PP The implementation of word-boundary matching is a bit of a kludge, and bugs may lurk in combinations of word-boundary matching and anchoring. http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/regex.7?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/regex.7 +++ php-src/ext/ereg/regex/regex.7..TH REGEX 7 "7 Feb 1994"..BY "Henry Spencer"..SH NAME regex \- POSIX 1003.2 regular expressions..SH DESCRIPTION Regular expressions (``RE''s), as defined in POSIX 1003.2, come in two forms: modern REs (roughly those of..IR egrep ; 1003.2 calls these ``extended'' REs) and obsolete REs (roughly those of..IR ed ; 1003.2 ``basic'' REs). Obsolete REs mostly exist for backward compatibility in some old programs; they will be discussed at the end. 1003.2 leaves some aspects of RE syntax and semantics open; `\(dg' marks decisions on these aspects that may not be fully portable to other 1003.2 implementations...PP A (modern) RE is one\(dg or more non-empty\(dg \fIbranches\fR, separated by `|'. It matches anything that matches one of the branches...PP A branch is one\(dg or more \fIpieces\fR, concatenated. It matches a match for the first, followed by a match for the second, etc...PP A piece is an \fIatom\fR possibly followed by a single\(dg `*', `+', `?', or \fIbound\fR. An atom followed by `*' matches a sequence of 0 or more matches of the atom. An atom followed by `+' matches a sequence of 1 or more matches of the atom. An atom followed by `?' matches a sequence of 0 or 1 matches of the atom...PP A \fIbound\fR is `{' followed by an unsigned decimal integer, possibly followed by `,' possibly followed by another unsigned decimal integer, always followed by `}'. The integers must lie between 0 and RE_DUP_MAX (255\(dg) inclusive, and if there are two of them, the first may not exceed the second. An atom followed by a bound containing one integer \fIi\fR and no comma matches a sequence of exactly \fIi\fR matches of the atom. An atom followed by a bound containing one integer \fIi\fR and a comma matches a sequence of \fIi\fR or more matches of the atom. An atom followed by a bound containing two integers \fIi\fR and \fIj\fR matches a sequence of \fIi\fR through \fIj\fR (inclusive) matches of the atom...PP An atom is a regular expression enclosed in `()' (matching a match for the regular expression), an empty set of `()' (matching the null string)\(dg, a \fIbracket expression\fR (see below), `.' (matching any single character), `^' (matching the null string at the beginning of a line), `$' (matching the null string at the end of a line), a `\e' followed by one of the characters `^.[$()|*+?{\e' (matching that character taken as an ordinary character), a `\e' followed by any other character\(dg (matching that character taken as an ordinary character, as if the `\e' had not been present\(dg), or a single character with no other significance (matching that character). A `{' followed by a character other than a digit is an ordinary character, not the beginning of a bound\(dg. It is illegal to end an RE with `\e'...PP A \fIbracket expression\fR is a list of characters enclosed in `[]'. It normally matches any single character from the list (but see below). If the list begins with `^', it matches any single character (but see below) \fInot\fR from the rest of the list. If two characters in the list are separated by `\-', this is shorthand for the full \fIrange\fR of characters between those two (inclusive) in the collating sequence, e.g. `[0-9]' in ASCII matches any decimal digit. It is illegal\(dg for two ranges to share an endpoint, e.g. `a-c-e'. Ranges are very collating-sequence-dependent, and portable programs should avoid relying on them...PP To include a literal `]' in the list, make it the first character (following a possible `^'). To include a literal `\-', make it the first or last character, or the second endpoint of a range. To use a literal `\-' as the first endpoint of a range, enclose it in `[.' and `.]' to make it a collating element (see below). With the exception of these and some combinations using `[' (see next paragraphs), all other special characters, including `\e', lose their special significance within a bracket expression...PP Within a bracket expression, a collating element (a character, a multi-character sequence that collates as if it were a single character, or a collating-sequence name for either) enclosed in `[.' and `.]' stands for the sequence of characters of that collating element. The sequence is a single element of the bracket expression's list. A bracket expression containing a multi-character collating element can thus match more than one character, e.g. if the collating sequence includes a `ch' collating element, then the RE `[[.ch.]]*c' matches the first five characters of `chchcc'...PP Within a bracket expression, a collating element enclosed in `[=' and `=]' is an equivalence class, standing for the sequences of characters of all collating elements equivalent to that one, including itself. (If there are no other equivalent collating elements, the treatment is as if the enclosing delimiters were `[.' and `.]'.) For example, if o and \o'o^' are the members of an equivalence class, then `[[=o=]]', `[[=\o'o^'=]]', and `[o\o'o^']' are all synonymous. An equivalence class may not\(dg be an endpoint of a range...PP Within a bracket expression, the name of a \fIcharacter class\fR enclosed in `[:' and `:]' stands for the list of all characters belonging to that class. Standard character class names are:..PP..RS..nf..ta 3c 6c 9c alnum digit punct alpha graph space blank lower upper cntrl print xdigit..fi..RE..PP These stand for the character classes defined in..IR ctype (3). A locale may provide others. A character class may not be used as an endpoint of a range...PP There are two special cases\(dg of bracket expressions: the bracket expressions `[[:<:]]' and `[[:>:]]' match the null string at the beginning and end of a word respectively. A word is defined as a sequence of word characters which is neither preceded nor followed by word characters. A word character is an..I alnum character (as defined by..IR ctype (3)) or an underscore. This is an extension, compatible with but not specified by POSIX 1003.2, and should be used with caution in software intended to be portable to other systems...PP In the event that an RE could match more than one substring of a given string, the RE matches the one starting earliest in the string. If the RE could match more than one substring starting at that point, it matches the longest. Subexpressions also match the longest possible substrings, subject to the constraint that the whole match be as long as possible, with subexpressions starting earlier in the RE taking priority over ones starting later. Note that higher-level subexpressions thus take priority over their lower-level component subexpressions...PP Match lengths are measured in characters, not collating elements. A null string is considered longer than no match at all. For example, `bb*' matches the three middle characters of `abbbc', `(wee|week)(knights|nights)' matches all ten characters of `weeknights', when `(.*).*' is matched against `abc' the parenthesized subexpression matches all three characters, and when `(a*)*' is matched against `bc' both the whole RE and the parenthesized subexpression match the null string...PP If case-independent matching is specified, the effect is much as if all case distinctions had vanished from the alphabet. When an alphabetic that exists in multiple cases appears as an ordinary character outside a bracket expression, it is effectively transformed into a bracket expression containing both cases, e.g. `x' becomes `[xX]'. When it appears inside a bracket expression, all case counterparts of it are added to the bracket expression, so that (e.g.) `[x]' becomes `[xX]' and `[^x]' becomes `[^xX]'...PP No particular limit is imposed on the length of REs\(dg. Programs intended to be portable should not employ REs longer than 256 bytes, as an implementation can refuse to accept such REs and remain POSIX-compliant...PP Obsolete (``basic'') regular expressions differ in several respects. `|', `+', and `?' are ordinary characters and there is no equivalent for their functionality. The delimiters for bounds are `\e{' and `\e}', with `{' and `}' by themselves ordinary characters. The parentheses for nested subexpressions are `\e(' and `\e)', with `(' and `)' by themselves ordinary characters. `^' is an ordinary character except at the beginning of the RE or\(dg the beginning of a parenthesized subexpression, `$' is an ordinary character except at the end of the RE or\(dg the end of a parenthesized subexpression, and `*' is an ordinary character if it appears at the beginning of the RE or the beginning of a parenthesized subexpression (after a possible leading `^'). Finally, there is one new type of atom, a \fIback reference\fR: `\e' followed by a non-zero decimal digit \fId\fR matches the same sequence of characters matched by the \fId\fRth parenthesized subexpression (numbering subexpressions by the positions of their opening parentheses, left to right), so that (e.g.) `\e([bc]\e)\e1' matches `bb' or `cc' but not `bc'...SH SEE ALSO regex(3)..PP POSIX 1003.2, section 2.8 (Regular Expression Notation)...SH BUGS Having two kinds of REs is a botch...PP The current 1003.2 spec says that `)' is an ordinary character in the absence of an unmatched `('; this was an unintentional result of a wording error, and change is likely. Avoid relying on it...PP Back references are a dreadful botch, posing major problems for efficient implementations. They are also somewhat vaguely defined (does `a\e(\e(b\e)*\e2\e)*d' match `abbbd'?). Avoid using them...PP 1003.2's specification of case-independent matching is vague. The ``one case implies all cases'' definition given above is current consensus among implementors as to the right interpretation...PP The syntax for word boundaries is incredibly ugly. http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/regex.dsp?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/regex.dsp +++ php-src/ext/ereg/regex/regex.dsp # Microsoft Developer Studio Project File - Name="regex" - Package Owner=<4> # Microsoft Developer Studio Generated Build File, Format Version 5.00 # ** DO NOT EDIT ** # TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 CFG=regex - Win32 Debug !MESSAGE This is not a valid makefile. To build this project using NMAKE, !MESSAGE use the Export Makefile command and run !MESSAGE !MESSAGE NMAKE /f "regex.mak". !MESSAGE !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: !MESSAGE !MESSAGE NMAKE /f "regex.mak" CFG="regex - Win32 Debug" !MESSAGE !MESSAGE Possible choices for configuration are: !MESSAGE !MESSAGE "regex - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") !MESSAGE "regex - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") !MESSAGE # Begin Project # PROP Scc_ProjName "" # PROP Scc_LocalPath "" CPP=cl.exe MTL=midl.exe RSC=rc.exe !IF "$(CFG)" == "regex - Win32 Release" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 0 # PROP BASE Output_Dir "Release" # PROP BASE Intermediate_Dir "Release" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 0 # PROP Output_Dir "Release" # PROP Intermediate_Dir "Release" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c # ADD CPP /nologo /MT /W3 /GX /O2 /I "." /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32 # ADD BASE RSC /l 0x409 /d "NDEBUG" # ADD RSC /l 0x409 /d "NDEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 !ELSEIF "$(CFG)" == "regex - Win32 Debug" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 1 # PROP BASE Output_Dir "Debug" # PROP BASE Intermediate_Dir "Debug" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 1 # PROP Output_Dir "Debug" # PROP Intermediate_Dir "Debug" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c # ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /I "." /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32 # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept !ENDIF # Begin Target # Name "regex - Win32 Release" # Name "regex - Win32 Debug" # Begin Source File SOURCE=.\regcomp.c # End Source File # Begin Source File SOURCE=.\regerror.c # End Source File # Begin Source File SOURCE=.\regexec.c # End Source File # Begin Source File SOURCE=.\regfree.c # End Source File # End Target # End Project http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/regex.dsw?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/regex.dsw +++ php-src/ext/ereg/regex/regex.dsw Microsoft Developer Studio Workspace File, Format Version 5.00 # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! ############################################################################### Project: "regex"=.\regex.dsp - Package Owner=<4> Package=<5> {{{ }}} Package=<4> {{{ }}} ############################################################################### Global: Package=<5> {{{ }}} Package=<3> {{{ }}} ############################################################################### http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/regex.h?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/regex.h +++ php-src/ext/ereg/regex/regex.h #ifndef _REGEX_H_ #define _REGEX_H_ /* never again */ /* ========= begin header generated by ./mkh ========= */ #ifdef __cplusplus extern "C" { #endif /* === regex2.h === */ #ifdef WIN32 #define API_EXPORT(type) __declspec(dllexport) type __stdcall #else #define API_EXPORT(type) type #endif typedef off_t regoff_t; typedef struct { int re_magic; size_t re_nsub; /* number of parenthesized subexpressions */ const char *re_endp; /* end pointer for REG_PEND */ struct re_guts *re_g; /* none of your business :-) */ } regex_t; typedef struct { regoff_t rm_so; /* start of match */ regoff_t rm_eo; /* end of match */ } regmatch_t; /* === regcomp.c === */ API_EXPORT(int) regcomp(regex_t *, const char *, int); #define REG_BASIC 0000 #define REG_EXTENDED 0001 #define REG_ICASE 0002 #define REG_NOSUB 0004 #define REG_NEWLINE 0010 #define REG_NOSPEC 0020 #define REG_PEND 0040 #define REG_DUMP 0200 /* === regerror.c === */ #define REG_NOMATCH 1 #define REG_BADPAT 2 #define REG_ECOLLATE 3 #define REG_ECTYPE 4 #define REG_EESCAPE 5 #define REG_ESUBREG 6 #define REG_EBRACK 7 #define REG_EPAREN 8 #define REG_EBRACE 9 #define REG_BADBR 10 #define REG_ERANGE 11 #define REG_ESPACE 12 #define REG_BADRPT 13 #define REG_EMPTY 14 #define REG_ASSERT 15 #define REG_INVARG 16 #define REG_ATOI 255 /* convert name to number (!) */ #define REG_ITOA 0400 /* convert number to name (!) */ API_EXPORT(size_t) regerror(int, const regex_t *, char *, size_t); /* === regexec.c === */ API_EXPORT(int) regexec(const regex_t *, const char *, size_t, regmatch_t [], int); #define REG_NOTBOL 00001 #define REG_NOTEOL 00002 #define REG_STARTEND 00004 #define REG_TRACE 00400 /* tracing of execution */ #define REG_LARGE 01000 /* force large representation */ #define REG_BACKR 02000 /* force use of backref code */ /* === regfree.c === */ API_EXPORT(void) regfree(regex_t *); #ifdef __cplusplus } #endif /* ========= end header generated by ./mkh ========= */ #endif http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/regex.mak?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/regex.mak +++ php-src/ext/ereg/regex/regex.mak # Microsoft Developer Studio Generated NMAKE File, Based on regex.dsp !IF "$(CFG)" == "" CFG=regex - Win32 Release !MESSAGE No configuration specified. Defaulting to regex - Win32 Release. !ENDIF !IF "$(CFG)" != "regex - Win32 Release" && "$(CFG)" != "regex - Win32 Debug" !MESSAGE Invalid configuration "$(CFG)" specified. !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: !MESSAGE !MESSAGE NMAKE /f "regex.mak" CFG="regex - Win32 Release" !MESSAGE !MESSAGE Possible choices for configuration are: !MESSAGE !MESSAGE "regex - Win32 Release" (based on "Win32 (x86) Static Library") !MESSAGE "regex - Win32 Debug" (based on "Win32 (x86) Static Library") !MESSAGE !ERROR An invalid configuration is specified. !ENDIF !IF "$(OS)" == "Windows_NT" NULL= !ELSE NULL=nul !ENDIF CPP=cl.exe !IF "$(CFG)" == "regex - Win32 Release" OUTDIR=.\Release INTDIR=.\Release # Begin Custom Macros OutDir=.\.\Release # End Custom Macros !IF "$(RECURSE)" == "0" ALL : "$(OUTDIR)\regex.lib" !ELSE ALL : "$(OUTDIR)\regex.lib" !ENDIF CLEAN : -@erase "$(INTDIR)\regcomp.obj" -@erase "$(INTDIR)\regerror.obj" -@erase "$(INTDIR)\regexec.obj" -@erase "$(INTDIR)\regfree.obj" -@erase "$(INTDIR)\vc50.idb" -@erase "$(OUTDIR)\regex.lib" "$(OUTDIR)" : if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)" CPP_PROJ=/nologo /MD /W3 /GX /O2 /I "." /D "WIN32" /D "NDEBUG" /D "_WINDOWS"\ /Fp"$(INTDIR)\regex.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c CPP_OBJS=.\Release/ CPP_SBRS=. BSC32=bscmake.exe BSC32_FLAGS=/nologo /o"$(OUTDIR)\regex.bsc" BSC32_SBRS= \ LIB32=link.exe -lib LIB32_FLAGS=/nologo /out:"$(OUTDIR)\regex.lib" LIB32_OBJS= \ "$(INTDIR)\regcomp.obj" \ "$(INTDIR)\regerror.obj" \ "$(INTDIR)\regexec.obj" \ "$(INTDIR)\regfree.obj" "$(OUTDIR)\regex.lib" : "$(OUTDIR)" $(DEF_FILE) $(LIB32_OBJS) $(LIB32) @<< $(LIB32_FLAGS) $(DEF_FLAGS) $(LIB32_OBJS) << !ELSEIF "$(CFG)" == "regex - Win32 Debug" OUTDIR=.\Debug INTDIR=.\Debug # Begin Custom Macros OutDir=.\.\Debug # End Custom Macros !IF "$(RECURSE)" == "0" ALL : "$(OUTDIR)\regex.lib" "$(OUTDIR)\regex.bsc" !ELSE ALL : "$(OUTDIR)\regex.lib" "$(OUTDIR)\regex.bsc" !ENDIF CLEAN : -@erase "$(INTDIR)\regcomp.obj" -@erase "$(INTDIR)\regcomp.sbr" -@erase "$(INTDIR)\regerror.obj" -@erase "$(INTDIR)\regerror.sbr" -@erase "$(INTDIR)\regexec.obj" -@erase "$(INTDIR)\regexec.sbr" -@erase "$(INTDIR)\regfree.obj" -@erase "$(INTDIR)\regfree.sbr" -@erase "$(INTDIR)\vc50.idb" -@erase "$(OUTDIR)\regex.bsc" -@erase "$(OUTDIR)\regex.lib" "$(OUTDIR)" : if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)" CPP_PROJ=/nologo /MDd /W3 /GX /Z7 /Od /I "." /D "WIN32" /D "_DEBUG" /D\ "_WINDOWS" /FR"$(INTDIR)\\" /Fp"$(INTDIR)\regex.pch" /YX /Fo"$(INTDIR)\\"\ /Fd"$(INTDIR)\\" /FD /c CPP_OBJS=.\Debug/ CPP_SBRS=.\Debug/ BSC32=bscmake.exe BSC32_FLAGS=/nologo /o"$(OUTDIR)\regex.bsc" BSC32_SBRS= \ "$(INTDIR)\regcomp.sbr" \ "$(INTDIR)\regerror.sbr" \ "$(INTDIR)\regexec.sbr" \ "$(INTDIR)\regfree.sbr" "$(OUTDIR)\regex.bsc" : "$(OUTDIR)" $(BSC32_SBRS) $(BSC32) @<< $(BSC32_FLAGS) $(BSC32_SBRS) << LIB32=link.exe -lib LIB32_FLAGS=/nologo /out:"$(OUTDIR)\regex.lib" LIB32_OBJS= \ "$(INTDIR)\regcomp.obj" \ "$(INTDIR)\regerror.obj" \ "$(INTDIR)\regexec.obj" \ "$(INTDIR)\regfree.obj" "$(OUTDIR)\regex.lib" : "$(OUTDIR)" $(DEF_FILE) $(LIB32_OBJS) $(LIB32) @<< $(LIB32_FLAGS) $(DEF_FLAGS) $(LIB32_OBJS) << !ENDIF ..c{$(CPP_OBJS)}.obj:: $(CPP) @<< $(CPP_PROJ) $< << ..cpp{$(CPP_OBJS)}.obj:: $(CPP) @<< $(CPP_PROJ) $< << ..cxx{$(CPP_OBJS)}.obj:: $(CPP) @<< $(CPP_PROJ) $< << ..c{$(CPP_SBRS)}.sbr:: $(CPP) @<< $(CPP_PROJ) $< << ..cpp{$(CPP_SBRS)}.sbr:: $(CPP) @<< $(CPP_PROJ) $< << ..cxx{$(CPP_SBRS)}.sbr:: $(CPP) @<< $(CPP_PROJ) $< << !IF "$(CFG)" == "regex - Win32 Release" || "$(CFG)" == "regex - Win32 Debug" SOURCE=.\regcomp.c !IF "$(CFG)" == "regex - Win32 Release" DEP_CPP_REGCO=\ ".\cclass.h"\ ".\cname.h"\ ".\regcomp.ih"\ ".\regex.h"\ ".\regex2.h"\ ".\utils.h"\ "$(INTDIR)\regcomp.obj" : $(SOURCE) $(DEP_CPP_REGCO) "$(INTDIR)" !ELSEIF "$(CFG)" == "regex - Win32 Debug" DEP_CPP_REGCO=\ ".\cclass.h"\ ".\cname.h"\ ".\regcomp.ih"\ ".\regex.h"\ ".\regex2.h"\ ".\utils.h"\ {$(INCLUDE)}"sys\types.h"\ "$(INTDIR)\regcomp.obj" "$(INTDIR)\regcomp.sbr" : $(SOURCE) $(DEP_CPP_REGCO)\ "$(INTDIR)" !ENDIF SOURCE=.\regerror.c !IF "$(CFG)" == "regex - Win32 Release" DEP_CPP_REGER=\ ".\regerror.ih"\ ".\regex.h"\ ".\utils.h"\ "$(INTDIR)\regerror.obj" : $(SOURCE) $(DEP_CPP_REGER) "$(INTDIR)" !ELSEIF "$(CFG)" == "regex - Win32 Debug" DEP_CPP_REGER=\ ".\regerror.ih"\ ".\regex.h"\ ".\utils.h"\ {$(INCLUDE)}"sys\types.h"\ "$(INTDIR)\regerror.obj" "$(INTDIR)\regerror.sbr" : $(SOURCE) $(DEP_CPP_REGER)\ "$(INTDIR)" !ENDIF SOURCE=.\regexec.c !IF "$(CFG)" == "regex - Win32 Release" DEP_CPP_REGEX=\ ".\engine.c"\ ".\engine.ih"\ ".\regex.h"\ ".\regex2.h"\ ".\utils.h"\ "$(INTDIR)\regexec.obj" : $(SOURCE) $(DEP_CPP_REGEX) "$(INTDIR)" !ELSEIF "$(CFG)" == "regex - Win32 Debug" DEP_CPP_REGEX=\ ".\engine.c"\ ".\engine.ih"\ ".\regex.h"\ ".\regex2.h"\ ".\utils.h"\ {$(INCLUDE)}"sys\types.h"\ "$(INTDIR)\regexec.obj" "$(INTDIR)\regexec.sbr" : $(SOURCE) $(DEP_CPP_REGEX)\ "$(INTDIR)" !ENDIF SOURCE=.\regfree.c !IF "$(CFG)" == "regex - Win32 Release" DEP_CPP_REGFR=\ ".\regex.h"\ ".\regex2.h"\ ".\utils.h"\ "$(INTDIR)\regfree.obj" : $(SOURCE) $(DEP_CPP_REGFR) "$(INTDIR)" !ELSEIF "$(CFG)" == "regex - Win32 Debug" DEP_CPP_REGFR=\ ".\regex.h"\ ".\regex2.h"\ ".\utils.h"\ {$(INCLUDE)}"sys\types.h"\ "$(INTDIR)\regfree.obj" "$(INTDIR)\regfree.sbr" : $(SOURCE) $(DEP_CPP_REGFR)\ "$(INTDIR)" !ENDIF SOURCE=.\engine.c !ENDIF http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/regex2.h?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/regex2.h +++ php-src/ext/ereg/regex/regex2.h /* * First, the stuff that ends up in the outside-world include file = #ifdef WIN32 = #define API_EXPORT(type) __declspec(dllexport) type __stdcall = #else = #define API_EXPORT(type) type = #endif = = typedef off_t regoff_t; = typedef struct { = int re_magic; = size_t re_nsub; // number of parenthesized subexpressions = const char *re_endp; // end pointer for REG_PEND = struct re_guts *re_g; // none of your business :-) = } regex_t; = typedef struct { = regoff_t rm_so; // start of match = regoff_t rm_eo; // end of match = } regmatch_t; */ /* * internals of regex_t */ #define MAGIC1 ((('r'^0200)<<8) | 'e') /* * The internal representation is a *strip*, a sequence of * operators ending with an endmarker. (Some terminology etc. is a * historical relic of earlier versions which used multiple strips.) * Certain oddities in the representation are there to permit running * the machinery backwards; in particular, any deviation from sequential * flow must be marked at both its source and its destination. Some * fine points: * * - OPLUS_ and O_PLUS are *inside* the loop they create. * - OQUEST_ and O_QUEST are *outside* the bypass they create. * - OCH_ and O_CH are *outside* the multi-way branch they create, while * OOR1 and OOR2 are respectively the end and the beginning of one of * the branches. Note that there is an implicit OOR2 following OCH_ * and an implicit OOR1 preceding O_CH. * * In state representations, an operator's bit is on to signify a state * immediately *preceding* "execution" of that operator. */ typedef unsigned long sop; /* strip operator */ typedef long sopno; #define OPRMASK 0xf8000000 #define OPDMASK 0x07ffffff #define OPSHIFT ((unsigned)27) #define OP(n) ((n)&OPRMASK) #define OPND(n) ((n)&OPDMASK) #define SOP(op, opnd) ((op)|(opnd)) /* operators meaning operand */ /* (back, fwd are offsets) */ #define OEND (1<<OPSHIFT) /* endmarker - */ #define OCHAR (2<<OPSHIFT) /* character unsigned char */ #define OBOL (3<<OPSHIFT) /* left anchor - */ #define OEOL (4<<OPSHIFT) /* right anchor - */ #define OANY (5<<OPSHIFT) /* . - */ #define OANYOF (6<<OPSHIFT) /* [...] set number */ #define OBACK_ (7<<OPSHIFT) /* begin \d paren number */ #define O_BACK (8<<OPSHIFT) /* end \d paren number */ #define OPLUS_ (9<<OPSHIFT) /* + prefix fwd to suffix */ #define O_PLUS (10<<OPSHIFT) /* + suffix back to prefix */ #define OQUEST_ (11<<OPSHIFT) /* ? prefix fwd to suffix */ #define O_QUEST (12<<OPSHIFT) /* ? suffix back to prefix */ #define OLPAREN (13<<OPSHIFT) /* ( fwd to ) */ #define ORPAREN (14<<OPSHIFT) /* ) back to ( */ #define OCH_ (15<<OPSHIFT) /* begin choice fwd to OOR2 */ #define OOR1 (16u<<OPSHIFT) /* | pt. 1 back to OOR1 or OCH_ */ #define OOR2 (17u<<OPSHIFT) /* | pt. 2 fwd to OOR2 or O_CH */ #define O_CH (18u<<OPSHIFT) /* end choice back to OOR1 */ #define OBOW (19u<<OPSHIFT) /* begin word - */ #define OEOW (20u<<OPSHIFT) /* end word - */ /* * Structure for [] character-set representation. Character sets are * done as bit vectors, grouped 8 to a byte vector for compactness. * The individual set therefore has both a pointer to the byte vector * and a mask to pick out the relevant bit of each byte. A hash code * simplifies testing whether two sets could be identical. * * This will get trickier for multicharacter collating elements. As * preliminary hooks for dealing with such things, we also carry along * a string of multi-character elements, and decide the size of the * vectors at run time. */ typedef struct { uch *ptr; /* -> uch [csetsize] */ uch mask; /* bit within array */ uch hash; /* hash code */ size_t smultis; char *multis; /* -> char[smulti] ab\0cd\0ef\0\0 */ } cset; /* note that CHadd and CHsub are unsafe, and CHIN doesn't yield 0/1 */ #define CHadd(cs, c) ((cs)->ptr[(uch)(c)] |= (cs)->mask, (cs)->hash += (c)) #define CHsub(cs, c) ((cs)->ptr[(uch)(c)] &= ~(cs)->mask, (cs)->hash -= (c)) #define CHIN(cs, c) ((cs)->ptr[(uch)(c)] & (cs)->mask) #define MCadd(p, cs, cp) mcadd(p, cs, cp) /* regcomp() internal fns */ /* stuff for character categories */ typedef unsigned char cat_t; /* * main compiled-expression structure */ struct re_guts { int magic; # define MAGIC2 ((('R'^0200)<<8)|'E') sop *strip; /* malloced area for strip */ int csetsize; /* number of bits in a cset vector */ int ncsets; /* number of csets in use */ cset *sets; /* -> cset [ncsets] */ uch *setbits; /* -> uch[csetsize][ncsets/CHAR_BIT] */ int cflags; /* copy of regcomp() cflags argument */ sopno nstates; /* = number of sops */ sopno firststate; /* the initial OEND (normally 0) */ sopno laststate; /* the final OEND */ int iflags; /* internal flags */ # define USEBOL 01 /* used ^ */ # define USEEOL 02 /* used $ */ # define BAD 04 /* something wrong */ int nbol; /* number of ^ used */ int neol; /* number of $ used */ int ncategories; /* how many character categories */ cat_t *categories; /* ->catspace[-CHAR_MIN] */ char *must; /* match must contain this string */ int mlen; /* length of must */ size_t nsub; /* copy of re_nsub */ int backrefs; /* does it use back references? */ sopno nplus; /* how deep does it nest +s? */ /* catspace must be last */ cat_t catspace[1]; /* actually [NC] */ }; /* misc utilities */ #define OUT (CHAR_MAX+1) /* a non-character value */ #define ISWORD(c) (isalnum(c) || (c) == '_') http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/regexec.c?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/regexec.c +++ php-src/ext/ereg/regex/regexec.c /* * the outer shell of regexec() * * This file includes engine.c *twice*, after muchos fiddling with the * macros that code uses. This lets the same code operate on two different * representations for state sets. */ #include <sys/types.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <limits.h> #include <ctype.h> #include <regex.h> #include "utils.h" #include "regex2.h" #ifndef NDEBUG static int nope = 0; /* for use in asserts; shuts lint up */ #endif /* macros for manipulating states, small version */ #define states long #define states1 states /* for later use in regexec() decision */ #define CLEAR(v) ((v) = 0) #define SET0(v, n) ((v) &= ~(1 << (n))) #define SET1(v, n) ((v) |= 1 << (n)) #define ISSET(v, n) ((v) & (1 << (n))) #define ASSIGN(d, s) ((d) = (s)) #define EQ(a, b) ((a) == (b)) #define STATEVARS int dummy /* dummy version */ #define STATESETUP(m, n) /* nothing */ #define STATETEARDOWN(m) /* nothing */ #define SETUP(v) ((v) = 0) #define onestate int #define INIT(o, n) ((o) = (unsigned)1 << (n)) #define INC(o) ((o) <<= 1) #define ISSTATEIN(v, o) ((v) & (o)) /* some abbreviations; note that some of these know variable names! */ /* do "if I'm here, I can also be there" etc without branches */ #define FWD(dst, src, n) ((dst) |= ((unsigned)(src)&(here)) << (n)) #define BACK(dst, src, n) ((dst) |= ((unsigned)(src)&(here)) >> (n)) #define ISSETBACK(v, n) ((v) & ((unsigned)here >> (n))) /* function names */ #define SNAMES /* engine.c looks after details */ #include "engine.c" /* now undo things */ #undef states #undef CLEAR #undef SET0 #undef SET1 #undef ISSET #undef ASSIGN #undef EQ #undef STATEVARS #undef STATESETUP #undef STATETEARDOWN #undef SETUP #undef onestate #undef INIT #undef INC #undef ISSTATEIN #undef FWD #undef BACK #undef ISSETBACK #undef SNAMES /* macros for manipulating states, large version */ #define states char * #define CLEAR(v) memset(v, 0, m->g->nstates) #define SET0(v, n) ((v)[n] = 0) #define SET1(v, n) ((v)[n] = 1) #define ISSET(v, n) ((v)[n]) #define ASSIGN(d, s) memcpy(d, s, m->g->nstates) #define EQ(a, b) (memcmp(a, b, m->g->nstates) == 0) #define STATEVARS int vn; char *space #define STATESETUP(m, nv) { (m)->space = malloc((nv)*(m)->g->nstates); \ if ((m)->space == NULL) return(REG_ESPACE); \ (m)->vn = 0; } #define STATETEARDOWN(m) { free((m)->space); } #define SETUP(v) ((v) = &m->space[m->vn++ * m->g->nstates]) #define onestate int #define INIT(o, n) ((o) = (n)) #define INC(o) ((o)++) #define ISSTATEIN(v, o) ((v)[o]) /* some abbreviations; note that some of these know variable names! */ /* do "if I'm here, I can also be there" etc without branches */ #define FWD(dst, src, n) ((dst)[here+(n)] |= (src)[here]) #define BACK(dst, src, n) ((dst)[here-(n)] |= (src)[here]) #define ISSETBACK(v, n) ((v)[here - (n)]) /* function names */ #define LNAMES /* flag */ #include "engine.c" /* - regexec - interface for matching = API_EXPORT(int) regexec(const regex_t *, const char *, size_t, \ = regmatch_t [], int); = #define REG_NOTBOL 00001 = #define REG_NOTEOL 00002 = #define REG_STARTEND 00004 = #define REG_TRACE 00400 // tracing of execution = #define REG_LARGE 01000 // force large representation = #define REG_BACKR 02000 // force use of backref code * * We put this here so we can exploit knowledge of the state representation * when choosing which matcher to call. Also, by this point the matchers * have been prototyped. */ API_EXPORT(int) /* 0 success, REG_NOMATCH failure */ regexec(preg, string, nmatch, pmatch, eflags) const regex_t *preg; const char *string; size_t nmatch; regmatch_t pmatch[]; int eflags; { register struct re_guts *g = preg->re_g; #ifdef REDEBUG # define GOODFLAGS(f) (f) #else # define GOODFLAGS(f) ((f)&(REG_NOTBOL|REG_NOTEOL|REG_STARTEND)) #endif if (preg->re_magic != MAGIC1 || g->magic != MAGIC2) return(REG_BADPAT); assert(!(g->iflags&BAD)); if (g->iflags&BAD) /* backstop for no-debug case */ return(REG_BADPAT); eflags = GOODFLAGS(eflags); if (g->nstates <= CHAR_BIT*sizeof(states1) && !(eflags®_LARGE)) return(smatcher(g, (char *)string, nmatch, pmatch, eflags)); else return(lmatcher(g, (char *)string, nmatch, pmatch, eflags)); } http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/regfree.c?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/regfree.c +++ php-src/ext/ereg/regex/regfree.c #include <sys/types.h> #include <stdio.h> #include <stdlib.h> #include <regex.h> #include "utils.h" #include "regex2.h" /* - regfree - free everything = API_EXPORT(void) regfree(regex_t *); */ API_EXPORT(void) regfree(preg) regex_t *preg; { register struct re_guts *g; if (preg->re_magic != MAGIC1) /* oops */ return; /* nice to complain, but hard */ g = preg->re_g; if (g == NULL || g->magic != MAGIC2) /* oops again */ return; preg->re_magic = 0; /* mark it invalid */ g->magic = 0; /* mark it invalid */ if (g->strip != NULL) free((char *)g->strip); if (g->sets != NULL) free((char *)g->sets); if (g->setbits != NULL) free((char *)g->setbits); if (g->must != NULL) free(g->must); free((char *)g); } http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/split.c?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/split.c +++ php-src/ext/ereg/regex/split.c #include <stdio.h> #include <string.h> /* - split - divide a string into fields, like awk split() = int split(char *string, char *fields[], int nfields, char *sep); */ int /* number of fields, including overflow */ split(string, fields, nfields, sep) char *string; char *fields[]; /* list is not NULL-terminated */ int nfields; /* number of entries available in fields[] */ char *sep; /* "" white, "c" single char, "ab" [ab]+ */ { register char *p = string; register char c; /* latest character */ register char sepc = sep[0]; register char sepc2; register int fn; register char **fp = fields; register char *sepp; register int trimtrail; /* white space */ if (sepc == '\0') { while ((c = *p++) == ' ' || c == '\t') continue; p--; trimtrail = 1; sep = " \t"; /* note, code below knows this is 2 long */ sepc = ' '; } else trimtrail = 0; sepc2 = sep[1]; /* now we can safely pick this up */ /* catch empties */ if (*p == '\0') return(0); /* single separator */ if (sepc2 == '\0') { fn = nfields; for (;;) { *fp++ = p; fn--; if (fn == 0) break; while ((c = *p++) != sepc) if (c == '\0') return(nfields - fn); *(p-1) = '\0'; } /* we have overflowed the fields vector -- just count them */ fn = nfields; for (;;) { while ((c = *p++) != sepc) if (c == '\0') return(fn); fn++; } /* not reached */ } /* two separators */ if (sep[2] == '\0') { fn = nfields; for (;;) { *fp++ = p; fn--; while ((c = *p++) != sepc && c != sepc2) if (c == '\0') { if (trimtrail && **(fp-1) == '\0') fn++; return(nfields - fn); } if (fn == 0) break; *(p-1) = '\0'; while ((c = *p++) == sepc || c == sepc2) continue; p--; } /* we have overflowed the fields vector -- just count them */ fn = nfields; while (c != '\0') { while ((c = *p++) == sepc || c == sepc2) continue; p--; fn++; while ((c = *p++) != '\0' && c != sepc && c != sepc2) continue; } /* might have to trim trailing white space */ if (trimtrail) { p--; while ((c = *--p) == sepc || c == sepc2) continue; p++; if (*p != '\0') { if (fn == nfields+1) *p = '\0'; fn--; } } return(fn); } /* n separators */ fn = 0; for (;;) { if (fn < nfields) *fp++ = p; fn++; for (;;) { c = *p++; if (c == '\0') return(fn); sepp = sep; while ((sepc = *sepp++) != '\0' && sepc != c) continue; if (sepc != '\0') /* it was a separator */ break; } if (fn < nfields) *(p-1) = '\0'; for (;;) { c = *p++; sepp = sep; while ((sepc = *sepp++) != '\0' && sepc != c) continue; if (sepc == '\0') /* it wasn't a separator */ break; } p--; } /* not reached */ } #ifdef TEST_SPLIT /* * test program * pgm runs regression * pgm sep splits stdin lines by sep * pgm str sep splits str by sep * pgm str sep n splits str by sep n times */ int main(argc, argv) int argc; char *argv[]; { char buf[512]; register int n; # define MNF 10 char *fields[MNF]; if (argc > 4) for (n = atoi(argv[3]); n > 0; n--) { (void) strcpy(buf, argv[1]); } else if (argc > 3) for (n = atoi(argv[3]); n > 0; n--) { (void) strcpy(buf, argv[1]); (void) split(buf, fields, MNF, argv[2]); } else if (argc > 2) dosplit(argv[1], argv[2]); else if (argc > 1) while (fgets(buf, sizeof(buf), stdin) != NULL) { buf[strlen(buf)-1] = '\0'; /* stomp newline */ dosplit(buf, argv[1]); } else regress(); exit(0); } dosplit(string, seps) char *string; char *seps; { # define NF 5 char *fields[NF]; register int nf; nf = split(string, fields, NF, seps); print(nf, NF, fields); } print(nf, nfp, fields) int nf; int nfp; char *fields[]; { register int fn; register int bound; bound = (nf > nfp) ? nfp : nf; printf("%d:\t", nf); for (fn = 0; fn < bound; fn++) printf("\"%s\"%s", fields[fn], (fn+1 < nf) ? ", " : "\n"); } #define RNF 5 /* some table entries know this */ struct { char *str; char *seps; int nf; char *fi[RNF]; } tests[] = { "", " ", 0, { "" }, " ", " ", 2, { "", "" }, "x", " ", 1, { "x" }, "xy", " ", 1, { "xy" }, "x y", " ", 2, { "x", "y" }, "abc def g ", " ", 5, { "abc", "def", "", "g", "" }, " a bcd", " ", 4, { "", "", "a", "bcd" }, "a b c d e f", " ", 6, { "a", "b", "c", "d", "e f" }, " a b c d ", " ", 6, { "", "a", "b", "c", "d " }, "", " _", 0, { "" }, " ", " _", 2, { "", "" }, "x", " _", 1, { "x" }, "x y", " _", 2, { "x", "y" }, "ab _ cd", " _", 2, { "ab", "cd" }, " a_b c ", " _", 5, { "", "a", "b", "c", "" }, "a b c_d e f", " _", 6, { "a", "b", "c", "d", "e f" }, " a b c d ", " _", 6, { "", "a", "b", "c", "d " }, "", " _~", 0, { "" }, " ", " _~", 2, { "", "" }, "x", " _~", 1, { "x" }, "x y", " _~", 2, { "x", "y" }, "ab _~ cd", " _~", 2, { "ab", "cd" }, " a_b c~", " _~", 5, { "", "a", "b", "c", "" }, "a b_c d~e f", " _~", 6, { "a", "b", "c", "d", "e f" }, "~a b c d ", " _~", 6, { "", "a", "b", "c", "d " }, "", " _~-", 0, { "" }, " ", " _~-", 2, { "", "" }, "x", " _~-", 1, { "x" }, "x y", " _~-", 2, { "x", "y" }, "ab _~- cd", " _~-", 2, { "ab", "cd" }, " a_b c~", " _~-", 5, { "", "a", "b", "c", "" }, "a b_c-d~e f", " _~-", 6, { "a", "b", "c", "d", "e f" }, "~a-b c d ", " _~-", 6, { "", "a", "b", "c", "d " }, "", " ", 0, { "" }, " ", " ", 2, { "", "" }, "x", " ", 1, { "x" }, "xy", " ", 1, { "xy" }, "x y", " ", 2, { "x", "y" }, "abc def g ", " ", 4, { "abc", "def", "g", "" }, " a bcd", " ", 3, { "", "a", "bcd" }, "a b c d e f", " ", 6, { "a", "b", "c", "d", "e f" }, " a b c d ", " ", 6, { "", "a", "b", "c", "d " }, "", "", 0, { "" }, " ", "", 0, { "" }, "x", "", 1, { "x" }, "xy", "", 1, { "xy" }, "x y", "", 2, { "x", "y" }, "abc def g ", "", 3, { "abc", "def", "g" }, "\t a bcd", "", 2, { "a", "bcd" }, " a \tb\t c ", "", 3, { "a", "b", "c" }, "a b c d e ", "", 5, { "a", "b", "c", "d", "e" }, "a b\tc d e f", "", 6, { "a", "b", "c", "d", "e f" }, " a b c d e f ", "", 6, { "a", "b", "c", "d", "e f " }, NULL, NULL, 0, { NULL }, }; regress() { char buf[512]; register int n; char *fields[RNF+1]; register int nf; register int i; register int printit; register char *f; for (n = 0; tests[n].str != NULL; n++) { (void) strcpy(buf, tests[n].str); fields[RNF] = NULL; nf = split(buf, fields, RNF, tests[n].seps); printit = 0; if (nf != tests[n].nf) { printf("split `%s' by `%s' gave %d fields, not %d\n", tests[n].str, tests[n].seps, nf, tests[n].nf); printit = 1; } else if (fields[RNF] != NULL) { printf("split() went beyond array end\n"); printit = 1; } else { for (i = 0; i < nf && i < RNF; i++) { f = fields[i]; if (f == NULL) f = "(NULL)"; if (strcmp(f, tests[n].fi[i]) != 0) { printf("split `%s' by `%s', field %d is `%s', not `%s'\n", tests[n].str, tests[n].seps, i, fields[i], tests[n].fi[i]); printit = 1; } } } if (printit) print(nf, RNF, fields); } } #endif http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/regex/utils.h?view=markup&rev=1.1 Index: php-src/ext/ereg/regex/utils.h +++ php-src/ext/ereg/regex/utils.h /* utility definitions */ #ifndef _POSIX2_RE_DUP_MAX #define _POSIX2_RE_DUP_MAX 255 #endif #define DUPMAX _POSIX2_RE_DUP_MAX /* xxx is this right? */ #define INFINITY (DUPMAX + 1) #define NC (CHAR_MAX - CHAR_MIN + 1) typedef unsigned char uch; /* switch off assertions (if not already off) if no REDEBUG */ #ifndef REDEBUG #ifndef NDEBUG #define NDEBUG /* no assertions please */ #endif #endif #include <assert.h> /* for old systems with bcopy() but no memmove() */ #ifdef USEBCOPY #define memmove(d, s, c) bcopy(s, d, c) #endif http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/tests/.cvsignore?view=markup&rev=1.1 Index: php-src/ext/ereg/tests/.cvsignore +++ php-src/ext/ereg/tests/.cvsignore *.exp *.out *.php phpt.* http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/tests/001.phpt?view=markup&rev=1.1 Index: php-src/ext/ereg/tests/001.phpt +++ php-src/ext/ereg/tests/001.phpt --TEST-- RegReplace test 1 --POST-- --GET-- --FILE-- <?php $a="abc123"; echo ereg_replace("123","def",$a)?> --EXPECT-- abcdef http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/tests/002.phpt?view=markup&rev=1.1 Index: php-src/ext/ereg/tests/002.phpt +++ php-src/ext/ereg/tests/002.phpt --TEST-- RegReplace test 2 --POST-- --GET-- --FILE-- <?php $a="abc123"; echo ereg_replace("123","",$a)?> --EXPECT-- abc http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/tests/003.phpt?view=markup&rev=1.1 Index: php-src/ext/ereg/tests/003.phpt +++ php-src/ext/ereg/tests/003.phpt --TEST-- ereg_replace single-quote test --POST-- --GET-- --FILE-- <?php $a="\\'test"; echo ereg_replace("\\\\'","'",$a) ?> --EXPECT-- 'test http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/tests/004.phpt?view=markup&rev=1.1 Index: php-src/ext/ereg/tests/004.phpt +++ php-src/ext/ereg/tests/004.phpt --TEST-- simple ereg test --POST-- --GET-- --FILE-- <?php $a="This is a nice and simple string"; if (ereg(".*nice and simple.*",$a)) { echo "ok\n"; } if (!ereg(".*doesn't exist.*",$a)) { echo "ok\n"; } ?> --EXPECT-- ok ok http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/tests/005.phpt?view=markup&rev=1.1 Index: php-src/ext/ereg/tests/005.phpt +++ php-src/ext/ereg/tests/005.phpt --TEST-- Test Regular expression register support in ereg --POST-- --GET-- --FILE-- <?php $a="This is a nice and simple string"; echo ereg(".*(is).*(is).*",$a,$registers); echo "\n"; echo $registers[0]; echo "\n"; echo $registers[1]; echo "\n"; echo $registers[2]; echo "\n"; ?> --EXPECT-- 32 This is a nice and simple string is is http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/tests/006.phpt?view=markup&rev=1.1 Index: php-src/ext/ereg/tests/006.phpt +++ php-src/ext/ereg/tests/006.phpt --TEST-- Test ereg_replace of start-of-line --POST-- --GET-- --FILE-- <?php $a="This is a nice and simple string"; echo ereg_replace("^This","That",$a); ?> --EXPECT-- That is a nice and simple string http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/tests/007.phpt?view=markup&rev=1.1 Index: php-src/ext/ereg/tests/007.phpt +++ php-src/ext/ereg/tests/007.phpt --TEST-- Test empty result buffer in reg_replace --POST-- --GET-- --FILE-- <?php $a="abcd"; $b=ereg_replace("abcd","",$a); echo strlen($b); ?> --EXPECT-- 0 http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/tests/008.phpt?view=markup&rev=1.1 Index: php-src/ext/ereg/tests/008.phpt +++ php-src/ext/ereg/tests/008.phpt --TEST-- Test back-references in regular expressions --POST-- --GET-- --FILE-- <?php echo ereg_replace("([a-z]*)([-=+|]*)([0-9]+)","\\3 \\1 \\2\n","abc+-|=123"); ?> --EXPECT-- 123 abc +-|= http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/tests/009.phpt?view=markup&rev=1.1 Index: php-src/ext/ereg/tests/009.phpt +++ php-src/ext/ereg/tests/009.phpt --TEST-- Test split() --POST-- --GET-- --FILE-- <?php $a=split("[[:space:]]","this is a test"); echo count($a) . "\n"; for ($i = 0; $i < count($a); $i++) { echo $a[$i] . "\n"; } ?> --EXPECT-- 4 this is a test http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/tests/010.phpt?view=markup&rev=1.1 Index: php-src/ext/ereg/tests/010.phpt +++ php-src/ext/ereg/tests/010.phpt --TEST-- Long back references --POST-- --GET-- --FILE-- <?php $a="abc122222222223"; echo ereg_replace("1(2*)3","\\1def\\1",$a)?> --EXPECT-- abc2222222222def2222222222 http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/tests/011.phpt?view=markup&rev=1.1 Index: php-src/ext/ereg/tests/011.phpt +++ php-src/ext/ereg/tests/011.phpt --TEST-- \0 back reference --POST-- --GET-- --FILE-- <?php $a="abc123"; echo ereg_replace("123","def\\0ghi",$a)?> --EXPECT-- abcdef123ghi http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/tests/012.phpt?view=markup&rev=1.1 Index: php-src/ext/ereg/tests/012.phpt +++ php-src/ext/ereg/tests/012.phpt --TEST-- nonexisting back reference --POST-- --GET-- --FILE-- <?php $a="abc123"; echo ereg_replace("123",'def\1ghi',$a)?> --EXPECT-- abcdef\1ghi http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/tests/013.phpt?view=markup&rev=1.1 Index: php-src/ext/ereg/tests/013.phpt +++ php-src/ext/ereg/tests/013.phpt --TEST-- escapes in replace string --POST-- --GET-- --FILE-- <?php $a="abc123"; echo ereg_replace("123","def\\g\\\\hi\\",$a)?> --EXPECT-- abcdef\g\\hi\ http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/tests/014.phpt?view=markup&rev=1.1 Index: php-src/ext/ereg/tests/014.phpt +++ php-src/ext/ereg/tests/014.phpt --TEST-- backreferences not replaced recursively --POST-- --GET-- --FILE-- <?php $a="a\\2bxc"; echo ereg_replace("a(.*)b(.*)c","\\1",$a)?> --EXPECT-- \2 http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/tests/015.phpt?view=markup&rev=1.1 Index: php-src/ext/ereg/tests/015.phpt +++ php-src/ext/ereg/tests/015.phpt --TEST-- replace empty matches --POST-- --GET-- --FILE-- <?php echo ereg_replace("^","z","abc123")?> --EXPECT-- zabc123 http://cvs.php.net/viewvc.cgi/php-src/ext/ereg/tests/016.phpt?view=markup&rev=1.1 Index: php-src/ext/ereg/tests/016.phpt +++ php-src/ext/ereg/tests/016.phpt --TEST-- test backslash handling in regular expressions --POST-- --GET-- --FILE-- <?php echo ereg_replace('\?',"abc","?123?")?> --EXPECT-- abc123abc