Debian Codegraph @

scripts/options_to_doc.py

raw symbols SCIP
1 #
2 # File: options_conv.py
3 #
4 # Copyright (C) 2013 Steve Ratcliffe
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 2 or
8 # version 3 as published by the Free Software Foundation.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 #
16 # Author: Steve Ratcliffe
17 # Create date: 28 Jun 2013
18 #
19
20 import sys
21 import re
22
23 f = open('options')
24
25 NONE = 0
26 OPT = 1
27 DESC = 2
28
29 WS=(' ', '\t')
30
31 def count_indent(line):
32 count = 0
33 for c in line:
34 if c == ' ':
35 count += 1
36 elif c == '\t':
37 count += 4
38 else:
39 break
40 return count
41
42 state = NONE
43 in_preserve = False
44 desc_indent = 0
45 last_indent = 0
46
47 def start_preserve():
48 global in_preserve
49 if in_preserve: return
50 in_preserve = True
51 print '<div class=preserve><nowiki>'
52
53 def end_preserve():
54 global in_preserve
55 if not in_preserve: return
56 in_preserve = False
57 print '</nowiki></div>'
58
59 print '= List of options ='
60
61 for line in f.xreadlines():
62 line = line[:-1]
63
64 if len(line) == 0 or len(line.strip()) == 0:
65 if state == DESC:
66 if in_preserve:
67 print
68 else:
69 print '<p>'
70 continue
71 print
72 continue
73
74 if line[0] == '-':
75 end_preserve()
76 line = ';' + line
77 state = OPT
78
79 if state == OPT and line[0] in WS:
80 state = DESC
81 desc_indent = count_indent(line)
82 last_indent = desc_indent
83 print ':', line
84 continue
85 elif state == DESC and line[0] not in WS:
86 if last_indent > desc_indent:
87 end_preserve()
88 print
89 last_indent = 0
90 state = NONE
91
92 if state == DESC:
93 new_indent = count_indent(line)
94 line = re.sub(r'^(\t| {1,4})', '', line)
95 if new_indent > last_indent:
96 start_preserve()
97 elif new_indent < last_indent and new_indent == desc_indent:
98 end_preserve()
99 last_indent = new_indent
100
101 print line