mirror of
https://github.com/freebsd/freebsd-src
synced 2024-11-05 18:22:52 +00:00
Merge FreeBSD changes into 2.4d.
This commit is contained in:
parent
7e1d495350
commit
73d1eabc26
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=56920
3 changed files with 210 additions and 237 deletions
|
@ -13,93 +13,39 @@
|
|||
.de Id
|
||||
.ds Dt \\$4
|
||||
..
|
||||
.Id $Id: grep.1,v 1.8 2000/01/17 00:55:06 alainm Exp $
|
||||
.Id $Id: grep.1,v 1.9 2000/01/26 03:42:16 alainm Exp $
|
||||
.TH GREP 1 \*(Dt "GNU Project"
|
||||
.SH NAME
|
||||
grep, egrep, fgrep, zgrep \- print lines matching a pattern
|
||||
.SH SYNOPSIS
|
||||
.B grep
|
||||
.RB [ \- [ ABC ]
|
||||
.IR NUM ]
|
||||
.RB [ \-EFGHLUVZabchilnqrsuvwxyz ]
|
||||
.RI [ options ]
|
||||
.I PATTERN
|
||||
.RI [ FILE .\|.\|.]
|
||||
.br
|
||||
.B grep
|
||||
.RI [ options ]
|
||||
.RB [ \-e
|
||||
.I PATTERN
|
||||
|
|
||||
.B \-f
|
||||
.IR FILE ]
|
||||
.RB [ \-d
|
||||
.IR ACTION ]
|
||||
.RB [ \-\^\-binary-files=\fITYPE\fP ]
|
||||
.RB [ \-\^\-directories=\fIACTION\fP ]
|
||||
.RB [ \-\^\-extended-regexp ]
|
||||
.RB [ \-\^\-fixed-strings ]
|
||||
.RB [ \-\^\-basic-regexp ]
|
||||
.RB [ \-\^\-regexp=\fIPATTERN\fP ]
|
||||
.RB [ \-\^\-file=\fIFILE\fP ]
|
||||
.RB [ \-\^\-ignore-case ]
|
||||
.RB [ \-\^\-word-regexp ]
|
||||
.RB [ \-\^\-line-regexp ]
|
||||
.RB [ \-\^\-line-regexp ]
|
||||
.RB [ \-\^\-no-messages ]
|
||||
.RB [ \-\^\-invert-match ]
|
||||
.RB [ \-\^\-version ]
|
||||
.RB [ \-\^\-help ]
|
||||
.RB [ \-\^\-byte-offset ]
|
||||
.RB [ \-\^\-line-number ]
|
||||
.RB [ \-\^\-with-filename ]
|
||||
.RB [ \-\^\-no-filename ]
|
||||
.RB [ \-\^\-quiet ]
|
||||
.RB [ \-\^\-silent ]
|
||||
.RB [ \-\^\-text ]
|
||||
.RB [ \-\^\-files-without-match ]
|
||||
.RB [ \-\^\-files-with-matches ]
|
||||
.RB [ \-\^\-count ]
|
||||
.RB [ \-\^\-before-context=\fINUM\fP ]
|
||||
.RB [ \-\^\-after-context=\fINUM\fP ]
|
||||
.RB [ \-\^\-context [ =\fINUM\fP ]]
|
||||
.RB [ \-\^\-binary ]
|
||||
.RB [ \-\^\-unix-byte-offsets ]
|
||||
.RB [ \-\^\-mmap ]
|
||||
.RB [ \-\^\-null ]
|
||||
.RB [ \-\^\-recursive ]
|
||||
.RB [ \-\^\-decompress ]
|
||||
.RI [ file .\|.\|.]
|
||||
.RI [ FILE .\|.\|.]
|
||||
.SH DESCRIPTION
|
||||
.PP
|
||||
.B grep
|
||||
searches the named input
|
||||
.I files
|
||||
.IR FILE s
|
||||
(or standard input if no files are named, or
|
||||
the file name
|
||||
.B \-
|
||||
is given)
|
||||
for lines containing a match to the given
|
||||
.IR pattern .
|
||||
.IR PATTERN .
|
||||
By default,
|
||||
.B grep
|
||||
prints the matching lines.
|
||||
.PP
|
||||
There are three major variants of
|
||||
.BR grep ,
|
||||
controlled by the following options.
|
||||
.PD 0
|
||||
.TP
|
||||
.BR \-G ", " \-\^\-basic-regexp
|
||||
Interpret
|
||||
.I pattern
|
||||
as a basic regular expression (see below). This is the default.
|
||||
.TP
|
||||
.BR \-E ", " \-\^\-extended-regexp
|
||||
Interpret
|
||||
.I pattern
|
||||
as an extended regular expression (see below).
|
||||
.TP
|
||||
.BR \-F ", " \-\^\-fixed-strings
|
||||
Interpret
|
||||
.I pattern
|
||||
as a list of fixed strings, separated by newlines,
|
||||
any of which is to be matched.
|
||||
.PP
|
||||
In addition, two variant programs
|
||||
.B egrep
|
||||
and
|
||||
|
@ -114,40 +60,31 @@ is the same as
|
|||
.B zgrep
|
||||
is the same as
|
||||
.BR "grep\ \-Z" .
|
||||
.PD
|
||||
.PP
|
||||
All variants of
|
||||
.B grep
|
||||
understand the following options:
|
||||
.PD 0
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.BI \-A " NUM" "\fR,\fP \-\^\-after-context=" NUM
|
||||
Print
|
||||
.I NUM
|
||||
lines of trailing context after matching lines.
|
||||
.TP
|
||||
.BR \-a ", " \-\^\-text
|
||||
Process a binary file as if it were text; this is equivalent to the
|
||||
.B \-\^\-binary-files=text
|
||||
option.
|
||||
.TP
|
||||
.BI \-B " NUM" "\fR,\fP \-\^\-before-context=" NUM
|
||||
Print
|
||||
.I NUM
|
||||
lines of leading context before matching lines.
|
||||
.TP
|
||||
.BI \-C " \fR[\fPNUM\fR]\fP" "\fR,\fP \-\^\-context\fR[\fP=" NUM\fR]\fP
|
||||
\fB\-C\fP [\fINUM\fP], \fB\-\fP\fINUM\fP, \fB\-\^\-context\fP[\fB=\fP\fINUM\fP]
|
||||
Print
|
||||
.I NUM
|
||||
lines (default 2) of output context.
|
||||
.TP
|
||||
.BI \- NUM
|
||||
Same as
|
||||
.BI \-\^\-context= NUM
|
||||
lines of leading and trailing context. However,
|
||||
.B grep
|
||||
will never print any given line more than once.
|
||||
.TP
|
||||
.BR \-V ", " \-\^\-version
|
||||
Print the version number of
|
||||
.B grep
|
||||
to standard error. This version number should
|
||||
be included in all bug reports (see below).
|
||||
.BR \-b ", " \-\^\-byte-offset
|
||||
Print the byte offset within the input file before
|
||||
each line of output.
|
||||
.TP
|
||||
.BI \-\^\-binary-files= TYPE
|
||||
If the first few bytes of a file indicate that the file contains binary
|
||||
|
@ -167,7 +104,9 @@ If
|
|||
is
|
||||
.BR without-match ,
|
||||
.B grep
|
||||
assumes that a binary file does not match.
|
||||
assumes that a binary file does not match; this is equivalent to the
|
||||
.B \-I
|
||||
option.
|
||||
If
|
||||
.I TYPE
|
||||
is
|
||||
|
@ -175,8 +114,6 @@ is
|
|||
.B grep
|
||||
processes a binary file as if it were text; this is equivalent to the
|
||||
.B \-a
|
||||
or
|
||||
.B \-\^\-text
|
||||
option.
|
||||
.I Warning:
|
||||
.B "grep \-\^\-binary-files=text"
|
||||
|
@ -184,10 +121,6 @@ might output binary garbage,
|
|||
which can have nasty side effects if the output is a terminal and if the
|
||||
terminal driver interprets some of it as commands.
|
||||
.TP
|
||||
.BR \-b ", " \-\^\-byte-offset
|
||||
Print the byte offset within the input file before
|
||||
each line of output.
|
||||
.TP
|
||||
.BR \-c ", " \-\^\-count
|
||||
Suppress normal output; instead print a count of
|
||||
matching lines for each input file.
|
||||
|
@ -218,18 +151,34 @@ this is equivalent to the
|
|||
.B \-r
|
||||
option.
|
||||
.TP
|
||||
.BR \-E ", " \-\^\-extended-regexp
|
||||
Interpret
|
||||
.I PATTERN
|
||||
as an extended regular expression (see below).
|
||||
.TP
|
||||
.BI \-e " PATTERN" "\fR,\fP \-\^\-regexp=" PATTERN
|
||||
Use
|
||||
.I PATTERN
|
||||
as the pattern; useful to protect patterns beginning with
|
||||
.BR \- .
|
||||
.TP
|
||||
.BR \-F ", " \-\^\-fixed-strings
|
||||
Interpret
|
||||
.I PATTERN
|
||||
as a list of fixed strings, separated by newlines,
|
||||
any of which is to be matched.
|
||||
.TP
|
||||
.BI \-f " FILE" "\fR,\fP \-\^\-file=" FILE
|
||||
Obtain patterns from
|
||||
.IR FILE ,
|
||||
one per line.
|
||||
The empty file contains zero patterns, and therfore matches nothing.
|
||||
.TP
|
||||
.BR \-G ", " \-\^\-basic-regexp
|
||||
Interpret
|
||||
.I PATTERN
|
||||
as a basic regular expression (see below). This is the default.
|
||||
.TP
|
||||
.BR \-H ", " \-\^\-with-filename
|
||||
Print the filename for each match.
|
||||
.TP
|
||||
|
@ -237,9 +186,18 @@ Print the filename for each match.
|
|||
Suppress the prefixing of filenames on output
|
||||
when multiple files are searched.
|
||||
.TP
|
||||
.B \-\^\-help
|
||||
Output a brief help message.
|
||||
.TP
|
||||
.BR \-I
|
||||
Process a binary file as if it did not contain matching data; this is
|
||||
equivalent to the
|
||||
.B \-\^\-binary-files=without-match
|
||||
option.
|
||||
.TP
|
||||
.BR \-i ", " \-\^\-ignore-case
|
||||
Ignore case distinctions in both the
|
||||
.I pattern
|
||||
.I PATTERN
|
||||
and the input files.
|
||||
.TP
|
||||
.BR \-L ", " \-\^\-files-without-match
|
||||
|
@ -254,6 +212,21 @@ the name of each input file from which output
|
|||
would normally have been printed. The scanning will
|
||||
stop on the first match.
|
||||
.TP
|
||||
.B \-\^\-mmap
|
||||
If possible, use the
|
||||
.BR mmap (2)
|
||||
system call to read input, instead of
|
||||
the default
|
||||
.BR read (2)
|
||||
system call. In some situations,
|
||||
.B \-\^\-mmap
|
||||
yields better performance. However,
|
||||
.B \-\^\-mmap
|
||||
can cause undefined behavior (including core dumps)
|
||||
if an input file shrinks while
|
||||
.B grep
|
||||
is operating, or if an I/O error occurs.
|
||||
.TP
|
||||
.BR \-n ", " \-\^\-line-number
|
||||
Prefix each line of output with the line number
|
||||
within its input file.
|
||||
|
@ -297,29 +270,6 @@ and
|
|||
.B \-s
|
||||
and should redirect output to /dev/null instead.
|
||||
.TP
|
||||
.BR \-a ", " \-\^\-text
|
||||
Process a binary file as if it were text; this is equivalent to the
|
||||
.B \-\^\-binary-files=text
|
||||
option.
|
||||
.TP
|
||||
.BR \-v ", " \-\^\-invert-match
|
||||
Invert the sense of matching, to select non-matching lines.
|
||||
.TP
|
||||
.BR \-w ", " \-\^\-word-regexp
|
||||
Select only those lines containing matches that form whole words.
|
||||
The test is that the matching substring must either be at the
|
||||
beginning of the line, or preceded by a non-word constituent
|
||||
character. Similarly, it must be either at the end of the line
|
||||
or followed by a non-word constituent character. Word-constituent
|
||||
characters are letters, digits, and the underscore.
|
||||
.TP
|
||||
.BR \-x ", " \-\^\-line-regexp
|
||||
Select only those matches that exactly match the whole line.
|
||||
.TP
|
||||
.B \-y
|
||||
Obsolete synonym for
|
||||
.BR \-i .
|
||||
.TP
|
||||
.BR \-U ", " \-\^\-binary
|
||||
Treat the file(s) as binary. By default, under MS-DOS and MS-Windows,
|
||||
.BR grep
|
||||
|
@ -351,20 +301,29 @@ on a Unix machine. This option has no effect unless
|
|||
option is also used;
|
||||
it has no effect on platforms other than MS-DOS and MS-Windows.
|
||||
.TP
|
||||
.B \-\^\-mmap
|
||||
If possible, use the
|
||||
.BR mmap (2)
|
||||
system call to read input, instead of
|
||||
the default
|
||||
.BR read (2)
|
||||
system call. In some situations,
|
||||
.B \-\^\-mmap
|
||||
yields better performance. However,
|
||||
.B \-\^\-mmap
|
||||
can cause undefined behavior (including core dumps)
|
||||
if an input file shrinks while
|
||||
.BR \-V ", " \-\^\-version
|
||||
Print the version number of
|
||||
.B grep
|
||||
is operating, or if an I/O error occurs.
|
||||
to standard error. This version number should
|
||||
be included in all bug reports (see below).
|
||||
.TP
|
||||
.BR \-v ", " \-\^\-invert-match
|
||||
Invert the sense of matching, to select non-matching lines.
|
||||
.TP
|
||||
.BR \-w ", " \-\^\-word-regexp
|
||||
Select only those lines containing matches that form whole words.
|
||||
The test is that the matching substring must either be at the
|
||||
beginning of the line, or preceded by a non-word constituent
|
||||
character. Similarly, it must be either at the end of the line
|
||||
or followed by a non-word constituent character. Word-constituent
|
||||
characters are letters, digits, and the underscore.
|
||||
.TP
|
||||
.BR \-x ", " \-\^\-line-regexp
|
||||
Select only those matches that exactly match the whole line.
|
||||
.TP
|
||||
.B \-y
|
||||
Obsolete synonym for
|
||||
.BR \-i .
|
||||
.TP
|
||||
.BR \-Z ", " \-\^\-null
|
||||
Output a zero byte (the \s-1ASCII\s0
|
||||
|
@ -383,14 +342,10 @@ and
|
|||
.B "xargs \-0"
|
||||
to process arbitrary file names,
|
||||
even those that contain newline characters.
|
||||
.PD
|
||||
.LP
|
||||
Following option is only available if compiled with zlib(3) library:
|
||||
.PD 0
|
||||
.TP
|
||||
.B \-Z, --decompress
|
||||
.BR \-Z ", " \-\^\-decompress
|
||||
Decompress the input data before searching.
|
||||
.PD
|
||||
This option is only available if compiled with zlib(3) library.
|
||||
.SH "REGULAR EXPRESSIONS"
|
||||
.PP
|
||||
A regular expression is a pattern that describes a set of strings.
|
||||
|
@ -424,7 +379,7 @@ then it matches any character
|
|||
in the list.
|
||||
For example, the regular expression
|
||||
.B [0123456789]
|
||||
matches any single digit. A range of ASCII characters
|
||||
matches any single digit. A range of characters
|
||||
may be specified by giving the first and last characters, separated
|
||||
by a hyphen.
|
||||
Finally, certain named classes of characters are predefined.
|
||||
|
@ -445,8 +400,9 @@ For example,
|
|||
.B [[:alnum:]]
|
||||
means
|
||||
.BR [0-9A-Za-z] ,
|
||||
except the latter form is dependent upon the ASCII character encoding,
|
||||
whereas the former is portable.
|
||||
except the latter form depends upon the \s-1POSIX\s0 locale and the
|
||||
\s-1ASCII\s0 character encoding, whereas the former is independent
|
||||
of locale and character set.
|
||||
(Note that the brackets in these class names are part of the symbolic
|
||||
names, and must be included in addition to the brackets delimiting
|
||||
the bracket list.) Most metacharacters lose their special meaning
|
||||
|
@ -590,14 +546,84 @@ searches for the two-character string
|
|||
instead of reporting a syntax error in the regular expression.
|
||||
\s-1POSIX.2\s0 allows this behavior as an extension, but portable scripts
|
||||
should avoid it.
|
||||
.SH ENVIRONMENT
|
||||
The environment variable
|
||||
.SH "ENVIRONMENT VARIABLES"
|
||||
.TP
|
||||
.B GREP_OPTIONS
|
||||
can hold a set of default
|
||||
options for
|
||||
.I grep.
|
||||
These options are interpreted first and can be overwritten by explicit command
|
||||
line parameters.
|
||||
This variable specifies default options to be placed in front of any
|
||||
explicit options. For example, if
|
||||
.B GREP_OPTIONS
|
||||
is
|
||||
.BR "'\-\^\-binary-files=without-match \-\^\-directories=skip'" ,
|
||||
.B grep
|
||||
behaves as if the two options
|
||||
.B \-\^\-binary-files=without-match
|
||||
and
|
||||
.B \-\^\-directories=skip
|
||||
had been specified before any explicit options.
|
||||
Option specifications are separated by whitespace.
|
||||
A backslash escapes the next character,
|
||||
so it can be used to specify an option containing whitespace or a backslash.
|
||||
.TP
|
||||
\fBLC_ALL\fP, \fBLC_MESSAGES\fP, \fBLANG\fP
|
||||
These variables specify the
|
||||
.B LC_MESSAGES
|
||||
locale, which determines the language that
|
||||
.B grep
|
||||
uses for messages.
|
||||
The locale is determined by the first of these variables that is set.
|
||||
American English is used if none of these environment variables are set,
|
||||
or if the message catalog is not installed, or if
|
||||
.B grep
|
||||
was not compiled with national language support (\s-1NLS\s0).
|
||||
.TP
|
||||
\fBLC_ALL\fP, \fBLC_CTYPE\fP, \fBLANG\fP
|
||||
These variables specify the
|
||||
.B LC_CTYPE
|
||||
locale, which determines the type of characters, e.g., which
|
||||
characters are whitespace.
|
||||
The locale is determined by the first of these variables that is set.
|
||||
The \s-1POSIX\s0 locale is used if none of these environment variables
|
||||
are set, or if the locale catalog is not installed, or if
|
||||
.B grep
|
||||
was not compiled with national language support (\s-1NLS\s0).
|
||||
.TP
|
||||
.B POSIXLY_CORRECT
|
||||
If set,
|
||||
.B grep
|
||||
behaves as \s-1POSIX.2\s0 requires; otherwise,
|
||||
.B grep
|
||||
behaves more like other \s-1GNU\s0 programs.
|
||||
\s-1POSIX.2\s0 requires that options that follow file names must be
|
||||
treated as file names; by default, such options are permuted to the
|
||||
front of the operand list and are treated as options.
|
||||
Also, \s-1POSIX.2\s0 requires that unrecognized options be diagnosed as
|
||||
\*(lqillegal\*(rq, but since they are not really against the law the default
|
||||
is to diagnose them as \*(lqinvalid\*(rq.
|
||||
.B POSIXLY_CORRECT
|
||||
also disables \fB_\fP\fIN\fP\fB_GNU_nonoption_argv_flags_\fP,
|
||||
described below.
|
||||
.TP
|
||||
\fB_\fP\fIN\fP\fB_GNU_nonoption_argv_flags_\fP
|
||||
(Here
|
||||
.I N
|
||||
is
|
||||
.BR grep 's
|
||||
numeric process ID.) If the
|
||||
.IR i th
|
||||
character of this environment variable's value is
|
||||
.BR 1 ,
|
||||
do not consider the
|
||||
.IR i th
|
||||
operand of
|
||||
.B grep
|
||||
to be an option, even if it appears to be one.
|
||||
A shell can put this variable in the environment for each command it runs,
|
||||
specifying which operands are the results of file name wildcard
|
||||
expansion and therefore should not be treated as options.
|
||||
This behavior is available only with the \s-1GNU\s0 C library, and only
|
||||
when
|
||||
.B POSIXLY_CORRECT
|
||||
is not set.
|
||||
.SH DIAGNOSTICS
|
||||
.PP
|
||||
Normally, exit status is 0 if matches were found,
|
||||
|
|
|
@ -66,7 +66,7 @@ static int filename_mask;
|
|||
|
||||
/* Short options. */
|
||||
static char const short_options[] =
|
||||
"0123456789A:B:C::EFGHUVX:abcd:e:f:hiLlnqrsuvwxyZz";
|
||||
"0123456789A:B:C::EFGHIUVX:abcd:e:f:hiLlnqrsuvwxyZz";
|
||||
|
||||
/* Non-boolean long options that have no corresponding short equivalents. */
|
||||
enum
|
||||
|
@ -169,9 +169,7 @@ static char *(*execute) PARAMS ((char *, size_t, char **));
|
|||
/* Print a message and possibly an error string. Remember
|
||||
that something awful happened. */
|
||||
static void
|
||||
error (mesg, errnum)
|
||||
const char *mesg;
|
||||
int errnum;
|
||||
error (const char *mesg, int errnum)
|
||||
{
|
||||
if (errnum)
|
||||
fprintf (stderr, "%s: %s: %s\n", prog, mesg, strerror (errnum));
|
||||
|
@ -182,9 +180,7 @@ error (mesg, errnum)
|
|||
|
||||
/* Like error (), but die horribly after printing. */
|
||||
void
|
||||
fatal (mesg, errnum)
|
||||
const char *mesg;
|
||||
int errnum;
|
||||
fatal (const char *mesg, int errnum)
|
||||
{
|
||||
error (mesg, errnum);
|
||||
exit (2);
|
||||
|
@ -192,8 +188,7 @@ fatal (mesg, errnum)
|
|||
|
||||
/* Interface to handle errors and fix library lossage. */
|
||||
char *
|
||||
xmalloc (size)
|
||||
size_t size;
|
||||
xmalloc (size_t size)
|
||||
{
|
||||
char *result;
|
||||
|
||||
|
@ -205,9 +200,7 @@ xmalloc (size)
|
|||
|
||||
/* Interface to handle errors and fix some library lossage. */
|
||||
char *
|
||||
xrealloc (ptr, size)
|
||||
char *ptr;
|
||||
size_t size;
|
||||
xrealloc (char *ptr, size_t size)
|
||||
{
|
||||
char *result;
|
||||
|
||||
|
@ -223,9 +216,7 @@ xrealloc (ptr, size)
|
|||
/* Convert STR to a positive integer, storing the result in *OUT.
|
||||
If STR is not a valid integer, return -1 (otherwise 0). */
|
||||
static int
|
||||
ck_atoi (str, out)
|
||||
char const *str;
|
||||
int *out;
|
||||
ck_atoi (char const *str, int *out)
|
||||
{
|
||||
char const *p;
|
||||
for (p = str; *p; p++)
|
||||
|
@ -275,9 +266,7 @@ static int Zflag; /* uncompress before searching. */
|
|||
possibly unaligned) buffer used to build the aligned buffer. To
|
||||
free the buffer, free (*UP). */
|
||||
static char *
|
||||
page_alloc (size, up)
|
||||
size_t size;
|
||||
char **up;
|
||||
page_alloc (size_t size, char **up)
|
||||
{
|
||||
size_t asize = size + pagesize - 1;
|
||||
if (size <= asize)
|
||||
|
@ -295,10 +284,7 @@ page_alloc (size, up)
|
|||
/* Reset the buffer for a new file, returning zero if we should skip it.
|
||||
Initialize on the first time through. */
|
||||
static int
|
||||
reset (fd, file, stats)
|
||||
int fd;
|
||||
char const *file;
|
||||
struct stats *stats;
|
||||
reset (int fd, char const *file, struct stats *stats)
|
||||
{
|
||||
if (pagesize)
|
||||
bufsalloc = ALIGN_TO (bufalloc / PREFERRED_SAVE_FACTOR, pagesize);
|
||||
|
@ -379,9 +365,7 @@ reset (fd, file, stats)
|
|||
to the beginning of the buffer contents, and 'buflim'
|
||||
points just after the end. Return zero if there's an error. */
|
||||
static int
|
||||
fillbuf (save, stats)
|
||||
size_t save;
|
||||
struct stats *stats;
|
||||
fillbuf (size_t save, struct stats *stats)
|
||||
{
|
||||
size_t fillsize = 0;
|
||||
int cc = 1;
|
||||
|
@ -551,8 +535,7 @@ static int done_on_match; /* Stop scanning file on first match */
|
|||
#endif
|
||||
|
||||
static void
|
||||
nlscan (lim)
|
||||
char *lim;
|
||||
nlscan (char *lim)
|
||||
{
|
||||
char *beg;
|
||||
for (beg = lastnl; (beg = memchr (beg, eolbyte, lim - beg)); beg++)
|
||||
|
@ -561,9 +544,7 @@ nlscan (lim)
|
|||
}
|
||||
|
||||
static void
|
||||
print_offset_sep (pos, sep)
|
||||
off_t pos;
|
||||
int sep;
|
||||
print_offset_sep (off_t pos, int sep)
|
||||
{
|
||||
/* Do not rely on printf to print pos, since off_t may be longer than long,
|
||||
and long long is not portable. */
|
||||
|
@ -580,10 +561,7 @@ print_offset_sep (pos, sep)
|
|||
}
|
||||
|
||||
static void
|
||||
prline (beg, lim, sep)
|
||||
char *beg;
|
||||
char *lim;
|
||||
int sep;
|
||||
prline (char *beg, char *lim, int sep)
|
||||
{
|
||||
if (out_file)
|
||||
printf ("%s%c", filename, sep & filename_mask);
|
||||
|
@ -609,8 +587,7 @@ prline (beg, lim, sep)
|
|||
|
||||
/* Print pending lines of trailing context prior to LIM. */
|
||||
static void
|
||||
prpending (lim)
|
||||
char *lim;
|
||||
prpending (char *lim)
|
||||
{
|
||||
char *nl;
|
||||
|
||||
|
@ -630,10 +607,7 @@ prpending (lim)
|
|||
/* Print the lines between BEG and LIM. Deal with context crap.
|
||||
If NLINESP is non-null, store a count of lines between BEG and LIM. */
|
||||
static void
|
||||
prtext (beg, lim, nlinesp)
|
||||
char *beg;
|
||||
char *lim;
|
||||
int *nlinesp;
|
||||
prtext (char *beg, char *lim, int *nlinesp)
|
||||
{
|
||||
static int used; /* avoid printing "--" before any output */
|
||||
char *bp, *p, *nl;
|
||||
|
@ -696,9 +670,7 @@ prtext (beg, lim, nlinesp)
|
|||
between matching lines if OUT_INVERT is true). Return a count of
|
||||
lines printed. */
|
||||
static int
|
||||
grepbuf (beg, lim)
|
||||
char *beg;
|
||||
char *lim;
|
||||
grepbuf (char *beg, char *lim)
|
||||
{
|
||||
int nlines, n;
|
||||
register char *p, *b;
|
||||
|
@ -738,10 +710,7 @@ grepbuf (beg, lim)
|
|||
but if the file is a directory and we search it recursively, then
|
||||
return -2 if there was a match, and -1 otherwise. */
|
||||
static int
|
||||
grep (fd, file, stats)
|
||||
int fd;
|
||||
char const *file;
|
||||
struct stats *stats;
|
||||
grep (int fd, char const *file, struct stats *stats)
|
||||
{
|
||||
int nlines, i;
|
||||
int not_text;
|
||||
|
@ -834,6 +803,7 @@ grep (fd, file, stats)
|
|||
}
|
||||
if (residue)
|
||||
{
|
||||
*buflim++ = eol;
|
||||
nlines += grepbuf (bufbeg + save - residue, buflim);
|
||||
if (pending)
|
||||
prpending (buflim);
|
||||
|
@ -848,9 +818,7 @@ grep (fd, file, stats)
|
|||
}
|
||||
|
||||
static int
|
||||
grepfile (file, stats)
|
||||
char const *file;
|
||||
struct stats *stats;
|
||||
grepfile (char const *file, struct stats *stats)
|
||||
{
|
||||
int desc;
|
||||
int count;
|
||||
|
@ -949,9 +917,7 @@ grepfile (file, stats)
|
|||
}
|
||||
|
||||
static int
|
||||
grepdir (dir, stats)
|
||||
char const *dir;
|
||||
struct stats *stats;
|
||||
grepdir (char const *dir, struct stats *stats)
|
||||
{
|
||||
int status = 1;
|
||||
struct stats *ancestor;
|
||||
|
@ -1009,8 +975,7 @@ grepdir (dir, stats)
|
|||
}
|
||||
|
||||
static void
|
||||
usage(status)
|
||||
int status;
|
||||
usage (int status)
|
||||
{
|
||||
if (status != 0)
|
||||
{
|
||||
|
@ -1022,7 +987,7 @@ int status;
|
|||
printf (_("Usage: %s [OPTION]... PATTERN [FILE] ...\n"), prog);
|
||||
printf (_("\
|
||||
Search for PATTERN in each FILE or standard input.\n\
|
||||
Example: %s -i 'hello.*world' menu.h main.c\n\
|
||||
Example: %s -i 'hello world' menu.h main.c\n\
|
||||
\n\
|
||||
Regexp selection and interpretation:\n"), prog);
|
||||
printf (_("\
|
||||
|
@ -1053,9 +1018,10 @@ Output control:\n\
|
|||
-H, --with-filename print the filename for each match\n\
|
||||
-h, --no-filename suppress the prefixing filename on output\n\
|
||||
-q, --quiet, --silent suppress all normal output\n\
|
||||
-a, --text equivalent to --binary-files=text\n\
|
||||
--binary-files=TYPE assume that binary files are TYPE\n\
|
||||
TYPE is 'binary', 'text', or 'without-match'.\n\
|
||||
-a, --text equivalent to --binary-files=text\n\
|
||||
-I equivalent to --binary-files=without-match\n\
|
||||
-d, --directories=ACTION how to handle directories\n\
|
||||
ACTION is 'read', 'recurse', or 'skip'.\n\
|
||||
-r, --recursive equivalent to --directories=recurse.\n\
|
||||
|
@ -1085,8 +1051,7 @@ and 2 if trouble.\n"));
|
|||
|
||||
/* Set the matcher to M, reporting any conflicts. */
|
||||
static void
|
||||
setmatcher (m)
|
||||
char const *m;
|
||||
setmatcher (char const *m)
|
||||
{
|
||||
if (matcher && strcmp (matcher, m) != 0)
|
||||
fatal (_("conflicting matchers specified"), 0);
|
||||
|
@ -1096,8 +1061,7 @@ setmatcher (m)
|
|||
/* Go through the matchers vector and look for the specified matcher.
|
||||
If we find it, install it in compile and execute, and return 1. */
|
||||
static int
|
||||
install_matcher (name)
|
||||
char const *name;
|
||||
install_matcher (char const *name)
|
||||
{
|
||||
int i;
|
||||
#ifdef HAVE_SETRLIMIT
|
||||
|
@ -1145,10 +1109,7 @@ install_matcher (name)
|
|||
Do not set ARGV[N] to NULL. If ARGV is NULL, do not store ARGV[0]
|
||||
etc. Backslash can be used to escape whitespace (and backslashes). */
|
||||
static int
|
||||
prepend_args (options, buf, argv)
|
||||
char const *options;
|
||||
char *buf;
|
||||
char **argv;
|
||||
prepend_args (char const *options, char *buf, char **argv)
|
||||
{
|
||||
char const *o = options;
|
||||
char *b = buf;
|
||||
|
@ -1177,10 +1138,7 @@ prepend_args (options, buf, argv)
|
|||
vector of a main program with argument count *PARGC and argument
|
||||
vector *PARGV. */
|
||||
static void
|
||||
prepend_default_options (options, pargc, pargv)
|
||||
char const *options;
|
||||
int *pargc;
|
||||
char ***pargv;
|
||||
prepend_default_options (char const *options, int *pargc, char ***pargv)
|
||||
{
|
||||
if (options)
|
||||
{
|
||||
|
@ -1199,15 +1157,14 @@ prepend_default_options (options, pargc, pargv)
|
|||
}
|
||||
|
||||
int
|
||||
main (argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
char *keys;
|
||||
size_t keycc, oldcc, keyalloc;
|
||||
int with_filenames;
|
||||
int opt, cc, status;
|
||||
unsigned digit_args_val, default_context;
|
||||
int default_context;
|
||||
unsigned digit_args_val;
|
||||
FILE *fp;
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
|
@ -1328,6 +1285,9 @@ main (argc, argv)
|
|||
case 'H':
|
||||
with_filenames = 1;
|
||||
break;
|
||||
case 'I':
|
||||
binary_files = WITHOUT_MATCH_BINARY_FILES;
|
||||
break;
|
||||
case 'U':
|
||||
#if O_BINARY
|
||||
dos_use_file_type = DOS_BINARY;
|
||||
|
|
|
@ -73,14 +73,13 @@ static kwset_t kwset;
|
|||
static int lastexact;
|
||||
|
||||
void
|
||||
dfaerror(mesg)
|
||||
const char *mesg;
|
||||
dfaerror (char const *mesg)
|
||||
{
|
||||
fatal(mesg, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
kwsinit()
|
||||
kwsinit (void)
|
||||
{
|
||||
static char trans[NCHAR];
|
||||
int i;
|
||||
|
@ -98,7 +97,7 @@ kwsinit()
|
|||
to find those strings, and thus quickly filter out impossible
|
||||
matches. */
|
||||
static void
|
||||
kwsmusts()
|
||||
kwsmusts (void)
|
||||
{
|
||||
struct dfamust *dm;
|
||||
char *err;
|
||||
|
@ -132,9 +131,7 @@ kwsmusts()
|
|||
}
|
||||
|
||||
static void
|
||||
Gcompile(pattern, size)
|
||||
char *pattern;
|
||||
size_t size;
|
||||
Gcompile (char *pattern, size_t size)
|
||||
{
|
||||
const char *err;
|
||||
|
||||
|
@ -186,9 +183,7 @@ Gcompile(pattern, size)
|
|||
}
|
||||
|
||||
static void
|
||||
Ecompile(pattern, size)
|
||||
char *pattern;
|
||||
size_t size;
|
||||
Ecompile (char *pattern, size_t size)
|
||||
{
|
||||
const char *err;
|
||||
|
||||
|
@ -248,10 +243,7 @@ Ecompile(pattern, size)
|
|||
}
|
||||
|
||||
static char *
|
||||
EGexecute(buf, size, endp)
|
||||
char *buf;
|
||||
size_t size;
|
||||
char **endp;
|
||||
EGexecute (char *buf, size_t size, char **endp)
|
||||
{
|
||||
register char *buflim, *beg, *end, save;
|
||||
char eol = eolbyte;
|
||||
|
@ -361,9 +353,7 @@ EGexecute(buf, size, endp)
|
|||
}
|
||||
|
||||
static void
|
||||
Fcompile(pattern, size)
|
||||
char *pattern;
|
||||
size_t size;
|
||||
Fcompile (char *pattern, size_t size)
|
||||
{
|
||||
char *beg, *lim, *err;
|
||||
|
||||
|
@ -386,10 +376,7 @@ Fcompile(pattern, size)
|
|||
}
|
||||
|
||||
static char *
|
||||
Fexecute(buf, size, endp)
|
||||
char *buf;
|
||||
size_t size;
|
||||
char **endp;
|
||||
Fexecute (char *buf, size_t size, char **endp)
|
||||
{
|
||||
register char *beg, *try, *end;
|
||||
register size_t len;
|
||||
|
|
Loading…
Reference in a new issue