Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

docs: doc-guide: parse-headers.rst update its documentation

Besides converting from Perl to Python, parse-headers has gained
some new functionality and was moved to tools/docs.

Update its documentation accordingly.

Reported-by: Randy Dunlap <rdunlap@infradead.org>
Closes: https://lore.kernel.org/linux-doc/9391a0f0-7c92-42aa-8190-28255b22e131@infradead.org/
Acked-by: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Reviewed-by: Dongliang Mu <dzm91@hust.edu.cn>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Message-ID: <1f9025dc98dc58da3cc31f3343d5027f351be338.1762594622.git.mchehab+huawei@kernel.org>

authored by

Mauro Carvalho Chehab and committed by
Jonathan Corbet
d69a03a9 e1cf4aac

+109 -114
+101 -106
Documentation/doc-guide/parse-headers.rst
··· 8 8 userspace API files has an additional vantage: Sphinx will generate warnings 9 9 if a symbol is not found at the documentation. That helps to keep the 10 10 uAPI documentation in sync with the Kernel changes. 11 - The :ref:`parse_headers.pl <parse_headers>` provide a way to generate such 11 + The :ref:`parse_headers.py <parse_headers>` provides a way to generate such 12 12 cross-references. It has to be called via Makefile, while building the 13 13 documentation. Please see ``Documentation/userspace-api/media/Makefile`` for an example 14 14 about how to use it inside the Kernel tree. 15 15 16 16 .. _parse_headers: 17 17 18 - parse_headers.pl 19 - ^^^^^^^^^^^^^^^^ 18 + tools/docs/parse_headers.py 19 + ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20 20 21 21 NAME 22 22 **** 23 23 24 - 25 - parse_headers.pl - parse a C file, in order to identify functions, structs, 24 + parse_headers.py - parse a C file, in order to identify functions, structs, 26 25 enums and defines and create cross-references to a Sphinx book. 27 26 27 + USAGE 28 + ***** 29 + 30 + parse-headers.py [-h] [-d] [-t] ``FILE_IN`` ``FILE_OUT`` ``FILE_RULES`` 28 31 29 32 SYNOPSIS 30 33 ******** 31 34 35 + Converts a C header or source file ``FILE_IN`` into a ReStructured Text 36 + included via ..parsed-literal block with cross-references for the 37 + documentation files that describe the API. It accepts an optional 38 + ``FILE_RULES`` file to describe what elements will be either ignored or 39 + be pointed to a non-default reference type/name. 32 40 33 - \ **parse_headers.pl**\ [<options>] <C_FILE> <OUT_FILE> [<EXCEPTIONS_FILE>] 41 + The output is written at ``FILE_OUT``. 34 42 35 - Where <options> can be: --debug, --help or --usage. 43 + It is capable of identifying ``define``, ``struct``, ``typedef``, ``enum`` 44 + and enum ``symbol``, creating cross-references for all of them. 36 45 46 + It is also capable of distinguishing ``#define`` used for specifying 47 + Linux-specific macros used to define ``ioctl``. 48 + 49 + The optional ``FILE_RULES`` contains a set of rules like:: 50 + 51 + ignore ioctl VIDIOC_ENUM_FMT 52 + replace ioctl VIDIOC_DQBUF vidioc_qbuf 53 + replace define V4L2_EVENT_MD_FL_HAVE_FRAME_SEQ :c:type:`v4l2_event_motion_det` 54 + 55 + POSITIONAL ARGUMENTS 56 + ******************** 57 + 58 + ``FILE_IN`` 59 + Input C file 60 + 61 + ``FILE_OUT`` 62 + Output RST file 63 + 64 + ``FILE_RULES`` 65 + Exceptions file (optional) 37 66 38 67 OPTIONS 39 68 ******* 40 69 41 - 42 - 43 - \ **--debug**\ 44 - 45 - Put the script in verbose mode, useful for debugging. 46 - 47 - 48 - 49 - \ **--usage**\ 50 - 51 - Prints a brief help message and exits. 52 - 53 - 54 - 55 - \ **--help**\ 56 - 57 - Prints a more detailed help message and exits. 70 + ``-h``, ``--help`` 71 + show a help message and exit 72 + ``-d``, ``--debug`` 73 + Increase debug level. Can be used multiple times 74 + ``-t``, ``--toc`` 75 + instead of a literal block, outputs a TOC table at the RST file 58 76 59 77 60 78 DESCRIPTION 61 79 *********** 62 80 81 + Creates an enriched version of a Kernel header file with cross-links 82 + to each C data structure type, from ``FILE_IN``, formatting it with 83 + reStructuredText notation, either as-is or as a table of contents. 63 84 64 - Convert a C header or source file (C_FILE), into a reStructuredText 65 - included via ..parsed-literal block with cross-references for the 66 - documentation files that describe the API. It accepts an optional 67 - EXCEPTIONS_FILE with describes what elements will be either ignored or 68 - be pointed to a non-default reference. 85 + It accepts an optional ``FILE_RULES`` which describes what elements will be 86 + either ignored or be pointed to a non-default reference, and optionally 87 + defines the C namespace to be used. 69 88 70 - The output is written at the (OUT_FILE). 89 + It is meant to allow having more comprehensive documentation, where 90 + uAPI headers will create cross-reference links to the code. 71 91 72 - It is capable of identifying defines, functions, structs, typedefs, 73 - enums and enum symbols and create cross-references for all of them. 74 - It is also capable of distinguish #define used for specifying a Linux 75 - ioctl. 92 + The output is written at the (``FILE_OUT``). 76 93 77 - The EXCEPTIONS_FILE contain two types of statements: \ **ignore**\ or \ **replace**\ . 94 + The ``FILE_RULES`` may contain contain three types of statements: 95 + **ignore**, **replace** and **namespace**. 78 96 79 - The syntax for the ignore tag is: 97 + By default, it create rules for all symbols and defines, but it also 98 + allows parsing an exception file. Such file contains a set of rules 99 + using the syntax below: 80 100 101 + 1. Ignore rules: 81 102 82 - ignore \ **type**\ \ **name**\ 103 + ignore *type* *symbol* 83 104 84 - The \ **ignore**\ means that it won't generate cross references for a 85 - \ **name**\ symbol of type \ **type**\ . 105 + Removes the symbol from reference generation. 86 106 87 - The syntax for the replace tag is: 107 + 2. Replace rules: 88 108 109 + replace *type* *old_symbol* *new_reference* 89 110 90 - replace \ **type**\ \ **name**\ \ **new_value**\ 111 + Replaces *old_symbol* with a *new_reference*. 112 + The *new_reference* can be: 91 113 92 - The \ **replace**\ means that it will generate cross references for a 93 - \ **name**\ symbol of type \ **type**\ , but, instead of using the default 94 - replacement rule, it will use \ **new_value**\ . 114 + - A simple symbol name; 115 + - A full Sphinx reference. 95 116 96 - For both statements, \ **type**\ can be either one of the following: 117 + 3. Namespace rules 97 118 119 + namespace *namespace* 98 120 99 - \ **ioctl**\ 121 + Sets C *namespace* to be used during cross-reference generation. Can 122 + be overridden by replace rules. 100 123 101 - The ignore or replace statement will apply to ioctl definitions like: 124 + On ignore and replace rules, *type* can be: 102 125 103 - #define VIDIOC_DBG_S_REGISTER _IOW('V', 79, struct v4l2_dbg_register) 126 + - ioctl: 127 + for defines of the form ``_IO*``, e.g., ioctl definitions 104 128 129 + - define: 130 + for other defines 105 131 132 + - symbol: 133 + for symbols defined within enums; 106 134 107 - \ **define**\ 135 + - typedef: 136 + for typedefs; 108 137 109 - The ignore or replace statement will apply to any other #define found 110 - at C_FILE. 138 + - enum: 139 + for the name of a non-anonymous enum; 111 140 112 - 113 - 114 - \ **typedef**\ 115 - 116 - The ignore or replace statement will apply to typedef statements at C_FILE. 117 - 118 - 119 - 120 - \ **struct**\ 121 - 122 - The ignore or replace statement will apply to the name of struct statements 123 - at C_FILE. 124 - 125 - 126 - 127 - \ **enum**\ 128 - 129 - The ignore or replace statement will apply to the name of enum statements 130 - at C_FILE. 131 - 132 - 133 - 134 - \ **symbol**\ 135 - 136 - The ignore or replace statement will apply to the name of enum value 137 - at C_FILE. 138 - 139 - For replace statements, \ **new_value**\ will automatically use :c:type: 140 - references for \ **typedef**\ , \ **enum**\ and \ **struct**\ types. It will use :ref: 141 - for \ **ioctl**\ , \ **define**\ and \ **symbol**\ types. The type of reference can 142 - also be explicitly defined at the replace statement. 143 - 141 + - struct: 142 + for structs. 144 143 145 144 146 145 EXAMPLES 147 146 ******** 148 147 148 + - Ignore a define ``_VIDEODEV2_H`` at ``FILE_IN``:: 149 149 150 - ignore define _VIDEODEV2_H 150 + ignore define _VIDEODEV2_H 151 + 152 + - On an data structure like this enum:: 153 + 154 + enum foo { BAR1, BAR2, PRIVATE }; 155 + 156 + It won't generate cross-references for ``PRIVATE``:: 157 + 158 + ignore symbol PRIVATE 159 + 160 + At the same struct, instead of creating one cross reference per symbol, 161 + make them all point to the ``enum foo`` C type:: 162 + 163 + replace symbol BAR1 :c:type:\`foo\` 164 + replace symbol BAR2 :c:type:\`foo\` 151 165 152 166 153 - Ignore a #define _VIDEODEV2_H at the C_FILE. 167 + - Use C namespace ``MC`` for all symbols at ``FILE_IN``:: 154 168 155 - ignore symbol PRIVATE 156 - 157 - 158 - On a struct like: 159 - 160 - enum foo { BAR1, BAR2, PRIVATE }; 161 - 162 - It won't generate cross-references for \ **PRIVATE**\ . 163 - 164 - replace symbol BAR1 :c:type:\`foo\` 165 - replace symbol BAR2 :c:type:\`foo\` 166 - 167 - 168 - On a struct like: 169 - 170 - enum foo { BAR1, BAR2, PRIVATE }; 171 - 172 - It will make the BAR1 and BAR2 enum symbols to cross reference the foo 173 - symbol at the C domain. 174 - 169 + namespace MC 175 170 176 171 BUGS 177 172 **** ··· 179 184 ********* 180 185 181 186 182 - Copyright (c) 2016 by Mauro Carvalho Chehab <mchehab+samsung@kernel.org>. 187 + Copyright (c) 2016, 2025 by Mauro Carvalho Chehab <mchehab+huawei@kernel.org>. 183 188 184 189 License GPLv2: GNU GPL version 2 <https://gnu.org/licenses/gpl.html>. 185 190
+4 -4
Documentation/translations/it_IT/doc-guide/parse-headers.rst
··· 13 13 d'avviso se un simbolo non viene trovato nella documentazione. Questo permette 14 14 di mantenere allineate la documentazione della uAPI (API spazio utente) 15 15 con le modifiche del kernel. 16 - Il programma :ref:`parse_headers.pl <it_parse_headers>` genera questi riferimenti. 16 + Il programma :ref:`parse_headers.py <it_parse_headers>` genera questi riferimenti. 17 17 Esso dev'essere invocato attraverso un Makefile, mentre si genera la 18 18 documentazione. Per avere un esempio su come utilizzarlo all'interno del kernel 19 19 consultate ``Documentation/userspace-api/media/Makefile``. 20 20 21 21 .. _it_parse_headers: 22 22 23 - parse_headers.pl 23 + parse_headers.py 24 24 ^^^^^^^^^^^^^^^^ 25 25 26 26 NOME 27 27 **** 28 28 29 29 30 - parse_headers.pl - analizza i file C al fine di identificare funzioni, 30 + parse_headers.py - analizza i file C al fine di identificare funzioni, 31 31 strutture, enumerati e definizioni, e creare riferimenti per Sphinx 32 32 33 33 SINTASSI 34 34 ******** 35 35 36 36 37 - \ **parse_headers.pl**\ [<options>] <C_FILE> <OUT_FILE> [<EXCEPTIONS_FILE>] 37 + \ **parse_headers.py**\ [<options>] <C_FILE> <OUT_FILE> [<EXCEPTIONS_FILE>] 38 38 39 39 Dove <options> può essere: --debug, --usage o --help. 40 40
+4 -4
Documentation/translations/zh_CN/doc-guide/parse-headers.rst
··· 13 13 有时,为了描述用户空间API并在代码和文档之间生成交叉引用,需要包含头文件和示例 14 14 C代码。为用户空间API文件添加交叉引用还有一个好处:如果在文档中找不到相应符号, 15 15 Sphinx将生成警告。这有助于保持用户空间API文档与内核更改同步。 16 - :ref:`parse_headers.pl <parse_headers_zh>` 提供了生成此类交叉引用的一种方法。 16 + :ref:`parse_headers.py <parse_headers_zh>` 提供了生成此类交叉引用的一种方法。 17 17 在构建文档时,必须通过Makefile调用它。有关如何在内核树中使用它的示例,请参阅 18 18 ``Documentation/userspace-api/media/Makefile`` 。 19 19 20 20 .. _parse_headers_zh: 21 21 22 - parse_headers.pl 22 + parse_headers.py 23 23 ---------------- 24 24 25 25 脚本名称 26 26 ~~~~~~~~ 27 27 28 28 29 - parse_headers.pl——解析一个C文件,识别函数、结构体、枚举、定义并对Sphinx文档 29 + parse_headers.py——解析一个C文件,识别函数、结构体、枚举、定义并对Sphinx文档 30 30 创建交叉引用。 31 31 32 32 ··· 34 34 ~~~~~~~~ 35 35 36 36 37 - \ **parse_headers.pl**\ [<选项>] <C文件> <输出文件> [<例外文件>] 37 + \ **parse_headers.py**\ [<选项>] <C文件> <输出文件> [<例外文件>] 38 38 39 39 <选项> 可以是: --debug, --help 或 --usage 。 40 40