/[pcre]/code/tags/pcre-1.09/pcreposix.c
ViewVC logotype

Diff of /code/tags/pcre-1.09/pcreposix.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3 by nigel, Sat Feb 24 21:38:01 2007 UTC revision 7 by nigel, Sat Feb 24 21:38:09 2007 UTC
# Line 39  restrictions: Line 39  restrictions:
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 };
# Line 72  static int eint[] = { Line 72  static int eint[] = {
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      */
# Line 106  look them up in a table to turn them int Line 106  look them up in a table to turn them int
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;
# Line 121  return REG_ASSERT; Line 121  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      {      {
# Line 147  if (errbuf_size > 0) Line 143  if (errbuf_size > 0)
143      }      }
144    }    }
145    
146  return length + adlength;  return length + addlength;
147  }  }
148    
149    
# Line 183  Returns: 0 on success Line 179  Returns: 0 on success
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    
# Line 225  if (rc == 0) return 0; /* All pmatch Line 221  if (rc == 0) return 0; /* All pmatch
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    }    }

Legend:
Removed from v.3  
changed lines
  Added in v.7

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12