[444] | 1 | #!/usr/bin/env python |
---|
| 2 | # |
---|
| 3 | # python script to convert the handwritten chapter .texi files, which include |
---|
| 4 | # the generated files for each function, to DocBook XML |
---|
| 5 | # |
---|
| 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. |
---|
| 9 | # |
---|
| 10 | |
---|
| 11 | from __future__ import print_function |
---|
| 12 | import sys |
---|
| 13 | import re |
---|
| 14 | |
---|
| 15 | def main(): |
---|
| 16 | first_node = True |
---|
| 17 | |
---|
| 18 | print ('<?xml version="1.0" encoding="UTF-8"?>') |
---|
| 19 | print ('<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">') |
---|
| 20 | |
---|
| 21 | for l in sys.stdin.readlines(): |
---|
| 22 | l = l.rstrip() |
---|
| 23 | |
---|
| 24 | # transform @file{foo} to <filename>foo</filename> |
---|
| 25 | l = re.sub("@file{(.*?)}", "<filename>\\1</filename>", l) |
---|
| 26 | |
---|
| 27 | if l.startswith("@node"): |
---|
| 28 | l = l.replace("@node", "", 1) |
---|
| 29 | l = l.strip() |
---|
| 30 | l = l.lower() |
---|
| 31 | if first_node: |
---|
| 32 | print ('<chapter id="%s" xmlns:xi="http://www.w3.org/2001/XInclude">' % l.replace(' ', '_')) |
---|
| 33 | first_node = False |
---|
| 34 | elif l.startswith("@chapter "): |
---|
| 35 | l = l.replace("@chapter ", "", 1) |
---|
| 36 | print ('<title>%s</title>' % l) |
---|
| 37 | elif l.startswith("@include "): |
---|
| 38 | l = l.replace("@include ", "", 1) |
---|
| 39 | l = l.replace(".def", ".xml", 1) |
---|
| 40 | print ('<xi:include href="%s"/>' % l.strip()) |
---|
| 41 | |
---|
| 42 | print ('</chapter>') |
---|
| 43 | |
---|
| 44 | if __name__ == "__main__" : |
---|
| 45 | main() |
---|