File: glade2c

package info (click to toggle)
pixelize 2.0.0~git20220108.d1f9da9-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, trixie
  • size: 456 kB
  • sloc: ansic: 2,248; makefile: 50; python: 45
file content (57 lines) | stat: -rwxr-xr-x 1,603 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/python3

import xml.dom.minidom
import sys, getopt


class XmlWriter:
    def __init__(self):
        self.snippets = []

    def write(self, data):
        if data.isspace(): return
        self.snippets.append(data)

    def __str__(self):
        return ''.join(self.snippets)


if __name__ == "__main__":
    execname = sys.argv[0]
    inputfile = ''
    outputfile = ''
    stringname = 'gladestring'
    try:
        opts, args = getopt.getopt(sys.argv[1:], "hi:o:s:", ["ifile=", "ofile=", "stringname="])
    except getopt.GetoptError:
        print (execname + ' -i <inputfile> -o <outputfile> [-s <stringname>]')
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print (execname + ' -i <inputfile> -o <outputfile> [-s <stringname>]')
            sys.exit()
        elif opt in ("-i", "--ifile"):
            inputfile = arg
        elif opt in ("-o", "--ofile"):
            outputfile = arg
        elif opt in ("-s", "--stringname"):
            stringname = arg

    if inputfile == '' or outputfile == '':
        print (execname + ' -i <inputfile> -o <outputfile> [-s <stringname>]')
        sys.exit(2)

    writer = XmlWriter()
    xml = xml.dom.minidom.parse(inputfile)
    xml.writexml(writer)
    strippedXml = ("%s" % (writer)).replace('"', '\\"')
    strippedXml = ("%s" % (strippedXml)).replace('\n', '\\n')

    byteCount = len(strippedXml)
    baseOffset = 0
    stripSize = 64

    output = open(outputfile, 'w')
    output.write("static const char *" + stringname + " = ")
    output.write('"%s";\n' % strippedXml)
    output.close()