Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1494829
  • 博文数量: 226
  • 博客积分: 3997
  • 博客等级: 少校
  • 技术积分: 2369
  • 用 户 组: 普通用户
  • 注册时间: 2010-06-19 17:26
个人简介

Never save something for a special occasion. Every day in your life is a special occasion.

文章分类

全部博文(226)

文章存档

2018年(5)

2017年(11)

2016年(1)

2015年(17)

2014年(14)

2013年(30)

2012年(5)

2011年(52)

2010年(107)

分类:

2010-12-04 09:54:38

Artistic Style 1.15.3
A Free , Fast and Small Automatic Formatter
for C , C++ , C# , Java Source Codes
Release Date:2010-11-29
Topic:Software Development
Operating System:OS Portable (Source code to work with many OS platforms)
License:GNU Library or Lesser General Public License (LGPL)
Translations:English
User Interface:Command-line
Programming Language:C++
Project Page

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 .

New versions, Comments, Questions, Bugs and Ideas for Improvement:
Visit Astyle's project page at for:
 Astyle sources and binaries
 Mailing lists
 Bug tracking facilities
Author's e-mail: Reach me directly at
 
示例:
 
命令行:
astyle --style=ansi < m.c > out.

 

输入文件 m.c(片断):
main() {
      BYTE i; lcd_init(); // 初始化LCD

      delay(10);
    while(1) {
      lcd_wcmd(0x06); //向右移动光标

      lcd_pos(0); //设置显示位置为第一行的第1个字符

     for(i=0; dis1[ i ] != '\0'; i++)
     { //显示字符"WLCOME TO"

       lcd_wdat(dis1[ i ]);
       delay(30); //控制两字之间显示速度

     }

输出结果 out.c:
main()
{
    BYTE i;
    lcd_init(); // 初始化LCD

    delay(10);
    while(1)
    {
        lcd_wcmd(0x06); //向右移动光标

        lcd_pos(0); //设置显示位置为第一行的第1个字符

        for(i=0; dis1[ i ] != '\0'; i++)
        { //显示字符"WLCOME TO"

            lcd_wdat(dis1[ i ]);
            delay(30); //控制两字之间显示速度

        }
        lcd_pos(0x40); //设置显示位置为第二行第1个字符

        for(i=0; dis2[ i ] != '\0'; i++)
        {
            lcd_wdat(dis2[ i ]); //显示字符" "

            delay(30); //控制两字之间显示速度

        }
        delay(800); //控制停留时间


 
命令选项
 
Astyle Options
style options

--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;
   
}
}

 

indentation options

-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.

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

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

// 括号缩进

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

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

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

-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).

// 长句拆分缩进

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

-m# OR --min-conditional-indent=#
Set the minimal indent that is added when a header is built of multiple-lines. This indent makes helps to easily separate the header from the command statements that follow. The default setting for this option is twice the current indent. (e.g. --min-conditional-indent=8)

--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.

 

formatting options

-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.

 
other options

--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.
 

 

阅读(1127) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~