Root/
| |
---|---|
Source at commit 1322 created 12 years 8 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 | #␊ |
14 | import xml.dom.minidom␊ |
15 | from xml.dom import minidom, Node␊ |
16 | ␊ |
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)␊ |
22 | ␉␊ |
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 "')␊ |
33 | ␉print " //----"␊ |
34 | if type=='bool':␊ |
35 | ␉if len(adefval)>0:␊ |
36 | ␉␉␉enabled = adefval␊ |
37 | ␉␉else:␊ |
38 | ␉␉␉enabled = "TRUE" if defval=='1' else "FALSE"␊ |
39 | ␉␉print " cb = cfg->addBool("␊ |
40 | ␉␉print " \"%s\"," % (name)␊ |
41 | ␉␉print " \"%s\"," % (docC)␊ |
42 | ␉␉print " %s" % (enabled)␊ |
43 | print " );"␊ |
44 | ␉␉if depends!='':␊ |
45 | ␉␉␉print " cb->addDependency(\"%s\");" % (depends)␊ |
46 | ␉elif type=='string':␊ |
47 | ␉␉print " cs = cfg->addString("␊ |
48 | ␉␉print " \"%s\"," % (name)␊ |
49 | ␉␉print " \"%s\"" % (docC)␊ |
50 | print " );"␊ |
51 | ␉␉if defval!='':␊ |
52 | ␉␉␉print " cs->setDefaultValue(\"%s\");" % (defval)␊ |
53 | ␉␉if format=='file':␊ |
54 | ␉␉␉print " cs->setWidgetType(ConfigString::File);"␊ |
55 | ␉␉elif format=='dir':␊ |
56 | ␉␉␉print " cs->setWidgetType(ConfigString::Dir);"␊ |
57 | ␉␉if depends!='':␊ |
58 | ␉␉␉print " cs->addDependency(\"%s\");" % (depends)␊ |
59 | ␉elif type=='enum':␊ |
60 | ␉␉print " ce = cfg->addEnum("␊ |
61 | ␉␉print " \"%s\"," % (name)␊ |
62 | ␉␉print " \"%s\"," % (docC)␊ |
63 | ␉␉print " \"%s\"" % (defval)␊ |
64 | print " );"␊ |
65 | addValues("ce",node)␊ |
66 | ␉␉if depends!='':␊ |
67 | ␉␉␉print " ce->addDependency(\"%s\");" % (depends)␊ |
68 | ␉elif type=='int':␊ |
69 | ␉␉minval = node.getAttribute('minval')␊ |
70 | ␉␉maxval = node.getAttribute('maxval')␊ |
71 | ␉␉print " ci = cfg->addInt("␊ |
72 | ␉␉print " \"%s\"," % (name)␊ |
73 | ␉␉print " \"%s\"," % (docC)␊ |
74 | ␉␉print " %s,%s,%s" % (minval,maxval,defval)␊ |
75 | print " );"␊ |
76 | ␉␉if depends!='':␊ |
77 | ␉␉␉print " ci->addDependency(\"%s\");" % (depends)␊ |
78 | ␉elif type=='list':␊ |
79 | ␉␉print " cl = cfg->addList("␊ |
80 | ␉␉print " \"%s\"," % (name)␊ |
81 | ␉␉print " \"%s\"" % (docC)␊ |
82 | print " );"␊ |
83 | ␉␉addValues("cl",node)␊ |
84 | ␉␉if depends!='':␊ |
85 | ␉␉␉print " cl->addDependency(\"%s\");" % (depends)␊ |
86 | ␉␉if format=='file':␊ |
87 | ␉␉␉print " cl->setWidgetType(ConfigList::File);"␊ |
88 | ␉␉elif format=='dir':␊ |
89 | ␉␉␉print " cl->setWidgetType(ConfigList::Dir);"␊ |
90 | ␉␉elif format=='filedir':␊ |
91 | ␉␉␉print " cl->setWidgetType(ConfigList::FileAndDir);"␊ |
92 | ␉elif type=='obsolete':␊ |
93 | ␉␉print " cfg->addObsolete(\"%s\");" % (name)␊ |
94 | ␉␉␊ |
95 | ␊ |
96 | ␊ |
97 | ␊ |
98 | def parseGroups(node):␊ |
99 | ␉name = node.getAttribute('name')␊ |
100 | ␉doc = node.getAttribute('docs')␊ |
101 | print " //---------------------------------------------------------------------------";␊ |
102 | ␉print " cfg->addInfo(\"%s\",\"%s\");" % (name,doc)␊ |
103 | print " //---------------------------------------------------------------------------";␊ |
104 | print␊ |
105 | for n in node.childNodes:␊ |
106 | ␉␉if n.nodeType == Node.ELEMENT_NODE:␊ |
107 | ␉␉␉parseOption(n)␊ |
108 | ␉␊ |
109 | ␊ |
110 | def main():␊ |
111 | ␉doc = xml.dom.minidom.parse("config.xml")␊ |
112 | ␉elem = 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 ""␊ |
130 | ␉for n in elem.childNodes:␊ |
131 | ␉␉if n.nodeType == Node.ELEMENT_NODE:␊ |
132 | ␉␉␉parseGroups(n)␊ |
133 | print "}"␊ |
134 | ␊ |
135 | if __name__ == '__main__':␊ |
136 | ␉main()␊ |
137 | ␊ |
138 |