+def parse_command(cmd):
+ proto = get_first_child(cmd, "proto")
+ name = get_text_contents(get_first_child(proto, "name"))
+ func = things.get(name)
+ if not func:
+ func = Function(name)
+ things[name] = func
+
+ aliases = get_nested_elements(cmd, "alias")
+ func.aliases = [a.getAttribute("name") for a in aliases]
+
+ ptype = get_first_child(proto, "ptype")
+ if ptype:
+ func.return_type = get_text_contents(ptype)
+ else:
+ for c in proto.childNodes:
+ if c.nodeType==xml.dom.Node.TEXT_NODE and c.data.strip():
+ func.return_type = c.data.strip()
+ break
+
+ params = get_nested_elements(cmd, "param")
+ func.params = map(get_text_contents, params)
+
+def parse_enum(en):
+ name = en.getAttribute("name")
+ enum = things.get(name)
+ if not enum:
+ enum = Enum(name)
+ things[name] = enum
+
+ enum.value = int(en.getAttribute("value"), 16)
+
+def parse_feature(feat):
+ api = feat.getAttribute("api")
+ if api=="gl":
+ version = feat.getAttribute("number")
+ if version:
+ version = map(int, version.split('.'))
+ else:
+ version = None
+
+ commands = get_nested_elements(feat, "require/command")
+ enums = get_nested_elements(feat, "require/enum")
+ for t in itertools.chain(commands, enums):
+ name = t.getAttribute("name")
+ thing = things.get(name)
+ if thing:
+ thing.version = version
+
+ if feat.getAttribute("name")=="MSPGL_REMOVE":
+ commands = get_nested_elements(feat, "remove/command")
+ enums = get_nested_elements(feat, "remove/enum")
+ for t in itertools.chain(commands, enums):
+ name = t.getAttribute("name")
+ if name in things:
+ del things[name]
+
+def parse_extension(ext):
+ ext_name = ext.getAttribute("name")
+ if ext_name.startswith("GL_"):
+ ext_name = ext_name[3:]
+
+ supported = ext.getAttribute("supported").split('|')
+ if "gl" in supported:
+ commands = get_nested_elements(ext, "require/command")
+ enums = get_nested_elements(ext, "require/enum")
+ for t in itertools.chain(commands, enums):
+ name = t.getAttribute("name")
+ thing = things.get(name)
+ if thing:
+ thing.extension = ext_name
+