📄 astyle.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <title>Artistic Style</title> <meta http-equiv="Content-Type" content="text/html; charset=us-ascii" /> <meta http-equiv="Content-Language" content="EN" /> <meta name="description" content="Artistic Style is a source code indenter, source code formatter, and source code beautifier for the C, C++, C# and Java programming languages." /> <meta name="keywords" content="artistic style, astyle, source code indenter, source code formatter, source code beautifier" /> <style type="text/css"> /*<![CDATA[*/ <!-- body {margin-top:0.5in; margin-right:0.8in; margin-bottom:0.5in; margin-left:1.3in;} h1 {color:#0000a0; margin-top:18pt; text-align:center; font-style:italic; font-size:250%} h2 {color:#0000A0; font-size:130%; margin-top:0.4in; margin-left:-0.4in;} h3 {color:#0000A0;} h4 {font-size:105%; margin-left:0.4in;} div.options {margin-left:0.4in;} div.code {margin-left:0.4in; margin-right:0.4in;} code {color:navy;} code.title {font-size:larger; font-weight:bold;} pre {color:navy; font-weight:bold;} span.brace {color:red;} span.comment {color:dimgray} span.option {color:saddlebrown} p {font-size:105%;} p.contents1 { margin-top:0in; margin-left:0in; margin-bottom:0in; margin-right:0in; font-size:105%; } p.contents2 { margin-top:0in; margin-left:.4in; margin-bottom:0in; margin-right:.4in; } p.contents3 { margin-top:0in; margin-left:.8in; margin-bottom:0in; margin-right:.8in; } a:link, a:visited { color:blue; text-decoration:none; } a:hover { color:#F00000; text-decoration:none; } --> /*]]>*/ </style></head><body lang="EN"> <!-- CUT HERE FOR INSERTION INTO SOURCEFORGE DOC MANAGER --> <!-- $Id: astyle.html,v 1.28 2004/07/20 04:26:28 devsolar Exp $ --> <h1>Artistic Style 1.22</h1> <h1 style="font-size:125%; font-style:normal">A Free, Fast and Small Automatic Formatter<br /> for C, C++, C#, and Java Source Code</h1> <h2 id="Contents">Contents</h2> <p class="contents1"><a href="#_General_Information">General Information</a></p> <p class="contents1"><a href="#_Usage">Usage</a></p> <p class="contents1"><a href="#_Options_File">Options File</a></p> <p class="contents1"><a href="#_Options">Options</a></p> <p class="contents2"> <a href="#_Predefined_Style_Options">Predefined Style Options</a></p> <p class="contents3"><a href="#_style=ansi">style=ansi</a> <a href="#_style=gnu">style=gnu</a> <a href="#_style=kr">style=kr</a> <a href="#_style=linux">style=linux</a> <a href="#_style=java">style=java</a> </p> <p class="contents2"> <a href="#_Tab_and_Bracket_Options">Tab and Bracket Options</a></p> <p class="contents3"><a href="#_default_indent">default indent</a> <a href="#_indent=spaces">indent=spaces</a> <a href="#_indent=tab">indent=tab</a> <a href="#_force-indent=tab">force‑indent=tab</a> <a href="#_default_brackets">default brackets</a> <a href="#_brackets=break">brackets=break</a> <a href="#_brackets=attach">brackets=attach</a> <a href="#_brackets=linux">brackets=linux</a> <a href="#_brackets=break-closing">brackets=break‑closing</a> </p> <p class="contents2"><a href="#_Indentation_Options">Indentation Options</a></p> <p class="contents3"><a href="#_indent-classes">indent‑classes</a> <a href="#_indent-switches">indent‑switches</a> <a href="#_indent-cases">indent‑cases</a> <a href="#_indent-blocks">indent‑blocks</a> <a href="#_indent-brackets">indent‑brackets</a> <a href="#_indent-namespaces">indent‑namespaces</a> <a href="#_indent-labels">indent‑labels</a> <a href="#_indent-preprocessor">indent‑preprocessor</a> <a href="#_max-instatement-indent">max‑instatement‑indent</a> <a href="#_min-conditional-indent">min‑conditional‑indent</a> </p> <p class="contents2"><a class="toc1" href="#_Formatting_Options">Formatting Options</a></p> <p class="contents3"><a href="#_break-blocks">break‑blocks</a> <a href="#_break-blocks=all">break‑blocks=all</a> <a href="#_break-elseifs">break‑elseifs</a> <a href="#_pad=oper">pad=oper</a> <a href="#_pad=paren">pad=paren</a> <a href="#_pad=paren-out">pad=paren‑out</a> <a href="#_pad=paren-in">pad=paren‑in</a> <a href="#_unpad=paren">unpad=paren</a> <a href="#_one-line=keep-statements">one‑line=keep‑statements</a> <a href="#_one-line=keep-blocks">one‑line=keep‑blocks</a> <a href="#_convert-tabs">convert‑tabs</a> <a href="#_fill-empty-lines">fill‑empty‑lines</a> <a href="#_mode=c">mode=c</a> <a href="#_mode=java">mode=java</a> <a href="#_mode=cs">mode=cs</a> </p> <p class="contents2"><a class="toc1" href="#_Other_Options">Other Options</a></p> <p class="contents3"><a href="#_suffix">suffix</a> <a href="#_suffix=none">suffix=none</a> <a href="#_options">options</a> <a href="#_options=none">options=none</a> <a href="#_recursive">recursive</a> <a href="#_exclude">exclude</a> <a href="#_errors-to-stdout">errors‑to‑stdout</a> <a href="#_preserve-date">preserve‑date</a> <a href="#_verbose">verbose</a> <a href="#_quiet">quiet</a> <a href="#_version">version</a> <a href="#_help">help</a> </p> <h2 id="_General_Information">General Information</h2> <p><b>Line Endings</b><br /> Line endings in the formatted file will be the same as the input file. If there are mixed line endings the most frequent occurrence will be used.</p> <p><b>File Type</b><br /> Artistic Style will determine the file type from the file extension. The extension ".java" indicates a Java file, and ".cs" indicates a C# file. Everything else is a C or C++ file. If you are using a non-standard file extension for Java or C#, use one of the <code>--mode=</code> options described in "Formatting Options".</p> <p><b></b><strong>Wildcards and Recursion</strong><br /> <span id="obmessage">Artistic Style can process directories recursively and wildcards 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 filename contains wildcards. For Windows use double quotes around paths whose filename contains spaces. The "Other Options" section contains information on recursive processing.</span></p> <p> <b>Quick Start</b><br /> If you have never used Artistic Style there are a couple of ways to start. One is to run it with no options at all. This will format the file with 4 spaces per indent and will leave the brackets unchanged. Another is to use one of the predefined styles described in the "Predefined Style Options". Select one with a bracket formatting style you like. Once you are familiar with the options you can customize the format to your personal preference.</p> <h2 id="_Usage">Usage</h2> <p>Artistic style is a console program that receives information from the command line. The format of the command line is:</p> <pre>astyle [options] <em>SourceFile1 SourceFile2 SourceFile3</em> [ . . . ]</pre> <p>Or to save the file with a different name:</p> <pre>astyle [options] < <em>OriginalSourceFile</em> > <em>BeautifiedSourceFile</em></pre> <p>The <span style="color:#0000a0"><</span> and <span style="color:#0000a0">></span> characters are used to redirect the files into standard input and out of standard output - don't forget them!</p> <p>The block parens [ ] indicate that more than one option or more than one filename can be entered. They are NOT actually included in the command. For the options format see the following Options section.</p> <p>With the first option, the newly indented file <strong>retains the original file name</strong>, while a copy of the original file is created with an <code><strong>.orig</strong></code> appended to the original file name. (This can be set to a different string by the option <code>--suffix=</code>, or suppressed altogether by the options <code>-n</code> or <code>--suffix=none</code>). Thus, after indenting <code><em>SourceFile1.cpp</em></code> as above, the indented result will be named <code><em>SourceFile1.cpp</em></code>, while the original pre-indented file will be renamed to <code><em>SourceFile1.cpp.orig</em></code>.</p> <p>With the second option, the file is saved with a different name. Therefore a copy is <strong>not</strong> created.</p> <p><code><b>Wildcards</b></code> (such as "*.cpp"), can be used if the project is compiled to include them. See the Installation Information for instructions.</p> <h2 id="_Options_File">Options File</h2> <p>A <span style="color:#0000a0">default options file</span> may be used to set your favorite source style.</p> <ul> <li>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.</li> <li> Artistic Style looks for this file in the following locations (in order): <ol> <li>the file indicated by the <strong>--options=</strong> command line option;</li> <li>the <b>file</b> and <b>directory</b> indicated by the environment variable <strong>ARTISTIC_STYLE_OPTIONS</strong> (if it exists);</li> <li>the file named <strong>.astylerc</strong> in the directory pointed to by the <strong>HOME</strong> environment variable (e.g. "<strong>$HOME/.astylerc</strong>" on Linux);</li> <li>the file named <strong>astylerc</strong> in the directory pointed to by the <strong>USERPROFILE</strong> environment variable (e.g. "<strong>%USERPROFILE%\astylerc</strong>" on Windows).</li> </ol> </li> <li>This option file lookup can be disabled by specifying <code>--options=none</code> on the command line.</li> <li>Options may be set apart by new-lines, tabs or spaces.</li> <li>Long options <strong>in the options file</strong> may be written <strong>without</strong> the preceding '<strong>--</strong>'.</li> <li>Lines within the options file that begin with '<strong>#</strong>' are considered <strong>line-comments</strong>.</li> <li> Example of a default options file: <div class="code"> <pre><span class="comment"># brackets should be attached to pre-bracket lines</span>brackets=attach<span class="comment"># set 6 spaces per indent</span>indent=spaces=6<span class="comment"># indent switch blocks</span>indent-switches<span class="comment"># suffix of original files should be .pre</span>suffix=.pre</pre> </div> </li> </ul> <h2 id="_Options">Options</h2> <p>Not specifying any option will result in 4 spaces per indent, no change in bracket placement, and no formatting changes.</p> <p>Options may be written in two different ways:</p> <ul> <li><strong>Long options:</strong><br /> These options start with '<strong><code>--</code></strong>', and <strong>must be written one at a time.</strong><br /> (Example: '<code>--brackets=attach --indent=spaces=4</code>')</li> <li><strong>Short Options:</strong><br /> These options start with a single '<strong><code>-</code></strong>', and <strong>may be concatenated together</strong>.<br /> (Example: '<code>-bps4</code>' is the same as writing '<code>-b -p -s4</code>'.)</li> </ul> <p> </p> <hr /> <h3 id="_Predefined_Style_Options">Predefined Style Options</h3> <p>Predefined Style options define the style by setting several other options. If other options are also used, the placement of the predefined style option in the command line is important. If the predefined style option is placed first, the other options may override the predefined style. If placed last, the predefined style will override the other options.</p> <p>For example the style --style=ansi sets the option --brackets=break. If the command line specifies "--style=ansi --brackets=attach", the brackets will be attached and the style will not be ansi style. If the order on the command line is reversed to "--brackets=attach --style=ansi ", the brackets will be broken (ansi style) and the attach option will be ignored.</p> <p>For the options set by each style check the parseOption function in astyle_main.cpp.</p> <div class="options"> <p id="_style=ansi"><code class="title">--style=ansi</code><br /> ANSI style formatting/indenting. Brackets are broken, indentation is 4 spaces. Namespaces, classes, and switches are NOT indented.</p> <div class="code"> <pre>namespace foospace<span class="brace">{</span>int Foo()<span class="brace">{</span> if (isBar)<span class="brace"> {</span> bar(); return 1;<span class="brace"> }</span> else return 0;<span class="brace">}}</span></pre> </div> <p> </p> <p id="_style=gnu"><code class="title">--style=gnu</code><br /> GNU style formatting/indenting. Brackets are broken, blocks are indented, and indentation is 2 spaces. Namespaces, classes, and switches are NOT indented.</p> <div class="code"> <pre>namespace foospace<span class="brace"> {</span> int Foo()<span class="brace"> {</span> if (isBar)<span class="brace"> {</span> bar(); return 1;<span class="brace"> }</span> else return 0;<span class="brace"> } }</span></pre> </div> <p> </p> <p id="_style=kr"><code class="title">--style=kr</code><br /> Kernighan & Ritchie style formatting/indenting. Brackets are attached, indentation is 4 spaces. Namespaces, classes, and switches are NOT indented.</p> <div class="code"> <pre>namespace foospace <span class="brace">{</span>int Foo() <span class="brace">{</span> if (isBar) <span class="brace">{</span> bar(); return 1;<span class="brace"> }</span> else return 0;<span class="brace">}}</span></pre> </div> <p> </p> <p id="_style=linux"><code class="title">--style=linux</code><br /> Linux style formatting/indenting. All brackets are linux style, indentation is 8 spaces. Namespaces, classes, and switches are NOT indented.</p> <div class="code"> <pre>namespace foospace<span class="brace">{</span>int Foo()<span class="brace">{</span> if (isBar) <span class="brace">{</span> bar(); return 1;<span class="brace"> }</span> else return 0;<span class="brace">}}</span></pre> </div> <p> </p> <p id="_style=java"><code class="title">--style=java</code><br /> Java style formatting/indenting. Brackets are attached, indentation is 4 spaces. Switches are NOT indented.</p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -