--- code/trunk/pcreposix.c 2007/02/24 21:38:01 3 +++ code/trunk/pcreposix.c 2007/02/24 21:38:45 25 @@ -12,7 +12,7 @@ Written by: Philip Hazel - Copyright (c) 1997 University of Cambridge + Copyright (c) 1998 University of Cambridge ----------------------------------------------------------------------------- Permission is granted to anyone to use this software for any purpose on any @@ -39,10 +39,10 @@ /* Corresponding tables of PCRE error messages and POSIX error codes. */ -static char *estring[] = { +static const char *estring[] = { ERR1, ERR2, ERR3, ERR4, ERR5, ERR6, ERR7, ERR8, ERR9, ERR10, ERR11, ERR12, ERR13, ERR14, ERR15, ERR16, ERR17, ERR18, ERR19, ERR20, - ERR21, ERR22, ERR23 }; + ERR21, ERR22, ERR23, ERR24, ERR25 }; static int eint[] = { REG_EESCAPE, /* "\\ at end of pattern" */ @@ -67,12 +67,17 @@ REG_ESIZE, /* "regular expression too large" */ REG_ESPACE, /* "failed to get memory" */ REG_EPAREN, /* "unmatched brackets" */ - REG_ASSERT /* "internal error: code overflow" */ + REG_ASSERT, /* "internal error: code overflow" */ + REG_BADPAT, /* "unrecognized character after (?<" */ + REG_BADPAT, /* "lookbehind assertion is not fixed length" */ + REG_BADPAT, /* "malformed number after (?(" */ + REG_BADPAT, /* "conditional group containe more than two branches" */ + REG_BADPAT /* "assertion expected after (?(" */ }; /* Table of texts corresponding to POSIX error codes */ -static char *pstring[] = { +static const char *pstring[] = { "", /* Dummy for value 0 */ "internal error", /* REG_ASSERT */ "invalid repeat counts in {}", /* BADBR */ @@ -106,7 +111,7 @@ static int pcre_posix_error_code(const char *s) { -int i; +size_t i; for (i = 0; i < sizeof(estring)/sizeof(char *); i++) if (strcmp(s, estring[i]) == 0) return eint[i]; return REG_ASSERT; @@ -121,25 +126,21 @@ size_t regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size) { -char *message, *addmessage; -int length, adlength; +const char *message, *addmessage; +size_t length, addlength; -message = (errcode >= sizeof(pstring)/sizeof(char *))? +message = (errcode >= (int)(sizeof(pstring)/sizeof(char *)))? "unknown error code" : pstring[errcode]; +length = strlen(message) + 1; -length = (int)strlen(message) + 1; - -if (preg != NULL && (int)preg->re_erroffset != -1) - { - addmessage = " at offset "; - adlength = (int)strlen(addmessage) + 6; - } -else adlength = 0; +addmessage = " at offset "; +addlength = (preg != NULL && (int)preg->re_erroffset != -1)? + strlen(addmessage) + 6 : 0; if (errbuf_size > 0) { - if (adlength > 0 && errbuf_size >= length + adlength) - sprintf(errbuf, "%s%s%-6d", message, addmessage, preg->re_erroffset); + if (addlength > 0 && errbuf_size >= length + addlength) + sprintf(errbuf, "%s%s%-6d", message, addmessage, (int)preg->re_erroffset); else { strncpy(errbuf, message, errbuf_size - 1); @@ -147,7 +148,7 @@ } } -return length + adlength; +return length + addlength; } @@ -183,14 +184,14 @@ int regcomp(regex_t *preg, const char *pattern, int cflags) { -char *errorptr; +const char *errorptr; int erroffset; int options = 0; if ((cflags & REG_ICASE) != 0) options |= PCRE_CASELESS; if ((cflags & REG_NEWLINE) != 0) options |= PCRE_MULTILINE; -preg->re_pcre = pcre_compile(pattern, options, &errorptr, &erroffset); +preg->re_pcre = pcre_compile(pattern, options, &errorptr, &erroffset, NULL); preg->re_erroffset = erroffset; if (preg->re_pcre == NULL) return pcre_posix_error_code(errorptr); @@ -216,7 +217,7 @@ if ((eflags & REG_NOTBOL) != 0) options |= PCRE_NOTBOL; if ((eflags & REG_NOTEOL) != 0) options |= PCRE_NOTEOL; -preg->re_erroffset = -1; /* Only has meaning after compile */ +preg->re_erroffset = (size_t)(-1); /* Only has meaning after compile */ rc = pcre_exec(preg->re_pcre, NULL, string, (int)strlen(string), options, (int *)pmatch, nmatch * 2); @@ -225,7 +226,7 @@ if (rc > 0) { - int i; + size_t i; for (i = rc; i < nmatch; i++) pmatch[i].rm_so = pmatch[i].rm_eo = -1; return 0; } @@ -233,7 +234,6 @@ else switch(rc) { case PCRE_ERROR_NOMATCH: return REG_NOMATCH; - case PCRE_ERROR_BADREF: return REG_ESUBREG; case PCRE_ERROR_NULL: return REG_INVARG; case PCRE_ERROR_BADOPTION: return REG_INVARG; case PCRE_ERROR_BADMAGIC: return REG_INVARG;