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