2010년 11월 3일 수요일

how to change tab to spaces for all source coes!!

Lots of code conventions including java and webkit suggests 4-pace indentation.
However, it is irritating sometimes.
Some IDE (i.e, Vim) clarify indentation using tab by default.
It's hard for programmer who has habit of indentation by tab to change habit.
If we changed IDE settings and succeeded in urging programmer to change his/her habit, we still have problem.
If we have thousands of files in repository, It's really hard to find tab among them.

Such problems are beginning of this how-to.
I made script to change tab to 4-space for every source code(c/c++ and java).

Following is the script.


tab2spc
-------------------------------------------------------------------------------

#!/bin/bash

EXTS="*c *.cpp *.cc *.h *.hpp *.hh *.java"
FILES=""

for EXT in $EXTS
do
FILES+=`find . -name $EXT`
done

for FILE in $FILES
do
SRCFILE="$FILE".tab
mv $FILE $SRCFILE
echo $FILE...
sed 's/\t/ /g' < $SRCFILE > $FILE
unix2dos $FILE
rm $SRCFILE
done

댓글 없음:

댓글 쓰기