]> git.donarmstrong.com Git - lilypond.git/blob - scripts/filter-lilypond-book.py
05a1743733fe2dafe937bd7d53c1ec4a57fd7875
[lilypond.git] / scripts / filter-lilypond-book.py
1 #!@PYTHON@
2
3 '''
4 TODO: @\ lilypondfile
5       \input, @include
6       check latex parameters
7       papersizes?
8       
9
10
11 Example usage:
12
13 test:
14      filter-lilypond-book --filter="tr '[a-z]' '[A-Z]'" BOOK
15           
16 convert-ly on book:
17      filter-lilypond-book --filter="convert-ly --no-version --from=1.6.11 -" BOOK
18
19 minimal classic lilypond-book (WIP):
20      filter-lilypond-book --process="lilypond-bin" BOOK.tely
21
22      (([0-9][0-9])*pt) -> staffsize=\2
23      
24 '''
25
26 import string
27 import __main__
28
29 ################################################################
30 # Users of python modules should include this snippet
31 # and customize variables below.
32
33 # We'll suffer this path init stuff as long as we don't install our
34 # python packages in <prefix>/lib/pythonx.y (and don't kludge around
35 # it as we do with teTeX on Red Hat Linux: set some environment var
36 # (PYTHONPATH) in profile)
37
38 # If set, LILYPONDPREFIX must take prevalence
39 # if datadir is not set, we're doing a build and LILYPONDPREFIX
40 import getopt, os, sys
41 datadir = '@local_lilypond_datadir@'
42 if not os.path.isdir (datadir):
43         datadir = '@lilypond_datadir@'
44 if os.environ.has_key ('LILYPONDPREFIX') :
45         datadir = os.environ['LILYPONDPREFIX']
46         while datadir[-1] == os.sep:
47                 datadir= datadir[:-1]
48
49 sys.path.insert (0, os.path.join (datadir, 'python'))
50
51 # Customize these
52 #if __name__ == '__main__':
53
54 import lilylib as ly
55 global _;_=ly._
56 global re;re = ly.re
57
58 # lilylib globals
59 program_version = '@TOPLEVEL_VERSION@'
60 #program_name = 'new-book'
61 program_name = 'filter-lilypond-book'
62 verbose_p = 0
63 pseudo_filter_p = 0
64 original_dir = os.getcwd ()
65
66
67 # help_summary = _ ("Process LilyPond snippets in hybrid html, LaTeX or texinfo document")
68 help_summary = _ ("""Process ly snippets from lilypond-book source.  Example usage:
69
70    filter-lilypond-book --filter="tr '[a-z]' '[A-Z]'" BOOK
71    filter-lilypond-book --filter="convert-ly --no-version --from=1.6.11 -" BOOK
72
73 """)
74 copyright = ('Jan Nieuwenhuizen <janneke@gnu.org>>',
75              'Han-Wen Nienhuys <hanwen@cs.uu.nl>')
76
77 option_definitions = [
78         (_ ("EXT"), 'f', 'format', _ ("use output format EXT (texi [default], texi-html, latex, html)")),
79         (_ ("FILTER"), 'F', 'filter', _ ("pipe snippets through FILTER [convert-ly -n -]")),
80         ('', 'h', 'help', _ ("print this help")),
81         (_ ("COMMAND"), 'P', 'process', _ ("process ly_files using COMMAND FILE...")),
82         (_ ("FILE"), 'o', 'output', _ ("write output to FILE")),
83         ('', 'V', 'verbose', _ ("be verbose")),
84         ('', 'v', 'version', _ ("print version information")),
85         ('', 'w', 'warranty', _ ("show warranty and copyright")),
86         ]
87
88 include_path = [os.getcwd ()]
89
90 lilypond_binary = os.path.join ('@bindir@', 'lilypond-bin')
91
92 # only use installed binary  when we're installed too.
93 if '@bindir@' == ('@' + 'bindir@') or not os.path.exists (lilypond_binary):
94         lilypond_binary = 'lilypond-bin'
95
96
97 use_hash_p = 1
98 format = 0
99 output_name = 0
100 latex_filter_cmd = 'latex "\\nonstopmode \input /dev/stdin"'
101 filter_cmd = 'convert-ly --no-version --from=2.0.0 -'
102 #filter_cmd = 0
103 #process_cmd = 'convert-ly --no-version --from=2.0.0'
104 process_cmd = 0
105 default_ly_options = { }
106
107 LATEX = 'latex'
108 HTML = 'html'
109 TEXINFO = 'texinfo'
110 BEFORE = 'before'
111 OUTPUT = 'output'
112 AFTER = 'after'
113 VERBATIM = 'verbatim'
114 LINEWIDTH = 'linewidth'
115
116 ## lilypond-book heritage.  to be cleaned
117
118 ################################################################
119 # Recognize special sequences in the input 
120
121
122 # Warning: This uses extended regular expressions.  Tread with care.
123 #
124 # legenda
125 #
126 # (?P<name>regex) -- assign result of REGEX to NAME
127 # *? -- match non-greedily.
128 # (?m) -- multiline regex: make ^ and $ match at each line
129 # (?s) -- make the dot match all characters including newline
130 no_match = 'a\ba'
131 re_dict = {
132         HTML: {
133                 'include':  no_match,
134                 'input': no_match,
135                 'header': no_match,
136                 'landscape': no_match,
137                 'verbatim': r'''(?s)(?P<code><pre>\s.*?</pre>\s)''',
138                 'verb': r'''(?P<code><pre>.*?</pre>)''',
139                 'lilypond-file': r'(?m)(?P<match><lilypondfile(?P<options>[^>]+)?>\s*(?P<filename>[^<]+)\s*</lilypondfile>)',
140                 'lilypond' : '(?m)(?P<match><lilypond((?P<options>[^:]*):)(?P<code>.*?)/>)',
141                 'lilypond-block': r'''(?ms)(?P<match><lilypond(?P<options>[^>]+)?>(?P<code>.*?)</lilypond>)''',
142                 'option-sep' : '\s*',
143                 'intertext': r',?\s*intertext=\".*?\"',
144                 'multiline-comment': r"(?sm)\s*(?!@c\s+)(?P<code><!--\s.*?!-->)\s",
145                 'singleline-comment': no_match,
146                 'numcols': no_match,
147                 'multicols': no_match,
148                 'ly2dvi': r'(?m)(?P<match><ly2dvifile(?P<options>[^>]+)?>\s*(?P<filename>[^<]+)\s*</ly2dvifile>)',
149                 },
150
151         LATEX: {
152                 'junkmeinput': r'(?m)^[^%\n]*?(?P<match>\\mbinput{?([^}\t \n}]*))',
153                 'junkmeinclude': r'(?m)^[^%\n]*?(?P<match>\\mbinclude{(?P<filename>[^}]+)})',
154                 'include': r'(?m)^[^%\n]*?(?P<match>\\input{(?P<filename>[^}]+)})',
155                 'option-sep' : ',\s*',
156                 'header': r"\n*\\documentclass\s*(\[.*?\])?",
157                 'verbatim': r"(?s)(?P<code>\\begin\s*{verbatim}.*?\\end{verbatim})",
158                 'verb': r"(?P<code>\\verb(?P<del>.).*?(?P=del))",
159                 'lilypond-file': r'(?m)^[^%\n]*?(?P<match>\\lilypondfile\s*(\[(?P<options>.*?)\])?\s*\{(?P<filename>.+)})',
160                 'lilypond' : r'(?m)^[^%\n]*?(?P<match>\\lilypond\s*(\[(?P<options>.*?)\])?\s*{(?P<code>.*?)})',
161                 'lilypond-block': r"(?sm)^[^%\n]*?(?P<match>\\begin\s*(\[(?P<options>.*?)\])?\s*{lilypond}(?P<code>.*?)\\end{lilypond})",
162                 'def-post-re': r"\\def\\postLilyPondExample",
163                 'def-pre-re': r"\\def\\preLilyPondExample",
164                 'usepackage-graphics': r"\usepackage\s*{graphics}",
165                 'intertext': r',?\s*intertext=\".*?\"',
166                 'multiline-comment': no_match,
167                 'singleline-comment': r"(?m)^.*?(?P<match>(?P<code>^%.*$\n+))",
168                 'numcols': r"(?P<code>\\(?P<num>one|two)column)",
169                 'multicols': r"(?P<code>\\(?P<be>begin|end)\s*{multicols}({(?P<num>\d+)?})?)",
170                 'ly2dvi': no_match,
171
172                 },
173
174         # why do we have distinction between @mbinclude and @include?
175
176         TEXINFO: {
177                 'junkmeinclude':  '(?m)^[^%\n]*?(?P<match>@mbinclude\s+(?P<filename>\S*))',
178                 'include':  '(?m)^[^%\n]*?(?P<match>@include\s+(?P<filename>\S*))',
179                 'input': no_match,
180                 'header': no_match,
181                 'landscape': no_match,
182                 'verbatim': r'''(?s)(?P<code>@example\s.*?@end example\s)''',
183                 'verb': r'''(?P<code>@code{.*?})''',
184                 'lilypond-file': '(?m)^(?P<match>@lilypondfile(\[(?P<options>[^]]*)\])?{(?P<filename>[^}]+)})',
185                 'lilypond' : '(?m)^(?P<match>@lilypond(\[(?P<options>[^]]*)\])?{(?P<code>.*?)})',
186                 'lilypond-block': r'''(?ms)^(?P<match>@lilypond(\[(?P<options>[^]]*)\])?\s(?P<code>.*?)@end lilypond)\s''',
187                 'option-sep' : ',\s*',
188                 'intertext': r',?\s*intertext=\".*?\"',
189                 'multiline-comment': r"(?sm)^\s*(?!@c\s+)(?P<code>@ignore\s.*?@end ignore)\s",
190                 'singleline-comment': r"(?m)^.*?(?P<match>(?P<code>@c.*$\n+))",
191                 'numcols': no_match,
192                 'multicols': no_match,
193                 'ly2dvi': no_match,
194                 }
195         }
196
197 NOTES = 'body'
198 PREAMBLE = 'preamble'
199 PAPER = 'paper'
200
201 ly_options = {
202         NOTES: {
203         #'xrelative': r'''\relative #(ly:make-pitch %(relative)s 0 0)''',
204         'relative': r'''\relative c%(relative_quotes)s''',
205         },
206         PAPER: {
207         'indent' : r'''
208     indent = %(indent)s''',
209         'linewidth' : r'''
210     linewidth = %(linewidth)s''',
211         'noindent' : r'''
212     indent = 0.0\mm''',
213         'notime' : r'''
214     \translator {
215         \StaffContext
216         \remove Time_signature_engraver
217     }''',
218         'raggedright' : r'''
219     indent = 0.0\mm
220     raggedright = ##t''',
221         },
222         PREAMBLE: {
223         'staffsize': r'''
224 #(set-global-staff-size %(staffsize)s)''',
225         },
226         }
227
228 # WIP
229 output = {
230         HTML : {
231         AFTER: '',
232         BEFORE: '',
233         OUTPUT: r'''<src image="%(base)s.png">''',
234         VERBATIM: r'''<pre>
235 %(code)s</pre>''',
236         },
237         
238         LATEX : {
239         AFTER: '',
240         BEFORE: '',
241         OUTPUT: r'''{\parindent 0pt
242 \ifx\preLilyPondExample\preLilyPondExample\fi
243 \def\lilypondbook{}
244 \input %(base)s.tex
245 \ifx\preLilyPondExample\postLilyPondExample\fi}
246 ''',
247         VERBATIM: r'''\begin{verbatim}
248 %(code)s\end{verbatim}
249 ''',
250         },
251         
252         TEXINFO :       {
253         BEFORE: '',
254         AFTER: '',
255         },
256         
257         }
258
259 PREAMBLE_LY = r'''%% Generated by %(program_name)s
260 %% Options: [%(option_string)s]
261 %(preamble_string)s
262 \paper {%(paper_string)s
263 }
264 ''' 
265
266 FRAGMENT_LY = r'''\score{
267     \notes%(notes_string)s{
268         %(code)s    }
269 }'''
270 FULL_LY = '%(code)s'
271
272
273 def compose_ly (code, option_string):
274         options = []
275         # urg
276         for i in default_ly_options.keys ():
277                 options.append (i)
278                 vars ()[i] = default_ly_options[i]
279                         
280         options = options + string.split (option_string, ',')
281         
282         m = re.search (r'''\\score''', code)
283         if not m and (not options \
284                       or not 'nofragment' in options \
285                       or 'fragment' in options):
286                 body = FRAGMENT_LY
287         else:
288                 body = FULL_LY
289
290         # defaults
291         relative = 0
292         staffsize = '16'
293
294         notes_options = []
295         paper_options = []
296         preamble_options = []
297         for i in options:
298                 if string.find (i, '=') > 0:
299                         key, value = string.split (i, '=')
300                         # hmm
301                         vars ()[key] = value
302                 else:
303                         key = i
304
305                 if key in ly_options[NOTES].keys ():
306                         notes_options.append (ly_options[NOTES][key])
307                 elif key in ly_options[PREAMBLE].keys ():
308                         preamble_options.append (ly_options[PREAMBLE][key])
309                 elif key in ly_options[PAPER].keys ():
310                         paper_options.append (ly_options[PAPER][key])
311
312         relative_quotes = (",,,", ",,", ",", "", "'", "''", "'''")[relative-3]
313         program_name = __main__.program_name
314         notes_string = string.join (notes_options, '\n    ') % vars ()
315         paper_string = string.join (paper_options, '\n    ') % vars ()
316         preamble_string = string.join (preamble_options, '\n    ') % vars ()
317         return (PREAMBLE_LY + body) % vars ()
318
319
320 # BARF
321 # use lilypond-bin for latex (.lytex) books,
322 # and lilypond --preview for html, texinfo books?
323 def to_eps (file):
324         cmd = r'latex "\nonstopmode \input %s"' % file
325         # Ugh.  (La)TeX writes progress and error messages on stdout
326         # Redirect to stderr
327         cmd = '(( %s  >&2 ) >&- )' % cmd
328         ly.system (cmd)
329         ly.system ('dvips -Ppdf -u+lilypond.map -E -o %s.eps %s' \
330                    % (file, file))
331
332 ## make source, index statics of Snippet?
333 index = 0
334
335 class Snippet:
336         def __init__ (self, type, index, match):
337                 self.type = type
338                 self.index = index
339                 self.match = match
340                 self.hash = 0
341
342         def start (self, s):
343                 return self.index + self.match.start (s)
344
345         def end (self, s):
346                 return self.index + self.match.end (s)
347
348         def substring (self, source, s):
349                 return source[self.start (s):self.end (s)]
350
351         def ly (self, source):
352                 if self.type == 'lilypond-block' or self.type == 'lilypond':
353                         return compose_ly (self.substring (source, 'code'),
354                                            self.match.group ('options'))
355                 return ''
356         
357         def get_hash (self, source):
358                 if not self.hash:
359                         self.hash = abs (hash (self.substring (source,
360                                                                'code')))
361                 return self.hash
362
363         def basename (self, source):
364                 if use_hash_p:
365                         return 'lily-%d' % self.get_hash (source)
366                 raise 'to be done'
367
368         def write_ly (self, source):
369                 h = open (self.basename (source) + '.ly', 'w')
370                 h.write (self.ly (source))
371                 h.close ()
372
373         def output_html (self, source):
374                 base = self.basename (source)
375                 if VERBATIM in self.match.group ('options'):
376                         code = self.substring (source, 'code')
377                         h.write (output[HTML][VERBATIM] % vars ())
378                 h.write (output[HTML][BEFORE])
379                 h.write (output[HTML][OUTPUT] % vars ())
380                 h.write (output[HTML][AFTER])
381                         
382         def output_latex (self, source):
383                 if VERBATIM in self.match.group ('options'):
384                         code = self.substring (source, 'code')
385                         h.write (output[LATEX][VERBATIM] % vars ())
386                 h.write (output[LATEX][BEFORE])
387                 base = self.basename (source)
388                 # h.write (open (base + '.tex').read ())
389                 # output = open (base + '.tex').read ()
390                 h.write (output[LATEX][OUTPUT] % vars ())
391                 h.write (output[LATEX][AFTER])
392                         
393         def output_texinfo (self, source):
394                 h.write ('\n@tex\n')
395                 self.output_latex (source)
396                 h.write ('\n@end tex\n')
397                 
398                 h.write ('\n@html\n')
399                 self.output_html (source)
400                 h.write ('\n@end html\n')
401                         
402         def outdated_p (self, source):
403                 base = self.basename (source)
404                 if os.path.exists (base + '.ly') \
405                    and os.path.exists (base + '.tex') \
406                    and (not use_hash_p \
407                         or self.ly (source) == open (base + '.ly').read ()):
408                         # TODO: something smart with target formats
409                         # (ps, png) and m/ctimes
410                         return None
411                 return self
412
413 def find_snippets (s, type):
414         re = ly.re.compile (re_dict[format][type])
415         i = 0
416         snippets = []
417         m = re.search (s[i:])
418         while m:
419                 snippets.append (Snippet (type, i, m))
420                 i = i + m.end (0)
421                 m = re.search (s[i:])
422         return snippets
423
424 def filter_pipe (input, cmd):
425         if verbose_p:
426                 ly.progress (_ ("Opening filter `%s\'") % cmd)
427                 
428         stdin, stdout, stderr = os.popen3 (cmd)
429         stdin.write (input)
430         status = stdin.close ()
431
432         if not status:
433                 status = 0
434                 output = stdout.read ()
435                 status = stdout.close ()
436                 error = stderr.read ()
437                 
438         if not status:
439                 status = 0
440         signal = 0x0f & status
441         if status or (not output and error):
442                 exit_status = status >> 8
443                 ly.error (_ ("`%s\' failed (%d)") % (cmd, exit_status))
444                 ly.error (_ ("The error log is as follows:"))
445                 sys.stderr.write (error)
446                 sys.stderr.write (stderr.read ())
447                 ly.exit (status)
448         
449         if verbose_p:
450                 ly.progress ('\n')
451
452         return output
453         
454 def run_filter (s):
455         return filter_pipe (s, filter_cmd)
456
457 def compare_index (a, b):
458         return a.start (0) - b.start (0)
459
460 # apply FUNC to every toplevel block in SNIPPETS, ie, enclosed
461 # snippets are skipped.  return list with all non-empty return values
462 # of FUNC
463
464 # Hmm, do we need enclosed snippets at all?  Maybe use MAP_SNIPPETS
465 # once and use simple filter/map on that resulting toplevel list iso
466 # silly map_snippets/do_snippets.
467 def map_snippets (source, snippets, func):
468         global index
469         index = 0
470         lst = []
471         for i in snippets:
472                 if i.start (0) < index:
473                         continue
474                 # lst.append (func (i, source))
475                 x = func (i, source)
476                 if x:
477                         lst.append (x)
478                 index = i.end (0)
479         return lst
480
481 # apply FUNC to every toplevel block in SNIPPETS, ie, enclosed
482 # snippets are skipped.  return last snippet's index
483 def do_snippets (source, snippets, func):
484         global index
485         index = 0
486         for i in snippets:
487                 if i.start (0) < index:
488                         continue
489                 func (i, source)
490                 # ugr, moved to FUNC
491                 #index = i.end ('code')
492         return index
493
494 def process_snippets (source, snippets, cmd):
495         names = map_snippets (source, snippets, Snippet.basename)
496         if names:
497                 ly.system (string.join ([cmd] + names))
498
499         if format == HTML or format == TEXINFO:
500                 for i in names:
501                         to_eps (i)
502                         ly.make_ps_images (i + '.eps', resolution=110)
503
504 LATEX_DOCUMENT = r'''
505 %(preamble)s
506 \begin{document}
507 \typeout{textwidth=\the\textwidth}
508 \typeout{columnsep=\the\columnsep}
509 \makeatletter\if@twocolumn\typeout{columns=2}\fi\makeatother
510 \end{document}
511 '''
512 #need anything else besides textwidth?
513 def get_latex_textwidth (source):
514         m = re.search (r'''(?P<preabmle>\\begin\s*{document})''', source)
515         preamble = source[:m.start (0)]
516         latex_document = LATEX_DOCUMENT % vars ()
517         parameter_string = filter_pipe (latex_document, latex_filter_cmd)
518
519         columns = 0
520         m = re.search ('columns=([0-9.]*)', parameter_string)
521         if m:
522                 columns = string.atoi (m.group (1))
523
524         columnsep = 0
525         m = re.search ('columnsep=([0-9.]*)pt', parameter_string)
526         if m:
527                 columnsep = string.atof (m.group (1))
528
529         textwidth = 0
530         m = re.search('textwidth=([0-9.]*)pt', parameter_string)
531         if m:
532                 textwidth = string.atof (m.group (1))
533                 if columns:
534                         textwidth = (textwidth - columnsep) / columns
535
536         return textwidth
537
538
539 def do_file (input_filename):
540         global format
541         
542         if not format:
543                 ext2format = {
544                         '.html' : HTML,
545                         '.itely' : TEXINFO,
546                         '.lytex' : LATEX,
547                         '.tely' : TEXINFO,
548                         '.tex': LATEX,
549                         '.texi' : TEXINFO,
550                         '.xml' : HTML,
551                         }
552                                
553                 e = os.path.splitext (input_filename)[1]
554                 if e in ext2format.keys ():
555                         format = ext2format[e]
556                 else:
557                         ly.error (_ ("cannot determine format for: %s" \
558                                      % input_filename))
559
560         global h
561
562         h = sys.stdin
563         if input_filename != '-':
564                 h = open (input_filename)
565         source = h.read ()
566
567         snippet_types = ('verbatim', 'verb', 'multiline-comment',
568                          'lilypond', 'lilypond-block')
569         snippets = []
570         for i in snippet_types:
571                 snippets += find_snippets (source, i)
572
573         snippets.sort (compare_index)
574
575         h = sys.stdout
576         if output_name and output_name != '-':
577                 if not os.path.isdir (output_name):
578                         os.mkdir (output_name, 0777)
579                 if input_filename != '-':
580                         h = open (output_name + '/' + input_filename + '.out',
581                                   'w')
582                 os.chdir (output_name)
583
584         def filter_source (snippet, source):
585                 global index
586                 # Hmm, why is verbatim's group called 'code'; rename to 'verb'?
587                 #if snippet.match.group ('code'):
588                 # urg
589                 if snippet.type == 'lilypond' or snippet.type == 'lilypond-block':
590                         h.write (source[index:snippet.start ('code')])
591                         h.write (run_filter (snippet.substring (source, 'code')))
592                         h.write (source[snippet.end ('code'):snippet.end (0)])
593                 else:
594                         h.write (source[index:snippet.end (0)])
595                 index = snippet.end (0)
596
597         # TODO: output dict?
598
599         snippet_output = eval ("Snippet.output_" + format)
600         def compile_output (snippet, source):
601                 global index
602                 # Hmm, why is verbatim's group called 'code'; rename to 'verb'?
603                 # if snippet.match.group ('code'):
604                 # urg
605                 if snippet.type == 'lilypond' \
606                        or snippet.type == 'lilypond-block':
607                         h.write (source[index:snippet.start (0)])
608                         snippet_output (snippet, source)
609                 index = snippet.end (0)
610
611         global default_ly_options
612         if format == LATEX and LINEWIDTH not in default_ly_options.keys ():
613                 textwidth = get_latex_textwidth (source)
614                 default_ly_options[LINEWIDTH] = '''%.0f\pt''' % textwidth
615
616         global index
617         if filter_cmd:
618                 index = do_snippets (source, snippets, filter_source)
619                 h.write (source[index:])
620         elif process_cmd:
621                 outdated = map_snippets (source, snippets, Snippet.outdated_p)
622                 do_snippets (source, snippets, Snippet.write_ly)
623                 process_snippets (source, outdated, process_cmd)
624                 do_snippets (source, snippets, compile_output)
625                 h.write (source[index:])
626
627         # misusing snippet bit silly?
628         includes = find_snippets (source, 'include')
629         for i in includes:
630                 os.chdir (original_dir)
631                 sys.stderr.write ('DO: ' + sys.argv[0] + ' OPTIONS ' + i.substring (source, 'filename') + '\n')
632
633 def do_options ():
634         global format, output_name
635         global filter_cmd, process_cmd, verbose_p
636         
637         (sh, long) = ly.getopt_args (option_definitions)
638         try:
639                 (options, files) = getopt.getopt (sys.argv[1:], sh, long)
640         except getopt.error, s:
641                 sys.stderr.write ('\n')
642                 ly.error (_ ("getopt says: `%s\'" % s))
643                 sys.stderr.write ('\n')
644                 ly.help ()
645                 ly.exit (2)
646
647         for opt in options:
648                 o = opt[0]
649                 a = opt[1]
650
651                 if 0:
652                         pass
653                 elif o == '--version' or o == '-v':
654                         ly.identify (sys.stdout)
655                         sys.exit (0)
656                 elif o == '--verbose' or o == '-V':
657                         verbose_p = 1
658                 elif o == '--filter' or o == '-F':
659                         filter_cmd = a
660                         process_cmd = 0
661                 elif o == '--format' or o == '-f':
662                         format = a
663                         if a == 'texi-html':
664                                 format = 'texi'
665                 elif o == '--help' or o == '-h':
666                         ly.help ()
667                         sys.exit (0)
668                 elif o == '--output' or o == '-o':
669                         output_name = a
670                 elif o == '--process' or o == '-P':
671                         process_cmd = a
672                         filter_cmd = 0
673                 elif o == '--warranty' or o == '-w':
674                         if 1 or status:
675                                 ly.warranty ()
676                         sys.exit (0)
677         return files
678
679 def main ():
680         files = do_options ()
681         ly.identify (sys.stderr)
682         ly.setup_environment ()
683         if files:
684                 do_file (files[0])
685
686 if __name__ == '__main__':
687         main ()