server/util_pcre.c was copied here from srclib/pcre/pcreposix.c, and has since been de-libpcre'ized.
It currently doesn't look anything like the standard httpd style, and it does not contain an ASL 2.0 License Header. Attached is a patch that cleans the style up, and also adds an ASL license block. If no one cares, I will apply it later tonight. -Paul
Index: server/util_pcre.c =================================================================== --- server/util_pcre.c (revision 168162) +++ server/util_pcre.c (working copy) @@ -1,3 +1,20 @@ +/* Copyright 2001-2005 The Apache Software Foundation or its licensors, as + * applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + /************************************************* * Perl-Compatible Regular Expressions * *************************************************/ @@ -58,40 +75,38 @@ * kept in synch with include/ap_regex.h's AP_REG_E* definitions. */ static const char *const pstring[] = { - "", /* Dummy for value 0 */ - "internal error", /* AP_REG_ASSERT */ - "failed to get memory", /* AP_REG_ESPACE */ - "bad argument", /* AP_REG_INVARG */ - "match failed" /* AP_REG_NOMATCH */ + "", /* Dummy for value 0 */ + "internal error", /* AP_REG_ASSERT */ + "failed to get memory", /* AP_REG_ESPACE */ + "bad argument", /* AP_REG_INVARG */ + "match failed" /* AP_REG_NOMATCH */ }; -AP_DECLARE(apr_size_t) ap_regerror(int errcode, const ap_regex_t *preg, - char *errbuf, apr_size_t errbuf_size) +AP_DECLARE(apr_size_t) ap_regerror(int errcode, const ap_regex_t * preg, + char *errbuf, apr_size_t errbuf_size) { -const char *message, *addmessage; -apr_size_t length, addlength; + const char *message, *addmessage; + apr_size_t length, addlength; -message = (errcode >= (int)(sizeof(pstring)/sizeof(char *)))? - "unknown error code" : pstring[errcode]; -length = strlen(message) + 1; + message = (errcode >= (int) (sizeof(pstring) / sizeof(char *))) ? + "unknown error code" : pstring[errcode]; + length = strlen(message) + 1; -addmessage = " at offset "; -addlength = (preg != NULL && (int)preg->re_erroffset != -1)? - strlen(addmessage) + 6 : 0; + addmessage = " at offset "; + addlength = (preg != NULL && (int) preg->re_erroffset != -1) ? + strlen(addmessage) + 6 : 0; -if (errbuf_size > 0) - { - if (addlength > 0 && errbuf_size >= length + addlength) - apr_snprintf(errbuf, sizeof errbuf, - "%s%s%-6d", message, addmessage, (int)preg->re_erroffset); - else - { - strncpy(errbuf, message, errbuf_size - 1); - errbuf[errbuf_size-1] = 0; + if (errbuf_size > 0) { + if (addlength > 0 && errbuf_size >= length + addlength) + apr_snprintf(errbuf, sizeof errbuf, + "%s%s%-6d", message, addmessage, (int) preg->re_erroffset); + else { + strncpy(errbuf, message, errbuf_size - 1); + errbuf[errbuf_size - 1] = 0; + } } - } -return length + addlength; + return length + addlength; } @@ -101,9 +116,9 @@ * Free store held by a regex * *************************************************/ -AP_DECLARE(void) ap_regfree(ap_regex_t *preg) +AP_DECLARE(void) ap_regfree(ap_regex_t * preg) { -(pcre_free)(preg->re_pcre); + (pcre_free) (preg->re_pcre); } @@ -123,22 +138,25 @@ various non-zero codes on failure */ -AP_DECLARE(int) ap_regcomp(ap_regex_t *preg, const char *pattern, int cflags) +AP_DECLARE(int) ap_regcomp(ap_regex_t * preg, const char *pattern, int cflags) { -const char *errorptr; -int erroffset; -int options = 0; + const char *errorptr; + int erroffset; + int options = 0; -if ((cflags & AP_REG_ICASE) != 0) options |= PCRE_CASELESS; -if ((cflags & AP_REG_NEWLINE) != 0) options |= PCRE_MULTILINE; + if ((cflags & AP_REG_ICASE) != 0) + options |= PCRE_CASELESS; + if ((cflags & AP_REG_NEWLINE) != 0) + options |= PCRE_MULTILINE; -preg->re_pcre = pcre_compile(pattern, options, &errorptr, &erroffset, NULL); -preg->re_erroffset = erroffset; + preg->re_pcre = pcre_compile(pattern, options, &errorptr, &erroffset, NULL); + preg->re_erroffset = erroffset; -if (preg->re_pcre == NULL) return AP_REG_INVARG; + if (preg->re_pcre == NULL) + return AP_REG_INVARG; -preg->re_nsub = pcre_info((const pcre *)preg->re_pcre, NULL, NULL); -return 0; + preg->re_nsub = pcre_info((const pcre *) preg->re_pcre, NULL, NULL); + return 0; } @@ -155,70 +173,81 @@ block of store on the stack, to reduce the use of malloc/free. The threshold is in a macro that can be changed at configure time. */ -AP_DECLARE(int) ap_regexec(const ap_regex_t *preg, const char *string, - apr_size_t nmatch, ap_regmatch_t pmatch[], - int eflags) +AP_DECLARE(int) ap_regexec(const ap_regex_t * preg, const char *string, + apr_size_t nmatch, ap_regmatch_t pmatch[], + int eflags) { -int rc; -int options = 0; -int *ovector = NULL; -int small_ovector[POSIX_MALLOC_THRESHOLD * 3]; -int allocated_ovector = 0; + int rc; + int options = 0; + int *ovector = NULL; + int small_ovector[POSIX_MALLOC_THRESHOLD * 3]; + int allocated_ovector = 0; -if ((eflags & AP_REG_NOTBOL) != 0) options |= PCRE_NOTBOL; -if ((eflags & AP_REG_NOTEOL) != 0) options |= PCRE_NOTEOL; + if ((eflags & AP_REG_NOTBOL) != 0) + options |= PCRE_NOTBOL; + if ((eflags & AP_REG_NOTEOL) != 0) + options |= PCRE_NOTEOL; -((ap_regex_t *)preg)->re_erroffset = (apr_size_t)(-1); /* Only has meaning after compile */ + ((ap_regex_t *) preg)->re_erroffset = (apr_size_t) (-1); /* Only has meaning + * after compile */ -if (nmatch > 0) - { - if (nmatch <= POSIX_MALLOC_THRESHOLD) - { - ovector = &(small_ovector[0]); + if (nmatch > 0) { + if (nmatch <= POSIX_MALLOC_THRESHOLD) { + ovector = &(small_ovector[0]); + } + else { + ovector = (int *) malloc(sizeof(int) * nmatch * 3); + if (ovector == NULL) + return AP_REG_ESPACE; + allocated_ovector = 1; + } } - else - { - ovector = (int *)malloc(sizeof(int) * nmatch * 3); - if (ovector == NULL) return AP_REG_ESPACE; - allocated_ovector = 1; - } - } -rc = pcre_exec((const pcre *)preg->re_pcre, NULL, string, (int)strlen(string), - 0, options, ovector, nmatch * 3); + rc = pcre_exec((const pcre *) preg->re_pcre, NULL, string, (int) strlen(string), + 0, options, ovector, nmatch * 3); -if (rc == 0) rc = nmatch; /* All captured slots were filled in */ + if (rc == 0) + rc = nmatch; /* All captured slots were filled in */ -if (rc >= 0) - { - apr_size_t i; - for (i = 0; i < (apr_size_t)rc; i++) - { - pmatch[i].rm_so = ovector[i*2]; - pmatch[i].rm_eo = ovector[i*2+1]; + if (rc >= 0) { + apr_size_t i; + for (i = 0; i < (apr_size_t) rc; i++) { + pmatch[i].rm_so = ovector[i * 2]; + pmatch[i].rm_eo = ovector[i * 2 + 1]; + } + if (allocated_ovector) + free(ovector); + for (; i < nmatch; i++) + pmatch[i].rm_so = pmatch[i].rm_eo = -1; + return 0; } - if (allocated_ovector) free(ovector); - for (; i < nmatch; i++) pmatch[i].rm_so = pmatch[i].rm_eo = -1; - return 0; - } -else - { - if (allocated_ovector) free(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; - case PCRE_ERROR_MATCHLIMIT: return AP_REG_ESPACE; - case PCRE_ERROR_BADUTF8: return AP_REG_INVARG; - case PCRE_ERROR_BADUTF8_OFFSET: return AP_REG_INVARG; - default: return AP_REG_ASSERT; + else { + if (allocated_ovector) + free(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; + case PCRE_ERROR_MATCHLIMIT: + return AP_REG_ESPACE; + case PCRE_ERROR_BADUTF8: + return AP_REG_INVARG; + case PCRE_ERROR_BADUTF8_OFFSET: + return AP_REG_INVARG; + default: + return AP_REG_ASSERT; + } } - } } /* End of pcreposix.c */
