15 import xml.dom.minidom
19 from xml.dom
import minidom, Node
25 doc = doc.replace(
"\n",
" ")
26 doc = doc.replace(
"\r",
" ")
27 doc = doc.replace(
"\t",
" ")
28 doc = doc.replace(
"\\&",
"&")
29 doc = doc.replace(
"(\\c ",
"(")
30 doc = doc.replace(
"\\c ",
" ")
31 doc = doc.replace(
"\\b ",
" ")
32 doc = doc.replace(
"\\e ",
" ")
33 doc = doc.replace(
"\\$",
"$")
34 doc = doc.replace(
"\\#include ",
"#include ")
35 doc = doc.replace(
"\\#undef ",
"#undef ")
36 doc = doc.replace(
"-# ",
"\n - ")
37 doc = doc.replace(
" - ",
"\n - ")
38 doc = doc.replace(
"\\sa",
"\nSee also: ")
39 doc = doc.replace(
"\\par",
"\n")
40 doc = doc.replace(
"@note",
"\nNote:")
41 doc = doc.replace(
"\\note",
"\nNote:")
42 doc = doc.replace(
"\\verbatim",
"\n")
43 doc = doc.replace(
"\\endverbatim",
"\n")
44 doc = doc.replace(
"<code>",
"")
45 doc = doc.replace(
"</code>",
"")
46 doc = doc.replace(
"`",
"")
47 doc = doc.replace(
"\\<",
"<")
48 doc = doc.replace(
"\\>",
">")
49 doc = doc.replace(
"\\@",
"@")
50 doc = doc.replace(
"\\\\",
"\\")
52 doc = re.sub(
'\\\\ref +[^ ]* +"([^"]*)"',
'\\1', doc)
55 doc = re.sub(
'\\\\ref +doxygen_usage',
'"Doxygen usage"', doc)
56 doc = re.sub(
'\\\\ref +extsearch',
'"External Indexing and Searching"',
58 doc = re.sub(
'\\\\ref +external',
'"Linking to external documentation"',
61 doc = re.sub(
'\\\\ref',
'', doc)
63 doc = re.sub(
'<a +href="([^"]*)" *>([^<]*)</a>',
'\\2 (see: \\1)', doc)
65 doc = doc.replace(
"\\f$\\mbox{\\LaTeX}\\f$",
"LaTeX")
67 doc = doc.replace(
"\\f$2^{(16+\\mbox{LOOKUP\\_CACHE\\_SIZE})}\\f$",
68 "2^(16+LOOKUP_CACHE_SIZE)")
69 doc = doc.replace(
"\\f$2^{16} = 65536\\f$",
"2^16=65536")
71 doc = re.sub(
" +",
" ", doc)
75 doc = doc.replace(
"<br>",
"\n<br>\n")
79 doc = doc.replace(
"<br/>",
"\n<br/>\n")
81 doc = doc.splitlines()
84 split_doc += textwrap.wrap(line, 78)
88 for line
in split_doc:
89 if (line.strip() !=
"<br/>"):
90 docC.append(line.strip().replace(
'\\',
'\\\\').
91 replace(
'"',
'\\"').replace(
"<br>",
""))
97 for n
in node.childNodes:
98 if (n.nodeName ==
"value"):
99 if n.nodeType == Node.ELEMENT_NODE:
100 if n.getAttribute(
'name') !=
"":
101 if n.getAttribute(
'show_docu') !=
"NO":
102 name =
"<code>" + n.getAttribute(
'name') +
"</code>" 103 desc = n.getAttribute(
'desc')
111 for n
in node.childNodes:
112 if (n.nodeName ==
"value"):
113 if n.nodeType == Node.ELEMENT_NODE:
114 name = n.getAttribute(
'name')
115 print(
" %s->addValue(\"%s\");" % (var, name))
120 for n
in node.childNodes:
121 if n.nodeType == Node.ELEMENT_NODE:
122 if (n.nodeName ==
"docs"):
123 if (n.getAttribute(
'doxyfile') !=
"0"):
126 print(
" %s->setHeader(" % (objName))
131 print(
" \"%s\\n\"" % (line))
133 print(
" \"%s\"" % (line))
138 type = node.getAttribute(
'type')
139 format = node.getAttribute(
'format')
140 defval = node.getAttribute(
'defval')
141 adefval = node.getAttribute(
'altdefval')
143 if (type !=
'obsolete'):
144 for n
in node.childNodes:
145 if (n.nodeName ==
"docs"):
146 if (n.getAttribute(
'doxyfile') !=
"0"):
147 if n.nodeType == Node.ELEMENT_NODE:
151 doc +=
"<br/>Possible values are: " 156 doc +=
"%s and " % (val)
160 doc +=
"%s, " % (val)
162 doc +=
"<br/>The default value is: <code>%s</code>." % (defval)
163 elif (type ==
'int'):
164 minval = node.getAttribute(
'minval')
165 maxval = node.getAttribute(
'maxval')
166 doc +=
"<br/>%s: %s, %s: %s, %s: %s." % (
" Minimum value", minval,
167 "maximum value", maxval,
168 "default value", defval)
169 elif (type ==
'bool'):
170 if (node.hasAttribute(
'altdefval')):
171 doc +=
"<br/>%s: %s." % (
"The default value is",
"system dependent")
173 doc +=
"<br/>%s: %s." % (
"The default value is",
"YES" if (defval ==
"1")
else "NO")
174 elif (type ==
'list'):
175 if format ==
'string':
181 doc +=
"%s and " % (val)
185 doc +=
"%s, " % (val)
186 elif (type ==
'string'):
189 doc +=
"<br/>The default directory is: <code>%s</code>." % (
191 elif format ==
'file':
192 abspath = node.getAttribute(
'abspath')
195 doc +=
"<br/>The default file is: <code>%s</code>." % (
198 doc +=
"<br/>%s: %s%s%s." % (
199 "The default file (with absolute path) is",
200 "<code>",defval,
"</code>")
203 doc +=
"<br/>The file has to be specified with full path." 204 elif format ==
'image':
205 abspath = node.getAttribute(
'abspath')
208 doc +=
"<br/>The default image is: <code>%s</code>." % (
211 doc +=
"<br/>%s: %s%s%s." % (
212 "The default image (with absolute path) is",
213 "<code>",defval,
"</code>")
216 doc +=
"<br/>The image has to be specified with full path." 219 doc +=
"<br/>The default value is: <code>%s</code>." % (
222 if (node.hasAttribute(
'depends')):
223 depends = node.getAttribute(
'depends')
224 doc +=
"<br/>%s \\ref cfg_%s \"%s\" is set to \\c YES." % (
225 "This tag requires that the tag", depends.lower(), depends.upper())
232 name = node.getAttribute(
'id')
233 type = node.getAttribute(
'type')
234 format = node.getAttribute(
'format')
235 defval = node.getAttribute(
'defval')
236 adefval = node.getAttribute(
'altdefval')
237 depends = node.getAttribute(
'depends')
238 setting = node.getAttribute(
'setting')
241 print(
"#if %s" % (setting))
250 print(
" cb = cfg->addBool(")
251 print(
" \"%s\"," % (name))
256 print(
" \"%s\\n\"" % (line))
258 print(
" \"%s\"," % (line))
259 print(
" %s" % (enabled))
262 print(
" cb->addDependency(\"%s\");" % (depends))
263 elif type ==
'string':
264 print(
" cs = cfg->addString(")
265 print(
" \"%s\"," % (name))
270 print(
" \"%s\\n\"" % (line))
272 print(
" \"%s\"" % (line))
275 print(
" cs->setDefaultValue(\"%s\");" % (defval))
277 print(
" cs->setWidgetType(ConfigString::File);")
278 elif format ==
'image':
279 print(
" cs->setWidgetType(ConfigString::Image);")
280 elif format ==
'dir':
281 print(
" cs->setWidgetType(ConfigString::Dir);")
283 print(
" cs->addDependency(\"%s\");" % (depends))
285 print(
" ce = cfg->addEnum(")
286 print(
" \"%s\"," % (name))
291 print(
" \"%s\\n\"" % (line))
293 print(
" \"%s\"," % (line))
294 print(
" \"%s\"" % (defval))
298 print(
" ce->addDependency(\"%s\");" % (depends))
300 minval = node.getAttribute(
'minval')
301 maxval = node.getAttribute(
'maxval')
302 print(
" ci = cfg->addInt(")
303 print(
" \"%s\"," % (name))
308 print(
" \"%s\\n\"" % (line))
310 print(
" \"%s\"," % (line))
311 print(
" %s,%s,%s" % (minval, maxval, defval))
314 print(
" ci->addDependency(\"%s\");" % (depends))
316 print(
" cl = cfg->addList(")
317 print(
" \"%s\"," % (name))
322 print(
" \"%s\\n\"" % (line))
324 print(
" \"%s\"" % (line))
328 print(
" cl->addDependency(\"%s\");" % (depends))
330 print(
" cl->setWidgetType(ConfigList::File);")
331 elif format ==
'dir':
332 print(
" cl->setWidgetType(ConfigList::Dir);")
333 elif format ==
'filedir':
334 print(
" cl->setWidgetType(ConfigList::FileAndDir);")
335 elif type ==
'obsolete':
336 print(
" cfg->addObsolete(\"%s\");" % (name))
339 print(
" cfg->addDisabled(\"%s\");" % (name))
344 name = node.getAttribute(
'name')
345 doc = node.getAttribute(
'docs')
346 print(
"%s%s" % (
" //-----------------------------------------",
347 "----------------------------------"))
348 print(
" cfg->addInfo(\"%s\",\"%s\");" % (name, doc))
349 print(
"%s%s" % (
" //-----------------------------------------",
350 "----------------------------------"))
352 for n
in node.childNodes:
353 if n.nodeType == Node.ELEMENT_NODE:
357 for n
in node.childNodes:
358 if n.nodeType == Node.ELEMENT_NODE:
359 type = n.getAttribute(
'type')
360 name = n.getAttribute(
'id')
362 if type !=
'obsolete':
364 print(
" \"%s\"," % (name))
369 print(
" \"%s\\n\"" % (line))
371 print(
" \"%s\"" % (line))
376 name = node.getAttribute(
'id')
377 type = node.getAttribute(
'type')
378 format = node.getAttribute(
'format')
379 defval = node.getAttribute(
'defval')
380 adefval = node.getAttribute(
'altdefval')
381 depends = node.getAttribute(
'depends')
382 setting = node.getAttribute(
'setting')
384 if (type !=
'obsolete'):
385 for n
in node.childNodes:
386 if (n.nodeName ==
"docs"):
387 if (n.getAttribute(
'documentation') !=
"0"):
388 if n.nodeType == Node.ELEMENT_NODE:
391 print(
" \\anchor cfg_%s" % (name.lower()))
394 print(
"<dt>\\c %s <dd>" % (name))
396 print(
" \\anchor cfg_%s" % (name.lower()))
397 print(
"<dt>\\c %s <dd>" % (name))
398 print(
" \\addindex %s" % (name))
403 print(
"Possible values are: ")
408 print(
"%s and " % (val))
412 print(
"%s, " % (val))
416 print(
"The default value is: <code>%s</code>." % (defval))
418 elif (type ==
'int'):
419 minval = node.getAttribute(
'minval')
420 maxval = node.getAttribute(
'maxval')
423 print(
"%s: %s%s%s, %s: %s%s%s, %s: %s%s%s." % (
424 " Minimum value",
"<code>", minval,
"</code>",
425 "maximum value",
"<code>", maxval,
"</code>",
426 "default value",
"<code>", defval,
"</code>"))
428 elif (type ==
'bool'):
431 if (node.hasAttribute(
'altdefval')):
432 print(
"The default value is: system dependent.")
434 print(
"The default value is: <code>%s</code>." % (
435 "YES" if (defval ==
"1")
else "NO"))
437 elif (type ==
'list'):
438 if format ==
'string':
444 print(
"%s and " % (val))
448 print(
"%s, " % (val))
450 elif (type ==
'string'):
454 print(
"The default directory is: <code>%s</code>." % (
456 elif format ==
'file':
457 abspath = node.getAttribute(
'abspath')
461 print(
"The default file is: <code>%s</code>." % (
464 print(
"%s: %s%s%s." % (
465 "The default file (with absolute path) is",
466 "<code>",defval,
"</code>"))
470 print(
"The file has to be specified with full path.")
471 elif format ==
'image':
472 abspath = node.getAttribute(
'abspath')
476 print(
"The default image is: <code>%s</code>." % (
479 print(
"%s: %s%s%s." % (
480 "The default image (with absolute path) is",
481 "<code>",defval,
"</code>"))
485 print(
"The image has to be specified with full path.")
489 print(
"The default value is: <code>%s</code>." % (
493 if (node.hasAttribute(
'depends')):
494 depends = node.getAttribute(
'depends')
496 print(
"%s \\ref cfg_%s \"%s\" is set to \\c YES." % (
497 "This tag requires that the tag", depends.lower(), depends.upper()))
502 name = node.getAttribute(
'name')
503 doc = node.getAttribute(
'docs')
504 print(
"\section config_%s %s" % (name.lower(), doc))
510 for n
in node.childNodes:
511 if n.nodeType == Node.ELEMENT_NODE:
519 for n
in node.childNodes:
520 if n.nodeType == Node.ELEMENT_NODE:
521 type = n.getAttribute(
'type')
522 if type !=
'obsolete':
523 commandsList = commandsList + (n.getAttribute(
'id'),)
529 for n
in node.childNodes:
530 if n.nodeType == Node.TEXT_NODE:
531 doc += n.nodeValue.strip()
532 if n.nodeType == Node.CDATA_SECTION_NODE:
533 doc += n.nodeValue.rstrip(
"\r\n ").lstrip(
"\r\n")
540 for n
in node.childNodes:
541 if n.nodeType == Node.ELEMENT_NODE:
542 if (n.nodeName ==
"docs"):
543 if (n.getAttribute(
'documentation') !=
"0"):
550 for n
in node.childNodes:
551 if n.nodeType == Node.ELEMENT_NODE:
552 if (n.nodeName ==
"docs"):
553 if (n.getAttribute(
'documentation') !=
"0"):
559 if len(sys.argv)<3
or (
not sys.argv[1]
in [
'-doc',
'-cpp',
'-wiz']):
560 sys.exit(
'Usage: %s -doc|-cpp|-wiz config.xml' % sys.argv[0])
562 doc = xml.dom.minidom.parse(sys.argv[2])
563 except Exception
as inst:
564 sys.stdout = sys.stderr
569 elem = doc.documentElement
570 if (sys.argv[1] ==
"-doc"):
571 print(
"/* WARNING: This file is generated!")
572 print(
" * Do not edit this file, but edit config.xml instead and run")
573 print(
" * python configgen.py -doc config.xml to regenerate this file!")
576 for n
in elem.childNodes:
577 if n.nodeType == Node.ELEMENT_NODE:
578 if (n.nodeName ==
"header"):
582 for n
in elem.childNodes:
583 if n.nodeType == Node.ELEMENT_NODE:
584 if (n.nodeName ==
"group"):
586 print(
"\\secreflist")
587 for x
in sorted(commandsList):
588 print(
"\\refitem cfg_%s %s" % (x.lower(), x))
589 print(
"\\endsecreflist")
591 for n
in elem.childNodes:
592 if n.nodeType == Node.ELEMENT_NODE:
593 if (n.nodeName ==
"group"):
596 for n
in elem.childNodes:
597 if n.nodeType == Node.ELEMENT_NODE:
598 if (n.nodeName ==
"footer"):
600 elif (sys.argv[1] ==
"-cpp"):
601 print(
"/* WARNING: This file is generated!")
602 print(
" * Do not edit this file, but edit config.xml instead and run")
603 print(
" * python configgen.py -cpp config.xml to regenerate this file!")
606 print(
"#include \"configoptions.h\"")
607 print(
"#include \"config.h\"")
608 print(
"#include \"portable.h\"")
609 print(
"#include \"settings.h\"")
611 print(
"void addConfigOptions(Config *cfg)")
613 print(
" ConfigString *cs;")
614 print(
" ConfigEnum *ce;")
615 print(
" ConfigList *cl;")
616 print(
" ConfigInt *ci;")
617 print(
" ConfigBool *cb;")
620 for n
in elem.childNodes:
621 if n.nodeType == Node.ELEMENT_NODE:
622 if (n.nodeName ==
"header"):
624 for n
in elem.childNodes:
625 if n.nodeType == Node.ELEMENT_NODE:
626 if (n.nodeName ==
"group"):
629 elif (sys.argv[1] ==
"-wiz"):
630 print(
"/* WARNING: This file is generated!")
631 print(
" * Do not edit this file, but edit config.xml instead and run")
632 print(
" * python configgen.py -wiz config.xml to regenerate this file!")
634 print(
"#include \"configdoc.h\"")
635 print(
"#include \"docintf.h\"")
637 print(
"void addConfigDocs(DocIntf *doc)")
639 for n
in elem.childNodes:
640 if n.nodeType == Node.ELEMENT_NODE:
641 if (n.nodeName ==
"header"):
643 for n
in elem.childNodes:
644 if n.nodeType == Node.ELEMENT_NODE:
645 if (n.nodeName ==
"group"):
649 if __name__ ==
'__main__':
def parseOptionDoc(node, first)
def parseGroupsList(node, commandsList)
def parseHeader(node, objName)
def parseGroupCDocs(node)