[BACK]Return to grep.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / grep

Diff for /src/usr.bin/grep/grep.c between version 1.8 and 1.9

version 1.8, 2003/06/22 23:51:22 version 1.9, 2003/06/23 00:55:09
Line 27 
Line 27 
  */   */
   
 #include <sys/types.h>  #include <sys/types.h>
   #include <sys/limits.h>
 #include <sys/stat.h>  #include <sys/stat.h>
   
 #include <err.h>  #include <err.h>
Line 67 
Line 68 
 #ifndef NOZ  #ifndef NOZ
 int      Zflag;         /* -Z: decompress input before processing */  int      Zflag;         /* -Z: decompress input before processing */
 #endif  #endif
 int      aflag;         /* -a: only search ascii files */  
 int      bflag;         /* -b: show block numbers for each match */  int      bflag;         /* -b: show block numbers for each match */
 int      cflag;         /* -c: only show a count of matching lines */  int      cflag;         /* -c: only show a count of matching lines */
 int      hflag;         /* -h: don't print filename headers */  int      hflag;         /* -h: don't print filename headers */
Line 81 
Line 81 
 int      wflag;         /* -w: pattern must start and end on word boundaries */  int      wflag;         /* -w: pattern must start and end on word boundaries */
 int      xflag;         /* -x: pattern must match entire line */  int      xflag;         /* -x: pattern must match entire line */
   
   int binbehave = BIN_FILE_BIN;
   
   enum {
           BIN_OPT = CHAR_MAX + 1,
           HELP_OPT,
           MMAP_OPT
   };
   
 /* Housekeeping */  /* Housekeeping */
 int      first;         /* flag whether or not this is our fist match */  int      first;         /* flag whether or not this is our fist match */
 int      tail;          /* lines left to print */  int      tail;          /* lines left to print */
Line 93 
Line 101 
 {  {
         fprintf(stderr,          fprintf(stderr,
 #ifdef NOZ  #ifdef NOZ
             "usage: %s [-[AB] num] [-CEFGHLPRSVabchilnoqsvwx]"              "usage: %s [-[AB] num] [-CEFGHILPRSUVabchilnoqsvwx]"
 #else  #else
             "usage: %s [-[AB] num] [-CEFGHLPRSVZabchilnoqsvwx]"              "usage: %s [-[AB] num] [-CEFGHILPRSUVZabchilnoqsvwx]"
 #endif  #endif
             " [-e pattern] [-f file] [file ...]\n", __progname);              " [-e pattern] [-f file] [file ...]\n", __progname);
         exit(2);          exit(2);
 }  }
   
 #ifdef NOZ  #ifdef NOZ
 static char *optstr = "0123456789A:B:CEFGHLPSRUVabce:f:hilnoqrsuvwxy";  static char *optstr = "0123456789A:B:CEFGHILPSRUVabce:f:hilnoqrsuvwxy";
 #else  #else
 static char *optstr = "0123456789A:B:CEFGHLPSRUVZabce:f:hilnoqrsuvwxy";  static char *optstr = "0123456789A:B:CEFGHILPSRUVZabce:f:hilnoqrsuvwxy";
 #endif  #endif
   
 struct option long_options[] =  struct option long_options[] =
 {  {
         {"basic-regexp",        no_argument,       NULL, 'G'},          {"binary-files",        required_argument, NULL, BIN_OPT},
         {"extended-regexp",     no_argument,       NULL, 'E'},          {"help",                no_argument,       NULL, HELP_OPT},
         {"fixed-strings",       no_argument,       NULL, 'F'},          {"mmap",                no_argument,       NULL, MMAP_OPT},
         {"after-context",       required_argument, NULL, 'A'},          {"after-context",       required_argument, NULL, 'A'},
         {"before-context",      required_argument, NULL, 'B'},          {"before-context",      required_argument, NULL, 'B'},
         {"context",             optional_argument, NULL, 'C'},          {"context",             optional_argument, NULL, 'C'},
           {"devices",             required_argument, NULL, 'D'},
           {"extended-regexp",     no_argument,       NULL, 'E'},
           {"fixed-strings",       no_argument,       NULL, 'F'},
           {"basic-regexp",        no_argument,       NULL, 'G'},
           {"binary",              no_argument,       NULL, 'U'},
         {"version",             no_argument,       NULL, 'V'},          {"version",             no_argument,       NULL, 'V'},
           {"text",                no_argument,       NULL, 'a'},
         {"byte-offset",         no_argument,       NULL, 'b'},          {"byte-offset",         no_argument,       NULL, 'b'},
         {"count",               no_argument,       NULL, 'c'},          {"count",               no_argument,       NULL, 'c'},
         {"regexp",              required_argument, NULL, 'e'},          {"regexp",              required_argument, NULL, 'e'},
Line 129 
Line 143 
         {"silent",              no_argument,       NULL, 'q'},          {"silent",              no_argument,       NULL, 'q'},
         {"recursive",           no_argument,       NULL, 'r'},          {"recursive",           no_argument,       NULL, 'r'},
         {"no-messages",         no_argument,       NULL, 's'},          {"no-messages",         no_argument,       NULL, 's'},
         {"text",                no_argument,       NULL, 'a'},  
         {"revert-match",        no_argument,       NULL, 'v'},          {"revert-match",        no_argument,       NULL, 'v'},
         {"word-regexp",         no_argument,       NULL, 'w'},          {"word-regexp",         no_argument,       NULL, 'w'},
         {"line-regexp",         no_argument,       NULL, 'x'},          {"line-regexp",         no_argument,       NULL, 'x'},
         {"binary",              no_argument,       NULL, 'U'},  
         {"unix-byte-offsets",   no_argument,       NULL, 'u'},          {"unix-byte-offsets",   no_argument,       NULL, 'u'},
 #ifndef NOZ  #ifndef NOZ
         {"decompress",          no_argument,       NULL, 'Z'},          {"decompress",          no_argument,       NULL, 'Z'},
Line 230 
Line 242 
                 case 'H':                  case 'H':
                         Hflag++;                          Hflag++;
                         break;                          break;
                   case 'I':
                           binbehave = BIN_FILE_SKIP;
                           break;
                 case 'L':                  case 'L':
                         lflag = 0;                          lflag = 0;
                         Lflag = qflag = 1;                          Lflag = qflag = 1;
Line 246 
Line 261 
                         oflag++;                          oflag++;
                         break;                          break;
                 case 'U':                  case 'U':
                 case 'u':                          binbehave = BIN_FILE_BIN;
                         /* these are here for compatability */  
                         break;                          break;
                 case 'V':                  case 'V':
                         fprintf(stderr, "grep version %u.%u\n", VER_MAJ, VER_MIN);                          fprintf(stderr, "grep version %u.%u\n", VER_MAJ, VER_MIN);
                         fprintf(stderr, argv[0]);                          exit(0);
                         usage();  
                         break;                          break;
 #ifndef NOZ  #ifndef NOZ
                 case 'Z':                  case 'Z':
Line 260 
Line 273 
                         break;                          break;
 #endif  #endif
                 case 'a':                  case 'a':
                         aflag = 1;                          binbehave = BIN_FILE_TEXT;
                         break;                          break;
                 case 'b':                  case 'b':
                         bflag = 1;                          bflag = 1;
Line 308 
Line 321 
                 case 'x':                  case 'x':
                         xflag = 1;                          xflag = 1;
                         break;                          break;
                   case BIN_OPT:
                           if (strcmp("binary", optarg) == 0)
                                   binbehave = BIN_FILE_BIN;
                           else if (strcmp("without-match", optarg) == 0)
                                   binbehave = BIN_FILE_SKIP;
                           else if (strcmp("text", optarg) == 0)
                                   binbehave = BIN_FILE_TEXT;
                           else
                                   errx(2, "Unknown binary-files option");
                           break;
                   case 'u':
                   case MMAP_OPT:
                           /* default, compatibility */
                           break;
                   case HELP_OPT:
                 default:                  default:
                         usage();                          usage();
                 }                  }

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9