Linux Code formatting Tool Indent__linux

Source: Internet
Author: User
Tags case statement coding standards function definition logical operators memory usage nfca

Linux kernel has a script lindent, nothing can be installed,

sudo apt-get install indent

can help you format your code with a good code style.
such as:/usr/src/linux-headers-2.6.22-14/scripts/lindent

Common settings:
Indent-npro-kr-i4-ts4-sob-l80-ss-bl-bli 0

(This style I like)

Parameter description:
-npro or--ignore-profile do not read the indent configuration file. Indent.pro.
-KR specifies the format for using Kernighan&ritchie. Can be changed to-ORIG,BSD style
-I4--indent-level Sets the number of rows indented to 4.
-TS4 to set tab length
-sob or--swallow-optional-blank-lines delete extra blank lines.
-L80 code more than 80 line wrap
-ss or--space-special-semicolon If the for section has only one row, add a space before the semicolon.
-ncs or--no-space-after-casts do not empty one after cast.
-BL {Branch Show
-bli 0 Brackets indent to 0

I am more commonly used is:

indent-npro-nip-nlp-npsl-i4-ts4-sob-l200-ss-bl-bli 0 code file name


Function Description: Adjust the format of C source code file.

Syntax: indent [parameter] [source file] or indent [parameter] [source file][-o target file]

Supplemental Note: Indent can identify the original code file of C, and format it to facilitate the program designer to read.

Parameters
-bad or--blank-lines-after-declarations in the Declaration section or plus a blank line.
-BAP or--blank-lines-after-procedures in the program or add a blank line.
-BBB or--blank-lines-after-block-comments adds a blank line after the annotation section.
-BC or--blank-lines-after-commas in the Declaration section, the line wraps if a comma occurs.
-BL or--braces-after-if-line if (or else,for, and so on) are not peers with "{" In the following execution section, and "}" is a row.
-bli< the number of rows indented > or--brace-indent< the number of cells > set {}.
-BR or--braces-on-if-line if (or else,for, and so on) do not walk with "{" with the trailing limp and "}" from one line.
-bs or--blank-before-sizeof is empty after sizeof.
-c< number of columns > or--comment-indentation< > Place comments in the field specified on the right side of the code.
-cd< number of columns > or--declaration-comment-column< > Place comments in the field specified on the right side of the declaration.
-cdb or--comment-delimiters-on-blank-lines annotation symbols from one line.
-ce or--cuddle-else to place else after "}" (the end of the If Execution section).
-ci< the number of indented cells > or--continuation-indentation< the number of indented lines > The number of rows indented after wrapping.
-cli< number of indents > or--case-indentation-< > Number of cells in the switch indent when using case.
-cp< number of columns > or-else-endif-column< > Place comments in the field that is set to the right of the else and ElseIf narration.
-cs or--space-after-cast is empty after cast.
-d< indent number > or-line-comments-indentation< number of indents > sets the number of indents for comments that are not on the right side of the program code.
-di< number of columns > or--declaration-indentation< > Place the variable of the declaration section in the specified field.
-FC1 or--format-first-column-comments Formats the comments that are placed at the front of each line.
-FCA or--format-all-comments to format all annotations.
-gnu or--gnu-style. Specifies the use of the GNU format, which is a preset value.
-i< > or--indent-level< number > sets the number of rows to indent.
-ip< > or--parameter-indentation< > Set the number of indents for the parameter.
-kr or--k-and-r-style. Specifies the format to use Kernighan&ritchie.
-lp or--continue-at-parentheses the narration is too long to wrap, and when the narration contains parentheses, the beginning field of each line in parentheses is arranged vertically.
-nbad or--no-blank-lines-after-declarations do not add blank lines after declaring the section.
-NBAP or--no-blank-lines-after-procedures do not add blank lines after the program.
-NBBB or--no-blank-lines-after-block-comments do not add blank lines after the annotation section.
-NBC or--no-blank-lines-after-commas in the Declaration section, do not wrap the line even if a comma appears.
-ncdb or--no-comment-delimiters-on-blank-lines annotation symbols do not come from one line.
-nce or--dont-cuddle-else do not place else after "}".
-ncs or--no-space-after-casts do not empty one after cast.
-NFC1 or--dont-format-first-column-comments do not format comments that are placed at the front of each line.
-NFCA or--dont-format-comments do not format any comments.
Do not indent-nip or--no-parameter-indentation parameters.
-NLP or--dont-line-up-parentheses the narration is too long to wrap, and when the narration contains parentheses, you do not have to arrange the starting field of each line in parentheses vertically.
-npcs or--no-space-after-function-call-names after the name of the function you called, do not add a space.
-npro or--ignore-profile do not read the indent configuration file. Indent.pro.
The-NPSL or--dont-break-procedure-type program type is placed on the same line as the program name.
Do not add an asterisk (*) to the left of the-NSC or--dont-star-comments annotations.
-nsob or--leave-optional-semicolon do not have to handle extra blank lines.
-nss or--dont-space-special-semicolon if the for or while section has only one row, the top of the semicolon is not added.
-NV or--no-verbosity do not display detailed information.
-orig or--original use the Berkeley format.
-pcs or--space-after-procedure-calls adds a space between the called function name and "{".
The-PSL or--procnames-start-lines program type is placed in the previous line of the program name.
-SC or--start-left-side-of-comments adds an asterisk (*) to the left of each line of comments.
-sob or--swallow-optional-blank-lines delete extra blank lines.
-ss or--space-special-semicolon if the for or Swile section has a row, add a space before the semicolon.
-st or--standard-output displays the results in a standard output device.
-T data type name indent.
Number of-ts< > or--tab-size< > Set tab length.
The-V or--verbose displays detailed information when executed.
-version Displays version information.

Alias myindent= ' Indent-npro-kr-bl-nce-bli0-i2-ts2-sob-l80-nfc1-ss-ncs ' Common styles

There are several common styles of C code, including the GNU style, the Kernighan & Ritchie style, and the original be Rkeley style. A style may is selected with a single background option, which specifies a set of values to all other options. However, explicitly specified options always override options implied by a background option.

As of version 1.2, the default style of GNU indent is the GNU style. Thus, it is no longer necessary to specify the option '-gnu ' to obtain this format, although doing so won't be cause an ER Ror. Option settings which correspond to the GNU style are:


<strong><em><span style= "FONT-SIZE:18PX;" >-nbad-bap-nbc-bbo-bl-bli2-bls-ncdb-nce-cp1-cs-di2
-ndj-nfc1-nfca-hnl-i2-ip5-lp-pcs-nprs-psl-s Af-sai
-saw-nsc-nsob
</span></em></strong>

The GNU coding style is this preferred by the GNU project. It is the style that GNU Emacs C mode encourages and which are used in the C portions of GNU Emacs. (People interested in writing programs for Project GNU should get a copy of the GNU Coding Standards, which also Covers semantic and portability issues such as memory usage, the size of integers, etc.)

The Kernighan & Ritchie style is used throughout their well-known book The C programmingLanguage. It is enabled with the '-kr ' option. The Kernighan & Ritchie style corresponds to the following set of options:


<strong><em><span style= "FONT-SIZE:18PX;" >-nbad-bap-bbo-nbc-br-brs-c33-cd33-ncdb-ce-ci4-cli0
-cp33-cs-d0-di1-nfc1-nfca-hnl-i4-ip0-l75-l P-npcs
-nprs-npsl-saf-sai-saw-nsc-nsob-nss</span></em></strong>

Kernighan & Ritchie Style does not put comments to the right of code in the same column at all times (nor does it use Only one spaces to the right of the code), so for this style indent has arbitrarily chosen column 33.

The style of the original Berkeley indent May is obtained by specifying '-orig ' (or by specifying '--original ', using the Long option name). This style is equivalent to the following settings:


<em><strong><span style= "FONT-SIZE:18PX;" >-nbad-nbap-bbo-bc-br-brs-c33-cd33-cdb-ce-ci4-cli0
-cp33-di16-fc1-fca-hnl-i4-ip4-l75-lp-npcs-n PRS-PSL
-saf-sai-saw-sc-nsob-nss-ts8
</span></strong></em>

The Linux style is used in the Linux kernel code and drivers. The Code generally has to follow the Linux coding style to is accepted. This style is equivalent to the following settings:


<em><strong><span style= "FONT-SIZE:18PX;" >-nbad-bap-nbc-bbo-hnl-br-brs-c33-cd33-ncdb-ce-ci4 
-cli0-d0-di1-nfc1-i8-ip0-l80-lp-npcs-nprs-n Psl-sai
-saf-saw-ncs-nsc-sob-nfca-cp33-ss-ts8-il1
</span></strong></em>

table 1. Indent Code Format Description

indent parameters to use value meaning
--blank-lines-after-declarations Bad Add blank line after variable declaration
--blank-lines-after-procedures Bap Add blank line after function ends
--blank-lines-before-block-comments Bbb Block comment before adding blank lines
--break-before-boolean-operator Bbo Longer lines, in front of logical operators branch
--blank-lines-after-commas Nbc Variable declaration, comma-delimited variable not branch
--braces-after-if-line Bl "If" and "{" are divided into two lines
--brace-indent 0 Bli0 ' {' does not continue indent
--braces-after-struct-decl-line Bls Define structure, "struct" and "{" Branch
--comment-indentationn C33 Statement after the comment starts at line 33
--declaration-comment-columnn Cd33 The comment starts at line 33 after the variable declaration
--comment-delimiters-on-blank-lines Ncdb Do not change single-line comment to block comment
--cuddle-do-while Ncdw "While" and "}" in front of "do---while" another row
--cuddle-else nCE "Else" and "}" in front of it, another row
--case-indentation 0 Cli0 0 spaces in a case statement in a switch
--else-endif-columnn Cp33 #else, #endif后面的注释开始于行33
--space-after-cast Cs Add a space after the type conversion
--line-comments-indentation N D0 Single-line comment (not starting from 1 columns), not indented to the left
--break-function-decl-args Nbfda Off: parameter of function a row
--declaration-indentationn Di2 Variable declaration, the variable starts at line 2, which is not justified
--format-first-column-comments Nfc1 Do not format comments from the first line
--format-all-comments Nfca Switch that does not open all formatted annotations
--honour-newlines Hnl Prefer to break long lines at the position of newlines in the input.
--indent-leveln I4 Set how many characters to indent, if tab is an integral number of times, indent with tab, otherwise fill with a space.
--parameter-indentationn Ip5 The parameter description in the function definition of the old style indents 5 spaces
--line-length 75 L75 Non-comment lines up to 75
--continue-at-parentheses Lp Continuation lines begin with parentheses that appear on the previous line
--space-after-procedure-calls Pcs Insert a space between the function and "(")
--space-after-parentheses Nprs Do not insert spaces before "(after")
--procnames-start-lines Psl Place the function name and return type in two-line definitions
--space-after-for Saf For a space after
--space-after-if Sai If there are spaces behind
--space-after-while Saw While there are spaces behind
--start-left-side-of-comments Nsc Do not add * in the generated block comment
--swallow-optional-blank-lines Nsob Do not remove the blank lines that can be added
--space-special-semicolon Nss A for or a while statement of a row, in the ";" No extra space before.
--tab-size Ts4 One tab is 4 spaces (to divide "-in")
--use-tabs Ut Use tab to indent

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.