diff options
Diffstat (limited to 'v4l/scripts/strip-trailing-whitespaces.sh')
-rwxr-xr-x | v4l/scripts/strip-trailing-whitespaces.sh | 57 |
1 files changed, 24 insertions, 33 deletions
diff --git a/v4l/scripts/strip-trailing-whitespaces.sh b/v4l/scripts/strip-trailing-whitespaces.sh index 1a23e436d..a546a0b9f 100755 --- a/v4l/scripts/strip-trailing-whitespaces.sh +++ b/v4l/scripts/strip-trailing-whitespaces.sh @@ -1,37 +1,28 @@ #!/bin/sh +# Strips trailing whitespace. Leading spaces and spaces after tabs are +# converted to the equivalent sequence of tabs only. -# tmp dir for my files -WORK="${TMPDIR-/tmp}/${0##*/}-$$" -mkdir "$WORK" || exit 1 -trap 'rm -rf "$WORK"' EXIT +# Use the option "fast" to only check files Hg thinks are new or modified. +# The option "manifest" will use Hg's manifest command to check all files +# under Hg revision control. +# Otherwise, all files under the linux tree are checked, except files in CVS +# directories and .cvsignore files. This is the historical behavior. -for file in `find linux -type d | grep -v CVS | grep -v .cvsignore` ; do - mkdir -p "$WORK/${file}" -done -for file in `find linux -type f | grep -v CVS | grep -v .cvsignore` ; do - tmpfile="$WORK/${file}.$$" - perl -ne 's/[ \t]+$//; - s/^\ \ \ \ \ \ \ \ /\t/; - s/^\ \ \ \ \ \ \ \t/\t/; - s/^\ \ \ \ \ \ \t/\t/; - s/^\ \ \ \ \ \t/\t/; - s/^\ \ \ \t/\t/; - s/^\ \ \t/\t/; - s/^\ \t/\t/; - $m=1; - while ($m>0) { - $m=0; - $m= s/\t\ \ \ \ \ \ \ \ /\t\t/g; - $m=$m+s/\t\ \ \ \ \ \ \ \t/\t\t/g; - $m=$m+s/\t\ \ \ \ \ \ \t/\t\t/g; - $m=$m+s/\t\ \ \ \ \ \t/\t\t/g; - $m=$m+s/\t\ \ \ \t/\t\t/g; - $m=$m+s/\t\ \ \t/\t\t/g; - $m=$m+s/\t\ \t/\t\t/g; - } - print' < "${file}" > "${tmpfile}" - diff -u "${file}" "${tmpfile}" | sed \ - -e "s|^--- ${file}|--- ${file}.orig|" \ - -e "s|^+++ ${tmpfile}|+++ ${file}|" - rm -f "$tmpfile" + +if [ "x$1" = "xfast" ]; then + files="hg status -man" +elif [ "x$1" = "xmanifest" ]; then + files="hg manifest | cut '-d ' -f3" +else + files="find linux -name CVS -prune -o -type f -not -name .cvsignore -print" +fi + +for file in `eval $files`; do + perl -ne ' + s/[ \t]+$//; + s<^ {8}> <\t>; + s<^ {1,7}\t> <\t>; + while( s<\t {8}> <\t\t>g || s<\t {1,7}\t> <\t\t>g ) {}; + print' < "${file}" | \ + diff -u --label="$file" "$file" --label="$file" - done |