summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorDoohwan Kim <dh8210.kim@samsung.com>2015-02-26 17:39:16 +0900
committerDoohwan Kim <dh8210.kim@samsung.com>2015-02-26 17:39:45 +0900
commitda07ee69267b4557028357eae802d2a7a57c34e7 (patch)
tree02a5d7590fc35cd3ad08aa8894ca5f32947a1da1 /scripts
parent34c41c0eecd122a3dd92b30f30267ea4d951343a (diff)
downloadmurphy-tizen_3.0.2015.q2_common.tar.gz
murphy-tizen_3.0.2015.q2_common.tar.bz2
murphy-tizen_3.0.2015.q2_common.zip
Signed-off-by: Doohwan Kim <dh8210.kim@samsung.com> Change-Id: I2ad7e23e121506673a724f512fea429489928451
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/cleanup-whitespace.sh55
1 files changed, 55 insertions, 0 deletions
diff --git a/scripts/cleanup-whitespace.sh b/scripts/cleanup-whitespace.sh
new file mode 100755
index 0000000..bfab741
--- /dev/null
+++ b/scripts/cleanup-whitespace.sh
@@ -0,0 +1,55 @@
+#!/bin/bash
+
+# Replace TABs with sequences of 8 spaces in all given files.
+replace_tabs() {
+ local _file _tmp
+
+ for _file in $*; do
+ _tmp=$_file.tabs
+ cp $_file $_tmp && \
+ cat $_tmp | \
+ sed 's/\t/ /g' > $_file && \
+ rm -f $_tmp
+ done
+}
+
+
+# Replaces lines containing only spaces with empty lines in all given files.
+strip_empty_lines() {
+ local _file _tmp
+
+ for _file in $*; do
+ _tmp=$_file.spaces
+ cp $_file $_tmp && \
+ cat $_tmp | \
+ sed 's/^ [ ]*$//g' > $_file && \
+ rm -f $_tmp
+ done
+}
+
+
+# Strip trailing white space from all the given files.
+strip_trailing_ws() {
+ local _file _tmp
+
+ for _file in $*; do
+ _tmp=$_file.spaces
+ cp $_file $_tmp && \
+ cat $_tmp | \
+ sed 's/ *$//g' > $_file && \
+ rm -f $_tmp
+ done
+}
+
+
+# Clean up TABS and empty lines in all given or found files.
+if [ -n "$*" ]; then
+ replace_tabs $* && \
+ strip_empty_lines $* && \
+ strip_trailing_ws $*
+else
+ files=$(find . -name \*.h -o -name \*.c)
+ replace_tabs $files && \
+ strip_empty_lines $files && \
+ strip_trailing_ws $files
+fi