/[pcre]/code/trunk/pcregrep.c
ViewVC logotype

Diff of /code/trunk/pcregrep.c

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

revision 1221 by ph10, Sun Nov 11 20:27:03 2012 UTC revision 1324 by ph10, Fri May 10 11:40:06 2013 UTC
# Line 1378  to find all possible matches. Line 1378  to find all possible matches.
1378  Arguments:  Arguments:
1379    matchptr     the start of the subject    matchptr     the start of the subject
1380    length       the length of the subject to match    length       the length of the subject to match
1381      options      options for pcre_exec
1382    startoffset  where to start matching    startoffset  where to start matching
1383    offsets      the offets vector to fill in    offsets      the offets vector to fill in
1384    mrc          address of where to put the result of pcre_exec()    mrc          address of where to put the result of pcre_exec()
# Line 1388  Returns:      TRUE if there was a match Line 1389  Returns:      TRUE if there was a match
1389  */  */
1390    
1391  static BOOL  static BOOL
1392  match_patterns(char *matchptr, size_t length, int startoffset, int *offsets,  match_patterns(char *matchptr, size_t length, unsigned int options,
1393    int *mrc)    int startoffset, int *offsets, int *mrc)
1394  {  {
1395  int i;  int i;
1396  size_t slen = length;  size_t slen = length;
# Line 1404  if (slen > 200) Line 1405  if (slen > 200)
1405  for (i = 1; p != NULL; p = p->next, i++)  for (i = 1; p != NULL; p = p->next, i++)
1406    {    {
1407    *mrc = pcre_exec(p->compiled, p->hint, matchptr, (int)length,    *mrc = pcre_exec(p->compiled, p->hint, matchptr, (int)length,
1408      startoffset, PCRE_NOTEMPTY, offsets, OFFSET_SIZE);      startoffset, options, offsets, OFFSET_SIZE);
1409    if (*mrc >= 0) return TRUE;    if (*mrc >= 0) return TRUE;
1410    if (*mrc == PCRE_ERROR_NOMATCH) continue;    if (*mrc == PCRE_ERROR_NOMATCH) continue;
1411    fprintf(stderr, "pcregrep: pcre_exec() gave error %d while matching ", *mrc);    fprintf(stderr, "pcregrep: pcre_exec() gave error %d while matching ", *mrc);
# Line 1539  while (ptr < endptr) Line 1540  while (ptr < endptr)
1540    int endlinelength;    int endlinelength;
1541    int mrc = 0;    int mrc = 0;
1542    int startoffset = 0;    int startoffset = 0;
1543      unsigned int options = 0;
1544    BOOL match;    BOOL match;
1545    char *matchptr = ptr;    char *matchptr = ptr;
1546    char *t = ptr;    char *t = ptr;
# Line 1628  while (ptr < endptr) Line 1630  while (ptr < endptr)
1630    
1631    /* Run through all the patterns until one matches or there is an error other    /* Run through all the patterns until one matches or there is an error other
1632    than NOMATCH. This code is in a subroutine so that it can be re-used for    than NOMATCH. This code is in a subroutine so that it can be re-used for
1633    finding subsequent matches when colouring matched lines. */    finding subsequent matches when colouring matched lines. After finding one
1634      match, set PCRE_NOTEMPTY to disable any further matches of null strings in
1635      this line. */
1636    
1637    match = match_patterns(matchptr, length, startoffset, offsets, &mrc);    match = match_patterns(matchptr, length, options, startoffset, offsets, &mrc);
1638      options = PCRE_NOTEMPTY;
1639    
1640    /* If it's a match or a not-match (as required), do what's wanted. */    /* If it's a match or a not-match (as required), do what's wanted. */
1641    
# Line 1871  while (ptr < endptr) Line 1876  while (ptr < endptr)
1876            {            {
1877            startoffset = offsets[1];            startoffset = offsets[1];
1878            if (startoffset >= (int)linelength + endlinelength ||            if (startoffset >= (int)linelength + endlinelength ||
1879                !match_patterns(matchptr, length, startoffset, offsets, &mrc))                !match_patterns(matchptr, length, options, startoffset, offsets,
1880                    &mrc))
1881              break;              break;
1882            FWRITE(matchptr + startoffset, 1, offsets[0] - startoffset, stdout);            FWRITE(matchptr + startoffset, 1, offsets[0] - startoffset, stdout);
1883            fprintf(stdout, "%c[%sm", 0x1b, colour_string);            fprintf(stdout, "%c[%sm", 0x1b, colour_string);

Legend:
Removed from v.1221  
changed lines
  Added in v.1324

  ViewVC Help
Powered by ViewVC 1.1.5