* Makefile.am (grep_SOURCES): Add gsearch.c. (EXTRA_DIST): Add search.c. * esearch.c (matchers): New. * fsearch.c (matchers): New. * gsearch.c: New. * search.c (matchers): Remove. * grep.c: Always compile most !GREP_PROGRAM sections. (main): Use first matcher if none is explicitly provided. Remove "default" matcher. * grep.h (struct matcher): Adjust comments. --- src/Makefile.am | 4 ++-- src/esearch.c | 6 ++++++ src/fsearch.c | 6 ++++++ src/grep.c | 17 +++++++---------- src/grep.h | 17 +++-------------- src/gsearch.c | 11 +++++++++++ src/search.c | 10 ---------- 7 files changed, 35 insertions(+), 36 deletions(-) create mode 100644 src/gsearch.c
diff --git a/src/Makefile.am b/src/Makefile.am index c5dcac5..0b0140e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -19,7 +19,7 @@ LN = ln AM_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS) bin_PROGRAMS = grep egrep fgrep -grep_SOURCES = grep.c search.c kwset.c dfa.c +grep_SOURCES = grep.c gsearch.c kwset.c dfa.c egrep_SOURCES = egrep.c esearch.c kwset.c dfa.c fgrep_SOURCES = fgrep.c fsearch.c kwset.c noinst_HEADERS = grep.h dfa.h kwset.h system.h mbsupport.h @@ -30,5 +30,5 @@ localedir = $(datadir)/locale INCLUDES = -I$(top_srcdir)/lib -DLOCALEDIR=\"$(localedir)\" EXTRA_DIST = \ - dosbuf.c \ + dosbuf.c search.c \ vms_fab.c vms_fab.h diff --git a/src/esearch.c b/src/esearch.c index f605e08..d76c310 100644 --- a/src/esearch.c +++ b/src/esearch.c @@ -1,2 +1,8 @@ #define EGREP_PROGRAM #include "search.c" + +struct matcher const matchers[] = { + { "egrep", Ecompile, EGexecute }, + { NULL, NULL, NULL }, +}; + diff --git a/src/fsearch.c b/src/fsearch.c index 3bcac9d..e1ca0b1 100644 --- a/src/fsearch.c +++ b/src/fsearch.c @@ -1,2 +1,8 @@ #define FGREP_PROGRAM #include "search.c" + +struct matcher const matchers[] = { + { "fgrep", Fcompile, Fexecute }, + { NULL, NULL, NULL }, +}; + diff --git a/src/grep.c b/src/grep.c index 538d4c8..6c78479 100644 --- a/src/grep.c +++ b/src/grep.c @@ -377,10 +377,8 @@ static inline int undossify_input (char *, size_t); #endif /* Functions we'll use to search. */ -#ifdef GREP_PROGRAM static compile_fp_t compile; static execute_fp_t execute; -#endif /* Like error, but suppress the diagnostic if requested. */ static void @@ -1567,9 +1565,9 @@ if any error occurs and -q was not given, the exit status is 2.\n")); exit (status); } -#ifdef GREP_PROGRAM static char const *matcher; +#ifdef GREP_PROGRAM /* Set the matcher to M, reporting any conflicts. */ static void setmatcher (char const *m) @@ -1578,6 +1576,7 @@ setmatcher (char const *m) error (EXIT_TROUBLE, 0, _("conflicting matchers specified")); matcher = m; } +#endif /* Go through the matchers vector and look for the specified matcher. If we find it, install it in compile and execute, and return 1. */ @@ -1595,7 +1594,6 @@ install_matcher (char const *name) } return 0; } -#endif /* GREP_PROGRAM */ static void set_limits(void) @@ -2228,13 +2226,12 @@ There is NO WARRANTY, to the extent permitted by law.\n"), else usage (EXIT_TROUBLE); -#ifdef GREP_PROGRAM - if (! matcher) - matcher = "grep"; - - if (!install_matcher (matcher) && !install_matcher ("default")) + if (matcher && install_matcher (matcher)) + ; + else if (install_matcher (matchers[0].name)) + ; + else abort (); -#endif /* GREP_PROGRAM */ set_limits(); diff --git a/src/grep.h b/src/grep.h index 8a0ca3b..1277b61 100644 --- a/src/grep.h +++ b/src/grep.h @@ -38,32 +38,21 @@ (char const *buf, size_t size, size_t *match_size, char const *start_ptr) /* start_ptr == NULL means the caller is not looking for an exact match. */ -#ifdef GREP_PROGRAM -/* Function definitions. */ # define COMPILE_FCT(f) static COMPILE_RET f COMPILE_ARGS # define EXECUTE_FCT(f) static EXECUTE_RET f EXECUTE_ARGS + /* Function pointer types. */ typedef COMPILE_RET (*compile_fp_t) COMPILE_ARGS; typedef EXECUTE_RET (*execute_fp_t) EXECUTE_ARGS; -/* grep.c expects the matchers vector to be terminated - by an entry with a NULL name, and to contain at least - an entry named "default". */ +/* grep.c expects the matchers vector to be terminated by an entry + * with a NULL name, and to contain at least an entry. */ extern struct matcher { const char *name; compile_fp_t compile; execute_fp_t execute; } const matchers[]; -#else /* !GREP_PROGRAM */ -/* Straight functions for specialized "egrep" and "fgrep" programs. */ -/* Function definitions. */ -# define COMPILE_FCT(f) COMPILE_RET compile COMPILE_ARGS -# define EXECUTE_FCT(f) EXECUTE_RET execute EXECUTE_ARGS -/* Function prototypes. */ -extern COMPILE_RET compile COMPILE_ARGS; -extern EXECUTE_RET execute EXECUTE_ARGS; -#endif /* GREP_PROGRAM */ /* The following flags are exported from grep for the matchers to look at. */ diff --git a/src/gsearch.c b/src/gsearch.c new file mode 100644 index 0000000..e3e0423 --- /dev/null +++ b/src/gsearch.c @@ -0,0 +1,11 @@ +#include "search.c" + +struct matcher const matchers[] = { + { "grep", Gcompile, EGexecute }, + { "egrep", Ecompile, EGexecute }, + { "awk", Acompile, EGexecute }, + { "fgrep", Fcompile, Fexecute }, + { "perl", Pcompile, Pexecute }, + { NULL, NULL, NULL }, +}; + diff --git a/src/search.c b/src/search.c index 9cb4abb..daa4bb3 100644 --- a/src/search.c +++ b/src/search.c @@ -839,14 +839,4 @@ EXECUTE_FCT(Pexecute) } #endif } - -struct matcher const matchers[] = { - { "default", Gcompile, EGexecute }, - { "grep", Gcompile, EGexecute }, - { "egrep", Ecompile, EGexecute }, - { "awk", Acompile, EGexecute }, - { "fgrep", Fcompile, Fexecute }, - { "perl", Pcompile, Pexecute }, - { NULL, NULL, NULL }, -}; #endif /* GREP_PROGRAM */ -- 1.6.6.1