doc: Add script to modify chm TOC.
authorlottaviano <lottaviano@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 29 Jun 2009 09:24:00 +0000 (09:24 +0000)
committerlottaviano <lottaviano@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 29 Jun 2009 09:24:00 +0000 (09:24 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@2718 38d2e660-2303-0410-9eaa-f027e97ec537

doc/chm-toc-modifier.py [new file with mode: 0644]

diff --git a/doc/chm-toc-modifier.py b/doc/chm-toc-modifier.py
new file mode 100644 (file)
index 0000000..f6239c8
--- /dev/null
@@ -0,0 +1,44 @@
+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