summaryrefslogtreecommitdiff
path: root/src/contrib/SDL-3.2.20/docs/README-documentation-rules.md
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2025-08-30 16:53:58 -0700
committer3gg <3gg@shellblade.net>2025-08-30 16:53:58 -0700
commit6aaedb813fa11ba0679c3051bc2eb28646b9506c (patch)
tree34acbfc9840e02cb4753e6306ea7ce978bf8b58e /src/contrib/SDL-3.2.20/docs/README-documentation-rules.md
parent8f228ade99dd3d4c8da9b78ade1815c9adf85c8f (diff)
Update to SDL3
Diffstat (limited to 'src/contrib/SDL-3.2.20/docs/README-documentation-rules.md')
-rw-r--r--src/contrib/SDL-3.2.20/docs/README-documentation-rules.md410
1 files changed, 410 insertions, 0 deletions
diff --git a/src/contrib/SDL-3.2.20/docs/README-documentation-rules.md b/src/contrib/SDL-3.2.20/docs/README-documentation-rules.md
new file mode 100644
index 0000000..3151de7
--- /dev/null
+++ b/src/contrib/SDL-3.2.20/docs/README-documentation-rules.md
@@ -0,0 +1,410 @@
1# Rules for documentation
2
3These are the rules for the care and feeding of wikiheaders.pl.
4
5
6## No style guide
7
8When adding or editing documentation, we don't (currently) have a style guide
9for what it should read like, so try to make it consistent with the rest of
10the existing text. It generally should read more like technical reference
11manuals and not sound conversational in tone.
12
13Most of these rules are about how to make sure the documentation works on
14a _technical_ level, as scripts need to parse it, and there are a few simple
15rules we need to obey to cooperate with those scripts.
16
17## The wiki and headers share the same text.
18
19There is a massive Perl script (`build-scripts/wikiheaders.pl`, hereafter
20referred to as "wikiheaders") that can read both the wiki and the public
21headers, and move changes in one across to the other.
22
23If you prefer to use the wiki, go ahead and edit there. If you prefer to use
24your own text editor, or command line tools to batch-process text, etc, you
25can [clone the wiki as a git repo](https://github.com/libsdl-org/sdlwiki) and
26work locally.
27
28
29## Don't taunt wikiheaders.
30
31The script isn't magic; it's a massive pile of Regular Expressions and not
32a full C or markdown parser. While it isn't _fragile_, if you try to do clever
33things, you might confuse it. This is to the benefit of documentation, though,
34where we would rather you not do surprising things.
35
36
37## We _sort of_ write in Doxygen format.
38
39To document a symbol, we use something that looks like Doxygen (and Javadoc)
40standard comment format:
41
42```c
43/**
44 * This is a function that does something.
45 *
46 * It can be used for frozzling bobbles. Be aware that the Frozulator module
47 * _must_ be initialized before calling this.
48 *
49 * \param frozzlevel The amount of frozzling to perform.
50 * \param color What color bobble to frozzle. 0 is red, 1 is green.
51 * \returns the number of bobbles that were actually frozzled, -1 on error.
52 *
53 * \threadsafety Do not call this from two threads at once, or the bobbles
54 * won't all frozzle correctly!
55 *
56 * \since This function is available since SDL 7.3.1.
57 *
58 * \sa SDL_DoSomethingElse
59 */
60extern SDL_DECLSPEC int SDLCALL SDL_DoSomething(int frozzlevel, int color);
61```
62
63Note the `/**` at the start of the comment. That's a "Doxygen-style" comment,
64and wikiheaders will treat this differently than a comment with one `*`, as
65this signifies that this is not just a comment, but _documentation_.
66
67These comments _must_ start in the first column of the line, or wikiheaders
68will ignore them, even with the "/**" start (we should improve the script
69someday to handle this, but currently this is a requirement).
70
71We do _not_ parse every magic Doxygen tag, and we don't parse them in `@param`
72format. The goal here was to mostly coexist with people that might want
73to run Doxygen on the SDL headers, not to build Doxygen from scratch. That
74being said, compatibility with Doxygen is not a hard requirement here.
75
76wikiheaders uses these specific tags to turn this comment into a (hopefully)
77well-formatted wiki page, and also can generate manpages and books in LaTeX
78format from it!
79
80Text markup in the headers is _always_ done in Markdown format! But less is
81more: try not to markup text more than necessary.
82
83
84## Doxygen tags we support:
85
86- `\brief one-line description` (Not required, and wikiheaders will remove tag).
87- `\param varname description` (One for each function/macro parameter)
88- `\returns description` (One for each function, don't use on `void` returns).
89- `\sa` (each of these get tucked into a "See Also" section on the wiki)
90- `\since This function is available since SDL 3.0.0.` (one per Doxygen comment)
91- `\threadsafety description` (one per function/macro).
92- `\deprecated description` (one per symbol, if symbol is deprecated!)
93
94Other Doxygen things might exist in the headers, but they aren't understood
95by wikiheaders.
96
97
98## Use Markdown.
99
100The wiki also supports MediaWiki format, but we are transitioning away from it.
101The headers always use Markdown. If you're editing the wiki from a git clone,
102just make .md files and the wiki will know what to do with them.
103
104
105## Most things in the headers can be documented.
106
107wikiheaders understands functions, typedefs, structs/unions/enums, `#defines`
108... basically most of what makes up a C header. Just slap a Doxygen-style
109comment in front of most things and it'll work.
110
111
112## Defines right below typedefs and functions bind.
113
114Any `#define` directly below a function or non-struct/union/enum typedef is
115considered part of that declaration. This happens to work well with how our
116headers work, as these defines tend to be bitflags and such that are related
117to that symbol.
118
119wikiheaders will include those defines in the syntax section of the wiki
120page, and generate stub pages for each define that simply says "please refer
121to (The Actual Symbol You Care About)" with a link. It will also pull in
122any blank lines and most preprocessor directives for the syntax text, too.
123
124Sometimes an unrelated define, by itself, just happens to be right below one
125of these symbols in the header. The easiest way to deal with this is either
126to document that define with a Doxygen-style comment, if it makes sense to do
127so, or just add a normal C comment right above it if not, so wikiheaders
128doesn't bind it to the previous symbol.
129
130
131## Don't document the `SDL_test*.h` headers.
132
133These are in the public headers but they aren't really considered public APIs.
134They live in a separate library that doesn't, or at least probably shouldn't,
135ship to end users. As such, we don't want it documented on the wiki.
136
137For now, we do this by not having any Doxygen-style comments in these files.
138Please keep it that way! If you want to document these headers, just don't
139use the magic two-`*` comment.
140
141
142## The first line is the summary.
143
144The first line of a piece of documentation is meant to be a succinct
145description. This is what Doxygen would call the `\brief` tag. wikiheaders
146will split this text out until the first period (end of sentence!), and when
147word wrapping, shuffle the overflow into a new paragraph below it.
148
149
150## Split paragraphs with a blank line.
151
152And don't indent them at all (indenting in Markdown is treated as preformatted
153text).
154
155wikiheaders will wordwrap header comments so they fit in 80 columns, so if you
156don't leave a blank line between paragraphs, they will smush into a single
157block of text when wordwrapping.
158
159
160## Don't worry about word wrapping.
161
162If you don't word-wrap your header edits perfectly (and you won't, I promise),
163wikiheaders will send your change to the wiki, and then to make things match,
164send it right back to the headers with correct word wrapping. Since this
165happens right after you push your changes, you might as well just write
166however you like and assume the system will clean it up for you.
167
168
169## Things that start with `SDL_` will automatically become wiki links.
170
171wikiheaders knows to turn these into links to other pages, so if you reference
172an SDL symbol in the header documentation, you don't need to link to it.
173You can optionally wrap the symbol in backticks, and wikiheaders will know to
174link the backticked thing. It will not generate links in three-backtick
175code/preformatted blocks.
176
177
178## URLs will automatically become links.
179
180You can use Markdown's `[link markup format](https://example.com/)`, but
181sometimes it's clearer to list bare URLs; the URL will be visible on the
182wiki page, but also clickable to follow the link. This is up to your judgment
183on a case-by-case basis.
184
185
186## Hide stuff from wikiheaders.
187
188If all else fails, you can block off pieces of the header with this
189magic line (whitespace is ignored):
190
191```c
192#ifndef SDL_WIKI_DOCUMENTATION_SECTION
193```
194
195Everything between this line and the next `#endif` will just be skipped by
196wikiheaders. Note that wikiheaders is not a C preprocessor! Don't try to
197nest conditionals or use `!defined`.
198
199Just block off sections if you need to. And: you almost never need to.
200
201
202## Hide stuff from the compiler.
203
204If you need to put something that's only of interest to wikiheaders, the
205convention is to put it in a block like this:
206
207```c
208#ifdef SDL_WIKI_DOCUMENTATION_SECTION
209```
210
211Generally this is used when there's a collection of preprocessor conditionals
212to define the same symbol differently in different circumstances. You put
213that symbol in this block with some reasonable generic version _and the
214Doxygen-style comment_. Because wikiheaders doesn't care about this
215preprocessor magic, and the C compiler can be as fancy as it wants, this is
216strictly a useful convention.
217
218
219## Struct/union/enum typedefs must have the name on the first line.
220
221This is because wikiheaders is not a full C parser. Don't write this:
222
223```c
224typedef struct
225{
226 int a;
227 int b;
228} SDL_MyStruct;
229```
230
231...make sure the name is at the start, too:
232
233```c
234typedef struct SDL_MyStruct
235{
236 int a;
237 int b;
238} SDL_MyStruct;
239```
240
241wikiheaders will complain loudly if you don't do this, and exit with an
242error message.
243
244
245## Don't repeat type names in `\param` and `\returns` sections.
246
247Wikiheaders will explicitly mention the datatype for each parameter and the
248return value, linking to the datatype's wikipage. Users reading the headers
249can see the types in the function signature right below the documentation
250comment. So don't mention the type a second time in the documentation if
251possible. It looks cluttered and repetitive to do so.
252
253
254## Code examples go in the wiki.
255
256We don't want the headers cluttered up with code examples. These live on the
257wiki pages, and wikiheaders knows to not bridge them back to the headers.
258
259Put them in a `## Code Examples` section, and make sure to wrap them in a
260three-backtick-c section for formatting purposes. Only write code in C,
261please.
262
263
264## Do you _need_ a code example?
265
266Most code examples aren't actually useful. If your code example is just
267`SDL_CreateWindow("Hello SDL", 640, 480, 0);` then just delete it; if all
268you're showing is how to call a function in C, it's not a useful code example.
269Not all functions need an example. One with complex setup or usage details
270might, though!
271
272
273## Code examples are compiled by GitHub Actions.
274
275On each change to the wiki, there is a script that pulls out all the code
276examples into discrete C files and attempts to compile them, and complains
277if they don't work.
278
279
280## Unrecognized sections are left alone in the wiki.
281
282A wiki section that starts with `## Section Name` (or `== Section Name ==` in
283MediaWiki format) that isn't one of the recognized names will be left alone
284by wikiheaders. Recognized sections might get overwritten with new content
285from the headers, but the wiki file will not have other sections cleaned out
286(this is how Code Examples remain wiki only, for example). You can use this
287to add Wiki-specific text, or stuff that doesn't make sense in a header, or
288would merely clutter it up.
289
290A possibly-incomplete list of sections that will be overwritten by changes
291to the headers:
292
293- The page title line, and the "brief" one-sentence description section.
294- "Deprecated"
295- "Header File"
296- "Syntax"
297- "Function Parameters"
298- "Macro Parameters"
299- "Fields"
300- "Values"
301- "Return Value"
302- "Remarks"
303- "Thread Safety"
304- "Version"
305- "See Also"
306
307
308## It's okay to repeat yourself.
309
310Each individual piece of documentation becomes a separate page on the wiki, so
311small repeated details can just exist in different pieces of documentation. If
312it's complicated, it's not unreasonable to say "Please refer to
313SDL_SomeOtherFunction for more details" ... wiki users can click right
314through, header users can search for the function name.
315
316
317## The docs directory is bridged to the wiki, too.
318
319You might be reading this document on the wiki! Any `README-*.md` files in
320the docs directory are bridged to the wiki, so `docs/README-linux.md` lands
321at https://wiki.libsdl.org/SDL3/README/linux ...these are just copied directly
322without any further processing by wikiheaders, and changes go in both
323directions.
324
325
326## The wiki can have its own pages, too.
327
328If a page name isn't a symbol that wikiheaders sees in the headers, or a
329README in the source's `docs` directory, or a few other exceptions, it'll
330assume it's an unrelated wiki page and leave it alone. So feel free to
331write any wiki-only pages that make sense and not worry about it junking
332up the headers!
333
334
335## Wiki categories are (mostly) managed automatically.
336
337The wiki will see this pattern as the last thing on a page and treat it as a
338list of categories that page belongs to:
339
340```
341----
342[CategoryStuff](CategoryStuff), [CategoryWhatever](CategoryWhatever)
343```
344
345You can use this to simply tag a page as part of a category, and the user can
346click directly to see other pages in that category. The wiki will
347automatically manage a `Category*` pages that list any tagged pages.
348
349You _should not_ add tags to the public headers. They don't mean anything
350there. wikiheaders will add a few tags that make sense when generating wiki
351content from the header files, and it will preserve other tags already present
352on the page, so if you want to add extra categories to something, tag it on
353the wiki itself.
354
355The wiki uses some magic HTML comment tags to decide how to list items on
356Category pages and let other content live on the page as well. You can
357see an example of this in action at:
358
359https://raw.githubusercontent.com/libsdl-org/sdlwiki/main/SDL3/CategoryEvents.md
360
361
362## Categorizing the headers.
363
364To put a symbol in a specific category, we use three approaches in SDL:
365
366- Things in the `SDL_test*.h` headers aren't categorized at all (and you
367 shouldn't document them!)
368- Most files are categorized by header name: we strip off the leading `SDL_`
369 and capitalize the first letter of what's left. So everything in SDL_audio.h
370 is in the "Audio" category, everything in SDL_video.h is in the "Video"
371 category, etc.
372- If wikiheaders sees a comment like this on a line by itself...
373 ```c
374 /* WIKI CATEGORY: Blah */
375 ```
376 ...then all symbols below that will land in the "Blah" category. We use this
377 at the top of a few headers where the simple
378 chop-off-SDL_-and-captialize-the-first-letter trick doesn't work well, but
379 one could theoretically use this for headers that have some overlap in
380 category.
381
382
383## Category documentation lives in headers.
384
385To document a category (text that lives before the item lists on a wiki
386category page), you have to follow a simple rule:
387
388The _first_ Doxygen-style comment in a header must start with:
389
390```
391/**
392 * # CategoryABC
393```
394
395If these conditions aren't met, wikiheaders will assume that documentation
396belongs to whatever is below it instead of the Category.
397
398The text of this comment will be added to the appropriate wiki Category page,
399at the top, replacing everything in the file until it sees a line that starts
400with an HTML comment (`<!--`), or a line that starts with `----`. Everything
401after that in the wiki file will be preserved.
402
403Likewise, when bridging _back_ to the headers, if wikiheaders sees one of
404these comments, it'll copy the top section of the Category page back into the
405comment.
406
407Beyond stripping the initial ` * ` portion off each line, these comments are
408treated as pure Markdown. They don't support any Doxygen tags like `\sa` or
409`\since`.
410