/[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 589 by ph10, Sat Jan 15 11:31:39 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 1358  while (ptr < endptr) Line 1352  while (ptr < endptr)
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 1368  while (ptr < endptr) Line 1363  while (ptr < endptr)
1363            last_offset += offsets[1];            last_offset += offsets[1];
1364            matchptr += offsets[1];            matchptr += offsets[1];
1365            length -= offsets[1];            length -= offsets[1];
1366            if (!match_patterns(matchptr, length, offsets, &mrc)) break;            if (last_offset >= linelength + endlinelength ||
1367                  !match_patterns(matchptr, length, offsets, &mrc)) break;
1368            FWRITE(matchptr, 1, offsets[0], stdout);            FWRITE(matchptr, 1, offsets[0], stdout);
1369            fprintf(stdout, "%c[%sm", 0x1b, colour_string);            fprintf(stdout, "%c[%sm", 0x1b, colour_string);
1370            FWRITE(matchptr + offsets[0], 1, offsets[1] - offsets[0], stdout);            FWRITE(matchptr + offsets[0], 1, offsets[1] - offsets[0], stdout);
1371            fprintf(stdout, "%c[00m", 0x1b);            fprintf(stdout, "%c[00m", 0x1b);
1372            }            }
1373          FWRITE(ptr + last_offset, 1,  
1374            (linelength + endlinelength) - last_offset, stdout);          /* In multiline mode, we may have already printed the complete line
1375            and its line-ending characters (if they matched the pattern), so there
1376            may be no more to print. */
1377    
1378            plength = (linelength + endlinelength) - last_offset;
1379            if (plength > 0)
1380              FWRITE(ptr + last_offset, 1, plength, stdout);
1381          }          }
1382    
1383        /* 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.589

  ViewVC Help
Powered by ViewVC 1.1.5