AStyle代码格式工具在source insight中的使用 --写给小白
2017-03-18 10:47
513 查看
一、AStyle下载路径
Astyle为开源项目,支持C/C++和Java的代码格式化
Home Page: http://astyle.sourceforge.NET/
Project Page: http://sourceforge.Net/projects/astyle/
下载最新Windows版本的AStyle,解压到你指定位置,笔者解压到D:\Program Files下的。
二、Source Insight中安装Astyle工具
如:增加Astyle命令,格式化C/C++文件
1. 打开source insight中的一个工程,选择Options--Custom Commands命令
2. 点击add,添加新的命令Astyle。
1)ansi C 格式化当前文件的命令为
其中,Run中输入astyle的命令参数:"D:\Program Files\AStyle\bin\AStyle.exe" --style=ansi -s4 -S -N -L -m0 -M40 --convert-tabs
--suffix=.pre %f
详细设置:
1处:输入名称:Astyle (ps:此名称可以改成任意的)
2处:粘贴命令参数:"D:\program files\AStyle\bin\AStyle.exe" --style=ansi -s4
-S -N -L -m0 -M40 --convert-tabs --suffix=.pre %f
3处:点击Close 即可添加此命令
3. 添加menu菜单,点击“Options”,选择Options--Menu
Assignments...,如下图操作。这样就可以在菜单栏View上多一个命令选项。 如图:
效果如图:
4. 添加快捷键,点击"Options -- Key Assignments...",输入快捷键:Ctrl+Alt+C。以后格式化C/C++文件,就可以直接使用快捷键了。
同理,新建java格式化命令,Astyle参数为
C:\AStyle\bin\AStyle.exe --style=java -s4 -S -N -L -m0 -M40 --suffix=none --convert-tabs %f
三、其他常用的参数:
基于V2.02版本,astyle主要支持的参数有:
Style-格式配置:
最常用的就是ansi或或kr格式,实际上,kr,stroustrup和linux这三种格式是非常接近的了,试了好几个文件,只有非常微小的区别,可以忽略不计。
转载并修改参考文档:
1. http://blog.csdn.net/gw_cs/article/details/7927735
如果对你有帮助就顶一下吧!
Astyle为开源项目,支持C/C++和Java的代码格式化
Home Page: http://astyle.sourceforge.NET/
Project Page: http://sourceforge.Net/projects/astyle/
下载最新Windows版本的AStyle,解压到你指定位置,笔者解压到D:\Program Files下的。
二、Source Insight中安装Astyle工具
如:增加Astyle命令,格式化C/C++文件
1. 打开source insight中的一个工程,选择Options--Custom Commands命令
2. 点击add,添加新的命令Astyle。
1)ansi C 格式化当前文件的命令为
其中,Run中输入astyle的命令参数:"D:\Program Files\AStyle\bin\AStyle.exe" --style=ansi -s4 -S -N -L -m0 -M40 --convert-tabs
--suffix=.pre %f
详细设置:
1处:输入名称:Astyle (ps:此名称可以改成任意的)
2处:粘贴命令参数:"D:\program files\AStyle\bin\AStyle.exe" --style=ansi -s4
-S -N -L -m0 -M40 --convert-tabs --suffix=.pre %f
3处:点击Close 即可添加此命令
3. 添加menu菜单,点击“Options”,选择Options--Menu
Assignments...,如下图操作。这样就可以在菜单栏View上多一个命令选项。 如图:
效果如图:
4. 添加快捷键,点击"Options -- Key Assignments...",输入快捷键:Ctrl+Alt+C。以后格式化C/C++文件,就可以直接使用快捷键了。
同理,新建java格式化命令,Astyle参数为
C:\AStyle\bin\AStyle.exe --style=java -s4 -S -N -L -m0 -M40 --suffix=none --convert-tabs %f
三、其他常用的参数:
-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 | 显示版本信息 |
Style-格式配置:
最常用的就是ansi或或kr格式,实际上,kr,stroustrup和linux这三种格式是非常接近的了,试了好几个文件,只有非常微小的区别,可以忽略不计。
stype 选项 | --style=allman --style=ansi --style=bsd --style=break -A1 | --style=java --style=attach -A2 | --style=kr --style=k&r --style=k/r -A3 | --style=stroustrup -A4 | --style=whitesmith -A5 | --style=banner -A6 |
代码风格 | int Foo() { if (isBar) { bar(); return 1; } else { return 0; } } | int Foo() { if (isBar) { bar(); return 1; } else { return 0; } } | int Foo() { if (isBar) { bar(); return 1; } else { return 0; } } | int Foo() { if (isBar) { bar(); return 1; } else { return 0; } } | int Foo() { if (isBar) { bar(); return 1; } else { return 0; } } | int Foo() { if (isBar) { bar(); return 1; } else { return 0; } } |
stype 选项 | --style=gnu -A7 | --style=linux -A8 | --style=horstmann -A9 | --style=1tbs -A10 | --style=pico -A11 | --style=lisp -A12 |
代码风格 | int Foo() { if (isBar) { bar(); return 1; } else { return 0; } } | int Foo() { if (isBar) { bar(); return 1; } else { return 0; } } | int Foo() { if (isBar) { bar(); return 1; } else { return 0; } } | int Foo() { if (isBar) { bar(); return 1; } else { return 0; } } | int Foo() { if (isBar) { bar(); return 1; } else return 0; } | int Foo() { if (isBar) { bar(); return 1; } else return 0; } |
1. http://blog.csdn.net/gw_cs/article/details/7927735
如果对你有帮助就顶一下吧!
相关文章推荐
- Source Insight 中使用 AStyle 代码格式工具
- AStyle代码格式工具在source insight中的使用
- AStyle代码格式工具在source insight中的使用
- AStyle代码格式工具在source insight中的使用
- AStyle代码格式工具在source insight中的使用
- AStyle代码格式工具在source insight中的使用
- AStyle代码格式工具在source insight中的使用
- AStyle代码格式工具在source insight中的使用
- AStyle代码格式工具在source insight中的使用
- 发表个asp.net的代码生成工具吧,自己写的,一直在项目中使用的,类似Pet Shop代码格式
- 【代码编辑工具】Source Insight的使用
- C/C++代码格式优化工具----astyle
- 一小时写给同组的如何使用工具检测代码质量
- 代码规范:在Keil5中使用代码格式化工具Astyle(插件)
- Visual Studio 2010 使用外部代码格式化工具 AStyle
- Astyle代码格式化工具在IAR中的使用
- 如何在source insight中使用astyle的代码整理功能
- AStyle代码格式工具
- IAR 工具使用AStyle工具格式化代码
- 如何在source insight中使用astyle的代码整理功能?