| 6 |
and semantics are as close as possible to those of the Perl 5 language. |
and semantics are as close as possible to those of the Perl 5 language. |
| 7 |
|
|
| 8 |
Written by Philip Hazel |
Written by Philip Hazel |
| 9 |
Copyright (c) 1997-2007 University of Cambridge |
Copyright (c) 1997-2008 University of Cambridge |
| 10 |
|
|
| 11 |
----------------------------------------------------------------------------- |
----------------------------------------------------------------------------- |
| 12 |
Redistribution and use in source and binary forms, with or without |
Redistribution and use in source and binary forms, with or without |
| 42 |
functions. */ |
functions. */ |
| 43 |
|
|
| 44 |
|
|
| 45 |
|
#ifdef HAVE_CONFIG_H |
| 46 |
|
#include "config.h" |
| 47 |
|
#endif |
| 48 |
|
|
| 49 |
|
|
| 50 |
|
/* Ensure that the PCREPOSIX_EXP_xxx macros are set appropriately for |
| 51 |
|
compiling these functions. This must come before including pcreposix.h, where |
| 52 |
|
they are set for an application (using these functions) if they have not |
| 53 |
|
previously been set. */ |
| 54 |
|
|
| 55 |
|
#if defined(_WIN32) && !defined(PCRE_STATIC) |
| 56 |
|
# define PCREPOSIX_EXP_DECL extern __declspec(dllexport) |
| 57 |
|
# define PCREPOSIX_EXP_DEFN __declspec(dllexport) |
| 58 |
|
#endif |
| 59 |
|
|
| 60 |
|
#include "pcre.h" |
| 61 |
#include "pcre_internal.h" |
#include "pcre_internal.h" |
| 62 |
#include "pcreposix.h" |
#include "pcreposix.h" |
|
#include "stdlib.h" |
|
|
|
|
| 63 |
|
|
| 64 |
|
|
| 65 |
/* Table to translate PCRE compile time error codes into POSIX error codes. */ |
/* Table to translate PCRE compile time error codes into POSIX error codes. */ |
| 123 |
REG_BADPAT, /* repeating a DEFINE group is not allowed */ |
REG_BADPAT, /* repeating a DEFINE group is not allowed */ |
| 124 |
REG_INVARG, /* inconsistent NEWLINE options */ |
REG_INVARG, /* inconsistent NEWLINE options */ |
| 125 |
REG_BADPAT, /* \g is not followed followed by an (optionally braced) non-zero number */ |
REG_BADPAT, /* \g is not followed followed by an (optionally braced) non-zero number */ |
| 126 |
REG_BADPAT /* (?+ or (?- must be followed by a non-zero number */ |
REG_BADPAT, /* (?+ or (?- must be followed by a non-zero number */ |
| 127 |
|
REG_BADPAT, /* number is too big */ |
| 128 |
|
REG_BADPAT, /* subpattern name expected */ |
| 129 |
|
REG_BADPAT, /* digit expected after (?+ */ |
| 130 |
|
REG_BADPAT /* ] is an invalid data character in JavaScript compatibility mode */ |
| 131 |
}; |
}; |
| 132 |
|
|
| 133 |
/* Table of texts corresponding to POSIX error codes */ |
/* Table of texts corresponding to POSIX error codes */ |
| 264 |
regexec(const regex_t *preg, const char *string, size_t nmatch, |
regexec(const regex_t *preg, const char *string, size_t nmatch, |
| 265 |
regmatch_t pmatch[], int eflags) |
regmatch_t pmatch[], int eflags) |
| 266 |
{ |
{ |
| 267 |
int rc; |
int rc, so, eo; |
| 268 |
int options = 0; |
int options = 0; |
| 269 |
int *ovector = NULL; |
int *ovector = NULL; |
| 270 |
int small_ovector[POSIX_MALLOC_THRESHOLD * 3]; |
int small_ovector[POSIX_MALLOC_THRESHOLD * 3]; |
| 297 |
} |
} |
| 298 |
} |
} |
| 299 |
|
|
| 300 |
rc = pcre_exec((const pcre *)preg->re_pcre, NULL, string, (int)strlen(string), |
/* REG_STARTEND is a BSD extension, to allow for non-NUL-terminated strings. |
| 301 |
|
The man page from OS X says "REG_STARTEND affects only the location of the |
| 302 |
|
string, not how it is matched". That is why the "so" value is used to bump the |
| 303 |
|
start location rather than being passed as a PCRE "starting offset". */ |
| 304 |
|
|
| 305 |
|
if ((eflags & REG_STARTEND) != 0) |
| 306 |
|
{ |
| 307 |
|
so = pmatch[0].rm_so; |
| 308 |
|
eo = pmatch[0].rm_eo; |
| 309 |
|
} |
| 310 |
|
else |
| 311 |
|
{ |
| 312 |
|
so = 0; |
| 313 |
|
eo = strlen(string); |
| 314 |
|
} |
| 315 |
|
|
| 316 |
|
rc = pcre_exec((const pcre *)preg->re_pcre, NULL, string + so, (eo - so), |
| 317 |
0, options, ovector, nmatch * 3); |
0, options, ovector, nmatch * 3); |
| 318 |
|
|
| 319 |
if (rc == 0) rc = nmatch; /* All captured slots were filled in */ |
if (rc == 0) rc = nmatch; /* All captured slots were filled in */ |