Silence some DocBook warnings.
[super-star-trek.git] / doc / makehelp.py
1 #!/usr/bin/env python
2 #
3 # Generate an on-line help file for SST 2K from the text generated from
4 # the XML documentation.
5 #
6 # By Eric S. Raymond for the Super Star Trek project
7 import os, re, sys
8
9 enddelim = "********\n"
10
11 # This is the part most likely to bit-rot
12 beginmarker1 = "Mnemonic:"
13 endmarker1 = "Miscellaneous Notes"
14 beginmarker2 = " ABBREV"
15 endmarker2 = "Game History and Modifications"
16
17 fp = open("sst-doc.txt", "r")
18 savetext = []
19 state = 0
20 while True:
21     line = fp.readline()
22     if not line:
23         break
24     if state == 0 and line.startswith(beginmarker1):
25         line = "% " + line[12:].lstrip()
26         state = 1
27     if state == 0 and line.startswith(beginmarker2):
28         savetext.append(enddelim + "%% ABBREV\n")
29         state = 2
30     if state == 1:
31         if line.find(endmarker1) > -1:
32             state = 0
33     if state == 2:
34         if line.find(endmarker2) > -1:
35             state = 0
36     if state:
37         line = line.replace("%", "%%")
38         # Hack Unicode non-breaking spaces into ordinary spaces
39         line = line.replace("\xc2\xa0", " ").replace("\240", "")
40         # Hack right and left quotes into regular ASCII quotes
41         line = line.replace("\xe2\x80\x9c", '"').replace("\xe2\x80\x9d", '"')
42         # Hack dashes and bullets (Hmmm...might want to handle this in curses)
43         line = line.replace("\xe2\x80\x94", "-").replace("\xe2\x97\x8f", "*");
44         if line.startswith("Mnemonic:"):
45             while not savetext[-1].strip():
46                 savetext.pop()
47         savetext.append(line)
48 savetext = "".join(savetext)
49
50 # Remove the section titles
51 savetext = re.sub("\n+.*\n*Mnemonic:\\s*", "\n********\n%% ", savetext)
52
53 sys.stdout.write(savetext + enddelim)