Lars Gullik Bjønnes wrote:
> | Not from me. Looks entirely reasonable. I'm getting pissed off with all
> | these whitespace changes though. I'm going to run this over the source
> | tree after I commit the BufferParams pimpl patch.
>>
> | find src -name "*" | while read file; do
> |         sed 's/^[<TAB> ]\{1,\}$//' $file > tmp
> |         cmp -s $file tmp || mv -f tmp $file
> | done
> 
> I do not understand what that sed does...

Well, _this_ removes all trailing whitespace from a line
        sed 's/[<TAB> ]\{1,\}$//' $file > tmp

Here's what it means:
'$' means end-of-line, so I'm trying to match a regex at the end of each line 
only.
[ab] is standard Regular Expression meaning match either 'a' or 'b'. In this 
case, I want to match either a literal tab, Cntl-VCntl-I, or a space.
\{1,\} matches 1 or more instances of the preceding regex.

Hence, sed 's/[<TAB> ]\{1,\}$//' will match 1 or more whitespace chars at the 
end of the line and remove them.

I ended up being paranoid and wnated to see what was going on, so I ran


for file in `find src -name "*"`
do
        # Is $file a directory?
        test -d $file && continue
        # Is $file readable and writable?
        test -w $file && test -r $file || continue
        # Strip trailing whitespace from $file, storing the result in tmp
        sed 's/[      ]\{1,\}$//' $file > tmp
        # Check: are $file and tmp different?
        cmp -s $file tmp && continue
        # Show the differences. cat -e displays a '$' at the end of the line
        # of the line so that I can see trailing whitespace.
        diff -u $file tmp | cat -e
        # Ask before replacing $file.
        mv -i tmp $file
done

The resulting diff is 300KB in size; there was lots of crap in the source tree 
:-(

134 files changed, 1967 insertions(+), 1967 deletions(-)

I have just finished re-building (curently linking) so will commit in a 
moment.

-- 
Angus

Reply via email to