轉自:https://www.cnblogs.com/jiangxinnju/p/4908575.html
歡迎關注我的社交賬號:
博客園地址: http://www.cnblogs.com/jiangxinnju
GitHub地址: https://github.com/jiangxincode
知乎地址: https://www.zhihu.com/people/jiangxinnju
astyle是一款代碼格式化工具,它的下載地址是:
http://sourceforge.net/projects/astyle
項目地址:
http://astyle.sourceforge.net/
文檔說明:
http://astyle.sourceforge.net/astyle.html
基本命令
astyle --style=ansi main.cs
格式化目錄
使用ansi風格格式當前目錄下的所有cpp,cs文件,注意在批處理文件時,"%f" 要改為"%%f"
for /R %f in (*.cpp;*.cs;) do astyle --style=ansi "%f"
參數說明:
http://astyle.sourceforge.net/astyle.html
加入到VS2008,VS2005
- 工具——>外部工具——>添加
- 標題:astyle
- 命令:AStyle.exe (填好astyle.exe的路徑)
- 參數:--style=allman -N $(ItemDir)$(ItemFileName)$(ItemExt)
- 初始目錄:$(TargetDir)
- 勾上“使用初始目錄”
- 點擊確定完成,以后就可以在工具菜單中找到“astyle“這一項了,點擊它,就可以對當前文件進行格式化操作。
加入到VS6
- Tools——>Customize——>Tools
- 標題:astyle
- 命令:AStyle.exe (填好astyle.exe的路徑)
- 參數:--style=ansi -s4 --suffix=.orig $(FileName)$(FileExt)
- 初始目錄:$(FileDir)
- 勾上“Using Output Window”
- 點擊確定完成。以后就可以在工具菜單中找到“astyle“這一項了,點擊它,就可以對當前文件進行格式化操作。
加入到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