/[pcre]/code/tags/pcre-8.01/pcregrep.c
ViewVC logotype

Diff of /code/tags/pcre-8.01/pcregrep.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 89 by nigel, Sat Feb 24 21:41:27 2007 UTC revision 97 by ph10, Mon Mar 5 12:36:47 2007 UTC
# Line 37  POSSIBILITY OF SUCH DAMAGE. Line 37  POSSIBILITY OF SUCH DAMAGE.
37  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
38  */  */
39    
40    #ifdef HAVE_CONFIG_H
41    #  include <config.h>
42    #endif
43    
44  #include <ctype.h>  #include <ctype.h>
45  #include <locale.h>  #include <locale.h>
46  #include <stdio.h>  #include <stdio.h>
# Line 48  POSSIBILITY OF SUCH DAMAGE. Line 52  POSSIBILITY OF SUCH DAMAGE.
52  #include <sys/stat.h>  #include <sys/stat.h>
53  #include <unistd.h>  #include <unistd.h>
54    
 #include "config.h"  
55  #include "pcre.h"  #include "pcre.h"
56    
57  #define FALSE 0  #define FALSE 0
# Line 56  POSSIBILITY OF SUCH DAMAGE. Line 59  POSSIBILITY OF SUCH DAMAGE.
59    
60  typedef int BOOL;  typedef int BOOL;
61    
 #define VERSION "4.2 09-Jan-2006"  
62  #define MAX_PATTERN_COUNT 100  #define MAX_PATTERN_COUNT 100
63    
64  #if BUFSIZ > 8192  #if BUFSIZ > 8192
# Line 65  typedef int BOOL; Line 67  typedef int BOOL;
67  #define MBUFTHIRD 8192  #define MBUFTHIRD 8192
68  #endif  #endif
69    
   
70  /* Values for the "filenames" variable, which specifies options for file name  /* Values for the "filenames" variable, which specifies options for file name
71  output. The order is important; it is assumed that a file name is wanted for  output. The order is important; it is assumed that a file name is wanted for
72  all values greater than FN_DEFAULT. */  all values greater than FN_DEFAULT. */
# Line 83  enum { DEE_READ, DEE_SKIP }; Line 84  enum { DEE_READ, DEE_SKIP };
84  #define PO_LINE_MATCH     0x0002  #define PO_LINE_MATCH     0x0002
85  #define PO_FIXED_STRINGS  0x0004  #define PO_FIXED_STRINGS  0x0004
86    
87    /* Line ending types */
88    
89    enum { EL_LF, EL_CR, EL_CRLF, EL_ANY };
90    
91    
92    
93  /*************************************************  /*************************************************
# Line 100  static const char *jfriedl_prefix = ""; Line 105  static const char *jfriedl_prefix = "";
105  static const char *jfriedl_postfix = "";  static const char *jfriedl_postfix = "";
106  #endif  #endif
107    
108    static int  endlinetype;
109    
110  static char *colour_string = (char *)"1;31";  static char *colour_string = (char *)"1;31";
111  static char *colour_option = NULL;  static char *colour_option = NULL;
112  static char *dee_option = NULL;  static char *dee_option = NULL;
113  static char *DEE_option = NULL;  static char *DEE_option = NULL;
114    static char *newline = NULL;
115  static char *pattern_filename = NULL;  static char *pattern_filename = NULL;
116  static char *stdin_name = (char *)"(standard input)";  static char *stdin_name = (char *)"(standard input)";
117  static char *locale = NULL;  static char *locale = NULL;
# Line 138  static BOOL number = FALSE; Line 146  static BOOL number = FALSE;
146  static BOOL only_matching = FALSE;  static BOOL only_matching = FALSE;
147  static BOOL quiet = FALSE;  static BOOL quiet = FALSE;
148  static BOOL silent = FALSE;  static BOOL silent = FALSE;
149    static BOOL utf8 = FALSE;
150    
151  /* Structure for options and list of them */  /* Structure for options and list of them */
152    
# Line 185  static option_item optionlist[] = { Line 194  static option_item optionlist[] = {
194    { OP_STRING,    N_LABEL,  &stdin_name,       "label=name",    "set name for standard input" },    { OP_STRING,    N_LABEL,  &stdin_name,       "label=name",    "set name for standard input" },
195    { OP_STRING,    N_LOCALE, &locale,           "locale=locale", "use the named locale" },    { OP_STRING,    N_LOCALE, &locale,           "locale=locale", "use the named locale" },
196    { OP_NODATA,    'M',      NULL,              "multiline",     "run in multiline mode" },    { OP_NODATA,    'M',      NULL,              "multiline",     "run in multiline mode" },
197      { OP_STRING,    'N',      &newline,          "newline=type",  "specify newline type (CR, LR, CRLF)" },
198    { OP_NODATA,    'n',      NULL,              "line-number",   "print line number with output lines" },    { OP_NODATA,    'n',      NULL,              "line-number",   "print line number with output lines" },
199    { OP_NODATA,    'o',      NULL,              "only-matching", "show only the part of the line that matched" },    { OP_NODATA,    'o',      NULL,              "only-matching", "show only the part of the line that matched" },
200    { OP_NODATA,    'q',      NULL,              "quiet",         "suppress output, just set return code" },    { OP_NODATA,    'q',      NULL,              "quiet",         "suppress output, just set return code" },
# Line 214  static const char *prefix[] = { Line 224  static const char *prefix[] = {
224  static const char *suffix[] = {  static const char *suffix[] = {
225    "", "\\b", ")$",   ")$",   "\\E", "\\E\\b", "\\E)$",   "\\E)$" };    "", "\\b", ")$",   ")$",   "\\E", "\\E\\b", "\\E)$",   "\\E)$" };
226    
227    /* UTF-8 tables - used only when the newline setting is "all". */
228    
229    const int utf8_table3[] = { 0xff, 0x1f, 0x0f, 0x07, 0x03, 0x01};
230    
231    const char utf8_table4[] = {
232      1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
233      1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
234      2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
235      3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5 };
236    
237    
238    
239  /*************************************************  /*************************************************
# Line 226  although at present the only ones are fo Line 246  although at present the only ones are fo
246    
247  /************* Directory scanning in Unix ***********/  /************* Directory scanning in Unix ***********/
248    
249  #if IS_UNIX  #if defined HAVE_SYS_STAT_H && defined HAVE_DIRENT_H && defined HAVE_SYS_TYPES_H
250  #include <sys/types.h>  #include <sys/types.h>
251  #include <sys/stat.h>  #include <sys/stat.h>
252  #include <dirent.h>  #include <dirent.h>
# Line 296  Lionel Fourquaux. David Burgess added a Line 316  Lionel Fourquaux. David Burgess added a
316  when it did not exist. */  when it did not exist. */
317    
318    
319  #elif HAVE_WIN32API  #elif HAVE_WINDOWS_H
320    
321  #ifndef STRICT  #ifndef STRICT
322  # define STRICT  # define STRICT
# Line 418  FALSE; Line 438  FALSE;
438  typedef void directory_type;  typedef void directory_type;
439    
440  int isdirectory(char *filename) { return 0; }  int isdirectory(char *filename) { return 0; }
441  directory_type * opendirectory(char *filename) {}  directory_type * opendirectory(char *filename) { return (directory_type*)0;}
442  char *readdirectory(directory_type *dir) {}  char *readdirectory(directory_type *dir) { return (char*)0;}
443  void closedirectory(directory_type *dir) {}  void closedirectory(directory_type *dir) {}
444    
445    
# Line 466  return sys_errlist[n]; Line 486  return sys_errlist[n];
486    
487    
488  /*************************************************  /*************************************************
489    *             Find end of line                   *
490    *************************************************/
491    
492    /* The length of the endline sequence that is found is set via lenptr. This may
493    be zero at the very end of the file if there is no line-ending sequence there.
494    
495    Arguments:
496      p         current position in line
497      endptr    end of available data
498      lenptr    where to put the length of the eol sequence
499    
500    Returns:    pointer to the last byte of the line
501    */
502    
503    static char *
504    end_of_line(char *p, char *endptr, int *lenptr)
505    {
506    switch(endlinetype)
507      {
508      default:      /* Just in case */
509      case EL_LF:
510      while (p < endptr && *p != '\n') p++;
511      if (p < endptr)
512        {
513        *lenptr = 1;
514        return p + 1;
515        }
516      *lenptr = 0;
517      return endptr;
518    
519      case EL_CR:
520      while (p < endptr && *p != '\r') p++;
521      if (p < endptr)
522        {
523        *lenptr = 1;
524        return p + 1;
525        }
526      *lenptr = 0;
527      return endptr;
528    
529      case EL_CRLF:
530      for (;;)
531        {
532        while (p < endptr && *p != '\r') p++;
533        if (++p >= endptr)
534          {
535          *lenptr = 0;
536          return endptr;
537          }
538        if (*p == '\n')
539          {
540          *lenptr = 2;
541          return p + 1;
542          }
543        }
544      break;
545    
546      case EL_ANY:
547      while (p < endptr)
548        {
549        int extra = 0;
550        register int c = *((unsigned char *)p);
551    
552        if (utf8 && c >= 0xc0)
553          {
554          int gcii, gcss;
555          extra = utf8_table4[c & 0x3f];  /* Number of additional bytes */
556          gcss = 6*extra;
557          c = (c & utf8_table3[extra]) << gcss;
558          for (gcii = 1; gcii <= extra; gcii++)
559            {
560            gcss -= 6;
561            c |= (p[gcii] & 0x3f) << gcss;
562            }
563          }
564    
565        p += 1 + extra;
566    
567        switch (c)
568          {
569          case 0x0a:    /* LF */
570          case 0x0b:    /* VT */
571          case 0x0c:    /* FF */
572          *lenptr = 1;
573          return p;
574    
575          case 0x0d:    /* CR */
576          if (p < endptr && *p == 0x0a)
577            {
578            *lenptr = 2;
579            p++;
580            }
581          else *lenptr = 1;
582          return p;
583    
584          case 0x85:    /* NEL */
585          *lenptr = utf8? 2 : 1;
586          return p;
587    
588          case 0x2028:  /* LS */
589          case 0x2029:  /* PS */
590          *lenptr = 3;
591          return p;
592    
593          default:
594          break;
595          }
596        }   /* End of loop for ANY case */
597    
598      *lenptr = 0;  /* Must have hit the end */
599      return endptr;
600      }     /* End of overall switch */
601    }
602    
603    
604    
605    /*************************************************
606    *         Find start of previous line            *
607    *************************************************/
608    
609    /* This is called when looking back for before lines to print.
610    
611    Arguments:
612      p         start of the subsequent line
613      startptr  start of available data
614    
615    Returns:    pointer to the start of the previous line
616    */
617    
618    static char *
619    previous_line(char *p, char *startptr)
620    {
621    switch(endlinetype)
622      {
623      default:      /* Just in case */
624      case EL_LF:
625      p--;
626      while (p > startptr && p[-1] != '\n') p--;
627      return p;
628    
629      case EL_CR:
630      p--;
631      while (p > startptr && p[-1] != '\n') p--;
632      return p;
633    
634      case EL_CRLF:
635      for (;;)
636        {
637        p -= 2;
638        while (p > startptr && p[-1] != '\n') p--;
639        if (p <= startptr + 1 || p[-2] == '\r') return p;
640        }
641      return p;   /* But control should never get here */
642    
643      case EL_ANY:
644      if (*(--p) == '\n' && p > startptr && p[-1] == '\r') p--;
645      if (utf8) while ((*p & 0xc0) == 0x80) p--;
646    
647      while (p > startptr)
648        {
649        register int c;
650        char *pp = p - 1;
651    
652        if (utf8)
653          {
654          int extra = 0;
655          while ((*pp & 0xc0) == 0x80) pp--;
656          c = *((unsigned char *)pp);
657          if (c >= 0xc0)
658            {
659            int gcii, gcss;
660            extra = utf8_table4[c & 0x3f];  /* Number of additional bytes */
661            gcss = 6*extra;
662            c = (c & utf8_table3[extra]) << gcss;
663            for (gcii = 1; gcii <= extra; gcii++)
664              {
665              gcss -= 6;
666              c |= (pp[gcii] & 0x3f) << gcss;
667              }
668            }
669          }
670        else c = *((unsigned char *)pp);
671    
672        switch (c)
673          {
674          case 0x0a:    /* LF */
675          case 0x0b:    /* VT */
676          case 0x0c:    /* FF */
677          case 0x0d:    /* CR */
678          case 0x85:    /* NEL */
679          case 0x2028:  /* LS */
680          case 0x2029:  /* PS */
681          return p;
682    
683          default:
684          break;
685          }
686    
687        p = pp;  /* Back one character */
688        }        /* End of loop for ANY case */
689    
690      return startptr;  /* Hit start of data */
691      }     /* End of overall switch */
692    }
693    
694    
695    
696    
697    
698    /*************************************************
699  *       Print the previous "after" lines         *  *       Print the previous "after" lines         *
700  *************************************************/  *************************************************/
701    
# Line 490  if (after_context > 0 && lastmatchnumber Line 720  if (after_context > 0 && lastmatchnumber
720    int count = 0;    int count = 0;
721    while (lastmatchrestart < endptr && count++ < after_context)    while (lastmatchrestart < endptr && count++ < after_context)
722      {      {
723        int ellength;
724      char *pp = lastmatchrestart;      char *pp = lastmatchrestart;
725      if (printname != NULL) fprintf(stdout, "%s-", printname);      if (printname != NULL) fprintf(stdout, "%s-", printname);
726      if (number) fprintf(stdout, "%d-", lastmatchnumber++);      if (number) fprintf(stdout, "%d-", lastmatchnumber++);
727      while (*pp != '\n') pp++;      pp = end_of_line(pp, endptr, &ellength);
728      fwrite(lastmatchrestart, 1, pp - lastmatchrestart + 1, stdout);      fwrite(lastmatchrestart, 1, pp - lastmatchrestart, stdout);
729      lastmatchrestart = pp + 1;      lastmatchrestart = pp;
730      }      }
731    hyphenpending = TRUE;    hyphenpending = TRUE;
732    }    }
# Line 552  way, the buffer is shifted left and re-f Line 783  way, the buffer is shifted left and re-f
783    
784  while (ptr < endptr)  while (ptr < endptr)
785    {    {
786    int i;    int i, endlinelength;
787    int mrc = 0;    int mrc = 0;
788    BOOL match = FALSE;    BOOL match = FALSE;
789    char *t = ptr;    char *t = ptr;
# Line 565  while (ptr < endptr) Line 796  while (ptr < endptr)
796    line. In multiline mode the PCRE_FIRSTLINE option is used for compiling, so    line. In multiline mode the PCRE_FIRSTLINE option is used for compiling, so
797    that any match is constrained to be in the first line. */    that any match is constrained to be in the first line. */
798    
799    linelength = 0;    t = end_of_line(t, endptr, &endlinelength);
800    while (t < endptr && *t++ != '\n') linelength++;    linelength = t - ptr - endlinelength;
801    length = multiline? endptr - ptr : linelength;    length = multiline? endptr - ptr : linelength;
802    
   
803    /* Extra processing for Jeffrey Friedl's debugging. */    /* Extra processing for Jeffrey Friedl's debugging. */
804    
805  #ifdef JFRIEDL_DEBUG  #ifdef JFRIEDL_DEBUG
# Line 700  while (ptr < endptr) Line 930  while (ptr < endptr)
930    
931        if (after_context > 0 && lastmatchnumber > 0)        if (after_context > 0 && lastmatchnumber > 0)
932          {          {
933            int ellength;
934          int linecount = 0;          int linecount = 0;
935          char *p = lastmatchrestart;          char *p = lastmatchrestart;
936    
937          while (p < ptr && linecount < after_context)          while (p < ptr && linecount < after_context)
938            {            {
939            while (*p != '\n') p++;            p = end_of_line(p, ptr, &ellength);
           p++;  
940            linecount++;            linecount++;
941            }            }
942    
# Line 719  while (ptr < endptr) Line 949  while (ptr < endptr)
949            char *pp = lastmatchrestart;            char *pp = lastmatchrestart;
950            if (printname != NULL) fprintf(stdout, "%s-", printname);            if (printname != NULL) fprintf(stdout, "%s-", printname);
951            if (number) fprintf(stdout, "%d-", lastmatchnumber++);            if (number) fprintf(stdout, "%d-", lastmatchnumber++);
952            while (*pp != '\n') pp++;            pp = end_of_line(pp, endptr, &ellength);
953            fwrite(lastmatchrestart, 1, pp - lastmatchrestart + 1, stdout);            fwrite(lastmatchrestart, 1, pp - lastmatchrestart, stdout);
954            lastmatchrestart = pp + 1;            lastmatchrestart = pp;
955            }            }
956          if (lastmatchrestart != ptr) hyphenpending = TRUE;          if (lastmatchrestart != ptr) hyphenpending = TRUE;
957          }          }
# Line 747  while (ptr < endptr) Line 977  while (ptr < endptr)
977                 linecount < before_context)                 linecount < before_context)
978            {            {
979            linecount++;            linecount++;
980            p--;            p = previous_line(p, buffer);
           while (p > buffer && p[-1] != '\n') p--;  
981            }            }
982    
983          if (lastmatchnumber > 0 && p > lastmatchrestart && !hyphenprinted)          if (lastmatchnumber > 0 && p > lastmatchrestart && !hyphenprinted)
# Line 756  while (ptr < endptr) Line 985  while (ptr < endptr)
985    
986          while (p < ptr)          while (p < ptr)
987            {            {
988              int ellength;
989            char *pp = p;            char *pp = p;
990            if (printname != NULL) fprintf(stdout, "%s-", printname);            if (printname != NULL) fprintf(stdout, "%s-", printname);
991            if (number) fprintf(stdout, "%d-", linenumber - linecount--);            if (number) fprintf(stdout, "%d-", linenumber - linecount--);
992            while (*pp != '\n') pp++;            pp = end_of_line(pp, endptr, &ellength);
993            fwrite(p, 1, pp - p + 1, stdout);   /* In case binary zero */            fwrite(p, 1, pp - p, stdout);
994            p = pp + 1;            p = pp;
995            }            }
996          }          }
997    
# Line 777  while (ptr < endptr) Line 1007  while (ptr < endptr)
1007        /* 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
1008        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
1009        line number appropriately. Because the PCRE_FIRSTLINE option is set, the        line number appropriately. Because the PCRE_FIRSTLINE option is set, the
1010        start of the match will always be before the first \n character. */        start of the match will always be before the first newline sequence. */
1011    
1012        if (multiline)        if (multiline)
1013          {          {
1014            int ellength;
1015          char *endmatch = ptr + offsets[1];          char *endmatch = ptr + offsets[1];
1016          t = ptr;          t = ptr;
1017          while (t < endmatch) { if (*t++ == '\n') linenumber++; }          while (t < endmatch)
1018          while (endmatch < endptr && *endmatch != '\n') endmatch++;            {
1019          linelength = endmatch - ptr;            t = end_of_line(t, endptr, &ellength);
1020              if (t <= endmatch) linenumber++; else break;
1021              }
1022            endmatch = end_of_line(endmatch, endptr, &ellength);
1023            linelength = endmatch - ptr - ellength;
1024          }          }
1025    
1026        /*** 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 817  while (ptr < endptr) Line 1052  while (ptr < endptr)
1052          fprintf(stdout, "%c[00m", 0x1b);          fprintf(stdout, "%c[00m", 0x1b);
1053          fwrite(ptr + offsets[1], 1, linelength - offsets[1], stdout);          fwrite(ptr + offsets[1], 1, linelength - offsets[1], stdout);
1054          }          }
1055        else fwrite(ptr, 1, linelength, stdout);        else fwrite(ptr, 1, linelength + endlinelength, stdout);
   
       fprintf(stdout, "\n");  
1056        }        }
1057    
1058      /* End of doing what has to be done for a match */      /* End of doing what has to be done for a match */
# Line 829  while (ptr < endptr) Line 1062  while (ptr < endptr)
1062      /* Remember where the last match happened for after_context. We remember      /* Remember where the last match happened for after_context. We remember
1063      where we are about to restart, and that line's number. */      where we are about to restart, and that line's number. */
1064    
1065      lastmatchrestart = ptr + linelength + 1;      lastmatchrestart = ptr + linelength + endlinelength;
1066      lastmatchnumber = linenumber + 1;      lastmatchnumber = linenumber + 1;
1067      }      }
1068    
1069    /* Advance to after the newline and increment the line number. */    /* Advance to after the newline and increment the line number. */
1070    
1071    ptr += linelength + 1;    ptr += linelength + endlinelength;
1072    linenumber++;    linenumber++;
1073    
1074    /* If we haven't yet reached the end of the file (the buffer is full), and    /* If we haven't yet reached the end of the file (the buffer is full), and
# Line 1091  switch(letter) Line 1324  switch(letter)
1324    case 'q': quiet = TRUE; break;    case 'q': quiet = TRUE; break;
1325    case 'r': dee_action = dee_RECURSE; break;    case 'r': dee_action = dee_RECURSE; break;
1326    case 's': silent = TRUE; break;    case 's': silent = TRUE; break;
1327    case 'u': options |= PCRE_UTF8; break;    case 'u': options |= PCRE_UTF8; utf8 = TRUE; break;
1328    case 'v': invert = TRUE; break;    case 'v': invert = TRUE; break;
1329    case 'w': process_options |= PO_WORD_MATCH; break;    case 'w': process_options |= PO_WORD_MATCH; break;
1330    case 'x': process_options |= PO_LINE_MATCH; break;    case 'x': process_options |= PO_LINE_MATCH; break;
1331    
1332    case 'V':    case 'V':
1333    fprintf(stderr, "pcregrep version %s using ", VERSION);    fprintf(stderr, "pcregrep version %s\n", pcre_version());
   fprintf(stderr, "PCRE version %s\n", pcre_version());  
1334    exit(0);    exit(0);
1335    break;    break;
1336    
# Line 1206  return FALSE; Line 1438  return FALSE;
1438  *************************************************/  *************************************************/
1439    
1440  /* When the -F option has been used, each string may be a list of strings,  /* When the -F option has been used, each string may be a list of strings,
1441  separated by newlines. They will be matched literally.  separated by line breaks. They will be matched literally.
1442    
1443  Arguments:  Arguments:
1444    pattern        the pattern string    pattern        the pattern string
# Line 1224  compile_pattern(char *pattern, int optio Line 1456  compile_pattern(char *pattern, int optio
1456  {  {
1457  if ((process_options & PO_FIXED_STRINGS) != 0)  if ((process_options & PO_FIXED_STRINGS) != 0)
1458    {    {
1459      char *eop = pattern + strlen(pattern);
1460    char buffer[MBUFTHIRD];    char buffer[MBUFTHIRD];
1461    for(;;)    for(;;)
1462      {      {
1463      char *p = strchr(pattern, '\n');      int ellength;
1464      if (p == NULL)      char *p = end_of_line(pattern, eop, &ellength);
1465        if (ellength == 0)
1466        return compile_single_pattern(pattern, options, filename, count);        return compile_single_pattern(pattern, options, filename, count);
1467      sprintf(buffer, "%.*s", p - pattern, pattern);      sprintf(buffer, "%.*s", p - pattern - ellength, pattern);
1468      pattern = p + 1;      pattern = p;
1469      if (!compile_single_pattern(buffer, options, filename, count))      if (!compile_single_pattern(buffer, options, filename, count))
1470        return FALSE;        return FALSE;
1471      }      }
# Line 1260  char *patterns[MAX_PATTERN_COUNT]; Line 1494  char *patterns[MAX_PATTERN_COUNT];
1494  const char *locale_from = "--locale";  const char *locale_from = "--locale";
1495  const char *error;  const char *error;
1496    
1497    /* Set the default line ending value from the default in the PCRE library;
1498    "lf", "cr", "crlf", and "any" are supported. Anything else is treated as "lf".
1499    */
1500    
1501    (void)pcre_config(PCRE_CONFIG_NEWLINE, &i);
1502    switch(i)
1503      {
1504      default:                 newline = (char *)"lf"; break;
1505      case '\r':               newline = (char *)"cr"; break;
1506      case ('\r' << 8) | '\n': newline = (char *)"crlf"; break;
1507      case -1:                 newline = (char *)"any"; break;
1508      }
1509    
1510  /* Process the options */  /* Process the options */
1511    
1512  for (i = 1; i < argc; i++)  for (i = 1; i < argc; i++)
# Line 1543  if (colour_option != NULL && strcmp(colo Line 1790  if (colour_option != NULL && strcmp(colo
1790      }      }
1791    }    }
1792    
1793    /* Interpret the newline type; the default settings are Unix-like. */
1794    
1795    if (strcmp(newline, "cr") == 0 || strcmp(newline, "CR") == 0)
1796      {
1797      pcre_options |= PCRE_NEWLINE_CR;
1798      endlinetype = EL_CR;
1799      }
1800    else if (strcmp(newline, "lf") == 0 || strcmp(newline, "LF") == 0)
1801      {
1802      pcre_options |= PCRE_NEWLINE_LF;
1803      endlinetype = EL_LF;
1804      }
1805    else if (strcmp(newline, "crlf") == 0 || strcmp(newline, "CRLF") == 0)
1806      {
1807      pcre_options |= PCRE_NEWLINE_CRLF;
1808      endlinetype = EL_CRLF;
1809      }
1810    else if (strcmp(newline, "any") == 0 || strcmp(newline, "ANY") == 0)
1811      {
1812      pcre_options |= PCRE_NEWLINE_ANY;
1813      endlinetype = EL_ANY;
1814      }
1815    else
1816      {
1817      fprintf(stderr, "pcregrep: Invalid newline specifier \"%s\"\n", newline);
1818      return 2;
1819      }
1820    
1821  /* Interpret the text values for -d and -D */  /* Interpret the text values for -d and -D */
1822    
1823  if (dee_option != NULL)  if (dee_option != NULL)

Legend:
Removed from v.89  
changed lines
  Added in v.97

  ViewVC Help
Powered by ViewVC 1.1.5