From: hanwen Date: Tue, 23 Apr 2002 10:23:21 +0000 (+0000) Subject: * scripts/lilypond-book.py: fix by Mats. Try to import pre if available. X-Git-Tag: release/1.5.59~97 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=e02f4257b098cac731a61093a0d92b7c1f475565;p=lilypond.git * scripts/lilypond-book.py: fix by Mats. Try to import pre if available. * scripts/ly2dvi.py (setup_environment): fix by Mats. --- diff --git a/ChangeLog b/ChangeLog index cf7b8cb15d..b06bd38c92 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2002-04-23 Han-Wen Nienhuys + * scripts/lilypond-book.py: fix by Mats. Try to import pre if available. + + * scripts/ly2dvi.py (setup_environment): fix by Mats. + * lily/stem.cc (head_count): Change function name. Change property to #'note-heads i.s.o. #'heads. (position_noteheads): Kern noteheads for invisible stems. diff --git a/Documentation/regression-test.tely b/Documentation/regression-test.tely index ca57437a83..cd1469458f 100644 --- a/Documentation/regression-test.tely +++ b/Documentation/regression-test.tely @@ -23,6 +23,8 @@ documenting bugfixes. @section Notes and rests +@lilypondfile[printfilename]{note-head-chord.ly} + @lilypondfile[printfilename]{note-head-style.ly} @lilypondfile[printfilename]{mensural.ly} diff --git a/scripts/lilypond-book.py b/scripts/lilypond-book.py index 4cab883e7a..7167d637b7 100644 --- a/scripts/lilypond-book.py +++ b/scripts/lilypond-book.py @@ -40,16 +40,29 @@ import os import stat import string -import re + + import getopt import sys import __main__ import operator +# Handle bug in Python 1.6-2.1 +# +# there are recursion limits for some patterns in Python 1.6 til 2.1. +# fix this by importing pre instead. Fix by Mats. + +# todo: should check Python version first. +try: + import pre + re = pre + del pre +except ImportError: + import re program_version = '@TOPLEVEL_VERSION@' if program_version == '@' + 'TOPLEVEL_VERSION' + '@': - program_version = '1.5.18' + program_version = '1.5.53' # if set, LILYPONDPREFIX must take prevalence # if datadir is not set, we're doing a build and LILYPONDPREFIX @@ -411,7 +424,8 @@ output_dict= { \verb+%s+:''', 'output-lilypond': r"""\begin[%s]{lilypond} %s -\end{lilypond}""", +\end{lilypond} +""", 'output-verbatim': "\\begin{verbatim}%s\\end{verbatim}", 'output-default-post': "\\def\postLilypondExample{}\n", 'output-default-pre': "\\def\preLilypondExample{}\n", @@ -420,6 +434,7 @@ output_dict= { 'output-tex': '{\\preLilypondExample \\input %(fn)s.tex \\postLilypondExample\n}', 'pagebreak': r'\pagebreak', }, + 'texi' : {'output-lilypond': """@lilypond[%s] %s @end lilypond @@ -467,24 +482,29 @@ def output_verbatim (body): return get_output ('output-verbatim') % body +#warning: this uses extended regular expressions. Tread with care. + +# legenda (?P name parameter +# *? match non-greedily. + re_dict = { - 'latex': {'input': r'(?m)^[^%\n]*(?P\\mbinput{?([^}\t \n}]*))', - 'include': r'(?m)^[^%\n]*(?P\\mbinclude{(?P[^}]+)})', + 'latex': {'input': r'(?m)^[^%\n]*?(?P\\mbinput{?([^}\t \n}]*))', + 'include': r'(?m)^[^%\n]*?(?P\\mbinclude{(?P[^}]+)})', 'option-sep' : ',\s*', - 'header': r"\\documentclass\s*(\[.*\])?", - 'geometry': r"^(?m)[^%\n]*\\usepackage\s*(\[(?P.*)\])?\s*{geometry}", + 'header': r"\\documentclass\s*(\[.*?\])?", + 'geometry': r"^(?m)[^%\n]*?\\usepackage\s*(\[(?P.*)\])?\s*{geometry}", 'preamble-end': r'(?P\\begin{document})', - 'verbatim': r"(?s)(?P\\begin{verbatim}.*\\end{verbatim})", - 'verb': r"(?P\\verb(?P.).*(?P=del))", - 'lilypond-file': r'(?m)^[^%\n]*(?P\\lilypondfile\s*(\[(?P.*)\])?\s*{(?P[^}]+)})', - 'lilypond' : r'(?m)^[^%\n]*(?P\\lilypond\s*(\[(?P.*)\])?\s*{(?P.*)})', - 'lilypond-block': r"(?sm)^[^%\n]*(?P\\begin\s*(\[(?P.*)\])?\s*{lilypond}(?P.*)\\end{lilypond})", + 'verbatim': r"(?s)(?P\\begin{verbatim}.*?\\end{verbatim})", + 'verb': r"(?P\\verb(?P.).*?(?P=del))", + 'lilypond-file': r'(?m)^[^%\n]*?(?P\\lilypondfile\s*(\[(?P.*?)\])?\s*\{(?P.+)})', + 'lilypond' : r'(?m)^[^%\n]*?(?P\\lilypond\s*(\[(?P.*?)\])?\s*{(?P.*?)})', + 'lilypond-block': r"(?sm)^[^%\n]*?(?P\\begin\s*(\[(?P.*?)\])?\s*{lilypond}(?P.*?)\\end{lilypond})", 'def-post-re': r"\\def\\postLilypondExample", 'def-pre-re': r"\\def\\preLilypondExample", 'usepackage-graphics': r"\usepackage{graphics}", - 'intertext': r',?\s*intertext=\".*\"', + 'intertext': r',?\s*intertext=\".*?\"', 'multiline-comment': no_match, - 'singleline-comment': r"(?m)^.*(?P(?P^%.*$\n+))", + 'singleline-comment': r"(?m)^.*?(?P(?P^%.*$\n+))", 'numcols': r"(?P\\(?Pone|two)column)", }, @@ -493,20 +513,20 @@ re_dict = { 'texi': { - 'include': '(?m)^[^%\n]*(?P@mbinclude[ \n\t]+(?P[^\t \n]*))', + 'include': '(?m)^[^%\n]*?(?P@mbinclude[ \n\t]+(?P[^\t \n]*))', 'input': no_match, 'header': no_match, 'preamble-end': no_match, 'landscape': no_match, - 'verbatim': r"""(?s)(?P@example\s.*@end example\s)""", - 'verb': r"""(?P@code{.*})""", - 'lilypond-file': r"""(?m)^(?P@lilypondfile(\[(?P[^]]*)\])?{(?P[^}]+)})""", - 'lilypond' : r"""(?m)^(?P@lilypond(\[(?P[^]]*)\])?{(?P.*)})""", - 'lilypond-block': r"""(?ms)^(?P@lilypond(\[(?P[^]]*)\])?\s(?P.*)@end lilypond)\s""", + 'verbatim': r"""(?s)(?P@example\s.*?@end example\s)""", + 'verb': r"""(?P@code{.*?})""", + 'lilypond-file': '(?m)^(?P@lilypondfile(\[(?P[^]]*)\])?{(?P[^}]+)})', + 'lilypond' : '(?m)^(?P@lilypond(\[(?P[^]]*)\])?{(?P.*?)})', + 'lilypond-block': r"""(?ms)^(?P@lilypond(\[(?P[^]]*)\])?\s(?P.*?)@end lilypond)\s""", 'option-sep' : ',\s*', - 'intertext': r',?\s*intertext=\".*\"', - 'multiline-comment': r"(?sm)^\s*(?!@c\s+)(?P@ignore\s.*@end ignore)\s", - 'singleline-comment': r"(?m)^.*(?P(?P@c.*$\n+))", + 'intertext': r',?\s*intertext=\".*?\"', + 'multiline-comment': r"(?sm)^\s*(?!@c\s+)(?P@ignore\s.*?@end ignore)\s", + 'singleline-comment': r"(?m)^.*?(?P(?P@c.*$\n+))", 'numcols': no_match, } } @@ -637,8 +657,8 @@ def compose_full_body (body, opts): def parse_options_string(s): d = {} - r1 = re.compile("((\w+)={(.*)})((,\s*)|$)") - r2 = re.compile("((\w+)=(.*))((,\s*)|$)") + r1 = re.compile("((\w+)={(.*?)})((,\s*)|$)") + r2 = re.compile("((\w+)=(.*?))((,\s*)|$)") r3 = re.compile("(\w+?)((,\s*)|$)") while s: m = r1.match(s) @@ -676,7 +696,7 @@ def scan_latex_preamble(chunks): for o in options: if o == 'landscape': paperguru.m_landscape = 1 - m = re.match("(.*)paper", o) + m = re.match("(.*?)paper", o) if m: paperguru.m_papersize = m.group() else: @@ -836,7 +856,6 @@ def chop_chunks(chunks, re_name, func, use_match=0): if c[0] == 'input': str = c[1] while str: -# print re_name m = get_re (re_name).search (str) if m == None: newchunks.append (('input', str)) @@ -917,7 +936,7 @@ def schedule_lilypond_block (chunk): file_body = compose_full_body (body, opts) basename = 'lily-' + `abs(hash (file_body))` for o in opts: - m = re.search ('filename="(.*)"', o) + m = re.search ('filename="(.*?)"', o) if m: basename = m.group (1) if not taken_file_names.has_key(basename): @@ -964,7 +983,7 @@ def schedule_lilypond_block (chunk): newbody = output_verbatim (body) for o in opts: - m = re.search ('intertext="(.*)"', o) + m = re.search ('intertext="(.*?)"', o) if m: newbody = newbody + m.group (1) + "\n\n" if format == 'latex': @@ -1261,7 +1280,7 @@ def fix_epswidth (chunks): return '%fpt' % (dims[0] *lmag) - body = re.sub (r"""\\lilypondepswidth{(.*)}""", replace_eps_dim, c[1]) + body = re.sub (r"""\\lilypondepswidth{(.*?)}""", replace_eps_dim, c[1]) newchunks.append(('lilypond', body, c[2], c[3], c[4])) return newchunks diff --git a/scripts/ly2dvi.py b/scripts/ly2dvi.py index 2f36d98200..bb3206df75 100644 --- a/scripts/ly2dvi.py +++ b/scripts/ly2dvi.py @@ -372,7 +372,9 @@ non_path_environment = { def setup_environment (): # $TEXMF is special, previous value is already taken care of - del os.environ['TEXMF'] + if os.environ.has_key ('TEXM'): + del os.environ['TEXMF'] + for key in environment.keys (): val = environment[key]