User Tools

Site Tools


mywiki:linux:linux_soding_style

This is an old revision of the document!


Table of Contents

Linux Coding Style

Formatting Tools

Code generally has to follow the Linux coding style to be accepted. Basically there are two tools for formatting the code: indent and astyle

indent

The indent program, an excellent GNU utility found on most Linux systems, formats source according to given rules. Refer to http://linux.die.net/man/1/indent

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 : indent -kr -i8 -ts8 -sob -l80 -ss -bs -psl <file>

The Kernighan & Ritchie 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) is equivalent to the following settings:

-nbad -bap -nbc -bbo -hnl -br -brs -c33 -cd33 -ncdb -ce -ci4 
-cli0 -d0 -di1 -nfc1 -i8 -ip0 -l80 -lp -npcs -nprs -npsl -sai
-saf -saw -ncs -nsc -sob -nfca -cp33 -ss -ts8 -il1
-kr The C Programming Language
The -kr from The the author of The C Programming Language, Brian Kernighan and Dennis Ritchie
(Prentice Hall, ISBN# 0-13-11-362-8)
-i8 indentation level to 8 spaces
-ts8 Set tab size to 8 spaces.
-sob
–swallow-optional-blank-lines
Swallow optional blank lines.
-l80 Set maximum line length for non-comment lines to 80 characters.
-ss\\–space-special-semicolon On one-line for and while statements, force a blank before the semicolon.
-bs
–Bill-Shannon
–blank-before-sizeof
Put a space between sizeof and its argument.
-psl
–procnames-start-lines
Put the type of a procedure on the line before its name.
-nbad
-bap
-nbc
-bbo
-hnl
-br
-brs
-c33
-cd33
-ncdb
-ce
-ci4
-cli0
-d0
-di1
-nfc1
-i8
-ip0
-l80
-lp
-npcs
-nprs
-npsl
-sai
-saf
-saw
-ncs
-nsc
-sob
-nfca
-cp33
-ss
-ts8
-il1
mywiki/linux/linux_soding_style.1411860444.txt.gz · Last modified: (external edit)