Code-style manifest for firk's Common C Library.

===============================================================================
******************************** Global layout ********************************

Maximum line length is 79 characters.

Header files:

> /*
>  * LICENSE TEXT
>  */
> #ifndef INCLUDED_{PROJECTNAME}_{HEADERNAME}_H
> #define INCLUDED_{PROJECTNAME}_{HEADERNAME}_H
> 
> (payload here)
> 
> #endif
> 

Source files:

> /*
>  * LICENSE TEXT
>  */
>
> #include <external_headers.h>
> #include "this_project_headers.h"
> #include "this_file_header.h"
> 
> (payload here)

Function prototypes in header:
> extern typename[ *] funcname(args);

Function prototype with long args list:
> extern typename[ *] funcname(type1 arg1, type2 * * arg2, type3 * arg3,
>                              type4 arg4);
OR
> extern typename[ *] funcname
>                      (type1 arg1, type2 * * arg2, type3 * arg3, type4 arg4);
(second line indent is not strictly fixed)

Function definition:
> {extern|static} typename funcname(args) {
>   type1 var1, var2;
>   type2 * var3;
>   (body)
> }

Two function definitons should be separated by at least one empty lines except
some special cases.

===============================================================================
******************************** Local  things ********************************

No C++-style comments (//)

Code blocks { } indent is 2 spaces.

STRICTLY no variables in middle of code block.
Avoid variables at beginning of non-function code block (but sometimes may be).
No embedded variable declarations like this: "for(int i=0; ; )"

Structs:

> [typedef ]struct[ name] {
>   type1 *   var1;
>   type2     var2;
> }[ typedefed_name];
OR
> [typedef ]struct[ name] {
>   type1 * var1;
>   type2 var2;
> }[ typedefed_name];
(variable names MAY BE aligned)

Ifs/loops:
> if(A1) cmd1;
> else if(A2) cmd2;
> else if(A3) {
>   cmd3;
>   cmd3a;
> } else if(A4) cmd4;
> else if(A5) { cmd5; cmd5a; }
> else cmd6;

> while(X) loop_cmd;

> while(X) {
>   loop_cmd;
> }

> for(A; B; C) loop_cmd;

> for(A; B; C) {
>   loop_cmd;
> }

> do { cmd; } while(A);

> do {
>   cmd;
> } while(A);

DISALLOWED:
> if(A)
>   cmd1;
> else
>   cmd2;
(when sub-ops are on separate lines, they should be wrapped by { } always)

May be combined (until fits line length):
> if(A) for(B1; B2; B3) if(C) { cmd1; cmd2; }

DISALLOWED:
> if(A) if(B) cmd; else cmd2;
Proper way:
> if(A) { if(B) cmd; else cmd2; }
(nested 'if-else' inside other 'if' should be always wrapped by { })

Conditions (same rules for if(), while(), and the second arg of for()):
> if(x==1)

> if(x==1 || y==2)

> if(x==1 && y==2 || z==3)

> if(x==1 && (y==2 || z==3))

> if(r = read(fd, buf, 10))

> if((r = read(fd, buf, 10))<0)

> if((r = test_x(a)) && x==1)

> if((r=func_with_manyargs(a1,a2,a3,a4,a5,a6,a7))>0 && (r2=otherfunc(a3,a4))<0)
(skip spaces when they looks like garbage)

NO unneeded braces: if((x==1 && y==2) || z==3)
NO unneeded braces: if((r = read(fd, buf, 10)))

Ternary operator:

1) wrap with () except it is entire function argument:
> x = (a?b:c);
but
> f(a1, a2, a?b:c);

2) wrap its subexpressions with () when it is not 100% clear in which order
they computed:
> x = ((a>1)?1:(q+5));

> x = ((a>1)?1:q)+5;

Return operator: wrap condition-expression with ():
> return (a>3);
but
> return a+3;
(a+3) is not a condition

Other:
> x = 1;

> x = f(a, b, c);

But spaces around '=' or after ',' may be omitted:
1) when trying to avoid line wrapping
2) doing typical boring thing like "{ errno=EINVAL; return -1; }"
3) it is "for(i=1; i<5; i++)" (here spaces around '=' not wanted)

===============================================================================
