<chapter><title>Coding rules</title>

<sect1><title>Naming conventions</title>

<sect2><title>Functions</title>

      <para>
All functions are named accordingly : module name (in lower case) + _ +
function name (in mixed case, <emphasis> without underscores</emphasis>).
For instance : <function>intf_FooFunction</function>. Static functions
don't need usage of the module name.
      </para>

</sect2>

<sect2><title>Variables</title>

      <para>
Hungarian notations are used, that means we have the following prefixes :
      </para>

      <itemizedlist>
        <listitem> <para> i_ for integers (sometimes l_ for long integers) ;
        </para> </listitem>
        <listitem> <para> b_ for booleans ; </para> </listitem>
        <listitem> <para> d_ for doubles (sometimes f_ for floats) ;
        </para> </listitem>
        <listitem> <para> pf_ for function pointers ; </para> </listitem>
        <listitem> <para> psz_ for a Pointer to a String terminated by a
        Zero (C-string) ;
        </para> </listitem>
        <listitem> <para> More generally, we add a p when the variable is
        a pointer to a type. </para> </listitem>
      </itemizedlist>
    
      <para>
If one variable has no basic type (for instance a complex structure), don't
put any prefix (except p_* if it's a pointer). After one prefix, put
an <emphasis> explicit </emphasis> variable name <emphasis> in lower
case</emphasis>. If several words are required, join them with an
underscore (no mixed case). Examples :
      </para>

      <itemizedlist>
        <listitem> <para>
        <type> data_packet_t * </type> <varname> p_buffer; </varname>
        </para> </listitem> <listitem> <para>
        <type> char </type> <varname> psz_msg_date[42]; </varname>
        </para> </listitem> <listitem> <para>
        <type> int </type> <varname> pi_es_refcount[MAX_ES]; </varname>
        </para> </listitem> <listitem> <para>
        <type> void </type> <varname> (* pf_next_data_packet)( int * ); </varname>
        </para> </listitem>
      </itemizedlist>

    </sect2>



</sect1>

<sect1><title>Code indentation</title>

<para>Code is indented with 4 spaces. Never use tabs in the source
code. If you are using Vim as your editor, you can use <command>set
expandtab</command>.</para>

<para>Please put spaces <emphasis> before and after </emphasis> operators, and
inside brackets. For instance :
<programlisting> for( i = 0; i &lt; 12; i++, j += 42 ); </programlisting>
      </para>

      <para>
Third, leave braces alone on their lines (GNU style). For instance :
        <programlisting>
if( i_es == 42 )
{
   p_buffer[0] = 0x12;
}
        </programlisting>
      </para>

      <para>
We write C, so use C-style comments /* ... */.
      </para>

</sect1>

</chapter>
