无网不进  
软硬件开发

一. 基本命令

例子 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

 

posted on 2022-05-13 22:35  无网不进  阅读(980)  评论(0编辑  收藏  举报