/[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 1543 by ph10, Tue Apr 7 15:52:11 2015 UTC revision 1548 by ph10, Tue Apr 14 17:02:30 2015 UTC
# Line 1582  while (ptr < endptr) Line 1582  while (ptr < endptr)
1582    int endlinelength;    int endlinelength;
1583    int mrc = 0;    int mrc = 0;
1584    int startoffset = 0;    int startoffset = 0;
1585    int prevoffsets[2];    int prevoffsets[2];
1586    unsigned int options = 0;    unsigned int options = 0;
1587    BOOL match;    BOOL match;
1588    char *matchptr = ptr;    char *matchptr = ptr;
1589    char *t = ptr;    char *t = ptr;
1590    size_t length, linelength;    size_t length, linelength;
1591    
1592    prevoffsets[0] = prevoffsets[1] = -1;    prevoffsets[0] = prevoffsets[1] = -1;
1593    
1594    /* At this point, ptr is at the start of a line. We need to find the length    /* At this point, ptr is at the start of a line. We need to find the length
1595    of the subject string to pass to pcre_exec(). In multiline mode, it is the    of the subject string to pass to pcre_exec(). In multiline mode, it is the
# Line 1733  while (ptr < endptr) Line 1733  while (ptr < endptr)
1733        if (!invert)        if (!invert)
1734          {          {
1735          int oldstartoffset = startoffset;          int oldstartoffset = startoffset;
1736    
1737          /* It is possible, when a lookbehind assertion contains \K, for the          /* It is possible, when a lookbehind assertion contains \K, for the
1738          same string to be found again. The code below advances startoffset, but          same string to be found again. The code below advances startoffset, but
1739          until it is past the "bumpalong" offset that gave the match, the same          until it is past the "bumpalong" offset that gave the match, the same
1740          substring will be returned. The PCRE1 library does not return the          substring will be returned. The PCRE1 library does not return the
1741          bumpalong offset, so all we can do is ignore repeated strings. (PCRE2          bumpalong offset, so all we can do is ignore repeated strings. (PCRE2
1742          does this better.) */          does this better.) */
1743    
1744          if (prevoffsets[0] != offsets[0] || prevoffsets[1] != offsets[1])          if (prevoffsets[0] != offsets[0] || prevoffsets[1] != offsets[1])
1745            {            {
1746            prevoffsets[0] = offsets[0];            prevoffsets[0] = offsets[0];
1747            prevoffsets[1] = offsets[1];            prevoffsets[1] = offsets[1];
1748    
1749            if (printname != NULL) fprintf(stdout, "%s:", printname);            if (printname != NULL) fprintf(stdout, "%s:", printname);
1750            if (number) fprintf(stdout, "%d:", linenumber);            if (number) fprintf(stdout, "%d:", linenumber);
1751    
1752            /* Handle --line-offsets */            /* Handle --line-offsets */
1753    
1754            if (line_offsets)            if (line_offsets)
1755              fprintf(stdout, "%d,%d\n", (int)(matchptr + offsets[0] - ptr),              fprintf(stdout, "%d,%d\n", (int)(matchptr + offsets[0] - ptr),
1756                offsets[1] - offsets[0]);                offsets[1] - offsets[0]);
1757    
1758            /* Handle --file-offsets */            /* Handle --file-offsets */
1759    
1760            else if (file_offsets)            else if (file_offsets)
1761              fprintf(stdout, "%d,%d\n",              fprintf(stdout, "%d,%d\n",
1762                (int)(filepos + matchptr + offsets[0] - ptr),                (int)(filepos + matchptr + offsets[0] - ptr),
1763                offsets[1] - offsets[0]);                offsets[1] - offsets[0]);
1764    
1765            /* Handle --only-matching, which may occur many times */            /* Handle --only-matching, which may occur many times */
1766    
1767            else            else
1768              {              {
1769              BOOL printed = FALSE;              BOOL printed = FALSE;
1770              omstr *om;              omstr *om;
1771    
1772              for (om = only_matching; om != NULL; om = om->next)              for (om = only_matching; om != NULL; om = om->next)
1773                {                {
1774                int n = om->groupnum;                int n = om->groupnum;
# Line 1785  while (ptr < endptr) Line 1785  while (ptr < endptr)
1785                    }                    }
1786                  }                  }
1787                }                }
1788    
1789              if (printed || printname != NULL || number) fprintf(stdout, "\n");              if (printed || printname != NULL || number) fprintf(stdout, "\n");
1790              }              }
1791            }            }
1792    
1793          /* Prepare to repeat to find the next match. If the patterned contained          /* Prepare to repeat to find the next match. If the patterned contained
1794          a lookbehind tht included \K, it is possible that the end of the match          a lookbehind tht included \K, it is possible that the end of the match
1795          might be at or before the actual strting offset we have just used. We          might be at or before the actual strting offset we have just used. We
1796          need to start one character further on. Unfortunately, for unanchored          need to start one character further on. Unfortunately, for unanchored
1797          patterns, the actual start offset can be greater that the one that was          patterns, the actual start offset can be greater that the one that was
1798          set as a result of "bumpalong". PCRE1 does not return the actual start          set as a result of "bumpalong". PCRE1 does not return the actual start
1799          offset, so we have to check against the original start offset. This may          offset, so we have to check against the original start offset. This may
1800          lead to duplicates - we we need the fudge above to avoid printing them.          lead to duplicates - we we need the fudge above to avoid printing them.
1801          (PCRE2 does this better.) */          (PCRE2 does this better.) */
1802    
1803          match = FALSE;          match = FALSE;
# Line 1806  while (ptr < endptr) Line 1806  while (ptr < endptr)
1806          startoffset = offsets[1];    /* Restart after the match */          startoffset = offsets[1];    /* Restart after the match */
1807          if (startoffset <= oldstartoffset)          if (startoffset <= oldstartoffset)
1808            {            {
1809            if ((size_t)startoffset >= length)            if ((size_t)startoffset >= length)
1810              goto END_ONE_MATCH;              /* We were at the end */              goto END_ONE_MATCH;              /* We were at the end */
1811            startoffset = oldstartoffset + 1;            startoffset = oldstartoffset + 1;
1812            if (utf8)            if (utf8)
1813              while ((matchptr[startoffset] & 0xc0) == 0x80) startoffset++;              while ((matchptr[startoffset] & 0xc0) == 0x80) startoffset++;
1814            }            }
1815          goto ONLY_MATCHING_RESTART;          goto ONLY_MATCHING_RESTART;
1816          }          }
1817        }        }

Legend:
Removed from v.1543  
changed lines
  Added in v.1548

  ViewVC Help
Powered by ViewVC 1.1.5