File: fix_ws.sh

package info (click to toggle)
acx100 20060521-3
  • links: PTS
  • area: contrib
  • in suites: etch, etch-m68k
  • size: 836 kB
  • ctags: 2,349
  • sloc: ansic: 14,341; sh: 636; makefile: 111; perl: 101
file content (43 lines) | stat: -rw-r--r-- 1,302 bytes parent folder | download | duplicates (2)
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
38
39
40
41
42
43
#!/bin/sh
# Whitespace fixer

temp=$$.$RANDOM

begin8sp_tab=$'s/^        /\t/'
beginchar7sp_chartab=$'s/^\\([^ \t]\\)       /\\1\t/'
tab8sp_tabtab=$'s/\t        /\t\t/g'
begin17sptab_tab=$'s/^ \\{1,7\\}\t/\t/'
tab17sptab_tabtab=$'s/\t \\{1,7\\}\t/\t\t/g'
trailingws_=$'s/[ \t]*$//'
# Fixes whitespace in strings:
# printk(KERN_WARNING "ISILoad:Card%d rejected load header:\n"...);
wscr_cr=$'s/[ \t]*\\\\n/\\\\n/'

find -type f \
| while read name; do
    if test "C" = "${name/*.[ch]/C}" \
	 -o "SH" = "${name/*.sh/SH}"; then
	echo "Formatting $name as C or sh file" >&2
	cat "$name" \
	| sed "$begin8sp_tab" \
	| sed "$begin17sptab_tab" \
	| sed -e "$tab8sp_tabtab" -e "$tab8sp_tabtab" -e "$tab8sp_tabtab" \
	      -e "$tab8sp_tabtab" -e "$tab8sp_tabtab" -e "$tab8sp_tabtab" \
	| sed -e "$tab17sptab_tabtab" -e "$tab17sptab_tabtab" \
	      -e "$tab17sptab_tabtab" -e "$tab17sptab_tabtab" \
	      -e "$tab17sptab_tabtab" -e "$tab17sptab_tabtab" \
	| sed "$trailingws_" \
	| sed -e "$wscr_cr" -e "$wscr_cr" -e "$wscr_cr" -e "$wscr_cr" \
	      -e "$wscr_cr" -e "$wscr_cr" -e "$wscr_cr" -e "$wscr_cr" \

    else
	echo "Removing trailing spaces from $name" >&2
	cat "$name" \
	| sed "$trailingws_" \

    fi >"$name.$temp"

    # Conserve mode:
    cat "$name.$temp" >"$name"
    rm "$name.$temp"
done