jtag: linuxgpiod: drop extra parenthesis
[openocd.git] / doc / manual / style.txt
1 /** @page styleguide Style Guides
2
3 The goals for each of these guides are:
4 - to produce correct code that appears clean, consistent, and readable,
5 - to allow developers to create patches that conform to a standard, and
6 - to eliminate these issues as points of future contention.
7
8 Some of these rules may be ignored in the spirit of these stated goals;
9 however, such exceptions should be fairly rare.
10
11 The following style guides describe a formatting, naming, and other
12 conventions that should be followed when writing or changing the OpenOCD
13 code:
14
15 - @subpage styletcl
16 - @subpage stylec
17 - @subpage styleperl
18 - @subpage styleautotools
19
20 In addition, the following style guides provide information for
21 providing documentation, either as part of the C code or stand-alone.
22
23 - @subpage styledoxygen
24 - @subpage styletexinfo
25 - @subpage stylelatex
26
27 Feedback would be welcome to improve the OpenOCD guidelines.
28
29 */
30 /** @page styletcl TCL Style Guide
31
32 OpenOCD needs to expand its Jim/TCL Style Guide.
33
34 Many of the guidelines listed on the @ref stylec page should apply to
35 OpenOCD's Jim/TCL code as well.
36
37 */
38 /** @page stylec C Style Guide
39
40 This page contains guidelines for writing new C source code for the
41 OpenOCD project.
42
43 @section styleformat Formatting Guide
44
45 - remove any trailing white space at the end of lines.
46 - use TAB characters for indentation; do NOT use spaces.
47 - displayed TAB width is 4 characters.
48 - use Unix line endings ('\\n'); do NOT use DOS endings ('\\r\\n')
49 - limit adjacent empty lines to at most two (2).
50 - remove any trailing empty lines at the end of source files
51 - do not "comment out" code from the tree nor put it within a block
52 @code
53 #if 0
54 ...
55 #endif
56 @endcode
57 otherwise it would never be checked at compile time and when new
58 patches get merged it could be not compilable anymore.
59 Code that is not fully working nor ready for submission should
60 instead be removed entirely (git can retrieve the old version).
61 For exceptional cases that require keeping some unused code, let
62 the compiler check it by putting it in a block
63 @code
64 if (false) {
65 /* explain why this code should be kept here */
66 ...
67 }
68 @endcode
69 - in a @c switch statement align the @c switch with the @c case label
70 @code
71 switch (dev_id) {
72 case 0x0123:
73 size = 0x10000;
74 break;
75 case 0x0412:
76 size = 0x20000;
77 break;
78 default:
79 size = 0x40000;
80 break;
81 }
82 @endcode
83 - in an <tt> if / then / else </tt> statement, if only one of the conditions
84 require curly brackets due to multi-statement block, put the curly brackets
85 also to the other condition
86 @code
87 if (x > 0)
88 a = 12 + x;
89 else
90 a = 24;
91 @endcode
92 @code
93 if (x > 0) {
94 a = 12 + x;
95 } else {
96 a = 24;
97 x = 0;
98 }
99 @endcode
100
101 Finally, try to avoid lines of code that are longer than 72-80 columns:
102
103 - long lines frequently indicate other style problems:
104 - insufficient use of static functions, macros, or temporary variables
105 - poor flow-control structure; "inverted" logical tests
106 - a few lines may be wider than this limit (typically format strings), but:
107 - all C compilers will concatenate series of string constants.
108 - all long string constants should be split across multiple lines.
109 - do never exceed 120 columns.
110
111 @section stylenames Naming Rules
112
113 - most identifiers must use lower-case letters (and digits) only.
114 - macros must use upper-case letters (and digits) only.
115 - OpenOCD identifiers should NEVER use @c MixedCaps.
116 - @c typedef names must end with the '_t' suffix.
117 - This should be reserved for types that should be passed by value.
118 - Do @b not mix the typedef keyword with @c struct.
119 - use underline characters between consecutive words in identifiers
120 (e.g. @c more_than_one_word).
121
122 @section style_include_guards Include Guards
123
124 Every header file should have a unique include guard to prevent multiple
125 inclusion.
126 To guarantee uniqueness, an include guard should be based on the filename and
127 the full path in the project source tree.
128
129 For the header file src/helper/jim-nvp.h, the include guard would look like
130 this:
131
132 @code
133 #ifndef OPENOCD_HELPER_JIM_NVP_H
134 #define OPENOCD_HELPER_JIM_NVP_H
135
136 /* Your code here. */
137
138 #endif /* OPENOCD_HELPER_JIM_NVP_H */
139 @endcode
140
141 @section stylec99 C99 Rules
142
143 - inline functions
144 - @c // comments -- in new code, prefer these for single-line comments
145 - trailing comma allowed in enum declarations
146 - designated initializers ( .field = value )
147 - variables declarations should occur at the point of first use
148 - new block scopes for selection and iteration statements
149 - use malloc() to create dynamic arrays. Do @b not use @c alloca
150 or variable length arrays on the stack. non-MMU hosts(uClinux) and
151 pthreads require modest and predictable stack usage.
152
153 @section styletypes Type Guidelines
154 - use native types (@c int or <tt> unsigned int </tt>) if the type is not important
155 - if size matters, use the types from \<stdint.h\> or \<inttypes.h\>:
156 - @c int8_t, @c int16_t, @c int32_t, or @c int64_t: signed types of specified size
157 - @c uint8_t, @c uint16_t, @c uint32_t, or @c uint64_t: unsigned types of specified size
158 - use the associated @c printf and @c scanf formatting strings for these types
159 (e.g. @c PRId8, PRIx16, SCNu8, ...)
160 - do @b NOT redefine @c uN types from "types.h"
161 - use type @c target_addr_t for target's address values
162 - prefer type <tt> unsigned int </tt> to type @c unsigned
163
164 @section stylefunc Functions
165
166 - static inline functions should be preferred over macros:
167 @code
168 /* do NOT define macro-like functions like this... */
169 #define CUBE(x) ((x) * (x) * (x))
170 /* instead, define the same expression using a C99 inline function */
171 static inline int cube(int x) { return x * x * x; }
172 @endcode
173 - Functions should be declared static unless required by other modules
174 - define static functions before first usage to avoid forward declarations.
175 - Functions should have no space between its name and its parameter list:
176 @code
177 int f(int x1, int x2)
178 {
179 ...
180 int y = f(x1, x2 - x1);
181 ...
182 }
183 @endcode
184 - Separate assignment and logical test statements. In other words, you
185 should write statements like the following:
186 @code
187 // separate statements should be preferred
188 result = foo();
189 if (result != ERROR_OK)
190 ...
191 @endcode
192 More directly, do @b not combine these kinds of statements:
193 @code
194 // Combined statements should be avoided
195 if ((result = foo()) != ERROR_OK)
196 return result;
197 @endcode
198 - Do not compare @c bool values with @c true or @c false but use the
199 value directly
200 @code
201 if (!is_enabled)
202 ...
203 @endcode
204 - Avoid comparing pointers with @c NULL
205 @code
206 buf = malloc(buf_size);
207 if (!buf) {
208 LOG_ERROR("Out of memory");
209 return ERROR_FAIL;
210 }
211 @endcode
212
213 */
214 /** @page styledoxygen Doxygen Style Guide
215
216 The following sections provide guidelines for OpenOCD developers
217 who wish to write Doxygen comments in the code or this manual.
218 For an introduction to Doxygen documentation,
219 see the @ref primerdoxygen.
220
221 @section styledoxyblocks Doxygen Block Selection
222
223 Several different types of Doxygen comments can be used; often,
224 one style will be the most appropriate for a specific context.
225 The following guidelines provide developers with heuristics for
226 selecting an appropriate form and writing consistent documentation
227 comments.
228
229 -# use @c /// to for one-line documentation of instances.
230 -# for documentation requiring multiple lines, use a "block" style:
231 @verbatim
232 /**
233 * @brief First sentence is short description. Remaining text becomes
234 * the full description block, where "empty" lines start new paragraphs.
235 *
236 * One can make text appear in @a italics, @b bold, @c monospace, or
237 * in blocks such as the one in which this example appears in the Style
238 * Guide. See the Doxygen Manual for the full list of commands.
239 *
240 * @param foo For a function, describe the parameters (e.g. @a foo).
241 * @returns The value(s) returned, or possible error conditions.
242 */
243 @endverbatim
244 -# The block should start on the line following the opening @c /\**.
245 -# The end of the block, @c *&zwj;/, should also be on its own line.
246 -# Every line in the block should have a @c '*' in-line with its start:
247 - A leading space is required to align the @c '*' with the @c /\** line.
248 - A single "empty" line should separate the function documentation
249 from the block of parameter and return value descriptions.
250 - Except to separate paragraphs of documentation, other extra
251 "empty" lines should be removed from the block.
252 -# Only single spaces should be used; do @b not add mid-line indentation.
253 -# If the total line length will be less than 72-80 columns, then
254 - The @c /\**< form can be used on the same line.
255 - This style should be used sparingly; the best use is for fields:
256 @verbatim int field; /**< field description */ @endverbatim
257
258 @section styledoxyall Doxygen Style Guide
259
260 The following guidelines apply to all Doxygen comment blocks:
261
262 -# Use the @c '\@cmd' form for all doxygen commands (do @b not use @c '\\cmd').
263 -# Use symbol names such that Doxygen automatically creates links:
264 -# @c function_name() can be used to reference functions
265 (e.g. flash_set_dirty()).
266 -# @c struct_name::member_name should be used to reference structure
267 fields in the documentation (e.g. @c flash_driver::name).
268 -# URLS get converted to markup automatically, without any extra effort.
269 -# new pages can be linked into the hierarchy by using the @c \@subpage
270 command somewhere the page(s) under which they should be linked:
271 -# use @c \@ref in other contexts to create links to pages and sections.
272 -# Use good Doxygen mark-up:
273 -# '\@a' (italics) should be used to reference parameters (e.g. <i>foo</i>).
274 -# '\@b' (bold) should be used to emphasizing <b>single</b> words.
275 -# '\@c' (monospace) should be used with <code>file names</code> and
276 <code>code symbols</code>, so they appear visually distinct from
277 surrounding text.
278 -# To mark-up multiple words, the HTML alternatives must be used.
279 -# Two spaces should be used when nesting lists; do @b not use '\\t' in lists.
280 -# Code examples provided in documentation must conform to the Style Guide.
281
282 @section styledoxytext Doxygen Text Inputs
283
284 In addition to the guidelines in the preceding sections, the following
285 additional style guidelines should be considered when writing
286 documentation as part of standalone text files:
287
288 -# Text files must contain Doxygen at least one comment block:
289 -# Documentation should begin in the first column (except for nested lists).
290 -# Do NOT use the @c '*' convention that must be used in the source code.
291 -# Each file should contain at least one @c \@page block.
292 -# Each new page should be listed as a \@subpage in the \@page block
293 of the page that should serve as its parent.
294 -# Large pages should be structure in parts using meaningful \@section
295 and \@subsection commands.
296 -# Include a @c \@file block at the end of each Doxygen @c .txt file to
297 document its contents:
298 - Doxygen creates such pages for files automatically, but no content
299 will appear on them for those that only contain manual pages.
300 - The \@file block should provide useful meta-documentation to assist
301 technical writers; typically, a list of the pages that it contains.
302 - For example, the @ref styleguide exists in @c doc/manual/style.txt,
303 which contains a reference back to itself.
304 -# The \@file and \@page commands should begin on the same line as
305 the start of the Doxygen comment:
306 @verbatim
307 /** @page pagename Page Title
308
309 Documentation for the page.
310
311 */
312 /** @file
313
314 This file contains the @ref pagename page.
315
316 */
317 @endverbatim
318
319 For an example, the Doxygen source for this Style Guide can be found in
320 @c doc/manual/style.txt, alongside other parts of The Manual.
321
322 */
323 /** @page styletexinfo Texinfo Style Guide
324
325 The User's Guide is there to provide two basic kinds of information. It
326 is a guide for how and why to use each feature or mechanism of OpenOCD.
327 It is also the reference manual for all commands and options involved
328 in using them, including interface, flash, target, and other drivers.
329 At this time, it is the only documentation for end users; everything
330 else is addressing OpenOCD developers.
331
332 There are two key audiences for the User's Guide, both developer based.
333 The primary audience is developers using OpenOCD as a tool in their
334 work, or who may be starting to use it that way. A secondary audience
335 includes developers who are supporting those users by packaging or
336 customizing it for their hardware, installing it as part of some software
337 distribution, or by evolving OpenOCD itself. There is some crossover
338 between those audiences. We encourage contributions from users as the
339 fundamental way to evolve and improve OpenOCD. In particular, creating
340 a board or target specific configuration file is something that many
341 users will end up doing at some point, and we like to see such files
342 become part of the mainline release.
343
344 General documentation rules to remember include:
345
346 - Be concise and clear. It's work to remove those extra words and
347 sentences, but such "noise" doesn't help readers.
348 - Make it easy to skim and browse. "Tell what you're going to say,
349 then say it". Help readers decide whether to dig in now, or
350 leave it for later.
351 - Make sure the chapters flow well. Presentations should not jump
352 around, and should move easily from overview down to details.
353 - Avoid using the passive voice.
354 - Address the reader to clarify roles ("your config file", "the board you
355 are debugging", etc.); "the user" (etc) is artificial.
356 - Use good English grammar and spelling. Remember also that English
357 will not be the first language for many readers. Avoid complex or
358 idiomatic usage that could create needless barriers.
359 - Use examples to highlight fundamental ideas and common idioms.
360 - Don't overuse list constructs. This is not a slide presentation;
361 prefer paragraphs.
362
363 When presenting features and mechanisms of OpenOCD:
364
365 - Explain key concepts before presenting commands using them.
366 - Tie examples to common developer tasks.
367 - When giving instructions, you can \@enumerate each step both
368 to clearly delineate the steps, and to highlight that this is
369 not explanatory text.
370 - When you provide "how to use it" advice or tutorials, keep it
371 in separate sections from the reference material.
372 - Good indexing is something of a black art. Use \@cindex for important
373 concepts, but don't overuse it. In particular, rely on the \@deffn
374 indexing, and use \@cindex primarily with significant blocks of text
375 such as \@subsection. The \@dfn of a key term may merit indexing.
376 - Use \@xref (and \@anchor) with care. Hardcopy versions, from the PDF,
377 must make sense without clickable links (which don't work all that well
378 with Texinfo in any case). If you find you're using many links,
379 read that as a symptom that the presentation may be disjointed and
380 confusing.
381 - Avoid font tricks like \@b, but use \@option, \@file, \@dfn, \@emph
382 and related mechanisms where appropriate.
383
384 For technical reference material:
385
386 - It's OK to start sections with explanations and end them with
387 detailed lists of the relevant commands.
388 - Use the \@deffn style declarations to define all commands and drivers.
389 These will automatically appear in the relevant index, and those
390 declarations help promote consistent presentation and style.
391 - It's a "Command" if it can be used interactively.
392 - Else it's a "Config Command" if it must be used before the
393 configuration stage completes.
394 - For a "Driver", list its name.
395 - Use EBNF style regular expressions to define parameters:
396 brackets around zero-or-one choices, parentheses around
397 exactly-one choices.
398 - Use \@option, \@file, \@var and other mechanisms where appropriate.
399 - Say what output it displays, and what value it returns to callers.
400 - Explain clearly what the command does. Sometimes you will find
401 that it can't be explained clearly. That usually means the command
402 is poorly designed; replace it with something better, if you can.
403 - Be complete: document all commands, except as part of a strategy
404 to phase something in or out.
405 - Be correct: review the documentation against the code, and
406 vice versa.
407 - Alphabetize the \@defn declarations for all commands in each
408 section.
409 - Keep the per-command documentation focused on exactly what that
410 command does, not motivation, advice, suggestions, or big examples.
411 When commands deserve such expanded text, it belongs elsewhere.
412 Solutions might be using a \@section explaining a cluster of related
413 commands, or acting as a mini-tutorial.
414 - Details for any given driver should be grouped together.
415
416 The User's Guide is the first place most users will start reading,
417 after they begin using OpenOCD. Make that investment of their time
418 be as productive as possible. Needing to look at OpenOCD source code,
419 to figure out how to use it is a bad sign, though it's OK to need to
420 look at the User's guide to figure out what a config script is doing.
421
422 */
423 /** @page stylelatex LaTeX Style Guide
424
425 This page needs to provide style guidelines for using LaTeX, the
426 typesetting language used by The References for OpenOCD Hardware.
427 Likewise, the @ref primerlatex for using this guide needs to be completed.
428
429 */
430 /** @page styleperl Perl Style Guide
431
432 This page provides some style guidelines for using Perl, a scripting
433 language used by several small tools in the tree:
434
435 -# Ensure all Perl scripts use the proper suffix (@c .pl for scripts, and
436 @c .pm for modules)
437 -# Pass files as script parameters or piped as input:
438 - Do NOT code paths to files in the tree, as this breaks out-of-tree builds.
439 - If you must, then you must also use an automake rule to create the script.
440 -# use @c '#!/usr/bin/perl' as the first line of Perl scripts.
441 -# always <code>use strict</code> and <code>use warnings</code>
442 -# invoke scripts indirectly in Makefiles or other scripts:
443 @code
444 perl script.pl
445 @endcode
446
447 Maintainers must also be sure to follow additional guidelines:
448 -# Ensure that Perl scripts are committed as executables:
449 Use "<code>chmod +x script.pl</code>"
450 @a before using "<code>git add script.pl</code>"
451
452 */
453 /** @page styleautotools Autotools Style Guide
454
455 This page contains style guidelines for the OpenOCD autotools scripts.
456
457 The following guidelines apply to the @c configure.ac file:
458 - Better guidelines need to be developed, but until then...
459 - Use good judgement.
460
461 The following guidelines apply to @c Makefile.am files:
462 -# When assigning variables with long lists of items:
463 -# Separate the values on each line to make the files "patch friendly":
464 @code
465 VAR = \
466 value1 \
467 value2 \
468 ...
469 value9 \
470 value10
471 @endcode
472 */
473 /** @file
474
475 This file contains the @ref styleguide pages. The @ref styleguide pages
476 include the following Style Guides for their respective code and
477 documentation languages:
478
479 - @ref styletcl
480 - @ref stylec
481 - @ref styledoxygen
482 - @ref styletexinfo
483 - @ref stylelatex
484 - @ref styleperl
485 - @ref styleautotools
486
487 */

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)