]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
msggrep now uses libgrep, instead of calling 'grep' through the command line.
authorBruno Haible <bruno@clisp.org>
Fri, 14 Jan 2005 12:24:23 +0000 (12:24 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:12:04 +0000 (12:12 +0200)
15 files changed:
NEWS
gettext-tools/ChangeLog
gettext-tools/Makefile.am
gettext-tools/Makefile.msvc
gettext-tools/Makefile.vms
gettext-tools/configure.ac
gettext-tools/m4/ChangeLog
gettext-tools/m4/Makefile.am
gettext-tools/src/ChangeLog
gettext-tools/src/Makefile.am
gettext-tools/src/Makefile.msvc
gettext-tools/src/Makefile.vms
gettext-tools/src/msggrep.c
gettext-tools/tests/ChangeLog
gettext-tools/tests/msggrep-4

diff --git a/NEWS b/NEWS
index 4cb91dcb65a08d6fec87ff2c7c5511c03c2bec8d..90c7125c539ad58c916505f9922633765ed04e79 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,7 @@ Version 0.14.2 - January 2005
 
 * Improved detection of the locale on MacOS X.
 * The gettext autoconf macros now require autoconf 2.50 or newer.
+* msggrep is much faster now.
 \f
 Version 0.14 - January 2004
 
index 26708eb1ebaaedec8d1ea40a30a39cf5b87f69f8..952bb1b9f27cb2ab38ed9e7f1d6a475c06f292a9 100644 (file)
@@ -1,3 +1,13 @@
+2005-01-08  Bruno Haible  <bruno@clisp.org>
+
+       * libgrep: New subdirectory.
+       * configure.ac: Invoke gt_LIBGREP. Declare libgrep/Makefile.am.
+       * Makefile.am (SUBDIRS): Add libgrep.
+       (config.h_vms, config.h.msvc): Define HAVE_DECL_STRDUP, HAVE_MEMCHR,
+       restrict.
+       * Makefile.msvc: Recurse into libgrep as well.
+       * Makefile.vms: Likewise.
+
 2005-01-06  Bruno Haible  <bruno@clisp.org>
 
        * configure.ac: Invoke gl_STRCASE. Don't test for strcasecmp and
index caa7b6f1b554fcce56784ab1492f3cd7b2d56bf5..786d4250ee1072107fd809264e0ac4898df87bf7 100644 (file)
@@ -20,7 +20,7 @@
 AUTOMAKE_OPTIONS = 1.5 gnu no-dependencies
 ACLOCAL_AMFLAGS = -I m4 -I ../gettext-runtime/m4 -I ../autoconf-lib-link/m4 -I ../config/m4
 
-SUBDIRS = doc intl lib libuniname src po projects misc man m4 tests examples
+SUBDIRS = doc intl lib libgrep libuniname src po projects misc man m4 tests examples
 
 EXTRA_DIST = misc/DISCLAIM
 
@@ -48,6 +48,7 @@ config.h_vms: config.h.in ../version.sh
             -e 's/#undef HAVE_BTOWC$$/#define HAVE_BTOWC 1/' \
             -e 's/#undef HAVE_CHOWN$$/#define HAVE_CHOWN 1/' \
             -e 's/#undef HAVE_DECL_GETENV$$/#define HAVE_DECL_GETENV 1/' \
+            -e 's/#undef HAVE_DECL_STRDUP$$/#define HAVE_DECL_STRDUP 1/' \
             -e 's/#undef HAVE_DECL_WCWIDTH$$/#define HAVE_DECL_WCWIDTH 1/' \
             -e 's/#undef HAVE_DIRENT_H$$/#define HAVE_DIRENT_H 1/' \
             -e 's/#undef HAVE_DLFCN_H$$/#define HAVE_DLFCN_H 1/' \
@@ -77,6 +78,7 @@ config.h_vms: config.h.in ../version.sh
             -e 's/#undef HAVE_MBRTOWC$$/#define HAVE_MBRTOWC 1/' \
             -e 's/#undef HAVE_MBSINIT$$/#define HAVE_MBSINIT 1/' \
             -e 's/#undef HAVE_MBSTATE_T$$/#define HAVE_MBSTATE_T 1/' \
+            -e 's/#undef HAVE_MEMCHR$$/#define HAVE_MEMCHR 1/' \
             -e 's/#undef HAVE_MEMMOVE$$/#define HAVE_MEMMOVE 1/' \
             -e 's/#undef HAVE_MEMORY_H$$/#define HAVE_MEMORY_H 1/' \
             -e 's/#undef HAVE_MEMSET$$/#define HAVE_MEMSET 1/' \
@@ -140,6 +142,7 @@ config.h_vms: config.h.in ../version.sh
             -e 's/#undef fnmatch$$/#define fnmatch rpl_fnmatch/' \
             -e 's/#undef getline$$/#define getline rpl_getline/' \
             -e 's/#undef realpath$$/#define realpath rpl_realpath/' \
+            -e 's/#undef restrict$$/#define restrict/' \
             -e 's/#undef uintmax_t$$/#define uintmax_t unsigned long long/' \
             -e 's/#undef PACKAGE$$/#define PACKAGE "gettext-tools"/' \
             -e 's/#undef VERSION$$/#define VERSION "$(VERSION)"/' \
@@ -158,6 +161,7 @@ config.h.msvc: config.h.in ../version.sh
            -e 's/#undef HAVE_ALLOCA$$/#define HAVE_ALLOCA 1/' \
            -e 's/#undef HAVE_BTOWC$$/#define HAVE_BTOWC 1/' \
            -e 's/#undef HAVE_DECL_GETENV$$/#define HAVE_DECL_GETENV 1/' \
+           -e 's/#undef HAVE_DECL_STRDUP$$/#define HAVE_DECL_STRDUP 1/' \
            -e 's/#undef HAVE_DECL_STRERROR$$/#define HAVE_DECL_STRERROR 1/' \
            -e 's/#undef HAVE_DECL_WCWIDTH$$/#define HAVE_DECL_WCWIDTH 0/' \
            -e 's/#undef HAVE_DECL__SNPRINTF$$/#define HAVE_DECL__SNPRINTF 1/' \
@@ -175,6 +179,7 @@ config.h.msvc: config.h.in ../version.sh
            -e 's/#undef HAVE_LIMITS_H$$/#define HAVE_LIMITS_H 1/' \
            -e 's/#undef HAVE_LOCALE_H$$/#define HAVE_LOCALE_H 1/' \
            -e 's/#undef HAVE_LONG_FILE_NAMES$$/#define HAVE_LONG_FILE_NAMES 1/' \
+           -e 's/#undef HAVE_MEMCHR$$/#define HAVE_MEMCHR 1/' \
            -e 's/#undef HAVE_MEMMOVE$$/#define HAVE_MEMMOVE 1/' \
            -e 's/#undef HAVE_MEMSET$$/#define HAVE_MEMSET 1/' \
            -e 's/#undef HAVE_PTRDIFF_T$$/#define HAVE_PTRDIFF_T 1/' \
@@ -215,6 +220,7 @@ config.h.msvc: config.h.in ../version.sh
            -e 's/#undef inline$$/#define inline __inline/' \
            -e 's/#undef mode_t$$/#define mode_t int/' \
            -e 's/#undef pid_t$$/#define pid_t int/' \
+           -e 's/#undef restrict$$/#define restrict/' \
            -e 's/#undef ssize_t$$/#define ssize_t int/' \
            -e 's/#undef uintmax_t$$/#define uintmax_t unsigned long/' \
            -e 's/#undef PACKAGE$$/#define PACKAGE "gettext-tools"/' \
index 64734fe9658d89bbbeb31049c1e560a7abc1d805..9350fece2095f415a39813ddce9dbfe17796eb78 100644 (file)
@@ -96,6 +96,9 @@ all : config.h force
        cd lib
        $(MAKE) -f Makefile.msvc all
        cd ..
+       cd libgrep
+       $(MAKE) -f Makefile.msvc all
+       cd ..
        cd libuniname
        $(MAKE) -f Makefile.msvc all
        cd ..
@@ -136,6 +139,9 @@ install : force
        cd lib
        $(MAKE) -f Makefile.msvc install
        cd ..
+       cd libgrep
+       $(MAKE) -f Makefile.msvc install
+       cd ..
        cd libuniname
        $(MAKE) -f Makefile.msvc install
        cd ..
@@ -172,6 +178,9 @@ installdirs : force
        cd lib
        $(MAKE) -f Makefile.msvc installdirs
        cd ..
+       cd libgrep
+       $(MAKE) -f Makefile.msvc installdirs
+       cd ..
        cd libuniname
        $(MAKE) -f Makefile.msvc installdirs
        cd ..
@@ -208,6 +217,9 @@ uninstall : force
        cd lib
        $(MAKE) -f Makefile.msvc uninstall
        cd ..
+       cd libgrep
+       $(MAKE) -f Makefile.msvc uninstall
+       cd ..
        cd libuniname
        $(MAKE) -f Makefile.msvc uninstall
        cd ..
@@ -244,6 +256,9 @@ check : all force
        cd lib
        $(MAKE) -f Makefile.msvc check
        cd ..
+       cd libgrep
+       $(MAKE) -f Makefile.msvc check
+       cd ..
        cd libuniname
        $(MAKE) -f Makefile.msvc check
        cd ..
@@ -280,6 +295,9 @@ mostlyclean : force
        cd lib
        $(MAKE) -f Makefile.msvc mostlyclean
        cd ..
+       cd libgrep
+       $(MAKE) -f Makefile.msvc mostlyclean
+       cd ..
        cd libuniname
        $(MAKE) -f Makefile.msvc mostlyclean
        cd ..
@@ -317,6 +335,9 @@ clean : force
        cd lib
        $(MAKE) -f Makefile.msvc clean
        cd ..
+       cd libgrep
+       $(MAKE) -f Makefile.msvc clean
+       cd ..
        cd libuniname
        $(MAKE) -f Makefile.msvc clean
        cd ..
@@ -354,6 +375,9 @@ distclean : force
        cd lib
        $(MAKE) -f Makefile.msvc distclean
        cd ..
+       cd libgrep
+       $(MAKE) -f Makefile.msvc distclean
+       cd ..
        cd libuniname
        $(MAKE) -f Makefile.msvc distclean
        cd ..
@@ -392,6 +416,9 @@ maintainer-clean : force
        cd lib
        $(MAKE) -f Makefile.msvc maintainer-clean
        cd ..
+       cd libgrep
+       $(MAKE) -f Makefile.msvc maintainer-clean
+       cd ..
        cd libuniname
        $(MAKE) -f Makefile.msvc maintainer-clean
        cd ..
index bb734283a8a098c988bf05ae1dcef7967c7f52fc..a33fa9be219edcd881bf792f09949b6e06805d4e 100644 (file)
@@ -20,6 +20,9 @@ all : config.h
        set default [.lib]
        $(MMS) $(MMSQUALIFIERS) /description=Makefile.vms all
        set default [-]
+       set default [.libgrep]
+       $(MMS) $(MMSQUALIFIERS) /description=Makefile.vms all
+       set default [-]
        set default [.libuniname]
        $(MMS) $(MMSQUALIFIERS) /description=Makefile.vms all
        set default [-]
@@ -58,6 +61,9 @@ install :
        set default [.lib]
        $(MMS) $(MMSQUALIFIERS) /description=Makefile.vms install
        set default [-]
+       set default [.libgrep]
+       $(MMS) $(MMSQUALIFIERS) /description=Makefile.vms install
+       set default [-]
        set default [.libuniname]
        $(MMS) $(MMSQUALIFIERS) /description=Makefile.vms install
        set default [-]
@@ -93,6 +99,9 @@ installdirs :
        set default [.lib]
        $(MMS) $(MMSQUALIFIERS) /description=Makefile.vms installdirs
        set default [-]
+       set default [.libgrep]
+       $(MMS) $(MMSQUALIFIERS) /description=Makefile.vms installdirs
+       set default [-]
        set default [.libuniname]
        $(MMS) $(MMSQUALIFIERS) /description=Makefile.vms installdirs
        set default [-]
@@ -128,6 +137,9 @@ uninstall :
        set default [.lib]
        $(MMS) $(MMSQUALIFIERS) /description=Makefile.vms uninstall
        set default [-]
+       set default [.libgrep]
+       $(MMS) $(MMSQUALIFIERS) /description=Makefile.vms uninstall
+       set default [-]
        set default [.libuniname]
        $(MMS) $(MMSQUALIFIERS) /description=Makefile.vms uninstall
        set default [-]
@@ -163,6 +175,9 @@ check : all
        set default [.lib]
        $(MMS) $(MMSQUALIFIERS) /description=Makefile.vms check
        set default [-]
+       set default [.libgrep]
+       $(MMS) $(MMSQUALIFIERS) /description=Makefile.vms check
+       set default [-]
        set default [.libuniname]
        $(MMS) $(MMSQUALIFIERS) /description=Makefile.vms check
        set default [-]
@@ -198,6 +213,9 @@ mostlyclean :
        set default [.lib]
        $(MMS) $(MMSQUALIFIERS) /description=Makefile.vms mostlyclean
        set default [-]
+       set default [.libgrep]
+       $(MMS) $(MMSQUALIFIERS) /description=Makefile.vms mostlyclean
+       set default [-]
        set default [.libuniname]
        $(MMS) $(MMSQUALIFIERS) /description=Makefile.vms mostlyclean
        set default [-]
@@ -234,6 +252,9 @@ clean :
        set default [.lib]
        $(MMS) $(MMSQUALIFIERS) /description=Makefile.vms clean
        set default [-]
+       set default [.libgrep]
+       $(MMS) $(MMSQUALIFIERS) /description=Makefile.vms clean
+       set default [-]
        set default [.libuniname]
        $(MMS) $(MMSQUALIFIERS) /description=Makefile.vms clean
        set default [-]
@@ -270,6 +291,9 @@ distclean :
        set default [.lib]
        $(MMS) $(MMSQUALIFIERS) /description=Makefile.vms distclean
        set default [-]
+       set default [.libgrep]
+       $(MMS) $(MMSQUALIFIERS) /description=Makefile.vms distclean
+       set default [-]
        set default [.libuniname]
        $(MMS) $(MMSQUALIFIERS) /description=Makefile.vms distclean
        set default [-]
@@ -306,6 +330,9 @@ maintainer-clean :
        set default [.lib]
        $(MMS) $(MMSQUALIFIERS) /description=Makefile.vms maintainer-clean
        set default [-]
+       set default [.libgrep]
+       $(MMS) $(MMSQUALIFIERS) /description=Makefile.vms maintainer-clean
+       set default [-]
        set default [.libuniname]
        $(MMS) $(MMSQUALIFIERS) /description=Makefile.vms maintainer-clean
        set default [-]
index fd54a081e84119c77583e16a65a34834edf71a19..702817cabe5f268c1ede6e2e634bb6820d0eb8b1 100644 (file)
@@ -153,6 +153,7 @@ gl_XREADLINK
 gl_CANONICALIZE
 gt_SETLOCALE
 gl_XSIZE
+gt_LIBGREP
 
 gt_PREREQ_HOSTNAME
 
@@ -284,6 +285,9 @@ AC_CONFIG_FILES([lib/Makefile],
 AC_CONFIG_FILES([lib/javacomp.sh lib/javaexec.sh])
 AC_CONFIG_FILES([lib/csharpcomp.sh lib/csharpexec.sh])
 
+AC_CONFIG_FILES([libgrep/Makefile],
+                [FIX_MAKEFILE_COMPILE])
+
 AC_CONFIG_FILES([libuniname/Makefile],
                 [FIX_MAKEFILE_COMPILE])
 
index 2728c7e04615cf483c39a924d193cbe9732096bd..349d9d14a7fbba5727e010cd7f64f93b7ffb1559 100644 (file)
@@ -1,3 +1,12 @@
+2005-01-08  Bruno Haible  <bruno@clisp.org>
+
+       * libgrep.m4: New file.
+       * hard-locale.m4: New file, from gnulib.
+       * memchr.m4: New file, from gnulib.
+       * regex.m4: New file, from gnulib.
+       * restrict.m4: New file, from gnulib.
+       * strdup.m4: New file, from gnulib.
+
 2005-01-06  Bruno Haible  <bruno@clisp.org>
 
        * strcase.m4: New file, from gnulib.
index 7bf11a8dd3fc6856184b3e3233f88e1ff205d748..f98a6a4d8324966d6d7b0d76c69cb499f5a7e0d6 100644 (file)
@@ -62,6 +62,7 @@ gcj.m4 \
 getline.m4 \
 getndelim2.m4 \
 getopt.m4 \
+hard-locale.m4 \
 hostname.m4 \
 javacomp.m4 \
 javaexec.m4 \
@@ -69,13 +70,16 @@ locale-fr.m4 \
 mbrtowc.m4 \
 mbstate_t.m4 \
 mbswidth.m4 \
+memchr.m4 \
 mkdtemp.m4 \
 onceonly.m4 \
 pathmax.m4 \
 quote.m4 \
 quotearg.m4 \
 readlink.m4 \
+regex.m4 \
 relocatable.m4 \
+restrict.m4 \
 setenv.m4 \
 setlocale.m4 \
 sig_atomic_t.m4 \
@@ -85,6 +89,7 @@ ssize_t.m4 \
 stdbool.m4 \
 stpncpy.m4 \
 strcase.m4 \
+strdup.m4 \
 strerror.m4 \
 strerror_r.m4 \
 tmpdir.m4 \
index 231a6275ed0f60f65f27a8b1e051f62a9391b7b5..0adf6252a48149e0a6a58f0e0a6aae4e57ae4bd2 100644 (file)
@@ -1,3 +1,22 @@
+2005-01-08  Bruno Haible  <bruno@clisp.org>
+
+       * msggrep.c (grep_args, grep_path, grep_argv): Remove variables.
+       (struct grep_task): New type.
+       (grep_task): New variable.
+       (main): Initialize grep_task instead of grep_args. Change processing
+       of options 'E', 'F' to set a matcher, of 'e', 'f' to append to the
+       pattern string, and of 'i' to set a boolean. Compile the patterns.
+       (is_string_selected): Execute a compiled pattern instead of calling
+       the grep program.
+       (is_message_selected): Update.
+       * Makefile.am (AM_CPPFLAGS): Add -I option for libgrep.
+       (LIBGREP): New variable.
+       (msggrep_LDADD): Add $(LIBGREP).
+       * Makefile.msvc (INCLUDES): Add libgrep directory.
+       (msggrep.exe): Link with libgrep.
+       * Makefile.vms (INCLUDES): Add libgrep directory.
+       (msggrep.exe): Link with libgrep.
+
 2005-01-09  Bruno Haible  <bruno@clisp.org>
 
        * msgl-ascii.h (is_ascii_msgdomain_list): New declaration.
index 0209147864923e45d17044a95693bab57f354af1..d1aafbaa44a55ccb7abb7a379bc5152e34b26ff8 100644 (file)
@@ -1,5 +1,5 @@
 ## Makefile for the gettext-tools/src subdirectory of GNU gettext
-## Copyright (C) 1995-1998, 2000-2004 Free Software Foundation, Inc.
+## Copyright (C) 1995-1998, 2000-2005 Free Software Foundation, Inc.
 ##
 ## This program is free software; you can redistribute it and/or modify
 ## it under the terms of the GNU General Public License as published by
@@ -65,6 +65,7 @@ pkglibdir = $(libdir)/gettext
 AM_CPPFLAGS = \
   -I. -I$(srcdir) \
   -I.. \
+  -I$(top_srcdir)/libgrep \
   -I$(top_srcdir)/libuniname \
   -I../lib -I$(top_srcdir)/lib \
   -I../intl -I$(top_srcdir)/../gettext-runtime/intl
@@ -122,6 +123,9 @@ LTV_CURRENT=1
 LTV_REVISION=0
 LTV_AGE=1
 
+# msggrep needs pattern matching.
+LIBGREP = ../libgrep/libgrep.a
+
 # x-python needs table of Unicode character names.
 LIBUNINAME = ../libuniname/libuniname.a
 
@@ -190,7 +194,7 @@ msgconv_LDADD = libgettextsrc.la
 msgen_LDADD = libgettextsrc.la
 msgexec_LDADD = libgettextsrc.la
 msgfilter_LDADD = libgettextsrc.la
-msggrep_LDADD = libgettextsrc.la
+msggrep_LDADD = $(LIBGREP) libgettextsrc.la
 msginit_LDADD = ../intl/localename.@INTL_LIBTOOL_SUFFIX_PREFIX@o \
                 @INTL_MACOSX_LDFLAGS@ libgettextsrc.la
 msguniq_LDADD = libgettextsrc.la
index 27bdbf2c9f1332ceb32f88875381f85bc748417f..373ed424d53d2b5d22913b2fd7018bc2a859652f 100644 (file)
@@ -83,7 +83,7 @@ DEBUGFLAGS =
 
 CFLAGS = $(MFLAGS) $(WARN_CFLAGS) $(OPTIMFLAGS) -DHAVE_CONFIG_H -DLOCALEDIR=\"$(IIlocaledir)\" -DLOCALE_ALIAS_PATH=\"$(IIaliaspath)\" -DGETTEXTJAR=\"$(IIjardir)\\gettext.jar\" -DLIBDIR=\"$(IIlibdir)\" -DGETTEXTDATADIR=\"$(IIpkgdatadir)\" -DPROJECTSDIR=\"$(IIprojectsdir)\"
 
-INCLUDES = -I. -I.. -I..\libuniname -I..\lib -I..\intl -I..\..\gettext-runtime\intl -I..\windows -I$(includedir)
+INCLUDES = -I. -I.. -I..\libgrep -I..\libuniname -I..\lib -I..\intl -I..\..\gettext-runtime\intl -I..\windows -I$(includedir)
 
 AR = lib
 AR_FLAGS = /out:
@@ -499,7 +499,7 @@ msgfilter.exe : $(msgfilter_OBJECTS)
        $(CC) $(MFLAGS) $(DEBUGFLAGS) $(msgfilter_OBJECTS) gettextsrc.lib ..\lib\gettextlib.lib ..\intl\intl.lib $(libdir)\iconv.lib $(LDADD) -Femsgfilter.exe
 
 msggrep.exe : $(msggrep_OBJECTS)
-       $(CC) $(MFLAGS) $(DEBUGFLAGS) $(msggrep_OBJECTS) gettextsrc.lib ..\lib\gettextlib.lib ..\intl\intl.lib $(libdir)\iconv.lib $(LDADD) -Femsggrep.exe
+       $(CC) $(MFLAGS) $(DEBUGFLAGS) $(msggrep_OBJECTS) ..\libgrep\grep.lib gettextsrc.lib ..\lib\gettextlib.lib ..\intl\intl.lib $(libdir)\iconv.lib $(LDADD) -Femsggrep.exe
 
 msginit.exe : $(msginit_OBJECTS)
        $(CC) $(MFLAGS) $(DEBUGFLAGS) $(msginit_OBJECTS) ..\intl\localename.obj gettextsrc.lib ..\lib\gettextlib.lib ..\intl\intl.lib $(libdir)\iconv.lib $(LDADD) -Femsginit.exe
index 53fb4e495ebc0054bdfc70feeff5934cbadee76f..509d4855b6e0f5135eaa779e940b608feec7ac51 100644 (file)
@@ -30,7 +30,7 @@ OPTIMFLAGS = /optimize
 CFLAGS = $(ABIFLAGS) $(WARN_CFLAGS) $(OPTIMFLAGS)
 DEFS = "VMS=1","HAVE_CONFIG_H=1","LOCALEDIR=""$(localedir)]""","GETTEXTJAR=""$(jardir)]gettext.jar""","LIBDIR=""$(libdir)]""","GETTEXTDATADIR=""$(pkgdatadir)]""","PROJECTSDIR=""$(projectsdir)"""
 
-INCLUDES = /include=([],[-],[-.libuniname],[-.lib],[-.intl],[-.-.gettext-runtime.intl])
+INCLUDES = /include=([],[-],[-.libgrep],[-.libuniname],[-.lib],[-.intl],[-.-.gettext-runtime.intl])
 
 LDADD = libiconv.opt/opt,[-.-.vms]link_options.opt
 LDADD_EXPAT = sys$library:expat/lib
@@ -433,7 +433,7 @@ msgfilter.exe : $(msgfilter_OBJECTS),libiconv.opt
        link /executable=msgfilter.exe $(msgfilter_OBJECTS),gettextsrc.olb/lib,[-.lib]gettextlib.olb/lib,[-.intl]intl.olb/lib,$(LDADD)
 
 msggrep.exe : $(msggrep_OBJECTS),libiconv.opt
-       link /executable=msggrep.exe $(msggrep_OBJECTS),gettextsrc.olb/lib,[-.lib]gettextlib.olb/lib,[-.intl]intl.olb/lib,$(LDADD)
+       link /executable=msggrep.exe $(msggrep_OBJECTS),[-.libgrep]grep.olb/lib,gettextsrc.olb/lib,[-.lib]gettextlib.olb/lib,[-.intl]intl.olb/lib,$(LDADD)
 
 msginit.exe : $(msginit_OBJECTS),libiconv.opt
        link /executable=msginit.exe $(msginit_OBJECTS),[-.intl]localename.obj,gettextsrc.olb/lib,[-.lib]gettextlib.olb/lib,[-.intl]intl.olb/lib,$(LDADD)
index 3d6675d97804e789637e4ac0f9c50def1f6071a6..d1a36c06cf0c1a37bc050a42a4e8b32a7df13f66 100644 (file)
@@ -22,6 +22,7 @@
 #endif
 #include <alloca.h>
 
+#include <assert.h>
 #include <errno.h>
 #include <getopt.h>
 #include <limits.h>
 #include "xalloc.h"
 #include "xallocsa.h"
 #include "exit.h"
-#include "full-write.h"
-#include "findprog.h"
-#include "pipe.h"
-#include "wait-process.h"
+#include "libgrep.h"
 #include "gettext.h"
 
 #define _(str) gettext (str)
@@ -71,14 +69,16 @@ static string_list_ty *location_files;
 /* Selected domain names.  */
 static string_list_ty *domain_names;
 
-/* Arguments to be passed to the grep subprocesses.  */
-static string_list_ty *grep_args[3];
-
-/* Pathname of the grep program.  */
-static const char *grep_path;
-
-/* Argument lists for the grep program.  */
-static char **grep_argv[3];
+/* Task for each grep pass.  */
+struct grep_task {
+  matcher_t *matcher;
+  size_t pattern_count;
+  char *patterns;
+  size_t patterns_size;
+  bool case_insensitive;
+  void *compiled_patterns;
+};
+static struct grep_task grep_task[3];
 
 /* Long options.  */
 static const struct option long_options[] =
@@ -142,6 +142,7 @@ main (int argc, char **argv)
   msgdomain_list_ty *result;
   bool sort_by_filepos = false;
   bool sort_by_msgid = false;
+  size_t i;
 
   /* Set program name for messages.  */
   set_program_name (argv[0]);
@@ -167,9 +168,17 @@ main (int argc, char **argv)
   grep_pass = -1;
   location_files = string_list_alloc ();
   domain_names = string_list_alloc ();
-  grep_args[0] = string_list_alloc ();
-  grep_args[1] = string_list_alloc ();
-  grep_args[2] = string_list_alloc ();
+
+  for (i = 0; i < 3; i++)
+    {
+      struct grep_task *gt = &grep_task[i];
+
+      gt->matcher = &matcher_grep;
+      gt->pattern_count = 0;
+      gt->patterns = NULL;
+      gt->patterns_size = 0;
+      gt->case_insensitive = false;
+    }
 
   while ((opt = getopt_long (argc, argv, "CD:e:Ef:FhiKM:N:o:pPTVw:",
                             long_options, NULL))
@@ -190,27 +199,77 @@ main (int argc, char **argv)
       case 'e':
        if (grep_pass < 0)
          no_pass (opt);
-       string_list_append (grep_args[grep_pass], "-e");
-       string_list_append (grep_args[grep_pass], optarg);
+       {
+         struct grep_task *gt = &grep_task[grep_pass];
+         /* Append optarg and a newline to gt->patterns.  */
+         size_t len = strlen (optarg);
+         gt->patterns =
+           (char *) xrealloc (gt->patterns, gt->patterns_size + len + 1);
+         memcpy (gt->patterns + gt->patterns_size, optarg, len);
+         gt->patterns_size += len;
+         *(gt->patterns + gt->patterns_size) = '\n';
+         gt->patterns_size += 1;
+         gt->pattern_count++;
+       }
        break;
 
       case 'E':
        if (grep_pass < 0)
          no_pass (opt);
-       string_list_append (grep_args[grep_pass], "-E");
+       grep_task[grep_pass].matcher = &matcher_egrep;
        break;
 
       case 'f':
        if (grep_pass < 0)
          no_pass (opt);
-       string_list_append (grep_args[grep_pass], "-f");
-       string_list_append (grep_args[grep_pass], optarg);
+       {
+         struct grep_task *gt = &grep_task[grep_pass];
+         /* Append the contents of the specified file to gt->patterns.  */
+         FILE *fp = fopen (optarg, "r");
+
+         if (fp == NULL)
+           error (EXIT_FAILURE, errno, _("\
+error while opening \"%s\" for reading"), optarg);
+
+         while (!feof (fp))
+           {
+             char buf[4096];
+             size_t count = fread (buf, 1, sizeof buf, fp);
+
+             if (count == 0)
+               {
+                 if (ferror (fp))
+                   error (EXIT_FAILURE, errno, _("\
+error while reading \"%s\""), optarg);
+                 /* EOF reached.  */
+                 break;
+               }
+
+             gt->patterns =
+               (char *) xrealloc (gt->patterns, gt->patterns_size + count);
+             memcpy (gt->patterns + gt->patterns_size, buf, count);
+             gt->patterns_size += count;
+           }
+
+         /* Append a final newline if file ended in a non-newline.  */
+         if (gt->patterns_size > 0
+             && *(gt->patterns + gt->patterns_size - 1) != '\n')
+           {
+             gt->patterns =
+               (char *) xrealloc (gt->patterns, gt->patterns_size + 1);
+             *(gt->patterns + gt->patterns_size) = '\n';
+             gt->patterns_size += 1;
+           }
+
+         fclose (fp);
+         gt->pattern_count++;
+       }
        break;
 
       case 'F':
        if (grep_pass < 0)
          no_pass (opt);
-       string_list_append (grep_args[grep_pass], "-F");
+       grep_task[grep_pass].matcher = &matcher_fgrep;
        break;
 
       case 'h':
@@ -220,7 +279,7 @@ main (int argc, char **argv)
       case 'i':
        if (grep_pass < 0)
          no_pass (opt);
-       string_list_append (grep_args[grep_pass], "-i");
+       grep_task[grep_pass].case_insensitive = true;
        break;
 
       case 'K':
@@ -344,61 +403,36 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
     error (EXIT_FAILURE, 0, _("%s and %s are mutually exclusive"),
           "--sort-output", "--sort-by-file");
 
+  /* Compile the patterns.  */
+  for (grep_pass = 0; grep_pass < 3; grep_pass++)
+    {
+      struct grep_task *gt = &grep_task[grep_pass];
+
+      if (gt->pattern_count > 0)
+       {
+         if (gt->patterns_size > 0)
+           {
+             /* Strip trailing newline.  */
+             assert (gt->patterns[gt->patterns_size - 1] == '\n');
+             gt->patterns_size--;
+           }
+         gt->compiled_patterns =
+           gt->matcher->compile (gt->patterns, gt->patterns_size,
+                                 gt->case_insensitive, false, false, '\n');
+       }
+    }
+
   /* Read input file.  */
   result = read_po_file (input_file);
 
-  if (grep_args[0]->nitems > 0
-      || grep_args[1]->nitems > 0
-      || grep_args[2]->nitems > 0)
+  if (grep_task[0].pattern_count > 0
+      || grep_task[1].pattern_count > 0
+      || grep_task[2].pattern_count > 0)
     {
       /* Warn if the current locale is not suitable for this PO file.  */
       compare_po_locale_charsets (result);
-
-      /* Attempt to locate the 'grep' program.
-        This is an optimization, to avoid that spawn/exec searches the PATH
-        on every call.  */
-      grep_path = find_in_path ("grep");
-
-      /* On Solaris, we need to use /usr/xpg4/bin/grep instead of
-        /usr/bin/grep, because /usr/bin/grep doesn't understand the options
-        -q and -e.  */
-#if (defined (sun) || defined (__sun)) && defined (__SVR4)
-      if ((strcmp (grep_path, "/usr/bin/grep") == 0
-          || strcmp (grep_path, "/bin/grep") == 0)
-         && access ("/usr/xpg4/bin/grep", X_OK) == 0)
-       grep_path = "/usr/xpg4/bin/grep";
-#endif
     }
 
-  /* Build argument lists for the 'grep' program.  */
-  for (grep_pass = 0; grep_pass < 3; grep_pass++)
-    if (grep_args[grep_pass]->nitems > 0)
-      {
-       string_list_ty *args = grep_args[grep_pass];
-       size_t option_q;
-       size_t i, j;
-
-       /* We use "grep -q" because it is slightly more efficient than
-          "grep".  We pipe grep's output to /dev/null anyway.  But
-          SunOS4's grep program doesn't understand the -q option.  */
-#if (defined (sun) || defined (__sun)) && !defined (__SVR4)
-       option_q = 0;
-#else
-       option_q = 1;
-#endif
-
-       grep_argv[grep_pass] =
-         (char **) xmalloc ((1 + option_q + args->nitems + 1)
-                            * sizeof (char *));
-       grep_argv[grep_pass][0] = (char *) grep_path;
-       j = 1;
-       if (option_q)
-         grep_argv[grep_pass][j++] = "-q";
-       for (i = 0; i < args->nitems; i++)
-         grep_argv[grep_pass][j++] = (char *) args->item[i];
-       grep_argv[grep_pass][j] = NULL;
-      }
-
   /* Select the messages.  */
   result = process_msgdomain_list (result);
 
@@ -588,25 +622,17 @@ nonintr_close (int fd)
 static bool
 is_string_selected (int grep_pass, const char *str, size_t len)
 {
-  if (grep_args[grep_pass]->nitems > 0)
-    {
-      pid_t child;
-      int fd[1];
-      int exitstatus;
+  const struct grep_task *gt = &grep_task[grep_pass];
 
-      /* Open a pipe to a grep subprocess.  */
-      child = create_pipe_out ("grep", grep_path, grep_argv[grep_pass],
-                              DEV_NULL, false, true, true, fd);
-
-      if (full_write (fd[0], str, len) < len)
-       error (EXIT_FAILURE, errno,
-              _("write to grep subprocess failed"));
-
-      close (fd[0]);
+  if (gt->pattern_count > 0)
+    {
+      size_t match_size;
+      size_t match_offset;
 
-      /* Remove zombie process from process list, and retrieve exit status.  */
-      exitstatus = wait_subprocess (child, "grep", false, false, true, true);
-      return (exitstatus == 0);
+      match_offset =
+       gt->matcher->execute (gt->compiled_patterns, str, len,
+                             &match_size, false);
+      return (match_offset != (size_t) -1);
     }
   else
     return 0;
@@ -653,7 +679,7 @@ is_message_selected (const message_ty *mp)
     }
 
   /* Test translator comments using the --comment arguments.  */
-  if (grep_args[2]->nitems > 0
+  if (grep_task[2].pattern_count > 0
       && mp->comment != NULL && mp->comment->nitems > 0)
     {
       size_t length;
index 36ecef2231ad3c47d5db9b3c968a5efd9d241a5f..6b65a4391463487cc050523a88413613a7bdd15d 100644 (file)
@@ -1,3 +1,7 @@
+2005-01-08  Bruno Haible  <bruno@clisp.org>
+
+       * msggrep-4: Remove unportability notes.
+
 2005-01-09  Bruno Haible  <bruno@clisp.org>
 
        * xgettext-8: New file.
index 873cc5fb70d417451b86d34e9533eeebd8f56d13..0d80f56dc2977ad6b434fd64442db8d279ced302 100755 (executable)
@@ -2,11 +2,6 @@
 
 # Test multiple -e and multiple -f options.
 
-# Note: This test fails on AIX 3 because grep, when called with both -e and
-# -f arguments, ignores the -e arguments. It is fixed on AIX 4.
-
-# Note: This test fails on SunOS 4 because grep doesn't have a -f option.
-
 tmpfiles=""
 trap 'rm -fr $tmpfiles' 1 2 3 15