summaryrefslogtreecommitdiff
path: root/v4l/scripts/strip-trailing-whitespaces.sh
blob: 1a23e436dc2309404d51205a3d2a2858b70b8d19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/sh

# tmp dir for my files
WORK="${TMPDIR-/tmp}/${0##*/}-$$"
mkdir "$WORK" || exit 1
trap 'rm -rf "$WORK"' EXIT

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"
done