AStyle (Artistic Style) is a versatile code formatting tool designed to automatically format source code files across various programming languages. It supports languages such as C, C++, C#, and Java, among others. AStyle ensures that code adheres to a consistent style, enhancing readability and maintainability in software projects.
By standardizing code formatting, AStyle simplifies collaboration among developers and improves code quality. It can be integrated into development workflows to enforce coding standards and reduce manual formatting efforts.
Installation of AStyle on Windows can be conveniently managed through Chocolatey, a popular package manager for Windows. Chocolatey streamlines the installation process, making it easy to set up and maintain AStyle across development environments.
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
choco install astyle
choco install astyle
installs AStyle and its dependencies via Chocolatey.astyle --recursive --suffix=none "*.c"
.c
files in the current directory and its
subdirectories
using AStyle, without saving original files with a .orig
extension.
--recursive
: Processes files in subdirectories recursively.--suffix=none
: Specifies not to create backup files with a suffix."*.c"
: Matches all files with the .c
extension for formatting..c
file according to default settings or those
specified in a configuration file, without creating .orig
backup files due to the
--suffix=none
option.
.orig
extension, thanks to the --suffix=none
option.
astyle --options=C:\ProgramData\chocolatey\lib\astyle\tools\astyle-3.5.2-x64\file\astyle.ini --recursive "*.c"
.c
files based on options defined in a configuration file
(astyle.ini
).
--options=C:\ProgramData\chocolatey\lib\astyle\tools\astyle-3.5.2-x64\file\astyle.ini
:
Specifies the path to the configuration file containing formatting options.--recursive "*.c"
: Recursively formats all .c
files in the current
directory and its subdirectories..c
file according to settings specified in
astyle.ini
.
.orig
extension.
astyle --style=allman --indent=spaces=4 example.c
example.c
) using inline options.
--style=allman
: Sets the brace style to "allman".--indent=spaces=4
: Sets indentation style to use 4 spaces.example.c
: Specifies the file to format.example.c
according to specified options.
example.c
file and creates a
formatted copy. The original file is saved with a .orig
extension.
astyle --style=java --indent=tab --recursive "src/*.c"
.c
files in a specific directory (src
) using inline options.
--style=java
: Sets the brace style to "java".--indent=tab
: Sets indentation style to use tabs.--recursive "src/*.c"
: Recursively formats all .c
files in the
src
directory.
.c
files in src
and its subdirectories
as
per specified options.
.orig
extension.
astyle --style=google --indent=spaces=2 --recursive "*.cpp"
.cpp
files in the current directory and its subdirectories using the Google
style
guide and 2-space indentation.
--style=google
: Sets the brace style to "google".--indent=spaces=2
: Sets indentation style to use 2 spaces.--recursive "*.cpp"
: Recursively formats all .cpp
files in the current
directory and its subdirectories..cpp
file according to the Google style guide
and
specified indentation.
.orig
extension.
astyle --style=kr --indent=tab=8 "source.c"
source.c
) using the K&R style and 8-space tab indentation.
--style=kr
: Sets the brace style to "K&R".--indent=tab=8
: Sets indentation style to use tabs with an 8-space width.source.c
: Specifies the file to format.source.c
according to specified options.
source.c
file and creates a
formatted copy. The original file is saved with a .orig
extension.
astyle --style=stroustrup --pad-oper --suffix=none "*.java"
.java
files in the current directory using the Stroustrup style and adds
padding
around operators.
--style=stroustrup
: Sets the brace style to "Stroustrup".--pad-oper
: Adds padding around operators.--suffix=none
: No backup files are created."*.java"
: Matches all files with the .java
extension for formatting.
.java
file according to specified options.
astyle --style=ansi --indent=force-tab=4 --suffix=.bak "*.h"
.h
files in the current directory using ANSI style and forces 4-space tab
indentation, with backups saved with a .bak
extension.
--style=ansi
: Sets the brace style to "ANSI".--indent=force-tab=4
: Forces tab indentation with a width of 4 spaces.--suffix=.bak
: Saves backup files with a .bak
extension."*.h"
: Matches all files with the .h
extension for formatting..h
file according to specified options.
.bak
extension.
astyle --style=linux --align-pointer=name "*.cpp"
.cpp
files in the current directory using the Linux style and aligns pointers
with
the
variable name.
--style=linux
: Sets the brace style to "Linux".--align-pointer=name
: Aligns pointers with the variable name."*.cpp"
: Matches all files with the .cpp
extension for formatting.
.cpp
file according to specified options.
.orig
extension.
astyle --style=mozilla --indent=spaces=2 "*.js"
.js
files in the current directory using the Mozilla style and 2-space
indentation.
--style=mozilla
: Sets the brace style to "Mozilla".--indent=spaces=2
: Sets indentation style to use 2 spaces."*.js"
: Matches all files with the .js
extension for formatting..js
file according to specified options.
.orig
extension.
astyle --style=gnu --add-brackets "*.cxx"
.cxx
files in the current directory using the GNU style and adds brackets to
control
statements.
--style=gnu
: Sets the brace style to "GNU".--add-brackets
: Adds brackets to control statements."*.cxx"
: Matches all files with the .cxx
extension for formatting.
.cxx
file according to specified options.
.orig
extension.
astyle --style=whitesmith --suffix=none "*.hpp"
.hpp
files in the current directory using the Whitesmith style and does not
create
backup files.
--style=whitesmith
: Sets the brace style to "Whitesmith".--suffix=none
: No backup files are created."*.hpp"
: Matches all files with the .hpp
extension for formatting.
.hpp
file according to specified options.
astyle --style=pico --delete-empty-lines "*.cs"
.cs
files in the current directory using the Pico style and deletes empty
lines.
--style=pico
: Sets the brace style to "Pico".--delete-empty-lines
: Deletes empty lines."*.cs"
: Matches all files with the .cs
extension for formatting..cs
file according to specified options.
.orig
extension.
astyle --style=kr --indent-classes "*.cpp"
.cpp
files in the current directory using the K&R style and indents class
declarations.
--style=kr
: Sets the brace style to "K&R".--indent-classes
: Indents class declarations."*.cpp"
: Matches all files with the .cpp
extension for formatting.
.cpp
file according to specified options.
.orig
extension.
astyle --style=ratliff --indent-switches "*.c"
.c
files in the current directory using the Ratliff style and indents switch
statements.
--style=ratliff
: Sets the brace style to "Ratliff".--indent-switches
: Indents switch statements."*.c"
: Matches all files with the .c
extension for formatting..c
file according to specified options.
.orig
extension.
astyle --style=horstmann --indent-preproc-block "*.cpp"
.cpp
files in the current directory using the Horstmann style and indents
preprocessor
blocks.
--style=horstmann
: Sets the brace style to "Horstmann".--indent-preproc-block
: Indents preprocessor blocks."*.cpp"
: Matches all files with the .cpp
extension for formatting.
.cpp
file according to specified options.
.orig
extension.
astyle --style=java --indent=spaces=4 "*.java"
--style=java
: Sets the brace style to "java".--indent=spaces=4
: Sets indentation style to use 4 spaces."*.java"
: Matches all files with the .java extension for formatting.astyle --style=google --convert-tabs --suffix=.bak "*.cpp"
--style=google
: Sets the brace style to "google".--convert-tabs
: Converts tabs to spaces.--suffix=.bak
: Saves backup files with a .bak extension."*.cpp"
: Matches all files with the .cpp extension for formatting.astyle --style=kr --attach-namespaces "*.hpp"
--style=kr
: Sets the brace style to "K&R".--attach-namespaces
: Attaches namespaces."*.hpp"
: Matches all files with the .hpp extension for formatting.astyle --style=otbs --align-pointer=name "*.c"
--style=otbs
: Sets the brace style to "OTBS".--align-pointer=name
: Aligns pointers with variable names."*.c"
: Matches all files with the .c extension for formatting.Thank you for visiting this website. If you have any questions or would like to get in touch, please feel free to contact me.
Visit on GitHub