util_pcre.c revision cfd9415521847b2f9394fad04fb701cfb955f503
2cacab200fb387e290386593d9b2fca2e7beef33csovant/*************************************************
2cacab200fb387e290386593d9b2fca2e7beef33csovant * Perl-Compatible Regular Expressions *
2cacab200fb387e290386593d9b2fca2e7beef33csovant *************************************************/
2cacab200fb387e290386593d9b2fca2e7beef33csovantThis is a library of functions to support regular expressions whose syntax
2cacab200fb387e290386593d9b2fca2e7beef33csovantand semantics are as close as possible to those of the Perl 5 language. See
2cacab200fb387e290386593d9b2fca2e7beef33csovantthe file Tech.Notes for some information on the internals.
3437829f938dbb44527d91fbbc5f430a1243c5a5JnRouvignacThis module is a wrapper that provides a POSIX API to the underlying PCRE
2cacab200fb387e290386593d9b2fca2e7beef33csovantWritten by: Philip Hazel <ph10@cam.ac.uk>
3437829f938dbb44527d91fbbc5f430a1243c5a5JnRouvignac Copyright (c) 1997-2004 University of Cambridge
3437829f938dbb44527d91fbbc5f430a1243c5a5JnRouvignac-----------------------------------------------------------------------------
3437829f938dbb44527d91fbbc5f430a1243c5a5JnRouvignacRedistribution and use in source and binary forms, with or without
2cacab200fb387e290386593d9b2fca2e7beef33csovantmodification, are permitted provided that the following conditions are met:
2cacab200fb387e290386593d9b2fca2e7beef33csovant * Redistributions of source code must retain the above copyright notice,
2cacab200fb387e290386593d9b2fca2e7beef33csovant this list of conditions and the following disclaimer.
23f633e1b8cc53fdac740eca4ab7e0341890bba2csovant * Redistributions in binary form must reproduce the above copyright
2cacab200fb387e290386593d9b2fca2e7beef33csovant notice, this list of conditions and the following disclaimer in the
2cacab200fb387e290386593d9b2fca2e7beef33csovant documentation and/or other materials provided with the distribution.
2cacab200fb387e290386593d9b2fca2e7beef33csovant * Neither the name of the University of Cambridge nor the names of its
2cacab200fb387e290386593d9b2fca2e7beef33csovant contributors may be used to endorse or promote products derived from
2cacab200fb387e290386593d9b2fca2e7beef33csovant this software without specific prior written permission.
2cacab200fb387e290386593d9b2fca2e7beef33csovantTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2cacab200fb387e290386593d9b2fca2e7beef33csovantAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2cacab200fb387e290386593d9b2fca2e7beef33csovantIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2cacab200fb387e290386593d9b2fca2e7beef33csovantARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
2cacab200fb387e290386593d9b2fca2e7beef33csovantLIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2cacab200fb387e290386593d9b2fca2e7beef33csovantCONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2cacab200fb387e290386593d9b2fca2e7beef33csovantSUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2cacab200fb387e290386593d9b2fca2e7beef33csovantINTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2cacab200fb387e290386593d9b2fca2e7beef33csovantCONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23f633e1b8cc53fdac740eca4ab7e0341890bba2csovantARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23f633e1b8cc53fdac740eca4ab7e0341890bba2csovantPOSSIBILITY OF SUCH DAMAGE.
23f633e1b8cc53fdac740eca4ab7e0341890bba2csovant-----------------------------------------------------------------------------
2cacab200fb387e290386593d9b2fca2e7beef33csovant/* Table of error strings corresponding to POSIX error codes; must be
2cacab200fb387e290386593d9b2fca2e7beef33csovant * kept in synch with include/ap_regex.h's AP_REG_E* definitions.
2cacab200fb387e290386593d9b2fca2e7beef33csovantstatic const char *const pstring[] = {
2cacab200fb387e290386593d9b2fca2e7beef33csovantAP_DECLARE(const char *) ap_pcre_version_string(int which)
switch (which) {
case AP_REG_PCRE_COMPILED:
case AP_REG_PCRE_LOADED:
return pcre_version();
if (errbuf_size > 0) {
const char *errorptr;
int erroffset;
int errcode = 0;
return AP_REG_ESPACE;
return AP_REG_INVARG;
int eflags)
eflags);
int rc;
int options = 0;
int allocated_ovector = 0;
if (nmatch > 0) {
return AP_REG_ESPACE;
if (rc == 0)
if (rc >= 0) {
apr_size_t i;
if (allocated_ovector)
for (; i < nmatch; i++)
if (allocated_ovector)
switch (rc) {
case PCRE_ERROR_NOMATCH:
return AP_REG_NOMATCH;
case PCRE_ERROR_NULL:
return AP_REG_INVARG;
case PCRE_ERROR_BADOPTION:
return AP_REG_INVARG;
case PCRE_ERROR_BADMAGIC:
return AP_REG_INVARG;
case PCRE_ERROR_UNKNOWN_NODE:
return AP_REG_ASSERT;
case PCRE_ERROR_NOMEMORY:
return AP_REG_ESPACE;
#ifdef PCRE_ERROR_MATCHLIMIT
case PCRE_ERROR_MATCHLIMIT:
return AP_REG_ESPACE;
#ifdef PCRE_ERROR_BADUTF8
case PCRE_ERROR_BADUTF8:
return AP_REG_INVARG;
#ifdef PCRE_ERROR_BADUTF8_OFFSET
return AP_REG_INVARG;
return AP_REG_ASSERT;
int upper)
int namecount;
int nameentrysize;
char *nametable;
for (i = 0; i < namecount; i++) {
NULL) :
if (upper) {
return namecount;
/* End of pcreposix.c */