12 |
|
|
13 |
Written by: Philip Hazel <ph10@cam.ac.uk> |
Written by: Philip Hazel <ph10@cam.ac.uk> |
14 |
|
|
15 |
Copyright (c) 1997 University of Cambridge |
Copyright (c) 1998 University of Cambridge |
16 |
|
|
17 |
----------------------------------------------------------------------------- |
----------------------------------------------------------------------------- |
18 |
Permission is granted to anyone to use this software for any purpose on any |
Permission is granted to anyone to use this software for any purpose on any |
42 |
static const char *estring[] = { |
static const char *estring[] = { |
43 |
ERR1, ERR2, ERR3, ERR4, ERR5, ERR6, ERR7, ERR8, ERR9, ERR10, |
ERR1, ERR2, ERR3, ERR4, ERR5, ERR6, ERR7, ERR8, ERR9, ERR10, |
44 |
ERR11, ERR12, ERR13, ERR14, ERR15, ERR16, ERR17, ERR18, ERR19, ERR20, |
ERR11, ERR12, ERR13, ERR14, ERR15, ERR16, ERR17, ERR18, ERR19, ERR20, |
45 |
ERR21, ERR22, ERR23 }; |
ERR21, ERR22, ERR23, ERR24, ERR25 }; |
46 |
|
|
47 |
static int eint[] = { |
static int eint[] = { |
48 |
REG_EESCAPE, /* "\\ at end of pattern" */ |
REG_EESCAPE, /* "\\ at end of pattern" */ |
67 |
REG_ESIZE, /* "regular expression too large" */ |
REG_ESIZE, /* "regular expression too large" */ |
68 |
REG_ESPACE, /* "failed to get memory" */ |
REG_ESPACE, /* "failed to get memory" */ |
69 |
REG_EPAREN, /* "unmatched brackets" */ |
REG_EPAREN, /* "unmatched brackets" */ |
70 |
REG_ASSERT /* "internal error: code overflow" */ |
REG_ASSERT, /* "internal error: code overflow" */ |
71 |
|
REG_BADPAT, /* "unrecognized character after (?<" */ |
72 |
|
REG_BADPAT, /* "lookbehind assertion is not fixed length" */ |
73 |
|
REG_BADPAT, /* "malformed number after (?(" */ |
74 |
|
REG_BADPAT, /* "conditional group containe more than two branches" */ |
75 |
|
REG_BADPAT /* "assertion expected after (?(" */ |
76 |
}; |
}; |
77 |
|
|
78 |
/* Table of texts corresponding to POSIX error codes */ |
/* Table of texts corresponding to POSIX error codes */ |
140 |
if (errbuf_size > 0) |
if (errbuf_size > 0) |
141 |
{ |
{ |
142 |
if (addlength > 0 && errbuf_size >= length + addlength) |
if (addlength > 0 && errbuf_size >= length + addlength) |
143 |
sprintf(errbuf, "%s%s%-6d", message, addmessage, preg->re_erroffset); |
sprintf(errbuf, "%s%s%-6d", message, addmessage, (int)preg->re_erroffset); |
144 |
else |
else |
145 |
{ |
{ |
146 |
strncpy(errbuf, message, errbuf_size - 1); |
strncpy(errbuf, message, errbuf_size - 1); |
191 |
if ((cflags & REG_ICASE) != 0) options |= PCRE_CASELESS; |
if ((cflags & REG_ICASE) != 0) options |= PCRE_CASELESS; |
192 |
if ((cflags & REG_NEWLINE) != 0) options |= PCRE_MULTILINE; |
if ((cflags & REG_NEWLINE) != 0) options |= PCRE_MULTILINE; |
193 |
|
|
194 |
preg->re_pcre = pcre_compile(pattern, options, &errorptr, &erroffset); |
preg->re_pcre = pcre_compile(pattern, options, &errorptr, &erroffset, NULL); |
195 |
preg->re_erroffset = erroffset; |
preg->re_erroffset = erroffset; |
196 |
|
|
197 |
if (preg->re_pcre == NULL) return pcre_posix_error_code(errorptr); |
if (preg->re_pcre == NULL) return pcre_posix_error_code(errorptr); |
217 |
if ((eflags & REG_NOTBOL) != 0) options |= PCRE_NOTBOL; |
if ((eflags & REG_NOTBOL) != 0) options |= PCRE_NOTBOL; |
218 |
if ((eflags & REG_NOTEOL) != 0) options |= PCRE_NOTEOL; |
if ((eflags & REG_NOTEOL) != 0) options |= PCRE_NOTEOL; |
219 |
|
|
220 |
preg->re_erroffset = -1; /* Only has meaning after compile */ |
preg->re_erroffset = (size_t)(-1); /* Only has meaning after compile */ |
221 |
|
|
222 |
rc = pcre_exec(preg->re_pcre, NULL, string, (int)strlen(string), options, |
rc = pcre_exec(preg->re_pcre, NULL, string, (int)strlen(string), options, |
223 |
(int *)pmatch, nmatch * 2); |
(int *)pmatch, nmatch * 2); |
234 |
else switch(rc) |
else switch(rc) |
235 |
{ |
{ |
236 |
case PCRE_ERROR_NOMATCH: return REG_NOMATCH; |
case PCRE_ERROR_NOMATCH: return REG_NOMATCH; |
|
case PCRE_ERROR_BADREF: return REG_ESUBREG; |
|
237 |
case PCRE_ERROR_NULL: return REG_INVARG; |
case PCRE_ERROR_NULL: return REG_INVARG; |
238 |
case PCRE_ERROR_BADOPTION: return REG_INVARG; |
case PCRE_ERROR_BADOPTION: return REG_INVARG; |
239 |
case PCRE_ERROR_BADMAGIC: return REG_INVARG; |
case PCRE_ERROR_BADMAGIC: return REG_INVARG; |