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 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
|
<chapter id="programming">
<title>Programming for LCDproc</title>
<sect1 id="getting-source">
<title>Get the source</title>
<para>If you want to start programming for LCDproc you will need the have
the most current source code available. You can get it several ways:</para>
<orderedlist>
<listitem>
<para>Download GIT version of as a tarball (preferred).</para>
</listitem>
<listitem>
<para>Download the latest version from GIT.</para>
</listitem>
<listitem>
<para>Download the last stable release from Github. (This is not
recommended as stable release may be months behind the current version.)
</para>
</listitem>
</orderedlist>
<sect2 id="downloadtar">
<title>Download GIT Version of LCDproc as a Tarball</title>
<para>
The source is available as tarball. You can
download them from <ulink url="https://github.com/lcdproc/lcdproc/archive/master.tar.gz"></ulink>.
For development we recommended to use the 'master' branch.
</para>
<para>
To extract the files run
</para>
<screen>
<prompt>$</prompt> <userinput>tar xvfz lcdproc-master.tar.gz</userinput>
</screen>
</sect2>
<sect2 id="downloadgit">
<title>Download The Latest Version of LCDproc from GitHub</title>
<para>
Of course you can download the latest stuff from GitHub.
For more information on how to use GitHub see
<ulink url="https://guides.github.com/"></ulink>.
</para>
<screen>
<prompt>$</prompt> <userinput>git clone https://github.com/lcdproc/lcdproc.git</userinput>
</screen>
<para>
Once you've done that and want to update the downloaded files to the latest stuff
you can use the "pull" command of git (make sure to be in the lcdproc directory!):
</para>
<screen>
<prompt>$</prompt> <userinput>git pull</userinput>
</screen>
<para>
Now that once you have downloaded the files you can prepare them for
compiling, but first you should (you don't have to) copy them to another
place on your machine.
</para>
</sect2>
</sect1>
<sect1 id="code-style">
<title>Code style guideline</title>
<para>
LCDproc has been developed by many contributors over many years. You may find
different programming styles (naming, indention, etc) in the source code.
</para>
<para>
When modifying an existing file, please take a careful look at its style and
program continuing that style instead of mixing it up with another one even
if it does not comply with the guidelines written below.
</para>
<para>
For newly added files the following guideline describes how source code
should look like.
</para>
<note>
<para>
All new submitted files will be passed through GNU <command>indent</command>
to enforce the style described below.
</para>
</note>
<sect2 id="code-style-indention">
<title>File format and indention</title>
<itemizedlist mark="opencircle">
<listitem>
<para>
<emphasis>Language: </emphasis>The programming language used for LCDd
(server core), drivers and the lcdproc client is Standard <literal>C</literal>,
currently <literal>C99</literal>.
No other programming language will be accepted.
</para>
</listitem>
<listitem>
<para>
<emphasis>File encoding: </emphasis>Files shall either encoded as UTF-8 or
ISO-8859-1 and line endings shall be Unix type.
</para>
</listitem>
<listitem>
<para>
<emphasis>Line length: </emphasis>Lines of source code should be wrapped
at column 100. Comment lines should wrap at column 79.
</para>
</listitem>
<listitem>
<para>
<emphasis>Indention: </emphasis>Tab indention shall be used (with tab
width set to 8 characters).
</para>
</listitem>
<listitem>
<para>
<emphasis>License: </emphasis>LCDproc is released under GNU General Public
License version 2 (GPL v2) and every file shall have a standard copyright
notice.
</para>
</listitem>
</itemizedlist>
</sect2>
<sect2 id="code-style-naming">
<title>Naming conventions</title>
<itemizedlist mark="opencircle">
<listitem>
<para>
<emphasis>Function names:</emphasis>
Function names shall be lowercase. We do not use CamelCase (some
historical exceptions may exist). Multiple words are separated by
underscore.
</para>
</listitem>
<listitem>
<para>
<emphasis>Variable names:</emphasis>
We do not use Hungarian Notation. CamelCase may be used,
but names shall begin with a lowercase letter.
</para>
</listitem>
<listitem>
<para>
<emphasis>Constants:</emphasis>
Constants shall be written in uppercase using underscore to
separate multiple words.
</para>
</listitem>
</itemizedlist>
<example>
<title>Names of constants, variables and functions</title>
<screen>
/* Constants */
#define KEYPAD_AUTOREPEAT_DELAY 500
#define KEYPAD_AUTOREPEAT_FREQ 15
/* Variable names */
MODULE_EXPORT char * api_version = API_VERSION;
MODULE_EXPORT int stay_in_foreground = 0;
MODULE_EXPORT int supports_multiple = 1;
/* Function names */
void HD44780_position(Driver *drvthis, int x, int y);
static void uPause(PrivateData *p, int usecs);
unsigned char HD44780_scankeypad(PrivateData *p);
</screen>
</example>
</sect2>
<sect2 id="code-style-comments">
<title>Comments</title>
<itemizedlist mark="opencircle">
<listitem>
<para>
All code comments shall be <literal>C</literal>-style comments (/* */).
Comments spanning multiple lines shall have a star at the beginning of
each line.
</para>
</listitem>
<listitem>
<para>
<literal>C++</literal>-style comments (//) may be used to comment out
single lines of code to disable these lines. Larger blocks of code which
shall be disabled should be wrapped within <literal>C</literal>-style
comments or using pre-processor directives (#if ... #endif).
</para>
<para>
<literal>C++</literal>-style comments should not be used in general.
</para>
</listitem>
<listitem>
<para>
We use Doxygen to document our source code. Functions shall be documented
using Doxygen-style comments (/** *).
See <ulink url="http://www.stack.nl/~dimitri/doxygen/manual.html">Doxygen Manual</ulink>
for more information and how to use it.
</para>
</listitem>
<listitem>
<para>
If you carefully formatted a comment, you may use the special comment
/*- */ (comment start is <quote>star minus</quote>) to prevent automatic
reformatting. This usually applies to the standard copyright notice.
</para>
<example>
<title>Standard copyright notice</title>
<screen>
/*-
* Copyright (C) 2010 Your Name <your_email_address>
*
* This file is released under the GNU General Public License.
* Refer to the COPYING file distributed with this package.
*/
</screen>
</example>
</listitem>
</itemizedlist>
</sect2>
<sect2 id="code-style-statements">
<title>Statement style</title>
<itemizedlist mark="opencircle">
<listitem>
<para><emphasis>Function declarations:</emphasis></para>
<para>
Function declarations have their declaration and
opening brace split across two lines.
</para>
<para>
Function names start in column one. The return type is placed on the
previous line.
</para>
<para>
There is no space between the function name and '('.
</para>
<example>
<title>A function declaration</title>
<screen>
/**
* This is a Doxygen function description.
*
* \param y The number of years
* \param str Pointer to a string containing X
* \return 0 on success; -1 on error
*/
int
this_is_a_function(int y, char *str)
{
code
}
</screen>
</example>
</listitem>
<listitem>
<para><emphasis>Operators:</emphasis></para>
<para>
There shall be a space characters before/after an operator or assignment,
except for increment (<quote>++</quote>) or decrement (<quote>--</quote>)
operators.
</para>
<example>
<title>Space around operators</title>
<screen>
if (p->dispSizes[dispID - 1] == 1 && p->width == 16) {
if (x >= 8) {
x -= 8;
relY = 1;
}
}
x--; /* Convert 1-based coords to 0-based */
y--;
</screen>
</example>
</listitem>
<listitem>
<para><emphasis>Function calls:</emphasis></para>
<para>
There shall be no space between the function call and the opening brace '(' of
the parameter list. Within the parameter list a space shall be after each
parameter.
</para>
<example>
<title>Function call</title>
<screen>
lib_vbar_static(drvthis, x, y, len, promille, options, p->cellheight, 0);
</screen>
</example>
</listitem>
<listitem>
<para><emphasis>Compound statements:</emphasis></para>
<para>
Opening braces occur on the same line as the
statement.
</para>
<para>
Else statements: Else statements are placed on a line of their own, even
is there is a previous closing brace.
</para>
<para>
Opening and closing braces may be omitted on single line compound
statements. However, if one part of an if-else-statement requires braces
the other part shall have braces as well.
</para>
<example>
<title>If-else with braces</title>
<screen>
if (...) {
code
}
else {
code
}
</screen>
</example>
<example>
<title>If-else with single statements</title>
<screen>
if (...)
print();
else
err = 1;
</screen>
</example>
<example>
<title>Other compound statements</title>
<screen>
while (...) {
code
}
for (a = 0; a < max; a++) {
code
}
/* case labels are not indented */
switch (icon) {
case ICON_BLOCK_FILLED:
HD44780_set_char(drvthis, 6, block_filled);
break;
case ICON_HEART_FILLED:
HD44780_set_char(drvthis, 0, heart_filled);
break;
case ICON_HEART_OPEN:
HD44780_set_char(drvthis, 0, heart_open);
break;
default:
return -1; /* Let the core do other icons */
}
</screen>
</example>
</listitem>
</itemizedlist>
</sect2>
<sect2 id="code-style-indent-profile">
<title>Example indent profile</title>
<para>The following example shows an indent profile that checks and corrects
the coding style guideline described above. Copy the following text into
file <filename>.indent.pro</filename> in your home directory.</para>
<example>
<title>indent.pro example</title>
<screen>
-TPrivateData
-TDriver
-l100
-lc79
-i8
-ip8
-di1
-cd33
-ci8
-cli0
-ts8
-ut
-nsob
-sc
-psl
-npcs
-lp
-fc1
-nbc
-nce
-brs
-br
-sbi0
-saw
-sai
-saf
-nprs
-hnl
-fca
-cdw
-nbfda
-nbbo
-ncdb
-nbad
-cs
</screen>
</example>
</sect2>
</sect1>
<sect1 id="submitting-code">
<title>Submitting code</title>
<para>When you have finished modifying the code you may decide to submit it to
the LCDproc project as a pull request.
<ulink url="https://help.github.com/articles/about-pull-requests/">Read the
documentation</ulink> to learn how to make one.</para>
</sect1>
</chapter>
|