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

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

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

revision 29 by nigel, Sat Feb 24 21:38:53 2007 UTC revision 43 by nigel, Sat Feb 24 21:39:21 2007 UTC
# Line 12  functions. Line 12  functions.
12    
13  Written by: Philip Hazel <ph10@cam.ac.uk>  Written by: Philip Hazel <ph10@cam.ac.uk>
14    
15             Copyright (c) 1997-1999 University of Cambridge             Copyright (c) 1997-2000 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
# Line 46  restrictions: Line 46  restrictions:
46  static const char *estring[] = {  static const char *estring[] = {
47    ERR1,  ERR2,  ERR3,  ERR4,  ERR5,  ERR6,  ERR7,  ERR8,  ERR9,  ERR10,    ERR1,  ERR2,  ERR3,  ERR4,  ERR5,  ERR6,  ERR7,  ERR8,  ERR9,  ERR10,
48    ERR11, ERR12, ERR13, ERR14, ERR15, ERR16, ERR17, ERR18, ERR19, ERR20,    ERR11, ERR12, ERR13, ERR14, ERR15, ERR16, ERR17, ERR18, ERR19, ERR20,
49    ERR21, ERR22, ERR23, ERR24, ERR25 };    ERR21, ERR22, ERR23, ERR24, ERR25, ERR26, ERR27, ERR29, ERR29, ERR30,
50      ERR31 };
51    
52  static int eint[] = {  static int eint[] = {
53    REG_EESCAPE, /* "\\ at end of pattern" */    REG_EESCAPE, /* "\\ at end of pattern" */
# Line 76  static int eint[] = { Line 77  static int eint[] = {
77    REG_BADPAT,  /* "lookbehind assertion is not fixed length" */    REG_BADPAT,  /* "lookbehind assertion is not fixed length" */
78    REG_BADPAT,  /* "malformed number after (?(" */    REG_BADPAT,  /* "malformed number after (?(" */
79    REG_BADPAT,  /* "conditional group containe more than two branches" */    REG_BADPAT,  /* "conditional group containe more than two branches" */
80    REG_BADPAT   /* "assertion expected after (?(" */    REG_BADPAT,  /* "assertion expected after (?(" */
81      REG_BADPAT,  /* "(?p must be followed by )" */
82      REG_ECTYPE,  /* "unknown POSIX class name" */
83      REG_BADPAT   /* "POSIX collating elements are not supported" */
84  };  };
85    
86  /* Table of texts corresponding to POSIX error codes */  /* Table of texts corresponding to POSIX error codes */
# Line 211  return 0; Line 215  return 0;
215  *              Match a regular expression        *  *              Match a regular expression        *
216  *************************************************/  *************************************************/
217    
218    /* Unfortunately, PCRE requires 3 ints of working space for each captured
219    substring, so we have to get and release working store instead of just using
220    the POSIX structures as was done in earlier releases when PCRE needed only 2
221    ints. */
222    
223  int  int
224  regexec(regex_t *preg, const char *string, size_t nmatch,  regexec(regex_t *preg, const char *string, size_t nmatch,
225    regmatch_t pmatch[], int eflags)    regmatch_t pmatch[], int eflags)
226  {  {
227  int rc;  int rc;
228  int options = 0;  int options = 0;
229    int *ovector = NULL;
230    
231  if ((eflags & REG_NOTBOL) != 0) options |= PCRE_NOTBOL;  if ((eflags & REG_NOTBOL) != 0) options |= PCRE_NOTBOL;
232  if ((eflags & REG_NOTEOL) != 0) options |= PCRE_NOTEOL;  if ((eflags & REG_NOTEOL) != 0) options |= PCRE_NOTEOL;
233    
234  preg->re_erroffset = (size_t)(-1);   /* Only has meaning after compile */  preg->re_erroffset = (size_t)(-1);   /* Only has meaning after compile */
235    
236  rc = pcre_exec(preg->re_pcre, NULL, string, (int)strlen(string), options,  if (nmatch > 0)
237    (int *)pmatch, nmatch * 2);    {
238      ovector = (int *)malloc(sizeof(int) * nmatch * 3);
239      if (ovector == NULL) return REG_ESPACE;
240      }
241    
242    rc = pcre_exec(preg->re_pcre, NULL, string, (int)strlen(string), 0, options,
243      ovector, nmatch * 3);
244    
245  if (rc == 0) return 0;    /* All pmatch were filled in */  if (rc == 0) rc = nmatch;    /* All captured slots were filled in */
246    
247  if (rc > 0)  if (rc >= 0)
248    {    {
249    size_t i;    size_t i;
250    for (i = rc; i < nmatch; i++) pmatch[i].rm_so = pmatch[i].rm_eo = -1;    for (i = 0; i < rc; i++)
251        {
252        pmatch[i].rm_so = ovector[i*2];
253        pmatch[i].rm_eo = ovector[i*2+1];
254        }
255      if (ovector != NULL) free(ovector);
256      for (; i < nmatch; i++) pmatch[i].rm_so = pmatch[i].rm_eo = -1;
257    return 0;    return 0;
258    }    }
259    
260  else switch(rc)  else
261    {    {
262    case PCRE_ERROR_NOMATCH: return REG_NOMATCH;    if (ovector != NULL) free(ovector);
263    case PCRE_ERROR_NULL: return REG_INVARG;    switch(rc)
264    case PCRE_ERROR_BADOPTION: return REG_INVARG;      {
265    case PCRE_ERROR_BADMAGIC: return REG_INVARG;      case PCRE_ERROR_NOMATCH: return REG_NOMATCH;
266    case PCRE_ERROR_UNKNOWN_NODE: return REG_ASSERT;      case PCRE_ERROR_NULL: return REG_INVARG;
267    case PCRE_ERROR_NOMEMORY: return REG_ESPACE;      case PCRE_ERROR_BADOPTION: return REG_INVARG;
268    default: return REG_ASSERT;      case PCRE_ERROR_BADMAGIC: return REG_INVARG;
269        case PCRE_ERROR_UNKNOWN_NODE: return REG_ASSERT;
270        case PCRE_ERROR_NOMEMORY: return REG_ESPACE;
271        default: return REG_ASSERT;
272        }
273    }    }
274  }  }
275    

Legend:
Removed from v.29  
changed lines
  Added in v.43

  ViewVC Help
Powered by ViewVC 1.1.5