File: c-to-xml.py

package info (click to toggle)
gst-plugins-bad1.0 1.0.8-1~bpo70%2B1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports
  • size: 36,832 kB
  • sloc: ansic: 297,908; cpp: 22,677; sh: 13,303; xml: 6,362; makefile: 4,867; perl: 1,435; objc: 1,273; python: 362; sed: 16
file content (34 lines) | stat: -rw-r--r-- 816 bytes parent folder | download | duplicates (36)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# -*- Mode: Python -*-
# vi:si:et:sw=4:sts=4:ts=4

"""
Convert a C program to valid XML to be included in docbook
"""

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).encode('UTF-8')
    print '</programlisting>'

main()