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