3 # name isn't really appropriate now ...
15 format_names = {'ps.gz': 'Compressed PostScript',
26 sys.stderr.write ("can't open file: %s\n" % f)
30 sys.stderr.write ("gulped empty file: %s\n" % f)
41 def read_latex_header (s):
43 m = re.search(r'\\author{([^}]+)}', s)
45 header.author = m.group (1)
47 m = re.search (r'\\title{([^}]+)}',s )
49 header.title = m.group (1)
51 header.formats = ['ps.gz']
55 def read_bib_header (s):
56 m = re.search ('% *AUTHOR *= *(.*)\n',s)
61 header.author = m.group (1)
63 m = re.search ('% *TITLE *= *(.*)\n',s )
65 header.title = m.group (1)
67 header.formats = ['html']
71 def read_pod_header (s):
72 header = Latex_head ()
74 i = re.search( '[^\n \t]', s)
76 i = re.search( '\n\n', s)
78 i = re.search( '\n\n', s)
81 header.formats = ['html']
84 def read_texinfo_header (s):
85 header = Latex_head ()
87 m = re.search( '@settitle (.*)\n', s)
89 header.title = m.group (1)
90 m = re.search( '@author (.*)\n', s)
92 header.author = m.group (1)
94 header.formats = ['html', 'ps.gz']
98 # should make a 'next_parens '
99 yo_article_re = re.compile ('article(\\([^)]*\\))[ \t\n]*(\\([^)]*\\))')
100 yo_report_re = re.compile ('report(\\([^)]*\\))[\t\n ]*(\\([^)]*\\))')
101 yo_sect_re = re.compile ('sect(\\([^)]*\\))')
102 yo_chapter_re = re.compile ('chapter(\\([^)]*\\))')
104 def read_yodl_header (s):
105 header = Latex_head ()
106 report = yo_report_re.search (s)
111 header.author = report.group (2)
112 header.title = yo_report_re.group (1)
114 article = yo_article_re.search (s)
116 header.author = article.group (2)
117 header.title = article.group (1)
119 chapter = yo_chapter_re.search (s)
121 header.title = chapter.group (1)
123 sect = yo_sect_re.search (s)
125 header.title = sect.group (1)
127 header.formats = ['html']
131 def print_html_head (l,o,h):
134 fn = pre + h.basename
138 t = t + ': '+ h.title
140 l.write ('<li>%s </a>' % t)
143 l.write ('<p>by %s</p>' % h.author)
146 l.write ('(<a href=%s.%s>%s</a>)' % (fn, f, format_names [f]))
150 sys.stdout.write (r"""Usage: ls-latex [OPTIONS]... FILE...
151 Generate html index file for FILE...
154 -h, --help print this help
160 (options, files) = getopt.getopt(sys.argv[1:],
161 'e:h', ['help', 'prefix=', 'title='])
174 elif o == '-h' or o == '--help':
180 l.write (r"""<html><title>%s</title>
183 """ % (title, title))
186 read_header_funcs = {
187 'pod' : read_pod_header,
188 'tex' : read_latex_header,
189 'doc' : read_latex_header,
190 'bib': read_bib_header,
191 'latex' : read_latex_header,
192 'tely' : read_texinfo_header,
193 'texi': read_texinfo_header,
194 'yo': read_yodl_header,
199 m = re.search ('\\.([^.]*)$', x)
204 head = read_header_funcs [m.group(1)] (s)
207 head.basename = re.sub ("\\.[^.]+", '', x)
209 print_html_head (l, pre, head)
211 l.write ('</ul></body></html>')