diff options
-rw-r--r-- | .x-sc_require_config_h | 2 | ||||
-rw-r--r-- | .x-sc_require_config_h_first | 2 | ||||
-rw-r--r-- | NEWS | 6 | ||||
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | po/POTFILES.in | 3 | ||||
-rw-r--r-- | src/Makefile.am | 14 | ||||
-rw-r--r-- | src/egrep.c | 2 | ||||
-rw-r--r-- | src/esearch.c | 4 | ||||
-rw-r--r-- | src/fgrep.c | 2 | ||||
-rw-r--r-- | src/fsearch.c | 4 | ||||
-rw-r--r-- | src/grep.c | 107 | ||||
-rw-r--r-- | src/grep.h | 11 | ||||
-rw-r--r-- | src/gsearch.c | 6 |
13 files changed, 76 insertions, 89 deletions
diff --git a/.x-sc_require_config_h b/.x-sc_require_config_h deleted file mode 100644 index c11a39bd..00000000 --- a/.x-sc_require_config_h +++ /dev/null @@ -1,2 +0,0 @@ -src/egrep.c -src/fgrep.c diff --git a/.x-sc_require_config_h_first b/.x-sc_require_config_h_first deleted file mode 100644 index c11a39bd..00000000 --- a/.x-sc_require_config_h_first +++ /dev/null @@ -1,2 +0,0 @@ -src/egrep.c -src/fgrep.c @@ -40,6 +40,12 @@ GNU grep NEWS -*- outline -*- --no-group-separator, enable further customization of the output when -A, -B or -C is being used. +** Other changes + + egrep accepts the -E option and fgrep accepts the -F option. If egrep + and fgrep are given another of the -E/-F/-G options, they print a more + meaningful error message. + * Noteworthy changes in release 2.5.4 (2009-02-10) [stable] - This is a bugfix release. No new features. @@ -28,8 +28,6 @@ Multithreading? GNU grep does 32-bit arithmetic, it needs to move to 64-bit (i.e. size_t/ptrdiff_t). -Clean up, too many #ifdefs! - Lazy dynamic linking of libpcre. Check FreeBSD's integration of zgrep (-Z) and bzgrep (-J) in one diff --git a/po/POTFILES.in b/po/POTFILES.in index e2454a0b..b047712d 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -27,4 +27,7 @@ src/dfa.c src/grep.c src/kwset.c src/dfasearch.c +src/esearch.c +src/fsearch.c +src/gsearch.c src/pcresearch.c diff --git a/src/Makefile.am b/src/Makefile.am index 65715290..a4f686fc 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -19,16 +19,16 @@ LN = ln AM_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS) bin_PROGRAMS = grep egrep fgrep -grep_SOURCES = grep.c gsearch.c -egrep_SOURCES = egrep.c esearch.c -fgrep_SOURCES = fgrep.c fsearch.c +grep_SOURCES = gsearch.c +egrep_SOURCES = esearch.c +fgrep_SOURCES = fsearch.c noinst_HEADERS = grep.h dfa.h kwset.h search.h system.h mbsupport.h -noinst_LIBRARIES = libsearch.a -libsearch_a_SOURCES = kwset.c dfa.c searchutils.c dfasearch.c kwsearch.c \ - pcresearch.c +noinst_LIBRARIES = libgrep.a +libgrep_a_SOURCES = kwset.c dfa.c searchutils.c dfasearch.c kwsearch.c \ + pcresearch.c grep.c -LDADD = $(LIBINTL) libsearch.a ../lib/libgreputils.a +LDADD = $(LIBINTL) libgrep.a ../lib/libgreputils.a grep_LDADD = $(LDADD) $(PCRE_LIBS) localedir = $(datadir)/locale INCLUDES = -I$(top_srcdir)/lib -DLOCALEDIR=\"$(localedir)\" diff --git a/src/egrep.c b/src/egrep.c deleted file mode 100644 index 1cabb4d8..00000000 --- a/src/egrep.c +++ /dev/null @@ -1,2 +0,0 @@ -#define EGREP_PROGRAM -#include "grep.c" diff --git a/src/esearch.c b/src/esearch.c index 647d2cbd..80595fe5 100644 --- a/src/esearch.c +++ b/src/esearch.c @@ -12,3 +12,7 @@ struct matcher const matchers[] = { { NULL, NULL, NULL }, }; +const char before_options[] = +N_("PATTERN is an extended regular expression (ERE).\n"); +const char after_options[] = +N_("Invocation as `egrep' is deprecated; use `grep -E' instead.\n"); diff --git a/src/fgrep.c b/src/fgrep.c deleted file mode 100644 index 43323101..00000000 --- a/src/fgrep.c +++ /dev/null @@ -1,2 +0,0 @@ -#define FGREP_PROGRAM -#include "grep.c" diff --git a/src/fsearch.c b/src/fsearch.c index a5244875..f91e6266 100644 --- a/src/fsearch.c +++ b/src/fsearch.c @@ -6,3 +6,7 @@ struct matcher const matchers[] = { { NULL, NULL, NULL }, }; +const char before_options[] = +N_("PATTERN is a set of newline-separated fixed strings.\n"); +const char after_options[] = +N_("Invocation as `fgrep' is deprecated; use `grep -F' instead.\n"); @@ -270,11 +270,7 @@ static struct exclude *included_patterns; static struct exclude *excluded_directory_patterns; /* Short options. */ static char const short_options[] = -"0123456789A:B:C:D:HITUVabcd:e:f:hiKLlm:noqRrsuvwxyZz" -#ifdef GREP_PROGRAM -"EFGPX:" -#endif -; +"0123456789A:B:C:D:EFGHIPTUVX:abcd:e:f:hiKLlm:noqRrsuvwxyZz"; /* Non-boolean long options that have no corresponding short equivalents. */ enum @@ -293,13 +289,11 @@ enum /* Long options equivalences. */ static struct option const long_options[] = { -#ifdef GREP_PROGRAM {"basic-regexp", no_argument, NULL, 'G'}, {"extended-regexp", no_argument, NULL, 'E'}, {"fixed-regexp", no_argument, NULL, 'F'}, {"fixed-strings", no_argument, NULL, 'F'}, {"perl-regexp", no_argument, NULL, 'P'}, -#endif {"after-context", required_argument, NULL, 'A'}, {"before-context", required_argument, NULL, 'B'}, {"binary-files", required_argument, NULL, BINARY_FILES_OPTION}, @@ -1454,28 +1448,18 @@ usage (int status) printf (_("Usage: %s [OPTION]... PATTERN [FILE]...\n"), program_name); printf (_("\ Search for PATTERN in each FILE or standard input.\n")); -#if defined(EGREP_PROGRAM) - printf (_("\ -PATTERN is an extended regular expression (ERE).\n")); -#elif defined(FGREP_PROGRAM) - printf (_("\ -PATTERN is a set of newline-separated fixed strings.\n")); -#else - printf (_("\ -PATTERN is, by default, a basic regular expression (BRE).\n")); -#endif /* ?GREP_PROGRAM */ + printf ("%s", gettext (before_options)); printf (_("\ Example: %s -i 'hello world' menu.h main.c\n\ \n\ Regexp selection and interpretation:\n"), program_name); -#ifdef GREP_PROGRAM - printf (_("\ + if (matchers[1].name) + printf (_("\ -E, --extended-regexp PATTERN is an extended regular expression (ERE)\n\ -F, --fixed-strings PATTERN is a set of newline-separated fixed strings\n\ -G, --basic-regexp PATTERN is a basic regular expression (BRE)\n\ -P, --perl-regexp PATTERN is a Perl regular expression\n")); /* -X is undocumented on purpose. */ -#endif /* GREP_PROGRAM */ printf (_("\ -e, --regexp=PATTERN use PATTERN for matching\n\ -f, --file=FILE obtain PATTERN from FILE\n\ @@ -1544,17 +1528,7 @@ Context control:\n\ -U, --binary do not strip CR characters at EOL (MSDOS)\n\ -u, --unix-byte-offsets report offsets as if CRs were not there (MSDOS)\n\ \n")); -#if defined(EGREP_PROGRAM) - printf (_("\ -Invocation as `egrep' is deprecated; use `grep -E' instead.\n")); -#elif defined(FGREP_PROGRAM) - printf (_("\ -Invocation as `fgrep' is deprecated; use `grep -F' instead.\n")); -#else - printf (_("\ -`egrep' means `grep -E'. `fgrep' means `grep -F'.\n\ -Direct invocation as either `egrep' or `fgrep' is deprecated.\n")); -#endif /* ?GREP_PROGRAM */ + printf ("%s", after_options); printf (_("\ With no FILE, or when FILE is -, read standard input. If less than two FILEs\n\ are given, assume -h. Exit status is 0 if any line was selected, 1 otherwise;\n\ @@ -1569,34 +1543,48 @@ if any error occurs and -q was not given, the exit status is 2.\n")); exit (status); } -static char const *matcher; - -#ifdef GREP_PROGRAM -/* Set the matcher to M, reporting any conflicts. */ +/* If M is NULL, initialize the matcher to the default. Otherwise set the + matcher to M if available. Exit in case of conflicts or if M is not + available. */ static void setmatcher (char const *m) { - if (matcher && strcmp (matcher, m) != 0) - error (EXIT_TROUBLE, 0, _("conflicting matchers specified")); - matcher = m; -} -#endif + static char const *matcher; + unsigned int i; -/* 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 (char const *name) -{ - int i; + if (!m) + { + compile = matchers[0].compile; + execute = matchers[0].execute; + if (!matchers[1].name) + matcher = matchers[0].name; + } - for (i = 0; matchers[i].name; i++) - if (strcmp (name, matchers[i].name) == 0) - { - compile = matchers[i].compile; - execute = matchers[i].execute; - return 1; - } - return 0; + else if (matcher) + { + if (matcher && strcmp (matcher, m) == 0) + ; + + else if (!matchers[1].name) + error (EXIT_TROUBLE, 0, _("%s can only use the %s pattern syntax"), + program_name, matcher); + else + error (EXIT_TROUBLE, 0, _("conflicting matchers specified")); + } + + else + { + for (i = 0; matchers[i].name; i++) + if (strcmp (m, matchers[i].name) == 0) + { + compile = matchers[i].compile; + execute = matchers[i].execute; + matcher = m; + return; + } + + error (EXIT_TROUBLE, 0, _("invalid matcher %s"), m); + } } static void @@ -1865,6 +1853,7 @@ main (int argc, char **argv) atexit (close_stdout); prepend_default_options (getenv ("GREP_OPTIONS"), &argc, &argv); + setmatcher (NULL); while ((opt = get_nondigit_option (argc, argv, &default_context)) != -1) switch (opt) @@ -1892,7 +1881,6 @@ main (int argc, char **argv) error (EXIT_TROUBLE, 0, _("unknown devices method")); break; -#ifdef GREP_PROGRAM case 'E': setmatcher ("egrep"); break; @@ -1912,7 +1900,6 @@ main (int argc, char **argv) case 'X': /* undocumented on purpose */ setmatcher (optarg); break; -#endif /* GREP_PROGRAM */ case 'H': with_filenames = 1; @@ -2228,15 +2215,7 @@ There is NO WARRANTY, to the extent permitted by law.\n"), else usage (EXIT_TROUBLE); - if (matcher && install_matcher (matcher)) - ; - else if (install_matcher (matchers[0].name)) - ; - else - abort (); - set_limits(); - compile(keys, keycc); free (keys); @@ -21,14 +21,6 @@ # define __attribute__(x) #endif -/* We build specialized legacy "egrep" and "fgrep" programs. - No program adjusts its behavior according to its argv[0]. - No scripts are provided as an alternative. Distributors - are free to do otherwise, but it is their burden to do so. */ -#if !defined(GREP_PROGRAM) && !defined(EGREP_PROGRAM) && !defined(FGREP_PROGRAM) -# define GREP_PROGRAM -#endif - /* Function pointer types. */ typedef void (*compile_fp_t) (char const *, size_t); typedef size_t (*execute_fp_t) (char const *, size_t, size_t *, char const *); @@ -42,6 +34,9 @@ extern struct matcher execute_fp_t execute; } const matchers[]; +extern const char before_options[]; +extern const char after_options[]; + /* The following flags are exported from grep for the matchers to look at. */ extern int match_icase; /* -i */ diff --git a/src/gsearch.c b/src/gsearch.c index b71d3b72..8ef49683 100644 --- a/src/gsearch.c +++ b/src/gsearch.c @@ -30,3 +30,9 @@ struct matcher const matchers[] = { { "perl", Pcompile, Pexecute }, { NULL, NULL, NULL }, }; + +const char before_options[] = +N_("PATTERN is, by default, a basic regular expression (BRE).\n"); +const char after_options[] = +N_("`egrep' means `grep -E'. `fgrep' means `grep -F'.\n\ +Direct invocation as either `egrep' or `fgrep' is deprecated.\n"); |