\documentclass[11pt]{article}
%\usepackage [spanish]{babel}
%\usepackage[latin1] {inputenc}

\title{Coding Standards}
\author{Emiliano Castagnari <ecastag@fi.uba.ar>}

\begin{document}

\tableofcontents
\newpage

\section{Files}
Every source code file must start with the filename, author(s), a short
description of the file contents, copyright notice and the abbreviated 
GPL notice.

\section{Modules}
The inclusion of header files (\#include) and declarations of macros and
constants (\#define) must be made at the beginning of the .c source file,
unless it is necessary to make it in the module header file (.h) (eg, when
other modules reference the same definition).

\section{Tabs}
Indentation is made with tab characters, except for comments used at the
right of the code, where spaces should be used instead.

\section{Screen width}
When possible, the 80 character width must be respected.

\section{Data types}
Data types should be defined following this scheme:\\

 \begin{center}
  \begin{tabular}{l|l|l|l}
   Data type & Prefix & Suffix & Example \\
   \hline
   Structures  & t\_     &    -   & t\_node \\
   Other       &    -    & \_t    & node\_t \\
   \hline
  \end{tabular}
 \end{center}


\section{Functions and prototypes}
Functions should not be declared inside other functions, and their prototypes
must be declared in the header file.

The syntax must be as follows:

\begin{verbatim}
/* Function prototype (in header file) */
/* Parameter names are optional. */
return_type function(type1, type2 *, type3);

/* Function implementation */
/* Short description of the function (recommended). */
return_type function(type1 FirstVariable, type2 *SecondVariable,
	type3 ThirdVariable)
{
    ...
    statements;
    ...
}
\end{verbatim}


\section{Blocks}
The {\bf conditional blocks}, {\bf control structures} and {\bf
iterative cycles} must be indented as follows:

If the block has only one statement:

\begin{verbatim}
/*...*/
if(<condition>) statement;
else statement;

/* alternatively */
if(<condition>) 
    statement;
else 
    statement;

for(statement1; <condition>; statement3) statement;

/* alternatively */
for(statement1; <condition>; statement3) 
    statement;

while(<condition>) statement;

/* alternatively */
while(<condition>) 
    statement;
  
 /*...*/
\end{verbatim}

General case (more than one statement in the block):

\begin{verbatim}
/*...*/
if(<condition>)
{
    statement1;
    statement2;
    /* ... */
} 
else 
{
    statement1;
    statement2;
    /* ... */
}

for(statement1; <condition>; statement3) 
{
    statement1;
    statement2;
    /* ... */
}

while(<condition>)
{
    statement1;
    statement2;
    /* ... */
}
\end{verbatim}

If a control structure is nested inside another one, the use of \{\} is
mandatory, especially with 'if' structures.

\begin{verbatim}
if(...)
{
	if(...)
	{
		...
	}
	else do_something();
}
\end{verbatim}

\section{indent(1)}

It is possible to use the \verb|indent(1)| tool to apply the proposed
indentation to any source file. To do this, the command line should be:

\begin{verbatim}
  $ indent -bli0 -nsob -di1 -npsl -npcs -ss -bls -i4 -ts4 -lc80 -l80 <file(s)>
\end{verbatim}

The only problem with this approach are the comments at the right of the code,
because \verb|indent| uses tabs for them, instead of spaces.

(Note that tab size has been set to 4 spaces).

\end{document}

