AStyle在配置VC中的配置方法


Artistic Style工具的使用说明

astyle工具用于实现c/c++等语言的代码缩进排版,与vc6的集成配置及参数情况如下:

一、格式化当前文件的设置

附录:

AStyle: Current File

-A1 -T4 -w -Y -m0 -M40 -f -p -H -U -k3 -W3 "$(FilePath)"

$(FileDir)

二、格式化整个工程中的文件代码的设置

附录:

AStyle: Files in Current Project

-A1 -T4 -w -Y -m0 -M40 -f -p -H -U -k3 -W3 -r  *.h *.cpp

$(TargetDir)\..

三、在vc中格式化代码

点击vc++6.0Tool菜单,将弹出已经集成进的astyle工具命令,点击命令项即可对当前代码文件(或当前工程文件夹及其子文件夹里的全部代码文件)进行格式化,如下图:

四、参数含义

各配置参数的含义,供大家讨论。更详细完整的说明可参见asytle工具的命令行帮助信息,或其自带的doc文档。

-------------------------------------------------------

-A1:决定括号位置及缩进的大体风格为ANSI风格,如下:

int Foo(bool isBar)

{

    if (isBar)

    {

        bar();

        return 1;

    }

    else

        return 0;

}

-T4:强制将tab键转为4个空格

-w:控制宏定义的缩进,如下:

#define Is_Bar(arg,a,b) \

(Is_Foo((arg), (a)) \

|| Is_Foo((arg), (b)))

将变成:

#define Is_Bar(arg,a,b) \

    (Is_Foo((arg), (a)) \

     || Is_Foo((arg), (b)))

-Y:将从第一列以“//”开头的注释移到和其下一行左对齐,如下:

void Foo()\n" 

{

// comment

    if (isFoo)

        bar();

}

将变成:

void Foo()\n" 

{

    // comment

    if (isFoo)

        bar();

}

 

-m0:将if括号中的换行后内容与括号中第一个内容左对齐

// but creates an exaggerated indent in this bracketed code

if (a < b

        || c > d)

{

    foo++;

}

将变成:

if (a < b

    || c > d)

{

    foo++;

}

-M40:将函数参数或数组赋值的换行内容左对齐,并且不超过第40列,以免缩进距离过大。如

fooFunction(barArg1,

         barArg2,

         barArg3);

将变成:

fooFunction(barArg1,

            barArg2,

            barArg3);

-fifwhile等块上下加空行

-p:操作符左右加空格

-Hif和其后的括号间加空格

-U:去掉括号里的空格,如

if ( isFoo( a, b ) )

    bar ( a, b );

将变成:

if(isFoo(a, b))

    bar(a, b);

-k3:指针的*符号与类型间加空格,并与变量名间无空格

-W3:引用的&符号与类型间加空格,并与变量名间无空格



在VS2010的配置如下:

格式化工程中的所有文件

标题:AStylePrj

命令:F:\CodeTools\AStyle\bin\AStyle.exe

参数:-A1 -s4 -C -S -K -w -Y -m0 -M40 -f -F -p -H -U -j -k1 -W1 -r  *.h *.cpp

初始目录:$(ProjectDir)

并勾选“使用输出窗口”


格式化单个文件

标题:AStyleFile

命令:F:\CodeTools\AStyle\bin\AStyle.exe

参数:-A1 -s4 -C -S -K -w -Y -m0 -M40 -f -F -p -H -U -j -k1 -W1 $(ItemFileName)$(ItemExt)

初始目录:$(ItemDir)

并勾选“使用输出窗口”



包含源代码,需要的可以自行下载。 把astyle.exe 复制到 C:\WINDOWS 目录里,省的指定路径 VC6++ 设置方法 菜单->工具->定制->工具菜单内容->新建菜单,参数如下 命令行:astyle.exe 变量: --style=k&r --brackets=break --indent=spaces --indent-cases --indent-preprocessor --pad-header --pad-oper --unpad-paren --keep-one-line-statements --keep-one-line-blocks --convert-tabs $(FileName)$(FileExt) 初始目录: $(FileDir) VC2008 外部工具里设置,还可以添加快捷键 命令:astyle.exe 参数: --style=k&r --brackets=break --indent=spaces --indent-cases --indent-preprocessor --pad-header --pad-oper --unpad-paren --keep-one-line-statements --keep-one-line-blocks --convert-tabs $(ItemFileName)$(ItemExt) 初始目录: $(ItemDir) CodeBlocks 设置差不多,很多绿色版的已经设置好了 AStyle_2.02_windows.zip bin 目录里有官方编译好的 Artistic Style 2.01 Maintained by: Jim Pattee Original Author: Tal Davidson Usage : astyle [options] Source1.cpp Source2.cpp [...] astyle [options] Beautified When indenting a specific file, the resulting indented file RETAINS the original file-name. The original pre-indented file is renamed, with a suffix of ".orig" added to the original filename. Wildcards (* and ?) may be used in the filename. A 'recursive' option can process directories recursively. By default, astyle is set up to indent C/C++/C#/Java files, with four spaces per indent, a maximal indentation of 40 spaces inside continuous statements, a minimum indentation of eight spaces inside conditional statements, and NO formatting options.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值