1 # python script to generate configoptions.cpp from config.xml
3 # Copyright (C) 1997-2012 by Dimitri van Heesch.
5 # Permission to use, copy, modify, and distribute this software and its
6 # documentation under the terms of the GNU General Public License is hereby
7 # granted. No representations are made about the suitability of this software
8 # for any purpose. It is provided "as is" without express or implied warranty.
9 # See the GNU General Public License for more details.
11 # Documents produced by Doxygen are derivative works derived from the
12 # input used in their production; they are not affected by this license.
14 import xml.dom.minidom
15 from xml.dom import minidom, Node
17 def addValues(var,node):
18 for n in node.childNodes:
19 if n.nodeType == Node.ELEMENT_NODE:
20 name = n.getAttribute('name');
21 print " %s->addValue(\"%s\");" % (var,name)
23 def parseOption(node):
24 name = node.getAttribute('id')
25 type = node.getAttribute('type')
26 format = node.getAttribute('format')
27 doc = node.getAttribute('docs')
28 defval = node.getAttribute('defval')
29 adefval = node.getAttribute('altdefval')
30 depends = node.getAttribute('depends')
31 # replace \ by \\, replace " by \", and ' ' by a newline with end string and start string at next line
32 docC = doc.strip().replace('\\','\\\\').replace('"','\\"').replace(' ','\\n"\n "')
41 print " cb = cfg->addBool("
42 print " \"%s\"," % (name)
43 print " \"%s\"," % (docC)
44 print " %s" % (enabled)
47 print " cb->addDependency(\"%s\");" % (depends)
49 print " cs = cfg->addString("
50 print " \"%s\"," % (name)
51 print " \"%s\"" % (docC)
54 print " cs->setDefaultValue(\"%s\");" % (defval)
56 print " cs->setWidgetType(ConfigString::File);"
58 print " cs->setWidgetType(ConfigString::Dir);"
60 print " cs->addDependency(\"%s\");" % (depends)
62 print " ce = cfg->addEnum("
63 print " \"%s\"," % (name)
64 print " \"%s\"," % (docC)
65 print " \"%s\"" % (defval)
69 print " ce->addDependency(\"%s\");" % (depends)
71 minval = node.getAttribute('minval')
72 maxval = node.getAttribute('maxval')
73 print " ci = cfg->addInt("
74 print " \"%s\"," % (name)
75 print " \"%s\"," % (docC)
76 print " %s,%s,%s" % (minval,maxval,defval)
79 print " ci->addDependency(\"%s\");" % (depends)
81 print " cl = cfg->addList("
82 print " \"%s\"," % (name)
83 print " \"%s\"" % (docC)
87 print " cl->addDependency(\"%s\");" % (depends)
89 print " cl->setWidgetType(ConfigList::File);"
91 print " cl->setWidgetType(ConfigList::Dir);"
92 elif format=='filedir':
93 print " cl->setWidgetType(ConfigList::FileAndDir);"
94 elif type=='obsolete':
95 print " cfg->addObsolete(\"%s\");" % (name)
100 def parseGroups(node):
101 name = node.getAttribute('name')
102 doc = node.getAttribute('docs')
103 print " //---------------------------------------------------------------------------";
104 print " cfg->addInfo(\"%s\",\"%s\");" % (name,doc)
105 print " //---------------------------------------------------------------------------";
107 for n in node.childNodes:
108 if n.nodeType == Node.ELEMENT_NODE:
113 doc = xml.dom.minidom.parse("config.xml")
114 elem = doc.documentElement
115 print "/* WARNING: This file is generated!"
116 print " * Do not edit this file, but edit config.xml instead and run"
117 print " * python configgen.py to regenerate this file!"
120 print "#include \"configoptions.h\""
121 print "#include \"config.h\""
122 print "#include \"portable.h\""
124 print "void addConfigOptions(Config *cfg)"
126 print " ConfigString *cs;"
127 print " ConfigEnum *ce;"
128 print " ConfigList *cl;"
129 print " ConfigInt *ci;"
130 print " ConfigBool *cb;"
132 for n in elem.childNodes:
133 if n.nodeType == Node.ELEMENT_NODE:
137 if __name__ == '__main__':