/[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 653 by ph10, Mon Aug 1 09:54:26 2011 UTC revision 654 by ph10, Tue Aug 2 11:00:40 2011 UTC
# Line 639  Arguments: Line 639  Arguments:
639    endptr    end of available data    endptr    end of available data
640    lenptr    where to put the length of the eol sequence    lenptr    where to put the length of the eol sequence
641    
642  Returns:    pointer after the last byte of the line,  Returns:    pointer after the last byte of the line,
643              including the newline byte(s)              including the newline byte(s)
644  */  */
645    
# Line 953  Returns:      TRUE if there was a match Line 953  Returns:      TRUE if there was a match
953  */  */
954    
955  static BOOL  static BOOL
956  match_patterns(char *matchptr, size_t length, int startoffset, int *offsets,  match_patterns(char *matchptr, size_t length, int startoffset, int *offsets,
957    int *mrc)    int *mrc)
958  {  {
959  int i;  int i;
# Line 1013  Arguments: Line 1013  Arguments:
1013    
1014  Returns:       0 if there was at least one match  Returns:       0 if there was at least one match
1015                 1 otherwise (no matches)                 1 otherwise (no matches)
1016                 2 if an overlong line is encountered                 2 if an overlong line is encountered
1017                 3 if there is a read error on a .bz2 file                 3 if there is a read error on a .bz2 file
1018  */  */
1019    
# Line 1086  while (ptr < endptr) Line 1086  while (ptr < endptr)
1086    {    {
1087    int endlinelength;    int endlinelength;
1088    int mrc = 0;    int mrc = 0;
1089    int startoffset = 0;    int startoffset = 0;
1090    BOOL match;    BOOL match;
1091    char *matchptr = ptr;    char *matchptr = ptr;
1092    char *t = ptr;    char *t = ptr;
# Line 1103  while (ptr < endptr) Line 1103  while (ptr < endptr)
1103    t = end_of_line(t, endptr, &endlinelength);    t = end_of_line(t, endptr, &endlinelength);
1104    linelength = t - ptr - endlinelength;    linelength = t - ptr - endlinelength;
1105    length = multiline? (size_t)(endptr - ptr) : linelength;    length = multiline? (size_t)(endptr - ptr) : linelength;
1106    
1107    /* Check to see if the line we are looking at extends right to the very end    /* Check to see if the line we are looking at extends right to the very end
1108    of the buffer without a line terminator. This means the line is too long to    of the buffer without a line terminator. This means the line is too long to
1109    handle. */    handle. */
1110    
1111    if (endlinelength == 0 && t == main_buffer + bufsize)    if (endlinelength == 0 && t == main_buffer + bufsize)
1112      {      {
1113      fprintf(stderr, "pcregrep: line %d%s%s is too long for the internal buffer\n"      fprintf(stderr, "pcregrep: line %d%s%s is too long for the internal buffer\n"
1114                      "pcregrep: check the --buffer-size option\n",                      "pcregrep: check the --buffer-size option\n",
1115                      linenumber,                      linenumber,
1116                      (filename == NULL)? "" : " of file ",                      (filename == NULL)? "" : " of file ",
1117                      (filename == NULL)? "" : filename);                      (filename == NULL)? "" : filename);
1118      return 2;      return 2;
1119      }      }
1120    
1121    /* Extra processing for Jeffrey Friedl's debugging. */    /* Extra processing for Jeffrey Friedl's debugging. */
1122    
# Line 1384  while (ptr < endptr) Line 1384  while (ptr < endptr)
1384            {            {
1385            startoffset = offsets[1];            startoffset = offsets[1];
1386            if (startoffset >= linelength + endlinelength ||            if (startoffset >= linelength + endlinelength ||
1387                !match_patterns(matchptr, length, startoffset, offsets, &mrc))                !match_patterns(matchptr, length, startoffset, offsets, &mrc))
1388              break;              break;
1389            FWRITE(matchptr + startoffset, 1, offsets[0] - startoffset, stdout);            FWRITE(matchptr + startoffset, 1, offsets[0] - startoffset, stdout);
1390            fprintf(stdout, "%c[%sm", 0x1b, colour_string);            fprintf(stdout, "%c[%sm", 0x1b, colour_string);
# Line 1737  if (frtype == FR_LIBBZ2) Line 1737  if (frtype == FR_LIBBZ2)
1737      else if (!silent)      else if (!silent)
1738        fprintf(stderr, "pcregrep: Failed to read %s using bzlib: %s\n",        fprintf(stderr, "pcregrep: Failed to read %s using bzlib: %s\n",
1739          pathname, err);          pathname, err);
1740      rc = 2;    /* The normal "something went wrong" code */      rc = 2;    /* The normal "something went wrong" code */
1741      }      }
1742    BZ2_bzclose(inbz2);    BZ2_bzclose(inbz2);
1743    }    }
# Line 1830  for (op = optionlist; op->one_char != 0; Line 1830  for (op = optionlist; op->one_char != 0;
1830    printf("%.*s%s\n", n, "                     ", op->help_text);    printf("%.*s%s\n", n, "                     ", op->help_text);
1831    }    }
1832    
1833  printf("\nNumbers may be followed by K or M, e.g. --buffer-size=100K.\n");  printf("\nNumbers may be followed by K or M, e.g. --buffer-size=100K.\n");
1834  printf("The default value for --buffer-size is %d.\n", PCREGREP_BUFSIZE);  printf("The default value for --buffer-size is %d.\n", PCREGREP_BUFSIZE);
1835  printf("When reading patterns from a file instead of using a command line option,\n");  printf("When reading patterns from a file instead of using a command line option,\n");
1836  printf("trailing white space is removed and blank lines are ignored.\n");  printf("trailing white space is removed and blank lines are ignored.\n");
1837  printf("There is a maximum of %d patterns, each of maximum size %d bytes.\n",  printf("There is a maximum of %d patterns, each of maximum size %d bytes.\n",
1838    MAX_PATTERN_COUNT, PATBUFSIZE);    MAX_PATTERN_COUNT, PATBUFSIZE);
1839    
1840  printf("\nWith no FILEs, read standard input. If fewer than two FILEs given, assume -h.\n");  printf("\nWith no FILEs, read standard input. If fewer than two FILEs given, assume -h.\n");
# Line 2321  for (i = 1; i < argc; i++) Line 2321  for (i = 1; i < argc; i++)
2321        n = n * 10 + (int)(*endptr++ - '0');        n = n * 10 + (int)(*endptr++ - '0');
2322      if (toupper(*endptr) == 'K')      if (toupper(*endptr) == 'K')
2323        {        {
2324        n *= 1024;        n *= 1024;
2325        endptr++;        endptr++;
2326        }        }
2327      else if (toupper(*endptr) == 'M')      else if (toupper(*endptr) == 'M')
2328        {        {
2329        n *= 1024*1024;        n *= 1024*1024;
2330        endptr++;        endptr++;
2331        }        }
2332      if (*endptr != 0)      if (*endptr != 0)
2333        {        {
2334        if (longop)        if (longop)
# Line 2665  if (include_dir_pattern != NULL) Line 2665  if (include_dir_pattern != NULL)
2665    
2666  if (i >= argc)  if (i >= argc)
2667    {    {
2668    rc = pcregrep(stdin, FR_PLAIN, stdin_name,    rc = pcregrep(stdin, FR_PLAIN, stdin_name,
2669      (filenames > FN_DEFAULT)? stdin_name : NULL);      (filenames > FN_DEFAULT)? stdin_name : NULL);
2670    goto EXIT;    goto EXIT;
2671    }    }

Legend:
Removed from v.653  
changed lines
  Added in v.654

  ViewVC Help
Powered by ViewVC 1.1.5