Fix for UBSan build
[platform/upstream/doxygen.git] / src / configgen.py
1 # python script to generate configoptions.cpp from config.xml
2 #
3 # Copyright (C) 1997-2012 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                 elif defval=='1':
38                         enabled = "TRUE"
39                 else:
40                         enabled = "FALSE"
41                 print "  cb = cfg->addBool("
42                 print "                 \"%s\"," % (name)
43                 print "                 \"%s\"," % (docC)
44                 print "                 %s"  % (enabled)
45                 print "                );"
46                 if depends!='':
47                         print "  cb->addDependency(\"%s\");" % (depends)
48         elif type=='string':
49                 print "  cs = cfg->addString("
50                 print "                 \"%s\"," % (name)
51                 print "                 \"%s\""  % (docC)
52                 print "                );"
53                 if defval!='':
54                         print "  cs->setDefaultValue(\"%s\");" % (defval)
55                 if format=='file':
56                         print "  cs->setWidgetType(ConfigString::File);"
57                 elif format=='dir':
58                         print "  cs->setWidgetType(ConfigString::Dir);"
59                 if depends!='':
60                         print "  cs->addDependency(\"%s\");" % (depends)
61         elif type=='enum':
62                 print "  ce = cfg->addEnum("
63                 print "                 \"%s\"," % (name)
64                 print "                 \"%s\"," % (docC)
65                 print "                 \"%s\""  % (defval)
66                 print "                );"
67                 addValues("ce",node)
68                 if depends!='':
69                         print "  ce->addDependency(\"%s\");" % (depends)
70         elif type=='int':
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)
77                 print "                );"
78                 if depends!='':
79                         print "  ci->addDependency(\"%s\");" % (depends)
80         elif type=='list':
81                 print "  cl = cfg->addList("
82                 print "                 \"%s\"," % (name)
83                 print "                 \"%s\""  % (docC)
84                 print "                );"
85                 addValues("cl",node)
86                 if depends!='':
87                         print "  cl->addDependency(\"%s\");" % (depends)
88                 if format=='file':
89                         print "  cl->setWidgetType(ConfigList::File);"
90                 elif format=='dir':
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)
96                 
97
98
99
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 "  //---------------------------------------------------------------------------";
106         print
107         for n in node.childNodes:
108                 if n.nodeType == Node.ELEMENT_NODE:
109                         parseOption(n)
110         
111
112 def main():
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!"
118         print " */"
119         print ""
120         print "#include \"configoptions.h\""
121         print "#include \"config.h\""
122         print "#include \"portable.h\""
123         print ""
124         print "void addConfigOptions(Config *cfg)"
125         print "{"
126         print "  ConfigString *cs;"
127         print "  ConfigEnum   *ce;"
128         print "  ConfigList   *cl;"
129         print "  ConfigInt    *ci;"
130         print "  ConfigBool   *cb;"
131         print ""
132         for n in elem.childNodes:
133                 if n.nodeType == Node.ELEMENT_NODE:
134                         parseGroups(n)
135         print "}"
136
137 if __name__ == '__main__':
138         main()
139