1. 程式人生 > 其它 >Astyle 常用引數整理

Astyle 常用引數整理

一. 基本命令

例子 astyle *.cpp *.h -r -A1 -c -s4 -xV -S -N -xt4 -xW -w -xw -Y -p -U -xe -k3 -W3 -e -j -xg -J
AStyle.exe --style=allman -s4 -S -p -c -xg -j -w -U -xb -f -Y “ ( F U L L C U R R E N T P A T H ) " " (FULL_CURRENT_PATH)" " (FULLC​URRENTP​ATH)""(FULL_CURRENT_PATH)”

-N 為名稱空間增加縮排
-s4 4個空格縮排(預設)
-S case縮排
-p 運算子左右新增空格
-xg 逗號後新增空格
-n 不保留備份
-c tab換成空格
-j 單行if會自動加入大括號
-U 表示括號內的兩頭的引數和括號之間不留空格
-w 對巨集進行縮排處理
-x 刪除多餘空行
-xV 將 ‘do-while’ 語句的結束 ‘while’ 附加到右大括號。
-Y 將註釋一起縮排
-xb 不放在一行,例如if 後的一句

-f 在塊的上部新增空白行

二. 基本命令

astyle --style=ansi main.cs
  • 1

格式化目錄

使用ansi風格格式當前目錄下的所有cpp,cs檔案,注意在批處理檔案時,"%f" 要改為"%%f"

for /R %f in (*.cpp;*.cs;) do astyle --style=ansi "%f"
  • 1

引數說明:

http://astyle.sourceforge.net/astyle.html
  • 1

加入到VS2008,VS2005

工具——>外部工具——>新增
標題:astyle
命令:AStyle.exe (填好astyle.exe的路徑)
引數:–style=allman -N ( I t e m D i r ) (ItemDir) (ItemDir)(ItemFileName) ( I t e m E x t ) 初 始 目 錄 : (ItemExt) 初始目錄: (ItemExt):(TargetDir)
勾上“使用初始目錄”
點選確定完成,以後就可以在工具選單中找到“astyle“這一項了,點選它,就可以對當前檔案進行格式化操作。

加入到VS6

Tools——>Customize——>Tools
標題:astyle
命令:AStyle.exe (填好astyle.exe的路徑)
引數:–style=ansi -s4 --suffix=.orig ( F i l e N a m e ) (FileName) (FileName)(FileExt)
初始目錄:$(FileDir)
勾上“Using Output Window”
點選確定完成。以後就可以在工具選單中找到“astyle“這一項了,點選它,就可以對當前檔案進行格式化操作。

加入到Source insight

  • Options–>Custom Command–>Add
  • Command:astyle
  • Run “D:\soft\astyle\astyle.exe” --style=ansi -f -p -P -U -v -n -N
    %f(填好astyle.exe的路徑)(“E:\softwares\AStyle_3.1_windows\AStyle\bin\AStyle.exe” --style=allman -k1 -W1 -t -xG -S -L -M120 -P -y -xb -j -xq -xS %f)
  • Output:不選.
  • Control: 選擇pause when done和exit to window.
  • source links in output:file, then line
  • –>menu
  • add to work menu.
  • 點選確定完成。以後就可以在Work選單中找到“astyle“這一項了,點選它,就可以對當前檔案進行格式化操作。

另外可以參考:在source insight中整合astyle: https://www.cnblogs.com/xuxm2007/archive/2013/04/06/3002390.html

加入到Ultraedit和UltraStudio

高階–>工具配置——>外部工具——>新增
命令:AStyle.exe -v --style=ansi -s4 --suffix=.orig “%f”(填好astyle.exe的路徑)
Optiones:選擇 Windows program和Save Active File.
Output: 選擇output to list box,show dos box 和no replace。
點選確定完成。以後就可以在工具選單中找到“astyle“這一項了,點選它,就可以對當前檔案進行格式化操作。
加入到Source insight
Options–>Custom Command–>Add
Command:astyle
Run “D:\soft\astyle\astyle.exe” --style=ansi -f -p -P -U -v -n -N %f(填好astyle.exe的路徑)
Output:不選.
Control: 選擇pause when done和exit to window.
source links in output:file, then line
–>menu
add to work menu.
點選確定完成。以後就可以在Work選單中找到“astyle“這一項了,點選它,就可以對當前檔案進行格式化操作。
另外可以參考:在source insight中整合astyle: https://www.cnblogs.com/xuxm2007/archive/2013/04/06/3002390.html

控制檯目錄批處理(astyle.bat)

REM 批量將本目錄中的所有C++檔案用Astyle進行程式碼美化操作
REM 設定Astyle命令位置和引數
@echo off
set astyle="astyle.exe"
REM 迴圈遍歷目錄
for /r . %%a in (*.cpp;*.c) do %astyle% --style=ansi --pad=oper --unpad=paren -s4 -n "%%a"
for /r . %%a in (*.hpp;*.h) do %astyle% --style=ansi --pad=oper --unpad=paren -s4 -n "%%a"
REM 刪除所有的astyle生成檔案
for /r . %%a in (*.orig) do del "%%a"
pause

三.  SourceInsight 配置引數:

    參考檔案:  http://www.tzwyx.com/717.html

  例如:  [  "C:\Program Files\Source Insight 4.0\AStyle\bin\AStyle.exe"  -A1/-A8/-A16  -k3 -W1 -xG -S -p -s4 -xb -U -xp -xf -xh  -xL -H -xc -w -xw -xW -xM -m0 -n  -xP2  %f  -xC200 ]

  "D:\Program Files\Source Insight 4.0\AStyle\bin\AStyle.exe"  -A16 -k3 -W1 -xG -S -p -s4 -xb -U -xp -xf -xh  -xL -H -xc -w -xw -xW -xM -m0 -n  -xP2  %f  -xC200