diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2020-11-03 11:09:47 -0800 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2020-11-03 11:09:47 -0800 |
commit | 790be1fb2a5949277ccc89f8a1c9c49733045d85 (patch) | |
tree | 488de6cc3ef46b7d41b91ae529525eb366ec9e91 | |
parent | ffc6e407e3657598702ba24ab1ba3a6b8ab253ea (diff) | |
download | grep-790be1fb2a5949277ccc89f8a1c9c49733045d85.tar.gz |
grep: remove GREP_OPTIONS
* NEWS: Mention this.
* doc/grep.in.1:
Remove GREP_OPTIONS documentation.
* doc/grep.texi (Environment Variables):
Move GREP_OPTIONS stuff into a “no longer implemented” paragraph.
* src/grep.c (prepend_args, prepend_default_options): Remove.
(main): Do not look at GREP_OPTIONS.
* tests/Makefile.am (TESTS_ENVIRONMENTS):
* tests/init.cfg (vars_): Remove GREP_OPTIONS.
-rw-r--r-- | NEWS | 6 | ||||
-rw-r--r-- | doc/grep.in.1 | 11 | ||||
-rw-r--r-- | doc/grep.texi | 32 | ||||
-rw-r--r-- | src/grep.c | 69 | ||||
-rw-r--r-- | tests/Makefile.am | 1 | ||||
-rw-r--r-- | tests/init.cfg | 1 |
6 files changed, 22 insertions, 98 deletions
@@ -2,6 +2,12 @@ GNU grep NEWS -*- outline -*- * Noteworthy changes in release ?.? (????-??-??) [?] +** Changes in behavior + + The GREP_OPTIONS environment variable no longer affects grep's behavior. + The variable was declared obsolescent in grep 2.21 (2014), and since + then any use had caused grep to issue a diagnostic. + ** Bug fixes grep's DFA matcher performed an invalid regex transformation diff --git a/doc/grep.in.1 b/doc/grep.in.1 index 7d5dfe5a..c56c4040 100644 --- a/doc/grep.in.1 +++ b/doc/grep.in.1 @@ -1001,17 +1001,6 @@ The shell command .B "locale \-a" lists locales that are currently available. .TP -.B GREP_OPTIONS -This variable specifies default options -to be placed in front of any explicit options. -As this causes problems when writing portable scripts, -this feature will be removed in a future release of -.BR grep , -and -.B grep -warns if it is used. -Please use an alias or script instead. -.TP .B GREP_COLOR This variable specifies the color used to highlight matched (non-empty) text. It is deprecated in favor of diff --git a/doc/grep.texi b/doc/grep.texi index 0c0bb124..fce36cdf 100644 --- a/doc/grep.texi +++ b/doc/grep.texi @@ -887,24 +887,6 @@ the @code{terminfo} library. @table @env -@item GREP_OPTIONS -@vindex GREP_OPTIONS @r{environment variable} -@cindex default options environment variable -This variable specifies default options to be placed in front of any -explicit options. -As this causes problems when writing portable scripts, this feature -will be removed in a future release of @command{grep}, and @command{grep} -warns if it is used. Please use an alias or script instead. -For example, if @command{grep} is in the directory @samp{/usr/bin} you -can prepend @file{$HOME/bin} to your @env{PATH} and create an -executable script @file{$HOME/bin/grep} containing the following: - -@example -#! /bin/sh -export PATH=/usr/bin -exec grep --color=auto --devices=skip "$@@" -@end example - @item GREP_COLOR @vindex GREP_COLOR @r{environment variable} @cindex highlight markers @@ -1097,6 +1079,20 @@ and only when @env{POSIXLY_CORRECT} is not set. @end table +The @env{GREP_OPTIONS} environment variable of @command{grep} 2.20 and +earlier is no longer supported, as it caused problems when writing +portable scripts. To make arbitrary changes to how @command{grep} +works, you can use an alias or script instead. For example, if +@command{grep} is in the directory @samp{/usr/bin} you can prepend +@file{$HOME/bin} to your @env{PATH} and create an executable script +@file{$HOME/bin/grep} containing the following: + +@example +#! /bin/sh +export PATH=/usr/bin +exec grep --color=auto --devices=skip "$@@" +@end example + @node Exit Status @section Exit Status @@ -2106,66 +2106,6 @@ setmatcher (char const *m, int matcher) die (EXIT_TROUBLE, 0, _("invalid matcher %s"), m); } -/* Find the white-space-separated options specified by OPTIONS, and - using BUF to store copies of these options, set ARGV[0], ARGV[1], - etc. to the option copies. Return the number N of options found. - 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 size_t -prepend_args (char const *options, char *buf, char **argv) -{ - char const *o = options; - char *b = buf; - size_t n = 0; - - for (;;) - { - while (c_isspace (to_uchar (*o))) - o++; - if (!*o) - return n; - if (argv) - argv[n] = b; - n++; - - do - if ((*b++ = *o++) == '\\' && *o) - b[-1] = *o++; - while (*o && ! c_isspace (to_uchar (*o))); - - *b++ = '\0'; - } -} - -/* Prepend the whitespace-separated options in OPTIONS to the argument - vector of a main program with argument count *PARGC and argument - vector *PARGV. Return the number of options prepended. */ -static int -prepend_default_options (char const *options, int *pargc, char ***pargv) -{ - if (options && *options) - { - char *buf = xmalloc (strlen (options) + 1); - size_t prepended = prepend_args (options, buf, NULL); - int argc = *pargc; - char *const *argv = *pargv; - char **pp; - enum { MAX_ARGS = MIN (INT_MAX, SIZE_MAX / sizeof *pp - 1) }; - if (MAX_ARGS - argc < prepended) - xalloc_die (); - pp = xmalloc ((prepended + argc + 1) * sizeof *pp); - *pargc = prepended + argc; - *pargv = pp; - *pp++ = *argv++; - pp += prepend_args (options, buf, pp); - while ((*pp++ = *argv++)) - continue; - return prepended; - } - - return 0; -} - /* Get the next non-digit option from ARGC and ARGV. Return -1 if there are no more options. Process any digit options that were encountered on the way, @@ -2530,7 +2470,7 @@ main (int argc, char **argv) char *keys = NULL; size_t keycc = 0, keyalloc = 0; int matcher = -1; - int opt, prepended; + int opt; int prev_optind, last_recursive; int fread_errno; intmax_t default_context; @@ -2574,11 +2514,6 @@ main (int argc, char **argv) if (!pattern_table) xalloc_die (); - prepended = prepend_default_options (getenv ("GREP_OPTIONS"), &argc, &argv); - if (prepended) - error (0, 0, _("warning: GREP_OPTIONS is deprecated;" - " please use an alias or script")); - while (prev_optind = optind, (opt = get_nondigit_option (argc, argv, &default_context)) != -1) switch (opt) @@ -3056,7 +2991,7 @@ main (int argc, char **argv) { files = argv + optind; } - else if (directories == RECURSE_DIRECTORIES && prepended < last_recursive) + else if (directories == RECURSE_DIRECTORIES && 0 < last_recursive) { static char *const cwd_only[] = { (char *) ".", NULL }; files = cwd_only; diff --git a/tests/Makefile.am b/tests/Makefile.am index cc55c7e3..480bfb47 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -237,7 +237,6 @@ TESTS_ENVIRONMENT = \ LOCALE_FR='$(LOCALE_FR)' \ LOCALE_FR_UTF8='$(LOCALE_FR_UTF8)' \ AWK=$(AWK) \ - GREP_OPTIONS='' \ LC_ALL=C \ abs_top_builddir='$(abs_top_builddir)' \ abs_top_srcdir='$(abs_top_srcdir)' \ diff --git a/tests/init.cfg b/tests/init.cfg index 0bd5aa21..4abe55ae 100644 --- a/tests/init.cfg +++ b/tests/init.cfg @@ -21,7 +21,6 @@ fi vars_=' GREP_COLOR GREP_COLORS -GREP_OPTIONS TERM ' envvar_check_fail=0 |