/[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 1039 by ph10, Thu Sep 13 16:39:03 2012 UTC revision 1335 by ph10, Tue May 28 09:13:59 2013 UTC
# Line 1266  switch(endlinetype) Line 1266  switch(endlinetype)
1266    
1267    while (p > startptr)    while (p > startptr)
1268      {      {
1269      register int c;      register unsigned int c;
1270      char *pp = p - 1;      char *pp = p - 1;
1271    
1272      if (utf8)      if (utf8)
# 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 1487  of what we have. In the case of libz, a Line 1488  of what we have. In the case of libz, a
1488  plain file. However, if a .bz2 file isn't actually bzipped, the first read will  plain file. However, if a .bz2 file isn't actually bzipped, the first read will
1489  fail. */  fail. */
1490    
1491    (void)frtype;
1492    
1493  #ifdef SUPPORT_LIBZ  #ifdef SUPPORT_LIBZ
1494  if (frtype == FR_LIBZ)  if (frtype == FR_LIBZ)
1495    {    {
# Line 1537  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 1573  while (ptr < endptr) Line 1577  while (ptr < endptr)
1577  #ifdef JFRIEDL_DEBUG  #ifdef JFRIEDL_DEBUG
1578    if (jfriedl_XT || jfriedl_XR)    if (jfriedl_XT || jfriedl_XR)
1579    {    {
1580        #include <sys/time.h>  #     include <sys/time.h>
1581        #include <time.h>  #     include <time.h>
1582        struct timeval start_time, end_time;        struct timeval start_time, end_time;
1583        struct timezone dummy;        struct timezone dummy;
1584        int i;        int i;
# Line 1626  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 1702  while (ptr < endptr) Line 1709  while (ptr < endptr)
1709            {            {
1710            BOOL printed = FALSE;            BOOL printed = FALSE;
1711            omstr *om;            omstr *om;
1712    
1713            for (om = only_matching; om != NULL; om = om->next)            for (om = only_matching; om != NULL; om = om->next)
1714              {              {
1715              int n = om->groupnum;              int n = om->groupnum;
# Line 1711  while (ptr < endptr) Line 1718  while (ptr < endptr)
1718                int plen = offsets[2*n + 1] - offsets[2*n];                int plen = offsets[2*n + 1] - offsets[2*n];
1719                if (plen > 0)                if (plen > 0)
1720                  {                  {
1721                  if (printed) fprintf(stdout, "%s", om_separator);                  if (printed) fprintf(stdout, "%s", om_separator);
1722                  if (do_colour) fprintf(stdout, "%c[%sm", 0x1b, colour_string);                  if (do_colour) fprintf(stdout, "%c[%sm", 0x1b, colour_string);
1723                  FWRITE(matchptr + offsets[n*2], 1, plen, stdout);                  FWRITE(matchptr + offsets[n*2], 1, plen, stdout);
1724                  if (do_colour) fprintf(stdout, "%c[00m", 0x1b);                  if (do_colour) fprintf(stdout, "%c[00m", 0x1b);
# Line 1719  while (ptr < endptr) Line 1726  while (ptr < endptr)
1726                  }                  }
1727                }                }
1728              }              }
1729    
1730            if (printed || printname != NULL || number) fprintf(stdout, "\n");            if (printed || printname != NULL || number) fprintf(stdout, "\n");
1731            }            }
1732    
# Line 1869  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);
# Line 2259  switch(letter) Line 2267  switch(letter)
2267    case 'L': filenames = FN_NOMATCH_ONLY; break;    case 'L': filenames = FN_NOMATCH_ONLY; break;
2268    case 'M': multiline = TRUE; options |= PCRE_MULTILINE|PCRE_FIRSTLINE; break;    case 'M': multiline = TRUE; options |= PCRE_MULTILINE|PCRE_FIRSTLINE; break;
2269    case 'n': number = TRUE; break;    case 'n': number = TRUE; break;
2270    
2271    case 'o':    case 'o':
2272    only_matching_last = add_number(0, only_matching_last);    only_matching_last = add_number(0, only_matching_last);
2273    if (only_matching == NULL) only_matching = only_matching_last;    if (only_matching == NULL) only_matching = only_matching_last;
2274    break;    break;
2275    
2276    case 'q': quiet = TRUE; break;    case 'q': quiet = TRUE; break;
2277    case 'r': dee_action = dee_RECURSE; break;    case 'r': dee_action = dee_RECURSE; break;
2278    case 's': silent = TRUE; break;    case 's': silent = TRUE; break;
# Line 2650  for (i = 1; i < argc; i++) Line 2658  for (i = 1; i < argc; i++)
2658      {      {
2659      char *s = argv[i] + 1;      char *s = argv[i] + 1;
2660      longop = FALSE;      longop = FALSE;
2661    
2662      while (*s != 0)      while (*s != 0)
2663        {        {
2664        for (op = optionlist; op->one_char != 0; op++)        for (op = optionlist; op->one_char != 0; op++)
# Line 2663  for (i = 1; i < argc; i++) Line 2671  for (i = 1; i < argc; i++)
2671            *s, argv[i]);            *s, argv[i]);
2672          pcregrep_exit(usage(2));          pcregrep_exit(usage(2));
2673          }          }
2674    
2675        option_data = s+1;        option_data = s+1;
2676    
2677        /* Break out if this is the last character in the string; it's handled        /* Break out if this is the last character in the string; it's handled
2678        below like a single multi-char option. */        below like a single multi-char option. */
2679    
2680        if (*option_data == 0) break;        if (*option_data == 0) break;
2681    
2682        /* Check for a single-character option that has data: OP_OP_NUMBER(S)        /* Check for a single-character option that has data: OP_OP_NUMBER(S)
2683        are used for ones that either have a numerical number or defaults, i.e.        are used for ones that either have a numerical number or defaults, i.e.
# Line 2687  for (i = 1; i < argc; i++) Line 2695  for (i = 1; i < argc; i++)
2695    
2696        /* Handle a single-character option with no data, then loop for the        /* Handle a single-character option with no data, then loop for the
2697        next character in the string. */        next character in the string. */
2698    
2699        pcre_options = handle_option(*s++, pcre_options);        pcre_options = handle_option(*s++, pcre_options);
2700        }        }
2701      }      }
2702    
2703    /* At this point we should have op pointing to a matched option. If the type    /* At this point we should have op pointing to a matched option. If the type
2704    is NO_DATA, it means that there is no data, and the option might set    is NO_DATA, it means that there is no data, and the option might set
2705    something in the PCRE options. */    something in the PCRE options. */
# Line 2706  for (i = 1; i < argc; i++) Line 2714  for (i = 1; i < argc; i++)
2714    either has a value or defaults to something. It cannot have data in a    either has a value or defaults to something. It cannot have data in a
2715    separate item. At the moment, the only such options are "colo(u)r",    separate item. At the moment, the only such options are "colo(u)r",
2716    "only-matching", and Jeffrey Friedl's special -S debugging option. */    "only-matching", and Jeffrey Friedl's special -S debugging option. */
2717    
2718    if (*option_data == 0 &&    if (*option_data == 0 &&
2719        (op->type == OP_OP_STRING || op->type == OP_OP_NUMBER ||        (op->type == OP_OP_STRING || op->type == OP_OP_NUMBER ||
2720         op->type == OP_OP_NUMBERS))         op->type == OP_OP_NUMBERS))

Legend:
Removed from v.1039  
changed lines
  Added in v.1335

  ViewVC Help
Powered by ViewVC 1.1.5