Hi Peter, * Peter Rosin wrote on Sat, Feb 19, 2011 at 12:28:53AM CET: > unindent () > { > sed ' > /^$/b # Nothing to do for empty lines, next line please. > x # Get x<indent> into pattern space. > /^$/{ # No prior x<indent>, go prepare it. > g # Copy this 1st non-blank line into pattern space. > s/^\([ ]*\).*/x\1/ # Prepare x<indent> in pattern space.
tab before space, please; or even better, use ...'"$tab"'... > } # Now: x<indent> in pattern and <line> in hold. > G # Build x<indent>\n<line> in pattern space, and > h # duplicate it into hold space. > s/\n.*$// # Restore x<indent> in pattern space, and > x # exchange with the above duplicate in hold space. > s/^x\(.*\)\n\1// # Remove leading <indent> from <line>. > s/^.*\n//' # Restore <line> when there's no leading <indent>. > } I kinda like this. It will be unintelligible without the comments, however. gnulib-tool has a sed comment removal, search for $sed_comments. What I wouldn't like is invoking an extra sed in each test startup just to remove comments from a helper function, that will noticeably slow down things (it could be removed at config.status time?); OTOH, this function will be faster than our current unindent. And I'll defer to Stefano's preference for or against complex code in the testsuite. Thanks, Ralf