diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-12 22:48:58 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-12 22:48:58 +0000 |
commit | a8374a19161f7a8d09309da730aa786ca773789f (patch) | |
tree | 0af2fe30dfc192404dc58234bd778c7bbe0d7381 | |
parent | adbb73bda7c0ff75caceaf6ad29187293f0afd3f (diff) | |
download | busybox-w32-a8374a19161f7a8d09309da730aa786ca773789f.tar.gz busybox-w32-a8374a19161f7a8d09309da730aa786ca773789f.tar.bz2 busybox-w32-a8374a19161f7a8d09309da730aa786ca773789f.zip |
whitespace fixing script
-rwxr-xr-x | scripts/fix_ws.sh | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/scripts/fix_ws.sh b/scripts/fix_ws.sh new file mode 100755 index 000000000..89fce959a --- /dev/null +++ b/scripts/fix_ws.sh | |||
@@ -0,0 +1,61 @@ | |||
1 | #!/bin/bash | ||
2 | # Whitespace fixer | ||
3 | # Usage: fix_ws [dir]... | ||
4 | |||
5 | temp="/tmp/fix_ws.$$.$RANDOM" | ||
6 | |||
7 | # Using $'xxx' bashism | ||
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]*$//' | ||
15 | |||
16 | #>fix_ws.diff | ||
17 | |||
18 | find "$@" -type f \ | ||
19 | | while read name; do | ||
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 | ||
29 | |||
30 | if test "YES" = "${name/*.[ch]/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/*Makefile*/YES}" \ | ||
36 | -o "YES" = "${name/*Kbuild*/YES}" \ | ||
37 | -o "YES" = "${name/*Config.in*/YES}" \ | ||
38 | ; then | ||
39 | # More aggressive whitespace fixes for known file types | ||
40 | echo "Formatting: $name" >&2 | ||
41 | cat "$name" \ | ||
42 | | sed -e "$tab8sptab_tabtabtab" -e "$tab8sptab_tabtabtab" \ | ||
43 | -e "$tab8sptab_tabtabtab" -e "$tab8sptab_tabtabtab" \ | ||
44 | | sed "$begin17sptab_tab" \ | ||
45 | | sed -e "$tab17sptab_tabtab" -e "$tab17sptab_tabtab" \ | ||
46 | -e "$tab17sptab_tabtab" -e "$tab17sptab_tabtab" \ | ||
47 | -e "$tab17sptab_tabtab" -e "$tab17sptab_tabtab" \ | ||
48 | | sed "$trailingws_" | ||
49 | else | ||
50 | # Only remove trailing WS for the rest | ||
51 | echo "Removing trailing whitespace: $name" >&2 | ||
52 | cat "$name" \ | ||
53 | | sed "$trailingws_" | ||
54 | fi >"$temp" | ||
55 | |||
56 | # diff -u "$temp" "$name" >>fix_ws.diff | ||
57 | |||
58 | # Conserve mode/symlink: | ||
59 | cat "$temp" >"$name" | ||
60 | done | ||
61 | rm "$temp" 2>/dev/null | ||