bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: grep-2.5.1a egrep/fgrep PATH problem


From: Paul Eggert
Subject: Re: grep-2.5.1a egrep/fgrep PATH problem
Date: Thu, 23 Jun 2005 17:04:29 -0700
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.4 (gnu/linux)

Charles Levert <address@hidden> writes:

> What do others on the list think?

We should go back to the way "grep" used to do this, before we broke it.
That is, we should use binaries by default.

I am partly responsible for this, because I introduced the wrappers
in the first place.  Sorry about that.

Can you please let me undo the damage I caused?  That is, how about if
you grant me write access to the grep repository, and let me install
the following change to revert to the old behavior.  We can improve on
this later if need be (e.g., by adding an installation-time option to
do non-conforming installations), but our first item of business ought
to be to conform to the GNU coding standards, and this patch does that.

2005-06-23  Paul Eggert  <address@hidden>

        * 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;
        as required by the GNU coding standards.
        Remove a test for !matcher, since matcher is always nonnull now.
        * src/grepmat.c (matcher): Initialize to "grep".
        * src/egrepmat.c, src/fgrepmat.c: New files.

Index: src/Makefile.am
===================================================================
RCS file: /cvsroot/grep/grep/src/Makefile.am,v
retrieving revision 1.33
diff -p -u -r1.33 Makefile.am
--- src/Makefile.am     23 Jun 2005 00:55:58 -0000      1.33
+++ src/Makefile.am     24 Jun 2005 00:02:28 -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.111
diff -p -u -r1.111 grep.c
--- src/grep.c  22 Jun 2005 01:47:43 -0000      1.111
+++ src/grep.c  24 Jun 2005 00:02:28 -0000
@@ -1458,9 +1458,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.
@@ -1702,38 +1704,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;
@@ -2081,9 +2051,6 @@ main (int argc, char **argv)
       parse_grep_colors();
     }
 
-  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       24 Jun 2005 00:02:28 -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-06-23 16:54:43 -0700
@@ -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-06-23 16:54:43 -0700
@@ -0,0 +1,6 @@
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include "system.h"
+#include "grep.h"
+char const *matcher = "fgrep";




reply via email to

[Prev in Thread] Current Thread [Next in Thread]