Artistic Style 1.15.3

Free , Fast and Small Automatic Formatter
for C , C++ , C# , Java Source Codes

by Tal Davidson, Israel (E-mail: davidsont@bigfoot.com)

Main home Page http://sourceforge.net
Project Page http://www.sourceforge.net/projects/astyle

Artistic Style is a reindenter and reformatter of C, C++, C# and Java source code.

When indenting source code, we as programmers have a tendency to use both spaces and tab characters to create the wanted indentation. Moreover, some editors by default insert spaces instead of tabs when pressing the tab key, and other editors (Emacs for example) have the ability to "pretty up" lines by automatically setting up the white space before the code on the line, possibly inserting spaces in a code that up to now used only tabs for indentation.

Since the NUMBER of space characters showed on screen for each tab character in the source code changes between editors (until the user sets up the number to his liking...), one of the standard problems facing programmers when moving from one source code editor to another is that code containing both spaces and tabs that was up to now perfectly indented, suddently becomes a mess to look at when changing to another editor. Even if you as a programmer take care to ONLY use spaces or tabs, looking at other peoples source code can still be problematic.

To address this problem I have created Artistic Style - a series of filters, written in C++, that automatically reindent & reformat C/C++/C#/Java source files. These can be used from a command line, or it can be incorporated as classes in another C++ program.

Read Release Notes

Read License

Artistic Style may be used and  distributed under the GNU General Public License (GPL).

New versions, Comments, Questions, Bugs and Ideas for Improvement:

To use from the command line:

1) Unzip astyle.zip and compile 'astyle' (read README.txt for instructions).

2) Either place the resulting executable file's directory in your PATH system-variable, or move the executable to a directory that appears in your PATH system-variable.

3) Run it with the following syntax:

astyle [options] < OriginalSourceFile > BeautifiedSourceFile

OR

astyle [options] Foo.java Bar.javaAnotherBar.java [ . . . ]

The < and > characters are used to redirect the files into standard input and out of standard output - don't forget them!!!

The newly indented file RETAINS the original file name, while a copy of the original file is created with a ".orig" appended to the original file name. Thus, after indenting Foo.java as above, the indented result will be named Foo.java, while the original pre-indented file will be renamed to Foo.java.orig .

Options:

Not specifying any option will bring to C/C++/C# style indentation, with a default of 4 spaces per indent, and NO formatting.

Options may be written in two different ways:

  1. Long options:

    These options start with '--', and must be written one at a time
    (e.g. --brackets=attach --pad --indent=spaces=4 ).

  2. Short Options:

    These options start with a single '-', and may be appended together.
    Thus, writing -bps4 is the same as writing -b -p -s4 .

default options file may be used to define default options:

  • Artistic Style looks for the default options file in the following order: 
    1. The value of the the system variable ARTISTIC_STYLE_OPTIONS if one exists.
    2. The file named .astylerc in the directory pointed to by the HOME system variable (i.e. $PATH/.astylerc)
    3. The file named .astylerc in the directory pointed to by the HOMEPATH system variable (i.e. %HOMEPATH%\.astylerc)
  • Options may be set apart by new-lines, tabs or spaces.
  • Long options may be written in the options file without the preceding '--'.
  • Lines within the options file that begin with '#' are considered line-comments.
  • Example contents of a default options file:

    # default parsing is of java files
    mode=java
    # brackets should be attached to pre-bracket lines
    brackets=attach
    # set 6 spaces per indent<tt><br>indent=spaces=6
    # indent switch blocks
    indent-switches

    # suffix of original files should be .pre
    suffix=.pre

The following predefined style options are currently avaiable:

--style=ansi
ANSI style formatting/indenting.

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

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

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

--style=linux
Linux style formatting/indenting (brackets are broken apart from class/function declarations, but connected to command lines, and indents are set to 8 spaces).

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

--style=gnu
GNU style formatting/indenting.

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

--style=java
Java style formatting/indenting.

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

The following indentation options are currently available:

-c OR --mode=c
Indent a C, C++ or C# file.

-j OR --mode=java
Indent a Java file.

-s# OR --indent=spaces=#
Indent using # spaces per indent (e.g. -s4 OR --indent=spaces=4).

-t OR -t# OR --indent=tab=#
Indent using tab characters. Treat each tab as # spaces. If no '#' is set, treats tabs as 4 spaces.

-T# OR --force-indent=tab=#
Indent using tab characters. Treat each tab as # spaces. Uses tabs as indents in areas '--indent=tab' prefers to use spaces, such as inside multi-line statements.

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

The default:

class Foo
{
public:
    Foo();
    virtual ~Foo();
};

becomes:

class Foo
{
    public:
        Foo();
        virtual ~Foo();
};

-S OR --indent-switches
Indent 'switch' blocks so that the 'case XXX:' headers are indented in the class block.

The default:

switch (foo)
{
case 1:
    a += 2;
    break;

default:
    a += 2;
    break;
}

becomes:

switch (foo)
{
    case 1:
        a += 2;
        break;

default:
        a += 2;
        break;
}

-K OR --indent-cases
Indent 'case XXX:' lines so that they are flush with the comand lines under them.

The default:

switch (foo)
{
case 1:
    
{
        a += 2;
        break;
    
}

default:
    
{
        a += 2;
        break;
    
}
}

becomes:

switch (foo)
{
    case 1:
    
{
        a += 2;
        break;
    
}

    default:
    
{
        a += 2;
        break;
    
}
}

-B OR --indent-brackets
Add extra indentation to brackets.

The default:

if (isFoo) 
{ 
    bar(); 
} 
else 
{ 
    anotherBar(); 
}

becomes:

if (isFoo) 
    { 
    bar(); 
    } 
else 
    { 
    anotherBar(); 
    }

-G OR --indent-blocks
Add extra indentation to entire blocks.

The default:

if (isFoo) 
{ 
    bar(); 
} 
else 
    anotherBar();

becomes:

if (isFoo) 
    { 
        bar(); 
    } 
else 
    anotherBar();

-N OR --indent-namespaces
Add extra indentation to namespaces.

The default:

namespace foospace
{
class Foo
{
    public:
        Foo();
        virtual ~Foo();
};
}

becomes:

namespace foospace
{
    class Foo
    
{
        public:
            Foo();
            virtual ~Foo();
    
};
}

-L OR --indent-labels
Add extra indentation to labels so they they appear 1 indent less than the current indentation, rather than being flushed to the left (the default).

The default:

int foospace()
{
    while (isFoo)
    
{
        ...
        goto error;

error:
        ...
    
}
}

becomes:

int foospace()
{
    while (isFoo)
    
{
        ...
        goto error;

error:
        ...
    
}
}

-M# OR --max-instatement-indent=# 
Indent a maximal # spaces in a continuous statement, relatively to the previous line (e.g. --max-instatement-indent=40)

)

The default:

// default setting makes this non-bracketed code clear
if (a < b
        || c > d)
    foo++;

// but creates an exaggerated indent in this bracketed code
if (a < b
        || c > d)
{
    foo++;
}

When setting --min-conditional=0 :

// setting makes this non-bracketed code less clear
if (a < b
    || c > d)
    foo++;

// but makes this bracketed code prettier
if (a < b
    || c > d)
{
    foo++;
}

--indent-preprocessor
Indent multi-line preprocessor definitions. should be used with --convert-tabs for proper results. Does a pretty good job, but can not perform miracles in obfuscated preprocessor definitions.

--convert-tabs
Converts tabs into single spaces.

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

The following formatting options are currently available:

-b OR --brackets=break
Break brackets  from their pre-block statements ( i.e. ANSI C, C++ style ).

if (isFoo) 
{ 
    bar(); 
} 
else 
{ 
    anotherBar(); 
}

-a OR --brackets=attach
Attach brackets to their pre-block statements ( i.e. Java , K&R style ).

if (isFoo){ 
    bar(); 
} else { 
    anotherBar(); 
}

-l OR --brackets=linux
Break brackets from class/function declarations, but attach brackets to pre-block command statements.

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

--brackets=break-closing-headers
When used with either '--brackets=attach' or '--brackets= linux' , breaks closing headers (e.g. 'else', 'catch', ...) from their immediately preceding closing brackets.).

if (isFoo){ 
    bar();
 
}else {
 
    anotherBar();
 
}

becomes:

if (isFoo) { 
    bar(); 
}
 
else { 
    anotherBar(); 
}

--break-blocks
Pad empty lines around header blocks (e.g. 'if', 'while'...).

isFoo = true;
if (isFoo) { 
    bar(); 
} else {
    anotherBar(); 

}
isBar = false;

becomes:

isFoo = true;

if (isFoo) { 
    bar(); 
} else {
    anotherBar(); 
}

isBar = false;

--break-blocks=all
Pad empty lines around header blocks (e.g. 'if', 'while'...). Treat closing header blocks (e.g. 'else', 'catch') as stand-alone blocks.

isFoo = true;
if (isFoo) { 
    bar(); 
} else {
    anotherBar(); 

}
isBar = false;

becomes:

isFoo = true;

if (isFoo) { 
    bar(); 

} else
 {
    anotherBar(); 
}

isBar = false;

--break-elseifs
Break 'else if()' header combinations into seperate lines.

if (isFoo) { 
    bar(); 
} else if (isBar()){
    anotherBar(); 

}

becomes:

if (isFoo) {
    bar(); 
} else 
    if (isBar())
{
        anotherBar();

    }

-p OR --pad=oper
Insert space padding around operators only.

if (isFoo) 
    a = bar((b-c)*a,*d--);

becomes:

if (isFoo) 
    a = bar((b - c) * a, *d--);

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

if (isFoo) 
    a = bar((b-c)*a,*d--);

becomes:

if ( isFoo ) 
    a = bar( ( b-c )*a, *d-- );

-POR --pad=all
Insert space padding around operators AND parenthesies.

if (isFoo) 
    a = bar((b-c)*a,*d--);

becomes:

if ( isFoo ) 
    a = bar( ( b - c ) * a, *d-- );

-o OR--one-line=keep-statements
Don't break complex statements and multiple statements residing in a single line.

if (isFoo)
{
  
    isFoo = false; cout << isFoo << endl;
}

remains as is.

if (isFoo) DoBar();

remains as is.

-O OR--one-line=keep-blocks
Don't break one-line blocks.

if (isFoo)
{ isFoo = false; cout << isFoo << endl; }

remains as is.

The following other options are currently available:

--suffix=####
Append the suffix #### instead of '.orig' to original filename. (e.g. --suffix=.prev)

-X OR --errors-to-standard-output
Print errors and help information to standard-output rather than to standard-error.
This option should be helpful for systems/shells that do not have this option, such as in Windows-95.

-v OR --version
Print version number.

-h OR -? OR --help
Print a help message and quit.
 

Acknowledgements:

-Special thanks to: Jim Watson, Fred Shwartz, W. Nathaniel Mills III, Danny Deschenes, Andre Houde, Richard Bullington, Paul-Michael Agapow, Daryn Adler for their patches and contributions to Artistic Style !!!

-Special thanks to Richard Bullington andMicroState for giving Artistic Style its original mailing-list !!!

-Special thanks toSourceForge for giving Artistic Style itshome !!!

-Special thanks to Paul Michael Agapow for creating a GUI interface for Artistic Style on the Macintosh.

-Thanks to all the dedicated beta-testers and bug notifiers !!!

ENJOY !!!

reference:

URL:http://www.desy.de/~njwalker/astyle.html

Indenting source code的更多相关文章

  1. Artistic Style 3.1 A Free, Fast, and Small Automatic Formatter for C, C++, C++/CLI, Objective‑C, C#, and Java Source Code

    Artistic Style - Index http://astyle.sourceforge.net/ Artistic Style 3.1 A Free, Fast, and Small Aut ...

  2. Tips for newbie to read source code

    This post is first posted on my WeChat public account: GeekArtT Reading source code is always one bi ...

  3. 编程等宽字体Source Code Pro(转)

    Source Code Pro - 最佳的免费编程字体之一!来自 Adobe 公司的开源等宽字体下载     每一位程序员都有一套自己喜爱的代码编辑器与编程字体,譬如我们之前就推荐过一款"神 ...

  4. How to build the Robotics Library from source code on Windows

    The Robotics Library is an open source C++ library for robot kinematics, motion planning and control ...

  5. How to build windows azure PowerShell Source Code

    Download any version source code of Windows Azure Powershell from https://github.com/Azure/azure-sdk ...

  6. akka cluster sharding source code 学习 (1/5) 替身模式

    为了使一个项目支持集群,自己学习使用了 akka cluster 并在项目中实施了,从此,生活就变得有些痛苦.再配上 apache 做反向代理和负载均衡,debug 起来不要太酸爽.直到现在,我还对 ...

  7. view class source code with JAD plugin in Eclipse

    The default class viewer doesn't decompile the class file so you cannot open and check the source co ...

  8. Classic Source Code Collected

    收藏一些经典的源码,持续更新!!! 1.深度学习框架(Deep Learning Framework). A:Caffe (Convolutional Architecture for Fast Fe ...

  9. Attach source code to a Netbeans Library Wrapper Module

    http://rubenlaguna.com/wp/2008/02/22/attach-source-code-to-a-netbeans-library-wrapper-module/ Attach ...

随机推荐

  1. PHP课程十大 PHP图像处理功能和实现的验证码

    假如你喜欢这个博客,访问这个博客地址:http://blog.csdn.net/junzaivip 总结: gd绘图库: 数学函数 PHP图片处理函数 图片处理函数使用场景 1.验证码 2.缩放 3. ...

  2. DDD实践案例:引入事件驱动与中间件机制来实现后台管理功能

    DDD实践案例:引入事件驱动与中间件机制来实现后台管理功能 一.引言 在当前的电子商务平台中,用户下完订单之后,然后店家会在后台看到客户下的订单,然后店家可以对客户的订单进行发货操作.此时客户会在自己 ...

  3. javascript系列之DOM(二)

    原文:javascript系列之DOM(二) 原生DOM扩展 我们接着第一部分来说,上文提到了两种常规的DOM操作:创建文档片段和遍历元素节点.我们知道那些雨后春笋般的库,有很大一部分工作就是提供了一 ...

  4. 使用Heartbeat实现双机热备

    使用Heartbeat实现"双机热备"或者称为"双机互备"heartbeat的工作原理:heartbeat最核心的包含两个部分,心跳监測部分和资源接管部分,心跳 ...

  5. JAVA于Get和Post差异请求

    1. get 离server在对数据的访问.post 它是对server数据的传输. get 请求返回 request - URI 随机信息指出,. Post 请求发送电子邮件.观看新闻或交互式用户发 ...

  6. Struts2.0+Spring3+Hibernate3(SSH~Demo)

    Struts2.0+Spring3+Hibernate3(SSH~Demo) 前言:整理一些集成框架,发现网上都是一些半成品,都是共享一部分出来(确实让人很纠结),这是整理了一份SSH的测试案例,完全 ...

  7. Qt 如何处理拖放应用程序参数时,中国

    你用 Qt 我们开发的应用程序.用户拖放文件到您的 exe 在.启动应用程序,在这个时候, main() 功能参数可以接收中国.如何正确处理它?非常easy,码如下面: QTextCodec *cod ...

  8. centos7的安装

    初装centos7还是在九月份,那时候关于win7 下centos7硬盘安装的资料很少,现在就好多, 在这里备份下东西吧 首先是安装的时候,关于找从那个地方找image的问题. hda ,sda分别表 ...

  9. IOS科研IOS开发笔记学习基础知识

    这篇文章是我的IOS学习笔记,他们是知识的基础,在这里,根据记录的查询后的条款. 1,UIScrollView能完毕滚动的功能. 示比例如以下: UIScrollView *tableScrollVi ...

  10. POJ 1637 Sightseeing tour(最大流)

    POJ 1637 Sightseeing tour 题目链接 题意:给一些有向边一些无向边,问能否把无向边定向之后确定一个欧拉回路 思路:这题的模型很的巧妙,转一个http://blog.csdn.n ...