From: lottaviano Date: Mon, 29 Jun 2009 09:24:00 +0000 (+0000) Subject: doc: Add script to modify chm TOC. X-Git-Tag: 2.2.0~250 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=34bc08f544f7745e99bdb9197c390701bdee5e4b;p=bertos.git doc: Add script to modify chm TOC. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@2718 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/doc/chm-toc-modifier.py b/doc/chm-toc-modifier.py new file mode 100644 index 00000000..f6239c8c --- /dev/null +++ b/doc/chm-toc-modifier.py @@ -0,0 +1,44 @@ +from __future__ import with_statement +import sys, re + +if len(sys.argv) < 1: + print "Usage: " + sys.argv[0] + " [hhc index file] [output file]" + sys.exit(-1) + +outfile = "out.hhc" +if len(sys.argv) == 3: + outfile = sys.argv[2] + +data_structures = [] + +section_start = re.compile(r"
  • .*? value=\"((File List)|(Data Structures)|(Main Page)|(Directory Hierarchy))\".*$") + +data_section = False +file_section = False + +with open(sys.argv[1], "r") as f: + with open(outfile, "w+") as out: + for line in f: + if re.search(section_start, line): + if line.find("Data Structures") != -1: + data_section = True + file_section = False + elif line.find("File List") != -1: + data_section = False + file_section = True + else: + data_section = False + file_section = False + + if data_section: + data_structures.append(line) + elif file_section: + pass + elif re.search(r"^<\/UL>$", line): + for i in data_structures: + out.write(i) + out.write(line) + else: + out.write(line) + +