From 78992b3411196a4e9e66bffed5a6ab96aa9d648f Mon Sep 17 00:00:00 2001 From: Peter Rosin Date: Tue, 1 Mar 2011 08:25:24 +0100 Subject: [PATCH] test defs: unindent without temporary file * tests/defs.in (commented_sed_unindent_prog): Commented Sed program that strips the "proper" amount of leading whitespace. (unindent): Lazily strip comments from the above program and use it to unindent without using a temporary file. Signed-off-by: Peter Rosin --- ChangeLog | 8 ++++++++ tests/defs.in | 27 +++++++++++++++++++-------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 47bc9fcdf..6f67d36cf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-03-01 Peter Rosin + + test defs: unindent without temporary file + * tests/defs.in (commented_sed_unindent_prog): Commented Sed program + that strips the "proper" amount of leading whitespace. + (unindent): Lazily strip comments from the above program and use it + to unindent without using a temporary file. + 2011-02-26 Stefano Lattarini libtool: suggest LT_INIT if LTLIBRARIES primary is used diff --git a/tests/defs.in b/tests/defs.in index fd0cc9cd5..2685112ed 100644 --- a/tests/defs.in +++ b/tests/defs.in @@ -440,6 +440,21 @@ AUTOMAKE_fails () AUTOMAKE_run 1 ${1+"$@"} } +commented_sed_unindent_prog=' + /^$/b # Nothing to do for empty lines. + x # Get x into pattern space. + /^$/{ # No prior x, go prepare it. + g # Copy this 1st non-blank line into pattern space. + s/^\(['"$tab"' ]*\).*/x\1/ # Prepare x in pattern space. + } # Now: x in pattern and in hold. + G # Build x\n in pattern space, and + h # duplicate it into hold space. + s/\n.*$// # Restore x in pattern space, and + x # exchange with the above duplicate in hold space. + s/^x\(.*\)\n\1// # Remove leading from . + s/^x.*\n// # Restore when there is no leading . +' + # unindent [input files...] # ------------------------- # Remove the "proper" amount of leading whitespace from the given files, @@ -448,14 +463,10 @@ AUTOMAKE_fails () # files. If no input file is specified, standard input is implied. unindent () { - cat ${1+"$@"} > deindent.tmp - indentation=`sed