Print this page
3737 grep does not support -H option

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/fgrep/fgrep.c
          +++ new/usr/src/cmd/fgrep/fgrep.c
↓ open down ↓ 99 lines elided ↑ open up ↑
 100  100  
 101  101  /*
 102  102   * The same() macro and letter() function were inserted to allow for
 103  103   * the -i option work for the multi-byte environment.
 104  104   */
 105  105  wchar_t letter();
 106  106  #define same(a, b) \
 107  107          (a == b || iflag && (!MULTI_BYTE || ISASCII(a)) && (a ^ b) == ' ' && \
 108  108          letter(a) == letter(b))
 109  109  
      110 +#define STDIN_FILENAME gettext("(standard input)")
 110  111  
 111  112  #define QSIZE 400
 112  113  struct words {
 113  114          wchar_t inp;
 114  115          char    out;
 115  116          struct  words *nst;
 116  117          struct  words *link;
 117  118          struct  words *fail;
 118  119  } *w = NULL, *smax, *q;
 119  120  
 120  121  FILE *fptr;
 121  122  long long lnum;
 122      -int     bflag, cflag, lflag, fflag, nflag, vflag, xflag, eflag, sflag;
 123      -int     hflag, iflag;
      123 +int     bflag, cflag, lflag, fflag, nflag, vflag, xflag, eflag, qflag;
      124 +int     Hflag, hflag, iflag;
 124  125  int     retcode = 0;
 125  126  int     nfile;
 126  127  long long blkno;
 127  128  int     nsucc;
 128  129  long long tln;
 129  130  FILE    *wordf;
 130  131  char    *argptr;
 131  132  off_t input_size = 0;
 132  133  
 133  134  void    execute(char *);
↓ open down ↓ 9 lines elided ↑ open up ↑
 143  144          int c;
 144  145          int errflg = 0;
 145  146          struct stat file_stat;
 146  147  
 147  148          (void) setlocale(LC_ALL, "");
 148  149  #if !defined(TEXT_DOMAIN)       /* Should be defined by cc -D */
 149  150  #define TEXT_DOMAIN "SYS_TEST"  /* Use this only if it weren't */
 150  151  #endif
 151  152          (void) textdomain(TEXT_DOMAIN);
 152  153  
 153      -        while ((c = getopt(argc, argv, "hybcie:f:lnvxs")) != EOF)
      154 +        while ((c = getopt(argc, argv, "Hhybcie:f:lnvxqs")) != EOF)
 154  155                  switch (c) {
 155  156  
 156      -                case 's':
 157      -                        sflag++;
      157 +                case 'q':
      158 +                case 's': /* Solaris: legacy option */
      159 +                        qflag++;
      160 +                        continue;
      161 +                case 'H':
      162 +                        Hflag++;
      163 +                        hflag = 0;
 158  164                          continue;
 159  165                  case 'h':
 160  166                          hflag++;
      167 +                        Hflag = 0;
 161  168                          continue;
 162  169                  case 'b':
 163  170                          bflag++;
 164  171                          continue;
 165  172  
 166  173                  case 'i':
 167  174                  case 'y':
 168  175                          iflag++;
 169  176                          continue;
 170  177  
↓ open down ↓ 43 lines elided ↑ open up ↑
 214  221                  case 'x':
 215  222                          xflag++;
 216  223                          continue;
 217  224  
 218  225                  case '?':
 219  226                          errflg++;
 220  227          }
 221  228  
 222  229          argc -= optind;
 223  230          if (errflg || ((argc <= 0) && !fflag && !eflag)) {
 224      -                (void) printf(gettext("usage: fgrep [ -bchilnsvx ] "
      231 +                (void) printf(gettext("usage: fgrep [ -bcHhilnqsvx ] "
 225  232                          "[ -e exp ] [ -f file ] [ strings ] [ file ] ...\n"));
 226  233                  exit(2);
 227  234          }
 228  235          if (!eflag && !fflag) {
 229  236                  argptr = argv[optind];
 230  237                  input_size = strlen(argptr);
 231  238                  input_size++;
 232  239                  optind++;
 233  240                  argc--;
 234  241          }
↓ open down ↓ 71 lines elided ↑ open up ↑
 306  313          }
 307  314  
 308  315          if (file) {
 309  316                  if ((fptr = fopen(file, "r")) == NULL) {
 310  317                          (void) fprintf(stderr,
 311  318                                  gettext("fgrep: can't open %s\n"), file);
 312  319                          retcode = 2;
 313  320                          return;
 314  321                  }
 315  322          } else {
 316      -                file = "<stdin>";
 317  323                  fptr = stdin;
      324 +                file = STDIN_FILENAME;
 318  325          }
 319  326          ccount = 0;
 320  327          failed = 0;
 321  328          lnum = 1;
 322  329          tln = 0;
 323  330          blkno = 0;
 324  331          p = buf;
 325  332          nlp = p;
 326  333          c = w;
 327  334          for (;;) {
↓ open down ↓ 82 lines elided ↑ open up ↑
 410  417                  fptr)) <= 0) break;
 411  418                  blkno += (long long)ccount;
 412  419          }
 413  420          GETONE(lc, p);
 414  421  }
 415  422                          if ((vflag && (failed == 0 || xflag == 0)) ||
 416  423                                  (vflag == 0 && xflag && failed))
 417  424                                  goto nomatch;
 418  425  succeed:
 419  426                          nsucc = 1;
 420      -                        if (cflag)
 421      -                                tln++;
 422      -                        else if (lflag && !sflag) {
 423      -                                (void) printf("%s\n", file);
      427 +                        if (lflag || qflag) {
      428 +                                if (!qflag)
      429 +                                        (void) printf("%s\n", file);
 424  430                                  (void) fclose(fptr);
 425  431                                  return;
 426      -                        } else if (!sflag) {
 427      -                                if (nfile > 1 && !hflag)
      432 +                        }
      433 +                        if (cflag) {
      434 +                                tln++;
      435 +                        } else {
      436 +                                if (Hflag || (nfile > 1 && !hflag))
 428  437                                          (void) printf("%s:", file);
 429  438                                  if (bflag)
 430  439                                          (void) printf("%lld:",
 431  440                                                  (blkno - (long long)(ccount-1))
 432  441                                                  / BUFSIZ);
 433  442                                  if (nflag)
 434  443                                          (void) printf("%lld:", lnum);
 435  444                                  if (p <= nlp) {
 436  445                                          while (nlp < &buf[fw_lBufsiz + BUFSIZ])
 437  446                                                  (void) putchar(*nlp++);
↓ open down ↓ 13 lines elided ↑ open up ↑
 451  460                          if (vflag)
 452  461                                  goto succeed;
 453  462                          else {
 454  463                                  lnum++;
 455  464                                  nlp = p;
 456  465                                  c = w;
 457  466                                  failed = 0;
 458  467                          }
 459  468          }
 460  469          (void) fclose(fptr);
 461      -        if (cflag) {
 462      -                if ((nfile > 1) && !hflag)
      470 +        if (cflag && !qflag) {
      471 +                if (Hflag || (nfile > 1 && !hflag))
 463  472                          (void) printf("%s:", file);
 464  473                  (void) printf("%lld\n", tln);
 465  474          }
 466  475  }
 467  476  
 468  477  
 469  478  wchar_t
 470  479  getargc(void)
 471  480  {
 472  481          /* appends a newline to shell quoted argument list so */
↓ open down ↓ 222 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX