packaging: fixed malformed changelog entry.
[profile/ivi/speech-recognition.git] / scripts / cleanup-whitespace.sh
1 #!/bin/bash
2
3 # Replace TABs with sequences of 8 spaces in all given files.
4 replace_tabs() {
5     local _file _tmp
6
7     for _file in $*; do
8         _tmp=$_file.tabs
9         cp $_file $_tmp && \
10             cat $_tmp | \
11                 sed 's/\t/        /g' > $_file && \
12         rm -f $_tmp
13     done
14 }
15
16
17 # Replaces lines containing only spaces with empty lines in all given files.
18 strip_empty_lines() {
19     local _file _tmp
20
21     for _file in $*; do
22         _tmp=$_file.spaces
23         cp $_file $_tmp && \
24             cat $_tmp | \
25                 sed 's/^ [ ]*$//g' > $_file && \
26         rm -f $_tmp
27     done
28 }
29
30
31 # Strip trailing white space from all the given files.
32 strip_trailing_ws() {
33     local _file _tmp
34
35     for _file in $*; do
36         _tmp=$_file.spaces
37         cp $_file $_tmp && \
38             cat $_tmp | \
39                 sed 's/ *$//g' > $_file && \
40         rm -f $_tmp
41     done
42 }
43
44
45 # Clean up TABS and empty lines in all given or found files.
46 if [ -n "$*" ]; then
47     replace_tabs $* && \
48         strip_empty_lines $* && \
49             strip_trailing_ws $*
50 else
51     files=$(find . -name \*.h -o -name \*.c)
52     replace_tabs $files && \
53         strip_empty_lines $files && \
54             strip_trailing_ws $files
55 fi