/[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 586 by ph10, Wed Jan 12 17:36:47 2011 UTC revision 587 by ph10, Fri Jan 14 19:01:25 2011 UTC
# Line 634  Arguments: Line 634  Arguments:
634    endptr    end of available data    endptr    end of available data
635    lenptr    where to put the length of the eol sequence    lenptr    where to put the length of the eol sequence
636    
637  Returns:    pointer to the last byte of the line  Returns:    pointer to the last byte of the line, including the newline byte(s)
638  */  */
639    
640  static char *  static char *
# Line 1316  while (ptr < endptr) Line 1316  while (ptr < endptr)
1316        (invert not set). Because the PCRE_FIRSTLINE option is set, the start of        (invert not set). Because the PCRE_FIRSTLINE option is set, the start of
1317        the match will always be before the first newline sequence. */        the match will always be before the first newline sequence. */
1318    
1319        if (multiline)        if (multiline & !invert)
1320          {          {
1321          int ellength;          char *endmatch = ptr + offsets[1];
1322          char *endmatch = ptr;          t = ptr;
1323          if (!invert)          while (t < endmatch)
1324            {            {
1325            endmatch += offsets[1];            t = end_of_line(t, endptr, &endlinelength);
1326            t = ptr;            if (t < endmatch) linenumber++; else break;
           while (t < endmatch)  
             {  
             t = end_of_line(t, endptr, &ellength);  
             if (t <= endmatch) linenumber++; else break;  
             }  
1327            }            }
1328          endmatch = end_of_line(endmatch, endptr, &ellength);          linelength = t - ptr - endlinelength;
         linelength = endmatch - ptr - ellength;  
1329          }          }
1330    
1331        /*** NOTE: Use only fwrite() to output the data line, so that binary        /*** NOTE: Use only fwrite() to output the data line, so that binary
# Line 1355  while (ptr < endptr) Line 1349  while (ptr < endptr)
1349    
1350        /* We have to split the line(s) up if colouring, and search for further        /* We have to split the line(s) up if colouring, and search for further
1351        matches, but not of course if the line is a non-match. */        matches, but not of course if the line is a non-match. */
1352    
1353        if (do_colour && !invert)        if (do_colour && !invert)
1354          {          {
1355            int plength;
1356          int last_offset = 0;          int last_offset = 0;
1357          FWRITE(ptr, 1, offsets[0], stdout);          FWRITE(ptr, 1, offsets[0], stdout);
1358          fprintf(stdout, "%c[%sm", 0x1b, colour_string);          fprintf(stdout, "%c[%sm", 0x1b, colour_string);
# Line 1374  while (ptr < endptr) Line 1369  while (ptr < endptr)
1369            FWRITE(matchptr + offsets[0], 1, offsets[1] - offsets[0], stdout);            FWRITE(matchptr + offsets[0], 1, offsets[1] - offsets[0], stdout);
1370            fprintf(stdout, "%c[00m", 0x1b);            fprintf(stdout, "%c[00m", 0x1b);
1371            }            }
1372          FWRITE(ptr + last_offset, 1,  
1373            (linelength + endlinelength) - last_offset, stdout);          /* In multiline mode, we may have already printed the complete line
1374            and its line-ending characters (if they matched the pattern), so there
1375            may be no more to print. */
1376    
1377            plength = (linelength + endlinelength) - last_offset;
1378            if (plength > 0)
1379              FWRITE(ptr + last_offset, 1, plength, stdout);
1380          }          }
1381    
1382        /* Not colouring; no need to search for further matches */        /* Not colouring; no need to search for further matches */

Legend:
Removed from v.586  
changed lines
  Added in v.587

  ViewVC Help
Powered by ViewVC 1.1.5