From 78063ca2bd6964d76654527eb8cf4971e4d93d50 Mon Sep 17 00:00:00 2001 From: Nick Terrell Date: Wed, 29 Mar 2017 18:47:23 -0700 Subject: [PATCH] spaces to tabs --- contrib/linux-kernel/spaces_to_tabs.sh | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 contrib/linux-kernel/spaces_to_tabs.sh diff --git a/contrib/linux-kernel/spaces_to_tabs.sh b/contrib/linux-kernel/spaces_to_tabs.sh new file mode 100755 index 000000000..ebde5fbaa --- /dev/null +++ b/contrib/linux-kernel/spaces_to_tabs.sh @@ -0,0 +1,28 @@ +#!/bin/sh +set -e + +# Constants +INCLUDE='include/' +LIB='lib/' +SPACES=' ' +TAB=$'\t' +TMP="replacements.tmp" + +echo "Files: " $INCLUDE* $LIB* + +# Check files for existing tabs +grep "$TAB" $INCLUDE* $LIB* && exit 1 || true +# Replace the first tab on every line +sed -i '' "s/^$SPACES/$TAB/" $INCLUDE* $LIB* + +# Execute once and then execute as long as replacements are happening +more_work="yes" +while [ ! -z "$more_work" ] +do + rm -f $TMP + # Replaces $SPACES that directly follow a $TAB with a $TAB. + # $TMP will be non-empty if any replacements took place. + sed -i '' "s/$TAB$SPACES/$TAB$TAB/w $TMP" $INCLUDE* $LIB* + more_work=$(cat "$TMP") +done +rm -f $TMP