AStyle下载 http://sourceforge.net/projects/astyle/
通过命令“astyle --help”可以获取所有参数的介绍
其常用的参数:
-C | 类中public,pretected,private关键字,一个tab的缩进 |
-S | switch中case关键字,一个tab的缩进 |
-K | switch中case关键字,无缩进 |
-N | 被namespace包含的block,一个tab的缩进 |
-w | 格式化多行的宏定义 |
-c | 将tab转化为对应个数的空格 |
--mode=c | 格式化的是C/C++的源文件或者头文件(缺省值) |
--mode=java | 格式化的是JAVA的源文件 |
--suffix=#### | 将原始文件保存为“####”后缀,而不是“orig” |
--suffix=none | 不保存原始文件 |
--exclude=#### | 优化时不包含“####”文件或目录 |
-Z | 修改后保持文件的修改时间不变 |
-X | 将错误信息输出到标准输出设备(stdout),而不是标准错误设备(stderr) |
-Q | 只显示格式化前后发生变化的文件 |
-q | 不输出任何信息 |
-z1 | 使用windows版本的回车符(CRLF) |
-z2 | 使用linux版本的回车符(LF) |
--help | 显示帮助信息 |
-v | 显示版本信息 |
Source Insight中使用Astyle
命令:"C:\program files\AStyle\bin\AStyle.exe"
参数: --style=ansi -s4 -S -N -L -m0 -M40 --convert-tabs --suffix=.pre %f
下面的命令可以一次性格式化某个目录下所有的源文件和头文件,非常好用,标记一下。
for /R %f in (*.cpp;*.c;*.h) do astyle --style=ansi "%f"
Editplus使用Astyle
命令="C:\EditPlus\AStyle.exe"
参数="--style=java --delete-empty-lines --suffix=none $(FilePath)"
起始目录="$(FileDir)"
动作:选择捕捉控制台输出
保存:选择当前文件
UltraEdit使用Astyle
打开ultraedit,高级->工具配置。
在命令行填写:C:\UltraEdit-32\GNU\astyle.exe --style=ansi "%f"
工作目录填写:%P
Keil uVision使用Astyle
菜单Tools选择 “Customize Tools Menu”
Command:C:\Program Files\AStyle\bin\AStyle.exe
Arguments:--style=ansi -s4 -S -N -L -m0 -M40 --suffix=none --convert-tabs !E
说明:
!E 当前文件
"$E*.c" "$E*.h" 当前文件所在文件夹中的所有.c 和.h文件
Style-格式配置:
stype | --style=allman | --style=java | --style=kr | --style=stroustrup | --style=whitesmith | --style=banner |
代码风格 | int Foo() | int Foo() { | int Foo() | int Foo() | int Foo() | int Foo() { |
stype | --style=gnu | --style=linux | --style=horstmann | --style=1tbs | --style=pico | --style=lisp |
代码风格 | int Foo() | int Foo() | int Foo() | int Foo() | int Foo() | int Foo() { |