mywiki:linux:linux_soding_style
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| mywiki:linux:linux_soding_style [2014/09/28 07:18] – shaoguoh | mywiki:linux:linux_soding_style [2022/04/02 17:29] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 7: | Line 7: | ||
| Basically there are two tools for formatting the code: indent and astyle | Basically there are two tools for formatting the code: indent and astyle | ||
| ===== indent ===== | ===== indent ===== | ||
| - | The indent program, an excellent GNU utility found on most Linux systems, formats source according to given rules. | + | The indent program, an excellent GNU utility found on most Linux systems, formats source according to given rules. |
| The default settings are for the GNU coding style, which is not too pretty. | The default settings are for the GNU coding style, which is not too pretty. | ||
| To get the utility to follow the Linux kernel style, the simple usage is : | To get the utility to follow the Linux kernel style, the simple usage is : | ||
| - | < | + | |
| - | For details, below setting | + | Note: -l is new as of version 2.1 however and not very intelligent or flexible yet. |
| + | |||
| + | Maybe need to add " | ||
| + | |||
| + | |||
| + | |||
| + | The **K**ernighan & **R**itchie style corresponds to the following set of options: | ||
| + | < | ||
| + | -nbad -bap -bbo -nbc -br -brs -c33 -cd33 -ncdb -ce -ci4 -cli0 | ||
| + | -cp33 -cs -d0 -di1 -nfc1 -nfca -hnl -i4 -ip0 -l75 -lp -npcs | ||
| + | -nprs -npsl -saf -sai -saw -nsc -nsob -nss | ||
| + | </ | ||
| + | |||
| + | This Linux style (-linux, --linux-style ) is equivalent to the following settings: | ||
| < | < | ||
| -nbad -bap -nbc -bbo -hnl -br -brs -c33 -cd33 -ncdb -ce -ci4 | -nbad -bap -nbc -bbo -hnl -br -brs -c33 -cd33 -ncdb -ce -ci4 | ||
| Line 20: | Line 33: | ||
| -saf -saw -ncs -nsc -sob -nfca -cp33 -ss -ts8 -il1 | -saf -saw -ncs -nsc -sob -nfca -cp33 -ss -ts8 -il1 | ||
| </ | </ | ||
| + | |||
| + | |||
| | -kr | The C Programming Language\\ | | -kr | The C Programming Language\\ | ||
| Line 64: | Line 79: | ||
| | -il1 | | | | -il1 | | | ||
| + | ==== Options' | ||
| + | |||
| + | Here is a list of options alphabetized by long option, to help you find the corresponding short option. | ||
| + | < | ||
| + | --blank-lines-after-commas | ||
| + | --blank-lines-after-declarations | ||
| + | --blank-lines-after-procedures | ||
| + | --blank-lines-before-block-comments | ||
| + | --braces-after-if-line | ||
| + | --braces-after-func-def-line | ||
| + | --brace-indent | ||
| + | --braces-after-struct-decl-line | ||
| + | --braces-on-if-line | ||
| + | --braces-on-func-def-line | ||
| + | --braces-on-struct-decl-line | ||
| + | --break-after-boolean-operator | ||
| + | --break-before-boolean-operator | ||
| + | --break-function-decl-args | ||
| + | --break-function-decl-args-end | ||
| + | --case-indentation | ||
| + | --case-brace-indentation | ||
| + | --comment-delimiters-on-blank-lines | ||
| + | --comment-indentation | ||
| + | --continuation-indentation | ||
| + | --continue-at-parentheses | ||
| + | --cuddle-do-while | ||
| + | --cuddle-else | ||
| + | --declaration-comment-column | ||
| + | --declaration-indentation | ||
| + | --dont-break-function-decl-args | ||
| + | --dont-break-function-decl-args-end | ||
| + | --dont-break-procedure-type | ||
| + | --dont-cuddle-do-while | ||
| + | --dont-cuddle-else | ||
| + | --dont-format-comments | ||
| + | --dont-format-first-column-comments | ||
| + | --dont-line-up-parentheses | ||
| + | --dont-left-justify-declarations | ||
| + | --dont-space-special-semicolon | ||
| + | --dont-star-comments | ||
| + | --else-endif-column | ||
| + | --format-all-comments | ||
| + | --format-first-column-comments | ||
| + | --gnu-style | ||
| + | --honour-newlines | ||
| + | --ignore-newlines | ||
| + | --ignore-profile | ||
| + | --indent-label | ||
| + | --indent-level | ||
| + | --k-and-r-style | ||
| + | --leave-optional-blank-lines | ||
| + | --leave-preprocessor-space | ||
| + | --left-justify-declarations | ||
| + | --line-comments-indentation | ||
| + | --line-length | ||
| + | --linux-style | ||
| + | --no-blank-lines-after-commas | ||
| + | --no-blank-lines-after-declarations | ||
| + | --no-blank-lines-after-procedures | ||
| + | --no-blank-lines-before-block-comments | ||
| + | --no-comment-delimiters-on-blank-lines | ||
| + | --no-space-after-casts | ||
| + | --no-parameter-indentation | ||
| + | --no-space-after-for -nsaf | ||
| + | --no-space-after-function-call-names | ||
| + | --no-space-after-if -nsai | ||
| + | --no-space-after-parentheses | ||
| + | --no-space-after-while -nsaw | ||
| + | --no-tabs | ||
| + | --no-verbosity | ||
| + | --original | ||
| + | --parameter-indentation | ||
| + | --paren-indentation | ||
| + | --preserve-mtime -pmt | ||
| + | --preprocessor-indentation | ||
| + | --procnames-start-lines | ||
| + | --space-after-cast | ||
| + | --space-after-for -saf | ||
| + | --space-after-if -sai | ||
| + | --space-after-parentheses | ||
| + | --space-after-procedure-calls | ||
| + | --space-after-while -saw | ||
| + | --space-special-semicolon | ||
| + | --standard-output | ||
| + | --start-left-side-of-comments | ||
| + | --struct-brace-indentation | ||
| + | --swallow-optional-blank-lines | ||
| + | --tab-size | ||
| + | --use-tabs | ||
| + | --verbose | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== Astyle ===== | ||
| + | astyle special usage based on V2.0.4 http:// | ||
| + | |||
| + | Example: | ||
| + | astyle --options=none --align-pointer=name --pad=oper --unpad-paren --pad-paren-out --trim-trailing-whitespace | ||
| + | |||
| + | --options=none | ||
| + | Disable the default options file. Only the command-line | ||
| + | | ||
| + | -p, --pad=oper | ||
| + | Insert space padding around operators | ||
| + | |||
| + | -U, --unpad-paren | ||
| + | Remove space padding around parenthesis on the inside | ||
| + | side. Can be used in combination with the paren padding options. | ||
| + | Only padding that has not been requested by other options | ||
| + | be removed. | ||
| + | |||
| + | -d, --pad-paren-out | ||
| + | Insert space paddings around parenthesies on the outside | ||
| + | This can be used with unpad=paren to remove unwanted spaces. | ||
| + | | ||
| + | With -U -d two options, it will be like if (k > 0), not if( k > 0 ) | ||
| + | |||
| + | -k3, --align-pointer=name | ||
| + | Attach a pointer or reference operator (*, &, or ^) to the variable name (right). | ||
| + | for example: **char* p** becomes **char *p** | ||
| + | |||
| + | ===== Perl/Bash ===== | ||
| + | Use perl to remove trailing whitespace in a string: | ||
| + | $str =~ s/\s+$//; | ||
| + | Take 1 or more white spaces (\s+) till the end of the string ($), and replace them with an empty string. | ||
mywiki/linux/linux_soding_style.1411859931.txt.gz · Last modified: (external edit)
