Atrinik Server  4.0
types-extra.py
1 # This script is used to generate documentation about field/flag
2 # usage of different object types. Unlike the Gridarta types.xml
3 # convert tool, types-extra should include everything, even
4 # internally used, to make it easier for developers to see unused
5 # fields/flags, and to understand what they do.
6 
7 fp = open("types-extra", "r")
8 
9 last_field = None
10 last_type = None
11 types = {}
12 definitions = {}
13 
14 def preprocess(string):
15  for definition in definitions:
16  string = string.replace(definition, definitions[definition])
17 
18  return string
19 
20 for line in fp:
21  if line[:1] == "#" and not last_type:
22  if line[:8] == "#define ":
23  definition_name = line[8:line.find(" ", 8)]
24  definition_content = line[8 + len(definition_name):].strip()
25  definitions[definition_name] = definition_content
26 
27  continue
28 
29  if line[:5] == "type ":
30  last_type = line[5:].strip()
31  types[last_type] = {
32  "fields": [],
33  }
34  elif line == "end\n":
35  last_field = None
36  last_type = None
37  elif line != "\n":
38  if last_field and line[:6] == "field ":
39  last_field = None
40 
41  if line[:6] == "field ":
42  last_field = line[6:].strip()
43  types[last_type]["fields"].append({
44  "field": last_field,
45  "explanation": "",
46  "field_help": None,
47  })
48  elif line[:11] == "field_help ":
49  types[last_type]["fields"][len(types[last_type]["fields"]) - 1]["field_help"] = line[11:].strip()
50  else:
51  types[last_type]["fields"][len(types[last_type]["fields"]) - 1]["explanation"] += line
52 
53 fp.close()
54 
55 doc_fp = open("types-extra.dox", "w")
56 
57 for type in types:
58  doc_fp.write("/**\n@def %s\n@ref ::obj \"Object\" fields and flags used by this type." % type)
59  doc_fp.write("\n<table>\n<tr>\n<th>Field/Flag</th>\n<th>Explanation</th>\n</tr>")
60 
61  for i in range(0, len(types[type]["fields"])):
62  doc_fp.write("\n<tr>\n<td>")
63 
64  if types[type]["fields"][i]["field_help"]:
65  doc_fp.write("<span title=\"%s\" style=\"border-bottom: 1px dashed #000;\">" % preprocess(types[type]["fields"][i]["field_help"]))
66 
67  if types[type]["fields"][i]["field"][:5] == "FLAG_":
68  doc_fp.write("@ref ")
69 
70  doc_fp.write(types[type]["fields"][i]["field"])
71 
72  if types[type]["fields"][i]["field_help"]:
73  doc_fp.write("</span>")
74 
75  doc_fp.write("</td>\n<td>%s</td>\n</tr>" % types[type]["fields"][i]["explanation"].strip())
76 
77  doc_fp.write("\n</table>\n*/\n\n")
78 
79 doc_fp.close()
static PyObject * append(Atrinik_AttrList *al, PyObject *value)
Definition: attr_list.c:547