aboutsummaryrefslogtreecommitdiff
path: root/doc/manual/style.txt
blob: 5434be082b843836718639187c102bc7fd2ce92b (plain)
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
/** @page styleguide Style Guides

The goals for each of these guides are:
- to produce correct code that appears clean, consistent, and readable,
- to allow developers to create patches that conform to a standard, and
- to eliminate these issues as points of future contention.

Some of these rules may be ignored in the spirit of these stated goals;
however, such exceptions should be fairly rare.

The following style guides describe a formatting, naming, and other
conventions that should be followed when writing or changing the OpenOCD
code:

- @subpage styletcl
- @subpage stylec
- @subpage styleperl
- @subpage styleautotools

In addition, the following style guides provide information for
providing documentation, either as part of the C code or stand-alone.

- @subpage styledoxygen
- @subpage styletexinfo
- @subpage stylelatex

Feedback would be welcome to improve the OpenOCD guidelines.

 */
/** @page styletcl TCL Style Guide

OpenOCD needs to expand its Jim/TCL Style Guide.

Many of the guidelines listed on the @ref stylec page should apply to
OpenOCD's Jim/TCL code as well.

 */
/** @page stylec C Style Guide

This page contains guidelines for writing new C source code for the
OpenOCD project.

@section styleformat Formatting Guide

- remove any trailing white space at the end of lines.
- use TAB characters for indentation; do NOT use spaces.
- displayed TAB width is 4 characters.
- use Unix line endings ('\\n'); do NOT use DOS endings ('\\r\\n')
- limit adjacent empty lines to at most two (2).
- remove any trailing empty lines at the end of source files
- do not "comment out" code from the tree; instead, one should either:
  -# remove it entirely (Subversion can retrieve the old version), or
  -# use an @c \#if/\#endif block.

Finally, try to avoid lines of code that are longer than than 72-80 columns:

- long lines frequently indicate other style problems:
  - insufficient use of static functions, macros, or temporary variables
  - poor flow-control structure; "inverted" logical tests
- a few lines may be wider than this limit (typically format strings), but:
  - all C compilers will concatenate series of string constants.
  - all long string constants should be split across multiple lines.

@section stylenames Naming Rules

- most identifiers must use lower-case letters (and digits) only.
  - macros must use upper-case letters (and digits) only.
  - OpenOCD identifiers should NEVER use @c MixedCaps.
- structure names must end with the '_s' suffix.
- typedef names must end with the '_t' suffix.
- use underline characters between consecutive words in identifiers
  (e.g. @c more_than_one_word).

@section stylec99 C99 Rules

- inline functions
- @c // comments -- in new code, prefer these for single-line comments
- trailing comma allowed in enum declarations
- designated initializers (@{ .field = value @})
- variables declarations may be mixed with code
- new block scopes for selection and iteration statements

@section stylefunc Functions

- static inline functions should be prefered over macros:
@code
/** do NOT define macro-like functions like this... */
#define CUBE(x) ((x) * (x) * (x))
/** instead, define the same expression using a C99 inline function */
static inline int cube(int x) { return x * x * x; }
@endcode
- Functions should be declared static unless required by other modules
  - define static functions before first usage to avoid forward declarations.
- Functions should have no space between its name and its parameter list:
@code
int f(int x1, int x2)
{
	...
	int y = f(x1, x2 - x1);
	...
}
@endcode

 */
/** @page styledoxygen Doxygen Style Guide

The following sections provide guidelines for OpenOCD developers
who wish to write Doxygen comments in the code or this manual.
For an introduction to Doxygen documentation,
see the @ref primerdoxygen.

@section styledoxyblocks Doxygen Block Selection

Several different types of Doxygen comments can be used; often,
one style will be the most appropriate for a specific context.
The following guidelines provide developers with heuristics for
selecting an appropriate form and writing consistent documentation
comments.

-# use @c /// to for one-line documentation of instances.
-# for documentation requiring multiple lines, use a "block" style:
@verbatim
/**
 * @brief First sentence is short description.  Remaining text becomes
 * the full description block, where "empty" lines start new paragraphs.
 *
 * One can make text appear in @a italics, @b bold, @c monospace, or
 * in blocks such as the one in which this example appears in the Style
 * Guide.  See the Doxygen Manual for the full list of commands.
 *
 * @param foo For a function, describe the parameters (e.g. @a foo). 
 * @returns The value(s) returned, or possible error conditions.
 */
@endverbatim
  -# The block should start on the line following the opening @c /**.
  -# The end of the block, \f$*/\f$, should also be on its own line.
  -# Every line in the block should have a @c '*' in-line with its start:
    - A leading space is required to align the @c '*' with the @c /** line.
    - A single "empty" line should separate the function documentation
      from the block of parameter and return value descriptions.
    - Except to separate paragraphs of documentation, other extra
      "empty" lines should be removed from the block.
  -# Only single spaces should be used; do @b not add mid-line indentation.
-# If the total line length will be less than 72-80 columns, then
  - The @c /**< form can be used on the same line.
  - This style should be used sparingly; the best use is for fields:
    @code int field; /**< field description */ @endcode

@section styledoxyall Doxygen Style Guide

The following guidelines apply to all Doxygen comment blocks:

-# Use the @c '\@cmd' form for all doxygen commands (do @b not use @c '\\cmd').
-# Use symbol names such that Doxygen automatically creates links:
  -# @c function_name() can be used to reference functions
    (e.g. flash_set_dirty()).
  -# @c struct_name::member_name should be used to reference structure
    fields in the documentation (e.g. @c flash_driver_s::name).
  -# URLS get converted to markup automatically, without any extra effort.
  -# new pages can be linked into the heirarchy by using the @c \@subpage
    command somewhere the page(s) under which they should be linked:
  -# use @c \@ref in other contexts to create links to pages and sections.
-# Use good Doxygen mark-up:
  -# '\@a' (italics) should be used to reference parameters (e.g. <i>foo</i>).
  -# '\@b' (bold) should be used to emphasizing <b>single</b> words.
  -# '\@c' (monospace) should be used with <code>file names</code> and
  <code>code symbols</code>, so they appear visually distinct from
  surrounding text.
  -# To mark-up multiple words, the HTML alternatives must be used.
-# Two spaces should be used when nesting lists; do @b not use '\\t' in lists.
-# Code examples provided in documentation must conform to the Style Guide.

@section styledoxytext Doxygen Text Inputs

In addition to the guidelines in the preceding sections, the following
additional style guidelines should be considered when writing
documentation as part of standalone text files:

-# Text files must contain Doxygen at least one comment block:
  -# Documentation should begin in the first column (except for nested lists).
  -# Do NOT use the @c '*' convention that must be used in the source code.
-# Each file should contain at least one @c \@page block.
  -# Each new page should be listed as a \@subpage in the \@page block
  of the page that should serve as its parent.
  -# Large pages should be structure in parts using meaningful \@section
  and \@subsection commands.
-# Include a @c \@file block at the end of each Doxygen @c .txt file to
  document its contents:
  - Doxygen creates such pages for files automatically, but no content
    will appear on them for those that only contain manual pages.
  - The \@file block should provide useful meta-documentation to assist
    techincal writers; typically, a list of the pages that it contains.
  - For example, the @ref styleguide exists in @c doc/manual/style.txt,
    which contains a reference back to itself.
-# The \@file and \@page commands should begin on the same line as
   the start of the Doxygen comment:
@verbatim
/** @page pagename Page Title

Documentation for the page.

 */
/** @file

This file contains the @ref pagename page.

 */
@endverbatim

For an example, the Doxygen source for this Style Guide can be found in
@c doc/manual/style.txt, alongside other parts of The Manual.  

 */
/** @page styletexinfo Texinfo Style Guide

This page needs to provide style guidelines for Texinfo, the mark-up
language used by The Guide for OpenOCD Users.

 */
/** @page stylelatex LaTeX Style Guide

This page needs to provide style guidelines for using LaTeX, the
typesetting language used by The References for OpenOCD Hardware.
Likewise, the @ref primerlatex for using this guide needs to be completed.

 */
/** @page styleperl Perl Style Guide

This page provides some style guidelines for using Perl, a scripting
language used by several small tools in the tree:

-# Ensure all Perl scripts use the proper suffix (@c .pl for scripts, and 
   @c .pm for modules)
-# Pass files as script parameters or piped as input:
  - Do NOT code paths to files in the tree, as this breaks out-of-tree builds.
  - If you must, then you must also use an automake rule to create the script.
-# use @c '#!/usr/bin/perl' as the first line of Perl scripts.
-# always <code>use strict</code> and <code>use warnings</code>
-# invoke scripts indirectly in Makefiles or other scripts:
@code
perl script.pl
@endcode

Maintainers must also be sure to follow additional guidelines:
-# Ensure that Perl scripts are committed as executables:
  - Use "<code>chmod +x script.pl</code>"
    @a before using "<code>svn add script.pl</code>", or
  - Use "<code>svn ps svn:executable '*' script.pl</code>"
    @a after using "<code>svn add script.pl</code>".

 */
/** @page styleautotools Autotools Style Guide

This page contains style guidelines for the OpenOCD autotools scripts.

The following guidelines apply to the @c configure.in file:
- Better guidelines need to be developed, but until then...
- Use good judgement.

The following guidelines apply to @c Makefile.am files:
-# When assigning variables with long lists of items:
  -# Separate the values on each line to make the files "patch friendly":
@code
VAR = \
	value1 \
	value2 \
	...
	value9 \
	value10
@endcode
 */
/** @file

This file contains the @ref styleguide pages.  The @ref styleguide pages
include the following Style Guides for their respective code and
documentation languages:

- @ref styletcl
- @ref stylec
- @ref styledoxygen
- @ref styletexinfo
- @ref stylelatex
- @ref styleperl
- @ref styleautotools

 */