|
Size: 1557
Comment: link to indent script used
|
← Revision 11 as of 2012-03-28 10:19:58 ⇥
Size: 1616
Comment:
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 3: | Line 3: |
| We use the `indent` command line in this script here: http://cgit.freedesktop.org/xorg/util/modular/tree/x-indent.sh?id=ea4c1a71bc5fc05026badb7d7ce1e560a5b3d1b5 | We use the `indent` command line in this script here: http://cgit.freedesktop.org/xorg/util/modular/tree/x-indent.sh with manual editing afterwards to fix the cases where indent gets hopelessly confused. |
| Line 5: | Line 5: |
| * Four-space indents | * Four-space indents (no tabs, not even if your editor wants to collapse eight consecutive spaces down to a single tab) |
| Line 8: | Line 8: |
| * Keywords punctuated like `if (x >= 0)` * Functions punctuated like `doSomethingClever(a, b, c);` |
|
| Line 14: | Line 12: |
| * Keywords punctuated like `if (x >= 0)` * Functions punctuated like `doSomethingClever(a, b, c);` |
|
| Line 15: | Line 15: |
| * If wrapping is required, function arguments to be aligned to the opening parenthesis of that column | |
| Line 16: | Line 17: |
| * ANSI prototypes for all new code; convert K&R declarations to ANSI with care * If wrapping is required, function arguments to be aligned to the opening parenthesis of that column |
This page describes the X server's current coding style. While the server was recently reformatted to fit this style, most modules have varied and disparate coding styles. Above all, the cardinal rule is to fit in: make sure your changes reflect the coding style of the surrounding code.
We use the indent command line in this script here: http://cgit.freedesktop.org/xorg/util/modular/tree/x-indent.sh with manual editing afterwards to fix the cases where indent gets hopelessly confused.
- Four-space indents (no tabs, not even if your editor wants to collapse eight consecutive spaces down to a single tab)
- 78-column limit
Function return type (and any modifiers, eg static) on a line by itself
Opening curly brace on the same line as the control construct: if (foo) {
Closing braces aligned with the keyword that opened them (K&R not GNU)
else on a new line from the closing } of the preceding if (i.e. not cuddling)
- Opening curly brace for functions in column 0
Keywords punctuated like if (x >= 0)
Functions punctuated like doSomethingClever(a, b, c);
case aligned in the same column as the switch
- If wrapping is required, function arguments to be aligned to the opening parenthesis of that column
- Wrap structs in typedefs
C-style comments, rather than C++/C99-style // foo
C89 + some extensions, see http://cgit.freedesktop.org/xorg/xserver/tree/doc/c-extensions
Notable objectionable things in the current coding style:
- Most structs have a typedef both for the struct and for a pointer to the struct.


