[开发工具] Keil之Astyle代码格式化

[复制链接]
 楼主| pmp 发表于 2023-12-17 21:39 | 显示全部楼层 |阅读模式
  1. Usage:
  2. ------
  3.             astyle [OPTIONS] File1 File2 File3 [...]

  4.             astyle [OPTIONS] < Original > Beautified

  5.     When indenting a specific file, the resulting indented file RETAINS
  6.     the original file-name. The original pre-indented file is renamed,
  7.     with a suffix of '.orig' added to the original filename.

  8.     Wildcards (* and ?) may be used in the filename.
  9.     A 'recursive' option can process directories recursively.
  10.     Multiple file extensions may be separated by a comma.

  11.     By default, astyle is set up to indent with four spaces per indent,
  12.     a maximal indentation of 40 spaces inside continuous statements,
  13.     a minimum indentation of eight spaces inside conditional statements,
  14.     and NO formatting options.

  15. Options:
  16. --------
  17.     This  program  follows  the  usual  GNU  command line syntax.
  18.     Long options (starting with '--') must be written one at a time.
  19.     Short options (starting with '-') may be appended together.
  20.     Thus, -bps4 is the same as -b -p -s4.

  21. Option Files:
  22. -------------
  23.     Artistic Style looks for a default option file and/or a project
  24.     option file in the following order:
  25.     1. The command line options have precedence.
  26.     2. The project option file has precedence over the default file
  27.        o the file name indicated by the --project= command line option.
  28.        o the file named .astylerc or _ astylerc.
  29.        o the file name identified by ARTISTIC_STYLE_PROJECT_OPTIONS.
  30.        o the file is disabled by --project=none on the command line.
  31.     3. The default option file that can be used for all projects.
  32.        o the file path indicated by the --options= command line option.
  33.        o the file path indicated by ARTISTIC_STYLE_OPTIONS.
  34.        o the file named .astylerc in the HOME directory (for Linux).
  35.        o the file name astylerc in the APPDATA directory (for Windows).
  36.        o the file is disabled by --project=none on the command line.
  37.     Long options within the option files may be written without '--'.
  38.     Line-end comments begin with a '#'.

  39. Disable Formatting:
  40. -------------------
  41.     Disable Block
  42.     Blocks of code can be disabled with the comment tags *INDENT-OFF*
  43.     and *INDENT-ON*. It must be contained in a one-line comment.

  44.     Disable Line
  45.     Padding of operators can be disabled on a single line using the
  46.     comment tag *NOPAD*. It must be contained in a line-end comment.

  47. Brace Style Options:
  48. --------------------
  49.     default brace style
  50.     If no brace style is requested, the opening braces will not be
  51.     changed and closing braces will be broken from the preceding line.

  52.     --style=allman  OR  --style=bsd  OR  --style=break  OR  -A1
  53.     Allman style formatting/indenting.
  54.     Broken braces.

  55.     --style=java  OR  --style=attach  OR  -A2
  56.     Java style formatting/indenting.
  57.     Attached braces.

  58.     --style=kr  OR  --style=k&r  OR  --style=k/r  OR  -A3
  59.     Kernighan & Ritchie style formatting/indenting.
  60.     Linux braces.

  61.     --style=stroustrup  OR  -A4
  62.     Stroustrup style formatting/indenting.
  63.     Linux braces.

  64.     --style=whitesmith  OR  -A5
  65.     Whitesmith style formatting/indenting.
  66.     Broken, indented braces.
  67.     Indented class blocks and switch blocks.

  68.     --style=vtk  OR  -A15
  69.     VTK style formatting/indenting.
  70.     Broken, indented braces except for the opening braces.

  71.     --style=ratliff  OR  --style=banner  OR  -A6
  72.     Ratliff style formatting/indenting.
  73.     Attached, indented braces.

  74.     --style=gnu  OR  -A7
  75.     GNU style formatting/indenting.
  76.     Broken braces, indented blocks.

  77.     --style=linux  OR  --style=knf  OR  -A8
  78.     Linux style formatting/indenting.
  79.     Linux braces, minimum conditional indent is one-half indent.

  80.     --style=horstmann  OR  --style=run-in  OR  -A9
  81.     Horstmann style formatting/indenting.
  82.     Run-in braces, indented switches.

  83.     --style=1tbs  OR  --style=otbs  OR  -A10
  84.     One True Brace Style formatting/indenting.
  85.     Linux braces, add braces to all conditionals.

  86.     --style=google  OR  -A14
  87.     Google style formatting/indenting.
  88.     Attached braces, indented class modifiers.

  89.     --style=mozilla  OR  -A16
  90.     Mozilla style formatting/indenting.
  91.     Linux braces, with broken braces for structs and enums,
  92.     and attached braces for namespaces.

  93.     --style=pico  OR  -A11
  94.     Pico style formatting/indenting.
  95.     Run-in opening braces and attached closing braces.
  96.     Uses keep one line blocks and keep one line statements.

  97.     --style=lisp  OR  -A12
  98.     Lisp style formatting/indenting.
  99.     Attached opening braces and attached closing braces.
  100.     Uses keep one line statements.

  101. Tab Options:
  102. ------------
  103.     default indent option
  104.     If no indentation option is set, the default
  105.     option of 4 spaces per indent will be used.

  106.     --indent=spaces=#  OR  -s#
  107.     Indent using # spaces per indent. Not specifying #
  108.     will result in a default of 4 spaces per indent.

  109.     --indent=tab  OR  --indent=tab=#  OR  -t  OR  -t#
  110.     Indent using tab characters, assuming that each
  111.     indent is # spaces long. Not specifying # will result
  112.     in a default assumption of 4 spaces per indent.

  113.     --indent=force-tab=#  OR  -T#
  114.     Indent using tab characters, assuming that each
  115.     indent is # spaces long. Force tabs to be used in areas
  116.     AStyle would prefer to use spaces.

  117.     --indent=force-tab-x=#  OR  -xT#
  118.     Allows the tab length to be set to a length that is different
  119.     from the indent length. This may cause the indentation to be
  120.     a mix of both spaces and tabs. This option sets the tab length.

  121. Brace Modify Options:
  122. ---------------------
  123.     --attach-namespaces  OR  -xn
  124.     Attach braces to a namespace statement.

  125.     --attach-classes  OR  -xc
  126.     Attach braces to a class statement.

  127.     --attach-inlines  OR  -xl
  128.     Attach braces to class inline function definitions.

  129.     --attach-extern-c  OR  -xk
  130.     Attach braces to an extern "C" statement.

  131.     --attach-closing-while  OR  -xV
  132.     Attach closing while of do-while to the closing brace.

  133. Indentation Options:
  134. --------------------
  135.     --indent-classes  OR  -C
  136.     Indent 'class' blocks so that the entire block is indented.

  137.     --indent-modifiers  OR  -xG
  138.     Indent 'class' access modifiers, 'public:', 'protected:' or
  139.     'private:', one half indent. The rest of the class is not
  140.     indented.

  141.     --indent-switches  OR  -S
  142.     Indent 'switch' blocks, so that the inner 'case XXX:'
  143.     headers are indented in relation to the switch block.

  144.     --indent-cases  OR  -K
  145.     Indent case blocks from the 'case XXX:' headers.
  146.     Case statements not enclosed in blocks are NOT indented.

  147.     --indent-namespaces  OR  -N
  148.     Indent the contents of namespace blocks.

  149.     --indent-after-parens  OR  -xU
  150.     Indent, instead of align, continuation lines following lines
  151.     that contain an opening paren '(' or an assignment '='.

  152.     --indent-continuation=#  OR  -xt#
  153.     Indent continuation lines an additional # indents.
  154.     The valid values are 0 thru 4 indents.
  155.     The default value is 1 indent.

  156.     --indent-labels  OR  -L
  157.     Indent labels so that they appear one indent less than
  158.     the current indentation level, rather than being
  159.     flushed completely to the left (which is the default).

  160.     --indent-preproc-block  OR  -xW
  161.     Indent preprocessor blocks at brace level 0.
  162.     Without this option the preprocessor block is not indented.

  163.     --indent-preproc-cond  OR  -xw
  164.     Indent preprocessor conditional statements #if/#else/#endif
  165.     to the same level as the source code.

  166.     --indent-preproc-define  OR  -w
  167.     Indent multi-line preprocessor #define statements.

  168.     --indent-col1-comments  OR  -Y
  169.     Indent line comments that start in column one.

  170.     --min-conditional-indent=#  OR  -m#
  171.     Indent a minimal # spaces in a continuous conditional
  172.     belonging to a conditional header.
  173.     The valid values are:
  174.     0 - no minimal indent.
  175.     1 - indent at least one additional indent.
  176.     2 - indent at least two additional indents.
  177.     3 - indent at least one-half an additional indent.
  178.     The default value is 2, two additional indents.

  179.     --max-continuation-indent=#  OR  -M#
  180.     Indent a maximal # spaces in a continuation line,
  181.     relative to the previous line.
  182.     The valid values are 40 thru 120.
  183.     The default value is 40.

  184. Padding Options:
  185. ----------------
  186.     --break-blocks  OR  -f
  187.     Insert empty lines around unrelated blocks, labels, classes, ...

  188.     --break-blocks=all  OR  -F
  189.     Like --break-blocks, except also insert empty lines
  190.     around closing headers (e.g. 'else', 'catch', ...).

  191.     --pad-oper  OR  -p
  192.     Insert space padding around operators.

  193.     --pad-comma  OR  -xg
  194.     Insert space padding after commas.

  195.     --pad-paren  OR  -P
  196.     Insert space padding around parenthesis on both the outside
  197.     and the inside.

  198.     --pad-paren-out  OR  -d
  199.     Insert space padding around parenthesis on the outside only.

  200.     --pad-first-paren-out  OR  -xd
  201.     Insert space padding around first parenthesis in a series on
  202.     the outside only.

  203.     --pad-paren-in  OR  -D
  204.     Insert space padding around parenthesis on the inside only.

  205.     --pad-header  OR  -H
  206.     Insert space padding after paren headers (e.g. 'if', 'for'...).

  207.     --unpad-paren  OR  -U
  208.     Remove unnecessary space padding around parenthesis. This
  209.     can be used in combination with the 'pad' options above.

  210.     --delete-empty-lines  OR  -xd
  211.     Delete empty lines within a function or method.
  212.     It will NOT delete lines added by the break-blocks options.

  213.     --fill-empty-lines  OR  -E
  214.     Fill empty lines with the white space of their
  215.     previous lines.

  216.     --align-pointer=type    OR  -k1
  217.     --align-pointer=middle  OR  -k2
  218.     --align-pointer=name    OR  -k3
  219.     Attach a pointer or reference operator (*, &, or ^) to either
  220.     the operator type (left), middle, or operator name (right).
  221.     To align the reference separately use --align-reference.

  222.     --align-reference=none    OR  -W0
  223.     --align-reference=type    OR  -W1
  224.     --align-reference=middle  OR  -W2
  225.     --align-reference=name    OR  -W3
  226.     Attach a reference operator (&) to either
  227.     the operator type (left), middle, or operator name (right).
  228.     If not set, follow pointer alignment.

  229. Formatting Options:
  230. -------------------
  231.     --break-closing-braces  OR  -y
  232.     Break braces before closing headers (e.g. 'else', 'catch', ...).
  233.     Use with --style=java, --style=kr, --style=stroustrup,
  234.     --style=linux, or --style=1tbs.

  235.     --break-elseifs  OR  -e
  236.     Break 'else if()' statements into two different lines.

  237.     --break-one-line-headers  OR  -xb
  238.     Break one line headers (e.g. 'if', 'while', 'else', ...) from a
  239.     statement residing on the same line.

  240.     --add-braces  OR  -j
  241.     Add braces to unbraced one line conditional statements.

  242.     --add-one-line-braces  OR  -J
  243.     Add one line braces to unbraced one line conditional
  244.     statements.

  245.     --remove-braces  OR  -xj
  246.     Remove braces from a braced one line conditional statements.

  247.     --break-return-type       OR  -xB
  248.     --break-return-type-decl  OR  -xD
  249.     Break the return type from the function name. Options are
  250.     for the function definitions and the function declarations.

  251.     --attach-return-type       OR  -xf
  252.     --attach-return-type-decl  OR  -xh
  253.     Attach the return type to the function name. Options are
  254.     for the function definitions and the function declarations.

  255.     --keep-one-line-blocks  OR  -O
  256.     Don't break blocks residing completely on one line.

  257.     --keep-one-line-statements  OR  -o
  258.     Don't break lines containing multiple statements into
  259.     multiple single-statement lines.

  260.     --convert-tabs  OR  -c
  261.     Convert tabs to the appropriate number of spaces.

  262.     --close-templates  OR  -xy
  263.     Close ending angle brackets on template definitions.

  264.     --remove-comment-prefix  OR  -xp
  265.     Remove the leading '*' prefix on multi-line comments and
  266.     indent the comment text one indent.

  267.     --max-code-length=#    OR  -xC#
  268.     --break-after-logical  OR  -xL
  269.     max-code-length=# will break the line if it exceeds more than
  270.     # characters. The valid values are 50 thru 200.


您需要登录后才可以回帖 登录 | 注册

本版积分规则

pmp

186

主题

7773

帖子

8

粉丝
快速回复 返回顶部 返回列表