dnl By default we'll compile and link against the bundled PCRE library
dnl if DIR is supplied, we'll use that for linking
-AC_MSG_CHECKING(whether to use PCRE library)
+AC_MSG_CHECKING(whether to include PCRE support)
AC_ARG_WITH(pcre-regex,
-[ --with-pcre-regex[=DIR] Enable Perl Compatible Regular Expressions support],[
- case "$withval" in
- no)
- AC_MSG_RESULT(no) ;;
- yes)
- EXTRA_LIBS="-Lext/pcre/pcrelib -lpcre $EXTRA_LIBS"
- PCRE_SUBDIR="pcrelib"
- AC_DEFINE(HAVE_PCRE, 1)
- AC_DEFINE(HAVE_BUNDLED_PCRE, 1)
- AC_MSG_RESULT(yes)
- PHP_EXTENSION(pcre) ;;
- *)
- test -f $withval/pcre.h && PCRE_INCLUDE="-I$withval"
- test -f $withval/libpcre.a && PCRE_LIB="-L$withval -lpcre"
-
- if test -n "$PCRE_INCLUDE" && test -n "$PCRE_LIB" ; then
- INCLUDES="$PCRE_INCLUDE $INCLUDES"
- EXTRA_LIBS="$PCRE_LIB $EXTRA_LIBS"
- AC_DEFINE(HAVE_PCRE, 1)
- AC_DEFINE(HAVE_BUNDLED_PCRE, 0)
- PCRE_SUBDIR=
- AC_MSG_RESULT(yes)
- PHP_EXTENSION(pcre)
- else
- AC_MSG_ERROR(Unable to find pcre.h and libpcre.a in $withval)
- fi ;;
- esac
+[ --with-pcre-regex[=DIR] Include Perl Compatible Regular Expressions support],[
+ if test "$withval" = "yes"; then
+ EXTRA_LIBS="-Lext/pcre/pcrelib -lpcre $EXTRA_LIBS"
+ PCRE_SUBDIR="pcrelib"
+ AC_DEFINE(HAVE_PCRE, 1)
+ AC_MSG_RESULT(yes)
+ PHP_EXTENSION(pcre)
+ else
+ AC_MSG_RESULT(no)
+ fi
],[
EXTRA_LIBS="-Lext/pcre/pcrelib -lpcre $EXTRA_LIBS"
PCRE_SUBDIR="pcrelib"
AC_DEFINE(HAVE_PCRE, 1)
- AC_DEFINE(HAVE_BUNDLED_PCRE, 1)
AC_MSG_RESULT(yes)
PHP_EXTENSION(pcre)
])
dnl By default we'll compile and link against the bundled PCRE library
dnl if DIR is supplied, we'll use that for linking
-AC_MSG_CHECKING(whether to use PCRE library)
+AC_MSG_CHECKING(whether to include PCRE support)
AC_ARG_WITH(pcre-regex,
-[ --with-pcre-regex[=DIR] Enable Perl Compatible Regular Expressions support],[
- case "$withval" in
- no)
- AC_MSG_RESULT(no) ;;
- yes)
- EXTRA_LIBS="-Lext/pcre/pcrelib -lpcre $EXTRA_LIBS"
- PCRE_SUBDIR="pcrelib"
- AC_DEFINE(HAVE_PCRE, 1)
- AC_DEFINE(HAVE_BUNDLED_PCRE, 1)
- AC_MSG_RESULT(yes)
- PHP_EXTENSION(pcre) ;;
- *)
- test -f $withval/pcre.h && PCRE_INCLUDE="-I$withval"
- test -f $withval/libpcre.a && PCRE_LIB="-L$withval -lpcre"
-
- if test -n "$PCRE_INCLUDE" && test -n "$PCRE_LIB" ; then
- INCLUDES="$PCRE_INCLUDE $INCLUDES"
- EXTRA_LIBS="$PCRE_LIB $EXTRA_LIBS"
- AC_DEFINE(HAVE_PCRE, 1)
- AC_DEFINE(HAVE_BUNDLED_PCRE, 0)
- PCRE_SUBDIR=
- AC_MSG_RESULT(yes)
- PHP_EXTENSION(pcre)
- else
- AC_MSG_ERROR(Unable to find pcre.h and libpcre.a in $withval)
- fi ;;
- esac
+[ --with-pcre-regex[=DIR] Include Perl Compatible Regular Expressions support],[
+ if test "$withval" = "yes"; then
+ EXTRA_LIBS="-Lext/pcre/pcrelib -lpcre $EXTRA_LIBS"
+ PCRE_SUBDIR="pcrelib"
+ AC_DEFINE(HAVE_PCRE, 1)
+ AC_MSG_RESULT(yes)
+ PHP_EXTENSION(pcre)
+ else
+ AC_MSG_RESULT(no)
+ fi
],[
EXTRA_LIBS="-Lext/pcre/pcrelib -lpcre $EXTRA_LIBS"
PCRE_SUBDIR="pcrelib"
AC_DEFINE(HAVE_PCRE, 1)
- AC_DEFINE(HAVE_BUNDLED_PCRE, 1)
AC_MSG_RESULT(yes)
PHP_EXTENSION(pcre)
])
/* $Id$ */
+/* Get PCRE library from ftp://ftp.cus.cam.ac.uk/pub/software/programs/pcre/ */
+
#include "php.h"
#if HAVE_PCRE
{NULL, NULL, NULL}
};
-php3_module_entry pcre_module_entry = {
+zend_module_entry pcre_module_entry = {
"PCRE", pcre_functions, php_minit_pcre, php_mshutdown_pcre,
php_rinit_pcre, NULL,
php_info_pcre, STANDARD_MODULE_PROPERTIES
count = pcre_exec(re, extra, &subject->value.str.val[subject_offset],
subject->value.str.len-subject_offset,
(subject_offset ? exoptions|PCRE_NOTBOL : exoptions),
- offsets, size_offsets);
+ offsets, size_offsets, 0);
/* Check for too many substrings condition. */
if (count == 0) {
int alloc_len; /* Actual allocated length */
int subject_len; /* Length of the subject string */
int result_len; /* Current length of the result */
- int subject_offset; /* Current position in the subject string */
int backref; /* Backreference number */
char *result, /* Result of replacement */
*new_buf, /* Temporary buffer for re-allocation */
*walkbuf, /* Location of current replacement in the result */
- *walk; /* Used to walk the replacement string */
+ *walk, /* Used to walk the replacement string */
+ *match, /* The current match */
+ *piece, /* The current piece of subject */
+ *subject_end; /* Points to the end of the subject */
/* Compile regex or get it from cache. */
if ((re = _pcre_get_compiled_regex(regex, extra)) == NULL) {
return NULL;
}
- subject_offset = 0;
+ /* Initialize */
result[0] = '\0';
+ piece = subject;
+ subject_end = subject + subject_len;
+ match = NULL;
while (count >= 0) {
/* Execute the regular expression. */
- count = pcre_exec(re, extra, &subject[subject_offset],
- subject_len-subject_offset,
- (subject_offset ? exoptions|PCRE_NOTBOL : exoptions),
- offsets, size_offsets);
-
- /* Check for too many substrings condition. */
+ count = pcre_exec(re, extra, piece,
+ subject_end-piece,
+ (piece==subject ? exoptions : exoptions|PCRE_NOTBOL),
+ offsets, size_offsets, (piece == match));
+
+ /* Check for too many substrings condition. */
if (count == 0) {
zend_error(E_NOTICE, "Matched, but too many substrings\n");
count = size_offsets/3;
}
if (count > 0) {
+ /* Set the match location in piece */
+ match = piece + offsets[0];
+
new_len = strlen(result) + offsets[0]; /* part before the match */
walk = replace;
while (*walk)
}
result_len = strlen(result);
/* copy the part of the string before the match */
- strncat(result, &subject[subject_offset], offsets[0]);
+ strncat(result, piece, match-piece);
/* copy replacement and backrefs */
walkbuf = &result[result_len + offsets[0]];
backref < count) {
result_len = offsets[(backref<<1)+1] - offsets[backref<<1];
memcpy (walkbuf,
- &subject[subject_offset + offsets[backref<<1]],
+ piece + offsets[backref<<1],
result_len);
walkbuf += result_len;
walk += (backref > 9) ? 3 : 2;
*walkbuf++ = *walk++;
*walkbuf = '\0';
- /* and get ready to keep looking for replacements */
- if (offsets[0] == offsets[1]) {
- if (offsets[0] + subject_offset >= subject_len)
- break;
- new_len = strlen (result) + 1;
- if (new_len + 1 > alloc_len) {
- alloc_len = 1 + alloc_len + 2 * new_len;
- new_buf = emalloc(alloc_len * sizeof(char));
- strcpy(new_buf, result);
- efree(result);
- result = new_buf;
- }
- subject_offset += offsets[1] + 1;
- result [new_len-1] = subject[subject_offset-1];
- result [new_len] = '\0';
- } else {
- subject_offset += offsets[1];
- }
+ /* Advance to the next piece */
+ piece += offsets[1];
} else {
- new_len = strlen(result) + strlen(&subject[subject_offset]);
+ new_len = strlen(result) + subject_end-piece;
if (new_len + 1 > alloc_len) {
alloc_len = new_len + 1; /* now we know exactly how long it is */
new_buf = emalloc(alloc_len * sizeof(char));
result = new_buf;
}
/* stick that last bit of string on our output */
- strcat(result, &subject[subject_offset]);
+ strcat(result, piece);
}
}
zval *regex,
*replace,
*subject,
- **subject_entry_ptr,
- *subject_entry,
- *return_entry;
+ **subject_entry_ptr,
+ *subject_entry;
char *result;
/* Get function parameters and do error-checking. */
count = pcre_exec(re, extra, &subject->value.str.val[last_offset],
subject->value.str.len-last_offset,
(last_offset ? exoptions|PCRE_NOTBOL : exoptions),
- offsets, size_offsets);
+ offsets, size_offsets, 0);
/* Check for too many substrings condition. */
if (count == 0) {