
Debian-installer style guide
============================

(This guide is ripped off from multiple sources, most notably Busybox's
style guide)

This document describes the coding style conventions used in
debian-installer. If you add a new file to any of the subprojects in
debian-installer CVS or are editing an existing file, please format your
code according to this style. If you are the maintainer of a file that does
not follow these guidelines, please -- at your own convenience -- modify the
file(s) you maintain to bring them into conformance with this style guide.
Please note that this is a low priority task.

Formatting
----------

Tabs vs spaces
~~~~~~~~~~~~~~

Indent lines with spaces.  Each indent is four spaces.

Operator Spacing
~~~~~~~~~~~~~~~~

Put spaces between terms and operators. Example:

Don't do this:

      for(i=0;i<num_items;i++){

Do this instead:

      for (i = 0; i < num_items; i++) {

While it extends the line a bit longer, the spaced version is more
readable. An allowable exception to this rule is the situation where
excluding the spacing makes it more obvious that we are dealing with a
single term (even if it is a compound term) such as:

      if (str[idx] == '/' && str[idx-1] != '\\')

or

      if ((argc-1) - (optind+1) > 0)

Bracket Spacing
~~~~~~~~~~~~~~~

If an opening bracket starts a function, it should be on the
next line with no spacing before it. However, if a bracket follows an opening
control block, it should be on the same line with a single space (not a tab)
between it and the opening control block statement. Examples:

Don't do this:

      while (!done)
      {

      do
      {

Don't do this either:

      while (!done){

      do{

And for heaven's sake, don't do this:

      while (!done)
        {

      do
        {

Do this instead:

      while (!done) {

      do {


Spacing around Parentheses
~~~~~~~~~~~~~~~~~~~~~~~~~~

Put a space between C keywords and left parens, but not between function names
and the left paren that starts it's parameter list (whether it is being
declared or called). Examples:

Don't do this:

      while(foo) {
      for(i = 0; i < n; i++) {

Do this instead:

      while (foo) {
      for (i = 0; i < n; i++) {

But do functions like this:

      static int my_func(int foo, char bar)
      ...
      baz = my_func(1, 2);

Also, don't put a space between the left paren and the first term, nor between
the last arg and the right paren.

Don't do this:

      if ( x < 1 )
      strcmp( thisstr, thatstr )

Do this instead:

      if (x < 1)
      strcmp (thisstr, thatstr)

Cuddled Elses
~~~~~~~~~~~~~

Also, please "cuddle" your else statements by putting the else keyword on the
same line after the right bracket that closes an 'if' statement.

Don't do this:

      if (foo) {
          stmt;
      }
      else {
          stmt;
      }

Do this instead:

     if (foo) {
         stmt;
     } else {
         stmt;
     }

The exception to this rule is if you want to include a comment before the else
block. Example:

     if (foo) {
         stmts...
     }
     /* otherwise, we're just kidding ourselves, so re-frob the input */
     else {
         other_stmts...
     }

Variable and Function Names
---------------------------

Use the K&R style with names in all lower-case and underscores occasionally
used to separate words (e.g., "variable_name" and "numchars" are both
acceptable). Using underscores makes variable and function names more readable
because it looks like whitespace; using lower-case is easy on the eyes.

        Frowned upon:

                hitList
                TotalChars
                szFileName
                pf_Nfol_TriState

        Preferred:

                hit_list
                total_chars
                file_name
                sensible_name

Exceptions:

 - Enums, macros, and constant variables are occasionally written in all
   upper-case with words optionally separated by underscores (i.e. FIFOTYPE,
   ISBLKDEV()).

