Astyle在visual c++ 6 中的安装和使用方法

astyle是一个常用的开放源码代码格式化工具。它可以方便的将c,c++,java程序代码格式化成自己想要的样式而不必人工修改。

Astyle下载地址:http://astyle.sourceforge.net/download.html

下载后解压,可以在astyle_1.23_windows/astyle/bin目标中得到AStyle.exe文件,记下地址。

打开visual c++中,在菜单中选择“工具 (tool)”->“定制”->然后在打开的面板里“工具”选项卡中点击图标新增一个菜单内容,取名“Astyle”。

       然后在下面的参数栏中,“命令”就是AStyle.exe文件所在的地址,如D:/1-常用安装程序/代码格式化工具/astyle_1.23_windows/astyle/bin/AStyle.exe。

     “初始目录”一栏填写$(WkspDir),表示当前工作空间目录,当然也可以通过右边的向右箭头选择。

      “变量”一栏填写 “--style=ansi *.cpp  *.h” ,这里的参数表示格式化当前目录中的所有.cpp ,.h后缀的文件,其实也就是我们的代码文件。

      使用的时候只需要在工具菜单中,选择新增的外部工具“Astyle”就可以直接格式化相关文件。

具体的来说,astyle包含了以下几种预定义风格,只需在参数中简单指定即可使用:

  --style=ansi:ANSI 风格格式和缩进

namespace foospace
{
 int Foo()
 {
  if (isBar)
  {
   bar();
   return 1;
  }
  else
   return 0;
 }
}


  --style=kr :Kernighan&Ritchie 风格格式和缩进

namespace foospace {
 int Foo() {
  if (isBar) {
   bar();
   return 1;
  } else
   return 0;
 }
}


  --style=linux :Linux 风格格式和缩进

namespace foospace
{
 int Foo()
 {
  if (isBar) {
   bar();
   return 1;
  } else
   return 0;
 }
}


  --style=gnu :GNU 风格格式和缩进

namespace foospace
{
 int Foo()
 {
  if (isBar)
  {
   bar();
   return 1;
  }
  else
   return 0;
 }
}


  --style=java :Java 风格格式和缩进

class foospace {
 int Foo() {
  if (isBar) {
   bar();
   return 1;
  } else
   return 0;
 }
}

 

从这里开始介绍astyle的高级应用!这里要介绍的是两种应用情形,一是在Visual Studio中整合,二是批量处理。

 

 

      本方法适用于visual c++ 6,其他IDE可以参考进行安装。

      不明白的话可以给我回复提问,我一有时间会给你回复。

     

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
包含源代码,需要的可以自行下载。 把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.
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值