On Tue, Jun 05, 2007 at 04:12:54PM +0200, Sam Ravnborg wrote:
> On Tue, Jun 05, 2007 at 03:38:34PM +0200, Oleg Verych wrote:
> > On Tue, Jun 05, 2007 at 10:19:59AM +0200, Sam Ravnborg wrote:
> > []
> > > If on the other hand you are proposing a script to clean whitespace
> > > damage in the code then git already does this nicely.
> > 
> > I've read that too quickly, sorry. What then all that clean scripts
> > are for?
> cleanfile compress spaces to tabs where appropriate. It does more
> than just warn about too long lines and remove leading whitespace.


It's not an occasion, that this script does job of two, you are referring
to. I should add documentation to this script, that will far longer, that
script itself.

-*- slightly i/o optimized <clean-whitespace.sh> -*-
#!/bin/sh -e
# clean whitespace damage; i/o=stdin/stdout
IFS='' ; t="`printf '\t'`" ; s=' ' ; s7="$s$s$s$s$s$s$s" ; w79=79 ;
case $0 in *diff* | *patch*) p='+' ; s='';; esac

expand | while read line
do case "$line" in
   ++*) echo "$line";;
   $p*) [ ${#line} -gt $w79 ] && : ${long:=line}
        echo "$line" | sed "/^$p/{s_ *\$__;s_^$p$s7${s}_$p${t}_;s_$s7 _${t}_g}"
     *) echo "$line";;
[ -n "$long" ] && echo "at least one line, wider than $w79 chars, found" 1>&2


First line stops word splitting, puts tab symbol in t, space in s,
seven spaces to s7 and line width limit to w79.

Second -- adjust set variables for need of unified diff processing, if
name of the script $0 (can be changed to match command-line
parameters) have "diff" or "patch".

Last -- bark, if there is at least one line longer that w79.

Rest is processing of files/patches to expand(posix tool) tabs to spaces
- patches are processed only by lines, starting from `+', but not `++'
- remove trailing whitespace;
- substitute eight spaces to one tab symbol
- patches have "linestart`+tab'" expanded to seven spaces, due to `+' and
  tabstop, thus seven spaces are substituted in this case.

Anything else, if have not noticed in whitespace damage matching can be
added on request ;)

> Please look at latest -git tree if you are trying to improve
> the clean* scripts or add counterparts.
> Thanks,
>       Sam

This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
kbuild-devel mailing list

Reply via email to