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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
# python script to generate configoptions.cpp from config.xml
#
# Copyright (C) 1997-2013 by Dimitri van Heesch.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation under the terms of the GNU General Public License is hereby
# granted. No representations are made about the suitability of this software
# for any purpose. It is provided "as is" without express or implied warranty.
# See the GNU General Public License for more details.
#
# Documents produced by Doxygen are derivative works derived from the
# input used in their production; they are not affected by this license.
#
import xml.dom.minidom
import sys
from xml.dom import minidom, Node
def addValues(var,node):
for n in node.childNodes:
if n.nodeType == Node.ELEMENT_NODE:
name = n.getAttribute('name');
print " %s->addValue(\"%s\");" % (var,name)
def parseOption(node):
name = node.getAttribute('id')
type = node.getAttribute('type')
format = node.getAttribute('format')
doc = node.getAttribute('docs')
defval = node.getAttribute('defval')
adefval = node.getAttribute('altdefval')
depends = node.getAttribute('depends')
setting = node.getAttribute('setting')
# replace \ by \\, replace " by \", and ' ' by a newline with end string and start string at next line
docC = doc.strip().replace('\\','\\\\').replace('"','\\"').replace(' ','\\n"\n\t\t\t"')
if len(setting)>0:
print "#if %s" % (setting)
print " //----"
if type=='bool':
if len(adefval)>0:
enabled = adefval
elif defval=='1':
enabled = "TRUE"
else:
enabled = "FALSE"
print " cb = cfg->addBool("
print " \"%s\"," % (name)
print " \"%s\"," % (docC)
print " %s" % (enabled)
print " );"
if depends!='':
print " cb->addDependency(\"%s\");" % (depends)
elif type=='string':
print " cs = cfg->addString("
print " \"%s\"," % (name)
print " \"%s\"" % (docC)
print " );"
if defval!='':
print " cs->setDefaultValue(\"%s\");" % (defval)
if format=='file':
print " cs->setWidgetType(ConfigString::File);"
elif format=='dir':
print " cs->setWidgetType(ConfigString::Dir);"
if depends!='':
print " cs->addDependency(\"%s\");" % (depends)
elif type=='enum':
print " ce = cfg->addEnum("
print " \"%s\"," % (name)
print " \"%s\"," % (docC)
print " \"%s\"" % (defval)
print " );"
addValues("ce",node)
if depends!='':
print " ce->addDependency(\"%s\");" % (depends)
elif type=='int':
minval = node.getAttribute('minval')
maxval = node.getAttribute('maxval')
print " ci = cfg->addInt("
print " \"%s\"," % (name)
print " \"%s\"," % (docC)
print " %s,%s,%s" % (minval,maxval,defval)
print " );"
if depends!='':
print " ci->addDependency(\"%s\");" % (depends)
elif type=='list':
print " cl = cfg->addList("
print " \"%s\"," % (name)
print " \"%s\"" % (docC)
print " );"
addValues("cl",node)
if depends!='':
print " cl->addDependency(\"%s\");" % (depends)
if format=='file':
print " cl->setWidgetType(ConfigList::File);"
elif format=='dir':
print " cl->setWidgetType(ConfigList::Dir);"
elif format=='filedir':
print " cl->setWidgetType(ConfigList::FileAndDir);"
elif type=='obsolete':
print " cfg->addObsolete(\"%s\");" % (name)
if len(setting)>0:
print "#else"
print " cfg->addDisabled(\"%s\");" % (name)
print "#endif"
def parseGroups(node):
name = node.getAttribute('name')
doc = node.getAttribute('docs')
print " //---------------------------------------------------------------------------";
print " cfg->addInfo(\"%s\",\"%s\");" % (name,doc)
print " //---------------------------------------------------------------------------";
print
for n in node.childNodes:
if n.nodeType == Node.ELEMENT_NODE:
parseOption(n)
def main():
doc = xml.dom.minidom.parse(sys.argv[1])
elem = doc.documentElement
print "/* WARNING: This file is generated!"
print " * Do not edit this file, but edit config.xml instead and run"
print " * python configgen.py to regenerate this file!"
print " */"
print ""
print "#include \"configoptions.h\""
print "#include \"config.h\""
print "#include \"portable.h\""
print "#include \"settings.h\""
print ""
print "void addConfigOptions(Config *cfg)"
print "{"
print " ConfigString *cs;"
print " ConfigEnum *ce;"
print " ConfigList *cl;"
print " ConfigInt *ci;"
print " ConfigBool *cb;"
print ""
for n in elem.childNodes:
if n.nodeType == Node.ELEMENT_NODE:
parseGroups(n)
print "}"
if __name__ == '__main__':
main()
|