Chinaunix首页 | 论坛 | 博客
  • 博客访问: 50429
  • 博文数量: 24
  • 博客积分: 2010
  • 博客等级: 大尉
  • 技术积分: 220
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-23 17:12
文章分类

全部博文(24)

文章存档

2010年(7)

2009年(11)

2008年(6)

我的朋友

分类: LINUX

2009-07-08 00:54:46

Windows平台下也有好多人都喜欢用SourceInsight编辑C/C++程序,但是SourceInsight没有提供对代码格式化的功能,如果将Artistic Style集成到SourceInsight中,那就可以为它扩展出代码格式化的功能了。
假定AStyle.exe的目录是“C:\ArtisticStyle\”,在该目录下有一个“c.opt”文件是用来保存配置的文件。下面简要地介绍下Artistic Style集成到SourceInsight中的方法。
1. 打开你的SourceInsight, 选择菜单“Options-->Custom Commands-->Add”, 输入Artistic Style(可以随便输入一个名字)。
2. Run中输入: for /R %f in (*.cpp;*.c;*.h) do C:\astyle\bin\AStyle.exe  --style=ansi -p --indent=spaces=4 "%f"
3. Dir留空,将Iconic Window, Capture Output, Parse Links in OutPut, File,then Line 四项前打上勾。
4. 然后点对话框中右侧的按钮“Menu”, Menu--->Menu-->View-->, 右侧Insert, OK.
5. 此时在SourceInsight中的View菜单下多了个Style的子菜单选项,可以用它来对单个C/C++文件进行格式化。
 
 

在文件夹下面直接执行下面命令
for /R .\ %f in (*.cpp) do astyle --style=ansi -f -p "%f"
for /R .\ %f in (*.h) do astyle --style=ansi -f -p "%f"

风格说明:
(1) -f
在两行不相关的代码之间插入空行,如import和public class之间、public class和成员之间等;
(2) -p
在操作符两边插入空格,如=、+、-等。
如:int a=10*60;
处理后变成int a = 10 * 60;
(3) -P
在括号两边插入空格。另,-d只在括号外面插入空格,-D只在里面插入。
如:System.out.println(1);
处理后变成System.out.println( 1 );
(4) -U
移除括号两边不必要的空格。
如:System.out.println( 1 );
处理后变成System.out.println(1);
(5) -V
将Tab替换为空格。

可以参考压缩包里附带的   Documentation

 
 
阅读(1106) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~