Update code-style.c
- mention Uncrustify instead of GNU Indent - add a missing argument of code_style_example_function() - make the function return 0 or 1 as per doxygen comment - replace tab with spaces - correct case() to switch() in a comment - add an indentation example for switch statement
This commit is contained in:
parent
9ccc1697cf
commit
49808b8f1c
1 changed files with 26 additions and 15 deletions
|
@ -7,15 +7,13 @@
|
|||
* belong to the same module. Typically, the \defgroup is placed in
|
||||
* the .h file and \addtogroup in the .c file.
|
||||
*
|
||||
* The Contiki source code contains a GNU Indent script that can
|
||||
* automatically format a C code file to match the Contiki code
|
||||
* style. The Indent configuration is in contiki/tools/indent.pro and
|
||||
* a small helper script is in contiki/tools/contiki-indent. Note that
|
||||
* this is not a silver bullet - for example, the script does not add
|
||||
* separators between functions, nor does it format comments
|
||||
* correctly. The script should be treated as an aid in formatting
|
||||
* code: first run the formatter on the source code, then manually
|
||||
* edit the file.
|
||||
* The Contiki source code contains an Uncrustify configuration file,
|
||||
* uncrustify.cfg, under tools/code-style and small helper scripts are
|
||||
* provided at the same place. Note that this is not a silver bullet -
|
||||
* for example, the script does not add separators between functions,
|
||||
* nor does it format comments correctly. The script should be treated
|
||||
* as an aid in formatting code: first run the formatter on the source
|
||||
* code, then manually edit the file.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
@ -74,22 +72,22 @@ static int flag;
|
|||
* between the name and the first parenthesis), followed
|
||||
* by a single curly bracket on its own line.
|
||||
*/
|
||||
void
|
||||
code_style_example_function(void)
|
||||
int
|
||||
code_style_example_function(char c)
|
||||
{
|
||||
/*
|
||||
* Local variables should always be declared at the start of the
|
||||
* function.
|
||||
*/
|
||||
int i; /* Use short variable names for loop
|
||||
counters. */
|
||||
counters. */
|
||||
|
||||
/*
|
||||
* There should be no space between keywords and the first
|
||||
* parenthesis. There should be spaces around binary operators, no
|
||||
* spaces between a unary operator and its operand.
|
||||
*
|
||||
* Curly brackets following for(), if(), do, and case() statements
|
||||
* Curly brackets following for(), if(), do, and switch() statements
|
||||
* should follow the statement on the same line.
|
||||
*/
|
||||
for(i = 0; i < 10; ++i) {
|
||||
|
@ -100,12 +98,25 @@ code_style_example_function(void)
|
|||
* are less error prone.
|
||||
*/
|
||||
if(i == c) {
|
||||
return c; /* No parentesis around return values. */
|
||||
return 1; /* No parentesis around return values. */
|
||||
} else { /* The else keyword is placed inbetween
|
||||
curly brackers, always on its own line. */
|
||||
curly brackers, always on its own line. */
|
||||
c++;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Indent "case" statement and "default" label by two spaces in "switch"
|
||||
* statement.
|
||||
*/
|
||||
switch(c) {
|
||||
case 19:
|
||||
return 1;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue