114b11b2bSmrgPixman coding style.
214b11b2bSmrg====================
314b11b2bSmrg
414b11b2bSmrgThe pixman coding style is close to cairo's with one exception: braces
514b11b2bSmrggo on their own line, rather than on the line of the if/while/for:
614b11b2bSmrg
714b11b2bSmrg	if (condition)
814b11b2bSmrg	{
914b11b2bSmrg	    do_something();
1014b11b2bSmrg	    do_something_else();
1114b11b2bSmrg	}
1214b11b2bSmrg
1314b11b2bSmrgnot
1414b11b2bSmrg
1514b11b2bSmrg	if (condition) {
1614b11b2bSmrg	    do_something();
1714b11b2bSmrg	    do_something_else();
1814b11b2bSmrg        }
1914b11b2bSmrg
2014b11b2bSmrg
2114b11b2bSmrg
2214b11b2bSmrgIndentation
2314b11b2bSmrg===========
2414b11b2bSmrg
2514b11b2bSmrgEach new level is indented four spaces:
2614b11b2bSmrg
2714b11b2bSmrg	if (condition)
2814b11b2bSmrg	    do_something();
2914b11b2bSmrg
3014b11b2bSmrgThis may be achieved with space characters or with a combination of
3114b11b2bSmrgtab characters and space characters. Tab characters are interpreted as
3214b11b2bSmrg
3314b11b2bSmrg	Advance to the next column which is a multiple of 8.
3414b11b2bSmrg
3514b11b2bSmrg
3614b11b2bSmrgNames
3714b11b2bSmrg=====
3814b11b2bSmrg
3914b11b2bSmrgIn all names, words are separated with underscores. Do not use
4014b11b2bSmrgCamelCase for any names.
4114b11b2bSmrg
4214b11b2bSmrgMacros have ALL_CAPITAL_NAMES
4314b11b2bSmrg
4414b11b2bSmrgType names are in lower case and end with "_t". For example
4514b11b2bSmrgpixman_image_t.
4614b11b2bSmrg
4714b11b2bSmrgLabels, functions and variables have lower case names.
4814b11b2bSmrg
4914b11b2bSmrg
5014b11b2bSmrgBraces
5114b11b2bSmrg======
5214b11b2bSmrg
5314b11b2bSmrgBraces always go on their own line:
5414b11b2bSmrg
5514b11b2bSmrg	if (condition)
5614b11b2bSmrg	{
5714b11b2bSmrg	    do_this ();
5814b11b2bSmrg	    do_that ();
5914b11b2bSmrg	}
6014b11b2bSmrg	else
6114b11b2bSmrg	{
6214b11b2bSmrg	    do_the_other ();
6314b11b2bSmrg	}
6414b11b2bSmrg
6514b11b2bSmrgRules for braces and substatements of if/while/for/do:
6614b11b2bSmrg
6714b11b2bSmrg* If a substatement spans multiple lines, then there must be braces
6814b11b2bSmrg  around it.
6914b11b2bSmrg
7014b11b2bSmrg* If the condition of an if/while/for spans multiple lines, then 
7114b11b2bSmrg  braces must be used for the substatements.
7214b11b2bSmrg
7314b11b2bSmrg* If one substatement of an if statement has braces, then the other
7414b11b2bSmrg  must too.
7514b11b2bSmrg
7614b11b2bSmrg* Otherwise, don't add braces.
7714b11b2bSmrg
7814b11b2bSmrg
7914b11b2bSmrgComments
8014b11b2bSmrg========
8114b11b2bSmrg
8214b11b2bSmrgFor comments either like this:
8314b11b2bSmrg
8414b11b2bSmrg        /* One line comment */
8514b11b2bSmrg
8614b11b2bSmrgor like this:
8714b11b2bSmrg
8814b11b2bSmrg	/* This is a multi-line comment
8914b11b2bSmrg	 *
9014b11b2bSmrg         * It extends over multiple lines
9114b11b2bSmrg	 */
9214b11b2bSmrg
9314b11b2bSmrgGenerally comments should say things that aren't clear from the code
9414b11b2bSmrgitself. If too many comments say obvious things, then people will just
9514b11b2bSmrgstop reading all comments, including the good ones.
9614b11b2bSmrg
9714b11b2bSmrg
9814b11b2bSmrgWhitespace
9914b11b2bSmrg==========
10014b11b2bSmrg
10114b11b2bSmrg* Put a single space after commas
10214b11b2bSmrg
10314b11b2bSmrg* Put spaces around arithmetic operators such a +, -, *, /:
10414b11b2bSmrg
10514b11b2bSmrg        y * stride + x
10614b11b2bSmrg
10714b11b2bSmrg        x / unit_x
10814b11b2bSmrg
10914b11b2bSmrg* Do not put spaces after the address-of operator, the * when used as
11014b11b2bSmrg  a pointer derefernce or the ! and ~ operators:
11114b11b2bSmrg
11214b11b2bSmrg     &foo;
11314b11b2bSmrg
11414b11b2bSmrg     ~0x00000000
11514b11b2bSmrg
11614b11b2bSmrg     !condition
11714b11b2bSmrg
11814b11b2bSmrg     *result = 100
11914b11b2bSmrg
12014b11b2bSmrg* Break up long lines (> ~80 characters) and use whitespace to align
12114b11b2bSmrg  things nicely. This is one way:
12214b11b2bSmrg
12314b11b2bSmrg  	 some_very_long_function name (
12414b11b2bSmrg	 	implementation, op, src, mask, dest, 
12514b11b2bSmrg		src_x, src_y, mask_x, mask_y, dest_x, dest_y,
12614b11b2bSmrg		width, height);
12714b11b2bSmrg
12814b11b2bSmrg  This is another:
12914b11b2bSmrg
13014b11b2bSmrg        some_very_long_function_name (implementation, op,
13114b11b2bSmrg                                      src, mask, dest,
13214b11b2bSmrg				      src_x, src_y,
13314b11b2bSmrg				      mask_x, mask_y,
13414b11b2bSmrg				      dest_x, dest_y,
13514b11b2bSmrg				      width, height);
13614b11b2bSmrg
13714b11b2bSmrg* Separate logically distinct chunks with a single newline. This
13814b11b2bSmrg  obviously applies between functions, but also applies within a
13914b11b2bSmrg  function or block or structure definition.
14014b11b2bSmrg
14114b11b2bSmrg* Use a newline after a block of variable declarations.
14214b11b2bSmrg
14314b11b2bSmrg* Use a single space before a left parenthesis, except where the
14414b11b2bSmrg  standard will not allow it, (eg. when defining a parameterized macro).
14514b11b2bSmrg
14614b11b2bSmrg* Don't eliminate newlines just because things would still fit on one
14714b11b2bSmrg  line. This breaks the expected visual structure of the code making
14814b11b2bSmrg  it much harder to read and understand:
14914b11b2bSmrg
15014b11b2bSmrg	if (condition) foo (); else bar ();	/* Yuck! */
15114b11b2bSmrg
15214b11b2bSmrg
15314b11b2bSmrgFunction Definitions
15414b11b2bSmrg====================
15514b11b2bSmrg
15614b11b2bSmrgFunction definitions should take the following form:
15714b11b2bSmrg
15814b11b2bSmrg	void
15914b11b2bSmrg	my_function (int argument)
16014b11b2bSmrg	{
16114b11b2bSmrg	    do_my_things ();
16214b11b2bSmrg	}
16314b11b2bSmrg
16414b11b2bSmrgIf all the parameters to a function fit naturally on one line, format
16514b11b2bSmrgthem that way. Otherwise, put one argument on each line, adding
16614b11b2bSmrgwhitespace so that the parameter names are aligned with each other.
16714b11b2bSmrg
16814b11b2bSmrgI.e., do either this:
16914b11b2bSmrg
17014b11b2bSmrg        void
17114b11b2bSmrg        short_arguments (const char *str, int x, int y, int z)
17214b11b2bSmrg        {
17314b11b2bSmrg        }
17414b11b2bSmrg
17514b11b2bSmrgor this:
17614b11b2bSmrg
17714b11b2bSmrg	void
17814b11b2bSmrg	long_arguments (const char *char_star_arg,
17914b11b2bSmrg			int	    int_arg,
18014b11b2bSmrg			double	   *double_star_arg,
18114b11b2bSmrg			double	    double_arg)
18214b11b2bSmrg	{
18314b11b2bSmrg	}
18414b11b2bSmrg
18514b11b2bSmrg
18614b11b2bSmrgMode lines
18714b11b2bSmrg==========
18814b11b2bSmrg
18914b11b2bSmrgGiven the rules above, what is the best way to simplify one's life as
19014b11b2bSmrga code monkey? Get your editor to do most of the tedious work of
19114b11b2bSmrgbeautifying your code!
19214b11b2bSmrg
19314b11b2bSmrgAs a reward for reading this far, here are some mode lines for the more
19414b11b2bSmrgpopular editors:
19514b11b2bSmrg/*
19614b11b2bSmrg * vim:sw=4:sts=4:ts=8:tw=78:fo=tcroq:cindent:cino=\:0,(0
19714b11b2bSmrg * vim:isk=a-z,A-Z,48-57,_,.,-,>
19814b11b2bSmrg */
19914b11b2bSmrg
200