summaryrefslogtreecommitdiff
path: root/pcreposix.c
diff options
context:
space:
mode:
authornigel <nigel@2f5784b3-3f2a-0410-8824-cb99058d5e15>2007-02-24 21:41:21 +0000
committernigel <nigel@2f5784b3-3f2a-0410-8824-cb99058d5e15>2007-02-24 21:41:21 +0000
commitced1f145fdf26ec7df4b9048a9da0ef17e9618f2 (patch)
tree371f88a16cfb5ac0a176622bcd424aa6c28c4cc8 /pcreposix.c
parent2550303b1f255c525d802f94d9c4411a0ccc630f (diff)
downloadpcre-ced1f145fdf26ec7df4b9048a9da0ef17e9618f2.tar.gz
Load pcre-6.5 into code/trunk.
git-svn-id: svn://vcs.exim.org/pcre/code/trunk@87 2f5784b3-3f2a-0410-8824-cb99058d5e15
Diffstat (limited to 'pcreposix.c')
-rw-r--r--pcreposix.c45
1 files changed, 31 insertions, 14 deletions
diff --git a/pcreposix.c b/pcreposix.c
index c8f25ad..cbb1ff8 100644
--- a/pcreposix.c
+++ b/pcreposix.c
@@ -6,7 +6,7 @@
and semantics are as close as possible to those of the Perl 5 language.
Written by Philip Hazel
- Copyright (c) 1997-2005 University of Cambridge
+ Copyright (c) 1997-2006 University of Cambridge
-----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -131,7 +131,7 @@ static const char *const pstring[] = {
* Translate error code to string *
*************************************************/
-PCRE_EXPORT size_t
+PCRE_DATA_SCOPE size_t
regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
{
const char *message, *addmessage;
@@ -166,7 +166,7 @@ return length + addlength;
* Free store held by a regex *
*************************************************/
-PCRE_EXPORT void
+PCRE_DATA_SCOPE void
regfree(regex_t *preg)
{
(pcre_free)(preg->re_pcre);
@@ -189,7 +189,7 @@ Returns: 0 on success
various non-zero codes on failure
*/
-PCRE_EXPORT int
+PCRE_DATA_SCOPE int
regcomp(regex_t *preg, const char *pattern, int cflags)
{
const char *errorptr;
@@ -197,9 +197,11 @@ int erroffset;
int errorcode;
int options = 0;
-if ((cflags & REG_ICASE) != 0) options |= PCRE_CASELESS;
+if ((cflags & REG_ICASE) != 0) options |= PCRE_CASELESS;
if ((cflags & REG_NEWLINE) != 0) options |= PCRE_MULTILINE;
-if ((cflags & REG_DOTALL) != 0) options |= PCRE_DOTALL;
+if ((cflags & REG_DOTALL) != 0) options |= PCRE_DOTALL;
+if ((cflags & REG_NOSUB) != 0) options |= PCRE_NO_AUTO_CAPTURE;
+if ((cflags & REG_UTF8) != 0) options |= PCRE_UTF8;
preg->re_pcre = pcre_compile2(pattern, options, &errorcode, &errorptr,
&erroffset, NULL);
@@ -223,9 +225,13 @@ substring, so we have to get and release working store instead of just using
the POSIX structures as was done in earlier releases when PCRE needed only 2
ints. However, if the number of possible capturing brackets is small, use a
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. */
+in a macro that can be changed at configure time.
-PCRE_EXPORT int
+If REG_NOSUB was specified at compile time, the PCRE_NO_AUTO_CAPTURE flag will
+be set. When this is the case, the nmatch and pmatch arguments are ignored, and
+the only result is yes/no/error. */
+
+PCRE_DATA_SCOPE int
regexec(const regex_t *preg, const char *string, size_t nmatch,
regmatch_t pmatch[], int eflags)
{
@@ -234,13 +240,20 @@ int options = 0;
int *ovector = NULL;
int small_ovector[POSIX_MALLOC_THRESHOLD * 3];
BOOL allocated_ovector = FALSE;
+BOOL nosub =
+ (((const pcre *)preg->re_pcre)->options & PCRE_NO_AUTO_CAPTURE) != 0;
if ((eflags & REG_NOTBOL) != 0) options |= PCRE_NOTBOL;
if ((eflags & REG_NOTEOL) != 0) options |= PCRE_NOTEOL;
((regex_t *)preg)->re_erroffset = (size_t)(-1); /* Only has meaning after compile */
-if (nmatch > 0)
+/* When no string data is being returned, ensure that nmatch is zero.
+Otherwise, ensure the vector for holding the return data is large enough. */
+
+if (nosub) nmatch = 0;
+
+else if (nmatch > 0)
{
if (nmatch <= POSIX_MALLOC_THRESHOLD)
{
@@ -248,6 +261,7 @@ if (nmatch > 0)
}
else
{
+ if (nmatch > INT_MAX/(sizeof(int) * 3)) return REG_ESPACE;
ovector = (int *)malloc(sizeof(int) * nmatch * 3);
if (ovector == NULL) return REG_ESPACE;
allocated_ovector = TRUE;
@@ -262,13 +276,16 @@ if (rc == 0) rc = nmatch; /* All captured slots were filled in */
if (rc >= 0)
{
size_t i;
- for (i = 0; i < (size_t)rc; i++)
+ if (!nosub)
{
- pmatch[i].rm_so = ovector[i*2];
- pmatch[i].rm_eo = ovector[i*2+1];
+ for (i = 0; i < (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;
}
- if (allocated_ovector) free(ovector);
- for (; i < nmatch; i++) pmatch[i].rm_so = pmatch[i].rm_eo = -1;
return 0;
}