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)
90 header.title = m.group (1)
91 m = re.search( '@author (.*)\n', s)
93 header.author = m.group (1)
95 header.formats = ['html', 'ps.gz']
99 # should make a 'next_parens '
100 yo_article_re = re.compile ('article(\\([^)]*\\))[ \t\n]*(\\([^)]*\\))')
101 yo_report_re = re.compile ('report(\\([^)]*\\))[\t\n ]*(\\([^)]*\\))')
102 yo_sect_re = re.compile ('sect(\\([^)]*\\))')
103 yo_chapter_re = re.compile ('chapter(\\([^)]*\\))')
105 def read_yodl_header (s):
106 header = Latex_head ()
107 report = yo_report_re.search (s)
112 header.author = report.group (2)
113 header.title = yo_report_re.group (1)
115 article = yo_article_re.search (s)
117 header.author = article.group (2)
118 header.title = article.group (1)
120 chapter = yo_chapter_re.search (s)
122 header.title = chapter.group (1)
124 sect = yo_sect_re.search (s)
126 header.title = sect.group (1)
128 header.formats = ['html']
132 def print_html_head (l,o,h):
135 fn = pre + h.basename
139 t = t + ': '+ h.title
141 l.write ('<li>%s </a>' % t)
144 l.write ('<p>by %s</p>' % h.author)
147 l.write ('(<a href=%s.%s>%s</a>)' % (fn, f, format_names [f]))
151 sys.stdout.write (r"""Usage: ls-latex [OPTION]... FILE...
152 Generate html index file for FILE...
155 -h, --help print this help
161 (options, files) = getopt.getopt(sys.argv[1:],
162 'e:h', ['help', 'prefix=', 'title='])
175 elif o == '-h' or o == '--help':
181 l.write (r"""<html><title>%s</title>
184 """ % (title, title))
187 read_header_funcs = {
188 'pod' : read_pod_header,
189 'tex' : read_latex_header,
190 'doc' : read_latex_header,
191 'bib': read_bib_header,
192 'latex' : read_latex_header,
193 'tely' : read_texinfo_header,
194 'texi': read_texinfo_header,
195 'yo': read_yodl_header,
200 m = re.search ('\\.([^.]*)$', x)
205 head = read_header_funcs [m.group(1)] (s)
208 head.basename = re.sub ("\\.[^.]+", '', x)
210 print_html_head (l, pre, head)
212 l.write ('</ul></body></html>')