| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 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
|
| 28 |
|
| 29 | from lib.parse_data_structs import ParseDataStructs
|
| 30 | from lib.enrich_formatter import EnrichFormatter
|
| 31 |
|
| 32 | def main():
|
| 33 |
|
| 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 |
|
| 59 | if __name__ == "__main__":
|
| 60 | main()
|