~ubuntu-branches/ubuntu/precise/transmageddon/precise

« back to all changes in this revision

Viewing changes to common/c-to-xml.py

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2009-10-14 08:28:43 UTC
  • Revision ID: james.westby@ubuntu.com-20091014082843-uxbyrcqydc13zrim
Tags: upstream-0.14
ImportĀ upstreamĀ versionĀ 0.14

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- Mode: Python -*-
 
2
# vi:si:et:sw=4:sts=4:ts=4
 
3
 
 
4
"""
 
5
Convert a C program to valid XML to be included in docbook
 
6
"""
 
7
 
 
8
import sys
 
9
import os
 
10
from xml.sax import saxutils
 
11
 
 
12
def main():
 
13
    if len(sys.argv) == 1:
 
14
        sys.stderr.write("Please specify a source file to convert")
 
15
        sys.exit(1)
 
16
    source = sys.argv[1]
 
17
 
 
18
    if not os.path.exists(source):
 
19
        sys.stderr.write("%s does not exist.\n" % source)
 
20
        sys.exit(1)
 
21
 
 
22
    content = open(source, "r").read()
 
23
 
 
24
    # print header
 
25
    print '<?xml version="1.0"?>'
 
26
    print '<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">'
 
27
    print
 
28
    print '<programlisting>'
 
29
 
 
30
    # print content
 
31
    print saxutils.escape(content).encode('UTF-8')
 
32
    print '</programlisting>'
 
33
        
 
34
main()