* Stefano Lattarini wrote on Tue, Feb 15, 2011 at 01:36:16PM CET: > OK, here's my shot at it. The implementation might be suboptimal, > but since it wasn't completely obvious to get right, I'd rather not > tweak it anymore, until there's a real need at least.
Lemme tweak it for you. ;-) > (By the way, I think that we should really start testing non-obvious > subroutines and pieces of code defined in tests/defs. But that's > for another thread). Fine with me, on all accounts. > Subject: [PATCH] test defs: add subroutine for input unindenting > > * tests/defs.in (unindent): New subroutine. > --- a/tests/defs.in > +++ b/tests/defs.in > @@ -440,6 +440,31 @@ 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]*$/n > + s/[^ $tab].*$// > + t end > + b > +: end > + p > + q > + "` The space after : is not portable. The sed script could be shortened to sed -n "/[^ $tab].*$/{ s///p d }" > + case $indentation in > + '') cat deindent.tmp;; > + *) sed "s/^$indentation//" deindent.tmp;; > + esac These four lines can be shortened to sed "s/^$indentation//" deindent.tmp > + rm -f deindent.tmp > +} OK with those addressed. It's a bit of a shame this uses a temp file though. awk should be able to cope without (but be sure to try old Solaris awk if you go for it). Thanks, Ralf