AStyle - 代码格式优化工具

astyle 全称为 Artistic Style, 官方网站是 http://astyle.sourceforge.net

astyle不但可以对C/C++进行格式优化,还可以处理Java和C#。

astyle 是一个命令行程序,简单的使用方法是直接使用astyle加上你要格式化的程序的源文件。

astyle支持不同的代码风格,也有不同的参数来设置自己想要的效果

通过命令“astyle -V”可以查询版本信息

通过命令“astyle --help”可以获取所有参数的介绍

下载最新版本 : http://sourceforge.net/projects/astyle

astyle是一个命令行工具,命令语法很简单:

astyle [options] < original > Beautified
astyle [options] Foo.cpp Bar.cpp  [...]

可以用通配符指定要处理的文件,用 -r 递归处理子目录

 

下面的命令可以一次性格式化某个目录(包含子目录)下所有的源文件和头文件

for /R %f in (*.cpp;*.c;*.h) do astyle --style=ansi "%f"

下面的命令将格式化foo.c文件,更改其风格为ANSI,并将原始文件备份到foo.c.orgin。 

astyle --style=ansi foo.c

astyle包含了以下几种预定义风格,只需在参数中简单指定即可使用

ansi, kr, linux, gnu, java

 

http://biancheng.dnbcw.info/linux/254469.html

设置选项 

By default, astyle is set up to indent C/C++/C#/Java files,

with 4 spaces per indent, a maximal indentation of 40 spaces inside continuous statements,and NO formatting.

Option's Format:
----------------
Long options (starting with '--') must be written one at a time.
Short options (starting with '-') may be appended together. 
Thus, -bps4 is the same as -b -p -s4

tab选项: 默认tab是4个空格.

--indent=spaces=#  OR  -s#  默认行缩进为4个空格,可以将#替换为缩进量
--indent=tab  OR  --indent=tab=#  OR  -t  OR  -t#  行缩进用tab, 默认tab长度与4个空格相等
--indent=force-tab=#  OR  -T#  优先采用空格缩进

大括号选项: If no brackets option is set, the brackets will not be changed.

--brackets=break  OR  -b 大括号与前一块隔开为两行  Break brackets from pre-block code (i.e. ANSI C/C++ style).
--brackets=attach OR  -a 大括号前一个与上一行在同一行 Attach brackets to pre-block code (i.e. Java/K&R style).
--brackets=linux  OR  -l 定义块 和 函数块中的大括号都被处理 Break definition-block brackets and attach command-block brackets.
--brackets=stroustrup  OR  -u  只处理函数中的大括号   Attach all brackets except function definition brackets.

缩进选项:

--indent-classes  OR  -C 缩进类定义中的public private protected标签.

Indent 'class' blocks, so that the inner 'public:','protected:' and 'private:
headers are indented in relation to the class block.

--indent-switches  OR  -S 缩进switch中的case块,case和switch不在同一列
Indent 'switch' blocks, so that the inner 'case XXX:' headers are indented in relation to the switch block.

--indent-cases  OR  -K 缩进case下面的语句
Indent case blocks from the 'case XXX:' headers.
Case statements not enclosed in blocks are NOT indented.

--indent-blocks  OR  -G 缩进块, 包括大括号
Add extra indentation entire blocks (including brackets).

--indent-brackets  OR  -B 缩进大括号
Add extra indentation to '{' and '}' block brackets.

--indent-namespaces  OR  -N 缩进命名空间定义行
Indent the contents of namespace blocks.

--indent-labels  OR  -L 缩进标签
Indent labels so that they appear one indent less than the current indentation level,
rather than being flushed completely to the left (which is the default).

--indent-preprocessor  OR  -w 缩进多行宏定义
Indent multi-line #define statements.

--max-instatement-indent=#  OR  -M#   跨行缩进,比如函数定义中的参数处在多行,那么参数缩进到同一列
Indent a maximal # spaces in a continuous statement, relative to the previous line.

--min-conditional-indent=#  OR  -m#
Indent a minimal # spaces in a continuous conditional belonging to a conditional header.

格式化选项:

--break-blocks  OR  -f   空行分隔没有关系的块,类,标签(不包括函数块)
Insert empty lines around unrelated blocks, labels, classes, ...

--break-blocks=all  OR  -F    空行分隔无关系的块,包括else catch等
Like --break-blocks,
except also insert empty lines around closing headers (e.g. 'else', 'catch', ...).

--break-closing-brackets  OR  -y   else catch左边的大括号与else catch分隔
Break brackets before closing headers (e.g. 'else', 'catch', ...).
Use with --brackets=attach, --brackets=linux, or --brackets=stroustrup.

--break-elseifs  OR  -e  else if()分隔为两行
Break 'else if()' statements into two different lines.

--delete-empty-lines  OR  -x   删除多余空行
Delete empty lines within a function or method.
It will NOT delete lines added by the break-blocks options.

--pad-oper  OR  -p    操作符两端插入一个空格
Insert space paddings around operators.

--pad-paren  OR  -P   括号内外都插入空格
Insert space padding around parenthesis on both the outside and the inside.

--pad-paren-out  OR  -d 括号外部插入空格
Insert space padding around parenthesis on the outside only.

--pad-paren-in  OR  -D 括号外部插入空格
Insert space padding around parenthesis on the inside only.

--unpad-paren  OR  -U  移除括号两端多余空格
Remove unnecessary space padding around parenthesis. 
This can be used in combination with the 'pad' options above.

--keep-one-line-statements  OR  -o  一行中的多个申明不分隔  int x;int y;int z 不被分为3行
Don't break lines containing multiple statements into multiple single-statement lines.

--keep-one-line-blocks  OR  -O  大括号中的单行语句不被拆分
Don't break blocks residing completely on one line.

--convert-tabs  OR  -c  tab转换为空格
Convert tabs to the appropriate number of spaces.

--fill-empty-lines  OR  -E  块间空行的换行符前插入一个空格
Fill empty lines with the white space of their previous lines.

--mode=c    处理c文件
Indent a C or C++ source file (this is the default).

--mode=java 处理jave文件
Indent a Java source file.

--mode=cs   处理c#文件
Indent a C# source file.

其他选项: 

--suffix=#### 指定备份文件的后缀
Append the suffix #### instead of '.orig' to original filename.

--suffix=none OR -n 不备份文件
Do not retain a backup of the original file.

--options=#### 指定从####文件读取选项信息
Specify an options file #### to read and use.

--options=none 禁止从文件读取选项信息
Disable the default options file.
Only the command-line parameters will be used.

--recursive OR -r OR -R 递归处理子目录
Process subdirectories recursively.

--exclude=#### 排除不处理的文件夹
Specify a file or directory #### to be excluded from processing.

--errors-to-stdout OR -X
Print errors and help information to standard-output rather than
to standard-error.

--preserve-date OR -Z 不修改时间
The date and time modified will not be changed in the formatted file.

--verbose OR -v 输出详细处理信息
Verbose mode. Extra informational messages will be displayed.

--formatted OR -Q 输出信息中只包括被修改的文件信息
Formatted display mode. Display only the files that have been formatted.

--quiet OR -q 忽略所有错误
Quiet mode. Suppress all output except error messages.

--version OR -V 输出astyle版本
Print version number.

--help OR -h OR -? 帮助信息
Print this help message.

Artistic Style for Windows

Artistic Style for Windows is a C, C++, C#, and Java source code indenter and formatter that uses Artistic Style as the indenting and formatting engine. It is a simple, easy to use, intuitive graphic user interface (GUI) that is fully integrated, not a separate front-end program. The Scintilla editing component is used as the editor and allows for unrestricted selective formatting of a document. Everything done in the editor is undo-able, including formatting of the entire document. Documents can be reviewed and, if necessary, reformatted using different options. It can be executed from most development environments and will open the currently selected document.

A wide range of options allow for customized document formatting. An Options Dialog box contains a user friendly preview window showing the effects of each option as it is selected. Search capabilities allow for review of selected code segments, such as classes, switches, or case statements. File backup capability is provided.

Artistic Style for Windows is absolutely free. For further information see the Downloads page.

Features

  •  Uses Artistic Style 2.03
  •  Fully integrated GUI
  •  Unrestricted selective formatting
  •  Undo capability
  •  Executable from development environments
  •  Syntax highlighting
  •  Option preview window
  •  Search capability
  •  Backup/restore capability

AStyleWin_1.7.zip

AStyle - 代码格式优化工具

你可能感兴趣的:(style)