3 # Usage: fix_ws [dir]...
5 temp="/tmp/fix_ws.$$.$RANDOM"
8 begin8sp_tab=$'s/^ /\t/'
9 beginchar7sp_chartab=$'s/^\\([^ \t]\\) /\\1\t/'
10 tab8sp_tabtab=$'s/\t /\t\t/g'
11 tab8sptab_tabtabtab=$'s/\t \t/\t\t\t/g'
12 begin17sptab_tab=$'s/^ \\{1,7\\}\t/\t/'
13 tab17sptab_tabtab=$'s/\t \\{1,7\\}\t/\t\t/g'
14 trailingws_=$'s/[ \t]*$//'
20 test "YES" = "${name/*.bz2/YES}" && continue
21 test "YES" = "${name/*.gz/YES}" && continue
22 test "YES" = "${name/*.png/YES}" && continue
23 test "YES" = "${name/*.gif/YES}" && continue
24 test "YES" = "${name/*.jpg/YES}" && continue
25 test "YES" = "${name/*.diff/YES}" && continue
26 test "YES" = "${name/*.patch/YES}" && continue
27 # shell testsuite entries are not to be touched too
28 test "YES" = "${name/*.right/YES}" && continue
30 if test "YES" = "${name/*.[chsS]/YES}" \
31 -o "YES" = "${name/*.sh/YES}" \
32 -o "YES" = "${name/*.txt/YES}" \
33 -o "YES" = "${name/*.html/YES}" \
34 -o "YES" = "${name/*.htm/YES}" \
35 -o "YES" = "${name/*Config.in*/YES}" \
37 # More aggressive whitespace fixes for known file types
38 echo "Formatting: $name" >&2
40 | sed -e "$tab8sptab_tabtabtab" -e "$tab8sptab_tabtabtab" \
41 -e "$tab8sptab_tabtabtab" -e "$tab8sptab_tabtabtab" \
42 | sed "$begin17sptab_tab" \
43 | sed -e "$tab17sptab_tabtab" -e "$tab17sptab_tabtab" \
44 -e "$tab17sptab_tabtab" -e "$tab17sptab_tabtab" \
45 -e "$tab17sptab_tabtab" -e "$tab17sptab_tabtab" \
47 elif test "YES" = "${name/*Makefile*/YES}" \
48 -o "YES" = "${name/*Kbuild*/YES}" \
50 # For Makefiles, never convert "1-7spaces+tab" into "tabtab"
51 echo "Makefile: $name" >&2
53 | sed -e "$tab8sptab_tabtabtab" -e "$tab8sptab_tabtabtab" \
54 -e "$tab8sptab_tabtabtab" -e "$tab8sptab_tabtabtab" \
55 | sed -e "$tab17sptab_tabtab" -e "$tab17sptab_tabtab" \
56 -e "$tab17sptab_tabtab" -e "$tab17sptab_tabtab" \
57 -e "$tab17sptab_tabtab" -e "$tab17sptab_tabtab" \
60 # Only remove trailing WS for the rest
61 echo "Removing trailing whitespace: $name" >&2
66 # diff -u "$temp" "$name" >>fix_ws.diff
68 # Conserve mode/symlink:
71 rm "$temp" 2>/dev/null