This document describes the coding style used in cinit.

1. Indent

Indent the code by 3 spaces for each level. Indent variable names, so the names begin all at the same position. Use three spaces to place them.

2. Whitespaces

Where to put or avoid whitespaces (space or linefeed (lf)).

2.1. Spaces

2.2. No spaces

2.3. Linebreaks

This somehow includes the setting of braces (indirectly through (not) setting spaces.

2.3.1. If

Put the if, the braces and the opening curly brace on one line, put the closing one together with else and the new opening curly brace on one line:

if(...) {
   /* code */
} else {
   /* else: code */
}

2.3.2. While

while(condition) {
   /* repeat */
}

2.3.3. Do-While

do {
   /* something */
} while(running);

2.3.4. Switch

switch(value) {
   case DO_SOMETHING:
      /* code */
      break;
   default:
      break;
}

3. Where to put curly braces

3.1. Functions

Opening and closing curly braces are placed on a seperate row:

int func(int params)
{
   body
}

3.2. If, else, while, do-while

See above.

4. Comments

where necessery, do not state the obvious in comments:

/* this code increments tmp */
++tmp;

If there is more than one line containing a comment, try to adjust them so they look the same in width and position:

   int illuminati                = 23; /* do not want to comment that   */
   int the_answer_to_everything  = 42; /* 42.                           */

   [...]

   while(illuminati < the_answer_to_everything) {  /* only try before them  */
      overtake_world(&self);                       /* overtake is complex   */
   }

5. Header

Put a header into each file, containing:

5.1. Includes

Include system headers first, then place own headers. Comment the includes, wherefore you added them. Example:

#include <unistd.h>     /* write          */
#include "cinit.h>      /* cinit_ipc_*    */