[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-grep] egrep and fgrep script assume path
From: |
Paul Eggert |
Subject: |
Re: [bug-grep] egrep and fgrep script assume path |
Date: |
Fri, 28 Jan 2005 21:42:27 -0800 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) |
Stepan Kasal <address@hidden> writes:
> I propose to install the patch attached to this mail.
How about the enclosed patch instead? It fixes the whole problem of
the GNU Coding Standards violation, instead of just some instances.
It does this by reverting to the previous implementation strategy
(e.g., it resurrects the files egrepmat.c and fgrepmat.c from the CVS
archive). This strategy doesn't rely on shell scripting at run-time,
so it is more conservative and reliable. Also, it simplifies the
code: overall, it subtracts about 30 lines. The downside is that it
generates three full-size executables instead of one, but this minor
efficiency problem is no big deal these days.
2005-01-28 Paul Eggert <address@hidden>
Change "grep", "fgrep", and "egrep" so that they don't
behave on the names that they are invoked by, as required
by the GNU coding standards.
* src/Makefile.am (bin_PROGRAMS): Add egrep, fgrep.
(bin_SCRIPTS, CLEANFILES, OPTION_for_egrep, OPTION_for_fgrep,
egrep, fgrep): Remove.
(base_sources, egrep_SOURCES, fgrep_SOURCES): New macro.
(grep_SOURCES): Use base_sources.
* src/grep.c (setmatcher): Use static boolean to test whether
it has already been set.
(main): Do not let behavior depend on the name of the program.
Remove a test for !matcher, since matcher is always nonnull now.
* src/grepmat.c (matcher): Initialize to "grep".
* src/egrepmat.c, src/fgrepmat.c: Resurrect these files from the
attic.
Index: src/Makefile.am
===================================================================
RCS file: /cvsroot/grep/grep/src/Makefile.am,v
retrieving revision 1.32
diff -p -u -r1.32 Makefile.am
--- src/Makefile.am 23 Nov 2004 12:49:36 -0000 1.32
+++ src/Makefile.am 29 Jan 2005 05:28:12 -0000
@@ -3,11 +3,11 @@ AUTOMAKE_OPTIONS = ansi2knr no-dependenc
LN = ln
-bin_PROGRAMS = grep
-bin_SCRIPTS = egrep fgrep
-CLEANFILES = egrep fgrep
-grep_SOURCES = grep.c dfa.c kwset.c search.c \
- grepmat.c
+bin_PROGRAMS = grep egrep fgrep
+base_sources = grep.c dfa.c kwset.c search.c
+egrep_SOURCES = $(base_sources) egrepmat.c
+fgrep_SOURCES = $(base_sources) fgrepmat.c
+grep_SOURCES = $(base_sources) grepmat.c
noinst_HEADERS = grep.h dfa.h kwset.h getpagesize.h system.h mbsupport.h
LDADD = @INTLLIBS@ ../lib/libgreputils.a
@@ -18,15 +18,3 @@ INCLUDES = -I../intl -I$(top_srcdir)/lib
EXTRA_DIST = \
dosbuf.c \
vms_fab.c vms_fab.h
-
-OPTION_for_egrep = -E
-OPTION_for_fgrep = -F
-
-egrep fgrep: Makefile
- (echo '#!/bin/sh'; \
- echo 'case $$0 in' ; \
- echo ' */*) dir=$${0%/*}/ ;;' ; \
- echo ' *) dir="" ;;' ; \
- echo 'esac' ; \
- echo 'exec $${dir}grep $(OPTION_for_$@) $${1+"$$@"}' ) >$@
- chmod a+x $@
Index: src/grep.c
===================================================================
RCS file: /cvsroot/grep/grep/src/grep.c,v
retrieving revision 1.91
diff -p -u -r1.91 grep.c
--- src/grep.c 16 Dec 2004 08:19:29 -0000 1.91
+++ src/grep.c 29 Jan 2005 05:28:12 -0000
@@ -1171,9 +1171,11 @@ if any error occurs and -q was not given
static void
setmatcher (char const *m)
{
- if (matcher && strcmp (matcher, m) != 0)
+ static int matcher_is_set;
+ if (matcher_is_set && strcmp (matcher, m) != 0)
error (2, 0, _("conflicting matchers specified"));
matcher = m;
+ matcher_is_set = 1;
}
/* Go through the matchers vector and look for the specified matcher.
@@ -1330,38 +1332,6 @@ main (int argc, char **argv)
initialize_main (&argc, &argv);
program_name = argv[0];
- if (program_name && strrchr (program_name, '/'))
- program_name = strrchr (program_name, '/') + 1;
-
- if (!strcmp(program_name, "egrep"))
- setmatcher ("egrep");
- if (!strcmp(program_name, "fgrep"))
- setmatcher ("fgrep");
-
-#if defined(__MSDOS__) || defined(_WIN32)
- /* DOS and MS-Windows use backslashes as directory separators, and usually
- have an .exe suffix. They also have case-insensitive filesystems. */
- if (program_name)
- {
- char *p = program_name;
- char *bslash = strrchr (argv[0], '\\');
-
- if (bslash && bslash >= program_name) /* for mixed forward/backslash
case */
- program_name = bslash + 1;
- else if (program_name == argv[0]
- && argv[0][0] && argv[0][1] == ':') /* "c:progname" */
- program_name = argv[0] + 2;
-
- /* Collapse the letter-case, so `strcmp' could be used hence. */
- for ( ; *p; p++)
- if (*p >= 'A' && *p <= 'Z')
- *p += 'a' - 'A';
-
- /* Remove the .exe extension, if any. */
- if ((p = strrchr (program_name, '.')) && strcmp (p, ".exe") == 0)
- *p = '\0';
- }
-#endif
keys = NULL;
keycc = 0;
@@ -1693,9 +1663,6 @@ main (int argc, char **argv)
grep_color = userval;
}
- if (! matcher)
- matcher = "grep";
-
if (show_version)
{
printf ("%s\n\n", PACKAGE_STRING);
Index: src/grepmat.c
===================================================================
RCS file: /cvsroot/grep/grep/src/grepmat.c,v
retrieving revision 1.3
diff -p -u -r1.3 grepmat.c
--- src/grepmat.c 6 Oct 1999 01:13:13 -0000 1.3
+++ src/grepmat.c 29 Jan 2005 05:28:12 -0000
@@ -3,4 +3,4 @@
#endif
#include "system.h"
#include "grep.h"
-char const *matcher;
+char const *matcher = "grep";
--- /dev/null 2003-03-18 13:55:57 -0800
+++ src/egrepmat.c 2005-01-28 20:09:09 -0800
@@ -0,0 +1,6 @@
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include "system.h"
+#include "grep.h"
+char const *matcher = "egrep";
--- /dev/null 2003-03-18 13:55:57 -0800
+++ src/fgrepmat.c 2005-01-28 20:09:09 -0800
@@ -0,0 +1,6 @@
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include "system.h"
+#include "grep.h"
+char const *matcher = "fgrep";
- Re: [bug-grep] egrep and fgrep script assume path, (continued)
- Re: [bug-grep] egrep and fgrep script assume path, Paul Jarc, 2005/01/27
- Re: [bug-grep] egrep and fgrep script assume path, Stepan Kasal, 2005/01/26
- Re: [bug-grep] egrep and fgrep script assume path, Paul Jarc, 2005/01/27
- Re: [bug-grep] egrep and fgrep script assume path, Stepan Kasal, 2005/01/27
- Re: [bug-grep] egrep and fgrep script assume path, Paul Jarc, 2005/01/27
- Re: [bug-grep] egrep and fgrep script assume path, Stepan Kasal, 2005/01/27
- Re: [bug-grep] egrep and fgrep script assume path, Paul Jarc, 2005/01/27
- Re: [bug-grep] egrep and fgrep script assume path, Stepan Kasal, 2005/01/27
- Re: [bug-grep] egrep and fgrep script assume path, Paul Eggert, 2005/01/27
- Re: [bug-grep] egrep and fgrep script assume path, Stepan Kasal, 2005/01/28
- Re: [bug-grep] egrep and fgrep script assume path,
Paul Eggert <=
- Re: [bug-grep] egrep and fgrep script assume path, Stepan Kasal, 2005/01/29
- Re: [bug-grep] egrep and fgrep script assume path, Paul Eggert, 2005/01/31
Re: [bug-grep] egrep and fgrep script assume path, Aharon Robbins, 2005/01/27