4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-01-23 07:27:21 +08:00
newlib-cygwin/newlib/doc/chapter-texi2docbook.py
Jon Turney 85148c43c4
Fix warning during manpage generaton
> ERROR: xref linking to Stubs has no generated link text.
> Error: no ID for constraint linkend: Stubs.

(Despite saying "ERROR", this is actually a warning, and manpages are
still generated)

Improve chapter-texi2docbook so it generates elements for texinfo
sections as well, so that a cross-reference to the "Stubs" section
contains a valid element ID.
2022-10-28 11:33:43 +01:00

56 lines
1.8 KiB
Python
Executable File

#!/usr/bin/env python3
#
# python script to convert the handwritten chapter .texi files, which include
# the generated files for each function, to DocBook XML
#
# all we care about is the content of the refentries, so all this needs to do is
# convert the @include of the makedoc generated .def files to xi:include of the
# makedocbook generated .xml files.
#
from __future__ import print_function
import sys
import re
def main():
first_node = True
prev_sect = False
print ('<?xml version="1.0" encoding="UTF-8"?>')
print ('<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">')
for l in sys.stdin.readlines():
l = l.rstrip()
# transform @file{foo} to <filename>foo</filename>
l = re.sub("@file{(.*?)}", "<filename>\\1</filename>", l)
if l.startswith("@node"):
l = l.replace("@node", "", 1)
l = l.strip()
if first_node:
print ('<chapter id="%s_chapter" xmlns:xi="http://www.w3.org/2001/XInclude">' % l.lower().replace(' ', '_'))
first_node = False
else:
if prev_sect:
print ('</section>')
print ('<section id="%s">' % l)
prev_sect = True
elif l.startswith("@chapter "):
l = l.replace("@chapter ", "", 1)
print ('<title>%s</title>' % l)
elif l.startswith("@section "):
l = l.replace("@section ", "", 1)
print ('<title>%s</title>' % l)
elif l.startswith("@include "):
l = l.replace("@include ", "", 1)
l = l.replace(".def", ".xml", 1)
print ('<xi:include href="%s"/>' % l.strip())
if prev_sect:
print ('</section>')
print ('</chapter>')
if __name__ == "__main__" :
main()