blob: 3d284312fbe0869473d1c93b943dcb0280d98b6a [file] [log] [blame]
Guido van Rossum7a2dba21993-11-05 14:45:11 +00001import os
2import sys
3import regex
4import string
5import getopt
6
7def main():
8 process(sys.stdin, sys.stdout)
9
10dashes = regex.compile('^-+[ \t]*$')
11equals = regex.compile('^=+[ \t]*$')
12stars = regex.compile('^\*+[ \t]*$')
13blank = regex.compile('^[ \t]*$')
14indented = regex.compile('^\( *\t\| \)[ \t]*[^ \t]')
15
16def process(fi, fo):
17 inverbatim = 0
18 line = '\n'
19 nextline = fi.readline()
20 while nextline:
21 prevline = line
22 line = nextline
23 nextline = fi.readline()
24 fmt = None
25 if dashes.match(nextline) >= 0:
26 fmt = '\\subsection{%s}\n'
27 elif equals.match(nextline) >= 0:
28 fmt = '\\section{%s}\n'
29 elif stars.match(nextline) >= 0:
30 fmt = '\\chapter{%s}\n'
31 if fmt:
32 nextline = '\n'
33 line = fmt % string.strip(line)
34 elif inverbatim:
35 if blank.match(line) >= 0 and \
36 indented.match(nextline) < 0:
37 inverbatim = 0
38 fo.write('\\end{verbatim}\n')
39 else:
40 if indented.match(line) >= 0 and \
41 blank.match(prevline) >= 0:
42 inverbatim = 1
43 fo.write('\\begin{verbatim}\n')
44 if inverbatim:
45 line = string.expandtabs(line, 4)
46 fo.write(line)
47
48#main()
49process(open('ext.tex', 'r'), sys.stdout)