Chameleon

Chameleon Svn Source Tree

Root/branches/xZenu/src/util/doxygen/src/configgen.py

  • Property svn:executable set to *
Source at commit 1322 created 9 years 5 months ago.
By meklort, Add doxygen to utils folder
1# python script to generate configoptions.cpp from config.xml
2#
3# Copyright (C) 1997-2008 by Dimitri van Heesch.
4#
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.
10#
11# Documents produced by Doxygen are derivative works derived from the
12# input used in their production; they are not affected by this license.
13#
14import xml.dom.minidom
15from xml.dom import minidom, Node
16
17def addValues(var,node):
18 for n in node.childNodes:
19if n.nodeType == Node.ELEMENT_NODE:
20name = n.getAttribute('name');
21print " %s->addValue(\"%s\");" % (var,name)
22
23def parseOption(node):
24name = node.getAttribute('id')
25type = node.getAttribute('type')
26format = node.getAttribute('format')
27doc = node.getAttribute('docs')
28defval = node.getAttribute('defval')
29adefval = node.getAttribute('altdefval')
30depends = 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 "')
33print " //----"
34 if type=='bool':
35 if len(adefval)>0:
36enabled = adefval
37else:
38enabled = "TRUE" if defval=='1' else "FALSE"
39print " cb = cfg->addBool("
40print " \"%s\"," % (name)
41print " \"%s\"," % (docC)
42print " %s" % (enabled)
43 print " );"
44if depends!='':
45print " cb->addDependency(\"%s\");" % (depends)
46elif type=='string':
47print " cs = cfg->addString("
48print " \"%s\"," % (name)
49print " \"%s\"" % (docC)
50 print " );"
51if defval!='':
52print " cs->setDefaultValue(\"%s\");" % (defval)
53if format=='file':
54print " cs->setWidgetType(ConfigString::File);"
55elif format=='dir':
56print " cs->setWidgetType(ConfigString::Dir);"
57if depends!='':
58print " cs->addDependency(\"%s\");" % (depends)
59elif type=='enum':
60print " ce = cfg->addEnum("
61print " \"%s\"," % (name)
62print " \"%s\"," % (docC)
63print " \"%s\"" % (defval)
64 print " );"
65 addValues("ce",node)
66if depends!='':
67print " ce->addDependency(\"%s\");" % (depends)
68elif type=='int':
69minval = node.getAttribute('minval')
70maxval = node.getAttribute('maxval')
71print " ci = cfg->addInt("
72print " \"%s\"," % (name)
73print " \"%s\"," % (docC)
74print " %s,%s,%s" % (minval,maxval,defval)
75 print " );"
76if depends!='':
77print " ci->addDependency(\"%s\");" % (depends)
78elif type=='list':
79print " cl = cfg->addList("
80print " \"%s\"," % (name)
81print " \"%s\"" % (docC)
82 print " );"
83addValues("cl",node)
84if depends!='':
85print " cl->addDependency(\"%s\");" % (depends)
86if format=='file':
87print " cl->setWidgetType(ConfigList::File);"
88elif format=='dir':
89print " cl->setWidgetType(ConfigList::Dir);"
90elif format=='filedir':
91print " cl->setWidgetType(ConfigList::FileAndDir);"
92elif type=='obsolete':
93print " cfg->addObsolete(\"%s\");" % (name)
94
95
96
97
98def parseGroups(node):
99name = node.getAttribute('name')
100doc = node.getAttribute('docs')
101 print " //---------------------------------------------------------------------------";
102print " cfg->addInfo(\"%s\",\"%s\");" % (name,doc)
103 print " //---------------------------------------------------------------------------";
104 print
105 for n in node.childNodes:
106if n.nodeType == Node.ELEMENT_NODE:
107parseOption(n)
108
109
110def main():
111doc = xml.dom.minidom.parse("config.xml")
112elem = doc.documentElement
113 print "/* WARNING: This file is generated!"
114 print " * Do not edit this file, but edit config.xml instead and run"
115 print " * python configgen.py to regenerate this file!"
116 print " */"
117 print ""
118 print "#include \"configoptions.h\""
119 print "#include \"config.h\""
120 print "#include \"portable.h\""
121 print ""
122 print "void addConfigOptions(Config *cfg)"
123 print "{"
124 print " ConfigString *cs;"
125 print " ConfigEnum *ce;"
126 print " ConfigList *cl;"
127 print " ConfigInt *ci;"
128 print " ConfigBool *cb;"
129 print ""
130for n in elem.childNodes:
131if n.nodeType == Node.ELEMENT_NODE:
132parseGroups(n)
133 print "}"
134
135if __name__ == '__main__':
136main()
137
138

Archive Download this file

Revision: 1322