File: makeXmlHeader.py

package info (click to toggle)
libsmbios 2.0.3.dfsg-1.1
  • links: PTS
  • area: main
  • in suites: squeeze, wheezy
  • size: 3,768 kB
  • ctags: 2,016
  • sloc: cpp: 14,292; sh: 9,408; xml: 3,820; makefile: 454; ansic: 402; python: 157
file content (68 lines) | stat: -rwxr-xr-x 1,488 bytes parent folder | download | duplicates (5)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/python
# vim: et:ai:sw=4:ts=4:filetype=python:nocindent:

import sys


def writeStdHeaders( out ):
    out.write ("""
#ifndef __STD_SMBIOS_XML_H
#define __STD_SMBIOS_XML_H

//
// This is an *AUTOMATICALLY* *GENERATED* file. Do not edit this file
// as your changes will be lost the next time the file is generated
//

""")

def writeStdFooters( out ):
    out.write ("""

#endif /* __STD_SMBIOS_XML_H */

""")

def processFile( input, output ):
    charsPerLine = 16
    output.write( """
const char stdXml[] = { """)
    
    charsWrittenThisLine = charsPerLine
    while 1:
        c = input.read(1)
        if c == "":   # end of file
            break 
        if charsWrittenThisLine == charsPerLine/2:
            output.write("  ")
        if charsWrittenThisLine >= charsPerLine:
            output.write( "\n" )
            output.write( "\t" )
            charsWrittenThisLine = 1
        output.write( "0x%02x, " % ord(c) )
        charsWrittenThisLine = charsWrittenThisLine + 1
        
    output.write( """0x00
};
""")

def main():
    inputXml = None
    outputHeader = None
    inputXml = sys.argv[1]
    if len(sys.argv) > 2:
        outputHeader = sys.argv[2]

    inputFh = open( inputXml, "r" )
    if outputHeader is not None:
        outputFh = open( outputHeader, "w+" )
    else:
        outputFh = sys.stdout

    writeStdHeaders( outputFh )
    processFile( inputFh, outputFh )
    writeStdFooters( outputFh )


if __name__ == "__main__":
    main()