mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2025-12-20 06:50:05 +01:00
Move CODING_STYLE to markdown
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
a23414dd1f
commit
50ca923c5f
1 changed files with 75 additions and 57 deletions
|
|
@ -1,41 +1,49 @@
|
||||||
|
|
||||||
- Indentation in tabs, 8 characters wide, spaces after the tabs where
|
- Indentation in tabs, 8 characters wide, spaces after the tabs where
|
||||||
vertical alignment is required (see below)
|
vertical alignment is required (see below)
|
||||||
|
|
||||||
|
**Note: this file uses spaces due to markdown rendering issues for tabs.
|
||||||
|
Code must be implemented using tabs.**
|
||||||
|
|
||||||
- Max line width 80ch, do not break up printed strings though
|
- Max line width 80ch, do not break up printed strings though
|
||||||
|
|
||||||
- Break up long lines at logical groupings, one line for each logical group
|
- Break up long lines at logical groupings, one line for each logical group
|
||||||
|
|
||||||
int a = somelongname() +
|
```c
|
||||||
someotherlongname();
|
int a = somelongname() +
|
||||||
|
someotherlongname();
|
||||||
|
|
||||||
if (a < 0 &&
|
if (a < 0 &&
|
||||||
(b > 20 & d < 10) &&
|
(b > 20 & d < 10) &&
|
||||||
d != 0.0)
|
d != 0.0)
|
||||||
|
|
||||||
|
|
||||||
somelongfunctioncall(arg1,
|
somelongfunctioncall(arg1,
|
||||||
arg2,
|
arg2,
|
||||||
arg3);
|
arg3);
|
||||||
|
```
|
||||||
|
|
||||||
- Function declarations: return type on separate line, {} on separate line,
|
- Function declarations: return type on separate line, {} on separate line,
|
||||||
arguments broken up as above.
|
arguments broken up as above.
|
||||||
|
|
||||||
static inline int
|
```c
|
||||||
foobar(int a, int b)
|
static inline int
|
||||||
{
|
foobar(int a, int b)
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
somenamethatiswaytoolong(int a,
|
somenamethatiswaytoolong(int a,
|
||||||
int b,
|
int b,
|
||||||
int c)
|
int c)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
- /* comments only */, no // comments
|
- `/* comments only */`, no `// comments`
|
||||||
|
|
||||||
- variable_name, not VariableName or variableName. same for functions.
|
- `variable_name`, not `VariableName` or `variableName`. same for functions.
|
||||||
|
|
||||||
- no typedefs of structs, enums, unions
|
- no typedefs of structs, enums, unions
|
||||||
|
|
||||||
|
|
@ -48,70 +56,80 @@
|
||||||
at the top.
|
at the top.
|
||||||
Exception: basic loop variables, e.g. for (int i = 0; ...)
|
Exception: basic loop variables, e.g. for (int i = 0; ...)
|
||||||
|
|
||||||
int a;
|
```c
|
||||||
int c;
|
int a;
|
||||||
|
int c;
|
||||||
|
|
||||||
if (foo) {
|
if (foo) {
|
||||||
int b;
|
int b;
|
||||||
|
|
||||||
c = get_value();
|
c = get_value();
|
||||||
usevalue(c);
|
usevalue(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bar) {
|
if (bar) {
|
||||||
c = get_value();
|
c = get_value();
|
||||||
useit(c);
|
useit(c);
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
- do not mix function invocations and variable definitions.
|
- do not mix function invocations and variable definitions.
|
||||||
|
|
||||||
wrong:
|
wrong:
|
||||||
|
|
||||||
{
|
```c
|
||||||
int a = foo();
|
{
|
||||||
int b = 7;
|
int a = foo();
|
||||||
}
|
int b = 7;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
right:
|
right:
|
||||||
{
|
```c
|
||||||
int a;
|
{
|
||||||
int b = 7;
|
int a;
|
||||||
|
int b = 7;
|
||||||
|
|
||||||
a = foo();
|
a = foo();
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
There are exceptions here, e.g. tp_libinput_context(),
|
There are exceptions here, e.g. `tp_libinput_context()`,
|
||||||
litest_current_device()
|
`litest_current_device()`
|
||||||
|
|
||||||
- if/else: { on the same line, no curly braces if both blocks are a single
|
- if/else: { on the same line, no curly braces if both blocks are a single
|
||||||
statement. If either if or else block are multiple statements, both must
|
statement. If either if or else block are multiple statements, both must
|
||||||
have curly braces.
|
have curly braces.
|
||||||
|
|
||||||
if (foo) {
|
```c
|
||||||
blah();
|
if (foo) {
|
||||||
bar();
|
blah();
|
||||||
} else {
|
bar();
|
||||||
a = 10;
|
} else {
|
||||||
}
|
a = 10;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
- public functions MUST be doxygen-commented, use doxygen's @foo rather than
|
- public functions MUST be doxygen-commented, use doxygen's `@foo` rather than
|
||||||
\foo notation
|
`\foo` notation
|
||||||
|
|
||||||
- include "config.h" comes first, followed by system headers, followed by
|
- `#include "config.h"` comes first, followed by system headers, followed by
|
||||||
external library headers, followed by internal headers.
|
external library headers, followed by internal headers.
|
||||||
sort alphabetically where it makes sense (specifically system headers)
|
sort alphabetically where it makes sense (specifically system headers)
|
||||||
|
|
||||||
#include "config.h"
|
```c
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <libevdev/libevdev.h>
|
#include <libevdev/libevdev.h>
|
||||||
|
|
||||||
#include "libinput-private.h"
|
#include "libinput-private.h"
|
||||||
|
```
|
||||||
|
|
||||||
- goto jumps only to the end of the function, and only for good reasons
|
- goto jumps only to the end of the function, and only for good reasons
|
||||||
(usually cleanup). goto never jumps backwards
|
(usually cleanup). goto never jumps backwards
|
||||||
|
|
||||||
- Use stdbool.h's bool for booleans within the library (instead of 'int').
|
- Use stdbool.h's bool for booleans within the library (instead of `int`).
|
||||||
Exception: the public API uses int, not bool.
|
Exception: the public API uses int, not bool.
|
||||||
Loading…
Add table
Reference in a new issue