# Walk PATH.
for directory in $PATH; do
if test -x "$directory/$1"; then
- echo "$directory/$1"
+ printf '%s\n' "$directory/$1"
return 0
fi
done
sed_i() {
cmd_i sed "$@"
}
+grep_i() {
+ cmd_i grep "$@"
+}
+
+# Usage: perl_line_filter <cmd> ...
+#
+# Run the perl command cmd on each line before printing it.
+perl_line_filter() {
+ cmd="$1"
+ shift
+
+ # Can't use -pe because it uses <> which treats the arguments as files.
+ perl -e "use strict; use warnings; while (<STDIN>) { $cmd; print; }" "$@"
+}
+
+# Usage: simple_cpp <FIRST> <SECOND> .. -- <replacement-for-first> ...
+#
+# Replaces each FIRST (on word boundaries) with <replacement-for-first> like a
+# simple cpp replacement.
+simple_cpp() {
+ cmd='my $i = 0;'
+
+ for x; do
+ shift
+
+ if test x"$x" = x--; then
+ break
+ fi
+
+ cmd="$cmd s/\b$x\b/\$ARGV[\$i]/g; \$i++;"
+ done
+
+ perl_line_filter "$cmd" -- "$@"
+}
# Print the current OS. The following OS are supported at the moment:
+#
# - Debian (debian)
# - Gentoo (gentoo)
# - Mac OS X (darwin)
# - Solaris/OpenSolaris (sun)
# - FreeBSD (freebsd)
+#
# If an unsupported OS is used an error is printed.
os() {
if test -f /etc/debian_version; then
# Get all necessary paths.
pwd=`pwd`
- base=`echo "$2" | sed "s|\~|$HOME|"` # expand ~, some sh don't do it
+ base=`printf '%s' "$2" | sed "s|\~|$HOME|"` # expand ~, some sh don't do it
base=`dirname "$base"`
- source=`echo "$pwd/$1" | sed "s|$base/||"`
+ source=`printf '%s' "$pwd/$1" | sed "s|$base/||"`
target=`basename "$2"`
# Go to the directory where the link is going to be created.
# overwriting real files.
if ( test -f "$target" && test ! -h "$target" ) || \
( test -s "$target" && test ! -h "$target" ); then
- echo "link(): target '$target' exists already and is no symbolic link!" >&2
+ printf "link(): target '%s' exists already and is no symbolic link!" \
+ "$target" >&2
exit 1
fi
# Make sure the source exists (is file, directory or link).
if test ! -f "$source" && test ! -d "$source" && test ! -h "$source"; then
- echo "link(): source '$source' doesn't exist!" >&2
+ printf "link(): source '%s' doesn't exist!" "$source" >&2
exit 1
fi
# Create the new symbolic link; remove the old one if necessary.
- echo "link(): linking '$source' to '$target'"
+ printf "link(): linking '%s' to '%s'\n" "$source" "$target"
rm -f "$target"
ln -s "$source" "$target"
echo '# WARNING! DO NOT EDIT THIS FILE! #' >>"$file"
echo '###################################' >>"$file"
echo >>"$file"
- echo "# It was generated from $file$extension on `date`." >>"$file"
+ printf "# It was generated from '%s' on %s.\n" \
+ "$file$extension" "`date`" >>"$file"
echo >>"$file"
file_tmp="$file"