1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
This page describes the Farsight2 coding style. Respect it or die.
It is a copy of
http://farsight.freedesktop.org/wiki/Fs2CodingStyle
They should both be in sync
Loosely based on GNU style C.
Max line width 80.
All long lines wrapped with 4 space indentation.
Spaces after all procedural calls (includes macros).
Function names and variables names use underscore word separators. All GObject methods are prefixed with the appropriate prefix for the object.
Typenames are in camelcase.
NO TABS!
Base indent unit is 2 spaces.
==== Function prototypes ====
The first parameter is on the same line as the function only if the function is a method.
static void farsight_rtp_stream_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
==== Function declarations ====
The first parameter is on the same line as the function only if the function is a method.
static void
farsight_rtp_stream_get_property (GObject * object,
guint prop_id,
GValue * value,
GParamSpec * pspec)
{
}
==== If/else/while/for/do/struct/switch/etc ====
if (condition)
{
die ();
}
else
{
die ();
}
For blocks that only contain one statement, the opening/closing brackets can be omitted. But this can only be done if all the blocks in a statement contain only one statement. This is an ILLEGAL example :
if (condition)
die ();
else
{
die ();
die_again ();
}
==== Breaks and boolean operators ====
if (self->priv->main_pipeline && src_in_pipeline
|| !self->priv->your_mama)
{
}
==== Pointer declarations ====
Type *var;
==== Switch ====
switch (var)
{
case 4:
die ();
break;
case 5:
die ();
}
==== Casting ====
FarsightRTPStream *self = (FarsightRTPStream *) stream;
==== #includes ====
If you're going to #include "config.h", do that first, in case it defines things like "inline".
Next, #include the header in which this .c file's API is declared. This guarantees that all public headers are self-contained.
Next, #define any libc feature-test macros you need (_GNU_SOURCE etc.) and #include any C/POSIX standard library headers you need, in alphabetical order.
Next, #include any headers you need from non-standard libraries (GLib, Gtk, GStreamer, ...) in alphabetical order.
Finally, #include any private (non-installed) headers from the library or program you're writing.
==== Emacs mode ====
(defun farsight2-c-mode ()
"C mode with farsight2 style"
(interactive)
(c-mode)
(c-set-style "GNU")
(setq tab-width 8)
(setq indent-tabs-mode nil)
(setq c-basic-offset 2)
(setq c-tab-always-indent nil)
(setq show-trailing-whitespace 't)
(c-set-offset 'case-label 2)
(c-set-offset 'arglist-intro 4)
(c-set-offset 'statement-cont 4)
(c-set-offset 'substatement-open 0)
(c-set-offset 'arglist-cont-nonempty 4)
(setq c-cleanup-list (quote (brace-else-brace brace-elseif-brace space-before-funcall)))
)
|