LibCGI code formatting and documentation conventions
for (i = 0; i < 10; i++) { [...] } else { [...] }or
for (i = 0; i < 10; i++) { [...] } else { [...] }or even
for (i = 0; i < 10; i++) { [...] } else { [...] }There is a simple diference for function braces:
int my_function() { [...] } char *foo() { [...] }Did you see the {}'s on that?
a = (b + c) * d;1.4.2.
while (true) {1.4.3.
someFunction(a, b, c); int d, e;1.4.4.
for (int a = 0; b++; c < d)1.5. Switch / Case constructs
switch (cmd) { case option_one: bleh(); break; case option_two: case option_three: blah(); break; default: bloh(); }1.6. Naming
MY_CONSTANT1.6.2. Functions and variables All lowercase, which underscore separators
int my_function(); char **my_another_char_function();
/** * .... **/ int my_function() { [...] }
/** * This is a brief description of the function. * * And here is a more detailed description, where * you can put some details of the internals of the * function. **/ in my_function() { [...] }Isn't necessary to repeat the brief description in the detailhed section. It is done automatically.
@param -> To document parameters @return -> Describes the function's return value @author -> Puts the author name @see -> To include related topics
/** * This is a brief description of the function. * * And here is a more detailed description, where * you can put some details of the internals of the * function. * * @param *src Source string * @param *dst Destiny string, to where the result will be put * @author Author Name * @return true if all worked fine, 0 if not * @see another_function, one_more_function_name **/ int my_another_function(char *src, char *dst) { [...] }
/** * @defgroup my_group_name Name of the group * @{ **/Note that the @defgroup keywork is followed by the internal group name and the "real" name. The the @{ keyword says that this group is starting in this point. To end a group, just put
/** * @} **/It works like a code block. Now, every function and variable which a well written commentary block will appear into the group previously defined.
/** * @defgroup libcgi_string String manipulation * @{ **/ /** * Explode's documentation here. **/ char *explode() { [...] } /** * str_replace's documentation here. **/ char *str_replace(char *param1, char param2, char param3) { [...] } /** * @} **/Now, let's suppose you have functions you like to be into the same group, but they are into different files. In this case, use "@ingroup" keyword for each function or variable you want to be part of some group:
/** * @ingroup libcgi_string **/ /** * Method's documentation. **/ char *my_another_string_function() { [...] }Or, if there is many functions into same source file, use the "@addtogroup" keyword instead of @intogroup. In this case you need to close the grouping when you no longer need it, like @defgroup.
/** * @addtogroup libcgi_string **/ /** * Documentation **/ char *method_name() { [..] } /** * Documentation **/ void another_function() { [...] } /** * @} **/