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