Astyle選項

    Astyle 全稱爲 Artistic Style,官方網站是 http://astyle.sourceforge.net

    Astyle 是一個命令行程序,簡單的使用方法是直接使用Astyle加上你要格式化的程序的源文件,Astyle支持不同的代碼風格,也有不同的參數來設置自己想要的效果,astyle是一個命令行工具。

    命令語法:

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

 

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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章