summaryrefslogtreecommitdiff
path: root/common/c-to-xml.py
diff options
context:
space:
mode:
Diffstat (limited to 'common/c-to-xml.py')
-rw-r--r--common/c-to-xml.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/common/c-to-xml.py b/common/c-to-xml.py
new file mode 100644
index 0000000..7a7a35b
--- /dev/null
+++ b/common/c-to-xml.py
@@ -0,0 +1,36 @@
+# -*- Mode: Python -*-
+# vi:si:et:sw=4:sts=4:ts=4
+
+"""
+Convert a C program to valid XML to be included in docbook
+"""
+
+from __future__ import print_function, unicode_literals
+
+import sys
+import os
+from xml.sax import saxutils
+
+def main():
+ if len(sys.argv) == 1:
+ sys.stderr.write("Please specify a source file to convert")
+ sys.exit(1)
+ source = sys.argv[1]
+
+ if not os.path.exists(source):
+ sys.stderr.write("%s does not exist.\n" % source)
+ sys.exit(1)
+
+ content = open(source, "r").read()
+
+ # print header
+ print ('<?xml version="1.0"?>')
+ print ('<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">')
+ print ()
+ print ('<programlisting>')
+
+ # print content
+ print (saxutils.escape(content))
+ print ('</programlisting>')
+
+main()