Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1#!/usr/bin/env python3
2# SPDX-License-Identifier: GPL-2.0
3# Copyright (c) 2016, 2025 by Mauro Carvalho Chehab <mchehab@kernel.org>.
4# pylint: disable=C0103
5
6"""
7Convert a C header or source file ``FILE_IN``, into a ReStructured Text
8included via ..parsed-literal block with cross-references for the
9documentation files that describe the API. It accepts an optional
10``FILE_RULES`` file to describes what elements will be either ignored or
11be pointed to a non-default reference type/name.
12
13The output is written at ``FILE_OUT``.
14
15It is capable of identifying defines, functions, structs, typedefs,
16enums and enum symbols and create cross-references for all of them.
17It is also capable of distinguish #define used for specifying a Linux
18ioctl.
19
20The optional ``FILE_RULES`` contains a set of rules like:
21
22 ignore ioctl VIDIOC_ENUM_FMT
23 replace ioctl VIDIOC_DQBUF vidioc_qbuf
24 replace define V4L2_EVENT_MD_FL_HAVE_FRAME_SEQ :c:type:`v4l2_event_motion_det`
25"""
26
27import argparse
28
29from lib.parse_data_structs import ParseDataStructs
30from lib.enrich_formatter import EnrichFormatter
31
32def main():
33 """Main function"""
34 parser = argparse.ArgumentParser(description=__doc__,
35 formatter_class=EnrichFormatter)
36
37 parser.add_argument("-d", "--debug", action="count", default=0,
38 help="Increase debug level. Can be used multiple times")
39 parser.add_argument("-t", "--toc", action="store_true",
40 help="instead of a literal block, outputs a TOC table at the RST file")
41
42 parser.add_argument("file_in", help="Input C file")
43 parser.add_argument("file_out", help="Output RST file")
44 parser.add_argument("file_rules", nargs="?",
45 help="Exceptions file (optional)")
46
47 args = parser.parse_args()
48
49 parser = ParseDataStructs(debug=args.debug)
50 parser.parse_file(args.file_in)
51
52 if args.file_rules:
53 parser.process_exceptions(args.file_rules)
54
55 parser.debug_print()
56 parser.write_output(args.file_in, args.file_out, args.toc)
57
58
59if __name__ == "__main__":
60 main()