Changes for 4.5.0 snapshot
[newlib-cygwin.git] / newlib / doc / chapter-texi2docbook.py
blobe9904ad00f2d2ea565404a262213c849939ff73d
1 #!/usr/bin/env python3
3 # python script to convert the handwritten chapter .texi files, which include
4 # the generated files for each function, to DocBook XML
6 # all we care about is the content of the refentries, so all this needs to do is
7 # convert the @include of the makedoc generated .def files to xi:include of the
8 # makedocbook generated .xml files.
11 from __future__ import print_function
12 import sys
13 import re
15 def main():
16 first_node = True
17 prev_sect = False
19 print('<?xml version="1.0" encoding="UTF-8"?>')
20 print('<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">')
22 for l in sys.stdin.readlines():
23 l = l.rstrip()
25 # transform @file{foo} to <filename>foo</filename>
26 l = re.sub("@file{(.*?)}", "<filename>\\1</filename>", l)
28 if l.startswith("@node"):
29 l = l.replace("@node", "", 1)
30 l = l.strip()
31 if first_node:
32 print('<chapter id="%s_chapter" xmlns:xi="http://www.w3.org/2001/XInclude">' % l.lower().replace(' ', '_'))
33 first_node = False
34 else:
35 if prev_sect:
36 print('</section>')
37 print('<section id="%s">' % l)
38 prev_sect = True
39 elif l.startswith("@chapter "):
40 l = l.replace("@chapter ", "", 1)
41 print('<title>%s</title>' % l)
42 elif l.startswith("@section "):
43 l = l.replace("@section ", "", 1)
44 print('<title>%s</title>' % l)
45 elif l.startswith("@include "):
46 l = l.replace("@include ", "", 1)
47 l = l.replace(".def", ".xml", 1)
48 print('<xi:include href="%s"/>' % l.strip())
50 if prev_sect:
51 print('</section>')
52 print('</chapter>')
54 if __name__ == "__main__":
55 main()