diff --git a/gnu/usr.bin/grep/ChangeLog b/gnu/usr.bin/grep/ChangeLog index 81065280d9df..1e279c347da0 100644 --- a/gnu/usr.bin/grep/ChangeLog +++ b/gnu/usr.bin/grep/ChangeLog @@ -1,3 +1,107 @@ +2000-01-28 Alain Magloire + + * src/grep.c (usage): The example "%s -i 'hello.*world' could + lead to confusion when progname is 'fgrep. + Noted by Akim Demaille. + + * configure.in: Reenable, jm_INCLUDE_REGEX() since we now + track GNU lib C. + * src/Makefile.am: EXTRA_DIST new macros with regex.c regex.h. + Requested By Ulrich Drepper. + +2000-01-25 Paul Eggert + + * src/grep.c (grep): If the final byte of an input file is not + a newline, grep now silently supplies one. + * doc/grep.texi, NEWS: Likewise. + +2000-01-25 Paul Eggert + + * NEWS, doc/grep.1, doc/grep.texi: Add -I option. + * src/grep.c (short_options, usage, main): Likewise. + + * doc/grep.texi: Fix some incorrect references to ASCII. + +2000-01-25 Paul Eggert + + * doc/grep.1: Simplify synopsis; sort options; mention + environment variables; clean up some minor gaffes. + +2000-01-25 Paul Eggert + + * doc/grep.texi: + Fix some errors in description of [:print:] and the like. + +2000-01-23 Paul Eggert + + * src/dfa.c (FETCH, lex): Put brackets around if-body to avoid + GCC warning about ambiguous if-then-else. + +2000-01-23 Paul Eggert + + * src/regex.c (GET_UNSIGNED_NUMBER): Allow only ASCII digits. + * src/dfa.c (ISASCIIDIGIT): New macro. + (lex): Use it instead of ISDIGIT. + +2000-01-23 Paul Eggert + + The bug is that regular expression ranges like [a-z] compare raw + byte codes to the range boundaries, whereas POSIX says that they + should use the current collating sequence instead. For example, + in Solaris 7 with LC_ALL=en_US, the command + echo x | grep '[ -~]' + outputs 'x', but it shouldn't output anything since ' ' and '~' + sort before all letters in that locale. + + * src/regex.c (compile_range): When matching a character + range, use the current collating sequence, as POSIX requires. + * src/dfa.c (lex): Likewise. + +2000-01-20 Alain Magloire + + * tests/Makefile.am (dist-hook): Added new rule to make sure + that the shell scripts have the right permissions. + * src/posix/Makefile.am (EXTRA_DIST): added regex.h in the + distribution. + * THANKS: updated. + +2000-01-18 Alain Magloire + + * Rectification the initial patch to add --binary-file option + was done by Ruslan Ermilov. + +2000-01-17 Paul Eggert + + Sync with sources of fileutils 4.0n, tar 1.13.17, glibc 2.1.3a1. + Convert to ANSI C prototypes (using ansi2knr for backwards + compatibility), as this makes it easier to sync. + + * configure.in (AC_OBJEXT): Spell in a funny way, to work around + a bug in automake 1.4 with ansi2knr. + (LIBOBJS): Add assignment so that .o files in LIBOBJS are also built + via the ANSI2KNR-filtering rules. + (AC_OUTPUT): Add src/posix/Makefile. + * src/Makefile.am (AUTOMAKE_OPTIONS): Add ansi2knr. + (SUBDIRS): New macro. + * src/ansi2knr.1, src/ansi2knr.c, src/posix/Makefile.am: New files. + * src/dfa.c, src/dosbuf.c, src/grep.c, src/kwset.c, src/search.c, + src/vms_fab.c: + Use prototypes for function definitions. + * src/grep.c (main): Use int counter for default context, + fixing an ANSI portability bug uncovered by the above changes. + + * config.guess, config.sub, install-sh, missing, src/alloca.c, + src/getpagesize.h, src/memchr.c, src/savedir.c, src/savedir.h, + src/stpcpy.c: + Upgrade to latest version from fileutils 4.0n. + + * src/getopt.c, src/getopt.h, src/getopt1.c: Upgrade to latest + version from tar 1.13.17. + + * src/obstack.c, src/obstack.h, src/regex.c, src/regex.h: + Upgrade to glibc 2.1.3 alpha 1, with K&R C portability fix. + * src/posix/regex.h: New file, from glibc 2.1.3 alpha 1. + 2000-01-04 Paul Eggert Inititial patch from David O'Brien. diff --git a/gnu/usr.bin/grep/NEWS b/gnu/usr.bin/grep/NEWS index 88701af78f01..e763647db3fb 100644 --- a/gnu/usr.bin/grep/NEWS +++ b/gnu/usr.bin/grep/NEWS @@ -1,9 +1,16 @@ +Version 2.4.1 + + - If the final byte of an input file is not a newline, grep now silently + supplies one. + - The new option --binary-files=TYPE makes grep assume that a binary input file is of type TYPE. --binary-files='binary' (the default) outputs a 1-line summary of matches. --binary-files='without-match' assumes binary files do not match. --binary-files='text' treats binary files as text - (equivalent to -a or --text). + (equivalent to the -a or --text option). + + - New option -I; equivalent to --binary-files='without-match'. Version 2.4: diff --git a/gnu/usr.bin/grep/THANKS b/gnu/usr.bin/grep/THANKS index 75ecc465838e..b0c23f9db041 100644 --- a/gnu/usr.bin/grep/THANKS +++ b/gnu/usr.bin/grep/THANKS @@ -1,5 +1,6 @@ Aharon Robbins -Alain Magloire +Akim Demaille +Alain Magloire Andreas Schwab Andreas Ley Ben Elliston @@ -34,6 +35,7 @@ Phillip C. Brisco Philippe Defert Philippe De Muyter Roland Roberts +Ruslan Ermilov Shannon Hill Sotiris Vassilopoulos Stewart Levin diff --git a/gnu/usr.bin/grep/dfa.c b/gnu/usr.bin/grep/dfa.c index 40a926b35d87..368348dc1763 100644 --- a/gnu/usr.bin/grep/dfa.c +++ b/gnu/usr.bin/grep/dfa.c @@ -77,6 +77,16 @@ extern void free(); #define ISCNTRL(C) (isascii(C) && iscntrl(C)) #endif +/* ISASCIIDIGIT differs from ISDIGIT, as follows: + - Its arg may be any int or unsigned int; it need not be an unsigned char. + - It's guaranteed to evaluate its argument exactly once. + - It's typically faster. + Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that + only '0' through '9' are digits. Prefer ISASCIIDIGIT to ISDIGIT unless + it's important to use the locale's definition of `digit' even when the + host does not conform to Posix. */ +#define ISASCIIDIGIT(c) ((unsigned) (c) - '0' <= 9) + /* If we (don't) have I18N. */ /* glibc defines _ */ #ifndef _ @@ -145,9 +155,7 @@ static char **addlists PARAMS ((char **old, char **new)); static char **inboth PARAMS ((char **left, char **right)); static ptr_t -xcalloc(n, s) - size_t n; - size_t s; +xcalloc (size_t n, size_t s) { ptr_t r = calloc(n, s); @@ -157,8 +165,7 @@ xcalloc(n, s) } static ptr_t -xmalloc(n) - size_t n; +xmalloc (size_t n) { ptr_t r = malloc(n); @@ -169,9 +176,7 @@ xmalloc(n) } static ptr_t -xrealloc(p, n) - ptr_t p; - size_t n; +xrealloc (ptr_t p, size_t n) { ptr_t r = realloc(p, n); @@ -197,8 +202,7 @@ xrealloc(p, n) #ifdef DEBUG static void -prtok(t) - token t; +prtok (token t) { char *s; @@ -236,33 +240,25 @@ prtok(t) /* Stuff pertaining to charclasses. */ static int -tstbit(b, c) - int b; - charclass c; +tstbit (int b, charclass c) { return c[b / INTBITS] & 1 << b % INTBITS; } static void -setbit(b, c) - int b; - charclass c; +setbit (int b, charclass c) { c[b / INTBITS] |= 1 << b % INTBITS; } static void -clrbit(b, c) - int b; - charclass c; +clrbit (int b, charclass c) { c[b / INTBITS] &= ~(1 << b % INTBITS); } static void -copyset(src, dst) - charclass src; - charclass dst; +copyset (charclass src, charclass dst) { int i; @@ -271,8 +267,7 @@ copyset(src, dst) } static void -zeroset(s) - charclass s; +zeroset (charclass s) { int i; @@ -281,8 +276,7 @@ zeroset(s) } static void -notset(s) - charclass s; +notset (charclass s) { int i; @@ -291,9 +285,7 @@ notset(s) } static int -equal(s1, s2) - charclass s1; - charclass s2; +equal (charclass s1, charclass s2) { int i; @@ -308,8 +300,7 @@ static struct dfa *dfa; /* Find the index of charclass s in dfa->charclasses, or allocate a new charclass. */ static int -charclass_index(s) - charclass s; +charclass_index (charclass s) { int i; @@ -333,10 +324,7 @@ static unsigned char eolbyte; /* Entry point to set syntax options. */ void -dfasyntax(bits, fold, eol) - reg_syntax_t bits; - int fold; - int eol; +dfasyntax (reg_syntax_t bits, int fold, int eol) { syntax_bits_set = 1; syntax_bits = bits; @@ -362,10 +350,12 @@ static int minrep, maxrep; /* Repeat counts for {m,n}. */ #define FETCH(c, eoferr) \ { \ if (! lexleft) \ - if (eoferr != 0) \ - dfaerror(eoferr); \ - else \ - return lasttok = END; \ + { \ + if (eoferr != 0) \ + dfaerror (eoferr); \ + else \ + return lasttok = END; \ + } \ (c) = (unsigned char) *lexptr++; \ --lexleft; \ } @@ -388,8 +378,8 @@ FUNC(is_print, ISPRINT) FUNC(is_graph, ISGRAPH) FUNC(is_cntrl, ISCNTRL) -static int is_blank(c) -int c; +static int +is_blank (int c) { return (c == ' ' || c == '\t'); } @@ -420,8 +410,7 @@ static struct { #define IS_WORD_CONSTITUENT(C) (ISALNUM(C) || (C) == '_') static int -looking_at(s) - const char *s; +looking_at (char const *s) { size_t len; @@ -432,12 +421,14 @@ looking_at(s) } static token -lex() +lex (void) { token c, c1, c2; int backslash = 0, invert; charclass ccl; int i; + char lo[2]; + char hi[2]; /* Basic plan: We fetch a character. If it's a backslash, we set the backslash flag and go through the loop again. @@ -570,10 +561,10 @@ lex() int lo = -1, hi = -1; char const *p = lexptr; char const *lim = p + lexleft; - for (; p != lim && ISDIGIT (*p); p++) + for (; p != lim && ISASCIIDIGIT (*p); p++) lo = (lo < 0 ? 0 : lo * 10) + *p - '0'; if (p != lim && *p == ',') - while (++p != lim && ISDIGIT (*p)) + while (++p != lim && ISASCIIDIGIT (*p)) hi = (hi < 0 ? 0 : hi * 10) + *p - '0'; else hi = lo; @@ -588,13 +579,13 @@ lex() {M,} - minimum count, maximum is infinity {M,N} - M through N */ FETCH(c, _("unfinished repeat count")); - if (ISDIGIT(c)) + if (ISASCIIDIGIT (c)) { minrep = c - '0'; for (;;) { FETCH(c, _("unfinished repeat count")); - if (!ISDIGIT(c)) + if (! ISASCIIDIGIT (c)) break; minrep = 10 * minrep + c - '0'; } @@ -604,7 +595,7 @@ lex() if (c == ',') { FETCH (c, _("unfinished repeat count")); - if (! ISDIGIT (c)) + if (! ISASCIIDIGIT (c)) maxrep = -1; else { @@ -612,7 +603,7 @@ lex() for (;;) { FETCH (c, _("unfinished repeat count")); - if (! ISDIGIT (c)) + if (! ISASCIIDIGIT (c)) break; maxrep = 10 * maxrep + c - '0'; } @@ -751,16 +742,26 @@ lex() } else c2 = c; - while (c <= c2) + + lo[0] = c; lo[1] = '\0'; + hi[0] = c2; hi[1] = '\0'; + for (c = 0; c < NOTCHAR; c++) { - setbit(c, ccl); - if (case_fold) - if (ISUPPER(c)) - setbit(tolower(c), ccl); - else if (ISLOWER(c)) - setbit(toupper(c), ccl); - ++c; + char ch[2]; + ch[0] = c; ch[1] = '\0'; + if (strcoll (lo, ch) <= 0 && strcoll (ch, hi) <= 0) + { + setbit (c, ccl); + if (case_fold) + { + if (ISUPPER (c)) + setbit (tolower (c), ccl); + else if (ISLOWER (c)) + setbit (toupper (c), ccl); + } + } } + skip: ; } @@ -809,8 +810,7 @@ static int depth; /* Current depth of a hypothetical stack /* Add the given token to the parse tree, maintaining the depth count and updating the maximum depth if necessary. */ static void -addtok(t) - token t; +addtok (token t) { REALLOC_IF_NECESSARY(dfa->tokens, token, dfa->talloc, dfa->tindex); dfa->tokens[dfa->tindex++] = t; @@ -869,7 +869,7 @@ addtok(t) The parser builds a parse tree in postfix form in an array of tokens. */ static void -atom() +atom (void) { if ((tok >= 0 && tok < NOTCHAR) || tok >= CSET || tok == BACKREF || tok == BEGLINE || tok == ENDLINE || tok == BEGWORD @@ -892,8 +892,7 @@ atom() /* Return the number of tokens in the given subexpression. */ static int -nsubtoks(tindex) -int tindex; +nsubtoks (int tindex) { int ntoks1; @@ -915,8 +914,7 @@ int tindex; /* Copy the given subexpression to the top of the tree. */ static void -copytoks(tindex, ntokens) - int tindex, ntokens; +copytoks (int tindex, int ntokens) { int i; @@ -925,7 +923,7 @@ copytoks(tindex, ntokens) } static void -closure() +closure (void) { int tindex, ntokens, i; @@ -960,7 +958,7 @@ closure() } static void -branch() +branch (void) { closure(); while (tok != RPAREN && tok != OR && tok >= 0) @@ -971,8 +969,7 @@ branch() } static void -regexp(toplevel) - int toplevel; +regexp (int toplevel) { branch(); while (tok == OR) @@ -990,11 +987,7 @@ regexp(toplevel) length of the string, so s can include NUL characters. D is a pointer to the struct dfa to parse into. */ void -dfaparse(s, len, d) - char *s; - size_t len; - struct dfa *d; - +dfaparse (char *s, size_t len, struct dfa *d) { dfa = d; lexstart = lexptr = s; @@ -1027,9 +1020,7 @@ dfaparse(s, len, d) /* Copy one set to another; the destination must be large enough. */ static void -copy(src, dst) - position_set *src; - position_set *dst; +copy (position_set *src, position_set *dst) { int i; @@ -1043,9 +1034,7 @@ copy(src, dst) the same index then their constraints are logically or'd together. S->elems must point to an array large enough to hold the resulting set. */ static void -insert(p, s) - position p; - position_set *s; +insert (position p, position_set *s) { int i; position t1, t2; @@ -1070,10 +1059,7 @@ insert(p, s) /* Merge two sets of positions into a third. The result is exactly as if the positions of both sets were inserted into an initially empty set. */ static void -merge(s1, s2, m) - position_set *s1; - position_set *s2; - position_set *m; +merge (position_set *s1, position_set *s2, position_set *m) { int i = 0, j = 0; @@ -1096,9 +1082,7 @@ merge(s1, s2, m) /* Delete a position from a set. */ static void -delete(p, s) - position p; - position_set *s; +delete (position p, position_set *s) { int i; @@ -1115,11 +1099,7 @@ delete(p, s) state. Newline and letter tell whether we got here on a newline or letter, respectively. */ static int -state_index(d, s, newline, letter) - struct dfa *d; - position_set *s; - int newline; - int letter; +state_index (struct dfa *d, position_set *s, int newline, int letter) { int hash = 0; int constraint; @@ -1184,12 +1164,8 @@ state_index(d, s, newline, letter) that position with the elements of its follow labeled with an appropriate constraint. Repeat exhaustively until no funny positions are left. S->elems must be large enough to hold the result. */ -static void epsclosure PARAMS ((position_set *s, struct dfa *d)); - static void -epsclosure(s, d) - position_set *s; - struct dfa *d; +epsclosure (position_set *s, struct dfa *d) { int i, j; int *visited; @@ -1301,9 +1277,7 @@ epsclosure(s, d) scheme; the number of elements in each set deeper in the stack can be used to determine the address of a particular set's array. */ void -dfaanalyze(d, searchflag) - struct dfa *d; - int searchflag; +dfaanalyze (struct dfa *d, int searchflag) { int *nullable; /* Nullable stack. */ int *nfirstpos; /* Element count stack for firstpos sets. */ @@ -1564,10 +1538,7 @@ dfaanalyze(d, searchflag) create a new group labeled with the characters of C and insert this position in that group. */ void -dfastate(s, d, trans) - int s; - struct dfa *d; - int trans[]; +dfastate (int s, struct dfa *d, int trans[]) { position_set grps[NOTCHAR]; /* As many as will ever be needed. */ charclass labels[NOTCHAR]; /* Labels corresponding to the groups. */ @@ -1809,9 +1780,7 @@ dfastate(s, d, trans) TODO: Improve this comment, get rid of the unnecessary redundancy. */ static void -build_state(s, d) - int s; - struct dfa *d; +build_state (int s, struct dfa *d) { int *trans; /* The new transition table. */ int i; @@ -1887,8 +1856,7 @@ build_state(s, d) } static void -build_state_zero(d) - struct dfa *d; +build_state_zero (struct dfa *d) { d->tralloc = 1; d->trcount = 0; @@ -1914,13 +1882,8 @@ build_state_zero(d) match needs to be verified by a backtracking matcher. Otherwise we store a 0 in *backref. */ char * -dfaexec(d, begin, end, newline, count, backref) - struct dfa *d; - char *begin; - char *end; - int newline; - int *count; - int *backref; +dfaexec (struct dfa *d, char *begin, char *end, + int newline, int *count, int *backref) { register int s, s1, tmp; /* Current state. */ register unsigned char *p; /* Current input character. */ @@ -2001,8 +1964,7 @@ dfaexec(d, begin, end, newline, count, backref) /* Initialize the components of a dfa that the other routines don't initialize for themselves. */ void -dfainit(d) - struct dfa *d; +dfainit (struct dfa *d) { d->calloc = 1; MALLOC(d->charclasses, charclass, d->calloc); @@ -2020,11 +1982,7 @@ dfainit(d) /* Parse and analyze a single string of the given length. */ void -dfacomp(s, len, d, searchflag) - char *s; - size_t len; - struct dfa *d; - int searchflag; +dfacomp (char *s, size_t len, struct dfa *d, int searchflag) { if (case_fold) /* dummy folding in service of dfamust() */ { @@ -2063,8 +2021,7 @@ dfacomp(s, len, d, searchflag) /* Free the storage held by the components of a dfa. */ void -dfafree(d) - struct dfa *d; +dfafree (struct dfa *d) { int i; struct dfamust *dm, *ndm; @@ -2176,9 +2133,7 @@ dfafree(d) 'psi|epsilon' is likelier)? */ static char * -icatalloc(old, new) - char *old; - char *new; +icatalloc (char *old, char *new) { char *result; size_t oldsize, newsize; @@ -2199,16 +2154,13 @@ icatalloc(old, new) } static char * -icpyalloc(string) - char *string; +icpyalloc (char *string) { return icatalloc((char *) NULL, string); } static char * -istrstr(lookin, lookfor) - char *lookin; - char *lookfor; +istrstr (char *lookin, char *lookfor) { char *cp; size_t len; @@ -2221,16 +2173,14 @@ istrstr(lookin, lookfor) } static void -ifree(cp) - char *cp; +ifree (char *cp) { if (cp != NULL) free(cp); } static void -freelist(cpp) - char **cpp; +freelist (char **cpp) { int i; @@ -2244,10 +2194,7 @@ freelist(cpp) } static char ** -enlist(cpp, new, len) - char **cpp; - char *new; - size_t len; +enlist (char **cpp, char *new, size_t len) { int i, j; @@ -2292,9 +2239,7 @@ enlist(cpp, new, len) list of their distinct common substrings. Return NULL if something seems wild. */ static char ** -comsubs(left, right) - char *left; - char *right; +comsubs (char *left, char *right) { char **cpp; char *lcp; @@ -2328,9 +2273,7 @@ comsubs(left, right) } static char ** -addlists(old, new) -char **old; -char **new; +addlists (char **old, char **new) { int i; @@ -2348,9 +2291,7 @@ char **new; /* Given two lists of substrings, return a new list giving substrings common to both. */ static char ** -inboth(left, right) - char **left; - char **right; +inboth (char **left, char **right) { char **both; char **temp; @@ -2391,16 +2332,14 @@ typedef struct } must; static void -resetmust(mp) -must *mp; +resetmust (must *mp) { mp->left[0] = mp->right[0] = mp->is[0] = '\0'; freelist(mp->in); } static void -dfamust(dfa) -struct dfa *dfa; +dfamust (struct dfa *dfa) { must *musts; must *mp; diff --git a/gnu/usr.bin/grep/doc/grep.texi b/gnu/usr.bin/grep/doc/grep.texi index d71f2c1bb4ac..49493de6c398 100644 --- a/gnu/usr.bin/grep/doc/grep.texi +++ b/gnu/usr.bin/grep/doc/grep.texi @@ -126,7 +126,13 @@ This document was produced for version @value{VERSION} of @sc{gnu} for lines containing a match to a given pattern list. When it finds a match in a line, it copies the line to standard output (by default), or does whatever other sort of output you have requested -with options. @command{grep} expects to do the matching on text. +with options. + +Though @command{grep} expects to do the matching on text, +it has no limits on input line length other than available memory, +and it can match arbitrary characters within a line. +If the final byte of an input file is not a newline, +@command{grep} silently supplies one. Since newline is also a separator for the list of patterns, there is no way to match newline characters in a text. @@ -283,9 +289,10 @@ data, assume that the file is of type @var{type}. By default, @var{type} is @samp{binary}, and @command{grep} normally outputs either a one-line message saying that a binary file matches, or no message if there is no match. If @var{type} is @samp{without-match}, -@command{grep} assumes that a binary file does not match. If @var{type} +@command{grep} assumes that a binary file does not match; +this is equivalent to the @samp{-I} option. If @var{type} is @samp{text}, @command{grep} processes a binary file as if it were -text; this is equivalent to the @samp{-a} or @samp{--text} option. +text; this is equivalent to the @samp{-a} option. @emph{Warning:} @samp{--binary-files=text} 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. @@ -347,6 +354,10 @@ The scanning of every file will stop on the first match. Process a binary file as if it were text; this is equivalent to the @samp{--binary-files=text} option. +@item -I +Process a binary file as if it did not contain matching data; this is +equivalent to the @samp{--binary-files=without-match} option. + @item -w @itemx --word-regexp @opindex -w @@ -457,9 +468,10 @@ Grep's behavior is affected by the following environment variables. @vindex GREP_OPTIONS @cindex default options environment variable This variable specifies default options to be placed in front of any -explicit options. For example, if @code{GREP_OPTIONS} is @samp{--text ---directories=skip}, @command{grep} behaves as if the two options -@samp{--text} and @samp{--directories=skip} had been specified before +explicit options. For example, if @code{GREP_OPTIONS} is +@samp{--binary-files=without-match --directories=skip}, @command{grep} +behaves as if the two options @samp{--binary-files=without-match} and +@samp{--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. @@ -595,7 +607,7 @@ single character in that list; if the first character of the list is the caret @samp{^}, then it matches any character @strong{not} in the list. For example, the regular expression @samp{[0123456789]} matches any single digit. -A range of @sc{ascii} characters may be specified by giving the first +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, as follows. @@ -610,74 +622,83 @@ if no @code{LC_CTYPE} locale is specified. @item [:alnum:] @opindex alnum @cindex alphanumeric characters -Any of @samp{[:digit:]} or @samp{[:alpha:]} +Alphanumeric characters: +@samp{[:alpha:]} and @samp{[:digit:]}. @item [:alpha:] @opindex alpha @cindex alphabetic characters -Any letter:@* -@code{a b c d e f g h i j k l m n o p q r s t u v w x y z},@* -@code{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}. +Alphabetic characters: +@samp{[:lower:]} and @samp{[:upper:]}. @item [:blank:] @opindex blank @cindex blank characters -Space or tab. +Blank characters: +space and tab. @item [:cntrl:] @opindex cntrl @cindex control characters -Any character with octal codes 000 through 037, or @code{DEL} (octal -code 177). +Control characters. In @sc{ascii}, these characters have octal codes 000 +through 037, and 177 (@code{DEL}). In other character sets, these are +the equivalent characters, if any. @item [:digit:] @opindex digit @cindex digit characters @cindex numeric characters -Any one of @code{0 1 2 3 4 5 6 7 8 9}. +Digits: @code{0 1 2 3 4 5 6 7 8 9}. @item [:graph:] @opindex graph @cindex graphic characters -Anything that is not a @samp{[:alnum:]} or @samp{[:punct:]}. +Graphical characters: +@samp{[:alnum:]} and @samp{[:punct:]}. @item [:lower:] @opindex lower -@cindex lower-case alphabetic characters -Any one of @code{a b c d e f g h i j k l m n o p q r s t u v w x y z}. +@cindex lower-case letters +Lower-case letters: +@code{a b c d e f g h i j k l m n o p q r s t u v w x y z}. @item [:print:] @opindex print @cindex printable characters -Any character from the @samp{[:space:]} class, and any character that is -@strong{not} in the @samp{[:graph:]} class. +Printable characters: +@samp{[:alnum:]}, @samp{[:punct:]}, and space. @item [:punct:] @opindex punct @cindex punctuation characters -Any one of @code{!@: " # $ % & ' ( ) * + , - .@: / : ; < = > ?@: @@ [ \ ] ^ _ ` @{ | @} ~}. +Punctuation characters: +@code{!@: " # $ % & ' ( ) * + , - .@: / : ; < = > ?@: @@ [ \ ] ^ _ ` @{ | @} ~}. @item [:space:] @opindex space @cindex space characters @cindex whitespace characters -Any one of @code{CR FF HT NL VT SPACE}. +Space characters: +tab, newline, vertical tab, form feed, carriage return, and space. @item [:upper:] @opindex upper -@cindex upper-case alphabetic characters -Any one of @code{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}. +@cindex upper-case letters +Upper-case letters: +@code{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}. @item [:xdigit:] @opindex xdigit @cindex xdigit class @cindex hexadecimal digits -Any one of @code{a b c d e f A B C D E F 0 1 2 3 4 5 6 7 8 9}. +Hexadecimal digits: +@code{0 1 2 3 4 5 6 7 8 9 A B C D E F a b c d e f}. @end table For example, @samp{[[:alnum:]]} means @samp{[0-9A-Za-z]}, except the latter -form is dependent upon the @sc{ascii} character encoding, whereas the -former is portable. (Note that the brackets in these class names are +depends upon the @sc{posix} locale and the @sc{ascii} 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 inside lists. To include a literal @samp{]}, place it @@ -897,7 +918,9 @@ would probably generate output that is not useful, and it might even muck up your display. So @sc{gnu} @command{grep} suppresses output from files that appear to be binary files. To force @sc{gnu} @command{grep} to output lines even from files that appear to be binary, use the -@samp{-a} or @samp{--text} option. +@samp{-a} or @samp{--binary-files=text} option. To eliminate the +``Binary file matches'' messages, use the @samp{-I} or +@samp{--binary-files=without-match} option. @item Why doesn't @samp{grep -lv} print nonmatching file names? diff --git a/gnu/usr.bin/grep/doc/version.texi b/gnu/usr.bin/grep/doc/version.texi index 2deace2186c3..5246f406c0b4 100644 --- a/gnu/usr.bin/grep/doc/version.texi +++ b/gnu/usr.bin/grep/doc/version.texi @@ -1,3 +1,3 @@ -@set UPDATED 16 January 2000 -@set EDITION 2.4a -@set VERSION 2.4a +@set UPDATED 27 January 2000 +@set EDITION 2.4d +@set VERSION 2.4d diff --git a/gnu/usr.bin/grep/getopt.c b/gnu/usr.bin/grep/getopt.c index eac576b83e44..d176d3e7e720 100644 --- a/gnu/usr.bin/grep/getopt.c +++ b/gnu/usr.bin/grep/getopt.c @@ -1,45 +1,40 @@ /* Getopt for GNU. - NOTE: getopt is now part of the C library, so if you don't know what - "Keep this file name-space clean" means, talk to roland@gnu.ai.mit.edu - before changing it! + NOTE: The canonical source of this file is maintained with the GNU + C Library. Bugs can be reported to bug-glibc@gnu.org. - Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97 + Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99 Free Software Foundation, Inc. - This file is part of the GNU C Library. Its master source is NOT part of - the C library, however. The master source lives in /gd/gnu/lib. + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* This tells Alpha OSF/1 not to define a getopt prototype in . Ditto for AIX 3.2 and . */ #ifndef _NO_PROTO -#define _NO_PROTO +# define _NO_PROTO #endif #ifdef HAVE_CONFIG_H -#include -#endif - -#if !defined (__STDC__) || !__STDC__ +# include +#else +# if !defined __STDC__ || !__STDC__ /* This is a separate conditional since some stdc systems reject `defined (const)'. */ -#ifndef const -#define const -#endif +# ifndef const +# define const +# endif +# endif #endif #include @@ -53,11 +48,11 @@ it is simpler to just do this in the source for each such file. */ #define GETOPT_INTERFACE_VERSION 2 -#if !defined (_LIBC) && defined (__GLIBC__) && __GLIBC__ >= 2 -#include -#if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION -#define ELIDE_CODE -#endif +#if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2 +# include +# if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION +# define ELIDE_CODE +# endif #endif #ifndef ELIDE_CODE @@ -68,32 +63,26 @@ #ifdef __GNU_LIBRARY__ /* Don't include stdlib.h for non-GNU C libraries because some of them contain conflicting prototypes for getopt. */ -#include -#include +# include +# include #endif /* GNU C library. */ #ifdef VMS -#include -#if HAVE_STRING_H - 0 -#include -#endif -#endif - -#if defined (WIN32) && !defined (__CYGWIN32__) -/* It's not Unix, really. See? Capital letters. */ -#include -#define getpid() GetCurrentProcessId() +# include +# if HAVE_STRING_H - 0 +# include +# endif #endif #ifndef _ /* This is for other GNU distributions with internationalized messages. When compiling libc, the _ macro is predefined. */ -#ifdef HAVE_LIBINTL_H -# include -# define _(msgid) gettext (msgid) -#else -# define _(msgid) (msgid) -#endif +# ifdef HAVE_LIBINTL_H +# include +# define _(msgid) gettext (msgid) +# else +# define _(msgid) (msgid) +# endif #endif /* This version of `getopt' appears to the caller like standard Unix `getopt' @@ -118,7 +107,7 @@ Also, when `ordering' is RETURN_IN_ORDER, each non-option ARGV-element is returned here. */ -char *optarg = NULL; +char *optarg; /* Index in ARGV of the next element to be scanned. This is used for communication to and from the caller @@ -139,7 +128,7 @@ int optind = 1; causes problems with re-calling getopt as programs generally don't know that. */ -int __getopt_initialized = 0; +int __getopt_initialized; /* The next char to be scanned in the option-element in which the last option character we returned was found. @@ -203,14 +192,22 @@ static char *posixly_correct; because there are many ways it can cause trouble. On some systems, it contains special magic macros that don't work in GCC. */ -#include -#define my_index strchr +# include +# define my_index strchr #else +# if HAVE_STRING_H +# include +# else +# include +# endif + /* Avoid depending on library functions or files whose names are inconsistent. */ -char *getenv (); +#ifndef getenv +extern char *getenv (); +#endif static char * my_index (str, chr) @@ -231,11 +228,11 @@ my_index (str, chr) #ifdef __GNUC__ /* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h. That was relevant to code that was here before. */ -#if !defined (__STDC__) || !__STDC__ +# if (!defined __STDC__ || !__STDC__) && !defined strlen /* gcc with -traditional declares the built-in strlen to return int, and has done so at least since version 2.4.5. -- rms. */ extern int strlen (const char *); -#endif /* not __STDC__ */ +# endif /* not __STDC__ */ #endif /* __GNUC__ */ #endif /* not __GNU_LIBRARY__ */ @@ -253,7 +250,10 @@ static int last_nonopt; /* Bash 2.0 gives us an environment variable containing flags indicating ARGV elements that should not be considered arguments. */ -static const char *nonoption_flags; +/* Defined in getopt_init.c */ +extern char *__getopt_nonoption_flags; + +static int nonoption_flags_max_len; static int nonoption_flags_len; static int original_argc; @@ -262,17 +262,29 @@ static char *const *original_argv; /* Make sure the environment variable bash 2.0 puts in the environment is valid for the getopt call we must make sure that the ARGV passed to getopt is that one passed to the process. */ -static void store_args (int argc, char *const *argv) __attribute__ ((unused)); static void -store_args (int argc, char *const *argv) +__attribute__ ((unused)) +store_args_and_env (int argc, char *const *argv) { /* XXX This is no good solution. We should rather copy the args so that we can compare them later. But we must not use malloc(3). */ original_argc = argc; original_argv = argv; } -text_set_element (__libc_subinit, store_args); -#endif +# ifdef text_set_element +text_set_element (__libc_subinit, store_args_and_env); +# endif /* text_set_element */ + +# define SWAP_FLAGS(ch1, ch2) \ + if (nonoption_flags_len > 0) \ + { \ + char __tmp = __getopt_nonoption_flags[ch1]; \ + __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \ + __getopt_nonoption_flags[ch2] = __tmp; \ + } +#else /* !_LIBC */ +# define SWAP_FLAGS(ch1, ch2) +#endif /* _LIBC */ /* Exchange two adjacent subsequences of ARGV. One subsequence is elements [first_nonopt,last_nonopt) @@ -283,7 +295,7 @@ text_set_element (__libc_subinit, store_args); `first_nonopt' and `last_nonopt' are relocated so that they describe the new indices of the non-options in ARGV after they are moved. */ -#if defined (__STDC__) && __STDC__ +#if defined __STDC__ && __STDC__ static void exchange (char **); #endif @@ -301,6 +313,28 @@ exchange (argv) It leaves the longer segment in the right place overall, but it consists of two parts that need to be swapped next. */ +#ifdef _LIBC + /* First make sure the handling of the `__getopt_nonoption_flags' + string can work normally. Our top argument must be in the range + of the string. */ + if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len) + { + /* We must extend the array. The user plays games with us and + presents new arguments. */ + char *new_str = malloc (top + 1); + if (new_str == NULL) + nonoption_flags_len = nonoption_flags_max_len = 0; + else + { + memset (__mempcpy (new_str, __getopt_nonoption_flags, + nonoption_flags_max_len), + '\0', top + 1 - nonoption_flags_max_len); + nonoption_flags_max_len = top + 1; + __getopt_nonoption_flags = new_str; + } + } +#endif + while (top > middle && middle > bottom) { if (top - middle > middle - bottom) @@ -315,6 +349,7 @@ exchange (argv) tem = argv[bottom + i]; argv[bottom + i] = argv[top - (middle - bottom) + i]; argv[top - (middle - bottom) + i] = tem; + SWAP_FLAGS (bottom + i, top - (middle - bottom) + i); } /* Exclude the moved bottom segment from further swapping. */ top -= len; @@ -331,6 +366,7 @@ exchange (argv) tem = argv[bottom + i]; argv[bottom + i] = argv[middle + i]; argv[middle + i] = tem; + SWAP_FLAGS (bottom + i, middle + i); } /* Exclude the moved top segment from further swapping. */ bottom += len; @@ -345,7 +381,7 @@ exchange (argv) /* Initialize the internal data when the first call is made. */ -#if defined (__STDC__) && __STDC__ +#if defined __STDC__ && __STDC__ static const char *_getopt_initialize (int, char *const *, const char *); #endif static const char * @@ -358,7 +394,7 @@ _getopt_initialize (argc, argv, optstring) is the program name); the sequence of previously skipped non-option ARGV-elements is empty. */ - first_nonopt = last_nonopt = optind = 1; + first_nonopt = last_nonopt = optind; nextchar = NULL; @@ -385,17 +421,27 @@ _getopt_initialize (argc, argv, optstring) if (posixly_correct == NULL && argc == original_argc && argv == original_argv) { - /* Bash 2.0 puts a special variable in the environment for each - command it runs, specifying which ARGV elements are the results of - file name wildcard expansion and therefore should not be - considered as options. */ - char var[100]; - sprintf (var, "_%d_GNU_nonoption_argv_flags_", getpid ()); - nonoption_flags = getenv (var); - if (nonoption_flags == NULL) - nonoption_flags_len = 0; - else - nonoption_flags_len = strlen (nonoption_flags); + if (nonoption_flags_max_len == 0) + { + if (__getopt_nonoption_flags == NULL + || __getopt_nonoption_flags[0] == '\0') + nonoption_flags_max_len = -1; + else + { + const char *orig_str = __getopt_nonoption_flags; + int len = nonoption_flags_max_len = strlen (orig_str); + if (nonoption_flags_max_len < argc) + nonoption_flags_max_len = argc; + __getopt_nonoption_flags = + (char *) malloc (nonoption_flags_max_len); + if (__getopt_nonoption_flags == NULL) + nonoption_flags_max_len = -1; + else + memset (__mempcpy (__getopt_nonoption_flags, orig_str, len), + '\0', nonoption_flags_max_len - len); + } + } + nonoption_flags_len = nonoption_flags_max_len; } else nonoption_flags_len = 0; @@ -471,10 +517,11 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) { optarg = NULL; - if (!__getopt_initialized || optind == 0) + if (optind == 0 || !__getopt_initialized) { + if (optind == 0) + optind = 1; /* Don't scan ARGV[0], the program name. */ optstring = _getopt_initialize (argc, argv, optstring); - optind = 1; /* Don't scan ARGV[0], the program name. */ __getopt_initialized = 1; } @@ -483,11 +530,11 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) from the shell indicating it is not an option. The later information is only used when the used in the GNU libc. */ #ifdef _LIBC -#define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0' \ - || (optind < nonoption_flags_len \ - && nonoption_flags[optind] == '1')) +# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0' \ + || (optind < nonoption_flags_len \ + && __getopt_nonoption_flags[optind] == '1')) #else -#define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0') +# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0') #endif if (nextchar == NULL || *nextchar == '\0') @@ -646,16 +693,18 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) else { if (opterr) - if (argv[optind - 1][1] == '-') - /* --option */ - fprintf (stderr, - _("%s: option `--%s' doesn't allow an argument\n"), - argv[0], pfound->name); - else - /* +option or -option */ - fprintf (stderr, - _("%s: option `%c%s' doesn't allow an argument\n"), - argv[0], argv[optind - 1][0], pfound->name); + { + if (argv[optind - 1][1] == '-') + /* --option */ + fprintf (stderr, + _("%s: option `--%s' doesn't allow an argument\n"), + argv[0], pfound->name); + else + /* +option or -option */ + fprintf (stderr, + _("%s: option `%c%s' doesn't allow an argument\n"), + argv[0], argv[optind - 1][0], pfound->name); + } nextchar += strlen (nextchar); diff --git a/gnu/usr.bin/grep/getopt.h b/gnu/usr.bin/grep/getopt.h index 2d8c8f946ab2..39f4a168626b 100644 --- a/gnu/usr.bin/grep/getopt.h +++ b/gnu/usr.bin/grep/getopt.h @@ -1,26 +1,27 @@ /* Declarations for getopt. - Copyright (C) 1989,90,91,92,93,94,96,97, 98 Free Software Foundation, Inc. + Copyright (C) 1989,90,91,92,93,94,96,97,98 Free Software Foundation, Inc. + NOTE: The canonical source of this file is maintained with the GNU C Library. + Bugs can be reported to bug-glibc@gnu.org. + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. - This file is part of the GNU C Library. Its master source is NOT part of - the C library, however. The master source lives in /gd/gnu/lib. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + USA. */ #ifndef _GETOPT_H -#define _GETOPT_H 1 + +#ifndef __need_getopt +# define _GETOPT_H 1 +#endif #ifdef __cplusplus extern "C" { @@ -57,6 +58,7 @@ extern int opterr; extern int optopt; +#ifndef __need_getopt /* Describe the long-named options requested by the application. The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector of `struct option' terminated by an element containing a name which is @@ -80,11 +82,11 @@ extern int optopt; struct option { -#if defined (__STDC__) && __STDC__ +# if defined __STDC__ && __STDC__ const char *name; -#else +# else char *name; -#endif +# endif /* has_arg can't be an enum because some compilers complain about type mismatches in all the code that assumes it is an int. */ int has_arg; @@ -94,40 +96,74 @@ struct option /* Names for the values of the `has_arg' field of `struct option'. */ -#define no_argument 0 -#define required_argument 1 -#define optional_argument 2 +# define no_argument 0 +# define required_argument 1 +# define optional_argument 2 +#endif /* need getopt */ -#if defined (__STDC__) && __STDC__ -#ifdef __GNU_LIBRARY__ + +/* Get definitions and prototypes for functions to process the + arguments in ARGV (ARGC of them, minus the program name) for + options given in OPTS. + + Return the option character from OPTS just read. Return -1 when + there are no more options. For unrecognized options, or options + missing arguments, `optopt' is set to the option letter, and '?' is + returned. + + The OPTS string is a list of characters which are recognized option + letters, optionally followed by colons, specifying that that letter + takes an argument, to be placed in `optarg'. + + If a letter in OPTS is followed by two colons, its argument is + optional. This behavior is specific to the GNU `getopt'. + + The argument `--' causes premature termination of argument + scanning, explicitly telling `getopt' that there are no more + options. + + If OPTS begins with `--', then non-option arguments are treated as + arguments to the option '\0'. This behavior is specific to the GNU + `getopt'. */ + +#if (defined __STDC__ && __STDC__) || defined PROTOTYPES +# ifdef __GNU_LIBRARY__ /* Many other libraries have conflicting prototypes for getopt, with differences in the consts, in stdlib.h. To avoid compilation errors, only prototype getopt for the GNU C library. */ -extern int getopt (int argc, char *const *argv, const char *shortopts); -#else /* not __GNU_LIBRARY__ */ +extern int getopt (int __argc, char *const *__argv, const char *__shortopts); +# else /* not __GNU_LIBRARY__ */ extern int getopt (); -#endif /* __GNU_LIBRARY__ */ -extern int getopt_long (int argc, char *const *argv, const char *shortopts, - const struct option *longopts, int *longind); -extern int getopt_long_only (int argc, char *const *argv, - const char *shortopts, - const struct option *longopts, int *longind); +# endif /* __GNU_LIBRARY__ */ + +# ifndef __need_getopt +extern int getopt_long (int __argc, char *const *__argv, const char *__shortopts, + const struct option *__longopts, int *__longind); +extern int getopt_long_only (int __argc, char *const *__argv, + const char *__shortopts, + const struct option *__longopts, int *__longind); /* Internal only. Users should not call this directly. */ -extern int _getopt_internal (int argc, char *const *argv, - const char *shortopts, - const struct option *longopts, int *longind, - int long_only); -#else /* not __STDC__ */ +extern int _getopt_internal (int __argc, char *const *__argv, + const char *__shortopts, + const struct option *__longopts, int *__longind, + int __long_only); +# endif +#else /* not ((defined __STDC__ && __STDC__) || defined PROTOTYPES) */ extern int getopt (); +# ifndef __need_getopt extern int getopt_long (); extern int getopt_long_only (); extern int _getopt_internal (); -#endif /* __STDC__ */ +# endif +#endif /* (defined __STDC__ && __STDC__) || defined PROTOTYPES */ #ifdef __cplusplus } #endif -#endif /* _GETOPT_H */ +/* Make sure we later can get all the definitions and declarations. */ +#undef __need_getopt + +#endif /* getopt.h */ diff --git a/gnu/usr.bin/grep/getopt1.c b/gnu/usr.bin/grep/getopt1.c index a967c3077169..9c8256567c49 100644 --- a/gnu/usr.bin/grep/getopt1.c +++ b/gnu/usr.bin/grep/getopt1.c @@ -1,37 +1,36 @@ /* getopt_long and getopt_long_only entry points for GNU getopt. - Copyright (C) 1987,88,89,90,91,92,93,94,96,97, 98 Free Software Foundation, Inc. + Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98 + Free Software Foundation, Inc. + NOTE: The canonical source of this file is maintained with the GNU C Library. + Bugs can be reported to bug-glibc@gnu.org. - This file is part of the GNU C Library. Its master source is NOT part of - the C library, however. The master source lives in /gd/gnu/lib. + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifdef HAVE_CONFIG_H #include -#endif - -#include "getopt.h" - -#if !defined (__STDC__) || !__STDC__ +#else +#if !defined __STDC__ || !__STDC__ /* This is a separate conditional since some stdc systems reject `defined (const)'. */ #ifndef const #define const #endif #endif +#endif + +#include "getopt.h" #include @@ -44,7 +43,7 @@ it is simpler to just do this in the source for each such file. */ #define GETOPT_INTERFACE_VERSION 2 -#if !defined (_LIBC) && defined (__GLIBC__) && __GLIBC__ >= 2 +#if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2 #include #if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION #define ELIDE_CODE @@ -129,9 +128,9 @@ main (argc, argv) switch (c) { case 0: - printf (_("option %s"), long_options[option_index].name); + printf ("option %s", long_options[option_index].name); if (optarg) - printf (_(" with arg %s"), optarg); + printf (" with arg %s", optarg); printf ("\n"); break; @@ -146,38 +145,38 @@ main (argc, argv) case '8': case '9': if (digit_optind != 0 && digit_optind != this_option_optind) - printf (_("digits occur in two different argv-elements.\n")); + printf ("digits occur in two different argv-elements.\n"); digit_optind = this_option_optind; - printf (_("option %c\n"), c); + printf ("option %c\n", c); break; case 'a': - printf (_("option a\n")); + printf ("option a\n"); break; case 'b': - printf (_("option b\n")); + printf ("option b\n"); break; case 'c': - printf (_("option c with value `%s'\n"), optarg); + printf ("option c with value `%s'\n", optarg); break; case 'd': - printf (_("option d with value `%s'\n"), optarg); + printf ("option d with value `%s'\n", optarg); break; case '?': break; default: - printf (_("?? getopt returned character code 0%o ??\n"), c); + printf ("?? getopt returned character code 0%o ??\n", c); } } if (optind < argc) { - printf (_("non-option ARGV-elements: ")); + printf ("non-option ARGV-elements: "); while (optind < argc) printf ("%s ", argv[optind++]); printf ("\n"); diff --git a/gnu/usr.bin/grep/getpagesize.h b/gnu/usr.bin/grep/getpagesize.h index a064973d15f3..4e513c31adeb 100644 --- a/gnu/usr.bin/grep/getpagesize.h +++ b/gnu/usr.bin/grep/getpagesize.h @@ -2,40 +2,34 @@ #ifndef HAVE_GETPAGESIZE -# ifdef VMS -# define getpagesize() 512 -# endif +#ifdef VMS +#define getpagesize() 512 +#endif -# ifdef HAVE_UNISTD_H -# include -# endif +#ifdef HAVE_UNISTD_H +#include +#endif -# ifdef _SC_PAGESIZE -# define getpagesize() sysconf(_SC_PAGESIZE) -# else /* no _SC_PAGESIZE */ -# ifdef HAVE_SYS_PARAM_H -# include -# ifdef EXEC_PAGESIZE -# define getpagesize() EXEC_PAGESIZE -# else /* no EXEC_PAGESIZE */ -# ifdef NBPG -# define getpagesize() NBPG * CLSIZE -# ifndef CLSIZE -# define CLSIZE 1 -# endif /* no CLSIZE */ -# else /* no NBPG */ -# ifdef NBPC -# define getpagesize() NBPC -# else /* no NBPC */ -# ifdef PAGESIZE -# define getpagesize() PAGESIZE -# endif /* PAGESIZE */ -# endif /* no NBPC */ -# endif /* no NBPG */ -# endif /* no EXEC_PAGESIZE */ -# else /* no HAVE_SYS_PARAM_H */ -# define getpagesize() 8192 /* punt totally */ -# endif /* no HAVE_SYS_PARAM_H */ -# endif /* no _SC_PAGESIZE */ +#ifdef _SC_PAGESIZE +#define getpagesize() sysconf(_SC_PAGESIZE) +#else -#endif /* no HAVE_GETPAGESIZE */ +#include + +#ifdef EXEC_PAGESIZE +#define getpagesize() EXEC_PAGESIZE +#else +#ifdef NBPG +#define getpagesize() NBPG * CLSIZE +#ifndef CLSIZE +#define CLSIZE 1 +#endif /* no CLSIZE */ +#else /* no NBPG */ +#ifdef NBPC +#define getpagesize() NBPC +#endif /* NBPC */ +#endif /* no NBPG */ +#endif /* no EXEC_PAGESIZE */ +#endif /* no _SC_PAGESIZE */ + +#endif /* not HAVE_GETPAGESIZE */ diff --git a/gnu/usr.bin/grep/grep.1 b/gnu/usr.bin/grep/grep.1 index f6f54852edc1..8212ff3e8f0a 100644 --- a/gnu/usr.bin/grep/grep.1 +++ b/gnu/usr.bin/grep/grep.1 @@ -12,92 +12,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 \- 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 ] -.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 @@ -109,40 +56,31 @@ is the same as .B Fgrep is the same as .BR "grep\ \-F" . -.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 @@ -162,7 +100,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 @@ -170,8 +110,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" @@ -179,10 +117,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. @@ -213,18 +147,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 @@ -232,9 +182,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 @@ -249,6 +208,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. @@ -292,29 +266,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 @@ -346,20 +297,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 @@ -378,7 +338,6 @@ and .B "xargs \-0" to process arbitrary file names, even those that contain newline characters. -.PD .SH "REGULAR EXPRESSIONS" .PP A regular expression is a pattern that describes a set of strings. @@ -412,7 +371,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. @@ -433,8 +392,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 @@ -578,6 +538,83 @@ 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 VARIABLES" +.TP +.B GREP_OPTIONS +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, diff --git a/gnu/usr.bin/grep/grep.c b/gnu/usr.bin/grep/grep.c index 80f74703fc26..661076a8d273 100644 --- a/gnu/usr.bin/grep/grep.c +++ b/gnu/usr.bin/grep/grep.c @@ -60,7 +60,7 @@ static int mmap_option; /* 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 @@ -157,9 +157,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)); @@ -170,9 +168,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); @@ -180,8 +176,7 @@ fatal (mesg, errnum) /* Interface to handle errors and fix library lossage. */ char * -xmalloc (size) - size_t size; +xmalloc (size_t size) { char *result; @@ -193,9 +188,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; @@ -211,9 +204,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++) @@ -257,9 +248,7 @@ static off_t initial_bufoffset; /* Initial value of bufoffset. */ 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) @@ -277,10 +266,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); @@ -349,9 +335,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; @@ -517,8 +501,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++) @@ -527,9 +510,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. */ @@ -546,10 +527,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); @@ -575,8 +553,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; @@ -596,10 +573,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; @@ -662,9 +636,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; @@ -704,10 +676,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; @@ -795,6 +764,7 @@ grep (fd, file, stats) } if (residue) { + *buflim++ = eol; nlines += grepbuf (bufbeg + save - residue, buflim); if (pending) prpending (buflim); @@ -809,9 +779,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; @@ -905,9 +873,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; @@ -965,8 +931,7 @@ grepdir (dir, stats) } static void -usage(status) -int status; +usage (int status) { if (status != 0) { @@ -978,7 +943,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 (_("\ @@ -1008,9 +973,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\ @@ -1040,8 +1006,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); @@ -1051,8 +1016,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 @@ -1100,10 +1064,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; @@ -1132,10 +1093,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) { @@ -1154,15 +1112,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; @@ -1276,6 +1233,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; diff --git a/gnu/usr.bin/grep/kwset.c b/gnu/usr.bin/grep/kwset.c index c7b088bdf9c5..92dbf0950c2d 100644 --- a/gnu/usr.bin/grep/kwset.c +++ b/gnu/usr.bin/grep/kwset.c @@ -96,8 +96,7 @@ static char * cwexec PARAMS((kwset_t, char *, size_t, struct kwsmatch *)); /* Allocate and initialize a keyword set object, returning an opaque pointer to it. Return NULL if memory is not available. */ kwset_t -kwsalloc(trans) - char *trans; +kwsalloc (char *trans) { struct kwset *kwset; @@ -132,10 +131,7 @@ kwsalloc(trans) /* Add the given string to the contents of the keyword set. Return NULL for success, an error message otherwise. */ char * -kwsincr(kws, text, len) - kwset_t kws; - char *text; - size_t len; +kwsincr (kwset_t kws, char *text, size_t len) { struct kwset *kwset; register struct trie *trie; @@ -292,9 +288,7 @@ kwsincr(kws, text, len) /* Enqueue the trie nodes referenced from the given tree in the given queue. */ static void -enqueue(tree, last) - struct tree *tree; - struct trie **last; +enqueue (struct tree *tree, struct trie **last) { if (!tree) return; @@ -307,10 +301,7 @@ enqueue(tree, last) from the given tree, given the failure function for their parent as well as a last resort failure node. */ static void -treefails(tree, fail, recourse) - register struct tree *tree; - struct trie *fail; - struct trie *recourse; +treefails (register struct tree *tree, struct trie *fail, struct trie *recourse) { register struct tree *link; @@ -344,10 +335,9 @@ treefails(tree, fail, recourse) /* Set delta entries for the links of the given tree such that the preexisting delta value is larger than the current depth. */ static void -treedelta(tree, depth, delta) - register struct tree *tree; - register unsigned int depth; - unsigned char delta[]; +treedelta (register struct tree *tree, + register unsigned int depth, + unsigned char delta[]) { if (!tree) return; @@ -359,9 +349,7 @@ treedelta(tree, depth, delta) /* Return true if A has every label in B. */ static int -hasevery(a, b) - register struct tree *a; - register struct tree *b; +hasevery (register struct tree *a, register struct tree *b) { if (!b) return 1; @@ -380,9 +368,7 @@ hasevery(a, b) /* Compute a vector, indexed by character code, of the trie nodes referenced from the given tree. */ static void -treenext(tree, next) - struct tree *tree; - struct trie *next[]; +treenext (struct tree *tree, struct trie *next[]) { if (!tree) return; @@ -394,8 +380,7 @@ treenext(tree, next) /* Compute the shift for each trie node, as well as the delta table and next cache for the given keyword set. */ char * -kwsprep(kws) - kwset_t kws; +kwsprep (kwset_t kws) { register struct kwset *kwset; register int i; @@ -513,10 +498,7 @@ kwsprep(kws) /* Fast boyer-moore search. */ static char * -bmexec(kws, text, size) - kwset_t kws; - char *text; - size_t size; +bmexec (kwset_t kws, char *text, size_t size) { struct kwset *kwset; register unsigned char *d1; @@ -599,11 +581,7 @@ bmexec(kws, text, size) /* Hairy multiple string search. */ static char * -cwexec(kws, text, len, kwsmatch) - kwset_t kws; - char *text; - size_t len; - struct kwsmatch *kwsmatch; +cwexec (kwset_t kws, char *text, size_t len, struct kwsmatch *kwsmatch) { struct kwset *kwset; struct trie **next, *trie, *accept; @@ -764,11 +742,7 @@ cwexec(kws, text, len, kwsmatch) in the referenced location the index number of the particular keyword matched. */ char * -kwsexec(kws, text, size, kwsmatch) - kwset_t kws; - char *text; - size_t size; - struct kwsmatch *kwsmatch; +kwsexec (kwset_t kws, char *text, size_t size, struct kwsmatch *kwsmatch) { struct kwset *kwset; char *ret; @@ -791,8 +765,7 @@ kwsexec(kws, text, size, kwsmatch) /* Free the components of the given keyword set. */ void -kwsfree(kws) - kwset_t kws; +kwsfree (kwset_t kws) { struct kwset *kwset; diff --git a/gnu/usr.bin/grep/obstack.c b/gnu/usr.bin/grep/obstack.c index 4258c1238e1f..17c63134315a 100644 --- a/gnu/usr.bin/grep/obstack.c +++ b/gnu/usr.bin/grep/obstack.c @@ -1,24 +1,23 @@ -/* obstack.h - object stack macros - Copyright (C) 1988,89,90,91,92,93,94,96,97, 98 Free Software Foundation, Inc. +/* obstack.c - subroutines used implicitly by object stack macros + Copyright (C) 1988-1994,96,97,98,99 Free Software Foundation, Inc. + This file is part of the GNU C Library. Its master source is NOT part of the C library, however. The master source lives in /gd/gnu/lib. -NOTE: The canonical source of this file is maintained with the -GNU C Library. Bugs can be reported to bug-glibc@prep.ai.mit.edu. + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. -This program is free software; you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) any -later version. + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software Foundation, -Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ #ifdef HAVE_CONFIG_H #include @@ -79,7 +78,9 @@ union fooround {long x; double d;}; /* The functions allocating more room by calling `obstack_chunk_alloc' jump to the handler pointed to by `obstack_alloc_failed_handler'. - This variable by default points to the internal function + This can be set to a user defined function which should either + abort gracefully or use longjump - but shouldn't return. This + variable by default points to the internal function `print_and_abort'. */ #if defined (__STDC__) && __STDC__ static void print_and_abort (void); @@ -143,9 +144,8 @@ struct obstack *_obstack; CHUNKFUN is the function to use to allocate chunks, and FREEFUN the function to free them. - Return nonzero if successful, zero if out of memory. - To recover from an out of memory error, - free up some memory, then call this again. */ + Return nonzero if successful, calls obstack_alloc_failed_handler if + allocation fails. */ int _obstack_begin (h, size, alignment, chunkfun, freefun) @@ -460,11 +460,16 @@ _obstack_memory_used (h) # define _(Str) (Str) # endif #endif +#if defined _LIBC && defined USE_IN_LIBIO +# include +# define fputs(s, f) _IO_fputs (s, f) +#endif static void print_and_abort () { - fputs (_("memory exhausted\n"), stderr); + fputs (_("memory exhausted"), stderr); + fputc ('\n', stderr); exit (obstack_exit_failure); } diff --git a/gnu/usr.bin/grep/obstack.h b/gnu/usr.bin/grep/obstack.h index 5c03f68fe4ba..4d49ce024b15 100644 --- a/gnu/usr.bin/grep/obstack.h +++ b/gnu/usr.bin/grep/obstack.h @@ -1,24 +1,23 @@ /* obstack.h - object stack macros - Copyright (C) 1988,89,90,91,92,93,94,96,97, 98 Free Software Foundation, Inc. + Copyright (C) 1988,89,90,91,92,93,94,96,97,98,99 Free Software Foundation, Inc. + This file is part of the GNU C Library. Its master source is NOT part of the C library, however. The master source lives in /gd/gnu/lib. -NOTE: The canonical source of this file is maintained with the -GNU C Library. Bugs can be reported to bug-glibc@prep.ai.mit.edu. + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. -This program is free software; you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 2, or (at your option) any -later version. + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software Foundation, -Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ /* Summary: @@ -117,45 +116,39 @@ extern "C" { may ignore the byte-within-word field of the pointer. */ #ifndef __PTR_TO_INT -#define __PTR_TO_INT(P) ((P) - (char *) 0) +# define __PTR_TO_INT(P) ((P) - (char *) 0) #endif #ifndef __INT_TO_PTR -#define __INT_TO_PTR(P) ((P) + (char *) 0) +# define __INT_TO_PTR(P) ((P) + (char *) 0) #endif -/* We need the type of the resulting object. In ANSI C it is ptrdiff_t - but in traditional C it is usually long. If we are in ANSI C and - don't already have ptrdiff_t get it. */ +/* We need the type of the resulting object. If __PTRDIFF_TYPE__ is + defined, as with GNU C, use that; that way we don't pollute the + namespace with 's symbols. Otherwise, if is + available, include it and use ptrdiff_t. In traditional C, long is + the best that we can do. */ -#if defined (__STDC__) && __STDC__ && ! defined (offsetof) -#if defined (__GNUC__) && defined (IN_GCC) -/* On Next machine, the system's stddef.h screws up if included - after we have defined just ptrdiff_t, so include all of stddef.h. - Otherwise, define just ptrdiff_t, which is all we need. */ -#ifndef __NeXT__ -#define __need_ptrdiff_t -#endif -#endif - -#include -#endif - -#if defined (__STDC__) && __STDC__ -#define PTR_INT_TYPE ptrdiff_t +#ifdef __PTRDIFF_TYPE__ +# define PTR_INT_TYPE __PTRDIFF_TYPE__ #else -#define PTR_INT_TYPE long +# ifdef HAVE_STDDEF_H +# include +# define PTR_INT_TYPE ptrdiff_t +# else +# define PTR_INT_TYPE long +# endif #endif -#if defined (_LIBC) || defined (HAVE_STRING_H) -#include -#define _obstack_memcpy(To, From, N) memcpy ((To), (From), (N)) +#if defined _LIBC || defined HAVE_STRING_H +# include +# define _obstack_memcpy(To, From, N) memcpy ((To), (From), (N)) #else -#ifdef memcpy -#define _obstack_memcpy(To, From, N) memcpy ((To), (From), (N)) -#else -#define _obstack_memcpy(To, From, N) bcopy ((From), (To), (N)) -#endif +# ifdef memcpy +# define _obstack_memcpy(To, From, N) memcpy ((To), (From), (N)) +# else +# define _obstack_memcpy(To, From, N) bcopy ((From), (To), (N)) +# endif #endif struct _obstack_chunk /* Lives at front of each chunk. */ @@ -174,7 +167,7 @@ struct obstack /* control current object in current chunk */ char *chunk_limit; /* address of char after current chunk */ PTR_INT_TYPE temp; /* Temporary for some macros. */ int alignment_mask; /* Mask of alignment for each object. */ -#if defined (__STDC__) && __STDC__ +#if defined __STDC__ && __STDC__ /* These prototypes vary based on `use_extra_arg', and we use casts to the prototypeless function type in all assignments, but having prototypes here quiets -Wstrict-prototypes. */ @@ -198,7 +191,7 @@ struct obstack /* control current object in current chunk */ /* Declare the external functions we use; they are in obstack.c. */ -#if defined (__STDC__) && __STDC__ +#if defined __STDC__ && __STDC__ extern void _obstack_newchunk (struct obstack *, int); extern void _obstack_free (struct obstack *, void *); extern int _obstack_begin (struct obstack *, int, int, @@ -215,7 +208,7 @@ extern int _obstack_begin_1 (); extern int _obstack_memory_used (); #endif -#if defined (__STDC__) && __STDC__ +#if defined __STDC__ && __STDC__ /* Do the function-declarations after the structs but before defining the macros. */ @@ -261,9 +254,10 @@ int obstack_memory_used (struct obstack *obstack); so we do not declare them. */ /* Error handler called when `obstack_chunk_alloc' failed to allocate - more memory. This can be set to a user defined function. The - default action is to print a message and abort. */ -#if defined (__STDC__) && __STDC__ + more memory. This can be set to a user defined function which + should either abort gracefully or use longjump - but shouldn't + return. The default action is to print a message and abort. */ +#if defined __STDC__ && __STDC__ extern void (*obstack_alloc_failed_handler) (void); #else extern void (*obstack_alloc_failed_handler) (); @@ -292,53 +286,53 @@ extern int obstack_exit_failure; /* To prevent prototype warnings provide complete argument list in standard C version. */ -#if defined (__STDC__) && __STDC__ +#if defined __STDC__ && __STDC__ -#define obstack_init(h) \ +# define obstack_init(h) \ _obstack_begin ((h), 0, 0, \ (void *(*) (long)) obstack_chunk_alloc, (void (*) (void *)) obstack_chunk_free) -#define obstack_begin(h, size) \ +# define obstack_begin(h, size) \ _obstack_begin ((h), (size), 0, \ (void *(*) (long)) obstack_chunk_alloc, (void (*) (void *)) obstack_chunk_free) -#define obstack_specify_allocation(h, size, alignment, chunkfun, freefun) \ +# define obstack_specify_allocation(h, size, alignment, chunkfun, freefun) \ _obstack_begin ((h), (size), (alignment), \ (void *(*) (long)) (chunkfun), (void (*) (void *)) (freefun)) -#define obstack_specify_allocation_with_arg(h, size, alignment, chunkfun, freefun, arg) \ +# define obstack_specify_allocation_with_arg(h, size, alignment, chunkfun, freefun, arg) \ _obstack_begin_1 ((h), (size), (alignment), \ (void *(*) (void *, long)) (chunkfun), \ (void (*) (void *, void *)) (freefun), (arg)) -#define obstack_chunkfun(h, newchunkfun) \ +# define obstack_chunkfun(h, newchunkfun) \ ((h) -> chunkfun = (struct _obstack_chunk *(*)(void *, long)) (newchunkfun)) -#define obstack_freefun(h, newfreefun) \ +# define obstack_freefun(h, newfreefun) \ ((h) -> freefun = (void (*)(void *, struct _obstack_chunk *)) (newfreefun)) #else -#define obstack_init(h) \ +# define obstack_init(h) \ _obstack_begin ((h), 0, 0, \ (void *(*) ()) obstack_chunk_alloc, (void (*) ()) obstack_chunk_free) -#define obstack_begin(h, size) \ +# define obstack_begin(h, size) \ _obstack_begin ((h), (size), 0, \ (void *(*) ()) obstack_chunk_alloc, (void (*) ()) obstack_chunk_free) -#define obstack_specify_allocation(h, size, alignment, chunkfun, freefun) \ +# define obstack_specify_allocation(h, size, alignment, chunkfun, freefun) \ _obstack_begin ((h), (size), (alignment), \ (void *(*) ()) (chunkfun), (void (*) ()) (freefun)) -#define obstack_specify_allocation_with_arg(h, size, alignment, chunkfun, freefun, arg) \ +# define obstack_specify_allocation_with_arg(h, size, alignment, chunkfun, freefun, arg) \ _obstack_begin_1 ((h), (size), (alignment), \ (void *(*) ()) (chunkfun), (void (*) ()) (freefun), (arg)) -#define obstack_chunkfun(h, newchunkfun) \ +# define obstack_chunkfun(h, newchunkfun) \ ((h) -> chunkfun = (struct _obstack_chunk *(*)()) (newchunkfun)) -#define obstack_freefun(h, newfreefun) \ +# define obstack_freefun(h, newfreefun) \ ((h) -> freefun = (void (*)()) (newfreefun)) #endif @@ -349,30 +343,30 @@ extern int obstack_exit_failure; #define obstack_memory_used(h) _obstack_memory_used (h) -#if defined (__GNUC__) && defined (__STDC__) && __STDC__ +#if defined __GNUC__ && defined __STDC__ && __STDC__ /* NextStep 2.0 cc is really gcc 1.93 but it defines __GNUC__ = 2 and does not implement __extension__. But that compiler doesn't define __GNUC_MINOR__. */ -#if __GNUC__ < 2 || (__NeXT__ && !__GNUC_MINOR__) -#define __extension__ -#endif +# if __GNUC__ < 2 || (__NeXT__ && !__GNUC_MINOR__) +# define __extension__ +# endif /* For GNU C, if not -traditional, we can define these macros to compute all args only once without using a global variable. Also, we can avoid using the `temp' slot, to make faster code. */ -#define obstack_object_size(OBSTACK) \ +# define obstack_object_size(OBSTACK) \ __extension__ \ ({ struct obstack *__o = (OBSTACK); \ (unsigned) (__o->next_free - __o->object_base); }) -#define obstack_room(OBSTACK) \ +# define obstack_room(OBSTACK) \ __extension__ \ ({ struct obstack *__o = (OBSTACK); \ (unsigned) (__o->chunk_limit - __o->next_free); }) -#define obstack_make_room(OBSTACK,length) \ +# define obstack_make_room(OBSTACK,length) \ __extension__ \ ({ struct obstack *__o = (OBSTACK); \ int __len = (length); \ @@ -380,7 +374,12 @@ __extension__ \ _obstack_newchunk (__o, __len); \ (void) 0; }) -#define obstack_grow(OBSTACK,where,length) \ +# define obstack_empty_p(OBSTACK) \ + __extension__ \ + ({ struct obstack *__o = (OBSTACK); \ + (__o->chunk->prev == 0 && __o->next_free - __o->chunk->contents == 0); }) + +# define obstack_grow(OBSTACK,where,length) \ __extension__ \ ({ struct obstack *__o = (OBSTACK); \ int __len = (length); \ @@ -390,7 +389,7 @@ __extension__ \ __o->next_free += __len; \ (void) 0; }) -#define obstack_grow0(OBSTACK,where,length) \ +# define obstack_grow0(OBSTACK,where,length) \ __extension__ \ ({ struct obstack *__o = (OBSTACK); \ int __len = (length); \ @@ -401,7 +400,7 @@ __extension__ \ *(__o->next_free)++ = 0; \ (void) 0; }) -#define obstack_1grow(OBSTACK,datum) \ +# define obstack_1grow(OBSTACK,datum) \ __extension__ \ ({ struct obstack *__o = (OBSTACK); \ if (__o->next_free + 1 > __o->chunk_limit) \ @@ -413,7 +412,7 @@ __extension__ \ and that the data added so far to the current object shares that much alignment. */ -#define obstack_ptr_grow(OBSTACK,datum) \ +# define obstack_ptr_grow(OBSTACK,datum) \ __extension__ \ ({ struct obstack *__o = (OBSTACK); \ if (__o->next_free + sizeof (void *) > __o->chunk_limit) \ @@ -421,7 +420,7 @@ __extension__ \ *((void **)__o->next_free)++ = ((void *)datum); \ (void) 0; }) -#define obstack_int_grow(OBSTACK,datum) \ +# define obstack_int_grow(OBSTACK,datum) \ __extension__ \ ({ struct obstack *__o = (OBSTACK); \ if (__o->next_free + sizeof (int) > __o->chunk_limit) \ @@ -429,10 +428,10 @@ __extension__ \ *((int *)__o->next_free)++ = ((int)datum); \ (void) 0; }) -#define obstack_ptr_grow_fast(h,aptr) (*((void **) (h)->next_free)++ = (void *)aptr) -#define obstack_int_grow_fast(h,aint) (*((int *) (h)->next_free)++ = (int) aint) +# define obstack_ptr_grow_fast(h,aptr) (*((void **) (h)->next_free)++ = (void *)aptr) +# define obstack_int_grow_fast(h,aint) (*((int *) (h)->next_free)++ = (int) aint) -#define obstack_blank(OBSTACK,length) \ +# define obstack_blank(OBSTACK,length) \ __extension__ \ ({ struct obstack *__o = (OBSTACK); \ int __len = (length); \ @@ -441,19 +440,19 @@ __extension__ \ __o->next_free += __len; \ (void) 0; }) -#define obstack_alloc(OBSTACK,length) \ +# define obstack_alloc(OBSTACK,length) \ __extension__ \ ({ struct obstack *__h = (OBSTACK); \ obstack_blank (__h, (length)); \ obstack_finish (__h); }) -#define obstack_copy(OBSTACK,where,length) \ +# define obstack_copy(OBSTACK,where,length) \ __extension__ \ ({ struct obstack *__h = (OBSTACK); \ obstack_grow (__h, (where), (length)); \ obstack_finish (__h); }) -#define obstack_copy0(OBSTACK,where,length) \ +# define obstack_copy0(OBSTACK,where,length) \ __extension__ \ ({ struct obstack *__h = (OBSTACK); \ obstack_grow0 (__h, (where), (length)); \ @@ -461,7 +460,7 @@ __extension__ \ /* The local variable is named __o1 to avoid a name conflict when obstack_blank is called. */ -#define obstack_finish(OBSTACK) \ +# define obstack_finish(OBSTACK) \ __extension__ \ ({ struct obstack *__o1 = (OBSTACK); \ void *value; \ @@ -477,41 +476,44 @@ __extension__ \ __o1->object_base = __o1->next_free; \ value; }) -#define obstack_free(OBSTACK, OBJ) \ +# define obstack_free(OBSTACK, OBJ) \ __extension__ \ ({ struct obstack *__o = (OBSTACK); \ void *__obj = (OBJ); \ if (__obj > (void *)__o->chunk && __obj < (void *)__o->chunk_limit) \ - __o->next_free = __o->object_base = __obj; \ + __o->next_free = __o->object_base = (char *)__obj; \ else (obstack_free) (__o, __obj); }) #else /* not __GNUC__ or not __STDC__ */ -#define obstack_object_size(h) \ +# define obstack_object_size(h) \ (unsigned) ((h)->next_free - (h)->object_base) -#define obstack_room(h) \ +# define obstack_room(h) \ (unsigned) ((h)->chunk_limit - (h)->next_free) +# define obstack_empty_p(h) \ + ((h)->chunk->prev == 0 && (h)->next_free - (h)->chunk->contents == 0) + /* Note that the call to _obstack_newchunk is enclosed in (..., 0) so that we can avoid having void expressions in the arms of the conditional expression. Casting the third operand to void was tried before, but some compilers won't accept it. */ -#define obstack_make_room(h,length) \ +# define obstack_make_room(h,length) \ ( (h)->temp = (length), \ (((h)->next_free + (h)->temp > (h)->chunk_limit) \ ? (_obstack_newchunk ((h), (h)->temp), 0) : 0)) -#define obstack_grow(h,where,length) \ +# define obstack_grow(h,where,length) \ ( (h)->temp = (length), \ (((h)->next_free + (h)->temp > (h)->chunk_limit) \ ? (_obstack_newchunk ((h), (h)->temp), 0) : 0), \ _obstack_memcpy ((h)->next_free, (char *) (where), (h)->temp), \ (h)->next_free += (h)->temp) -#define obstack_grow0(h,where,length) \ +# define obstack_grow0(h,where,length) \ ( (h)->temp = (length), \ (((h)->next_free + (h)->temp + 1 > (h)->chunk_limit) \ ? (_obstack_newchunk ((h), (h)->temp + 1), 0) : 0), \ @@ -519,40 +521,40 @@ __extension__ \ (h)->next_free += (h)->temp, \ *((h)->next_free)++ = 0) -#define obstack_1grow(h,datum) \ +# define obstack_1grow(h,datum) \ ( (((h)->next_free + 1 > (h)->chunk_limit) \ ? (_obstack_newchunk ((h), 1), 0) : 0), \ (*((h)->next_free)++ = (datum))) -#define obstack_ptr_grow(h,datum) \ +# define obstack_ptr_grow(h,datum) \ ( (((h)->next_free + sizeof (char *) > (h)->chunk_limit) \ ? (_obstack_newchunk ((h), sizeof (char *)), 0) : 0), \ (*((char **) (((h)->next_free+=sizeof(char *))-sizeof(char *))) = ((char *) datum))) -#define obstack_int_grow(h,datum) \ +# define obstack_int_grow(h,datum) \ ( (((h)->next_free + sizeof (int) > (h)->chunk_limit) \ ? (_obstack_newchunk ((h), sizeof (int)), 0) : 0), \ (*((int *) (((h)->next_free+=sizeof(int))-sizeof(int))) = ((int) datum))) -#define obstack_ptr_grow_fast(h,aptr) (*((char **) (h)->next_free)++ = (char *) aptr) -#define obstack_int_grow_fast(h,aint) (*((int *) (h)->next_free)++ = (int) aint) +# define obstack_ptr_grow_fast(h,aptr) (*((char **) (h)->next_free)++ = (char *) aptr) +# define obstack_int_grow_fast(h,aint) (*((int *) (h)->next_free)++ = (int) aint) -#define obstack_blank(h,length) \ +# define obstack_blank(h,length) \ ( (h)->temp = (length), \ (((h)->chunk_limit - (h)->next_free < (h)->temp) \ ? (_obstack_newchunk ((h), (h)->temp), 0) : 0), \ ((h)->next_free += (h)->temp)) -#define obstack_alloc(h,length) \ +# define obstack_alloc(h,length) \ (obstack_blank ((h), (length)), obstack_finish ((h))) -#define obstack_copy(h,where,length) \ +# define obstack_copy(h,where,length) \ (obstack_grow ((h), (where), (length)), obstack_finish ((h))) -#define obstack_copy0(h,where,length) \ +# define obstack_copy0(h,where,length) \ (obstack_grow0 ((h), (where), (length)), obstack_finish ((h))) -#define obstack_finish(h) \ +# define obstack_finish(h) \ ( ((h)->next_free == (h)->object_base \ ? (((h)->maybe_empty_object = 1), 0) \ : 0), \ @@ -566,21 +568,21 @@ __extension__ \ (h)->object_base = (h)->next_free, \ __INT_TO_PTR ((h)->temp)) -#if defined (__STDC__) && __STDC__ -#define obstack_free(h,obj) \ +# if defined __STDC__ && __STDC__ +# define obstack_free(h,obj) \ ( (h)->temp = (char *) (obj) - (char *) (h)->chunk, \ (((h)->temp > 0 && (h)->temp < (h)->chunk_limit - (char *) (h)->chunk)\ ? (int) ((h)->next_free = (h)->object_base \ = (h)->temp + (char *) (h)->chunk) \ : (((obstack_free) ((h), (h)->temp + (char *) (h)->chunk), 0), 0))) -#else -#define obstack_free(h,obj) \ +# else +# define obstack_free(h,obj) \ ( (h)->temp = (char *) (obj) - (char *) (h)->chunk, \ (((h)->temp > 0 && (h)->temp < (h)->chunk_limit - (char *) (h)->chunk)\ ? (int) ((h)->next_free = (h)->object_base \ = (h)->temp + (char *) (h)->chunk) \ : (_obstack_free ((h), (h)->temp + (char *) (h)->chunk), 0))) -#endif +# endif #endif /* not __GNUC__ or not __STDC__ */ diff --git a/gnu/usr.bin/grep/savedir.c b/gnu/usr.bin/grep/savedir.c index e329717b953b..29b3842c0402 100644 --- a/gnu/usr.bin/grep/savedir.c +++ b/gnu/usr.bin/grep/savedir.c @@ -76,9 +76,7 @@ char *stpcpy (); Return NULL if DIR cannot be opened or if out of memory. */ char * -savedir (dir, name_size) - const char *dir; - unsigned int name_size; +savedir (const char *dir, off_t name_size) { DIR *dirp; struct dirent *dp; @@ -108,7 +106,7 @@ savedir (dir, name_size) || (dp->d_name[1] != '\0' && (dp->d_name[1] != '.' || dp->d_name[2] != '\0'))) { - unsigned size_needed = (namep - name_space) + NAMLEN (dp) + 2; + off_t size_needed = (namep - name_space) + NAMLEN (dp) + 2; if (size_needed > name_size) { diff --git a/gnu/usr.bin/grep/savedir.h b/gnu/usr.bin/grep/savedir.h index 033e56752d06..89be04d0238b 100644 --- a/gnu/usr.bin/grep/savedir.h +++ b/gnu/usr.bin/grep/savedir.h @@ -10,6 +10,6 @@ # endif char * -savedir PARAMS ((const char *dir, unsigned int name_size)); +savedir PARAMS ((const char *dir, off_t name_size)); #endif diff --git a/gnu/usr.bin/grep/search.c b/gnu/usr.bin/grep/search.c index 8fb3af0ab3d6..4f18bbee5805 100644 --- a/gnu/usr.bin/grep/search.c +++ b/gnu/usr.bin/grep/search.c @@ -67,14 +67,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; @@ -92,7 +91,7 @@ kwsinit() to find those strings, and thus quickly filter out impossible matches. */ static void -kwsmusts() +kwsmusts (void) { struct dfamust *dm; char *err; @@ -126,9 +125,7 @@ kwsmusts() } static void -Gcompile(pattern, size) - char *pattern; - size_t size; +Gcompile (char *pattern, size_t size) { const char *err; @@ -180,9 +177,7 @@ Gcompile(pattern, size) } static void -Ecompile(pattern, size) - char *pattern; - size_t size; +Ecompile (char *pattern, size_t size) { const char *err; @@ -242,10 +237,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; @@ -355,9 +347,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; @@ -380,10 +370,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; diff --git a/gnu/usr.bin/grep/stpcpy.c b/gnu/usr.bin/grep/stpcpy.c index 380e65f7dcc2..a01636cd1c60 100644 --- a/gnu/usr.bin/grep/stpcpy.c +++ b/gnu/usr.bin/grep/stpcpy.c @@ -34,9 +34,7 @@ /* Copy SRC to DEST, returning the address of the terminating '\0' in DEST. */ char * -__stpcpy (dest, src) - char *dest; - const char *src; +__stpcpy (char *dest, const char *src) { register char *d = dest; register const char *s = src;