Change most in-tree references from SVN to GIT.
[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; instead, one should either:
52 -# remove it entirely (git can retrieve the old version), or
53 -# use an @c \#if/\#endif block.
54
55 Finally, try to avoid lines of code that are longer than than 72-80 columns:
56
57 - long lines frequently indicate other style problems:
58 - insufficient use of static functions, macros, or temporary variables
59 - poor flow-control structure; "inverted" logical tests
60 - a few lines may be wider than this limit (typically format strings), but:
61 - all C compilers will concatenate series of string constants.
62 - all long string constants should be split across multiple lines.
63
64 @section stylenames Naming Rules
65
66 - most identifiers must use lower-case letters (and digits) only.
67 - macros must use upper-case letters (and digits) only.
68 - OpenOCD identifiers should NEVER use @c MixedCaps.
69 - structure names must end with the '_s' suffix.
70 - typedef names must end with the '_t' suffix.
71 - use underline characters between consecutive words in identifiers
72 (e.g. @c more_than_one_word).
73
74 @section stylec99 C99 Rules
75
76 - inline functions
77 - @c // comments -- in new code, prefer these for single-line comments
78 - trailing comma allowed in enum declarations
79 - designated initializers (@{ .field = value @})
80 - variables declarations may be mixed with code
81 - new block scopes for selection and iteration statements
82
83 @section styletypes Type Guidelines
84 - use native types (@c int or @c unsigned) if the type is not important
85 - if size matters, use the types from \<stdint.h\> or \<inttypes.h\>:
86 - @c int8_t, @c int16_t, @c int32_t, or @c int64_t: signed types of specified size
87 - @c uint8_t, @c uint16_t, @c uint32_t, or @c uint64_t: unsigned types of specified size
88 - do @b NOT redefine @c uN types from "types.h"
89
90 @section stylefunc Functions
91
92 - static inline functions should be prefered over macros:
93 @code
94 /** do NOT define macro-like functions like this... */
95 #define CUBE(x) ((x) * (x) * (x))
96 /** instead, define the same expression using a C99 inline function */
97 static inline int cube(int x) { return x * x * x; }
98 @endcode
99 - Functions should be declared static unless required by other modules
100 - define static functions before first usage to avoid forward declarations.
101 - Functions should have no space between its name and its parameter list:
102 @code
103 int f(int x1, int x2)
104 {
105 ...
106 int y = f(x1, x2 - x1);
107 ...
108 }
109 @endcode
110 - Separate assignment and logical test statements. In other words, you
111 should write statements like the following:
112 @code
113 // separate statements should be preferred
114 result = foo();
115 if (ERROR_OK != result)
116 ...
117 @endcode
118 More directly, do @b not combine these kinds of statements:
119 @code
120 // Combined statements should be avoided
121 if (ERROR_OK != (result = foo()))
122 return result;
123 @endcode
124
125 */
126 /** @page styledoxygen Doxygen Style Guide
127
128 The following sections provide guidelines for OpenOCD developers
129 who wish to write Doxygen comments in the code or this manual.
130 For an introduction to Doxygen documentation,
131 see the @ref primerdoxygen.
132
133 @section styledoxyblocks Doxygen Block Selection
134
135 Several different types of Doxygen comments can be used; often,
136 one style will be the most appropriate for a specific context.
137 The following guidelines provide developers with heuristics for
138 selecting an appropriate form and writing consistent documentation
139 comments.
140
141 -# use @c /// to for one-line documentation of instances.
142 -# for documentation requiring multiple lines, use a "block" style:
143 @verbatim
144 /**
145 * @brief First sentence is short description. Remaining text becomes
146 * the full description block, where "empty" lines start new paragraphs.
147 *
148 * One can make text appear in @a italics, @b bold, @c monospace, or
149 * in blocks such as the one in which this example appears in the Style
150 * Guide. See the Doxygen Manual for the full list of commands.
151 *
152 * @param foo For a function, describe the parameters (e.g. @a foo).
153 * @returns The value(s) returned, or possible error conditions.
154 */
155 @endverbatim
156 -# The block should start on the line following the opening @c /**.
157 -# The end of the block, \f$*/\f$, should also be on its own line.
158 -# Every line in the block should have a @c '*' in-line with its start:
159 - A leading space is required to align the @c '*' with the @c /** line.
160 - A single "empty" line should separate the function documentation
161 from the block of parameter and return value descriptions.
162 - Except to separate paragraphs of documentation, other extra
163 "empty" lines should be removed from the block.
164 -# Only single spaces should be used; do @b not add mid-line indentation.
165 -# If the total line length will be less than 72-80 columns, then
166 - The @c /**< form can be used on the same line.
167 - This style should be used sparingly; the best use is for fields:
168 @code int field; /**< field description */ @endcode
169
170 @section styledoxyall Doxygen Style Guide
171
172 The following guidelines apply to all Doxygen comment blocks:
173
174 -# Use the @c '\@cmd' form for all doxygen commands (do @b not use @c '\\cmd').
175 -# Use symbol names such that Doxygen automatically creates links:
176 -# @c function_name() can be used to reference functions
177 (e.g. flash_set_dirty()).
178 -# @c struct_name::member_name should be used to reference structure
179 fields in the documentation (e.g. @c flash_driver_s::name).
180 -# URLS get converted to markup automatically, without any extra effort.
181 -# new pages can be linked into the heirarchy by using the @c \@subpage
182 command somewhere the page(s) under which they should be linked:
183 -# use @c \@ref in other contexts to create links to pages and sections.
184 -# Use good Doxygen mark-up:
185 -# '\@a' (italics) should be used to reference parameters (e.g. <i>foo</i>).
186 -# '\@b' (bold) should be used to emphasizing <b>single</b> words.
187 -# '\@c' (monospace) should be used with <code>file names</code> and
188 <code>code symbols</code>, so they appear visually distinct from
189 surrounding text.
190 -# To mark-up multiple words, the HTML alternatives must be used.
191 -# Two spaces should be used when nesting lists; do @b not use '\\t' in lists.
192 -# Code examples provided in documentation must conform to the Style Guide.
193
194 @section styledoxytext Doxygen Text Inputs
195
196 In addition to the guidelines in the preceding sections, the following
197 additional style guidelines should be considered when writing
198 documentation as part of standalone text files:
199
200 -# Text files must contain Doxygen at least one comment block:
201 -# Documentation should begin in the first column (except for nested lists).
202 -# Do NOT use the @c '*' convention that must be used in the source code.
203 -# Each file should contain at least one @c \@page block.
204 -# Each new page should be listed as a \@subpage in the \@page block
205 of the page that should serve as its parent.
206 -# Large pages should be structure in parts using meaningful \@section
207 and \@subsection commands.
208 -# Include a @c \@file block at the end of each Doxygen @c .txt file to
209 document its contents:
210 - Doxygen creates such pages for files automatically, but no content
211 will appear on them for those that only contain manual pages.
212 - The \@file block should provide useful meta-documentation to assist
213 techincal writers; typically, a list of the pages that it contains.
214 - For example, the @ref styleguide exists in @c doc/manual/style.txt,
215 which contains a reference back to itself.
216 -# The \@file and \@page commands should begin on the same line as
217 the start of the Doxygen comment:
218 @verbatim
219 /** @page pagename Page Title
220
221 Documentation for the page.
222
223 */
224 /** @file
225
226 This file contains the @ref pagename page.
227
228 */
229 @endverbatim
230
231 For an example, the Doxygen source for this Style Guide can be found in
232 @c doc/manual/style.txt, alongside other parts of The Manual.
233
234 */
235 /** @page styletexinfo Texinfo Style Guide
236
237 The User's Guide is there to provide two basic kinds of information. It
238 is a guide for how and why to use each feature or mechanism of OpenOCD.
239 It is also the reference manual for all commands and options involved
240 in using them, including interface, flash, target, and other drivers.
241 At this time, it is the only user-targetted documentation; everything
242 else is addressing OpenOCD developers.
243
244 There are two key audiences for the User's Guide, both developer based.
245 The primary audience is developers using OpenOCD as a tool in their
246 work, or who may be starting to use it that way. A secondary audience
247 includes developers who are supporting those users by packaging or
248 customizing it for their hardware, installing it as part of some software
249 distribution, or by evolving OpenOCD itself. There is some crossover
250 between those audiences. We encourage contributions from users as the
251 fundamental way to evolve and improve OpenOCD. In particular, creating
252 a board or target specific configuration file is something that many
253 users will end up doing at some point, and we like to see such files
254 become part of the mainline release.
255
256 General documentation rules to remember include:
257
258 - Be concise and clear. It's work to remove those extra words and
259 sentences, but such "noise" doesn't help readers.
260 - Make it easy to skim and browse. "Tell what you're going to say,
261 then say it". Help readers decide whether to dig in now, or
262 leave it for later.
263 - Make sure the chapters flow well. Presentations should not jump
264 around, and should move easily from overview down to details.
265 - Avoid using the passive voice.
266 - Address the reader to clarify roles ("your config file", "the board you
267 are debugging", etc.); "the user" (etc) is artificial.
268 - Use good English grammar and spelling. Remember also that English
269 will not be the first language for many readers. Avoid complex or
270 idiomatic usage that could create needless barriers.
271 - Use examples to highlight fundamental ideas and common idioms.
272 - Don't overuse list constructs. This is not a slide presentation;
273 prefer paragraphs.
274
275 When presenting features and mechanisms of OpenOCD:
276
277 - Explain key concepts before presenting commands using them.
278 - Tie examples to common developer tasks.
279 - When giving instructions, you can \@enumerate each step both
280 to clearly delineate the steps, and to highlight that this is
281 not explanatory text.
282 - When you provide "how to use it" advice or tutorials, keep it
283 in separate sections from the reference material.
284 - Good indexing is something of a black art. Use \@cindex for important
285 concepts, but don't overuse it. In particular, rely on the \@deffn
286 indexing, and use \@cindex primarily with significant blocks of text
287 such as \@subsection. The \@dfn of a key term may merit indexing.
288 - Use \@xref (and \@anchor) with care. Hardcopy versions, from the PDF,
289 must make sense without clickable links (which don't work all that well
290 with Texinfo in any case). If you find you're using many links,
291 read that as a symptom that the presentation may be disjointed and
292 confusing.
293 - Avoid font tricks like \@b, but use \@option, \@file, \@dfn, \@emph
294 and related mechanisms where appropriate.
295
296 For technical reference material:
297
298 - It's OK to start sections with explanations and end them with
299 detailed lists of the relevant commands.
300 - Use the \@deffn style declarations to define all commands and drivers.
301 These will automatically appear in the relevant index, and those
302 declarations help promote consistent presentation and style.
303 - It's a "Command" if it can be used interactively.
304 - Else it's a "Config Command" if it must be used before the
305 configuration stage completes.
306 - For a "Driver", list its name.
307 - Use BNF style regular expressions to define parameters:
308 brackets around zero-or-one choices, parentheses around
309 exactly-one choices.
310 - Use \@option, \@file, \@var and other mechanisms where appropriate.
311 - Say what output it displays, and what value it returns to callers.
312 - Explain clearly what the command does. Sometimes you will find
313 that it can't be explained clearly. That usually means the command
314 is poorly designed; replace it with something better, if you can.
315 - Be complete: document all commands, except as part of a strategy
316 to phase something in or out.
317 - Be correct: review the documentation against the code, and
318 vice versa.
319 - Alphabetize the \@defn declarations for all commands in each
320 section.
321 - Keep the per-command documentation focussed on exactly what that
322 command does, not motivation, advice, suggestions, or big examples.
323 When commands deserve such expanded text, it belongs elsewhere.
324 Solutions might be using a \@section explaining a cluster of related
325 commands, or acting as a mini-tutorial.
326 - Details for any given driver should be grouped together.
327
328 The User's Guide is the first place most users will start reading,
329 after they begin using OpenOCD. Make that investment of their time
330 be as productive as possible. Needing to look at OpenOCD source code,
331 to figure out how to use it is a bad sign, though it's OK to need to
332 look at the User's guide to figure out what a config script is doing.
333
334 */
335 /** @page stylelatex LaTeX Style Guide
336
337 This page needs to provide style guidelines for using LaTeX, the
338 typesetting language used by The References for OpenOCD Hardware.
339 Likewise, the @ref primerlatex for using this guide needs to be completed.
340
341 */
342 /** @page styleperl Perl Style Guide
343
344 This page provides some style guidelines for using Perl, a scripting
345 language used by several small tools in the tree:
346
347 -# Ensure all Perl scripts use the proper suffix (@c .pl for scripts, and
348 @c .pm for modules)
349 -# Pass files as script parameters or piped as input:
350 - Do NOT code paths to files in the tree, as this breaks out-of-tree builds.
351 - If you must, then you must also use an automake rule to create the script.
352 -# use @c '#!/usr/bin/perl' as the first line of Perl scripts.
353 -# always <code>use strict</code> and <code>use warnings</code>
354 -# invoke scripts indirectly in Makefiles or other scripts:
355 @code
356 perl script.pl
357 @endcode
358
359 Maintainers must also be sure to follow additional guidelines:
360 -# Ensure that Perl scripts are committed as executables:
361 Use "<code>chmod +x script.pl</code>"
362 @a before using "<code>git add script.pl</code>"
363
364 */
365 /** @page styleautotools Autotools Style Guide
366
367 This page contains style guidelines for the OpenOCD autotools scripts.
368
369 The following guidelines apply to the @c configure.in file:
370 - Better guidelines need to be developed, but until then...
371 - Use good judgement.
372
373 The following guidelines apply to @c Makefile.am files:
374 -# When assigning variables with long lists of items:
375 -# Separate the values on each line to make the files "patch friendly":
376 @code
377 VAR = \
378 value1 \
379 value2 \
380 ...
381 value9 \
382 value10
383 @endcode
384 */
385 /** @file
386
387 This file contains the @ref styleguide pages. The @ref styleguide pages
388 include the following Style Guides for their respective code and
389 documentation languages:
390
391 - @ref styletcl
392 - @ref stylec
393 - @ref styledoxygen
394 - @ref styletexinfo
395 - @ref stylelatex
396 - @ref styleperl
397 - @ref styleautotools
398
399 */

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)