<astyle>

[This is preliminary documentation and subject to change.]

Formats source code in a given directory to a specified code format.

Most examples inline have been produced by Tal Davidson and team and are part of the astyle documentation. They have been included in the task documentation as an easy reference.

NOTE: This task relies on the astyle.exe file being in your path variable. Please download the astyle.exe from http://astyle.sourceforge.net.

Parameters

AttributeTypeDescriptionRequired
brackets-attachbooltrue if brackets should be attached.
            
               if (isFoo){
                   bar();
               } else {
                   anotherBar();
               }
            
            
False
brackets-linuxbooltrue if brackets should be put on a new line and indented.
                           namespace foospace
               {
                   int Foo()
                   {
                       if (isBar) {
                           bar();
                           return 1;
                       } else
                           return 0;
                   }
               }
                        
False
brackets-newlinebooltrue if brackets should be put on a new line.
                           if (isFoo)
               {
                   bar();
               }
               else
               {
                   anotherBar();
               }
               
            
False
break-blocksbooltrue to break block statements with an empty line.
                           isFoo = true;
               if (isFoo) {
                   bar();
               } else {
                   anotherBar();
               }
               isBar = false;
                           becomes:
                           isFoo = true;
                           if (isFoo) {
                   bar();
               } else {
                   anotherBar();
               }
                           isBar = false;
                        
False
break-blocks-allbooltrue to break all block statements, even on nested ifs with an empty line.
                           isFoo = true;
               if (isFoo) {
                   bar();
               } else {
                   anotherBar();
               }
               isBar = false;
                           becomes:
                           isFoo = true;
                           if (isFoo) {
                   bar();
                           } else {
                   anotherBar();
               }
                           isBar = false;
                        
False
break-closingbooltrue if the line after a bracket (i.e. an else statement after the closing if) should be placed on the next line.
            
               if (isFoo){
                   bar();
               }else {
                   anotherBar();
               }
                           becomes:
                           if (isFoo) {
                   bar();
               }
               else {
                   anotherBar();
               }
               
            
False
break-elseifbooltrue to put the if component of an else if on a new line.
                           if (isFoo) {
                   bar();
               } else if (isBar()){
                   anotherBar();
               }
                           becomes:
                           if (isFoo) {
                   bar();
               } else
                   if (isBar()){
                       anotherBar();
                   } 
                        
False
cleanupbool Astyle leaves the original files around, renamed with a different suffix. Setting this to
true
will remove these files.
False
commandlinestring The command-line arguments for the program. False
convert-tabsbooltrue to convert tabs to spaces. False
fill-empty-linesbooltrue if empty lines should be filled with the whitespace of the previous line. False
indent-blocksbooltrue if block statements should be indented. The default: if (isFoo) { bar(); } else anotherBar(); becomes: if (isFoo) { bar(); } else anotherBar(); False
indent-bracketsbool
true
if bracket statements should be indented.
            
               The default:
                           if (isFoo)
               {
                   bar();
               }
               else
               {
                   anotherBar();
               }
                           becomes:
                           if (isFoo)
                   {
                   bar();
                   }
               else
                   {
                   anotherBar();
                   }
                   
            
False
indent-casesbooltrue if case statements should be indented.
            
               The default:
                           switch (foo)
               {
               case 1:
                   {
                       a += 2;
                       break;
                   }
                           default:
                   {
                       a += 2;
                       break;
                   }
               }
                           becomes:
                           switch (foo)
               {
                   case 1:
                   {
                       a += 2;
                       break;
                   }
                               default:
                   {
                       a += 2;
                       break;
                   }
               }
               
            
False
indent-classesbooltrue if class statements should be indented.
            
               The default:
                           class Foo
               {
               public:
                   Foo();
                   virtual ~Foo();
               };
                           becomes:
                           class Foo
               {
                   public:
                       Foo();
                       virtual ~Foo();
               };
               
            
False
indent-labelsbooltrue if label statements should be indented.
            
               The default:
                           int foospace()
               {
                   while (isFoo)
                   {
                       ...
                       goto error;
                           error:
                       ...
                   }
               }
                           becomes:
                           int foospace()
               {
                   while (isFoo)
                   {
                       ...
                       goto error;
                               error:
                       ...
                   }
               }
                        
False
indent-maxint Indicate the maximum number of spaces to indent relative to a previous line. False
indent-minint Indicate the maximum number of spaces to indent relative to a previous line. False
indent-namespacesbooltrue if namespace statements should be indented.
                           The default:
                           namespace foospace
               {
               class Foo
               {
                   public:
                       Foo();
                       virtual ~Foo();
               };
               }
                           becomes:
                           namespace foospace
               {
                   class Foo
                   {
                       public:
                           Foo();
                           virtual ~Foo();
                   };
               }
                        
False
indent-num-spacesint Indicate the maximum number of spaces to indent relative to a previous line. False
indent-num-tabsint Indicate that tabs should be used to indent sources. The number specified indicates the maximum number of spaces the tab character will represent. False
indent-num-tabs-forceint Indent using tab characters. Treat each tab as # spaces. Uses tabs as indents in areas '--indent=tab' prefers to use spaces, such as inside multi-line statements. False
indent-switchesbooltrue if switch statements should be indented.
            
                   The default:
                               switch (foo)
                   {
                   case 1:
                       a += 2;
                       break;
                               default:
                       a += 2;
                       break;
                   }
                               becomes:
                               switch (foo)
                   {
                       case 1:
                           a += 2;
                           break;
                                   default:
                           a += 2;
                           break;
                   }
                   
            
False
nobreak-complexbooltrue to keep complex statements on the same line.
            
               if (isFoo)
               {  
                   isFoo = false; cout << isFoo << endl;
               }
                           remains as is.
                           if (isFoo) DoBar();
                           remains as is.
                        
False
nobreak-singlelineblocksbooltrue to keep single line statements on the same line.
                           if (isFoo)
               { isFoo = false; cout << isFoo << endl; }
                           remains as is.
                        
False
pad-allbooltrue to pad operators and parenthesis.
            
               if (isFoo)
                   a = bar((b-c)*a,*d--);
                           becomes:
                           if ( isFoo )
                   a = bar( ( b - c ) * a, *d-- );
                        
False
pad-operatorsbooltrue to pad operators with a space.
            
               if (isFoo)
                   a = bar((b-c)*a,*d--);
                           becomes:
                           if (isFoo)
                   a = bar((b - c) * a, *d--);
                        
False
pad-parenthesisbooltrue to pad parenthesis with a space.
                           if (isFoo)
                   a = bar((b-c)*a,*d--);
                           becomes:
                           if ( isFoo )
                   a = bar( ( b-c )*a, *d-- );
                        
False
stylestring Indicate the preset style to use.
ansi
                           namespace foospace
                           {
                               int Foo()
                               {
                                   if (isBar)
                                   {
                                       bar();
                                       return 1;
                                   }
                                   else
                                       return 0;
                               }
                           }
                        
kr ( Kernighan&Ritchie )
                           namespace foospace {
                               int Foo() {
                                   if (isBar) {
                                       bar();
                                       return 1;
                                   } else
                                       return 0;
                               }
                           }
                        
linux
                           namespace foospace
                           {
                                   int Foo()
                                   {
                                           if (isBar) {
                                                   bar();
                                                   return 1;
                                           } else
                                                   return 0;
                                   }
                           }
                        
gnu
                           namespace foospace
                           {
                               int Foo()
                               {
                                   if (isBar)
                                   {
                                       bar();
                                       return 1;
                                   }
                                   else
                                   return 0;
                               }
                           }
                        
java
                           class foospace {
                               int Foo() {
                                   if (isBar) {
                                       bar();
                                       return 1;
                                   } else
                                       return 0;
                               }
                           }
                        
NAnt
                           namespace foospace {
                               class foo() {
                           #region Protected Static Fields
                                   private int Foo() {
                                       if (isBar) {
                                           bar();
                                           return 1;
                                       } else {
                                           return 0;
                                       }
                                   }
                           #endregion
                           }
                        
False
suffixstring The suffix to append to original files, defaults to .orig if not specified. False
failonerrorbool Determines if task failure stops the build, or is just reported. The default is true. False
ifbool If true then the task will be executed; otherwise, skipped. The default is true. False
timeoutint The maximum amount of time the application is allowed to execute, expressed in milliseconds. Defaults to no time-out. False
unlessbool Opposite of if. If false then the task will be executed; otherwise, skipped. The default is false. False
verbosebool Determines whether the task should report detailed build log messages. The default is false. False

Framework-configurable parameters

AttributeTypeDescriptionRequired
exenamestring The name of the executable that should be used to launch the external program. False
managedManagedExecution Specifies whether the external program should be treated as a managed application, possibly forcing it to be executed under the currently targeted version of the CLR. False
useruntimeengineboolDeprecated. Specifies whether the external program is a managed application which should be executed using a runtime engine, if configured. The default is false. False

Nested Elements:

<fileset>

Used to select the files to copy.

</fileset>

<arg>

The command-line arguments for the external program.

Represents a command-line argument.

When passed to an external application, the argument will be quoted when appropriate. This does not apply to the line parameter, which is always passed as is.

Parameters

AttributeTypeDescriptionRequired
dirdirectory The value for a directory-based command-line argument; will be replaced with the absolute path of the directory. False
filefile The name of a file as a single command-line argument; will be replaced with the absolute filename of the file. False
ifbool Indicates if the argument should be passed to the external program. If true then the argument will be passed; otherwise, skipped. The default is true. False
linestring List of command-line arguments; will be passed to the executable as is. False
path<path> The value for a PATH-like command-line argument; you can use : or ; as path separators and NAnt will convert it to the platform's local conventions, while resolving references to environment variables. False
unlessbool Indicates if the argument should not be passed to the external program. If false then the argument will be passed; otherwise, skipped. The default is false. False
valuestring A single command-line argument; can contain space characters. False

Nested Elements:

<path>

Sets a single command-line argument and treats it like a PATH - ensures the right separator for the local platform is used.

</path>

Examples

</arg>

Examples

Requirements

Assembly: NAnt.Contrib.Tasks (0.91.4298.0)