Scroll to navigation

astyle(1) user documentation astyle(1)

NAME

astyle - C syntax indenter and formatter

SYNOPSIS

astyle [OPTIONS] [input files]

DESCRIPTION

astyle provides a variety of options to apply a consistent coding style to C, C++, Java or Objective-C source code files.

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.

Wildcards (* and ?) may be used in the filename. A 'recursive' option can process directories recursively. Multiple file extensions may be separated by a comma.

By default, astyle is set up to indent with four spaces per indent, a maximal indentation of 40 spaces inside continuous statements, a minimum indentation of eight spaces inside conditional statements, and NO formatting options.

Brace Style Options

If no brace style is requested, the opening braces will not be changed and closing braces will be broken from the preceding line.

Allman style formatting/indenting. Broken braces.

Java style formatting/indenting. Attached braces.

Kernighan & Ritchie style formatting/indenting. Linux braces.

Stroustrup style formatting/indenting. Linux braces, with broken closing headers.

Whitesmith style formatting/indenting. Broken, indented braces. Indented class blocks and switch blocks.

VTK style formatting/indenting. Broken, indented braces except for the opening braces.

Ratliff style formatting/indenting. Attached, indented braces.

GNU style formatting/indenting. Broken braces, indented blocks.

Linux style formatting/indenting. Linux braces, minimum conditional indent is one-half indent.

Horstmann style formatting/indenting. Run-in braces, indented switches.

One True Brace Style formatting/indenting. Linux braces, add braces to all conditionals.

Google style formatting/indenting. Attached braces, indented class modifiers.

Mozilla style formatting/indenting. Linux braces, with broken braces for structs and enums, and attached braces for namespaces.

WebKit style formatting/indenting. Linux braces, with attached closing headers.

Pico style formatting/indenting. Run-in opening braces and attached closing braces. Uses keep one line blocks and keep one line statements.

Lisp style formatting/indenting. Attached opening braces and attached closing braces. Uses keep one line statements.

Tab Options:

If no indentation option is set, the default option of 4 spaces per indent will be used.

Indent using # spaces per indent. Not specifying # will result in a default of 4 spaces per indent.

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

Indent using tab characters, assuming that each indent is # spaces long. Force tabs to be used in areas AStyle would prefer to use spaces.

Allows the tab length to be set to a length that is different from the indent length. This may cause the indentation to be a mix of both spaces and tabs. This option sets the tab length.

Brace Modify Options:

Attach braces to a namespace statement.

Attach braces to a class statement.

Attach braces to class inline function definitions.

Attach braces to an extern "C" statement.

Attach closing while of do-while to the closing brace.

Indentation Options:

Indent 'class' blocks so that the entire block is indented.

Indent 'class' access modifiers, 'public:', 'protected:' or indented.

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

Indent case blocks from the 'case XXX:' headers. Case statements not enclosed in blocks are NOT indented.

Indent the contents of namespace blocks.

Indent, instead of align, continuation lines following lines that contain an opening paren '(' or an assignment '='.

Indent continuation lines an additional # indents. The valid values are 0 thru 4 indents. The default value is 1 indent.

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

Indent preprocessor blocks at brace level 0. Without this option the preprocessor block is not indented.

Indent preprocessor conditional statements #if/#else/#endif to the same level as the source code.

Indent multi-line preprocessor #define statements.

Indent line comments that start in column one.

Indent a minimal # spaces in a continuous conditional belonging to a conditional header. The valid values are: 0 - no minimal indent. 1 - indent at least one additional indent. 2 - indent at least two additional indents. 3 - indent at least one-half an additional indent. The default value is 2, two additional indents.

Indent a maximal # spaces in a continuation line, relative to the previous line. The minimum and default value is 40.

Padding Options

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

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

Insert space padding around operators.

Insert space padding after commas.

Insert space padding around parenthesis on both the outside and the inside.

Insert space padding around parenthesis on the outside only.

Insert space padding around first parenthesis in a series on the outside only.

Insert space padding around parenthesis on the inside only.

Insert space padding after paren headers (e.g. 'if', 'for'...).

Remove unnecessary space padding around parenthesis. This can be used in combination with the 'pad' options above.

Apply padding to empty pairs of parentheses; combine with other parenthesis padding options.

Insert space padding around square brackets on both the outside and the inside.

Insert space padding around square brackets the inside only.

Insert space padding around square brackets the outside only.

Remove unnecessary space padding around square brackets.

Delete empty lines within a function or method. It will NOT delete lines added by the break-blocks options.

Fill empty lines with the white space of their previous lines.

Attach a pointer or reference operator (*, &, or ^) to either the operator type (left), middle, or operator name (right). To align the reference separately use --align-reference.

Attach a reference operator (&) to either the operator type (left), middle, or operator name (right). If not set, follow pointer alignment.

Remove superfluous empty lines exceeding the given number.

Remove superfluous whitespace.

Formatting Options

Break braces before closing headers (e.g. 'else', 'catch', ...). Use with --style=java, --style=kr, --style=stroustrup, --style=linux, or --style=1tbs."

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

Break one line headers (e.g. 'if', 'while', 'else', ...) from a statement residing on the same line.

Add braces to unbraced one line conditional statements.

Add one line braces to unbraced one line conditional statements.

Remove braces from a braced one line conditional statements.

Break the return type from the function name. Options are for the function definitions and the function declarations.

Attach the return type to the function name. Options are for the function definitions and the function declarations.

Don't break blocks residing completely on one line.

Don't break lines containing multiple statements into multiple single-statement lines.

Convert tabs to the appropriate number of spaces.

Close ending angle brackets on template definitions.

Remove the leading '*' prefix on multi-line comments and indent the comment text one indent.

max-code-length=# will break the line if it exceeds more than # characters. The valid values are 50 thru 200. If the line contains logical conditionals they will be placed first on the new line. The option break-after-logical will cause the logical conditional to be placed last on the previous line.

Indent a C or C++ source file (this is the default).

Indent a Java source file.

Indent a C# source file.

Indent an Objective-C source file.

Indent a JavaScript source file (experimental).

Indent a GHC source file (experimental).

Objective-C Options

Insert space padding after the '-' or '+' Objective-C method prefix.

Remove all space padding after the '-' or '+' Objective-C method prefix.

Insert space padding after the Objective-C return type.

Remove all space padding after the Objective-C return type.

Insert space padding after the Objective-C param type.

Remove all space padding after the Objective-C param type.

Align the colons in an Objective-C method definition.

Add or remove space padding before or after the colons in an Objective-C method call.

Other Options

Append the suffix #### instead of '.orig' to original filename.

Do not retain a backup of the original file.

Process subdirectories recursively.

Perform a trial run with no changes made to check for formatting.

Specify a file or directory #### to be excluded from processing.

Allow processing to continue if there are errors in the exclude=#### options. It will display the unmatched excludes.

Allow processing to continue if there are errors in the exclude=#### options. It will NOT display the unmatched excludes.

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

Preserve the original file's date and time modified. The time modified will be changed a few micro seconds to force a compile.

Verbose mode. Extra informational messages will be displayed.

Formatted display mode. Display only the files that have been formatted.

Quiet mode. Suppress all output except error messages.

Force use of the specified line end style. Valid options are windows (CRLF), linux (LF), and macold (CR).

Command Line Only

Specify a default option file #### to read and use. It must contain a file path and a file name.

Specify a project option file #### to read and use. It must contain a file name only, without a directory path. The file should be included in the project top-level directory. The default file name is .astylerc or _astylerc.

The displayed output will be ascii characters only.

Print version number.

Print this help message.

Open the HTML help file "astyle.html" in the default browser. The documentation must be installed in the standard install path.

Open a HTML help file in the default browser using the file path ####. The path may include a directory path and a file name, or a file name only. Paths containing spaces must be enclosed in quotes.

Use the file path #### as input to single file formatting. This is a replacement for redirection.

Use the file path #### as output from single file formatting. This is a replacement for redirection.

Option Files

Artistic Style looks for a default option file and/or a project option file in the following order:

1. The command line options have precedence.

2. The project option file has precedence over the default file
o the file name indicated by the --project= command line option.
o the file named .astylerc or _ astylerc.
o the file name identified by ARTISTIC_STYLE_PROJECT_OPTIONS.
o the file is disabled by --project=none on the command line.

3. The default option file that can be used for all projects.
o the file path indicated by the --options= command line option.
o the file path indicated by ARTISTIC_STYLE_OPTIONS.
o the file named .astylerc in the HOME directory (for Linux).
o the file name astylerc in the APPDATA directory (for Windows).
o the file is disabled by --project=none on the command line.

Long options within the option files may be written without '--'.

Line-end comments begin with a '#'.

Disable Formatting

Blocks of code can be disabled with the comment tags *INDENT-OFF* and *INDENT-ON*. It must be contained in a one-line comment.

Padding of operators can be disabled on a single line using the comment tag *NOPAD*. It must be contained in a line-end comment.

Examples

File conversions:

astyle --style=allman /home/project/foo.cpp

astyle --style=allman --recursive /home/project/*.cpp,*.h

astyle --style=allman < OriginalSourceFile > BeautifiedSourceFile

AUTHORS

Andre Simon <as@andre-simon.de>

SEE ALSO

More information at https://sourceforge.net/p/astyle/.

2024-01-19 Andre Simon