--- /dev/null
+from __future__ import with_statement\r
+import sys, re\r
+\r
+if len(sys.argv) < 1:\r
+ print "Usage: " + sys.argv[0] + " [hhc index file] [output file]"\r
+ sys.exit(-1)\r
+\r
+outfile = "out.hhc"\r
+if len(sys.argv) == 3:\r
+ outfile = sys.argv[2]\r
+\r
+data_structures = []\r
+\r
+section_start = re.compile(r"<LI>.*? value=\"((File List)|(Data Structures)|(Main Page)|(Directory Hierarchy))\".*$")\r
+\r
+data_section = False\r
+file_section = False\r
+\r
+with open(sys.argv[1], "r") as f:\r
+ with open(outfile, "w+") as out:\r
+ for line in f:\r
+ if re.search(section_start, line):\r
+ if line.find("Data Structures") != -1:\r
+ data_section = True\r
+ file_section = False\r
+ elif line.find("File List") != -1:\r
+ data_section = False\r
+ file_section = True\r
+ else:\r
+ data_section = False\r
+ file_section = False\r
+\r
+ if data_section:\r
+ data_structures.append(line)\r
+ elif file_section:\r
+ pass\r
+ elif re.search(r"^<\/UL>$", line):\r
+ for i in data_structures:\r
+ out.write(i)\r
+ out.write(line)\r
+ else:\r
+ out.write(line)\r
+\r
+\r