Linux平台下:
(1) apt-get install astyle 或者去主页http://sourceforge.net/projects/astyle下载
(2) astyl.sh 脚本
#!/bin/bash
dir=`pwd`
filelist=`find $dir -type f -name "*.c" -or -name "*.h"`
for file in $filelist
do
astyle --style=ansi -s4 -S -N -L -j -m0 -M40 --convert-tabs -n -U -H -p $file
done
(3)把这个脚本放在需要格式化的工程文件夹下,chmod +x astyl.sh ,./astyl.sh 执行即可
Windows平台下:
1.下载astyle
2.将Astyle整个目录放到 C:\Program Files
3.将C:\Program Files\AStyle\bin 添加到环境变量中
按照1,2,3,4,5,6的顺序
4. 将代码格式化.bat 拷贝到要格式化的目录下
代码格式化.bat:
for /R %%f in ( *.cpp;*.c;*.h ) do astyle.exe --style=ansi -s4 -S -N -L -j -m0 -M40 --convert-tabs -n "%%f"
pause
5.点击运行批处理,这个路径下包含子目录中的所有.c, .h, .cpp文件都被格式化