有段時間總覺得C代碼風格,真是千人千種風格,尤其在tape-out後,還要對其進行打patch,要獲取其function、variable等,更是受不了,於是搞了格式化批處理。
::--style=kr / 1tbs
::--align-pointer=type / -k1
::--align-pointer=middle / -k2
::--align-pointer=name / -k3
::--suffix=none / -n
::--align-reference=none / -W0
::--align-reference=type / -W1
::--align-reference=middle / -W2
::--align-reference=name / -W3
::--indent=tab / --indent=tab=# / -t / -t#
::--indent=spaces / --indent=spaces=# / -s#
::--indent-modifiers / -xG
::--indent-switches / -S
::--indent-labels / -L
::--indent-preproc-block / -xW
::--indent-col1-comments / -Y
::--max-continuation-indent=# / -M#
::--pad-oper / -p
::--pad-paren-in / -D
::--unpad-paren / -U
::--break-one-line-headers / -xb
::--add-braces / -j
::--pad-return-type / -xq
::--pad-param-type / -xS
::--delete-empty-lines
::--attach-closing-while / -xV
::--indent-namespaces / -N
::--indent-continuation=# / -xt#
::--break-elseifs / -e
::--mode=c
::--convert-tabs / -c
::--indent-preproc-define / -w
::--indent-preproc-cond / -xw
::--lineend=windows / -z1
::--lineend=linux / -z2
::--lineend=macold / -z3
::--suffix=none / -n
@echo off
set astyle="astyle.exe"
set excludefile="vsys_patch.c"
set style=kr -k3 -xV -N -xt4 -w -p -D -n -W3 -s4 -xG -S -L -xW -M120 -P -xb -j -xR -xq -Y -xS -z1 -c --mode=c
for /r .. %%f in (*.h;*.c) do (
if "%%~nxf" == %excludefile% (
echo %%~nxf don't format!!!!
) else (
%astyle% --style=%style% "%%f"
)
)
pause
把上述保存爲AStyle.bat文件,再把AStyle.exe放在同級目錄下,運行批處理,就把上一層文件及其子目錄所有c/h都格式化。