]> git.donarmstrong.com Git - lilypond.git/commitdiff
(Snippet.output_print_filename): new
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Fri, 6 Feb 2004 13:20:01 +0000 (13:20 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Fri, 6 Feb 2004 13:20:01 +0000 (13:20 +0000)
file, process printfilename option.
(Snippet.__init__): rewrite: do not use global variables h or
index.
(main): really support -I option.
(find_toplevel_snippets): new code.

ChangeLog
input/template/GNUmakefile
scm/music-functions.scm
scripts/lilypond-book.py

index 826844170494676d34a0ea433b52732c062d5ad9..02dab38493b5e9615b2d6481bb01c245740eccb3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,7 @@
        (Snippet.__init__): rewrite: do not use global variables h or
        index.
        (main): really support -I option.
+       (find_toplevel_snippets): new code.
 
        * tex/texinfo.tex: really add file.
        
index 84f81ed45f25d573e3e11171bd8e5dfe413ce02f..5e769a12648dce656ee3aa38b1339a00ee8ee6d4 100644 (file)
@@ -1,6 +1,7 @@
 depth = ../..
 
 STEPMAKE_TEMPLATES=documentation texinfo tex
+LILYPOND_BOOK_FLAGS = --process="lilypond-bin -I $(srcdir)/input/regression -e '(ly:set-option (quote internal-type-checking) \#t)'"
 LOCALSTEPMAKE_TEMPLATES=lilypond ly lysdoc
 EXTRA_DIST_FILES=README
 
index 9dc18d1621f71eb7bb861c8bbd84dd69c5f12e02..91c6bbaaaf11725b13f3d1c10ecee1092c68d8eb 100644 (file)
@@ -501,7 +501,8 @@ Rest can contain a list of beat groupings
 
 
 ;;; splitting chords into voices.
-
+;; todo: spec \context Staff for  <<\\>>
+;;
 (define (voicify-list lst number)
    "Make a list of Musics.
 
index 678894935d06c77ff082d7444ff8fcc9965908fe..61943d67d45400d984515767dd2b1d978bc32751 100644 (file)
@@ -237,7 +237,8 @@ border="0" src="%(base)s.png" alt="[picture of music]">''',
        BEFORE: '',
        AFTER: '',
        VERBATIM: r'''@example
-%(verb)s@end example''',
+%(verb)s@end example
+''',
        
        },
        
@@ -365,9 +366,8 @@ def split_options (option_string):
 
 
 class Snippet:
-       def __init__ (self, type, source, match):
+       def __init__ (self, type, match):
                self.type = type
-               self.source = source
                self.match = match
                self.hash = 0
                self.options = []
@@ -426,7 +426,11 @@ class Snippet:
                        func = Snippet.__dict__ ['output_' + format]
                        return func (self)
                elif self.type == 'include':
-                       return ''
+                       s = self.match.group (0)
+                       f = self.substring ('filename')
+                       nf = os.path.splitext (f)[0] + format2ext[format]
+                       
+                       return re.sub (f, nf, s)
                else:
                        return self.match.group (0)
        
@@ -505,7 +509,7 @@ class Snippet:
        
 
 
-def find_toplevel_snippets (str, types):
+def simple_find_toplevel_snippets (str, types):
        "return: (new string, snippets)" 
        snippets  = []
        for t in types:
@@ -523,6 +527,29 @@ def find_toplevel_snippets (str, types):
                str = regex.sub (notice_snippet, str)
        return (str, snippets)
 
+def find_toplevel_snippets (infile, outfile, types):
+       res = ['(?P<regex%s>%s)' % (t,
+
+                                   re.sub (r"\(\?P<[^>]+>", "(", snippet_res[format][t]))
+              for t in types]
+
+       big_re = re.compile (string.join (res, '|'))
+       str = infile.read ()
+       i = big_re.finditer(str) 
+
+       snips= []
+       last_end = 0
+       for match in i:
+               outfile.write (str[last_end:match.start (0)])
+               last_end = match.end (0)
+               for t in types:
+                       m =re.match (snippet_res[format][t], match.group(0))
+                       if m:
+                               sn = Snippet (t, m)
+                               snips.append (sn)
+                               outfile.write (sn.replacement_text (format))
+                               break
+       return snips            
 
 
 def filter_pipe (input, cmd):
@@ -640,7 +667,6 @@ def do_file (input_filename):
        else:
                ih = open (input_filename)
 
-       source = ih.read ()
        ly.progress ('\n')
 
        ly.progress (_ ("Dissecting..."))
@@ -655,9 +681,6 @@ def do_file (input_filename):
                'include',
                'lilypond', )
        
-       (source, snippets) = find_toplevel_snippets (source, snippet_types)
-       ly.progress ('\n')
-
        output_file = None
        if output_name == '-' or not output_name:
                output_file = sys.stdout
@@ -677,6 +700,9 @@ def do_file (input_filename):
                os.chdir (output_name)
 
                
+       snippets = find_toplevel_snippets (ih, output_file, snippet_types)
+       ly.progress ('\n')
+
 
        global default_ly_options
        textwidth = 0
@@ -703,8 +729,6 @@ def do_file (input_filename):
                ly.progress (_ ("Compiling %s...") % output_filename)
                ly.progress ('\n')
 
-       output_file.write (source)
-
        def process_include (snippet):
                os.chdir (original_dir)
                name = snippet.substring ('filename')
@@ -770,7 +794,8 @@ def main ():
        files = do_options ()
        global process_cmd
        if process_cmd:
-               process_cmd += string.join ([(' -I %s' % p) for p in include_path])
+               process_cmd += string.join ([(' -I %s' % p)
+                                            for p in include_path])
 
        ly.identify (sys.stderr)
        ly.setup_environment ()