test defs: add subroutine for input unindenting
authorStefano Lattarini <stefano.lattarini@gmail.com>
Tue, 15 Feb 2011 11:45:28 +0000 (12:45 +0100)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Wed, 16 Feb 2011 11:57:55 +0000 (12:57 +0100)
* tests/defs.in (unindent): New subroutine.

ChangeLog
tests/defs.in

index fa53707..4563585 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2011-02-16  Stefano Lattarini  <stefano.lattarini@gmail.com>
+           Ralf Wildenhues  <Ralf.Wildenhues@gmx.de>
+
+       test defs: add subroutine for input unindenting
+       * tests/defs.in (unindent): New subroutine.
+
 2011-02-15  Stefano Lattarini  <stefano.lattarini@gmail.com>
 
        python: report the 'PYTHON' influential environment variable
index eb92caa..ffe21e1 100644 (file)
@@ -440,6 +440,24 @@ AUTOMAKE_fails ()
   AUTOMAKE_run 1 ${1+"$@"}
 }
 
+# unindent [input files...]
+# -------------------------
+# Remove the "proper" amount of leading whitespace from the given files,
+# and output the result on stdout.  That amount is determined by looking
+# at the leading whitespace of the first non-blank line in the input
+# files.  If no input file is specified, standard input is implied.
+unindent ()
+{
+  cat ${1+"$@"} > deindent.tmp
+  indentation=`sed <deindent.tmp -n "
+    /[^ $tab].*$/{
+      s///p
+      q
+  }"`
+  sed "s/^$indentation//" deindent.tmp
+  rm -f deindent.tmp
+}
+
 # Turn on shell traces.
 set -x