Linux command
astyle 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Format
astyle [file.cpp]
Example
astyle --style=google [file.cpp]
Example
astyle --suffix=none [file.cpp]
Example
astyle --recursive "*.cpp,*.h"
Example
astyle --indent=spaces=4 --style=kr [file.cpp]
说明
astyle (Artistic Style) is a source code indenter and formatter for C, C++, C++/CLI, Objective-C, C#, and Java. It reformats code to follow consistent style guidelines, improving readability and maintainability. The tool supports various predefined styles (Google, Mozilla, GNU, etc.) and extensive customization.
参数
- --style=_name_
- Predefined style: allman, java, kr, stroustrup, whitesmith, vtk, ratliff, gnu, linux, horstmann, 1tbs, google, mozilla, webkit, pico, lisp.
- --indent=_type_
- Indentation: spaces=n, tab, force-tab=n.
- --attach-braces / --break-braces
- Attach or break opening braces from headers (replaces the older --brackets option).
- --indent-classes
- Indent class blocks
- --indent-switches
- Indent switch blocks
- --pad-oper
- Pad operators with spaces
- --pad-header
- Pad headers (if, for, while)
- --unpad-paren
- Remove padding inside parentheses
- --suffix=_suffix_
- Backup file suffix (none to overwrite)
- --recursive
- Process directories recursively
- -n, --suffix=none
- Don't create backup files
- --dry-run
- Show changes without applying
FAQ
What is the astyle command used for?
astyle (Artistic Style) is a source code indenter and formatter for C, C++, C++/CLI, Objective-C, C#, and Java. It reformats code to follow consistent style guidelines, improving readability and maintainability. The tool supports various predefined styles (Google, Mozilla, GNU, etc.) and extensive customization.
How do I run a basic astyle example?
Run `astyle [file.cpp]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does --style=_name_ do in astyle?
Predefined style: allman, java, kr, stroustrup, whitesmith, vtk, ratliff, gnu, linux, horstmann, 1tbs, google, mozilla, webkit, pico, lisp.