| 39 |
|
|
| 40 |
/* Corresponding tables of PCRE error messages and POSIX error codes. */ |
/* Corresponding tables of PCRE error messages and POSIX error codes. */ |
| 41 |
|
|
| 42 |
static 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 }; |
| 72 |
|
|
| 73 |
/* Table of texts corresponding to POSIX error codes */ |
/* Table of texts corresponding to POSIX error codes */ |
| 74 |
|
|
| 75 |
static char *pstring[] = { |
static const char *pstring[] = { |
| 76 |
"", /* Dummy for value 0 */ |
"", /* Dummy for value 0 */ |
| 77 |
"internal error", /* REG_ASSERT */ |
"internal error", /* REG_ASSERT */ |
| 78 |
"invalid repeat counts in {}", /* BADBR */ |
"invalid repeat counts in {}", /* BADBR */ |
| 106 |
static int |
static int |
| 107 |
pcre_posix_error_code(const char *s) |
pcre_posix_error_code(const char *s) |
| 108 |
{ |
{ |
| 109 |
int i; |
size_t i; |
| 110 |
for (i = 0; i < sizeof(estring)/sizeof(char *); i++) |
for (i = 0; i < sizeof(estring)/sizeof(char *); i++) |
| 111 |
if (strcmp(s, estring[i]) == 0) return eint[i]; |
if (strcmp(s, estring[i]) == 0) return eint[i]; |
| 112 |
return REG_ASSERT; |
return REG_ASSERT; |
| 121 |
size_t |
size_t |
| 122 |
regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size) |
regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size) |
| 123 |
{ |
{ |
| 124 |
char *message, *addmessage; |
const char *message, *addmessage; |
| 125 |
int length, adlength; |
size_t length, addlength; |
| 126 |
|
|
| 127 |
message = (errcode >= sizeof(pstring)/sizeof(char *))? |
message = (errcode >= (int)(sizeof(pstring)/sizeof(char *)))? |
| 128 |
"unknown error code" : pstring[errcode]; |
"unknown error code" : pstring[errcode]; |
| 129 |
|
length = strlen(message) + 1; |
| 130 |
|
|
| 131 |
length = (int)strlen(message) + 1; |
addmessage = " at offset "; |
| 132 |
|
addlength = (preg != NULL && (int)preg->re_erroffset != -1)? |
| 133 |
if (preg != NULL && (int)preg->re_erroffset != -1) |
strlen(addmessage) + 6 : 0; |
|
{ |
|
|
addmessage = " at offset "; |
|
|
adlength = (int)strlen(addmessage) + 6; |
|
|
} |
|
|
else adlength = 0; |
|
| 134 |
|
|
| 135 |
if (errbuf_size > 0) |
if (errbuf_size > 0) |
| 136 |
{ |
{ |
| 137 |
if (adlength > 0 && errbuf_size >= length + adlength) |
if (addlength > 0 && errbuf_size >= length + addlength) |
| 138 |
sprintf(errbuf, "%s%s%-6d", message, addmessage, preg->re_erroffset); |
sprintf(errbuf, "%s%s%-6d", message, addmessage, preg->re_erroffset); |
| 139 |
else |
else |
| 140 |
{ |
{ |
| 143 |
} |
} |
| 144 |
} |
} |
| 145 |
|
|
| 146 |
return length + adlength; |
return length + addlength; |
| 147 |
} |
} |
| 148 |
|
|
| 149 |
|
|
| 179 |
int |
int |
| 180 |
regcomp(regex_t *preg, const char *pattern, int cflags) |
regcomp(regex_t *preg, const char *pattern, int cflags) |
| 181 |
{ |
{ |
| 182 |
char *errorptr; |
const char *errorptr; |
| 183 |
int erroffset; |
int erroffset; |
| 184 |
int options = 0; |
int options = 0; |
| 185 |
|
|
| 221 |
|
|
| 222 |
if (rc > 0) |
if (rc > 0) |
| 223 |
{ |
{ |
| 224 |
int i; |
size_t i; |
| 225 |
for (i = rc; i < nmatch; i++) pmatch[i].rm_so = pmatch[i].rm_eo = -1; |
for (i = rc; i < nmatch; i++) pmatch[i].rm_so = pmatch[i].rm_eo = -1; |
| 226 |
return 0; |
return 0; |
| 227 |
} |
} |