+ "$@" >"$last".tmp
+ mv "$last".tmp "$last"
+}
+
+# Usage: sed_i ... <file>
+#
+# sed -i is not portable due to different implementations. See cmd_i.
+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)
+# - Solaris/OpenSolaris (sun)
+# - FreeBSD (freebsd)
+#
+# If an unsupported OS is used an error is printed.
+os() {
+ if test -f /etc/debian_version; then
+ echo debian
+ elif test -f /etc/gentoo-release; then
+ echo gentoo
+ elif test x"`uname`" = xSunOS; then
+ echo sun
+ elif test x"`uname`" = xFreeBSD; then
+ echo freebsd
+ else
+ echo 'unsupported OS!' >&2
+ return 1
+ fi
+}
+
+# Creates a symbolic link for file $1 in dirname of $2 with name of basename