Describes a C/C ++, C #, and Java code beautification tool.

Source: Internet
Author: User

We will introduce you to an open-source tool astyle, which supports C/C ++, C #, Java, and other languages and is formatted according to different styles.Code, Also known as beautification code.
The Code formatted with this tool is almost the same as my own style. I like this tool very much and can easily integrate it into.

 

The result is as follows:

 
DWORD dwthreadid; handle hthread = createthread (null, 0, mythreadfunction, 0, 0, & dwthreadid); If (hthread! = NULL) {waitforsingleobject (hthread, infinite);} else {_ tprintf (_ T ("createthread error % d \ n"), getlasterror ());}

Formatted code:

DWORD dwthreadid; handle hthread = createthread (null, 0, mythreadfunction, 0, 0, & dwthreadid); If (hthread! = NULL) {waitforsingleobject (hthread, infinite);} else {_ tprintf (_ T ("createthread error % d \ n"), getlasterror ());}

 

If you do not like the formatted code style, you can also choose other styles.

 

Parameter description:

Astyle.exe-A1-S4-M80-p-J-D-H-C-W test. cpp

-A1/-- style = ansi c style code I personally like to use this style

Void Foo (bool isfoo) {If (isfoo) {bar () ;}else {anotherbar ();}}

 

-- Indent = spaces/-- indent = spaces = #/-S # forcibly use spaces as indentation

# Indicates the number of spaces to be indented. For example,-S4 indicates four spaces to be indented. this parameter is strongly recommended.

 

-P adds spaces around the operator number, depending on your preferences.

 
If (FOO = 2) A = bar (B-c) * a, d --); becomes: If (FOO = 2) A = bar (B-c) * a, d -);

-J. Add braces for each if object based on your preferences.

 
If (isfoo) isfoo = false; becomes: If (isfoo) {isfoo = false ;}

-D Add a space on the side of the parentheses, depending on your preferences.

 
If (isfoo (a, B) bar (a, B); becomes: If (isfoo (a, B) bar (A, B );

-H adds a space after the C/C ++ keyword. We recommend that you use

If (isfoo (a, B) bar (a, B); becomes: If (isfoo (a, B) bar (A, B );

-M # alignment the defined parameters and variables. this parameter is very useful and can be used to alignment the parameters in disorder.

 
Fooarray [] = {red, green, blue}; foofunction (bararg1, bararg2, bararg3); becomes (with larger value): fooarray [] = {red, green, blue }; foofunction (bararg1, bararg2, bararg3 );

 

-C: Replace the Tab character with a space. We strongly recommend that you use this parameter.

Why should we replace the tab with a space?

This is mainly because different editors have different interpretations of tabs. Some editors interpret tabs as four spaces, eight, and two.

This will damage the alignment structure of the original code, so it is best to replace the tab with a space so that the code in any editor is displayed in an alignment style.

 

-W is recommended for macro alignment processing.

 
# Define is_bar (ARG, a, B) \ (is_foo (ARG), (a) \ | is_foo (ARG), (B) becomes: # define is_bar (ARG, a, B) \ (is_foo (ARG), (a) \ | is_foo (ARG), (B )))

It's really hi to see so many parameters for beautifying the code above.

 

Astyle.exe-A1-S4-M80-p-J-D-H-C-W $ (itemfilename) $ (itemext)
This parameter is used by myself. You can set it according to your own style. astyle also has many other parameters. I just list the parameters that I commonly use, for more information about other parameters, see the help documentation.

What if it is integrated into?

1. Copy astyle.exe to the "C: \ Program Files \ Microsoft Visual Studio 9.0 \ common7 \ ide \" directory.

2. Tools-> external tools

Add an external tool Configuration

 

Under the Tools menu, A beau is added and you can click it to beautify the current file, for example:

 

In general, the beautification effect of this tool is still very good. You can try it for anyone you like.

Http://astyle.sourceforge.net/

Download: http://nchc.dl.sourceforge.net/project/astyle/astyle/astyle%202.02/AStyle_2.02_windows.zip

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.