Astyle 参数设置

Astyle 参数设置

Written By Tomy Stark.
E-mail: ro7enkranz@qq.com
Ver 1.0.0

Note:

  • 转载请注明本文出处链接、作者

A. *.bat批处理文件调用Astyle进行代码格式化[KR风格]

1. 一键格式化所有代码(包括子目录)_完整参数版

1
2
for /R %%f in (*.c;*.h) do AStyle.exe --style=kr --indent=spaces=4 --attach-closing-while --indent-switches --indent-preproc-define --indent-col1-comments --max-continuation-indent=60 --break-blocks --pad-oper --pad-comma --pad-header --align-pointer=name --align-reference=name --break-one-line-headers --add-braces --attach-return-type --attach-return-type-decl --convert-tabs --max-code-length=200 --suffix=none --verbose %%f
pause

2. 一键格式化所有代码(包括子目录)_短参数版

1
2
for /R %%f in (*.c;*.h) do AStyle.exe -A3 -s4 -xV -S -w -Y -M60 -f -p -xg -H -k3 -W3 -xb -j -xf -xh -c -xC200 -n -v %%f
pause

B. Keil调用Astyle进行代码格式化[KR风格]

Keil 设置 - Step 1

Keil 设置 - Step 2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# A.代码格式化-全部文件

# [完全名称版(参数过长,Keil中无法正常执行,可用以下短参数版代替)]
--style=kr --indent=spaces=4 --attach-closing-while --indent-switches --indent-preproc-define --indent-col1-comments --max-continuation-indent=60 --break-blocks --pad-oper --pad-comma --pad-header --align-pointer=name --align-reference=name --break-one-line-headers --add-braces --attach-return-type --attach-return-type-decl --convert-tabs --max-code-length=200 --suffix=none --verbose "$E*.c" "$E*.h"

# [短参数版]
-A3 -s4 -xV -S -w -Y -M60 -f -p -xg -H -k3 -W3 -xb -j -xf -xh -c -xC200 -n -v "$E*.c" "$E*.h"


# B.代码格式化-当前文件

# [完全名称版(参数过长,Keil中无法正常执行,可用以下短参数版代替)]
--style=kr --indent=spaces=4 --attach-closing-while --indent-switches --indent-preproc-define --indent-col1-comments --max-continuation-indent=60 --break-blocks --pad-oper --pad-comma --pad-header --align-pointer=name --align-reference=name --break-one-line-headers --add-braces --attach-return-type --attach-return-type-decl --convert-tabs --max-code-length=200 --suffix=none --verbose !E

# [短参数版]
-A3 -s4 -xV -S -w -Y -M60 -f -p -xg -H -k3 -W3 -xb -j -xf -xh -c -xC200 -n -v !E

C. Eclipse系IDE调用Astyle进行代码格式化[KR风格]

(例如 S32 Design Studio, MCUXpresso IDE, TrueStudio, TI Code Composer Studio, Xilinx SDK ……)

  1. 位置(例如AStyle放置于以下目录时)
    D:\Software\AStyle\bin\AStyle.exe

  2. 工作目录
    ${workspace_loc:/${project_name}}

  3. 自变量

Eclipse系IDE的设置

1
2
3
4
5
6
7
# 代码格式化-当前文件

# [完全名称版(参数过长,Keil中无法正常执行,可用以下短参数版代替)]
--style=kr --indent=spaces=4 --attach-closing-while --indent-switches --indent-preproc-define --indent-col1-comments --max-continuation-indent=60 --break-blocks --pad-oper --pad-comma --pad-header --align-pointer=name --align-reference=name --break-one-line-headers --add-braces --attach-return-type --attach-return-type-decl --convert-tabs --max-code-length=200 --suffix=none --verbose ${resource_loc}

# [短参数版]
-A3 -s4 -xV -S -w -Y -M60 -f -p -xg -H -k3 -W3 -xb -j -xf -xh -c -xC200 -n -v ${resource_loc}

评论