Artistic Style can process directories recursively. Wildcards (such as "*.cpp" or "*.c??") are processed internally.
If a shell is used, it should pass the wildcards to Artistic Style instead of resolving them first. For Linux
- use
- double quotes around paths whose file name contains wildcards. For Windows use double quotes around paths whose
- file name contains spaces. The recursive option in the
+ use double quotes around paths whose file name contains wildcards. For Windows use double quotes around paths
+ whose file name contains spaces. The recursive option in the
Other Options section contains information on recursive processing.
File Names
@@ -252,17 +282,17 @@
The names of special characters used in programming vary by region. The terminology used by Artistic Style,
followed by other common names, is:
- braces { } ‑ also called curly braces, brackets, or curly brackets.
- parens ( ) ‑ also called parentheses, brackets, round brackets, circle brackets, or soft brackets.
+ braces or curly braces { } ‑ also called brackets, or curly brackets.
+ parens or round brackets ( ) ‑ also called parentheses, brackets, circle brackets, or soft brackets.
square brackets [ ] ‑ also called block parens, brackets, closed brackets, or hard brackets.
angle brackets < > ‑ also called brackets, pointy brackets, triangular brackets, diamond brackets, tuples,
or chevrons.
- Visual Studio, and possibly other development environments, has an Edit option "Align Assignments" that will align
- assignment operators across multiple lines. There is also an extension named "Code alignment" that will align
- the code on other items as well. Formatting with these options and extensions can be used with Artistic Style.
- The space padding will be maintained and the alignment will be preserved.
+ Visual Studio, and possibly other development environments, has extensions that will align assignment operators
+ across multiple lines. There is an extension named "Code alignment" that will align the code on other items as
+ well. Formatting with these options and extensions can be used with Artistic Style. The space padding will be
+ maintained and the alignment will be preserved.
Artistic Style can format standard class library statements such as Open GL, wxWidgets, Qt, and MFC.
@@ -276,11 +306,9 @@
Unicode files encoded as UTF‑16, both big and little endian, will be formatted. The files must begin with
a byte order mark (BOM) to be recognized. Files encoded as UTF‑32 will be rejected. Some compilers do not
support these encodings. These files can be converted to UTF‑8 encoding with the program "iconv". There
- are Linux and Windows versions available (the Windows version does not seem to work for all encodings). A sample
- command line is "iconv ‑f UTF‑16 ‑t UTF‑8 < filein.cpp > fileout.cpp. Visual
- Studio can convert the files from the "File > Advanced Save Options" menu. Then select encoding "Unicode (UTF‑8
- with signature) - Codepage 65001". There are other development environments and text editors, such as SciTE, that
- can convert files to UTF‑8.
+ are Linux and Windows versions available (the Windows version does not seem to work for all encodings). Visual
+ Studio can convert the files from the "File > Advanced Save Options" menu. There are other development environments
+ and text editors, such as SciTE, that can convert files to UTF‑8.
Embedded statements that are multiple-line and are NOT in a C-type format, such as Python, are usually mal-formatted
(a C-type format has blocks enclosed by braces and statements terminated by a semi-colon). Macros that define
@@ -297,8 +325,7 @@
Quick Start
- If you have never used Artistic Style there are a
- several of ways to start.
+ If you have never used Artistic Style, there are several of ways to get started.
One is to run it with no options at all. This will use the default brace
style, 4 spaces per indent, and no formatting changes. This will break the braces for one
@@ -312,8 +339,8 @@
as described above.
A third option is to use an options file from the "file" folder. If there is a coding style you want
- to duplicate, input the appropriate options file. Use the option
- options=#### to specify the file to use. It must contain a path for the file, including
+ to duplicate, input the appropriate option file. Use the option
+ options=#### to specify the file to use. It must contain a path for the file, including
the file name.
Once you are familiar with the options you can customize the format to your personal preference.
@@ -325,12 +352,14 @@
Usage
+
Command Line
+
Artistic style is a console program that receives information from the command line.
+ Multiple file extensions may be used if separated by commas or semicolons. An optional space may follow if the
+ entire file path is enclosed in double quotes. There is no limit to the number of extensions used.
+
+
+
+ Example to format C++ files recursively using multiple file extensions:
The < and > characters may be used to redirect the files into standard input (stdin) and out of standard output
- (stdout) - don't forget them! With this option only one file at a time can be formatted. Wildcards are not
- recognized, there are no console messages, and a backup is not created. On Windows the output will always have
- Windows line ends.
+ (stdout) - don't forget them! With this option, only one file at a time can be formatted. Wildcards are not
+ recognized, there are no console messages, and a backup is not created. On Windows, the output will always have
+ Windows line ends. The options "stdin=" and "stdout=" can be used instead of redirection.
Example of redirection option to format a single file and change the name:
@@ -374,7 +423,7 @@
Not specifying any options will result in the default brace style,
4 spaces per indent, and no formatting changes.
- Options may be written in two different ways.
+ This program follows the usual GNU command line syntax. Options may be written two different ways.
Long options
@@ -393,33 +442,59 @@
-
Options File
+
Option Files
- An OPTIONAL, default options file may be used to supplement or replace the command line options.
-
-
The command line options have precedence. If there is a conflict between a command line option and an option in
- the default options file, the command line option will be used.
+ An OPTIONAL default option file and/or project option file may be used to supplement or replace the command
+ line options. They may use the computer's standard encoding, UTF-8 or UTF-16 unicode encoding.
+
+ Options may be set apart by new-lines, tabs, commas, or spaces. Long options in the option file may be written
+ without the preceding '--'. Lines within the option file that begin with '#' are considered line-comments.
+ The option files used in formatting and their location can be displayed by using the --verbose
+ option.
+
+
The command line options have precedence. If there is a conflict between a command line option
+ and an option in a default or project file, the command line option will be used.
+
+
The project option file has precedence over the default option file but not the command line
+ options. The project option file should be in the top directory of the project being formatted. The file is identified
+ by a file name only. One of the command line project options must be used to indicate
+ a file is available, or it must be referred to by the environment variable. Artistic Style looks for the file
+ in the current directory or one of its parent directories in the following order.
+
+
the file name indicated by the --project= command line option.
+
the file named .astylerc or _ astylerc.
+
the file name identified by the environment variable ARTISTIC_STYLE_PROJECT_OPTIONS if it exists.
+
the file or environment variable can be disabled by specifying --project=none on the command line.
+
+ The file is expected to be in the top directory of the project being formatted. Only one file will be used per
+ execution and all files to be formatted are assumed to be in the same project. Artistic Style will search
+ backward in the directory path to find the project option file. The initial directory path for the search is obtained
+ from one of the following locations in the following order.
+
+
The first SourceFilePath entered on the command line.
+
The value of "--stdin=" if it is used for redirection.
+
The current directory if "<" is used for rediredction. If the file to be formatted is not in the current
+ directory, use the "--stdin=" option instead.
+
-
Artistic Style looks for this file in the following locations (in order):
-
-
the file indicated by the --options= command line option;
-
the file and directory indicated by the environment variable ARTISTIC_STYLE_OPTIONS (if it exists);
-
the file named .astylerc in the directory pointed to by the HOME environment variable (e.g. "$HOME/.astylerc"
- on Linux);
-
-
the file named astylerc in the directory pointed to by the USERPROFILE environment variable (e.g. "%USERPROFILE%\astylerc"
- on Windows).
-
-
+
The default option file can be used for all projects. The file is identified by a file path and
+ a file name. One of the command line options must be used to indicate a file is available,
+ or it must be referred to by the environment variable. Artistic Style looks for a file path and file name in the
+ following order.
+
+
the file path indicated by the --options= command line option.
+
the file path indicated by the environment variable ARTISTIC_STYLE_OPTIONS if it exists.
+
the file named .astylerc in the directory pointed to by the HOME environment variable
+ (e.g. "$HOME/.astylerc" on Linux);
+
the file named astylerc in the directory pointed to by the APPDATA environment variable
+ (e.g. "%APPDATA%\astylerc" on Windows).
+
the file or environment variable can be disabled by specifying --options=none on the command line.
+
-
This option file lookup can be disabled by specifying --options=none on the command line.
-
Options may be set apart by new-lines, tabs, commas, or spaces.
-
Long options in the options file may be written without the preceding '--'.
-
Lines within the options file that begin with '#' are considered line-comments.
-
+
- Example of a default options file:
+ Example of a default or project option file:
# this line is a comment
--style=allman # this is a line-end comment
@@ -452,8 +527,8 @@
The beginning tag is "*INDENT-OFF*" and the ending tag is "*INDENT-ON*".
They may be used anywhere in the program with the condition that parsing is partially disabled between the
- tags. Disabling partial statements may result in incorrect formatting after the ending tag. If this happens expand
- the tags to include additional code.
+ tags. Disabling partial statements may result in incorrect formatting after the ending tag. If this happens,
+ expand the tags to include additional code.
The following retains the format of a preprocessor define:
@@ -475,9 +550,9 @@
padded incorrectly, then disabling the formatting may be necessary. To avoid having to use the "disable block"
tags above, a single line disable is available.
- A line-end comment tag "*NOPAD* will disable the "pad-oper", "align-pointer", and "align-reference"
- options. Parsing does NOT stop and all other formatting will be applied to the line. The tag applies to the
- one line only.
+ A line-end comment tag "*NOPAD*" will disable the "pad-oper", "align-pointer", and
+ "align-reference" options. Parsing does NOT stop and all other formatting will be applied to the line.
+ The tag applies to the one line only.
The following prevents the operator padding from changing:
@@ -503,8 +578,8 @@
Other brace styles are variations of these. Some will use variations on the placement of class, namespace,
or other braces. (Stroustrup, Google, One True Brace, Lisp). Others will indent the braces (Whitesmith, VTK,
- Banner, GNU). Still others will use run-in braces where the following statement is on the same line as the brace
- (Horstmann, Pico).
+ Banner, and GNU). Others will use run-in braces where the following statement is on the same line as the
+ brace (Horstmann and Pico).
There are technical arguments for selecting one style over another. But the usual reason comes down to
personal preference. Some like broken braces with vertical whitespace that makes the code easy to read.
@@ -594,10 +669,11 @@
--style=stroustrup / -A4
- Stroustrup style uses linux braces. Opening braces are broken from function definitions only.
- The braces are attached to everything else, including namespaces, classes, arrays, structs, enums,
- and statements within a function. This style frequently is used with headers broken from closing braces
- (break-closing-braces) and an indent of 5 spaces.
+ Stroustrup style uses linux braces with closing headers broken from closing braces
+ (e.g. ‑‑break‑closing‑headers). Opening braces are broken from function definitions only.
+ The opening braces are attached to everything else, including namespaces, classes, arrays, structs, enums, and
+ statements within a function. This style frequently is used with "attach‑closing‑while",
+ tabbed indents, and an indent of 5 spaces.
int Foo(bool isBar)
{
@@ -633,8 +709,9 @@
--style=vtk / -A15
- VTK (Visualization Toolkit) style uses broken, indented braces, except for the opening brace. Switch blocks
- are indented to prevent a 'hanging indent' with following case statements.
+ VTK (Visualization Toolkit) style uses broken, indented braces, except for the opening brace of classes,
+ arrays, structs, enums, and function definitions.. Switch blocks are indented to prevent a 'hanging
+ indent' with following case statements.
int Foo(bool isBar)
{
@@ -650,9 +727,9 @@
-
- --style=banner / -A6
- Banner style uses attached, indented braces. Switch blocks and class blocks are indented to prevent a 'hanging
+
+ --style=ratliff / --style=banner / -A6
+ Ratliff style uses attached, indented braces. Switch blocks and class blocks are indented to prevent a 'hanging
indent' with following case statements and C++ class modifiers (public, private, protected).
int Foo(bool isBar) {
@@ -669,9 +746,9 @@
--style=gnu / -A7
- GNU style uses broken braces and indented blocks. Extra indentation is added to blocks within a
- function only. Other braces and blocks are broken, but NOT indented. This style frequently is
- used with an indent of 2 spaces.
+ GNU style uses broken braces. Extra indentation is added to blocks within a function
+ only. The entire block is indented, not just the brace. This style frequently is used with an indent of 2
+ spaces.
int Foo(bool isBar)
{
@@ -729,7 +806,7 @@
--style=1tbs / --style=otbs / -A10
- "One True Brace Style" uses linux braces and adds braces to unbraceed one line conditional statements. Opening
+ "One True Brace Style" uses linux braces and adds braces to unbraced one line conditional statements. Opening
braces are broken from namespaces, classes, and function definitions. The braces are attached to everything
else, including arrays, structs, enums, and statements within a function.
@@ -770,7 +847,7 @@
--style=mozilla / -A16
Mozilla style uses linux braces. Opening braces are broken from classes, structs, enums, and function
definitions. The braces are attached to everything else, including namespaces, arrays, and statements
- within a function. This style frequently is used with an indent of 2 spaces.
+ within a function. This style frequently is used with an indent of 2 spaces and --break-return-type.
int Foo(bool isBar)
{
@@ -963,11 +1040,11 @@
--attach-inlines / -xl
- Attach braces to class and struct inline function definitions. This is not done for run-in type braces
- (Horstmann and Pico styles). This option is effective for C++ files only.
+ Attach braces to class and struct inline function definitions. This option has precedence for all
+ styles except Horstmann and Pico (run-in styles). It is effective for C++ files only.
- all braces are always attached to class and struct inline function definitions:
+ all braces are attached to class and struct inline method definitions:
class FooClass
{
void Foo() {
@@ -1217,7 +1294,7 @@
--indent-continuation=# / -xt#
Set the continuation indent for a line that ends with an opening paren '(' or an assignment '='. This includes
- function definitions and declarations. It will also modify the prevoius indent-after-paren option. The value for
+ function definitions and declarations. It will also modify the previous indent-after-paren option. The value for
# indicates a number of indents. The valid values are the integer
values from 0 thru 4. If this option is not used, the default value of 1 is
used.
@@ -1379,7 +1456,7 @@
3 - indent at least one-half an additional indent. This is intended for large indents (e.g. 8).
The default value is 2, two additional indents.
-
// default setting makes this non-braceed code clear
+
// default setting makes this non-braced code clear
if (a < b
|| c > d)
foo++;
@@ -1411,9 +1488,8 @@
--max-continuation-indent=# / -M#
- --max-instatement-indent=# is depreciated
Set the maximum of # spaces to indent a continuation line. The
- # indicates a number of columns and must not be less than 40 nor
+ # indicates a number of columns and must not be less than 40 or
greater than 120. If no value is set, the default value of 40 will be
used. This option will prevent continuation lines from extending too far to the right. Setting a larger value
will allow the code to be extended further to the right.
@@ -1523,12 +1599,12 @@
remain in the original column, if possible. Note that there is no option to unpad. Once padded, they
stay padded.
-
if (isFoo(a,b)
+
if (isFoo(a,b))
bar(a,b);
becomes:
-
if (isFoo(a, b)
+
if (isFoo(a, b))
bar(a, b);
@@ -1576,7 +1652,7 @@
only. Parens that are empty will not be padded. Any end of line comments will remain in the original column,
if possible. This can be used with unpad-paren below to remove unwanted spaces. If used with pad‑paren or
pad‑paren‑out, this option will be ignored. If used with pad‑paren‑in, the result will
- be the same as pad‑paren.
+ be the pad‑paren.
if (isFoo((a+2), b))
bar(a, b);
@@ -1691,32 +1767,32 @@
char* foo1;
char & foo2;
-String ^s1;
+string ^s1;
becomes (with align-pointer=type):
char* foo1;
char& foo2;
-String^ s1;
+string^ s1;
char* foo1;
char & foo2;
-String ^s1;
+string ^s1;
becomes (with align-pointer=middle):
char * foo1;
char & foo2;
-String ^ s1;
+string ^ s1;
char* foo1;
char & foo2;
-String ^s1;
+string ^s1;
becomes (with align-pointer=name):
char *foo1;
char &foo2;
-String ^s1;
+string ^s1;
@@ -1757,9 +1833,7 @@
Formatting Options
- --break-closing-braces / -y
- --break-closing-brackets is depreciated
-
+ --break-closing-braces / -y
When used with --style=java, --style=kr, --style=stroustrup, --style=linux, or --style=1tbs, this breaks closing
headers (e.g. 'else', 'catch', ...) from their immediately preceding closing braces. Closing header braces
are always broken with the other styles.
@@ -1821,10 +1895,7 @@
- --break-one-line-headers / -xb
-
-
-
+ --break-one-line-headers / -xb
Break one line headers (e.g. 'if', 'while', 'else', ...) from a statement residing
on the same line. If the statement is enclosed in braces, the braces will be formatted according to the requested
brace style.
@@ -1855,16 +1926,14 @@
- --add-braces / -j
- --add-brackets is depreciated
-
+ --add-braces / -j
Add braces to unbraced one line conditional statements (e.g. 'if', 'for', 'while'...). The statement must
be on a single line. The braces will be added according to the requested brace style. If no style is requested
the braces will be attached.
Braces will NOT be added to a multi-statement line if keep-one-line-statements is requested. Braces will
- NOT be added to a one line block if keep-one-line-blocks is requested. If --add-one-line-braces is also
- used, the result will be one line braces.
+ NOT be added to a one line block if keep-one-line-blocks is requested. If used with --add-one-line-braces,
+ the result will be one line braces.
if (isFoo)
isFoo = false;
@@ -1879,9 +1948,7 @@
- --add-one-line-braces / -J
- --add-one-line-brackets is depreciated
-
+ --add-one-line-braces / -J
Add one line braces to unbraced one line conditional statements (e.g. 'if', 'for',
'while'...). The statement must be on a single line. The option implies --keep-one-line-blocks and
will not break the one line blocks.
@@ -1898,9 +1965,7 @@
- --remove-braces / -xj
- --remove-brackets is depreciated
-
+ --remove-braces / -xj
Remove braces from conditional statements (e.g. 'if', 'for', 'while'...).
The statement must be a single statement on a single line. If --add-braces or --add-one-line-braces is also
used the result will be to add braces. Braces will not be removed from "One True Brace Style",
@@ -1918,6 +1983,39 @@
+
+ --break-return-type / -xB
+ --break-return-type-decl / -xD
+ Break the return type from the function name. The two options are for the function definitions (-xB), and the
+ function declarations or signatures (-xD). If used with --attach-return-type, the result will be to break the
+ return type. This option has no effect on Objective-C functions.
+
+
void Foo(bool isFoo);
+
+ becomes:
+
void
+Foo(bool isFoo);
+
+
+
+
+ --attach-return-type / -xf
+ --attach-return-type-decl / -xh
+ Attach the return type to the function name. The two options are for the function definitions (-xf), and the
+ function declarations or signatures (-xh). They are intended to undo the --break-return-type options. If used
+ with --break-return-type, the result will be to break the return type. This option has no effect on
+ Objective-C functions.
+
+
void
+Foo(bool isFoo);
+
+ becomes:
+
void Foo(bool isFoo);
+
+
+
+
+
--keep-one-line-blocks / -O
@@ -1992,8 +2090,8 @@
--break-after-logical / -xL
The option max‑code‑length will break a line if the code exceeds #
- characters. The valid values are 50 thru 200. Lines without logical conditionals will break on a logical conditional
- (||, &&, ...), comma, paren, semicolon, or space.
+ characters. The valid values are 50 thru 200. Lines without logical conditionals
+ will break on a logical conditional (||, &&, ...), comma, paren, semicolon, or space.
Some code will not be broken, such as comments, quotes, and arrays. If used with keep‑one‑line‑blocks
or add-one-line-braces the blocks will NOT be broken. If used with keep‑one‑line‑statements
@@ -2001,9 +2099,9 @@
break point within the max code length, the line will be broken at the first available break point after the max
code length.
- By default logical conditionals will be placed first in the new line. The option break‑after‑logical
- will cause the logical conditionals to be placed last on the previous line. This option has no effect without
- max‑code‑length.
+ By default logical conditionals will be placed first in the new line. The option
+ break‑after‑logical will cause the logical conditionals to be placed last on the
+ previous line. This option has no effect without max‑code‑length.
- These options are effective for Objective‑C files only. The paren padding options will still apply to the
- Objective-C method prefix and return type unless overridden by the following options.
+ These options are effective for Objective‑C files only. The standard paren padding options will still apply
+ to the Objective-C method prefix and return type unless overridden by the following options.
Because of the longer indents sometimes needed for Objective‑C, the option "max-continuation-indent" may
- need to be increased. If you are not getting the paren and square bracket alignment you want try increasing
+ need to be increased. If you are not getting the paren and square bracket alignment you want, try increasing
this value. The option is described in the "Indentation Options" section.
--pad-method-prefix / -xQ
@@ -2105,9 +2203,9 @@
--pad-param-type / -xS
- Insert space padding around the Objective‑C parameter type. This will add exactly one space. Any additional
- spaces will be deleted. This has precedence over the pad method colon option and will always cause space padding
- after the method colon.
+ Insert space padding around an Objective‑C parameter type. This will add exactly
+ one space. Any additional spaces will be deleted. This has precedence over the pad method colon option and
+ will always cause space padding after a method colon.
--unpad-param-type / -xs
- Remove all space padding around the Objective‑C parameter type. This option takes precedence over the pad
- paren outside option. The pad method colon option has precedence over the opening paren. The
- closing paren will always be unpadded.
+ Remove all space padding around an Objective‑C parameter type. This option takes precedence over the
+ pad paren outside option. The pad method colon option has precedence over the opening paren.
+ The closing paren will always be unpadded.
- These are non-formatting options available for the command-line. They can also be included in an options
+ These are non-formatting options available for the command-line. They can also be included in an option
file.
@@ -2234,11 +2332,11 @@
Excludes are matched from the end of the file path. 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.
+ proceed backward 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
+ contained in a "python" subdirectory. You may proceed backward in the directory tree to exclude only the
required files.
Wildcards are NOT allowed. There may be more than one exclude statement. The file path and name may be placed
@@ -2267,7 +2365,8 @@
file.
--verbose / -v
- Verbose display mode. Display optional information, such as release number, date, and statistical data.
+ Verbose display mode. Display optional information, such as release number, date,
+ option file locations, and statistical data.
--formatted / -Q
Formatted files display mode. Display only the files that have been formatted. Do not display files that
@@ -2281,8 +2380,8 @@
--lineend=macold / -z3
Force use of the specified line end style. Valid options are windows (CRLF), linux (LF), and macold (CR). MacOld
- style is the format for Mac OS 9 and earlier. OS X uses the Linux style. If one of these options
- is not used, the line ends will be determined automatically from the input file.
+ style is the format for Mac OS 9 and earlier. MacOS and OS X uses the Linux style. If one of
+ these options is not used, the line ends will be determined automatically from the input file.
When redirection is used on Windows the output will always have Windows line ends. This option
will be ignored.
@@ -2295,13 +2394,33 @@
Command Line Only
These options are available for the command-line only. They are NOT available in an options file.
-
+
+
--options=####
- Specify an options file #### to read and use. It must contain a file path for the file. This will allow the file
- name to be changed from astylerc or .astylerc.
-
--options=none
- Disable the default options file. Only the command-line parameters will be used.
+ Specify an options file #### to read and use. It must contain a file path and a file name. This will allow
+ the file name to be changed from astylerc or .astylerc.
+
+ The "none" option will disable the default options file if one exists. Only command-line parameters will be used.
+
+
+ Further information is available in the Option Files section.
+
+ --project
+ --project=####
+ --project=none
+ Specify a project option file to use. The option file
+ should have the default name of .astylerc or _astylerc and should be in the top directory of the project
+ being formatted.
+
+ Specify a project options file #### to use. It must contain a file name only without a directory path.
+ This will allow the project file name to be changed from .astylerc or _astylerc. It should be in the top directory
+ of the project being formatted.
+
+ The "none" option will disable a project options file if one exists. In this case, the project option file will
+ not be used.
+
+ Further information is available in the Option Files section.
--ascii / -I
The displayed output will be ASCII characters only. The text will be displayed in English and numbers will not
@@ -2316,8 +2435,7 @@
options.
--html / -!
- Open the HTML help
- file "astyle.html" in the default browser and quit. The short option must be by itself, it
+ Open the HTML help file "astyle.html" in the default browser and quit. The short option must be by itself, it
cannot be concatenated with other options. The documentation must be installed in the standard install path (/usr/share/doc/astyle/html
for Linux or %PROGRAMFILES%\AStyle\doc for Windows). If installed to a different path use html=###.
@@ -2325,7 +2443,7 @@
Open an HTML help file in the default browser using the file path #### and quit. An HTML file other than "astyle.help"
may be specified. The path may include a directory path and a file name, or a file name only (e.g. html=install.html).
If only a file name is used, it is assumed to be in the standard install path (/usr/share/doc/astyle/html
- for Linux or %PROGRAMFILES%\AStyle\doc for Windows). In both cases the file name must include the html extension.
+ for Linux or %PROGRAMFILES%\AStyle\doc for Windows). In both cases, the file name must include the html extension.
File paths containing spaces must be enclosed in quotes.
On Linux the HTML file is opened using the script "xdg-open" from the install package "xdg-utils". This should
@@ -2333,6 +2451,14 @@
Any HTML file can be opened by this option. The files you are likely to need are astyle.html (the default), install.html,
and index.html.
+
+ --stdin=####
+ Open a file using the file path #### as input to single file formatting. This is a replacement for redirection.
+ Do not use this with "<" redirection.
+
+ --stdout=####
+ Open a file using the file path #### as output from single file formatting. This is a replacement for redirection.
+ Do not use this with ">" redirection.
diff -Nru codeblocks-16.01+p~launchpadrev9384~ubuntu17.04.1/src/plugins/astyle/astyle/astyle_main.cpp codeblocks-16.01+p~launchpadrev9388~ubuntu17.04.1/src/plugins/astyle/astyle/astyle_main.cpp
--- codeblocks-16.01+p~launchpadrev9384~ubuntu17.04.1/src/plugins/astyle/astyle/astyle_main.cpp 2018-01-12 02:21:57.000000000 +0000
+++ codeblocks-16.01+p~launchpadrev9388~ubuntu17.04.1/src/plugins/astyle/astyle/astyle_main.cpp 2018-01-15 20:56:41.000000000 +0000
@@ -1,5 +1,5 @@
// astyle_main.cpp
-// Copyright (c) 2017 by Jim Pattee .
+// Copyright (c) 2018 by Jim Pattee .
// This code is licensed under the MIT License.
// License.md describes the conditions under which this software may be distributed.
@@ -94,11 +94,12 @@
jmethodID g_mid;
#endif
-const char* g_version = "3.0";
+const char* g_version = "3.1";
//-----------------------------------------------------------------------------
// ASStreamIterator class
-// typename will be istringstream for GUI and istream otherwise
+// typename will be stringstream for AStyle
+// it could be istream or wxChar for plug-ins
//-----------------------------------------------------------------------------
template
@@ -206,6 +207,16 @@
inStream->clear();
}
+ // has not detected an input end of line
+ if (!eolWindows && !eolLinux && !eolMacOld)
+ {
+#ifdef _WIN32
+ eolWindows++;
+#else
+ eolLinux++;
+#endif
+ }
+
// set output end of line characters
if (eolWindows >= eolLinux)
{
@@ -334,7 +345,6 @@
isFormattedOnly = false;
ignoreExcludeErrors = false;
ignoreExcludeErrorsDisplay = false;
- optionsFileRequired = false;
useAscii = false;
// other variables
bypassBrowserOpen = false;
@@ -357,7 +367,7 @@
assert(lineEnd == LINEEND_WINDOWS || lineEnd == LINEEND_LINUX || lineEnd == LINEEND_MACOLD);
const string& inStr = out.str(); // avoids strange looking syntax
string outStr; // the converted output
- int inLength = (int)inStr.length();
+ int inLength = (int) inStr.length();
for (int pos = 0; pos < inLength; pos++)
{
if (inStr[pos] == '\r')
@@ -454,7 +464,9 @@
{
FileEncoding encoding = ENCODING_8BIT;
- if (dataSize >= 4 && memcmp(data, "\x00\x00\xFE\xFF", 4) == 0)
+ if (dataSize >= 3 && memcmp(data, "\xEF\xBB\xBF", 3) == 0)
+ encoding = UTF_8BOM;
+ else if (dataSize >= 4 && memcmp(data, "\x00\x00\xFE\xFF", 4) == 0)
encoding = UTF_32BE;
else if (dataSize >= 4 && memcmp(data, "\xFF\xFE\x00\x00", 4) == 0)
encoding = UTF_32LE;
@@ -469,7 +481,7 @@
// error exit without a message
void ASConsole::error() const
{
- (*errorStream) << _("\nArtistic Style has terminated") << endl;
+ (*errorStream) << _("Artistic Style has terminated\n") << endl;
exit(EXIT_FAILURE);
}
@@ -483,7 +495,7 @@
/**
* If no files have been given, use cin for input and cout for output.
*
- * This is used to format text for text editors like TextWrangler (Mac).
+ * This is used to format text for text editors.
* Do NOT display any console messages when this function is used.
*/
void ASConsole::formatCinToCout()
@@ -650,16 +662,47 @@
assert(formatter.getChecksumDiff() == 0);
}
-// build a vector of argv options
-// the program path argv[0] is excluded
-vector ASConsole::getArgvOptions(int argc, char** argv) const
+/**
+ * Searches for a file named fileName_ in the current directory. If it is not
+ * found, recursively searches for fileName_ in the current directory's parent
+ * directories, returning the location of the first instance of fileName_
+ * found. If fileName_ is not found, an empty string is returned.
+ *
+ * @param fileName_ The filename the function should attempt to locate.
+ * @return The full path to fileName_ in the current directory or
+ * nearest parent directory if found, otherwise an empty
+ * string.
+ */
+string ASConsole::findProjectOptionFilePath(const string& fileName_) const
{
- vector argvOptions;
- for (int i = 1; i < argc; i++)
+ string parent;
+
+ if (!fileNameVector.empty())
+ parent = getFullPathName(fileNameVector.front());
+ else if (!stdPathIn.empty())
+ parent = getFullPathName(stdPathIn);
+ else
+ parent = getFullPathName(getCurrentDirectory(fileName_));
+
+ // remove filename from path
+ size_t endPath = parent.find_last_of(g_fileSeparator);
+ if (endPath != string::npos)
+ parent = parent.substr(0, endPath + 1);
+
+ while (!parent.empty())
{
- argvOptions.emplace_back(string(argv[i]));
+ string filepath = parent + fileName_;
+ if (fileExists(filepath.c_str()))
+ return filepath;
+ else if (fileName_ == ".astylerc")
+ {
+ filepath = parent + "_astylerc";
+ if (fileExists(filepath.c_str()))
+ return filepath;
+ }
+ parent = getParentDirectory(parent);
}
- return argvOptions;
+ return string();
}
// for unit testing
@@ -731,8 +774,8 @@
{ return noBackup; }
// for unit testing
-string ASConsole::getOptionsFileName() const
-{ return optionsFileName; }
+string ASConsole::getOptionFileName() const
+{ return optionFileName; }
// for unit testing
vector ASConsole::getOptionsVector() const
@@ -747,6 +790,21 @@
{ return preserveDate; }
// for unit testing
+string ASConsole::getProjectOptionFileName() const
+{
+ assert(projectOptionFileName.length() > 0);
+ // remove the directory path
+ size_t start = projectOptionFileName.find_last_of(g_fileSeparator);
+ if (start == string::npos)
+ start = 0;
+ return projectOptionFileName.substr(start + 1);
+}
+
+// for unit testing
+vector ASConsole::getProjectOptionsVector() const
+{ return projectOptionsVector; }
+
+// for unit testing
string ASConsole::getStdPathIn() const
{ return stdPathIn; }
@@ -769,11 +827,54 @@
errorStream = errStreamPtr;
}
+// build a vector of argv options
+// the program path argv[0] is excluded
+vector ASConsole::getArgvOptions(int argc, char** argv) const
+{
+ vector argvOptions;
+ for (int i = 1; i < argc; i++)
+ {
+ argvOptions.emplace_back(string(argv[i]));
+ }
+ return argvOptions;
+}
+
string ASConsole::getParam(const string& arg, const char* op)
{
return arg.substr(strlen(op));
}
+void ASConsole::getTargetFilenames(string& targetFilename_,
+ vector& targetFilenameVector) const
+{
+ size_t beg = 0;
+ size_t sep = 0;
+ while (beg < targetFilename_.length())
+ {
+ // find next target
+ sep = targetFilename_.find_first_of(",;", beg);
+ if (sep == string::npos)
+ sep = targetFilename_.length();
+ string fileExtension = targetFilename_.substr(beg, sep - beg);
+ beg = sep + 1;
+ // remove whitespace
+ while (fileExtension.length() > 0
+ && (fileExtension[0] == ' ' || fileExtension[0] == '\t'))
+ fileExtension = fileExtension.erase(0, 1);
+ while (fileExtension.length() > 0
+ && (fileExtension[fileExtension.length() - 1] == ' '
+ || fileExtension[fileExtension.length() - 1] == '\t'))
+ fileExtension = fileExtension.erase(fileExtension.length() - 1, 1);
+ if (fileExtension.length() > 0)
+ targetFilenameVector.emplace_back(fileExtension);
+ }
+ if (targetFilenameVector.size() == 0)
+ {
+ fprintf(stderr, _("Missing filename in %s\n"), targetFilename_.c_str());
+ error();
+ }
+}
+
// initialize output end of line
void ASConsole::initializeOutputEOL(LineEndFormat lineEndFormat)
{
@@ -796,18 +897,19 @@
outputEOL.clear();
}
+// read a file into the stringstream 'in'
FileEncoding ASConsole::readFile(const string& fileName_, stringstream& in) const
{
const int blockSize = 65536; // 64 KB
ifstream fin(fileName_.c_str(), ios::binary);
if (!fin)
- error("Cannot open input file", fileName_.c_str());
+ error("Cannot open file", fileName_.c_str());
char* data = new (nothrow) char[blockSize];
if (data == nullptr)
- error("Cannot allocate memory for input file", fileName_.c_str());
+ error("Cannot allocate memory to open file", fileName_.c_str());
fin.read(data, blockSize);
if (fin.bad())
- error("Cannot read input file", fileName_.c_str());
+ error("Cannot read file", fileName_.c_str());
size_t dataSize = static_cast(fin.gcount());
FileEncoding encoding = detectEncoding(data, dataSize);
if (encoding == UTF_32BE || encoding == UTF_32LE)
@@ -819,12 +921,12 @@
if (encoding == UTF_16LE || encoding == UTF_16BE)
{
// convert utf-16 to utf-8
- size_t utf8Size = utf8_16.utf8LengthFromUtf16(data, dataSize, isBigEndian);
+ size_t utf8Size = encode.utf8LengthFromUtf16(data, dataSize, isBigEndian);
char* utf8Out = new (nothrow) char[utf8Size];
if (utf8Out == nullptr)
error("Cannot allocate memory for utf-8 conversion", fileName_.c_str());
- size_t utf8Len = utf8_16.utf16ToUtf8(data, dataSize, isBigEndian, firstBlock, utf8Out);
- assert(utf8Len == utf8Size);
+ size_t utf8Len = encode.utf16ToUtf8(data, dataSize, isBigEndian, firstBlock, utf8Out);
+ assert(utf8Len <= utf8Size);
in << string(utf8Out, utf8Len);
delete[] utf8Out;
}
@@ -832,7 +934,7 @@
in << string(data, dataSize);
fin.read(data, blockSize);
if (fin.bad())
- error("Cannot read input file", fileName_.c_str());
+ error("Cannot read file", fileName_.c_str());
dataSize = static_cast(fin.gcount());
firstBlock = false;
}
@@ -865,8 +967,8 @@
void ASConsole::setNoBackup(bool state)
{ noBackup = state; }
-void ASConsole::setOptionsFileName(const string& name)
-{ optionsFileName = name; }
+void ASConsole::setOptionFileName(const string& name)
+{ optionFileName = name; }
void ASConsole::setOrigSuffix(const string& suffix)
{ origSuffix = suffix; }
@@ -874,6 +976,9 @@
void ASConsole::setPreserveDate(bool state)
{ preserveDate = state; }
+void ASConsole::setProjectOptionFileName(const string& optfilepath)
+{ projectOptionFileName = optfilepath; }
+
void ASConsole::setStdPathIn(const string& path)
{ stdPathIn = path; }
@@ -947,9 +1052,9 @@
* The fileName vector is filled with the path and names of files to process.
*
* @param directory The path of the directory to be processed.
- * @param wildcard The wildcard to be processed (e.g. *.cpp).
+ * @param wildcards A vector of wildcards to be processed (e.g. *.cpp).
*/
-void ASConsole::getFileNames(const string& directory, const string& wildcard)
+void ASConsole::getFileNames(const string& directory, const vector& wildcards)
{
vector subDirectory; // sub directories of directory
WIN32_FIND_DATA findFileData; // for FindFirstFile and FindNextFile
@@ -991,17 +1096,20 @@
continue;
}
- // save the file name
string filePathName = directory + g_fileSeparator + findFileData.cFileName;
// check exclude before wildcmp to avoid "unmatched exclude" error
bool isExcluded = isPathExclued(filePathName);
// save file name if wildcard match
- if (wildcmp(wildcard.c_str(), findFileData.cFileName))
+ for (size_t i = 0; i < wildcards.size(); i++)
{
- if (isExcluded)
- printMsg(_("Exclude %s\n"), filePathName.substr(mainDirectoryLength));
- else
- fileName.emplace_back(filePathName);
+ if (wildcmp(wildcards[i].c_str(), findFileData.cFileName))
+ {
+ if (isExcluded)
+ printMsg(_("Exclude %s\n"), filePathName.substr(mainDirectoryLength));
+ else
+ fileName.emplace_back(filePathName);
+ break;
+ }
}
}
while (FindNextFile(hFind, &findFileData) != 0);
@@ -1015,11 +1123,20 @@
// recurse into sub directories
// if not doing recursive subDirectory is empty
for (unsigned i = 0; i < subDirectory.size(); i++)
- getFileNames(subDirectory[i], wildcard);
+ getFileNames(subDirectory[i], wildcards);
return;
}
+// WINDOWS function to get the full path name from the relative path name
+// Return the full path name or an empty string if failed.
+string ASConsole::getFullPathName(const string& relativePath) const
+{
+ char fullPath[MAX_PATH];
+ GetFullPathName(relativePath.c_str(), MAX_PATH, fullPath, NULL);
+ return fullPath;
+}
+
/**
* WINDOWS function to format a number according to the current locale.
* This formats positive integers only, no float.
@@ -1070,6 +1187,28 @@
}
/**
+ * WINDOWS function to check for a HOME directory
+ *
+ * @param absPath The path to be evaluated.
+ * @returns true if absPath is HOME or is an invalid absolute
+ * path, false otherwise.
+ */
+bool ASConsole::isHomeOrInvalidAbsPath(const string& absPath) const
+{
+ char* env = getenv("USERPROFILE");
+ if (env == nullptr)
+ return true;
+
+ if (absPath.c_str() == env)
+ return true;
+
+ if (absPath.compare(0, strlen(env), env) != 0)
+ return true;
+
+ return false;
+}
+
+/**
* WINDOWS function to open a HTML file in the default browser.
*/
void ASConsole::launchDefaultBrowser(const char* filePathIn /*nullptr*/) const
@@ -1150,9 +1289,9 @@
* The fileName vector is filled with the path and names of files to process.
*
* @param directory The path of the directory to be processed.
- * @param wildcard The wildcard to be processed (e.g. *.cpp).
+ * @param wildcards A vector of wildcards to be processed (e.g. *.cpp).
*/
-void ASConsole::getFileNames(const string& directory, const string& wildcard)
+void ASConsole::getFileNames(const string& directory, const vector& wildcards)
{
struct dirent* entry; // entry from readdir()
struct stat statbuf; // entry from stat()
@@ -1202,12 +1341,16 @@
// check exclude before wildcmp to avoid "unmatched exclude" error
bool isExcluded = isPathExclued(entryFilepath);
// save file name if wildcard match
- if (wildcmp(wildcard.c_str(), entry->d_name) != 0)
+ for (string wildcard : wildcards)
{
- if (isExcluded)
- printMsg(_("Exclude %s\n"), entryFilepath.substr(mainDirectoryLength));
- else
- fileName.emplace_back(entryFilepath);
+ if (wildcmp(wildcard.c_str(), entry->d_name) != 0)
+ {
+ if (isExcluded)
+ printMsg(_("Exclude %s\n"), entryFilepath.substr(mainDirectoryLength));
+ else
+ fileName.emplace_back(entryFilepath);
+ break;
+ }
}
}
}
@@ -1228,10 +1371,23 @@
sort(subDirectory.begin(), subDirectory.end());
for (unsigned i = 0; i < subDirectory.size(); i++)
{
- getFileNames(subDirectory[i], wildcard);
+ getFileNames(subDirectory[i], wildcards);
}
}
+// LINUX function to get the full path name from the relative path name
+// Return the full path name or an empty string if failed.
+string ASConsole::getFullPathName(const string& relativePath) const
+{
+ // ignore realPath attribute warning
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-result"
+ char fullPath[PATH_MAX];
+ realpath(relativePath.c_str(), fullPath);
+ return fullPath;
+#pragma GCC diagnostic pop
+}
+
/**
* LINUX function to get locale information and call getNumberFormat.
* This formats positive integers only, no float.
@@ -1306,6 +1462,28 @@
}
/**
+ * LINUX function to check for a HOME directory
+ *
+ * @param absPath The path to be evaluated.
+ * @returns true if absPath is HOME or is an invalid absolute
+ * path, false otherwise.
+ */
+bool ASConsole::isHomeOrInvalidAbsPath(const string& absPath) const
+{
+ char* env = getenv("HOME");
+ if (env == nullptr)
+ return true;
+
+ if (absPath.c_str() == env)
+ return true;
+
+ if (absPath.compare(0, strlen(env), env) != 0)
+ return true;
+
+ return false;
+}
+
+/**
* LINUX function to open a HTML file in the default browser.
* Use xdg-open from freedesktop.org cross-desktop compatibility suite xdg-utils.
* see http://portland.freedesktop.org/wiki/
@@ -1378,12 +1556,41 @@
#endif // _WIN32
+/**
+ * Returns the parent directory of absPath. If absPath is not a valid absolute
+ * path or if it does not have a parent, an empty string is returned.
+ *
+ * @param absPath The initial directory.
+ * @return The parent directory of absPath, or an empty string if
+ * one cannot be found.
+ */
+string ASConsole::getParentDirectory(const string& absPath) const
+{
+ if (isHomeOrInvalidAbsPath(absPath))
+ {
+ return string();
+ }
+ size_t offset = absPath.size() - 1;
+ if (absPath[absPath.size() - 1] == g_fileSeparator)
+ {
+ offset -= 1;
+ }
+ size_t idx = absPath.rfind(g_fileSeparator, offset);
+ if (idx == string::npos)
+ {
+ return string();
+ }
+ string str = absPath.substr(0, idx + 1);
+ return str;
+}
+
// get individual file names from the command-line file path
void ASConsole::getFilePaths(const string& filePath)
{
fileName.clear();
targetDirectory = string();
targetFilename = string();
+ vector targetFilenameVector;
// separate directory and file name
size_t separator = filePath.find_last_of(g_fileSeparator);
@@ -1412,11 +1619,6 @@
if (targetFilename.find_first_of("*?") != string::npos)
hasWildcard = true;
- // clear exclude hits vector
- size_t excludeHitsVectorSize = excludeHitsVector.size();
- for (size_t ix = 0; ix < excludeHitsVectorSize; ix++)
- excludeHitsVector[ix] = false;
-
// If the filename is not quoted on Linux, bash will replace the
// wildcard instead of passing it to the program.
if (isRecursive && !hasWildcard)
@@ -1428,6 +1630,10 @@
error();
}
+ bool hasMultipleTargets = false;
+ if (targetFilename.find_first_of(",;") != string::npos)
+ hasMultipleTargets = true;
+
// display directory name for wildcard processing
if (hasWildcard)
{
@@ -1435,9 +1641,17 @@
printMsg(_("Directory %s\n"), targetDirectory + g_fileSeparator + targetFilename);
}
+ // clear exclude hits vector
+ size_t excludeHitsVectorSize = excludeHitsVector.size();
+ for (size_t ix = 0; ix < excludeHitsVectorSize; ix++)
+ excludeHitsVector[ix] = false;
+
// create a vector of paths and file names to process
- if (hasWildcard || isRecursive)
- getFileNames(targetDirectory, targetFilename);
+ if (hasWildcard || isRecursive || hasMultipleTargets)
+ {
+ getTargetFilenames(targetFilename, targetFilenameVector);
+ getFileNames(targetDirectory, targetFilenameVector);
+ }
else
{
// verify a single file is not a directory (needed on Linux)
@@ -1489,6 +1703,13 @@
printSeparatingLine();
}
+// Check if a file exists
+bool ASConsole::fileExists(const char* file) const
+{
+ struct stat buf;
+ return (stat(file, &buf) == 0);
+}
+
bool ASConsole::fileNameVectorIsEmpty() const
{
return fileNameVector.empty();
@@ -1509,7 +1730,7 @@
bool retVal = arg.compare(0, strlen(option), option) == 0;
// if comparing for short option, 2nd char of arg must be numeric
if (retVal && strlen(option) == 1 && arg.length() > 1)
- if (!isdigit((unsigned char)arg[1]))
+ if (!isdigit((unsigned char) arg[1]))
retVal = false;
return retVal;
}
@@ -1544,9 +1765,9 @@
{
// make it case insensitive for Windows
for (size_t j = 0; j < compare.length(); j++)
- compare[j] = (char)tolower(compare[j]);
+ compare[j] = (char) tolower(compare[j]);
for (size_t j = 0; j < exclude.length(); j++)
- exclude[j] = (char)tolower(exclude[j]);
+ exclude[j] = (char) tolower(exclude[j]);
}
// compare sub directory to exclude data - must check them all
if (compare == exclude)
@@ -1578,6 +1799,7 @@
cout << endl;
cout << " Wildcards (* and ?) may be used in the filename.\n";
cout << " A \'recursive\' option can process directories recursively.\n";
+ cout << " Multiple file extensions may be separated by a comma.\n";
cout << endl;
cout << " By default, astyle is set up to indent with four spaces per indent,\n";
cout << " a maximal indentation of 40 spaces inside continuous statements,\n";
@@ -1591,20 +1813,24 @@
cout << " Short options (starting with '-') may be appended together.\n";
cout << " Thus, -bps4 is the same as -b -p -s4.\n";
cout << endl;
- cout << "Options File:\n";
+ cout << "Option Files:\n";
cout << "-------------\n";
- cout << " Artistic Style looks for a default options file in the\n";
- cout << " following order:\n";
- cout << " 1. The contents of the ARTISTIC_STYLE_OPTIONS environment\n";
- cout << " variable if it exists.\n";
- cout << " 2. The file called .astylerc in the directory pointed to by the\n";
- cout << " HOME environment variable ( i.e. $HOME/.astylerc ).\n";
- cout << " 3. The file called astylerc in the directory pointed to by the\n";
- cout << " USERPROFILE environment variable (i.e. %USERPROFILE%\\astylerc).\n";
- cout << " If a default options file is found, the options in this file will\n";
- cout << " be parsed BEFORE the command-line options.\n";
- cout << " Long options within the default option file may be written without\n";
- cout << " the preliminary '--'.\n";
+ cout << " Artistic Style looks for a default option file and/or a project\n";
+ cout << " option file in the following order:\n";
+ cout << " 1. The command line options have precedence.\n";
+ cout << " 2. The project option file has precedence over the default file\n";
+ cout << " o the file name indicated by the --project= command line option.\n";
+ cout << " o the file named .astylerc or _ astylerc.\n";
+ cout << " o the file name identified by ARTISTIC_STYLE_PROJECT_OPTIONS.\n";
+ cout << " o the file is disabled by --project=none on the command line.\n";
+ cout << " 3. The default option file that can be used for all projects.\n";
+ cout << " o the file path indicated by the --options= command line option.\n";
+ cout << " o the file path indicated by ARTISTIC_STYLE_OPTIONS.\n";
+ cout << " o the file named .astylerc in the HOME directory (for Linux).\n";
+ cout << " o the file name astylerc in the APPDATA directory (for Windows).\n";
+ cout << " o the file is disabled by --project=none on the command line.\n";
+ cout << " Long options within the option files may be written without '--'.\n";
+ cout << " Line-end comments begin with a '#'.\n";
cout << endl;
cout << "Disable Formatting:\n";
cout << "-------------------\n";
@@ -1647,8 +1873,8 @@
cout << " VTK style formatting/indenting.\n";
cout << " Broken, indented braces except for the opening braces.\n";
cout << endl;
- cout << " --style=banner OR -A6\n";
- cout << " Banner style formatting/indenting.\n";
+ cout << " --style=ratliff OR --style=banner OR -A6\n";
+ cout << " Ratliff style formatting/indenting.\n";
cout << " Attached, indented braces.\n";
cout << endl;
cout << " --style=gnu OR -A7\n";
@@ -1876,6 +2102,16 @@
cout << " --remove-braces OR -xj\n";
cout << " Remove braces from a braced one line conditional statements.\n";
cout << endl;
+ cout << " --break-return-type OR -xB\n";
+ cout << " --break-return-type-decl OR -xD\n";
+ cout << " Break the return type from the function name. Options are\n";
+ cout << " for the function definitions and the function declarations.\n";
+ cout << endl;
+ cout << " --attach-return-type OR -xf\n";
+ cout << " --attach-return-type-decl OR -xh\n";
+ cout << " Attach the return type to the function name. Options are\n";
+ cout << " for the function definitions and the function declarations.\n";
+ cout << endl;
cout << " --keep-one-line-blocks OR -O\n";
cout << " Don't break blocks residing completely on one line.\n";
cout << endl;
@@ -1995,11 +2231,19 @@
cout << "Command Line Only:\n";
cout << "------------------\n";
cout << " --options=####\n";
- cout << " Specify an options file #### to read and use.\n";
- cout << endl;
cout << " --options=none\n";
- cout << " Disable the default options file.\n";
- cout << " Only the command-line parameters will be used.\n";
+ cout << " Specify a default option file #### to read and use.\n";
+ cout << " It must contain a file path and a file name.\n";
+ cout << " 'none' disables the default option file.\n";
+ cout << endl;
+ cout << " --project\n";
+ cout << " --project=####\n";
+ cout << " --project=none\n";
+ cout << " Specify a project option file #### to read and use.\n";
+ cout << " It must contain a file name only, without a directory path.\n";
+ cout << " The file should be included in the project top-level directory.\n";
+ cout << " The default file name is .astylerc or _astylerc.\n";
+ cout << " 'none' disables the project or environment variable file.\n";
cout << endl;
cout << " --ascii OR -I\n";
cout << " The displayed output will be ascii characters only.\n";
@@ -2019,6 +2263,14 @@
cout << " ####. The path may include a directory path and a file name, or a\n";
cout << " file name only. Paths containing spaces must be enclosed in quotes.\n";
cout << endl;
+ cout << " --stdin=####\n";
+ cout << " Use the file path #### as input to single file formatting.\n";
+ cout << " This is a replacement for redirection.\n";
+ cout << endl;
+ cout << " --stdout=####\n";
+ cout << " Use the file path #### as output from single file formatting.\n";
+ cout << " This is a replacement for redirection.\n";
+ cout << endl;
cout << endl;
}
@@ -2047,62 +2299,102 @@
printVerboseStats(startTime);
}
-// process options from the command line and options file
-// build the vectors fileNameVector, excludeVector, optionsVector, and fileOptionsVector
+// process options from the command line and option files
+// build the vectors fileNameVector, excludeVector, optionsVector,
+// projectOptionsVector and fileOptionsVector
void ASConsole::processOptions(const vector& argvOptions)
{
string arg;
bool ok = true;
- bool shouldParseOptionsFile = true;
+ bool optionFileRequired = false;
+ bool shouldParseOptionFile = true;
+ bool projectOptionFileRequired = false;
+ bool shouldParseProjectOptionFile = true;
+ string projectOptionArg; // save for display
// get command line options
for (size_t i = 0; i < argvOptions.size(); i++)
{
arg = argvOptions[i];
- if ( isOption(arg, "-I" )
- || isOption(arg, "--ascii") )
+ if (isOption(arg, "-I")
+ || isOption(arg, "--ascii"))
{
useAscii = true;
setlocale(LC_ALL, "C"); // use English decimal indicator
localizer.setLanguageFromName("en");
}
- else if ( isOption(arg, "--options=none") )
+ else if (isOption(arg, "--options=none"))
{
- shouldParseOptionsFile = false;
+ optionFileRequired = false;
+ shouldParseOptionFile = false;
+ optionFileName = "";
}
- else if ( isParamOption(arg, "--options=") )
+ else if (isParamOption(arg, "--options="))
{
- optionsFileName = getParam(arg, "--options=");
- optionsFileRequired = true;
- if (optionsFileName.empty())
- setOptionsFileName(" ");
+ optionFileName = getParam(arg, "--options=");
+ standardizePath(optionFileName);
+ optionFileName = getFullPathName(optionFileName);
+ optionFileRequired = true;
}
- else if ( isOption(arg, "-h")
- || isOption(arg, "--help")
- || isOption(arg, "-?") )
+ else if (isOption(arg, "--project=none"))
+ {
+ projectOptionFileRequired = false;
+ shouldParseProjectOptionFile = false;
+ setProjectOptionFileName("");
+ }
+ else if (isParamOption(arg, "--project="))
+ {
+ projectOptionFileName = getParam(arg, "--project=");
+ standardizePath(projectOptionFileName);
+ projectOptionFileRequired = true;
+ shouldParseProjectOptionFile = false;
+ projectOptionArg = projectOptionFileName;
+ }
+ else if (isOption(arg, "--project"))
+ {
+ projectOptionFileName = ".astylerc";
+ projectOptionFileRequired = true;
+ shouldParseProjectOptionFile = false;
+ projectOptionArg = projectOptionFileName;
+ }
+ else if (isOption(arg, "-h")
+ || isOption(arg, "--help")
+ || isOption(arg, "-?"))
{
printHelp();
exit(EXIT_SUCCESS);
}
- else if ( isOption(arg, "-!")
- || isOption(arg, "--html") )
+ else if (isOption(arg, "-!")
+ || isOption(arg, "--html"))
{
launchDefaultBrowser();
exit(EXIT_SUCCESS);
}
- else if ( isParamOption(arg, "--html=") )
+ else if (isParamOption(arg, "--html="))
{
string htmlFilePath = getParam(arg, "--html=");
launchDefaultBrowser(htmlFilePath.c_str());
exit(EXIT_SUCCESS);
}
- else if ( isOption(arg, "-V" )
- || isOption(arg, "--version") )
+ else if (isOption(arg, "-V")
+ || isOption(arg, "--version"))
{
printf("Artistic Style Version %s\n", g_version);
exit(EXIT_SUCCESS);
}
+ else if (isParamOption(arg, "--stdin="))
+ {
+ string path = getParam(arg, "--stdin=");
+ standardizePath(path);
+ setStdPathIn(path);
+ }
+ else if (isParamOption(arg, "--stdout="))
+ {
+ string path = getParam(arg, "--stdout=");
+ standardizePath(path);
+ setStdPathOut(path);
+ }
else if (arg[0] == '-')
{
optionsVector.emplace_back(arg);
@@ -2114,53 +2406,125 @@
}
}
- // get options file path and name
- if (shouldParseOptionsFile)
+ // get option file path and name
+ if (shouldParseOptionFile)
{
- if (optionsFileName.empty())
+ if (optionFileName.empty())
{
char* env = getenv("ARTISTIC_STYLE_OPTIONS");
if (env != nullptr)
- setOptionsFileName(env);
+ {
+ setOptionFileName(env);
+ standardizePath(optionFileName);
+ optionFileName = getFullPathName(optionFileName);
+ }
}
- if (optionsFileName.empty())
+ // for Linux
+ if (optionFileName.empty())
{
char* env = getenv("HOME");
if (env != nullptr)
- setOptionsFileName(string(env) + "/.astylerc");
+ {
+ string name = string(env) + "/.astylerc";
+ if (fileExists(name.c_str()))
+ setOptionFileName(name);
+ }
+ }
+ // for Windows
+ if (optionFileName.empty())
+ {
+ char* env = getenv("APPDATA");
+ if (env != nullptr)
+ {
+ string name = string(env) + "\\astylerc";
+ if (fileExists(name.c_str()))
+ setOptionFileName(name);
+ }
}
- if (optionsFileName.empty())
+ // for Windows
+ // NOTE: depreciated with release 3.1, remove when appropriate
+ // there is NO test data for this option
+ if (optionFileName.empty())
{
char* env = getenv("USERPROFILE");
if (env != nullptr)
- setOptionsFileName(string(env) + "/astylerc");
+ {
+ string name = string(env) + "\\astylerc";
+ if (fileExists(name.c_str()))
+ setOptionFileName(name);
+ }
}
- if (!optionsFileName.empty())
- standardizePath(optionsFileName);
}
- // create the options file vector and parse the options for errors
- ASOptions options(formatter, *this);
- if (!optionsFileName.empty())
+ // find project option file
+ if (projectOptionFileRequired)
{
- ifstream optionsIn(optionsFileName.c_str());
- if (optionsIn)
- {
- options.importOptions(optionsIn, fileOptionsVector);
- ok = options.parseOptions(fileOptionsVector,
- string(_("Invalid option file options:")));
- }
- else
- {
- if (optionsFileRequired)
- error(_("Cannot open options file"), optionsFileName.c_str());
- optionsFileName.clear();
+ string optfilepath = findProjectOptionFilePath(projectOptionFileName);
+ if (optfilepath.empty() || projectOptionArg.empty())
+ error(_("Cannot open project option file"), projectOptionArg.c_str());
+ standardizePath(optfilepath);
+ setProjectOptionFileName(optfilepath);
+ }
+ if (shouldParseProjectOptionFile)
+ {
+ char* env = getenv("ARTISTIC_STYLE_PROJECT_OPTIONS");
+ if (env != nullptr)
+ {
+ string optfilepath = findProjectOptionFilePath(env);
+ standardizePath(optfilepath);
+ setProjectOptionFileName(optfilepath);
}
- optionsIn.close();
}
+
+ ASOptions options(formatter, *this);
+ if (!optionFileName.empty())
+ {
+ stringstream optionsIn;
+ if (!fileExists(optionFileName.c_str()))
+ error(_("Cannot open default option file"), optionFileName.c_str());
+ FileEncoding encoding = readFile(optionFileName, optionsIn);
+ // bypass a BOM, all BOMs have been converted to utf-8
+ if (encoding == UTF_8BOM || encoding == UTF_16LE || encoding == UTF_16BE)
+ {
+ char buf[4];
+ optionsIn.get(buf, 4);
+ assert(strcmp(buf, "\xEF\xBB\xBF") == 0);
+ }
+ options.importOptions(optionsIn, fileOptionsVector);
+ ok = options.parseOptions(fileOptionsVector,
+ string(_("Invalid default options:")));
+ }
+ else if (optionFileRequired)
+ error(_("Cannot open default option file"), optionFileName.c_str());
+
if (!ok)
{
- (*errorStream) << options.getOptionErrors() << endl;
+ (*errorStream) << options.getOptionErrors();
+ (*errorStream) << _("For help on options type 'astyle -h'") << endl;
+ error();
+ }
+
+ if (!projectOptionFileName.empty())
+ {
+ stringstream projectOptionsIn;
+ if (!fileExists(projectOptionFileName.c_str()))
+ error(_("Cannot open project option file"), projectOptionFileName.c_str());
+ FileEncoding encoding = readFile(projectOptionFileName, projectOptionsIn);
+ // bypass a BOM, all BOMs have been converted to utf-8
+ if (encoding == UTF_8BOM || encoding == UTF_16LE || encoding == UTF_16BE)
+ {
+ char buf[4];
+ projectOptionsIn.get(buf, 4);
+ assert(strcmp(buf, "\xEF\xBB\xBF") == 0);
+ }
+ options.importOptions(projectOptionsIn, projectOptionsVector);
+ ok = options.parseOptions(projectOptionsVector,
+ string(_("Invalid project options:")));
+ }
+
+ if (!ok)
+ {
+ (*errorStream) << options.getOptionErrors();
(*errorStream) << _("For help on options type 'astyle -h'") << endl;
error();
}
@@ -2170,7 +2534,7 @@
string(_("Invalid command line options:")));
if (!ok)
{
- (*errorStream) << options.getOptionErrors() << endl;
+ (*errorStream) << options.getOptionErrors();
(*errorStream) << _("For help on options type 'astyle -h'") << endl;
error();
}
@@ -2227,12 +2591,12 @@
// If we are on a VMS system, translate VMS style filenames to unix
// style.
fab = cc$rms_fab;
- fab.fab$l_fna = (char*) -1; // *NOPAD*
+ fab.fab$l_fna = (char*) -1;
fab.fab$b_fns = 0;
fab.fab$l_naml = &naml;
naml = cc$rms_naml;
strcpy(sess, path.c_str());
- naml.naml$l_long_filename = (char*)sess;
+ naml.naml$l_long_filename = (char*) sess;
naml.naml$l_long_filename_size = path.length();
naml.naml$l_long_expand = less;
naml.naml$l_long_expand_alloc = sizeof(less);
@@ -2248,14 +2612,14 @@
{
if (!$VMS_STATUS_SUCCESS(r0_status))
{
- (void)lib$signal (r0_status);
+ (void) lib$signal(r0_status);
}
}
less[naml.naml$l_long_expand_size - naml.naml$b_ver] = '\0';
sess[naml.naml$b_esl - naml.naml$b_ver] = '\0';
if (naml.naml$l_long_expand_size > naml.naml$b_esl)
{
- path = decc$translate_vms (less);
+ path = decc$translate_vms(less);
}
else
{
@@ -2310,9 +2674,19 @@
header.append(str);
header.append("\n");
printf("%s", header.c_str());
- // print options file
- if (!optionsFileName.empty())
- printf(_("Using default options file %s\n"), optionsFileName.c_str());
+ // print option files
+ if (!optionFileName.empty())
+ printf(_("Default option file %s\n"), optionFileName.c_str());
+ // NOTE: depreciated with release 3.1, remove when appropriate
+ if (!optionFileName.empty())
+ {
+ char* env = getenv("USERPROFILE");
+ if (env != nullptr && optionFileName == string(env) + "\\astylerc")
+ printf("The above option file has been DEPRECIATED\n");
+ }
+ // end depreciated
+ if (!projectOptionFileName.empty())
+ printf(_("Project option file %s\n"), projectOptionFileName.c_str());
}
void ASConsole::printVerboseStats(clock_t startTime) const
@@ -2328,7 +2702,7 @@
// show processing time
clock_t stopTime = clock();
- double secs = (stopTime - startTime) / double (CLOCKS_PER_SEC);
+ double secs = (stopTime - startTime) / double(CLOCKS_PER_SEC);
if (secs < 60)
{
if (secs < 2.0)
@@ -2344,18 +2718,19 @@
// show minutes and seconds if time is greater than one minute
int min = (int) secs / 60;
secs -= min * 60;
- int minsec = int (secs + .5);
+ int minsec = int(secs + .5);
printf(_("%d min %d sec "), min, minsec);
}
string lines = getNumberFormat(linesOut);
printf(_("%s lines\n"), lines.c_str());
+ printf("\n");
}
void ASConsole::sleep(int seconds) const
{
clock_t endwait;
- endwait = clock_t (clock () + seconds * CLOCKS_PER_SEC);
+ endwait = clock_t(clock() + seconds * CLOCKS_PER_SEC);
while (clock() < endwait) {}
}
@@ -2485,11 +2860,11 @@
{
// convert utf-8 to utf-16
bool isBigEndian = (encoding == UTF_16BE);
- size_t utf16Size = utf8_16.utf16LengthFromUtf8(out.str().c_str(), out.str().length());
+ size_t utf16Size = encode.utf16LengthFromUtf8(out.str().c_str(), out.str().length());
char* utf16Out = new char[utf16Size];
- size_t utf16Len = utf8_16.utf8ToUtf16(const_cast(out.str().c_str()),
- out.str().length(), isBigEndian, utf16Out);
- assert(utf16Len == utf16Size);
+ size_t utf16Len = encode.utf8ToUtf16(const_cast(out.str().c_str()),
+ out.str().length(), isBigEndian, utf16Out);
+ assert(utf16Len <= utf16Size);
fout << string(utf16Out, utf16Len);
delete[] utf16Out;
}
@@ -2527,10 +2902,10 @@
// used by shared object (DLL) calls
//-----------------------------------------------------------------------------
-utf16_t* ASLibrary::formatUtf16(const utf16_t* pSourceIn, // the source to be formatted
- const utf16_t* pOptions, // AStyle options
- fpError fpErrorHandler, // error handler function
- fpAlloc fpMemoryAlloc) const // memory allocation function)
+char16_t* ASLibrary::formatUtf16(const char16_t* pSourceIn, // the source to be formatted
+ const char16_t* pOptions, // AStyle options
+ fpError fpErrorHandler, // error handler function
+ fpAlloc fpMemoryAlloc) const // memory allocation function)
{
const char* utf8In = convertUtf16ToUtf8(pSourceIn);
if (utf8In == nullptr)
@@ -2560,7 +2935,7 @@
if (utf8Out == nullptr)
return nullptr;
// convert text to wide char and return it
- utf16_t* utf16Out = convertUtf8ToUtf16(utf8Out, fpMemoryAlloc);
+ char16_t* utf16Out = convertUtf8ToUtf16(utf8Out, fpMemoryAlloc);
delete[] utf8Out;
utf8Out = nullptr;
if (utf16Out == nullptr)
@@ -2584,26 +2959,26 @@
* Memory is allocated by the calling program memory allocation function.
* The calling function must check for errors.
*/
-utf16_t* ASLibrary::convertUtf8ToUtf16(const char* utf8In, fpAlloc fpMemoryAlloc) const
+char16_t* ASLibrary::convertUtf8ToUtf16(const char* utf8In, fpAlloc fpMemoryAlloc) const
{
if (utf8In == nullptr)
return nullptr;
char* data = const_cast(utf8In);
size_t dataSize = strlen(utf8In);
- bool isBigEndian = utf8_16.getBigEndian();
- // return size is in number of CHARs, not utf16_t
- size_t utf16Size = (utf8_16.utf16LengthFromUtf8(data, dataSize) + sizeof(utf16_t));
- char* utf16Out = fpMemoryAlloc((long)utf16Size);
+ bool isBigEndian = encode.getBigEndian();
+ // return size is in number of CHARs, not char16_t
+ size_t utf16Size = (encode.utf16LengthFromUtf8(data, dataSize) + sizeof(char16_t));
+ char* utf16Out = fpMemoryAlloc((long) utf16Size);
if (utf16Out == nullptr)
return nullptr;
#ifdef NDEBUG
- utf8_16.utf8ToUtf16(data, dataSize + 1, isBigEndian, utf16Out);
+ encode.utf8ToUtf16(data, dataSize + 1, isBigEndian, utf16Out);
#else
- size_t utf16Len = utf8_16.utf8ToUtf16(data, dataSize + 1, isBigEndian, utf16Out);
+ size_t utf16Len = encode.utf8ToUtf16(data, dataSize + 1, isBigEndian, utf16Out);
assert(utf16Len == utf16Size);
#endif
- assert(utf16Size == (utf8_16.utf16len(reinterpret_cast(utf16Out)) + 1) * sizeof(utf16_t));
- return reinterpret_cast(utf16Out);
+ assert(utf16Size == (encode.utf16len(reinterpret_cast(utf16Out)) + 1) * sizeof(char16_t));
+ return reinterpret_cast(utf16Out);
}
/**
@@ -2611,22 +2986,22 @@
* The calling function must check for errors and delete the
* allocated memory.
*/
-char* ASLibrary::convertUtf16ToUtf8(const utf16_t* utf16In) const
+char* ASLibrary::convertUtf16ToUtf8(const char16_t* utf16In) const
{
if (utf16In == nullptr)
return nullptr;
- char* data = reinterpret_cast(const_cast(utf16In));
+ char* data = reinterpret_cast(const_cast(utf16In));
// size must be in chars
- size_t dataSize = utf8_16.utf16len(utf16In) * sizeof(utf16_t);
- bool isBigEndian = utf8_16.getBigEndian();
- size_t utf8Size = utf8_16.utf8LengthFromUtf16(data, dataSize, isBigEndian) + 1;
+ size_t dataSize = encode.utf16len(utf16In) * sizeof(char16_t);
+ bool isBigEndian = encode.getBigEndian();
+ size_t utf8Size = encode.utf8LengthFromUtf16(data, dataSize, isBigEndian) + 1;
char* utf8Out = new (nothrow) char[utf8Size];
if (utf8Out == nullptr)
return nullptr;
#ifdef NDEBUG
- utf8_16.utf16ToUtf8(data, dataSize + 1, isBigEndian, true, utf8Out);
+ encode.utf16ToUtf8(data, dataSize + 1, isBigEndian, true, utf8Out);
#else
- size_t utf8Len = utf8_16.utf16ToUtf8(data, dataSize + 1, isBigEndian, true, utf8Out);
+ size_t utf8Len = encode.utf16ToUtf8(data, dataSize + 1, isBigEndian, true, utf8Out);
assert(utf8Len == utf8Size);
#endif
assert(utf8Size == strlen(utf8Out) + 1);
@@ -2652,7 +3027,9 @@
/**
* parse the options vector
- * optionsVector can be either a fileOptionsVector (options file) or an optionsVector (command line)
+ * optionsVector can be either a fileOptionsVector (option file),
+ * a projectOptionsVector (project option file),
+ * or an optionsVector (command line)
*
* @return true if no errors, false if errors
*/
@@ -2675,7 +3052,7 @@
for (i = 1; i < arg.length(); ++i)
{
if (i > 1
- && isalpha((unsigned char)arg[i])
+ && isalpha((unsigned char) arg[i])
&& arg[i - 1] != 'x')
{
// parse the previous option in subArg
@@ -2702,122 +3079,83 @@
void ASOptions::parseOption(const string& arg, const string& errorInfo)
{
- if ( isOption(arg, "style=allman") || isOption(arg, "style=bsd") || isOption(arg, "style=break") )
+ if (isOption(arg, "A1", "style=allman") || isOption(arg, "style=bsd") || isOption(arg, "style=break"))
{
formatter.setFormattingStyle(STYLE_ALLMAN);
}
- else if ( isOption(arg, "style=java") || isOption(arg, "style=attach") )
+ else if (isOption(arg, "A2", "style=java") || isOption(arg, "style=attach"))
{
formatter.setFormattingStyle(STYLE_JAVA);
}
- else if ( isOption(arg, "style=k&r") || isOption(arg, "style=kr") || isOption(arg, "style=k/r") )
+ else if (isOption(arg, "A3", "style=k&r") || isOption(arg, "style=kr") || isOption(arg, "style=k/r"))
{
formatter.setFormattingStyle(STYLE_KR);
}
- else if ( isOption(arg, "style=stroustrup") )
+ else if (isOption(arg, "A4", "style=stroustrup"))
{
formatter.setFormattingStyle(STYLE_STROUSTRUP);
}
- else if ( isOption(arg, "style=whitesmith") )
+ else if (isOption(arg, "A5", "style=whitesmith"))
{
formatter.setFormattingStyle(STYLE_WHITESMITH);
}
- else if ( isOption(arg, "style=vtk") )
+ else if (isOption(arg, "A15", "style=vtk"))
{
formatter.setFormattingStyle(STYLE_VTK);
}
- else if ( isOption(arg, "style=banner") )
+ else if (isOption(arg, "A6", "style=ratliff") || isOption(arg, "style=banner"))
{
- formatter.setFormattingStyle(STYLE_BANNER);
+ formatter.setFormattingStyle(STYLE_RATLIFF);
}
- else if ( isOption(arg, "style=gnu") )
+ else if (isOption(arg, "A7", "style=gnu"))
{
formatter.setFormattingStyle(STYLE_GNU);
}
- else if ( isOption(arg, "style=linux") || isOption(arg, "style=knf") )
+ else if (isOption(arg, "A8", "style=linux") || isOption(arg, "style=knf"))
{
formatter.setFormattingStyle(STYLE_LINUX);
}
- else if ( isOption(arg, "style=horstmann") || isOption(arg, "style=run-in") )
+ else if (isOption(arg, "A9", "style=horstmann") || isOption(arg, "style=run-in"))
{
formatter.setFormattingStyle(STYLE_HORSTMANN);
}
- else if ( isOption(arg, "style=1tbs") || isOption(arg, "style=otbs") )
+ else if (isOption(arg, "A10", "style=1tbs") || isOption(arg, "style=otbs"))
{
formatter.setFormattingStyle(STYLE_1TBS);
}
- else if ( isOption(arg, "style=google") )
+ else if (isOption(arg, "A14", "style=google"))
{
formatter.setFormattingStyle(STYLE_GOOGLE);
}
- else if (isOption(arg, "style=mozilla"))
+ else if (isOption(arg, "A16", "style=mozilla"))
{
formatter.setFormattingStyle(STYLE_MOZILLA);
}
- else if ( isOption(arg, "style=pico") )
+ else if (isOption(arg, "A11", "style=pico"))
{
formatter.setFormattingStyle(STYLE_PICO);
}
- else if ( isOption(arg, "style=lisp") || isOption(arg, "style=python") )
+ else if (isOption(arg, "A12", "style=lisp") || isOption(arg, "style=python"))
{
formatter.setFormattingStyle(STYLE_LISP);
}
- else if ( isParamOption(arg, "A") )
- {
- int style = 0;
- string styleParam = getParam(arg, "A");
- if (styleParam.length() > 0)
- style = atoi(styleParam.c_str());
- if (style == 1)
- formatter.setFormattingStyle(STYLE_ALLMAN);
- else if (style == 2)
- formatter.setFormattingStyle(STYLE_JAVA);
- else if (style == 3)
- formatter.setFormattingStyle(STYLE_KR);
- else if (style == 4)
- formatter.setFormattingStyle(STYLE_STROUSTRUP);
- else if (style == 5)
- formatter.setFormattingStyle(STYLE_WHITESMITH);
- else if (style == 6)
- formatter.setFormattingStyle(STYLE_BANNER);
- else if (style == 7)
- formatter.setFormattingStyle(STYLE_GNU);
- else if (style == 8)
- formatter.setFormattingStyle(STYLE_LINUX);
- else if (style == 9)
- formatter.setFormattingStyle(STYLE_HORSTMANN);
- else if (style == 10)
- formatter.setFormattingStyle(STYLE_1TBS);
- else if (style == 11)
- formatter.setFormattingStyle(STYLE_PICO);
- else if (style == 12)
- formatter.setFormattingStyle(STYLE_LISP);
- else if (style == 14)
- formatter.setFormattingStyle(STYLE_GOOGLE);
- else if (style == 15)
- formatter.setFormattingStyle(STYLE_VTK);
- else if (style == 16)
- formatter.setFormattingStyle(STYLE_MOZILLA);
- else
- isOptionError(arg, errorInfo);
- }
// must check for mode=cs before mode=c !!!
- else if ( isOption(arg, "mode=cs") )
+ else if (isOption(arg, "mode=cs"))
{
formatter.setSharpStyle();
formatter.setModeManuallySet(true);
}
- else if ( isOption(arg, "mode=c") )
+ else if (isOption(arg, "mode=c"))
{
formatter.setCStyle();
formatter.setModeManuallySet(true);
}
- else if ( isOption(arg, "mode=java") )
+ else if (isOption(arg, "mode=java"))
{
formatter.setJavaStyle();
formatter.setModeManuallySet(true);
}
- else if ( isParamOption(arg, "t", "indent=tab=") )
+ else if (isParamOption(arg, "t", "indent=tab="))
{
int spaceNum = 4;
string spaceNumParam = getParam(arg, "t", "indent=tab=");
@@ -2830,11 +3168,11 @@
formatter.setTabIndentation(spaceNum, false);
}
}
- else if ( isOption(arg, "indent=tab") )
+ else if (isOption(arg, "indent=tab"))
{
formatter.setTabIndentation(4);
}
- else if ( isParamOption(arg, "T", "indent=force-tab=") )
+ else if (isParamOption(arg, "T", "indent=force-tab="))
{
int spaceNum = 4;
string spaceNumParam = getParam(arg, "T", "indent=force-tab=");
@@ -2847,11 +3185,11 @@
formatter.setTabIndentation(spaceNum, true);
}
}
- else if ( isOption(arg, "indent=force-tab") )
+ else if (isOption(arg, "indent=force-tab"))
{
formatter.setTabIndentation(4, true);
}
- else if ( isParamOption(arg, "xT", "indent=force-tab-x=") )
+ else if (isParamOption(arg, "xT", "indent=force-tab-x="))
{
int tabNum = 8;
string tabNumParam = getParam(arg, "xT", "indent=force-tab-x=");
@@ -2864,11 +3202,11 @@
formatter.setForceTabXIndentation(tabNum);
}
}
- else if ( isOption(arg, "indent=force-tab-x") )
+ else if (isOption(arg, "indent=force-tab-x"))
{
formatter.setForceTabXIndentation(8);
}
- else if ( isParamOption(arg, "s", "indent=spaces=") )
+ else if (isParamOption(arg, "s", "indent=spaces="))
{
int spaceNum = 4;
string spaceNumParam = getParam(arg, "s", "indent=spaces=");
@@ -2881,7 +3219,7 @@
formatter.setSpaceIndentation(spaceNum);
}
}
- else if ( isOption(arg, "indent=spaces") )
+ else if (isOption(arg, "indent=spaces"))
{
formatter.setSpaceIndentation(4);
}
@@ -2898,7 +3236,7 @@
else
formatter.setContinuationIndentation(contIndent);
}
- else if ( isParamOption(arg, "m", "min-conditional-indent=") )
+ else if (isParamOption(arg, "m", "min-conditional-indent="))
{
int minIndent = MINCOND_TWO;
string minIndentParam = getParam(arg, "m", "min-conditional-indent=");
@@ -2909,7 +3247,7 @@
else
formatter.setMinConditionalIndentOption(minIndent);
}
- else if ( isParamOption(arg, "M", "max-continuation-indent=") )
+ else if (isParamOption(arg, "M", "max-continuation-indent="))
{
int maxIndent = 40;
string maxIndentParam = getParam(arg, "M", "max-continuation-indent=");
@@ -2922,31 +3260,31 @@
else
formatter.setMaxContinuationIndentLength(maxIndent);
}
- else if ( isOption(arg, "N", "indent-namespaces") )
+ else if (isOption(arg, "N", "indent-namespaces"))
{
formatter.setNamespaceIndent(true);
}
- else if ( isOption(arg, "C", "indent-classes") )
+ else if (isOption(arg, "C", "indent-classes"))
{
formatter.setClassIndent(true);
}
- else if ( isOption(arg, "xG", "indent-modifiers") )
+ else if (isOption(arg, "xG", "indent-modifiers"))
{
formatter.setModifierIndent(true);
}
- else if ( isOption(arg, "S", "indent-switches") )
+ else if (isOption(arg, "S", "indent-switches"))
{
formatter.setSwitchIndent(true);
}
- else if ( isOption(arg, "K", "indent-cases") )
+ else if (isOption(arg, "K", "indent-cases"))
{
formatter.setCaseIndent(true);
}
- else if ( isOption(arg, "xU", "indent-after-parens") )
+ else if (isOption(arg, "xU", "indent-after-parens"))
{
formatter.setAfterParenIndent(true);
}
- else if ( isOption(arg, "L", "indent-labels") )
+ else if (isOption(arg, "L", "indent-labels"))
{
formatter.setLabelIndent(true);
}
@@ -2954,52 +3292,52 @@
{
formatter.setPreprocBlockIndent(true);
}
- else if ( isOption(arg, "w", "indent-preproc-define") )
+ else if (isOption(arg, "w", "indent-preproc-define"))
{
formatter.setPreprocDefineIndent(true);
}
- else if ( isOption(arg, "xw", "indent-preproc-cond") )
+ else if (isOption(arg, "xw", "indent-preproc-cond"))
{
formatter.setPreprocConditionalIndent(true);
}
- else if ( isOption(arg, "y", "break-closing-braces") )
+ else if (isOption(arg, "y", "break-closing-braces"))
{
formatter.setBreakClosingHeaderBracesMode(true);
}
- else if ( isOption(arg, "O", "keep-one-line-blocks") )
+ else if (isOption(arg, "O", "keep-one-line-blocks"))
{
formatter.setBreakOneLineBlocksMode(false);
}
- else if ( isOption(arg, "o", "keep-one-line-statements") )
+ else if (isOption(arg, "o", "keep-one-line-statements"))
{
formatter.setBreakOneLineStatementsMode(false);
}
- else if ( isOption(arg, "P", "pad-paren") )
+ else if (isOption(arg, "P", "pad-paren"))
{
formatter.setParensOutsidePaddingMode(true);
formatter.setParensInsidePaddingMode(true);
}
- else if ( isOption(arg, "d", "pad-paren-out") )
+ else if (isOption(arg, "d", "pad-paren-out"))
{
formatter.setParensOutsidePaddingMode(true);
}
- else if ( isOption(arg, "xd", "pad-first-paren-out") )
+ else if (isOption(arg, "xd", "pad-first-paren-out"))
{
formatter.setParensFirstPaddingMode(true);
}
- else if ( isOption(arg, "D", "pad-paren-in") )
+ else if (isOption(arg, "D", "pad-paren-in"))
{
formatter.setParensInsidePaddingMode(true);
}
- else if ( isOption(arg, "H", "pad-header") )
+ else if (isOption(arg, "H", "pad-header"))
{
formatter.setParensHeaderPaddingMode(true);
}
- else if ( isOption(arg, "U", "unpad-paren") )
+ else if (isOption(arg, "U", "unpad-paren"))
{
formatter.setParensUnPaddingMode(true);
}
- else if ( isOption(arg, "p", "pad-oper") )
+ else if (isOption(arg, "p", "pad-oper"))
{
formatter.setOperatorPaddingMode(true);
}
@@ -3007,68 +3345,68 @@
{
formatter.setCommaPaddingMode(true);
}
- else if ( isOption(arg, "xe", "delete-empty-lines") )
+ else if (isOption(arg, "xe", "delete-empty-lines"))
{
formatter.setDeleteEmptyLinesMode(true);
}
- else if ( isOption(arg, "E", "fill-empty-lines") )
+ else if (isOption(arg, "E", "fill-empty-lines"))
{
formatter.setEmptyLineFill(true);
}
- else if ( isOption(arg, "c", "convert-tabs") )
+ else if (isOption(arg, "c", "convert-tabs"))
{
formatter.setTabSpaceConversionMode(true);
}
- else if ( isOption(arg, "xy", "close-templates") )
+ else if (isOption(arg, "xy", "close-templates"))
{
formatter.setCloseTemplatesMode(true);
}
- else if ( isOption(arg, "F", "break-blocks=all") )
+ else if (isOption(arg, "F", "break-blocks=all"))
{
formatter.setBreakBlocksMode(true);
formatter.setBreakClosingHeaderBlocksMode(true);
}
- else if ( isOption(arg, "f", "break-blocks") )
+ else if (isOption(arg, "f", "break-blocks"))
{
formatter.setBreakBlocksMode(true);
}
- else if ( isOption(arg, "e", "break-elseifs") )
+ else if (isOption(arg, "e", "break-elseifs"))
{
formatter.setBreakElseIfsMode(true);
}
- else if ( isOption(arg, "xb", "break-one-line-headers") )
+ else if (isOption(arg, "xb", "break-one-line-headers"))
{
formatter.setBreakOneLineHeadersMode(true);
}
- else if ( isOption(arg, "j", "add-braces") )
+ else if (isOption(arg, "j", "add-braces"))
{
formatter.setAddBracesMode(true);
}
- else if ( isOption(arg, "J", "add-one-line-braces") )
+ else if (isOption(arg, "J", "add-one-line-braces"))
{
formatter.setAddOneLineBracesMode(true);
}
- else if ( isOption(arg, "xj", "remove-braces") )
+ else if (isOption(arg, "xj", "remove-braces"))
{
formatter.setRemoveBracesMode(true);
}
- else if ( isOption(arg, "Y", "indent-col1-comments") )
+ else if (isOption(arg, "Y", "indent-col1-comments"))
{
formatter.setIndentCol1CommentsMode(true);
}
- else if ( isOption(arg, "align-pointer=type") )
+ else if (isOption(arg, "align-pointer=type"))
{
formatter.setPointerAlignment(PTR_ALIGN_TYPE);
}
- else if ( isOption(arg, "align-pointer=middle") )
+ else if (isOption(arg, "align-pointer=middle"))
{
formatter.setPointerAlignment(PTR_ALIGN_MIDDLE);
}
- else if ( isOption(arg, "align-pointer=name") )
+ else if (isOption(arg, "align-pointer=name"))
{
formatter.setPointerAlignment(PTR_ALIGN_NAME);
}
- else if ( isParamOption(arg, "k") )
+ else if (isParamOption(arg, "k"))
{
int align = 0;
string styleParam = getParam(arg, "k");
@@ -3083,23 +3421,23 @@
else if (align == 3)
formatter.setPointerAlignment(PTR_ALIGN_NAME);
}
- else if ( isOption(arg, "align-reference=none") )
+ else if (isOption(arg, "align-reference=none"))
{
formatter.setReferenceAlignment(REF_ALIGN_NONE);
}
- else if ( isOption(arg, "align-reference=type") )
+ else if (isOption(arg, "align-reference=type"))
{
formatter.setReferenceAlignment(REF_ALIGN_TYPE);
}
- else if ( isOption(arg, "align-reference=middle") )
+ else if (isOption(arg, "align-reference=middle"))
{
formatter.setReferenceAlignment(REF_ALIGN_MIDDLE);
}
- else if ( isOption(arg, "align-reference=name") )
+ else if (isOption(arg, "align-reference=name"))
{
formatter.setReferenceAlignment(REF_ALIGN_NAME);
}
- else if ( isParamOption(arg, "W") )
+ else if (isParamOption(arg, "W"))
{
int align = 0;
string styleParam = getParam(arg, "W");
@@ -3116,7 +3454,7 @@
else if (align == 3)
formatter.setReferenceAlignment(REF_ALIGN_NAME);
}
- else if ( isParamOption(arg, "max-code-length=") )
+ else if (isParamOption(arg, "max-code-length="))
{
int maxLength = 50;
string maxLengthParam = getParam(arg, "max-code-length=");
@@ -3129,7 +3467,7 @@
else
formatter.setMaxCodeLength(maxLength);
}
- else if ( isParamOption(arg, "xC") )
+ else if (isParamOption(arg, "xC"))
{
int maxLength = 50;
string maxLengthParam = getParam(arg, "xC");
@@ -3140,40 +3478,56 @@
else
formatter.setMaxCodeLength(maxLength);
}
- else if ( isOption(arg, "xL", "break-after-logical") )
+ else if (isOption(arg, "xL", "break-after-logical"))
{
formatter.setBreakAfterMode(true);
}
- else if ( isOption(arg, "xc", "attach-classes") )
+ else if (isOption(arg, "xc", "attach-classes"))
{
formatter.setAttachClass(true);
}
- else if ( isOption(arg, "xV", "attach-closing-while") )
+ else if (isOption(arg, "xV", "attach-closing-while"))
{
formatter.setAttachClosingWhile(true);
}
- else if ( isOption(arg, "xk", "attach-extern-c") )
+ else if (isOption(arg, "xk", "attach-extern-c"))
{
formatter.setAttachExternC(true);
}
- else if ( isOption(arg, "xn", "attach-namespaces") )
+ else if (isOption(arg, "xn", "attach-namespaces"))
{
formatter.setAttachNamespace(true);
}
- else if ( isOption(arg, "xl", "attach-inlines") )
+ else if (isOption(arg, "xl", "attach-inlines"))
{
formatter.setAttachInline(true);
}
- else if ( isOption(arg, "xp", "remove-comment-prefix") )
+ else if (isOption(arg, "xp", "remove-comment-prefix"))
{
formatter.setStripCommentPrefix(true);
}
+ else if (isOption(arg, "xB", "break-return-type"))
+ {
+ formatter.setBreakReturnType(true);
+ }
+ else if (isOption(arg, "xD", "break-return-type-decl"))
+ {
+ formatter.setBreakReturnTypeDecl(true);
+ }
+ else if (isOption(arg, "xf", "attach-return-type"))
+ {
+ formatter.setAttachReturnType(true);
+ }
+ else if (isOption(arg, "xh", "attach-return-type-decl"))
+ {
+ formatter.setAttachReturnTypeDecl(true);
+ }
// Objective-C options
- else if ( isOption(arg, "xQ", "pad-method-prefix") )
+ else if (isOption(arg, "xQ", "pad-method-prefix"))
{
formatter.setMethodPrefixPaddingMode(true);
}
- else if ( isOption(arg, "xR", "unpad-method-prefix") )
+ else if (isOption(arg, "xR", "unpad-method-prefix"))
{
formatter.setMethodPrefixUnPaddingMode(true);
}
@@ -3197,49 +3551,50 @@
{
formatter.setAlignMethodColon(true);
}
- else if ( isOption(arg, "xP0", "pad-method-colon=none") )
+ else if (isOption(arg, "xP0", "pad-method-colon=none"))
{
formatter.setObjCColonPaddingMode(COLON_PAD_NONE);
}
- else if ( isOption(arg, "xP1", "pad-method-colon=all") )
+ else if (isOption(arg, "xP1", "pad-method-colon=all"))
{
formatter.setObjCColonPaddingMode(COLON_PAD_ALL);
}
- else if ( isOption(arg, "xP2", "pad-method-colon=after") )
+ else if (isOption(arg, "xP2", "pad-method-colon=after"))
{
formatter.setObjCColonPaddingMode(COLON_PAD_AFTER);
}
- else if ( isOption(arg, "xP3", "pad-method-colon=before") )
+ else if (isOption(arg, "xP3", "pad-method-colon=before"))
{
formatter.setObjCColonPaddingMode(COLON_PAD_BEFORE);
}
+ // NOTE: depreciated options - remove when appropriate
// depreciated options ////////////////////////////////////////////////////////////////////////
- else if ( isOption(arg, "indent-preprocessor") ) // depreciated release 2.04
+ else if (isOption(arg, "indent-preprocessor")) // depreciated release 2.04
{
formatter.setPreprocDefineIndent(true);
}
- else if ( isOption(arg, "style=ansi") ) // depreciated release 2.05
+ else if (isOption(arg, "style=ansi")) // depreciated release 2.05
{
formatter.setFormattingStyle(STYLE_ALLMAN);
}
// depreciated in release 3.0 /////////////////////////////////////////////////////////////////
- else if ( isOption(arg, "break-closing-brackets") ) // depreciated release 3.0
+ else if (isOption(arg, "break-closing-brackets")) // depreciated release 3.0
{
formatter.setBreakClosingHeaderBracketsMode(true);
}
- else if ( isOption(arg, "add-brackets") ) // depreciated release 3.0
+ else if (isOption(arg, "add-brackets")) // depreciated release 3.0
{
formatter.setAddBracketsMode(true);
}
- else if ( isOption(arg, "add-one-line-brackets") ) // depreciated release 3.0
+ else if (isOption(arg, "add-one-line-brackets")) // depreciated release 3.0
{
formatter.setAddOneLineBracketsMode(true);
}
- else if ( isOption(arg, "remove-brackets") ) // depreciated release 3.0
+ else if (isOption(arg, "remove-brackets")) // depreciated release 3.0
{
formatter.setRemoveBracketsMode(true);
}
- else if ( isParamOption(arg, "max-instatement-indent=") ) // depreciated release 3.0
+ else if (isParamOption(arg, "max-instatement-indent=")) // depreciated release 3.0
{
int maxIndent = 40;
string maxIndentParam = getParam(arg, "max-instatement-indent=");
@@ -3252,27 +3607,6 @@
else
formatter.setMaxInStatementIndentLength(maxIndent);
}
-// NOTE: Removed in release 2.04.
-// else if ( isOption(arg, "b", "brackets=break") )
-// {
-// formatter.setBracketFormatMode(BREAK_MODE);
-// }
-// else if ( isOption(arg, "a", "brackets=attach") )
-// {
-// formatter.setBracketFormatMode(ATTACH_MODE);
-// }
-// else if ( isOption(arg, "l", "brackets=linux") )
-// {
-// formatter.setBracketFormatMode(LINUX_MODE);
-// }
-// else if ( isOption(arg, "u", "brackets=stroustrup") )
-// {
-// formatter.setBracketFormatMode(STROUSTRUP_MODE);
-// }
-// else if ( isOption(arg, "g", "brackets=run-in") )
-// {
-// formatter.setBracketFormatMode(RUN_IN_MODE);
-// }
// end depreciated options ////////////////////////////////////////////////////////////////////
#ifdef ASTYLE_LIB
// End of options used by GUI /////////////////////////////////////////////////////////////////
@@ -3280,11 +3614,11 @@
isOptionError(arg, errorInfo);
#else
// Options used by only console ///////////////////////////////////////////////////////////////
- else if ( isOption(arg, "n", "suffix=none") )
+ else if (isOption(arg, "n", "suffix=none"))
{
console.setNoBackup(true);
}
- else if ( isParamOption(arg, "suffix=") )
+ else if (isParamOption(arg, "suffix="))
{
string suffixParam = getParam(arg, "suffix=");
if (suffixParam.length() > 0)
@@ -3292,13 +3626,13 @@
console.setOrigSuffix(suffixParam);
}
}
- else if ( isParamOption(arg, "exclude=") )
+ else if (isParamOption(arg, "exclude="))
{
string suffixParam = getParam(arg, "exclude=");
if (suffixParam.length() > 0)
console.updateExcludeVector(suffixParam);
}
- else if ( isOption(arg, "r", "R") || isOption(arg, "recursive") )
+ else if (isOption(arg, "r", "R") || isOption(arg, "recursive"))
{
console.setIsRecursive(true);
}
@@ -3306,47 +3640,47 @@
{
console.setIsDryRun(true);
}
- else if ( isOption(arg, "Z", "preserve-date") )
+ else if (isOption(arg, "Z", "preserve-date"))
{
console.setPreserveDate(true);
}
- else if ( isOption(arg, "v", "verbose") )
+ else if (isOption(arg, "v", "verbose"))
{
console.setIsVerbose(true);
}
- else if ( isOption(arg, "Q", "formatted") )
+ else if (isOption(arg, "Q", "formatted"))
{
console.setIsFormattedOnly(true);
}
- else if ( isOption(arg, "q", "quiet") )
+ else if (isOption(arg, "q", "quiet"))
{
console.setIsQuiet(true);
}
- else if ( isOption(arg, "i", "ignore-exclude-errors") )
+ else if (isOption(arg, "i", "ignore-exclude-errors"))
{
console.setIgnoreExcludeErrors(true);
}
- else if ( isOption(arg, "xi", "ignore-exclude-errors-x") )
+ else if (isOption(arg, "xi", "ignore-exclude-errors-x"))
{
console.setIgnoreExcludeErrorsAndDisplay(true);
}
- else if ( isOption(arg, "X", "errors-to-stdout") )
+ else if (isOption(arg, "X", "errors-to-stdout"))
{
console.setErrorStream(&cout);
}
- else if ( isOption(arg, "lineend=windows") )
+ else if (isOption(arg, "lineend=windows"))
{
formatter.setLineEndFormat(LINEEND_WINDOWS);
}
- else if ( isOption(arg, "lineend=linux") )
+ else if (isOption(arg, "lineend=linux"))
{
formatter.setLineEndFormat(LINEEND_LINUX);
}
- else if ( isOption(arg, "lineend=macold") )
+ else if (isOption(arg, "lineend=macold"))
{
formatter.setLineEndFormat(LINEEND_MACOLD);
}
- else if ( isParamOption(arg, "z") )
+ else if (isParamOption(arg, "z"))
{
int lineendType = 0;
string lineendParam = getParam(arg, "z");
@@ -3361,25 +3695,13 @@
else if (lineendType == 3)
formatter.setLineEndFormat(LINEEND_MACOLD);
}
- else if ( isParamOption(arg, "stdin=") )
- {
- string path = getParam(arg, "stdin=");
- console.standardizePath(path);
- console.setStdPathIn(path);
- }
- else if ( isParamOption(arg, "stdout=") )
- {
- string path = getParam(arg, "stdout=");
- console.standardizePath(path);
- console.setStdPathOut(path);
- }
else
isOptionError(arg, errorInfo);
#endif
} // End of parseOption function
-// Parse options from the options file.
-void ASOptions::importOptions(istream& in, vector& optionsVector)
+// Parse options from the option file.
+void ASOptions::importOptions(stringstream& in, vector& optionsVector)
{
char ch;
bool isInQuote = false;
@@ -3456,7 +3778,7 @@
{
if (optionErrors.str().length() == 0)
optionErrors << errorInfo << endl; // need main error message
- optionErrors << arg << endl;
+ optionErrors << "\t" << arg << endl;
}
bool ASOptions::isParamOption(const string& arg, const char* option)
@@ -3464,7 +3786,7 @@
bool retVal = arg.compare(0, strlen(option), option) == 0;
// if comparing for short option, 2nd char of arg must be numeric
if (retVal && strlen(option) == 1 && arg.length() > 1)
- if (!isdigit((unsigned char)arg[1]))
+ if (!isdigit((unsigned char) arg[1]))
retVal = false;
return retVal;
}
@@ -3481,7 +3803,7 @@
// Return true if an int is big endian.
bool ASEncoding::getBigEndian() const
{
- short int word = 0x0001;
+ char16_t word = 0x0001;
char* byte = (char*) &word;
return (byte[0] ? false : true);
}
@@ -3489,11 +3811,11 @@
// Swap the two low order bytes of a 16 bit integer value.
int ASEncoding::swap16bit(int value) const
{
- return ( ((value & 0xff) << 8) | ((value & 0xff00) >> 8) );
+ return (((value & 0xff) << 8) | ((value & 0xff00) >> 8));
}
// Return the length of a utf-16 C string.
-// The length is in number of utf16_t.
+// The length is in number of char16_t.
size_t ASEncoding::utf16len(const utf16* utf16In) const
{
size_t length = 0;
@@ -3510,16 +3832,16 @@
size_t ASEncoding::utf8LengthFromUtf16(const char* utf16In, size_t inLen, bool isBigEndian) const
{
size_t len = 0;
- size_t wcharLen = inLen / 2;
- const short* uptr = reinterpret_cast(utf16In);
- for (size_t i = 0; i < wcharLen && uptr[i];)
+ size_t wcharLen = (inLen / 2) + (inLen % 2);
+ const char16_t* uptr = reinterpret_cast(utf16In);
+ for (size_t i = 0; i < wcharLen;)
{
size_t uch = isBigEndian ? swap16bit(uptr[i]) : uptr[i];
if (uch < 0x80)
len++;
else if (uch < 0x800)
len += 2;
- else if ((uch >= SURROGATE_LEAD_FIRST) && (uch <= SURROGATE_TRAIL_LAST))
+ else if ((uch >= SURROGATE_LEAD_FIRST) && (uch <= SURROGATE_LEAD_LAST))
{
len += 4;
i++;
@@ -3828,10 +4150,10 @@
* /EXPORT:AStyleGetVersion=_AStyleGetVersion@0
* No /EXPORT is required for x64
*/
-extern "C" EXPORT utf16_t* STDCALL AStyleMainUtf16(const utf16_t* pSourceIn, // the source to be formatted
- const utf16_t* pOptions, // AStyle options
- fpError fpErrorHandler, // error handler function
- fpAlloc fpMemoryAlloc) // memory allocation function
+extern "C" EXPORT char16_t* STDCALL AStyleMainUtf16(const char16_t* pSourceIn, // the source to be formatted
+ const char16_t* pOptions, // AStyle options
+ fpError fpErrorHandler, // error handler function
+ fpAlloc fpMemoryAlloc) // memory allocation function
{
if (fpErrorHandler == nullptr) // cannot display a message if no error handler
return nullptr;
@@ -3852,17 +4174,17 @@
return nullptr;
}
#ifndef _WIN32
- // check size of utf16_t on Linux
+ // check size of char16_t on Linux
int sizeCheck = 2;
- if (sizeof(utf16_t) != sizeCheck)
+ if (sizeof(char16_t) != sizeCheck)
{
- fpErrorHandler(104, "Unsigned short is not the correct size.");
+ fpErrorHandler(104, "char16_t is not the correct size.");
return nullptr;
}
#endif
ASLibrary library;
- utf16_t* utf16Out = library.formatUtf16(pSourceIn, pOptions, fpErrorHandler, fpMemoryAlloc);
+ char16_t* utf16Out = library.formatUtf16(pSourceIn, pOptions, fpErrorHandler, fpMemoryAlloc);
return utf16Out;
}
@@ -3904,7 +4226,7 @@
ASOptions options(formatter);
vector optionsVector;
- istringstream opt(pOptions);
+ stringstream opt(pOptions);
options.importOptions(opt, optionsVector);
@@ -3912,8 +4234,8 @@
if (!ok)
fpErrorHandler(130, options.getOptionErrors().c_str());
- istringstream in(pSourceIn);
- ASStreamIterator streamIterator(&in);
+ stringstream in(pSourceIn);
+ ASStreamIterator streamIterator(&in);
ostringstream out;
formatter.init(&streamIterator);
@@ -3934,7 +4256,7 @@
}
size_t textSizeOut = out.str().length();
- char* pTextOut = fpMemoryAlloc((long)textSizeOut + 1); // call memory allocation function
+ char* pTextOut = fpMemoryAlloc((long) textSizeOut + 1); // call memory allocation function
if (pTextOut == nullptr)
{
fpErrorHandler(120, "Allocation failure on output.");
@@ -3970,9 +4292,9 @@
{
// create objects
ASFormatter formatter;
- auto console = make_shared(formatter);
+ unique_ptr console(new ASConsole(formatter));
- // process command line and options file
+ // process command line and option files
// build the vectors fileNameVector, optionsVector, and fileOptionsVector
vector argvOptions;
argvOptions = console->getArgvOptions(argc, argv);
diff -Nru codeblocks-16.01+p~launchpadrev9384~ubuntu17.04.1/src/plugins/astyle/astyle/astyle_main.h codeblocks-16.01+p~launchpadrev9388~ubuntu17.04.1/src/plugins/astyle/astyle/astyle_main.h
--- codeblocks-16.01+p~launchpadrev9384~ubuntu17.04.1/src/plugins/astyle/astyle/astyle_main.h 2018-01-12 02:21:57.000000000 +0000
+++ codeblocks-16.01+p~launchpadrev9388~ubuntu17.04.1/src/plugins/astyle/astyle/astyle_main.h 2018-01-15 20:56:41.000000000 +0000
@@ -1,5 +1,5 @@
// astyle_main.h
-// Copyright (c) 2017 by Jim Pattee .
+// Copyright (c) 2018 by Jim Pattee .
// This code is licensed under the MIT License.
// License.md describes the conditions under which this software may be distributed.
@@ -57,9 +57,9 @@
#pragma warning(disable: 4996) // secure version deprecation warnings
#endif
-// for namespace problem in version 5.0
-#if defined(_MSC_VER) && _MSC_VER < 1200 // check for V6.0
- #error - Use Microsoft compiler version 6 or higher
+// for Visual Studio supported C++11 standard
+#if defined(_MSC_VER) && _MSC_VER < 1600
+ #error Use Microsoft Visual Studio 2010 or higher
#endif
#ifdef __clang__
@@ -101,8 +101,6 @@
#endif
#endif // #ifdef _WIN32
- // define utf-16 bit text for the platform
- typedef unsigned short utf16_t;
// define pointers to callback error handler and memory allocation
typedef void (STDCALL* fpError)(int errorNumber, const char* errorMessage);
typedef char* (STDCALL* fpAlloc)(unsigned long memoryNeeded);
@@ -117,8 +115,9 @@
//
//----------------------------------------------------------------------------
// ASStreamIterator class
-// typename will be istringstream for GUI and istream otherwise
-// ASSourceIterator is an abstract class defined in astyle.h
+// typename will be stringstream for AStyle
+// it could be istream or wxChar for plug-ins
+// ASSourceIterator is an inherited abstract class defined in astyle.h
//----------------------------------------------------------------------------
template
@@ -156,6 +155,7 @@
bool compareToInputBuffer(const string& nextLine_) const
{ return (nextLine_ == prevBuffer); }
const string& getOutputEOL() const { return outputEOL; }
+ streamoff getPeekStart() const { return peekStart; }
bool hasMoreLines() const { return !inStream->eof(); }
};
@@ -167,7 +167,7 @@
class ASEncoding
{
private:
- typedef unsigned short utf16; // 16 bits
+ typedef char16_t utf16; // 16 bits unsigned
typedef unsigned char utf8; // 8 bits
typedef unsigned char ubyte; // 8 bits
enum { SURROGATE_LEAD_FIRST = 0xD800 };
@@ -203,7 +203,7 @@
ASOptions(ASFormatter& formatterArg, ASConsole& consoleArg);
#endif
string getOptionErrors() const;
- void importOptions(istream& in, vector& optionsVector);
+ void importOptions(stringstream& in, vector& optionsVector);
bool parseOptions(vector& optionsVector, const string& errorInfo);
private:
@@ -237,7 +237,8 @@
{
private: // variables
ASFormatter& formatter; // reference to the ASFormatter object
- ASLocalizer localizer; // ASLocalizer object
+ ASEncoding encode; // file encoding conversion
+ ASLocalizer localizer; // language translation
ostream* errorStream; // direct error messages to cerr or cout
// command line options
bool isRecursive; // recursive option
@@ -249,7 +250,6 @@
bool isFormattedOnly; // formatted lines only option
bool ignoreExcludeErrors; // don't abort on unmatched excludes
bool ignoreExcludeErrorsDisplay; // don't display unmatched excludes
- bool optionsFileRequired; // options= option
bool useAscii; // ascii option
// other variables
bool bypassBrowserOpen; // don't open the browser on html options
@@ -261,12 +261,11 @@
bool lineEndsMixed; // output has mixed line ends
int linesOut; // number of output lines
- ASEncoding utf8_16; // utf8/16 conversion methods
-
string outputEOL; // current line end
string prevEOL; // previous line end
- string optionsFileName; // file path and name of the options file to use
+ string optionFileName; // file path and name of the options file
string origSuffix; // suffix= option
+ string projectOptionFileName; // file path and name of the project options file
string stdPathIn; // path to input from stdin=
string stdPathOut; // path to output from stdout=
string targetDirectory; // path to the directory being processed
@@ -276,6 +275,7 @@
vector excludeHitsVector; // exclude flags for error reporting
vector fileNameVector; // file paths and names from the command line
vector optionsVector; // options from the command line
+ vector projectOptionsVector;// project options from the project options file
vector fileOptionsVector; // options from the options file
vector fileName; // files to be processed including path
@@ -288,6 +288,7 @@
void error(const char* why, const char* what) const;
void formatCinToCout();
vector getArgvOptions(int argc, char** argv) const;
+ bool fileExists(const char* file) const;
bool fileNameVectorIsEmpty() const;
ostream* getErrorStream() const;
bool getFilesAreIdentical() const;
@@ -305,10 +306,12 @@
string getLanguageID() const;
string getNumberFormat(int num, size_t lcid = 0) const;
string getNumberFormat(int num, const char* groupingArg, const char* separator) const;
- string getOptionsFileName() const;
+ string getOptionFileName() const;
string getOrigSuffix() const;
+ string getProjectOptionFileName() const;
string getStdPathIn() const;
string getStdPathOut() const;
+ void getTargetFilenames(string& targetFilename_, vector& targetFilenameVector) const;
void processFiles();
void processOptions(const vector& argvOptions);
void setBypassBrowserOpen(bool state);
@@ -321,9 +324,10 @@
void setIsRecursive(bool state);
void setIsVerbose(bool state);
void setNoBackup(bool state);
- void setOptionsFileName(const string& name);
+ void setOptionFileName(const string& name);
void setOrigSuffix(const string& suffix);
void setPreserveDate(bool state);
+ void setProjectOptionFileName(const string& optfilepath);
void setStdPathIn(const string& path);
void setStdPathOut(const string& path);
void standardizePath(string& path, bool removeBeginningSeparator = false) const;
@@ -333,6 +337,7 @@
vector getExcludeHitsVector() const;
vector getFileNameVector() const;
vector getOptionsVector() const;
+ vector getProjectOptionsVector() const;
vector getFileOptionsVector() const;
vector getFileName() const;
@@ -341,10 +346,14 @@
ASConsole& operator=(ASConsole&); // assignment operator not to be implemented
void correctMixedLineEnds(ostringstream& out);
void formatFile(const string& fileName_);
+ string getParentDirectory(const string& absPath) const;
+ string findProjectOptionFilePath(const string& fileName_) const;
string getCurrentDirectory(const string& fileName_) const;
- void getFileNames(const string& directory, const string& wildcard);
+ void getFileNames(const string& directory, const vector& wildcards);
void getFilePaths(const string& filePath);
+ string getFullPathName(const string& relativePath) const;
string getParam(const string& arg, const char* op);
+ bool isHomeOrInvalidAbsPath(const string& absPath) const;
void initializeOutputEOL(LineEndFormat lineEndFormat);
bool isOption(const string& arg, const char* op);
bool isOption(const string& arg, const char* a, const char* b);
@@ -380,15 +389,15 @@
ASLibrary() {}
virtual ~ASLibrary() {}
// virtual functions are mocked in testing
- utf16_t* formatUtf16(const utf16_t*, const utf16_t*, fpError, fpAlloc) const;
- virtual utf16_t* convertUtf8ToUtf16(const char* utf8In, fpAlloc fpMemoryAlloc) const;
- virtual char* convertUtf16ToUtf8(const utf16_t* utf16In) const;
+ char16_t* formatUtf16(const char16_t*, const char16_t*, fpError, fpAlloc) const;
+ virtual char16_t* convertUtf8ToUtf16(const char* utf8In, fpAlloc fpMemoryAlloc) const;
+ virtual char* convertUtf16ToUtf8(const char16_t* utf16In) const;
private:
static char* STDCALL tempMemoryAllocation(unsigned long memoryNeeded);
private:
- ASEncoding utf8_16; // utf8/16 conversion methods
+ ASEncoding encode; // file encoding conversion
};
#endif // ASTYLE_LIB
@@ -420,10 +429,10 @@
//----------------------------------------------------------------------------
#ifdef ASTYLE_LIB
extern "C" EXPORT
-utf16_t* STDCALL AStyleMainUtf16(const utf16_t* pSourceIn,
- const utf16_t* pOptions,
- fpError fpErrorHandler,
- fpAlloc fpMemoryAlloc);
+char16_t* STDCALL AStyleMainUtf16(const char16_t* pSourceIn,
+ const char16_t* pOptions,
+ fpError fpErrorHandler,
+ fpAlloc fpMemoryAlloc);
#endif // ASTYLE_LIB
//-----------------------------------------------------------------------------
diff -Nru codeblocks-16.01+p~launchpadrev9384~ubuntu17.04.1/src/plugins/astyle/astyle/install.html codeblocks-16.01+p~launchpadrev9388~ubuntu17.04.1/src/plugins/astyle/astyle/install.html
--- codeblocks-16.01+p~launchpadrev9384~ubuntu17.04.1/src/plugins/astyle/astyle/install.html 2018-01-12 02:21:57.000000000 +0000
+++ codeblocks-16.01+p~launchpadrev9388~ubuntu17.04.1/src/plugins/astyle/astyle/install.html 2018-01-15 20:56:41.000000000 +0000
@@ -24,7 +24,7 @@
@@ -69,44 +73,73 @@
documentation, Visual C project files, and an executable. The Windows Version compile instructions below give
information for compiling the source code.
+ astyle_x.x_windows_xp.zip is the Windows XP version of Artistic Style. It is identical to the
+ above Windows version except the executable is compiled to be compatible with Windows XP. If you are not running
+ Windows XP, use the above version.
+
Only one platform is supported in each distribution package. If you use Artistic Style on more than one platform
you will need to download packages for each platform. The main difference in platforms is the build directories
and the line endings. Most compilers and development packages will accept any type of line ending. The source
code and documentation are the same for all distributions.
-
Linux Version
+
Linux Version
-
CodeBlocks Linux
+
CMake Linux
- There are workspace and project files for several Linux compilers. Open a workspace file for the appropriate
- compiler. All projects have at least Debug and Release configurations. All output will be in the
- "bin" directory. The workspace contains the following projects.
+ Artistic Style has CMake support for GCC, Clang, and Intel compilers. Other compilers will probably work if
+ the necessary options are set. Refer to the section on Compiler Options for
+ more information.
+
+ Since the different builds use the same source files an "out of source" build should be used. The
+ default build is a release version. A debug version must be specifically requested. The
+ the following options are available for building the various configurations.
-
AStyle builds the Artistic Style command line program (AStyle.exe).
-
AStyle Dll builds the Artistic Style program as a Dynamic Link Library (AStyle.dll). This will
- also build an export library for linking the dll.
-
AStyle Java builds the Artistic Style program as a Dynamic Link Library (AStylej.dll) that can
- be called from a Java program. The Java Development (JDK) is required for the project to compile. The Project
- Properties must have an include path to the JDK include and include/win32 directories. This is set in "Project
- > Properties > C/C++ > General > Additional Include Directories". The default setting
- is for the JDK to be installed in the default directory, but it may not be the most current release. The output
- DLL can also be called from a C++ or C# program.
-
AStyle Lib builds the Artistic Style program as a Static Library (libAStyle.lib). This can be
- statically linked to a calling program.
+
The default builds the Artistic Style command line executable (astyle).
+
BUILD_SHARED_LIBS builds the Artistic Style program as a shared object (libastyle.so).
+
BUILD_JAVA_LIBS builds the Artistic Style program as a shared object (libastylej.so) that can be called
+ from a Java program. The Java Development Kit (JDK) must be installed for the project to compile.
+
BUILD_STATIC_LIBS builds the Artistic Style program as a Static Library (libastyle.a) that can be
+ statically linked to a user program.
+
EXAMPLES
+
- There are build
- folders for the following compilers. All compiler folders are in the "build" directory.
-
-
-
cb-clang contains the workspace and project files for the Linux Clang Compiler.
-
cb-gcc contains the workspace and project files for the GCC Compiler.
-
cb-intel contains the workspace and project files for the Linux Intel Compiler.
-
+ The following examples are assumed to be run from the astyle directory that contains
+ CMakeLists.txt. They show out of source builds that generate makefiles.
+
+ The makefile install option installs the astyle executable and documentation files. The default is /usr/bin for
+ the executable and /usr/share/doc/astyle for the documentation. You must have the appropriate permissions to use
+ install.
+
+
+ There is no uninstall. The easiest way to uninstall is to use the install_manifest.txt file, for example
+ "xargs rm < install_manifest.txt".
GCC Makefile
@@ -123,19 +156,19 @@
or "make release" will build the command line configuration. Following are the symbolic names and file names (in
parens) of the various configurations:
-
release builds the Artistic Style command line program (astyle). This is the default option.
-
-
shared builds the Artistic Style program as a shared library (libastyle.so).
-
static builds the Artistic Style program as a static library (libastyle.a).
-
debug builds the Artistic Style command line program with debugging information (astyled).
-
-
shareddebug builds the Artistic Style program as a shared library with debugging information
- (libastyled.so).
-
-
staticdebug builds the Artistic Style program as a static library with debugging information
- (libastyled.a).
-
-
all builds all the above configurations.
+
release or astyle builds the Artistic Style command line program. This is the
+ default option.
+
shared or libastyle.so builds the Artistic Style program as a shared
+ library.
+
static or libastyle.a builds the Artistic Style program as a static
+ library.
+
debug or astyled builds the Artistic Style command line program with debugging
+ information
+
shareddebug or libastyled.so builds the Artistic Style program as a shared library
+ with debugging information.
+
staticdebug or libastyled.a builds the Artistic Style program as a static library
+ with debugging information.
+
all builds all the above configurations.
The following Java shared library builds are separate from the above. They include a Java Native Interface (JNI)
and require that the Java Development Kit (JDK) be installed. The environment variable JAVA_HOME should be defined.
@@ -148,7 +181,7 @@
javadebug builds the Artistic Style program as a shared library which includes the JNI and debugging
information
(libastylejd.so).
-
javaall builds all the above java configurations.
+
javaall builds all the above java configurations.
More than one configuration can be built at the same time. For example, to build all the release configurations
@@ -162,7 +195,7 @@
Clang has a static analyzer that finds potential bugs in C/C++ and Objective-C programs. It can be run as a standalone
- tool from the command-line, and runs in tandem with a build. There is a script file, analyze.sh, that will run
+ tool from the command-line and runs in tandem with a build. There is a script file, analyze.sh, that will run
the analysis on Artistic Style.
The build has no autoconf dependency. To build the Artistic Style configurations use the makefile located in the
@@ -172,7 +205,7 @@
To build the other astyle configurations, you can enter the file name or a symbolic name. The configurations for
- Clang are the same as for the GCC compiler. More than one configuration can be
+ Clang are the same as for the GCC Makefile. More than one configuration can be
built at the same time. For example, to build all the release configurations enter:
cd astyle/build/clang make release shared static
@@ -186,14 +219,10 @@
These procedures and the makefile are for recent versions of the compiler. They may not work for earlier versions.
Instructions for your compiler are in the compiler documentation file "get_started_lc.htm".
- To compile the source there are environment variables that must be set by running the compiler environment script
- compilervars.sh (or compilervars.csh) with an argument that specifies the target architecture. If this has not
- been done already enter: "source <install-dir>/bin/compilervars.sh <arg>",
- where <install-dir> is the directory where the compiler is installed and <arg> is ia32
- or intel64. If this is not done "make" will display an error message "*** The compiler environment
- variables are not set." On an Intel x64 platform installed in the default directory the instruction would
- be
-
source /opt/intel/bin/compilervars.sh intel64
+ To compile with Intel there are environment variables that must be set by running the compiler environment
+ script compilervars.sh (or compilervars.csh) with an argument that specifies the target architecture. This
+ should be done before running the make. If it is not done, "make" will display an error message
+ stating that the compiler environment variables are not set.
The build has no autoconf dependency. To build the Artistic Style configurations use the makefile located in the
astyle/build/intel directory. The output executables will be in the astyle/build/intel/bin directory. To build
@@ -201,88 +230,72 @@
cd astyle/build/intel make
To build the other astyle configurations, you can enter the file name or a symbolic name. The configuration names
- for Intel are the same as for the GCC compiler. More than one configuration can be
+ for Intel are the same as for the GCC Makefile. More than one configuration can be
built at the same time. For example, to build the entire debug configurations enter:
cd astyle/build/intel make debug shareddebug staticdebug
- The following makefile targets are available for GCC, Clang, Intel, and Mac.
-
-
clean
-
+ There are build folders for the following compilers. All compiler folders are in the "build" directory.
+
+
+
cb-clang contains the workspace and project files for the Linux Clang Compiler.
+
cb-gcc contains the workspace and project files for the Linux GCC Compiler.
+
cb-intel contains the workspace and project files for the Linux Intel Compiler.
+
- Removes the object and executable files for all configurations.
+ There are workspace and project files for each folder. All projects have at least Debug and Release
+ configurations. All output will be in the "bin" directory.
- To remove the files for all configurations:
-
make clean
-
-
-
cleanobj
+ The workspace contains the following projects.
+
+
AStyle builds the Artistic Style command line program (astyle).
+
AStyle So builds the Artistic Style program as a shared object (libastyle.so).
+
AStyle Java builds the Artistic Style program as a shared object (libastylej.so) that can
+ be called from a Java program. The Java Development Kit (JDK) is required for the project to compile. The
+ Project Properties must have an include path to the JDK include directories.
+
AStyle A builds the Artistic Style program as a Static Library (libastyle.a). This can be
+ statically linked to a user program.
+
- Removes the object files for all configurations. The executables will not be removed.
-
- To remove only the object files for all configurations:
- Installs the
- astyle executable and documentation files. The default is /usr/bin for the executable and /usr/share/doc/astyle
- for the documentation. You must have the appropriate permissions to use install.
-
- To install the astyle to the default directories:
-
sudo make install
-
-
- To install astyle to a different bin directory set a value for the macro $(prefix). For example, to install the
- executable to a user's home directory (/home/user/bin):
-
sudo make prefix=$HOME install
-
+ Artistic Style has CMake support for MacOS. It is used the same as CMake Linux
+ except the supported compilers are only GCC and Clang.
-
uninstall
+
MacOS Makefile
- Uninstalls the executable and documentation. You must have the appropriate permissions to use uninstall.
+ The Artistic Style makefile compile uses the Mac OS "Command Line Tools". If you have Xcode 4.3 or newer
+ the command line tools, such as "make", are NOT installed by default. They must be downloaded and installed
+ separately. Once everything is successfully installed, you should see "make" and other command line
+ developer tools in /usr/bin.
- To uninstall astyle from the default directories:
-
sudo make uninstall
+ The build has no autoconf dependency. To build the Artistic Style configurations use the makefile located in the
+ astyle/build/mac directory. The executables will be in the astyle/build/mac/bin directory. To build the command
+ line configuration, enter the following:
+
cd astyle/build/mac make
- To uninstall the files from a different directory set a value for the macro $(prefix). For example, to uninstall
- the files from a user's home directory (/home/user):
-
sudo make prefix=$HOME uninstall
+ To build the other astyle configurations, you can enter the file name or a symbolic name. The configurations for
+ Mac are the same as for the GCC Makefile. More than one configuration can be
+ built at the same time. For example, to build all the release configurations enter:
+
cd astyle/build/mac make release shared static
- NOTE: The uninstall option will NOT remove the .astylerc files from the users' home directories. The files must
- be removed individually for each user.
-
-
MacOS Version
-
-
CodeBlocks MacOS
-
-
- There are workspace and project files for the MacOS compiler. Open the workspace file for the MacOS compiler.
- All projects have at least Debug and Release configurations. All output will be in the "bin"
- directory.
Only the astyle executable is installed. The library project installs are sent to UninstalledProjects in
@@ -321,7 +334,7 @@
sudo bash install.sh
-
uninstall
+
UNINSTALL
Uninstalls the executable and documentation. You must have the appropriate permissions to use uninstall.
@@ -333,55 +346,109 @@
NOTE: The uninstall option will NOT remove the .astylerc files from the users' home directories. The files must
be removed individually for each user.
-
MacOS Makefile
+
Windows Version
+
+
Precompiled Executable
- The Artistic Style makefile compile uses the Mac OS "Command Line Tools". If you have Xcode 4.3 or newer
- the command line tools, such as "make", are NOT installed by default. They must be downloaded and installed
- separately. Once everything is successfully installed, you should see "make" and other command line
- developer tools in /usr/bin.
+ In addition to the source files, the Windows distribution package contains an Artistic Style Win32 executable
+ (AStyle.exe). If you prefer to compile the executable yourself, pursue the following instructions.
+
+
CMake Windows
+
- The build has no autoconf dependency. To build the Artistic Style configurations use the makefile located in the
- astyle/build/mac directory. The executables will be in the astyle/build/mac/bin directory. To build the command
- line configuration, enter the following:
-
cd astyle/build/mac make
+ Artistic Style has CMake support for Borland, and MinGW compilers. Other compilers will probably work if
+ the necessary options are set. Refer to the section on Compiler Options for
+ more information.
+
+ The console executable will run for both of the supported compilers. The DLL builds may not. CMake does not
+ fully support all Windows compilers. To build the DLLs it would be best to generate an IDE project file and
+ compile the DLLs with the IDE. The "build" folder contains project files for CodeBlocks and Visual Studio.
+
+
+ Since the different builds use the same source files an "out of source" build should be used. The
+ default build for MinGW is a release version. A debug version must be specifically requested. For
+ Borland, a release build may need to be specifically requested, depending on the CMake release used. Borland
+ has been tested with the bcc32c free compiler. It may or may not work with other Borland compilers. The the following
+ options are available for building the various configurations.
+
+
The default builds the Artistic Style command line executable (AStyle.exe).
+
BUILD_SHARED_LIBS builds the Artistic Style program as a DLL (AStylexx.dll, where xx is the astyle release
+ number).
+
BUILD_JAVA_LIBS builds the Artistic Style program as a DLL (AStylexxj.dll, where xx is the astyle release
+ number) that can be called from a Java program. The Java Development Kit (JDK) must be installed for the project
+ to compile.
+
BUILD_STATIC_LIBS builds the Artistic Style program as a Static Library (AStyleLib.lib) that can be
+ statically linked to a user program.
+
+
+
EXAMPLES
+
+
+ The following examples are assumed to be run from the astyle directory that contains
+ CMakeLists.txt. They show out of source builds that generate makefiles.
+
+ A path to the compiler executable
+ may need to be declared before compiling. And the Borland free compiler will need the compiler name.
+ To set the variables before compiling (replace the path names with the paths on your computer):
+
set PATH=C:\Program Files\CMake\bin;%PATH%
+set PATH=C:\Program Files (x86)\Embarcadero\BCC101\bin;%PATH%
+set CXX=bcc32c
- To build the other astyle configurations, you can enter the file name or a symbolic name. The configurations for
- Mac are the same as for the Linux GCC compiler. More than one configuration can be
- built at the same time. For example, to build all the release configurations enter:
-
cd astyle/build/mac make release shared static
+ To build the Borland console release version (the release build may need to be specified):
+
As stated previously, the DLL builds may not work with the CMake generated makefiles.
+
INSTALL
-
Precompiled Executable
+
+ The makefile install option installs the astyle executable and documentation files. The default is "C:\Program
+ Files (x86)\AStyle" for the executable and "C:\Program Files (x86)\AStyle\doc" for the documentation.
+ You may need to run as an administrator to install.
- In addition to the source files, the Windows distribution package contains an Artistic Style Win32 executable
- (AStyle.exe). If you prefer to compile the executable yourself, pursue the following instructions.
+ There is no uninstall. The uninstall must be done manually. Just remove the two folders indicated in the
+ Install.
CodeBlocks Windows
- There are workspace and project files for several Windows compilers. Open a workspace file for the appropriate
- compiler. All projects have at least Debug and Release configurations. All output will be in the "bin"
- directory.
There are build folders for the following compilers. All compiler folders are in the "build" directory.
-
cb-bcc32ccontains the workspace and project files for the Embarcadero BCC32C Compiler.
-
cb-mingwcontains the workspace and project files for the MinGw or TDM_GCC Compilers.
+
cb-bcc32c contains the workspace and project files for the Embarcadero BCC32C Compiler.
+
cb-mingw contains the workspace and project files for the MinGw or TDM_GCC Compilers.
+
+
+
+ There are workspace and project files for each folder. All projects have at least Debug and Release configurations.
+ All output
+ will be in the "bin" directory.
+
+ The workspace contains the following projects.
+
+
AStyle builds the Artistic Style command line program (AStyle.exe).
+
AStyle Dll builds the Artistic Style program as a shared object (AStyle.dll).
+
AStyle Java builds the Artistic Style program as a shared object AStylej.dll) that can
+ be called from a Java program. The Java Development Kit (JDK) is required for the project to compile. The
+ Project Properties must have an include path to the JDK include directories.
+
AStyle Lib builds the Artistic Style program as a Static Library (astyle.lib). This can be
+ statically linked to a calling program.
- For other compilers, follow the instructions in Other Compilers.
All AStyle builds the release and the debug configurations for all the following.
AStyle builds the Artistic Style command line program (AStyle.exe). This project has an extra
- "Static" option. It is the same as the "Release" build except that it is linked with a static runtime library.
- This is needed if the executable is to be run on a system without Visual Studio installed. The builds for this
- configuration are placed in a separate "binstatic" directory.
+ "Static"" option. It is the same as the "Release" build except that it is linked with a static
+ runtime library. This is needed if the executable is to be run on a system without Visual Studio installed. The
+ builds for this configuration are placed in a separate "binstatic" directory.
AStyle Dll builds the Artistic Style program as a Dynamic Link Library (AStyle.dll). This will
also build an export library and a static library for linking the dll.
AStyle Java builds the Artistic Style program as a Dynamic Link Library (AStylej.dll) that can
@@ -409,13 +476,72 @@
AStyle Lib builds the Artistic Style program as a Static Library (libAStyle.lib). This can be
statically linked to a calling program.
- To use other compilers a project file must be built using a development environment.
+ The following makefile targets are available for GCC, Clang, Intel, and Mac.
+
+
CLEAN
+
+
+ Removes the object and executable files for all configurations.
+
+ To remove the files for all configurations:
+
make clean
+
+
+
CLEANOBJ
+
+
+ Removes the object files for all configurations. The executables will not be removed.
+
+ To remove only the object files for all configurations:
+
make cleanobj
+
+
+
INSTALL
+
+
+ Installs the astyle executable and documentation files. The default is /usr/bin for the executable and /usr/share/doc/astyle
+ for the documentation. You must have the appropriate permissions to use install.
+
+ To install the astyle to the default directories:
+
sudo make install
+
+
+ To install astyle to a different bin directory set a value for the macro $(prefix). For example, to install the
+ executable to a user's home directory (/home/user/bin):
+
sudo make prefix=$HOME install
+
+
+
UNINSTALL
+
+
+ Uninstalls the executable and documentation. You must have the appropriate permissions to use uninstall.
+
+ To uninstall astyle from the default directories:
+
sudo make uninstall
+
+
+ To uninstall the files from a different directory set a value for the macro $(prefix). For example, to uninstall
+ the files from a user's home directory (/home/user):
+
sudo make prefix=$HOME uninstall
+
+
+ NOTE: The uninstall option will NOT remove the .astylerc files from the users' home directories. The files must
+ be removed individually for each user.
+
+
Other Development Environments
+
+
+ To use other development environments project files usually must be built. CMake can be used if the development
+ environment is supported. Otherwise, use the development environment to create files.
-
Create a project using the compiler development environment.
+
Create a project using the development environment.
Add to the project all the .cpp and .h files in the "src" directory.
The Compiler Options section discusses the compiler options to use.
Compile.
@@ -432,10 +558,10 @@
Artistic Style is a small program and it is best to optimize for speed. The debug configurations are not usually
optimized. To optimize for speed in the release configurations, use the macro NDEBUG to remove asserts. If
- necessary, use an option to activate the C++11 standards (--std=c++0x on most compilers). Use an option that allows
- inline function expansion. Runtime Type Information (RTTI) is NOT needed and exceptions are NOT used. Use whole
- program optimization if your compiler supports it. There may be other options you can use depending on the
- compiler.
+ necessary, use an option to activate the C++11 standards (-std=c++11 or -std=c++0x on most compilers). Use an
+ option that allows inline function expansion. Runtime Type Information (RTTI) is NOT needed and exceptions are
+ NOT used. Use whole program optimization if your compiler supports it. There may be other options you can use
+ depending on the compiler.
+ The Windows default option file location has been changed from USERPROFILE to APPDATA. This
+ moves the file from the User directory and to the user's hidden AppData\Roaming directory. The
+ USERPROFILE location has been depreciated and will be removed in a future release. You will need to relocate the
+ options file manually, Artistic Style will not change it. If the options file is in both locations, the new APPDATA
+ location will be used.
+
+ The console build now accepts option file input encoded in UTF-16, or UTF-8 with a Byte Order Mark (BOM or signature).
+
+
+ New options, "break-return-type" and "break-return-type-decl", will break the return type
+ from function definitions and function declarations. Additional new options, "attach-return-type" and
+ "attach-return-type-decl", will attach the broken return types to function definitions and function
+ declarations. There is more information in the "Formatting Options" section of the documentation.
+
+
+ A new option, "style=ratliff", has been added as an alternate for banner style.
+
+ Several changes have been made to Objective-C which will improve formatting in certain cases.
+
+ CMake can now be used to compile the AStyle builds. It is run from the top level folder instead of the
+ "build" folder, and builds a Release configuration by default. The "Install Information"
+ contains additional information.
+
+ When formatting files from the command line, multiple file extensions may now be used. The file
+ extensions should be separated by commas or semicolons. For example, to format C++ files, use
+ "astyle /home/project/*.cpp,*.h". This will change the processing sequence to format all requested files
+ in a directory rather than formatting a directory once for each file extension. There is additional information
+ in the "Usage" section of the documentation.
+
+
+ New options "project", "project=####", and "project=none"will allow the use of an
+ optional project option file. This may be used to supplement or replace the command line options and the default
+ option file. The file is identified by a file name only and resides in the top level folder of a project. The
+ default file names are .astylerc or _astylerc. A specific file name may also be specified. Instead of an
+ option, the environment variable ARTISTIC_STYLE_PROJECT_OPTION may be used. Using the environment variable
+ will make the project file the default for all projects. When formatting files in a project, the project option
+ file will be obtained from the files directory or a parent directory. The documentation has the details
+ in the "Option Files" section. The "project" option is described in the
+ "Command Line Only" section.
+
+ Allowing both option files enables them to be used for different purposes. For example, the default
+ options could contain the file formatting options and the project options could contain the excludes for the
+ given project. The order of precedence, highest to lowest, is command line options, project options, and default
+ options. Options with a value (e.g. style=kr, indent=spaces) may be replaced by an option with a higher precedence.
+ The binary options (indent-classes, pad-oper) cannot be changed. Once they are set they stay set. Both the
+ default and project option files may be disabled if they are present and not required. When testing the
+ option files, the options "verbose" and "dry-run" may be used. The option files used
+ will be displayed by the "verbose" option.
+
+ When making changes to more than one file in a project, it may be desirable to format an entire folder. Wildcards
+ may be used in a single folder without recursive. The current directory is used if a path is not given. So,
+ for example, to format all changed files in the current directory using the project options, use the command:
+ "astyle --project -A9s *.cpp,*.h". This example uses the project option file .astylerc
+ or _astylerc and overrides the project options with the command line -A9s options.
+
+ Language translations have been added for the new project option file. A few of the other messages were changed
+ as well. If there is a better translation available report the change as a bug report. Be sure to include the
+ new translation. Translations are in the ASLocalizer.cpp file.
+
+ A new virtual method, getPeekStart(), has been added to the pure virtual class ASSourceIterator. If you have
+ inherited this class to access the formatter, you will need to add a method similar to getPeekStart() in the
+ ASStreamIterator class in astyle_main.h.
+
+ The Artistic Style source code has been fuzz tested with American Fuzzy Lop (AFL) and libFuzzer from Clang. This
+ will help prevent crashes caused by invalid input. There were about 30 corrections made to the source code. Most
+ of the crashes were caused by asserts which would not be present in a release version. There were a couple of
+ corrections that required logic changes. The changes should not affect the way the code is formatted.
+
+ The documentation file, astyle.html, now has a sticky button in the lower right corner. It appears after you
+ have scrolled past the Contents section. It is labeled "Top" but actually takes you back to the Contents.
+ The purpose is to improve speed in navigating the document.
+
+ Thanks to Rian Quinn, David Haney, and Tamás Kurucsai for their contributions.
+
+
Artistic Style 3.0 (April 2017)
+
+
+ Release 3.0.1 (May 2017) is a maintenance release and no new features were added. A list of changes is in
+ the Release Notes. The following information is for the original 3.0 release. Thanks to Juan Alday for his
+ contribution.
In the Artistic Style documentation, in General Information, Other Considerations, there is a list of
- terminology used for special characters used in programming. The terms used by Artistic Style has been
+ terminology used for special characters used in programming. The terms used by Artistic Style have been
different than is used by Visual Studio, Clang, and others. In this release the terms used by Artistic Style
have been changed to the ones most commonly used in programming documentation. The following chart indicates
the changes.
@@ -79,17 +161,116 @@
A new option, "indent-after-parens", will indent continuation lines following lines that contain an
opening paren '(' or an assignment '='. This includes function definitions and declarations
- and return statements. This option ay be preferred for editors displaying proportional fonts.
+ and return statements. This option may be preferred for editors displaying proportional fonts.
A new option, "attach-closing-while", will attach the closing "while" of a
"do-while" statement to the closing brace. It has precedence over both the brace style and the break
closing braces option.
- Thanks to Matthew Woehlke for his contribution.
+ The option "break-closing-braces" has been included in "style=stroustrup". This is the
+ correct style according to Wikipedia. The new option "attach-closing-while" is not included in
+ the style but can be used if you want. If there is a problem with the new format, change to the K&R style
+ using the same options as for Stroustrup.
+
+ If you are using Windows XP, there is a download file available that has an XP compatible executable. Artistic
+ Style will still compile with Visual Studio 2010.
+
+ Thanks to Jochen Tucht and Matthew Woehlke for their contributions.
The following are additional topics.
+
Version 3
+
+
+ Artistic Style was written in the 1990's when personal computers were much slower and compilers were not as
+ sophisticated as today. It used a lot of global variables instead of class members. In previous releases, classes
+ were created for the astyle_main.h source code. With this release, the classes have been made independent
+ of the source file containing them and the shared and global data has been eliminated. The classes could now be
+ separated into separate source files. They have not been actually separated because it seems more convenient
+ to leave them combined.
+
+ As explained previously, the terminology for special characters has been changed to agree with various
+ development environments and compilers. The variable and method names in the source code were changed as well
+ as the documentation. This was a major renaming. If not for the "rename" refactoring feature in Visual
+ Studio, and the AStyleTest programs, it would probably not have been attempted.
+
+ Artistic Style has also started using C++11. Older compiler versions and compilers without C++11support cannot
+ be used. If your compiler requires a compiler directive for C++, such as -std=c++11 or -std=c++0x, it will
+ need to be used.
+
Library File Names
+
+
+ The shared library object (DLL) compile was originally intended to be a local library used by a single program.
+ Users could update the library at their convenience. Recently, it has started being distributed as a system library
+ for some distributions. In the past was not maintained for doing this. Since it is already being offered as
+ a distribution, the library soname on Linux has been standardized.
+
+ It can still be used as a local or a static library if you want to control the changes. Or the system library
+ can be used. The system library version, of course, may change at any time. With this release the system
+ library will be available on Debian based systems, as well as possibly others.
+
+ The Windows library name has been changed also. This Windows version is AStyle30.dll. The "30" refers
+ to the Artistic Style release number "3.0". The Linux library name is a soname version number, not the
+ Artistic Style release number.
+
+
Artistic Style Wx
+
+
+ There is a new GUI test program AStyleWx that uses wxWidgets. This replaces the old AStyleWin program. AStyleWx
+ is multi-platform and has more features simply because they are easier to implement with wxWidgets.
+
+ It has download files and a website in a new sub-project directory of Artistic Style. The downloads contain
+ source code, documentation, and scripts. The Windows download contains an executable. The needed Artistic Style
+ source files are included.
+
+ It is licensed under the MIT license. The source code may be used and modified for any purpose you
+ choose. Developers using Artistic Style in another project may use any part of AStyleWx in their project. The
+ modified source code does NOT need to be made available to others.
+
+
Code::Blocks Support
+
+
+ Code::Blocks is a free, open-source cross-platform IDE that supports multiple compilers. It currently gets over
+ 100,000 downloads per week. It is used by Artistic Style to test compilers on various systems. Code::Blocks build
+ files for several free compilers are now provided with the Artistic Style release. The "Install Information"
+ contains additional information.
+
+
Embarcadero Compiler
+
+
+ Embarcadero is offering a new, free, BCC32C C++ compiler. It includes C++11 language support, the Dinkumware
+ Standard Template Library, and the Embarcadero Runtime Library. Included are a linker, a
+ resource compiler, and a number of command line tools. It is currently for Win32 only. There is more
+ information at their Free Tools web page. They are also currently offering a free debugger and two
+ different
+ development environments.
+
+
Naming Conventions
+
+
+ If you use cppcheck, it has an add-on to check naming standards for functions and variables by using regular
+ expressions. Cppcheck must be run first to generate ".dump" files. The Python program, naming.py,
+ can then be run to check the names. It is basically a shell that you will probably want to modify for regular
+ use. The add-ons must be installed with cppcheck for naming.py to be available.
+
+
WinMerge 2011
+
+
+ WinMerge 2011 is a fork of the original WinMerge application published on SourceForge by Thingamahoochie
+ Software. It is has removed the ATL/MFC dependencies and added some useful features. It uses Artistic Style
+ to format the source code.
+
+
Whatstyle
+
+
+ Whatstyle finds a code format style that fits given source files. This program looks at your source code and
+ generates a style definition that fits its original formatting style as closely as possible.
+ Several formatters and programming languages are supported. It is written in Python and has an interesting
+ method for finding the style options.
+