/[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 149 by ph10, Mon Apr 16 15:28:08 2007 UTC revision 222 by ph10, Fri Aug 17 10:48:51 2007 UTC
# Line 38  POSSIBILITY OF SUCH DAMAGE. Line 38  POSSIBILITY OF SUCH DAMAGE.
38  */  */
39    
40  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
41  #  include <config.h>  #include <config.h>
42  #endif  #endif
43    
44  #include <ctype.h>  #include <ctype.h>
# Line 50  POSSIBILITY OF SUCH DAMAGE. Line 50  POSSIBILITY OF SUCH DAMAGE.
50    
51  #include <sys/types.h>  #include <sys/types.h>
52  #include <sys/stat.h>  #include <sys/stat.h>
53    
54  #ifdef HAVE_UNISTD_H  #ifdef HAVE_UNISTD_H
55  #  include <unistd.h>  #include <unistd.h>
56  #endif  #endif
57    
58  #include <pcre.h>  #include <pcre.h>
# Line 280  for (;;) Line 281  for (;;)
281    if (strcmp(dent->d_name, ".") != 0 && strcmp(dent->d_name, "..") != 0)    if (strcmp(dent->d_name, ".") != 0 && strcmp(dent->d_name, "..") != 0)
282      return dent->d_name;      return dent->d_name;
283    }    }
284  return NULL;   /* Keep compiler happy; never executed */  /* Control never reaches here */
285  }  }
286    
287  static void  static void
# Line 580  switch(endlinetype) Line 581  switch(endlinetype)
581          }          }
582        else *lenptr = 1;        else *lenptr = 1;
583        return p;        return p;
584    
585        default:        default:
586        break;        break;
587        }        }
588      }   /* End of loop for ANYCRLF case */      }   /* End of loop for ANYCRLF case */
589    
590    *lenptr = 0;  /* Must have hit the end */    *lenptr = 0;  /* Must have hit the end */
591    return endptr;    return endptr;
592    
# Line 687  switch(endlinetype) Line 688  switch(endlinetype)
688    return p;   /* But control should never get here */    return p;   /* But control should never get here */
689    
690    case EL_ANY:    case EL_ANY:
691    case EL_ANYCRLF:    case EL_ANYCRLF:
692    if (*(--p) == '\n' && p > startptr && p[-1] == '\r') p--;    if (*(--p) == '\n' && p > startptr && p[-1] == '\r') p--;
693    if (utf8) while ((*p & 0xc0) == 0x80) p--;    if (utf8) while ((*p & 0xc0) == 0x80) p--;
694    
# Line 721  switch(endlinetype) Line 722  switch(endlinetype)
722        case 0x0a:    /* LF */        case 0x0a:    /* LF */
723        case 0x0d:    /* CR */        case 0x0d:    /* CR */
724        return p;        return p;
725    
726        default:        default:
727        break;        break;
728        }        }
729    
730      else switch (c)      else switch (c)
731        {        {
# Line 855  while (ptr < endptr) Line 856  while (ptr < endptr)
856    
857    t = end_of_line(t, endptr, &endlinelength);    t = end_of_line(t, endptr, &endlinelength);
858    linelength = t - ptr - endlinelength;    linelength = t - ptr - endlinelength;
859    length = multiline? endptr - ptr : linelength;    length = multiline? (size_t)(endptr - ptr) : linelength;
860    
861    /* Extra processing for Jeffrey Friedl's debugging. */    /* Extra processing for Jeffrey Friedl's debugging. */
862    
# Line 1063  while (ptr < endptr) Line 1064  while (ptr < endptr)
1064    
1065        /* In multiline mode, we want to print to the end of the line in which        /* In multiline mode, we want to print to the end of the line in which
1066        the end of the matched string is found, so we adjust linelength and the        the end of the matched string is found, so we adjust linelength and the
1067        line number appropriately. Because the PCRE_FIRSTLINE option is set, the        line number appropriately, but only when there actually was a match
1068        start of the match will always be before the first newline sequence. */        (invert not set). Because the PCRE_FIRSTLINE option is set, the start of
1069          the match will always be before the first newline sequence. */
1070    
1071        if (multiline)        if (multiline)
1072          {          {
1073          int ellength;          int ellength;
1074          char *endmatch = ptr + offsets[1];          char *endmatch = ptr;
1075          t = ptr;          if (!invert)
         while (t < endmatch)  
1076            {            {
1077            t = end_of_line(t, endptr, &ellength);            endmatch += offsets[1];
1078            if (t <= endmatch) linenumber++; else break;            t = ptr;
1079              while (t < endmatch)
1080                {
1081                t = end_of_line(t, endptr, &ellength);
1082                if (t <= endmatch) linenumber++; else break;
1083                }
1084            }            }
1085          endmatch = end_of_line(endmatch, endptr, &ellength);          endmatch = end_of_line(endmatch, endptr, &ellength);
1086          linelength = endmatch - ptr - ellength;          linelength = endmatch - ptr - ellength;
# Line 1123  while (ptr < endptr) Line 1129  while (ptr < endptr)
1129      lastmatchnumber = linenumber + 1;      lastmatchnumber = linenumber + 1;
1130      }      }
1131    
1132      /* For a match in multiline inverted mode (which of course did not cause
1133      anything to be printed), we have to move on to the end of the match before
1134      proceeding. */
1135    
1136      if (multiline && invert && match)
1137        {
1138        int ellength;
1139        char *endmatch = ptr + offsets[1];
1140        t = ptr;
1141        while (t < endmatch)
1142          {
1143          t = end_of_line(t, endptr, &ellength);
1144          if (t <= endmatch) linenumber++; else break;
1145          }
1146        endmatch = end_of_line(endmatch, endptr, &ellength);
1147        linelength = endmatch - ptr - ellength;
1148        }
1149    
1150    /* Advance to after the newline and increment the line number. */    /* Advance to after the newline and increment the line number. */
1151    
1152    ptr += linelength + endlinelength;    ptr += linelength + endlinelength;
# Line 1525  if ((process_options & PO_FIXED_STRINGS) Line 1549  if ((process_options & PO_FIXED_STRINGS)
1549      char *p = end_of_line(pattern, eop, &ellength);      char *p = end_of_line(pattern, eop, &ellength);
1550      if (ellength == 0)      if (ellength == 0)
1551        return compile_single_pattern(pattern, options, filename, count);        return compile_single_pattern(pattern, options, filename, count);
1552      sprintf(buffer, "%.*s", p - pattern - ellength, pattern);      sprintf(buffer, "%.*s", (int)(p - pattern - ellength), pattern);
1553      pattern = p;      pattern = p;
1554      if (!compile_single_pattern(buffer, options, filename, count))      if (!compile_single_pattern(buffer, options, filename, count))
1555        return FALSE;        return FALSE;
# Line 1567  switch(i) Line 1591  switch(i)
1591    case '\r':               newline = (char *)"cr"; break;    case '\r':               newline = (char *)"cr"; break;
1592    case ('\r' << 8) | '\n': newline = (char *)"crlf"; break;    case ('\r' << 8) | '\n': newline = (char *)"crlf"; break;
1593    case -1:                 newline = (char *)"any"; break;    case -1:                 newline = (char *)"any"; break;
1594    case -2:                 newline = (char *)"anycrlf"; break;    case -2:                 newline = (char *)"anycrlf"; break;
1595    }    }
1596    
1597  /* Process the options */  /* Process the options */
# Line 1625  for (i = 1; i < argc; i++) Line 1649  for (i = 1; i < argc; i++)
1649          else                 /* Special case xxx=data */          else                 /* Special case xxx=data */
1650            {            {
1651            int oplen = equals - op->long_name;            int oplen = equals - op->long_name;
1652            int arglen = (argequals == NULL)? strlen(arg) : argequals - arg;            int arglen = (argequals == NULL)? (int)strlen(arg) : argequals - arg;
1653            if (oplen == arglen && strncmp(arg, op->long_name, oplen) == 0)            if (oplen == arglen && strncmp(arg, op->long_name, oplen) == 0)
1654              {              {
1655              option_data = arg + arglen;              option_data = arg + arglen;
# Line 1644  for (i = 1; i < argc; i++) Line 1668  for (i = 1; i < argc; i++)
1668          char buff2[24];          char buff2[24];
1669          int baselen = opbra - op->long_name;          int baselen = opbra - op->long_name;
1670          sprintf(buff1, "%.*s", baselen, op->long_name);          sprintf(buff1, "%.*s", baselen, op->long_name);
1671          sprintf(buff2, "%s%.*s", buff1, strlen(op->long_name) - baselen - 2,          sprintf(buff2, "%s%.*s", buff1,
1672            opbra + 1);            (int)strlen(op->long_name) - baselen - 2, opbra + 1);
1673          if (strcmp(arg, buff1) == 0 || strcmp(arg, buff2) == 0)          if (strcmp(arg, buff1) == 0 || strcmp(arg, buff2) == 0)
1674            break;            break;
1675          }          }

Legend:
Removed from v.149  
changed lines
  Added in v.222

  ViewVC Help
Powered by ViewVC 1.1.5