Update preset.
[bertos.git] / doc / chm-toc-modifier.py
1 from __future__ import with_statement
2 import sys, re
3
4 if len(sys.argv) < 1:
5     print "Usage: " + sys.argv[0] + " [hhc index file] [output file]"
6     sys.exit(-1)
7
8 outfile = "out.hhc"
9 if len(sys.argv) == 3:
10     outfile = sys.argv[2]
11
12 data_structures = []
13
14 section_start = re.compile(r"<LI>.*? value=\"((File List)|(Data Structures)|(Main Page)|(Directory Hierarchy))\".*$")
15
16 data_section = False
17 file_section = False
18
19 with open(sys.argv[1], "r") as f:
20     with open(outfile, "w+") as out:
21         for line in f:
22             if re.search(section_start, line):
23                 if line.find("Data Structures") != -1:
24                     data_section = True
25                     file_section = False
26                 elif line.find("File List") != -1:
27                     data_section = False
28                     file_section = True
29                 else:
30                     data_section = False
31                     file_section = False
32
33             if data_section:
34                 data_structures.append(line)
35             elif file_section:
36                 pass
37             elif re.search(r"^<\/UL>$", line):
38                 for i in data_structures:
39                     out.write(i)
40                 out.write(line)
41             else:
42                 out.write(line)
43
44