最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

astyle – a good code indenter/ formatter/ beautifier

工作和技术 crifan 2735浏览 0评论

Artistic Style 1.22

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

Home Page:http://astyle.sourceforge.net/
Project Page:http://sourceforge.net/projects/astyle/

first give some example :

F:Linux_resourceastyletestfile>astyle -r test/*.c
————————————————–
directory test*.c
————————————————–
formatted nandas.c
formatted t2nandas2.c
formatted t2nandas4.c
formatted t2t3nandas3.c

F:Linux_resourceastyletestfile>astyle –style=ansi –mode=c -r test/*.c
————————————————–
directory test*.c
————————————————–
formatted nandas.c
formatted t2nandas2.c
formatted t2nandas4.c
formatted t2t3nandas3.c

F:Linux_resourceastyletestfile>astyle –style=kr –mode=c -r test/*.c
————————————————–
directory test*.c
————————————————–
formatted nandas.c
formatted t2nandas2.c
formatted t2nandas4.c
formatted t2t3nandas3.c

F:Linux_resourceastyletestfile>astyle –style=linux -r test/*.c
————————————————–
directory test*.c
————————————————–
formatted nandas.c
formatted t2nandas2.c
formatted t2nandas4.c
formatted t2t3nandas3.c

F:Linux_resourceastyletestfile>astyle –style=gnu –mode=c -r test/*.c
————————————————–
directory test*.c
————————————————–
formatted nandas.c
formatted t2nandas2.c
formatted t2nandas4.c
formatted t2t3nandas3.c

F:Linux_resourceastyletestfile>astyle -V
Artistic Style Version 1.22

simple explanation :

–style= gnu / linux / ansi /java ,these are predefined style ,we can use it directly ,very useful ones.

-r is –recursive or -R.

–mode= c / java / cs to destinate the source file format .

some useful info :

Usage

Artistic style is a console program that receives information from the command line. The format of the command line is:

astyle  [options]  <em>SourceFile1  SourceFile2  SourceFile3</em>  [ . . . ]

Or to save the file with a different name:

astyle [options] &lt; <em>OriginalSourceFile</em> &gt; <em>BeautifiedSourceFile</em>

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

The block parens [ ] indicate that more than one option or more than one filename can be entered. They are NOT actually included in the command. For the options format see the following Options section.

With the first option, the newly indented file retains the original file name, while a copy of the original file is created with an .orig appended to the original file name. (This can be set to a different string by the option --suffix=, or suppressed altogether by the options -n or --suffix=none). Thus, after indenting SourceFile1.cpp as above, the indented result will be named SourceFile1.cpp, while the original pre-indented file will be renamed to SourceFile1.cpp.orig.

With the second option, the file is saved with a different name. Therefore a copy is not created.

Wildcards (such as "*.cpp"), can be used if the project is compiled to include them. See the Installation Information for instructions.

Predefined Style Options

Predefined Style options define the style by setting several other options. If other options are also used, the placement of the predefined style option in the command line is important. If the predefined style option is placed first, the other options may override the predefined style. If placed last, the predefined style will override the other options.

For example the style –style=ansi sets the option –brackets=break. If the command line specifies "–style=ansi –brackets=attach", the brackets will be attached and the style will not be ansi style. If the order on the command line is reversed to "–brackets=attach –style=ansi ", the brackets will be broken (ansi style) and the attach option will be ignored.

For the options set by each style check the parseOption function in astyle_main.cpp.

--style=ansi
ANSI style formatting/indenting. Brackets are broken, indentation is 4 spaces. Namespaces, classes, and switches are NOT indented.

namespace foospace
<span class="brace"><font color="#ff0000">{</font></span>
int Foo()
<span class="brace"><font color="#ff0000">{</font></span>
    if (isBar)
<span class="brace"><font color="#ff0000">    {</font></span>
        bar();
        return 1;
<span class="brace"><font color="#ff0000">    }</font></span>
    else
        return 0;
<span class="brace"><font color="#ff0000">}
}</font></span>

--style=gnu
GNU style formatting/indenting. Brackets are broken, blocks are indented, and indentation is 2 spaces. Namespaces, classes, and switches are NOT indented.

namespace foospace
<span class="brace"><font color="#ff0000">  {</font></span>
    int Foo()
<span class="brace"><font color="#ff0000">      {</font></span>
        if (isBar)
<span class="brace"><font color="#ff0000">          {</font></span>
            bar();
            return 1;
<span class="brace"><font color="#ff0000">          }</font></span>
        else
          return 0;
<span class="brace"><font color="#ff0000">      }
  }</font></span>

--style=kr
Kernighan & Ritchie style formatting/indenting. Brackets are attached, indentation is 4 spaces. Namespaces, classes, and switches are NOT indented.

namespace foospace <span class="brace"><font color="#ff0000">{</font></span>
int Foo() <span class="brace"><font color="#ff0000">{</font></span>
    if (isBar) <span class="brace"><font color="#ff0000">{</font></span>
        bar();
        return 1;
<span class="brace"><font color="#ff0000">    }</font></span> else
        return 0;
<span class="brace"><font color="#ff0000">}
}</font></span>

--style=linux
Linux style formatting/indenting. All brackets are linux style, indentation is 8 spaces. Namespaces, classes, and switches are NOT indented.

namespace foospace
<span class="brace"><font color="#ff0000">{</font></span>
int Foo()
<span class="brace"><font color="#ff0000">{</font></span>
        if (isBar) <span class="brace"><font color="#ff0000">{</font></span>
                bar();
                return 1;
<span class="brace"><font color="#ff0000">        }</font></span> else
                return 0;
<span class="brace"><font color="#ff0000">}
}</font></span>

--style=java
Java style formatting/indenting. Brackets are attached, indentation is 4 spaces. Switches are NOT indented.

class foospace <span class="brace"><font color="#ff0000">{</font></span>
    int Foo() <span class="brace"><font color="#ff0000">{</font></span>
        if (isBar) <span class="brace"><font color="#ff0000">{</font></span>
            bar();
            return 1;
<span class="brace"><font color="#ff0000">        }</font></span> else
            return 0;
<span class="brace"><font color="#ff0000">    }
}</font></span>

Formatting Options

………..

--mode=c
Indent a C or C++ file. The option is usually set from the file extension for each file. You can override the setting with this entry. It will be used for all files regardless of the file extension. It allows the formatter to identify language specific syntax such as C++ classes, templates, and keywords.

--mode=java
Indent a Java file. The option is usually set from the file extension for each file. You can override the setting with this entry. It will be used for all files regardless of the file extension. It allows the formatter to identify language specific syntax such as Java class’s keywords.

--mode=cs
Indent a C sharp file. The option is usually set from the file extension for each file. You can override the setting with this entry. It will be used for all files regardless of the file extension. It allows the formatter to identify language specific syntax such as C sharp classes and keywords.

Other Options

--suffix=####
Append the suffix #### instead of ‘.orig’ to original filename (e.g. --suffix=.bak). If this is to be a file extension, the dot ‘.’ must be included. Otherwise the suffix will be appended to the current file extension.

--suffix=none / -n
Do not retain a backup of the original file. The original file is purged after it is formatted.

--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 / -r / -R
For each directory in the command line, process all subdirectories recursively. When using the recursive option the file name statement should contain a wildcard. Linux users should place the filepath and name in double quotes so the shell will not resolve the wildcards (e.g. "$HOME/src/*.cpp"). Windows users should place the filepath and name in double quotes if the path or name contains spaces.

--exclude=####
Specify a file or sub directory #### to be excluded from processing.

Excludes are matched from the end of the filepath. An exclude option of "templates" will exclude ALL directories named "templates". An exclude option of "cpp/templates" will exclude ALL "cpp/templates" directories. You may proceed backwards in the directory tree to exclude only the required directories.

Specific files may be excluded in the same manner. An exclude option of "default.cpp" will exclude ALL files named "default.cpp". An exclude option of "python/default.cpp" will exclude ALL files named "default.cpp" contained in a "python" subdirectory. You may proceed backwards in the directory tree to exclude only the required files.

Wildcards are NOT allowed. There may be more than one exclude statement. The filepath and name may be placed in double quotes (e.g. ‑‑exclude="foo bar.cpp").

--errors-to-stdout / -X
Print errors 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 Windows95.

--preserve-date / -Z
Preserve the original file’s date and time modified. The date and time modified will not be changed in the formatted file. This option is not effective if redirection is used.

--verbose / -v
Verbose mode. Display optional information, such as release number and statistical data.

--quiet / -q
Quiet mode. Suppress all output except error messages.

--version / -V
Print version number and quit. The short option must be by itself, it cannot be concatenated with other options.

--help / -h / -?
Print a help message and quit. The short option must be by itself, it cannot be concatenated with other options.

more details please refer :

Download

Download the latest release from the file releases page. Get the file for the appropriate platform (Linux, Mac, OpenVMS, or Windows). Extract the compressed package and copy it to a work folder. Then follow the install instructions for the appropriate platform as described in the Install Information.

转载请注明:在路上 » astyle – a good code indenter/ formatter/ beautifier

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
79 queries in 0.183 seconds, using 22.14MB memory