Artistic Style详解

    Astyle 全称为 Artistic Style,官方网站是 http://astyle.sourceforge.net

    Astyle 是一个命令行程序,简单的使用方法是直接使用Astyle加上你要格式化的程序的源文件,Astyle支持不同的代码风格,也有不同的参数来设置自己想要的效果,astyle是一个命令行工具。

关于学习最好的方法还是官方文档:http://astyle.sourceforge.net/astyle.html

    命令语法:

astyle [options] < original > Beautified
astyle [options] Foo.cpp Bar.cpp  [...]

可以用通配符指定要处理的文件,用 -r 递归处理子目录

   举例:

  • 下面的命令可以一次性格式化某个目录(包含子目录)下所有的源文件和头文件
for /R %f in (*.cpp;*.c;*.h) do astyle --style=ansi "%f"
  • 下面的命令将格式化foo.c文件,更改其风格为ANSI,并将原始文件备份到foo.c.orgin 
astyle --style=ansi foo.c

 

1. 通用命令

查询版本:astyle -V

帮助信息:astyle --help

 

2. 预定义风格

Astyle包含了以下几种预定义风格,只需在参数中简单指定即可使用:ansi, kr, linux, gnu, java

  • --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;
 }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值