--style=java -n -p -c !E

astyle是一个命令行工具,命令语法很简单:
          astyle [options] < original > Beautified
          astyle [options] Foo.cpp Bar.cpp  [...]

例如:

astyle --style=ansi foo.cpp

上面的命令将美化foo.cpp文件,更改其风格为ANSI,并将原始文件备份到foo.cpp.orgin。所以,你可以安全的使用该软件而不必担心会将代码改得无法回头。

预定风格

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

  --style=ansi:ANSI 风格格式和缩进

namespace foospace
{
 int Foo()
 {
  if (isBar)
  {
   bar();
   return 1;
  }
  else
   return 0;
 }
}

  --style=kr :Kernighan&Ritchie 风格格式和缩进

namespace foospace {
 int Foo() {
  if (isBar) {
   bar();
   return 1;
  } else
   return 0;
 }
}

  --style=linux :Linux 风格格式和缩进

namespace foospace
{
 int Foo()
 {
  if (isBar) {
   bar();
   return 1;
  } else
   return 0;
 }
}

  --style=gnu :GNU 风格格式和缩进

namespace foospace
{
 int Foo()
 {
  if (isBar)
  {
   bar();
   return 1;
  }
  else
   return 0;
 }
}

  --style=java :Java 风格格式和缩进

class foospace {
 int Foo() {
  if (isBar) {
   bar();
   return 1;
  } else
   return 0;
 }
}

1. 常用功能

(1) 单个文件--缺省美化

astyle --style=ansi Form1.cs

(2) 单个文件--更改缩进2个空格
astyle --style=ansi --indent=spaces=2 Form1.cs
缺省缩进一个TAB,也可以显式说明使用Tab,如下:
astyle --style=ansi --indent=tab Form1.cs

(3) 处理多个文件--有限个
astyle --style=ansi Form1.cs Form2.cs

(4) 批量处理多个文件--无限个
for /R ./ %f in (*.cs) do astyle --style=ansi "%f"
说明:/R表明遍历一个目录树,后面紧跟的路径是根,缺省为当前目录。
本例中,根为./表示当前目录,命令等价于:
for /R %f in (*.cs) do astyle --style=ansi "%f"
作用是从(目录树根)当前目录开始,查找所有java文件,包含子目录中的文件;然后交给astyle处理。
当然,目录树根也可以使用绝对路径,下面的命令查找C盘所有的java文件并处理。
for /R c:/ %f in (*.cs) do astyle --style=ansi "%f"

2. 其他比较有用的开关:

(1) -f
在两行不相关的代码之间插入空行,如import和public class之间、public class和成员之间等;

(2) -p
在操作符两边插入空格,如=、+、-等。
如:int a=10*60;
处理后变成int a = 10 * 60;

(3) -P
在括号两边插入空格。另,-d只在括号外面插入空格,-D只在里面插入。
如:MessageBox.Show ("aaa");
处理后变成MessageBox.Show ( "aaa" );

(4) -U
移除括号两边不必要的空格。
如:MessageBox.Show ( "aaa" );
处理后变成MessageBox.Show ("aaa");

(5) -V
将Tab替换为空格。

(6) -n
不保存备份

Artistic Style 1.15.3   (http://www.bigfoot.com/~davidsont/astyle)
                       (created by Tal Davidson, davidsont@bigfoot.com)

Modified edition by Qiongzhu Wan, 2004.09

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

When indenting a specific file, the resulting indented file RETAINS the
original file-name. The original pre-indented file is renamed, with a
suffix of ".orig" added to the original filename.

By default, astyle is set up to indent C/C++/C# 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.

Predefined Styling options:
--------------------
    --style=ansi
    ANSI style formatting/indenting.

--style=kr
    Kernighan&Ritchie style formatting/indenting.

--style=gnu
    GNU style formatting/indenting.

--style=java
    Java mode, with standard java style formatting/indenting.

--style=linux
    Linux mode (i.e. 8 spaces per indent, break definition-block
    brackets but attach command-block brackets.

Indentation options:
--------------------
    -c   or   --mode=c
    Indent a C, C++ or C# source file (default)

-j   or   --mode=java
    Indent a Java(TM) source file

-s   or   -s#   or   --indent=spaces=#
    Indent using # spaces per indent. Not specifying #
    will result in a default of 4 spacec per indent.

-t   or   -t#   or   --indent=tab=#
    Indent using tab characters, assuming that each
    tab is # spaces long. Not specifying # will result
    in a default assumption of 4 spaces per tab.

-T#   or   --force-indent=tab=#    Indent using tab characters, assuming tha
t each
    tab is # spaces long. Force tabs to be used in areas
    Astyle would prefer to use spaces.

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

-S   or   --indent-switches
    Indent 'switch' blocks, so that the inner 'case XXX:'
    headers are indented in relation to the switch block.

-K   or   --indent-cases
    Indent 'case XXX:' lines, so that they are flush with
    their bodies..

-N   or   --indent-namespaces
    Indent the contents of namespace blocks.

-B   or   --indent-brackets
    Add extra indentation to '{' and '}' block brackets.

-G   or   --indent-blocks
    Add extra indentation entire blocks (including brackets).

-L   or   --indent-labels
    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).

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

-M#  or  --max-instatement-indent=#
    Indent a maximal # spaces in a continuous statement,
    relatively to the previous line.

-E  or  --fill-empty-lines
    Fill empty lines with the white space of their
    previous lines.

--indent-preprocessor
    Indent multi-line #define statements

Formatting options:
-------------------
    -b  or  --brackets=break
    Break brackets from pre-block code (i.e. ANSI C/C++ style).

-a  or  --brackets=attach
    Attach brackets to pre-block code (i.e. Java/K&R style).

-l  or  --brackets=linux
    Break definition-block brackets and attach command-block
    brackets.

--brackets=break-closing-headers
    Break brackets before closing headers (e.g. 'else', 'catch', ..).
    Should be appended to --brackets=attach or --brackets=linux.

-o   or  --one-line=keep-statements
    Don't break lines containing multiple statements into
    multiple single-statement lines.

-O   or  --one-line=keep-blocks
    Don't break blocks residing completely on one line

-p   or  --pad=oper
    Insert space paddings around operators only.

--pad=paren
    Insert space paddings around parenthesies only.

-P   or  --pad=all
    Insert space paddings around operators AND parenthesies.

--convert-tabs
    Convert tabs to spaces.

--break-blocks
    Insert empty lines around unrelated blocks, labels, classes, ...

--break-blocks=all
    Like --break-blocks, except also insert empty lines
    around closing headers (e.g. 'else', 'catch', ...).

--break-elseifs
    Break 'else if()' statements into two different lines.

Other options:
-------------
    --suffix=####
    Append the suffix #### instead of '.orig' to original filename.

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

-v   or   --version
    Print version number

-h   or   -?   or   --help
    Print this help message

Default options file:
---------------------
    Artistic Style looks for a default options file in the
    following order:
    1. The contents of the ARTISTIC_STYLE_OPTIONS environment
       variable if it exists.
    2. The file called .astylerc in the directory pointed to by the
       HOME environment variable ( i.e. $HOME/.astylerc ).
    3. The file called .astylerc in the directory pointed to by the
       HOMEPATH environment variable ( i.e. %HOMEPATH%/.astylerc ).
    If a default options file is found, the options in this file
    will be parsed BEFORE the command-line options.
    Options within the default option file may be written without
    the preliminary '-' or '--'.

Astyle 快速入门,常用指令的更多相关文章

  1. vue入门-常用指令操作

    指令:v-xx组成的特殊指令,如果一个标签中有指令会默认替换原有的书 v-model:实现数据和视图的双向绑定 v-text:在元素中插入值 v-html:在元素中插入标签或者插入文本 v-if:根据 ...

  2. Vue入门---常用指令详解

    Vue入门 Vue是一个MVVM(Model / View / ViewModel)的前端框架,相对于Angular来说简单.易学上手快,近两年也也别流行,发展速度较快,已经超越Angular了.比较 ...

  3. Linux入门常用指令

    linux获取硬盘和目录大小的命令 df命令 Linux下可以用df命令获取硬盘的使用情况,通过man可以获取df命令的详细情况.df命令经常用的参数为: a:显示全部的档案系统和各分割区的磁盘使用情 ...

  4. linux入门常用指令1.配置本地yum源

    创建光盘挂载点 [root@localhost /]# mkdir /mnt/cdrom 挂载光盘 #挂载光盘 [root@localhost /]# mount /dev/cdrom /mnt/cd ...

  5. PHP快速入门 常用配置

    1 打开php.ini-dist文件 2 查找"file_uploads",确定为On(确定服务器上的 PHP 脚本是否可以接受文件上传.) 3 查找"max_execu ...

  6. linux入门常用指令4.挂载数据盘

    挂载硬盘 #查看当前分区情况 [root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sdb 8:16 0 5G 0 dis ...

  7. linux入门常用指令3.安装mysql

    下载安装包 MySQL-5.6.42-1.el6.x86_64.rpm-bundle_redhat [root@localhost src]# mkdir mysql [root@localhost ...

  8. linux入门常用指令2.安装nginx

    下载nginx包 nginx-1.10.3.tar.gz 解压 [root@localhost src]# tar -zxvf nginx-1.10.3.tar.gz [root@localhost ...

  9. grid布局快速入门

    Grid布局快速入门 常用Grid布局属性介绍 下面从一个简单Grid布局例子说起.CSS Grid 布局由两个核心组成部分是 wrapper(父元素)和 items(子元素). wrapper 是实 ...

随机推荐

  1. Centos 安装php Imagick 扩展

    从 centos 仓库安装 首先安装 php-pear php-devel,gcc三个软件包 yum install php-pear php-devel gcc 通过 yum 安装Centos 官方 ...

  2. d3操作svg路径动画,及dom移动

    图片跟随路径循环运动,dom也跟着路径运动(利用实时获取坐标位置的方法,改变transform) 1,准备路径 a,自己脑补路径 b,在ps上画好,然后在保存成png-24图片,背景透明,在网站htt ...

  3. Delphi GDI(一)

    Delphi 7下IGDIPlus库的使用 IGDI+是一个免费开源封装微软GDI+功能的Delphi库,该库使得可以用Delphi语言代码快速简短的实现复杂GDI+应用程序. 官方网站:http:/ ...

  4. 10、 导出python脚本进行数据驱动的接口测试

    postman自带脚本导出功能,对于代码小白来说,可以不错的学习代码级接口测试 第一步:输入接口地址,点击send 第二步:点击code,导出脚本文件,为python脚本 第三步:安装python3以 ...

  5. ncurses库的介绍与安装

    Frm: http://blog.csdn.net/Mary_Jane/article/details/50769631 介绍 ncurses(new curses)是一套编程库,它提供了一系列的函数 ...

  6. HDU1501-Zipper-字符串的dfs

    Given three strings, you are to determine whether the third string can be formed by combining the ch ...

  7. [14]APUE:API for Mysql

    库:/usr/lib64/libmysqlclient.so.#.#... 头文件:/usr/lib64/mysql/mysql.h 一.建立连接 MYSQL *mysql_init(MYSQL *) ...

  8. Android Telephony分析(四) ---- TelephonyManager详解

    前言 TelephonyManager主要提供Telephony相关信息的查询/修改功能,以及Phone状态监听功能,封装的方法主要是提供给APP上层使用.TelephonyManager.java ...

  9. scala实现读取Oracle数据

    用scala实现读取oracle数据 增加oralce的jar包后 package cn.bigdata.scala.oracle import java.sql.{DriverManager, Co ...

  10. 整理及优化CSS代码的7个原则

    作为网页设计师(前端工程师),你可能还记得曾经的那个网页大小建议:一个网页(包括HTML.CSS.Javacript.Flash和图片)尽量不要超过30KB的大小,随着互联网的日益庞大,网络带宽也在飞 ...