[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 4/4] gnulib-tool: faster string handling for Posix shells.
From: |
Ralf Wildenhues |
Subject: |
[PATCH 4/4] gnulib-tool: faster string handling for Posix shells. |
Date: |
Sun, 28 Dec 2008 11:20:00 +0100 |
User-agent: |
Mutt/1.5.18 (2008-05-17) |
* gnulib-tool (func_strip): New function.
(func_get_dependencies, func_get_automake_snippet): Use it
where possible to avoid 'sed' with Posix shells.
---
gnulib-tool | 96 ++++++++++++++++++++++++++++++++++++++++------------------
1 files changed, 66 insertions(+), 30 deletions(-)
diff --git a/gnulib-tool b/gnulib-tool
index af0726e..eebc2bf 100755
--- a/gnulib-tool
+++ b/gnulib-tool
@@ -405,6 +405,21 @@ else
}
fi
+# func_strip name prefix suffix
+if ( eval 'foo=bar; test "${foo%r}" = ba' ) >/dev/null 2>&1; then
+ func_strip ()
+ {
+ stripped=$1
+ stripped=${stripped#$2}
+ stripped=${stripped%$3}
+ }
+else
+ func_strip ()
+ {
+ stripped=`echo "$1" | sed "s/^$2//; s/$3$//"`
+ }
+fi
+
# func_fatal_error message
# outputs to stderr a fatal error message, and terminates the program.
# Input:
@@ -1421,8 +1436,10 @@ func_get_dependencies ()
module_deps=
# ${module}-tests always implicitly depends on ${module}.
case $1 in
- *-tests*)
- module_deps=`echo "$1" | sed -n -e 's/-tests$//p'` ;;
+ *-tests)
+ func_strip "$1" '' -tests
+ module_deps=$stripped
+ ;;
esac
# Then the explicit dependencies listed in the module description.
func_cache_lookup_module "$1"
@@ -1467,11 +1484,15 @@ func_get_automake_snippet ()
# Synthesize an EXTRA_DIST augmentation.
func_get_filelist "$mymodule"
all_files=$module_files
- tests_files=`for f in $all_files; do \
- case $f in \
- tests/*) echo $f ;; \
- esac; \
- done | sed -e 's,^tests/,,'`
+ tests_files=
+ for f in $all_files; do
+ case $f in
+ tests/*)
+ func_strip "$f" tests/ ''
+ func_append tests_files " $stripped"
+ ;;
+ esac
+ done
extra_files="$tests_files"
if test -n "$extra_files"; then
set x $extra_files
@@ -1495,11 +1516,15 @@ func_get_automake_snippet ()
| sed -n -e "$sed_extract_mentioned_files" | sed -e 's/#.*//'`
func_get_filelist "$mymodule"
all_files=$module_files
- lib_files=`for f in $all_files; do \
- case $f in \
- lib/*) echo $f ;; \
- esac; \
- done | sed -e 's,^lib/,,'`
+ lib_files=
+ for f in $all_files; do
+ case $f in
+ lib/*)
+ func_strip "$f" lib/ ''
+ func_append lib_files "$nl$stripped"
+ ;;
+ esac
+ done
# Remove $already_mentioned_files from $lib_files.
echo "$lib_files" | LC_ALL=C sort -u > "$tmp"/lib-files
extra_files=`func_reset_sigpipe; \
@@ -1524,36 +1549,47 @@ func_get_automake_snippet ()
case "$mymodule" in
relocatable-prog-wrapper) ;;
*)
- sed_extract_c_files='/\.c$/p'
- extra_files=`echo "$extra_files" | sed -n -e "$sed_extract_c_files"`
- if test -n "$extra_files"; then
- set x $extra_files
+ extra_c_files=
+ for f in $extra_files; do
+ case $f in
+ *.c)
+ func_append extra_c_files " $f" ;;
+ esac
+ done
+ if test -n "$extra_c_files"; then
+ set x $extra_c_files
shift
func_append module_makefile "${nl}EXTRA_lib_SOURCES += $*"
fi
;;
esac
# Synthesize an EXTRA_DIST augmentation also for the files in build-aux/.
- buildaux_files=`for f in $all_files; do \
- case $f in \
- build-aux/*) echo $f ;; \
- esac; \
- done | sed -e 's,^build-aux/,,'`
+ buildaux_files=
+ for f in $all_files; do
+ case $f in
+ build-aux/*)
+ func_strip "$f" build-aux/ ''
+ func_append buildaux_files " \$(top_srcdir)/$auxdir/$stripped"
+ ;;
+ esac
+ done
if test -n "$buildaux_files"; then
- sed_prepend_auxdir='s,^,$(top_srcdir)/'"$auxdir"'/,'
- set x `echo "$buildaux_files" | sed -e "$sed_prepend_auxdir"`
+ set x $buildaux_files
shift
func_append module_makefile "${nl}EXTRA_DIST += $*"
fi
# Synthesize an EXTRA_DIST augmentation also for the files from top/.
- top_files=`for f in $all_files; do \
- case $f in \
- top/*) echo $f ;; \
- esac; \
- done | sed -e 's,^top/,,'`
+ top_files=
+ for f in $all_files; do \
+ case $f in \
+ top/*)
+ func_strip "$f" top/ ''
+ func_append top_files " \$(top_srcdir)/$stripped"
+ ;;
+ esac
+ done
if test -n "$top_files"; then
- sed_prepend_topdir='s,^,$(top_srcdir)/,'
- set x `echo "$top_files" | sed -e "$sed_prepend_topdir"`
+ set x $top_files
shift
func_append module_makefile "${nl}EXTRA_DIST += $*"
fi
--
1.6.1.rc3.96.g159c88