From:	MERC::"uunet!WKUVX1.BITNET!FILESERV-Mgr" 12-JUN-1992 15:44:41.59
To:	galaxy::gleeve
CC:	
Subj:	FGREP.02_OF_06

-+-+-+-+-+-+-+-+ START OF PART 2 -+-+-+-+-+-+-+-+
X`09break;
X      case 'b':
X`09out_byte = 1;
X`09break;
X      case 'c':
X`09out_silent = 1;
X`09count_matches = 1;
X`09break;
X      case 'e':
X`09if (keys)
X`09  usage();
X`09keys = optarg;
X`09keycc = strlen(keys);
X`09break;
X      case 'f':
X`09if (keys)
X`09  usage();
X`09fp = strcmp(optarg, "-") ? fopen(optarg, "r") : stdin;
X`09if (!fp)
X`09  fatal(optarg, errno);
X`09keyalloc = 1024;
X`09keys = xmalloc(keyalloc);
X`09keycc = 0;
X`09while (!feof(fp)
X`09       && (cc = fread(keys + keycc, 1, keyalloc - keycc, fp)) > 0)
X`09  `7B
X`09    keycc += cc;
X`09    if (keycc == keyalloc)
X`09      keys = xrealloc(keys, keyalloc *= 2);
X`09  `7D
X`09if (fp != stdin)
X`09  fclose(fp);
X`09break;
X      case 'h':
X`09no_filenames = 1;
X`09break;
X      case 'i':
X      case 'y':`09`09`09/* For old-timers . . . */
X`09match_fold = 1;
X`09break;
X      case 'l':
X`09out_silent = 1;
X`09list_files = 1;
X`09break;
X      case 'n':
X`09out_line = 1;
X`09break;
X      case 's':
X`09out_silent = 1;
X`09break;
X      case 'v':
X`09out_invert = 1;
X`09break;
X      case 'w':
X`09match_words = 1;
X`09break;
X      case 'x':
X`09match_lines = 1;
X`09break;
X      default:
X`09usage();
X`09break;
X      `7D
X
X  if (!keys)
X    if (optind < argc)
X      `7B
X`09keys = argv`5Boptind++`5D;
X`09keycc = strlen(keys);
X      `7D
X    else
X      usage();
X
X  compile(keys, keycc);
X
X  if (argc - optind > 1 && !no_filenames)
X    out_file = 1;
X
X#ifdef VMS
X  status = 3;
X#else
X  status = 1;
X#endif
X  initbuf();
X
X  if (optind < argc)
X    while (optind < argc)
X      `7B
X`09desc = strcmp(argv`5Boptind`5D, "-") ?
X#ifdef VMS
X`09`09open(argv`5Boptind`5D, 0, 0, "shr=get,put,del,upd") : 0;
X#else
X`09`09open(argv`5Boptind`5D, 0) : 0;
X#endif
X`09if (desc < 0)
X`09  error(argv`5Boptind`5D, errno);
X`09else
X`09  `7B
X`09    count = grep(desc, argv`5Boptind`5D);
X`09    if (count_matches)
X`09      `7B
X`09`09if (out_file)
X`09`09  printf("%s:", argv`5Boptind`5D);
X`09`09printf("%d\n", count);
X`09      `7D
X`09    if (count)
X`09      `7B
X#ifdef VMS
X`09`09status = SS$_NORMAL;
X#else
X`09`09status = 0;
X#endif
X`09`09if (list_files)
X`09`09  printf("%s\n", argv`5Boptind`5D);
X`09      `7D
X`09  `7D
X`09if (desc)
X`09  close(desc);
X`09++optind;
X      `7D
X  else
X    `7B
X      count = grep(0, "<stdin>");
X      if (count_matches)
X`09printf("%d\n", count);
X      if (count)
X`09`7B
X#ifdef VMS
X`09  status = SS$_NORMAL;
X#else
X`09  status = 0;
X#endif
X`09  if (list_files)
X`09    printf("%s\n", argv`5Boptind`5D);
X`09`7D
X    `7D
X
X#ifdef VMS
X  exit(error_seen ? SS$_ABORT : status);
X#else
X  exit(error_seen ? 2 : status);
X#endif
X`7D
$ CALL UNPACK [.FGREP011]FGREP.C;1 1862786404
$ create 'f'
X!
X!  CLD file for defining fgrep command as DCL command
X!
X!  To install for all users, modify the dev:`5Bdir`5D strings below and
X!  execute the following commands:
X!
X!`09$ SET COMMAND FGREP.CLD/TABLE=SYS$LIBRARY:DCLTABLES.EXE-
X!`09`09/OUTPUT=SYS$COMMON:`5BSYSLIB`5DDCLTABLES.EXE
X!`09$ INSTALL :== $INSTALL/COMMAND
X!`09$ INSTALL REPLACE SYS$LIBRARY:DCLTABLES.EXE
X!
XDEFINE VERB fgrep
X`09image dev:`5Bdir`5Dfgrep.exe`09`09!**** Local
X`09cliflags(foreign)
$ CALL UNPACK [.FGREP011]FGREP.CLD;1 1984834257
$ create 'f'
X/* Getopt for GNU.
X   Copyright (C) 1987 Free Software Foundation, Inc.
X
X`09`09       NO WARRANTY
X
X  BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
XNO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW.  EXCEPT
XWHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
XRICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
XWITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
XBUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
XFITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY
XAND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE
XDEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
XCORRECTION.
X
X IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
XSTALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
XWHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
XLIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
XOTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
XUSE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
XDATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
XA FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
XPROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
XDAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
X
X`09`09GENERAL PUBLIC LICENSE TO COPY
X
X  1. You may copy and distribute verbatim copies of this source file
Xas you receive it, in any medium, provided that you conspicuously and
Xappropriately publish on each copy a valid copyright notice "Copyright
X (C) 1987 Free Software Foundation, Inc."; and include following the
Xcopyright notice a verbatim copy of the above disclaimer of warranty
Xand of this License.  You may charge a distribution fee for the
Xphysical act of transferring a copy.
X
X  2. You may modify your copy or copies of this source file or
Xany portion of it, and copy and distribute such modifications under
Xthe terms of Paragraph 1 above, provided that you also do the following:
X
X    a) cause the modified files to carry prominent notices stating
X    that you changed the files and the date of any change; and
X
X    b) cause the whole of any work that you distribute or publish,
X    that in whole or in part contains or is a derivative of this
X    program or any part thereof, to be licensed at no charge to all
X    third parties on terms identical to those contained in this
X    License Agreement (except that you may choose to grant more
X    extensive warranty protection to third parties, at your option).
X
X    c) You may charge a distribution fee for the physical act of
X    transferring a copy, and you may at your option offer warranty
X    protection in exchange for a fee.
X
X  3. You may copy and distribute this program or any portion of it in
Xcompiled, executable or object code form under the terms of Paragraphs
X1 and 2 above provided that you do the following:
X
X    a) cause each such copy to be accompanied by the
X    corresponding machine-readable source code, which must
X    be distributed under the terms of Paragraphs 1 and 2 above; or,
X
X    b) cause each such copy to be accompanied by a
X    written offer, with no time limit, to give any third party
X    free (except for a nominal shipping charge) a machine readable
X    copy of the corresponding source code, to be distributed
X    under the terms of Paragraphs 1 and 2 above; or,
X
X    c) in the case of a recipient of this program in compiled, executable
X    or object code form (without the corresponding source code) you
X    shall cause copies you distribute to be accompanied by a copy
X    of the written offer of source code which you received along
X    with the copy you received.
X
X  4. You may not copy, sublicense, distribute or transfer this program
Xexcept as expressly provided under this License Agreement.  Any attempt
Xotherwise to copy, sublicense, distribute or transfer this program is void a
Vnd
Xyour rights to use the program under this License agreement shall be
Xautomatically terminated.  However, parties who have received computer
Xsoftware programs from you with this License Agreement will not have
Xtheir licenses terminated so long as such parties remain in full compliance.
X
X  5. If you wish to incorporate parts of this program into other free
Xprograms whose distribution conditions are different, write to the Free
XSoftware Foundation at 675 Mass Ave, Cambridge, MA 02139.  We have not yet
Xworked out a simple rule that can be stated here, but we will often permit
Xthis.  We will be guided by the two goals of preserving the free status of
Xall derivatives of our free software and of promoting the sharing and reuse
V of
Xsoftware.
X
X
XIn other words, you are welcome to use, share and improve this program.
XYou are forbidden to forbid anyone else to use, share and improve
Xwhat you give them.   Help stamp out software-hoarding!  */
X`0C
X/* This version of `60getopt' appears to the caller like standard Unix `60ge
Vtopt'
X   but it behaves differently for the user, since it allows the user
X   to intersperse the options with the other arguments.
X
X   As `60getopt' works, it permutes the elements of `60argv' so that,
X   when it is done, all the options precede everything else.  Thus
X   all application programs are extended to handle flexible argument order.
X
X   Setting the environment variable _POSIX_OPTION_ORDER disables permutation
V.
X   Then the behavior is completely standard.
X
X   GNU application programs can use a third alternative mode in which
X   they can distinguish the relative order of options and other arguments.
V  */
X
X#include <stdio.h>
X
X#ifdef sparc
X#include <alloca.h>
X#endif
X#ifdef USG
X#define bcopy(s, d, l) memcpy((d), (s), (l))
X#endif
X#ifdef VAXC
X#include string
X#define bcopy(s, d, l) memcpy((d), (s), (l))
X#endif
X
X/* For communication from `60getopt' to the caller.
X   When `60getopt' finds an option that takes an argument,
X   the argument value is returned here.
X   Also, when `60ordering' is RETURN_IN_ORDER,
X   each non-option ARGV-element is returned here.  */
X
Xchar *optarg = 0;
X
X/* Index in ARGV of the next element to be scanned.
X   This is used for communication to and from the caller
X   and for communication between successive calls to `60getopt'.
X
X   On entry to `60getopt', zero means this is the first call; initialize.
X
X   When `60getopt' returns EOF, this is the index of the first of the
X   non-option elements that the caller should itself scan.
X
X   Otherwise, `60optind' communicates from one call to the next
X   how much of ARGV has been scanned so far.  */
X
Xint optind = 0;
X
X/* The next char to be scanned in the option-element
X   in which the last option character we returned was found.
X   This allows us to pick up the scan where we left off.
X
X   If this is zero, or a null string, it means resume the scan
X   by advancing to the next ARGV-element.  */
X
Xstatic char *nextchar;
X
X/* Callers store zero here to inhibit the error message
X   for unrecognized options.  */
X
Xint opterr = 1;
X
X/* Describe how to deal with options that follow non-option ARGV-elements.
X
X   UNSPECIFIED means the caller did not specify anything;
X   the default is then REQUIRE_ORDER if the environment variable
X   _OPTIONS_FIRST is defined, PERMUTE otherwise.
X
X   REQUIRE_ORDER means don't recognize them as options.
X   Stop option processing when the first non-option is seen.
X   This is what Unix does.
X
X   PERMUTE is the default.  We permute the contents of `60argv' as we scan,
X   so that eventually all the options are at the end.  This allows options
X   to be given in any order, even with programs that were not written to
X   expect this.
X
X   RETURN_IN_ORDER is an option available to programs that were written
X   to expect options and other ARGV-elements in any order and that care abou
Vt
X   the ordering of the two.  We describe each non-option ARGV-element
X   as if it were the argument of an option with character code zero.
X   Using `60-' as the first character of the list of option characters
X   requests this mode of operation.
X
X   The special argument `60--' forces an end of option-scanning regardless
X   of the value of `60ordering'.  In the case of RETURN_IN_ORDER, only
X   `60--' can cause `60getopt' to return EOF with `60optind' != ARGC.  */
X
Xstatic enum `7B REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER `7D ordering;
X`0C
X/* Handle permutation of arguments.  */
X
X/* Describe the part of ARGV that contains non-options that have
X   been skipped.  `60first_nonopt' is the index in ARGV of the first of them
V;
X   `60last_nonopt' is the index after the last of them.  */
X
Xstatic int first_nonopt;
Xstatic int last_nonopt;
X
X/* Exchange two adjacent subsequences of ARGV.
X   One subsequence is elements `5Bfirst_nonopt,last_nonopt)
X    which contains all the non-options that have been skipped so far.
X   The other is elements `5Blast_nonopt,optind), which contains all
X    the options processed since those non-options were skipped.
X
X   `60first_nonopt' and `60last_nonopt' are relocated so that they describe
X    the new indices of the non-options in ARGV after they are moved.  */
X
Xstatic void
Xexchange (argv)
X     char **argv;
X`7B
X  int nonopts_size
X    = (last_nonopt - first_nonopt) * sizeof (char *);
X  char **temp = (char **) alloca (nonopts_size);
X
X  /* Interchange the two blocks of data in argv.  */
X
X  bcopy (&argv`5Bfirst_nonopt`5D, temp, nonopts_size);
X  bcopy (&argv`5Blast_nonopt`5D, &argv`5Bfirst_nonopt`5D,
X`09 (optind - last_nonopt) * sizeof (char *));
X  bcopy (temp, &argv`5Bfirst_nonopt + optind - last_nonopt`5D,
X`09 nonopts_size);
X
X  /* Update records for the slots the non-options now occupy.  */
X
X  first_nonopt += (optind - last_nonopt);
X  last_nonopt = optind;
X`7D
X`0C
X/* Scan elements of ARGV (whose length is ARGC) for option characters
X   given in OPTSTRING.
X
X   If an element of ARGV starts with '-', and is not exactly "-" or "--",
X   then it is an option element.  The characters of this element
X   (aside from the initial '-') are option characters.  If `60getopt'
X   is called repeatedly, it returns successively each of theoption character
Vs
X   from each of the option elements.
X
X   If `60getopt' finds another option character, it returns that character,
X   updating `60optind' and `60nextchar' so that the next call to `60getopt'
V can
X   resume the scan with the following option character or ARGV-element.
X
X   If there are no more option characters, `60getopt' returns `60EOF'.
X   Then `60optind' is the index in ARGV of the first ARGV-element
X   that is not an option.  (The ARGV-elements have been permuted
X   so that those that are not options now come last.)
X
X   OPTSTRING is a string containing the legitimate option characters.
X   A colon in OPTSTRING means that the previous character is an option
X   that wants an argument.  The argument is taken from the rest of the
X   current ARGV-element, or from the following ARGV-element,
X   and returned in `60optarg'.
X
X   If an option character is seen that is not listed in OPTSTRING,
X   return '?' after printing an error message.  If you set `60opterr' to
X   zero, the error message is suppressed but we still return '?'.
X
X   If a char in OPTSTRING is followed by a colon, that means it wants an arg
V,
X   so the following text in the same ARGV-element, or the text of the follow
Ving
X   ARGV-element, is returned in `60optarg.  Two colons mean an option that
X   wants an optional arg; if there is text in the current ARGV-element,
X   it is returned in `60optarg'.
X
X   If OPTSTRING starts with `60-', it requests a different method of handlin
Vg the
X   non-option ARGV-elements.  See the comments about RETURN_IN_ORDER, above.
V  */
X
Xint
Xgetopt (argc, argv, optstring)
X     int argc;
X     char **argv;
X     char *optstring;
X`7B
X  /* Initialize the internal data when the first call is made.
X     Start processing options with ARGV-element 1 (since ARGV-element 0
X     is the program name); the sequence of previously skipped
X     non-option ARGV-elements is empty.  */
X
X  if (optind == 0)
X    `7B
X      first_nonopt = last_nonopt = optind = 1;
X
X      nextchar = 0;
X
X      /* Determine how to handle the ordering of options and nonoptions.  */
X
X      if (optstring`5B0`5D == '-')
X`09ordering = RETURN_IN_ORDER;
X      else if (getenv ("_POSIX_OPTION_ORDER") != 0)
X`09ordering = REQUIRE_ORDER;
X      else
X`09ordering = PERMUTE;
X    `7D
X
X  if (nextchar == 0 `7C`7C *nextchar == 0)
X    `7B
X      if (ordering == PERMUTE)
X`09`7B
X`09  /* If we have just processed some options following some non-options,
X`09     exchange them so that the options come first.  */
X
X`09  if (first_nonopt != last_nonopt && last_nonopt != optind)
X`09    exchange (argv);
X`09  else if (last_nonopt != optind)
X`09    first_nonopt = optind;
X
X`09  /* Now skip any additional non-options
X`09     and extend the range of non-options previously skipped.  */
X
X`09  while (optind < argc
X`09`09 && (argv`5Boptind`5D`5B0`5D != '-'
X`09`09     `7C`7C argv`5Boptind`5D`5B1`5D == 0))
X`09    optind++;
X`09  last_nonopt = optind;
X`09`7D
X
X      /* Special ARGV-element `60--' means premature end of options.
X`09 Skip it like a null option,
X`09 then exchange with previous non-options as if it were an option,
X`09 then skip everything else like a non-option.  */
X
X      if (optind != argc && !strcmp (argv`5Boptind`5D, "--"))
X`09`7B
X`09  optind++;
X
X`09  if (first_nonopt != last_nonopt && last_nonopt != optind)
X`09    exchange (argv);
X`09  else if (first_nonopt == last_nonopt)
X`09    first_nonopt = optind;
X`09  last_nonopt = argc;
X
X`09  optind = argc;
X`09`7D
X
X      /* If we have done all the ARGV-elements, stop the scan
X`09 and back over any non-options that we skipped and permuted.  */
X
X      if (optind == argc)
X`09`7B
X`09  /* Set the next-arg-index to point at the non-options
X`09     that we previously skipped, so the caller will digest them.  */
X`09  if (first_nonopt != last_nonopt)
X`09    optind = first_nonopt;
X`09  return EOF;
X`09`7D
X`09`20
X      /* If we have come to a non-option and did not permute it,
X`09 either stop the scan or describe it to the caller and pass it by.  */
X
X      if (argv`5Boptind`5D`5B0`5D != '-' `7C`7C argv`5Boptind`5D`5B1`5D == 0
V)
X`09`7B
X`09  if (ordering == REQUIRE_ORDER)
X`09    return EOF;
X`09  optarg = argv`5Boptind++`5D;
X`09  return 0;
X`09`7D
X
X      /* We have found another option-ARGV-element.
X`09 Start decoding its characters.  */
X
X      nextchar = argv`5Boptind`5D + 1;
X    `7D
X
X  /* Look at and handle the next option-character.  */
X
X  `7B
X    char c = *nextchar++;
X#ifdef VAXC
X    char *temp = strchr (optstring, c);
X#else
X    char *temp = (char *) index (optstring, c);
X#endif
X    /* Increment `60optind' when we start to process its last character.  */
X    if (*nextchar == 0)
X      optind++;
X
X    if (temp == 0 `7C`7C c == ':')
X      `7B
X`09if (opterr != 0)
X`09  `7B
X`09    if (c < 040 `7C`7C c >= 0177)
X`09      fprintf (stderr, "%s: unrecognized option, character code 0%o\n",
X`09`09       argv`5B0`5D, c);
X`09    else
X`09      fprintf (stderr, "%s: unrecognized option `60-%c'\n",
X`09`09       argv`5B0`5D, c);
X`09  `7D
X`09return '?';
X      `7D
X    if (temp`5B1`5D == ':')
X      `7B
X`09if (temp`5B2`5D == ':')
X`09  `7B
X`09    /* This is an option that accepts an argument optionally.  */
X`09    if (*nextchar != 0)
X`09      `7B
X`09        optarg = nextchar;
X`09`09optind++;
X`09      `7D
X`09    else
X`09      optarg = 0;
X`09    nextchar = 0;
X`09  `7D
X`09else
X`09  `7B
X`09    /* This is an option that requires an argument.  */
X`09    if (*nextchar != 0)
X`09      `7B
X`09`09optarg = nextchar;
X`09`09/* If we end this ARGV-element by taking the rest as an arg,
X`09`09   we must advance to the next element now.  */
X`09`09optind++;
X`09      `7D
X`09    else if (optind == argc)
X`09      `7B
X`09`09if (opterr != 0)
X`09`09  fprintf (stderr, "%s: no argument for `60-%c' option\n",
X`09`09`09   argv`5B0`5D, c);
X`09`09c = '?';
X`09      `7D
X`09    else
X`09      /* We already incremented `60optind' once;
X`09`09 increment it again when taking next ARGV-elt as argument.  */
X`09      optarg = argv`5Boptind++`5D;
X`09    nextchar = 0;
X`09  `7D
X      `7D
X    return c;
X  `7D
X`7D
X`0C
X#ifdef TEST
X
X/* Compile with -DTEST to make an executable for use in testing
X   the above definition of `60getopt'.  */
X
Xint
Xmain (argc, argv)
X     int argc;
X     char **argv;
X`7B
X  char c;
X  int digit_optind = 0;
X
X  while (1)
X    `7B
X      int this_option_optind = optind;
X      if ((c = getopt (argc, argv, "abc:d:0123456789")) == EOF)
X`09break;
X
X      switch (c)
X`09`7B
X`09case '0':
X`09case '1':
X`09case '2':
X`09case '3':
X`09case '4':
X`09case '5':
X`09case '6':
X`09case '7':
X`09case '8':
X`09case '9':
X`09  if (digit_optind != 0 && digit_optind != this_option_optind)
X`09    printf ("digits occur in two different argv-elements.\n");
X`09  digit_optind = this_option_optind;
X`09  printf ("option %c\n", c);
X`09  break;
X
X`09case 'a':
X`09  printf ("option a\n");
X`09  break;
X
X`09case 'b':
X`09  printf ("option b\n");
X`09  break;
X
X`09case 'c':
X`09  printf ("option c with value `60%s'\n", optarg);
X`09  break;
X
X`09case '?':
X`09  break;
X
X`09default:
X`09  printf ("?? getopt returned character code 0%o ??\n", c);
X`09`7D
X    `7D
X
X  if (optind < argc)
X    `7B
X      printf ("non-option ARGV-elements: ");
X      while (optind < argc)
X`09printf ("%s ", argv`5Boptind++`5D);
X      printf ("\n");
X    `7D
X
X  return 0;
X`7D
X
X#endif /* TEST */
$ CALL UNPACK [.FGREP011]GETOPT.C;1 1165863716
$ create 'f'
X.!
X.!  File:`09GREP.RNH
X.!
X.!  Author:`09Hunter Goatley
X.!
X.!  Date:`09September 11, 1991
X.!
X.!  Description:
X.!
X.!`09RUNOFF source file for GNU grep on-line help.
X.!
X.!`09To build:`09$ RUNOFF GREP.RNH
X.!`09`09`09$ LIBR/HELP/INSERT libr GREP
X.!
X.!  Modification history:
X.!
X.!`0901-003`09`09Hunter Goatley`09`0911-JUN-1992 16:46
X.!`09`09Minor mods (author info) for v1.6.
X.!
X.!`0901-002`09`09Hunter Goatley`09`0917-SEP-1991 08:44
X.!`09`09Added fgrep.
X.!
X.!`0901-001`09`09Hunter Goatley`09`0911-SEP-1991 09:24
X.!`09`09Genesis.
X.!
X.noflags
X.lm4 .rm72
X.indent -4
X1 GREP
X.br
XGREP is GNU grep, the Free Software Foundation's implementation of
Xgrep, which prints lines matching a regular expression.
XThe command syntax is UNIX-like, not VMS-like.
X.sk
XGrep searches the files listed in the arguments (or SYS$INPUT: if no files
Xare given) for all lines that contain a match for
Xthe given expression.  If any lines match, they are printed.
X.sk
XAlso, if any matches were found, grep exits with a status of 1, but if no
Xmatches found it exits with a status of 3.  This is useful for building
Xcommand procedures that use grep as a condition for, for example, the
XIF statement.
X.sk
XThe grep family also includes EGREP and FGREP.
XWhen invoked as egrep, the syntax of the expression is slightly different;
XSee the subtopic "Options".
X.sk
XWhen invoked as fgrep, the expression can consist only of a fixed string
X(regular expressions cannot be used).  Multiple search strings can be used
Xwith fgrep by creating a file containing one string per line and using
Xthe "-f" option.
X.sk
XFormat:
X.sk;.lm+1;.literal
Xgrep `5B-options`5D `5B-num`5D `5B-AB num`5D `5B`5B-e`5D expr`7C-f file`5D `
V5B"files ..."`5D
X.end literal;.lm-1
X.!--------------------------------------------------------------------------
V----
X.indent -4
X2 Options
X.literal
X-A <num>     print <num> lines of context after every matching line
X-B <num>     print <num> lines of context before every matching line
X-C           print 2 lines of context on each side of every match
X-<num>       print <num> lines of context on each side of every match
X-V           print the version number on the diagnostic output
X-b           print every match preceded by its byte offset
X-c           print a total count of matching lines only
X-e <expr>    search for <expr>; useful if <expr> begins with -
X-f <file>    search for the expression contained in file
X-h           don't display filenames on matches
X-i           ignore case difference when comparing strings
X-l           list files containing matches only
X-n           print each match preceded by its line number
X-s           run silently producing no output except error messages
X-v           print only lines that contain no matches for the <expr>
X-w           print only lines where the match is a complete word
X-x           print only lines where the match is a whole line
X.end literal
X.!--------------------------------------------------------------------------
V----
X.indent -4
X2 Regular_Expressions
X.br
XThe grep expression can include the following characters:
X.sk
X.literal
Xgrep    egrep   Explanation
X----    -----   -----------
Xc       c       a single (non-meta) character matches itself.
X.       .       matches any single character except newline.
X\?      ?       postfix operator; preceeding item is optional.
X*       *       postfix operator; preceeding item 0 or more times.
X\+      +       postfix operator; preceeding item 1 or more times.
X\`7C      `7C       infix operator; matches either argument.
X`5E       `5E       matches the empty string at the beginning of a line.
X$       $       matches the empty string at the end of a line.
X\<      \<      matches the empty string at the beginning of a word.
X\>      \>      matches the empty string at the end of a word.
X`5Bchars`5D `5Bchars`5D match any character in the given class; if the
X                first character after `5B is `5E, match any character
X                not in the given class; a range of characters may
X                be specified by "first-last"; for example, \W
X                (below) is equivalent to the class `5B`5EA-Za-z0-9`5D
X\( \)   ( )     parentheses are used to override operator precedence.
X\digit  \digit  \n matches a repeat of the text matched earlier in the
X                regexp by the subexpression inside the nth opening
X                parenthesis.
X\       \       any special character may be preceded by a backslash
X                to match it literally.
X
X(the following are for compatibility with GNU Emacs)
X
X\b      \b      matches the empty string at the edge of a word.
X\B      \B      matches the empty string if not at the edge of a word.
X\w      \w      matches word-constituent characters (letters & digits).
X\W      \W      matches characters that are not word-constituent.
X.end literal
X.sk
XOperator precedence is (highest to lowest) ?, **, and +, concatenation,
Xand finally `7C.  All other constructs are syntactically identical to
Xnormal characters.  For the truly interested, the file dfa.c describes
X(and implements) the exact grammar understood by the parser.
X.!--------------------------------------------------------------------------
V----
X.indent -4
X2 Incompatibilities
X.br
XThe following incompatibilities with UNIX grep exist:
X.br;.list 1,"o"
X.le;The context-dependent meaning of ** is not quite the same (grep only).
X.le;-b prints a byte offset instead of a block offset.
X.le;The `7Bm,nfP`7D construct of System V grep is not implemented.
X.le;Exit statuses are different from UNIX grep:
X.sk
X.literal
X        Meaning                  UNIX       VMS
X        -------                  ----       ---
X        matches found               0         1
X        no matches found            1         3
X        error                       2        44 (SS$_ABORT)
X.end literal
X.end list
X.!--------------------------------------------------------------------------
V----
X.indent -4
X2 Bugs
X.br
XGNU e?grep has been thoroughly debugged and tested over a period
Xof several years; we think it's a reliable beast or we wouldn't
Xdistribute it.  If by some fluke of the universe you discover a bug,
Xsend a detailed description (including options, regular expressions,
Xand a copy of an input file that can reproduce it) to mike@ai.mit.edu.
X.!--------------------------------------------------------------------------
V----
X.indent -4
X2 Availability
X.br
XGNU grep is free; anyone may redistribute copies of grep to anyone under the
Xterms stated in the  GNU General Public License, a copy of which may be foun
Vd in
Xeach copy of  "GNU Emacs". See also the comment at the beginning of the sour
Vce
Xcode file grep.c.
X.sk
XCopies of GNU grep may sometimes be received packaged with distributions of
V Unix
Xsystems, but it is never included in the scope of any license covering those
Xsystems.  Such inclusion violates the terms on which distribution is permitt
Ved.`20
XIn fact, the primary purpose of the General Public License is to prohibit an
Vyone
Xfrom attaching any other restrictions to redistribution of any of the Free
XSoftware Foundation programs.
X.!--------------------------------------------------------------------------
V----
X.indent-4
X2 Authors
X.br
XMike Haertel wrote the deterministic regexp code and the bulk
Xof the program.  Mike also wrote fgrep.
X.sk
XJames A. Woods is responsible for the hybridized search strategy
Xof using Boyer-Moore-Gosper fixed-string search as a filter
Xbefore calling the general regexp matcher.
X.sk
+-+-+-+-+-+-+-+-  END  OF PART 2 +-+-+-+-+-+-+-+-
