]> git.donarmstrong.com Git - lilypond.git/commitdiff
* lily/lily-parser-scheme.cc: print mapped file name for progress
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Tue, 5 Apr 2005 09:27:44 +0000 (09:27 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Tue, 5 Apr 2005 09:27:44 +0000 (09:27 +0000)
* scripts/lilypond-book.py (find_linestarts): new function.
(find_toplevel_snippets): keep track of line numbers.

* lily/key-performer.cc (try_music): remove FIXME warning, gobble
all key changes.

ChangeLog
Documentation/user/GNUmakefile
lily/file-name-map.cc [new file with mode: 0644]
lily/include/file-name-map.hh [new file with mode: 0644]
lily/key-performer.cc
lily/lily-parser-scheme.cc
lily/source-file.cc
scripts/lilypond-book.py

index 505b86ba058e3ab89c30aff1ed207e12c86245b6..4b504977fb481d3ae86b0f160696d4c62a1ccb14 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2005-04-05  Han-Wen Nienhuys  <hanwen@xs4all.nl>
 
+       * lily/lily-parser-scheme.cc:  print mapped file name for progress
+
+       * scripts/lilypond-book.py (find_linestarts): new function.
+       (find_toplevel_snippets): keep track of line numbers.
+
+       * lily/key-performer.cc (try_music): remove FIXME warning, gobble
+       all key changes.
+
        * ly/declarations-init.ly (partCombineListener): use
        ignoreBarChecks. Fixes: warn-partcombine-barcheck.ly
 
index 0209740d6c55e6f645e894139f56750b475b2cae..7a4e6cb9bfbbce8107ba345b0eee38181434de59 100644 (file)
@@ -36,6 +36,11 @@ ps: $(PS_FILES)
 
 info: $(INFO_FILES)
 
+pathsettings:
+       @echo export PATH=$(PATH)
+       @echo export LILYPONDPREFIX=$(LILYPONDPREFIX)
+       @echo export PYTHONPATH=$(PYTHONPATH)
+
 xml: $(outdir)/lilypond/lilypond.xml $(outdir)/lilypond-internals/lilypond-internals.xml
 
 # There are two modes for info: with and without images.
diff --git a/lily/file-name-map.cc b/lily/file-name-map.cc
new file mode 100644 (file)
index 0000000..c569f45
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+  file-name-map.cc --  implement map_file_name()
+
+  source file of the GNU LilyPond music typesetter
+
+  (c) 2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
+
+*/
+
+#include <map>
+
+#include "file-name-map.hh"
+#include "lily-guile.hh"
+
+std::map<String, String> file_name_map_global;
+
+String
+map_file_name (String s)
+{
+  if  (file_name_map_global.find (s) != file_name_map_global.end ())
+    {
+      s = file_name_map_global[s];
+    }
+  return s;
+}
+
+LY_DEFINE (ly_add_file_name_alist, "ly:add-file-name-alist",
+          1, 0, 0, (SCM alist),
+          "Add mappings for error messages from specified alist")
+{
+  for (SCM s = alist; scm_is_pair (s); s = scm_cdr (s))
+    {
+      SCM key = scm_caar (s);
+      SCM val = scm_cdar (s);
+
+      file_name_map_global[ly_scm2string (key)] = ly_scm2string (val);
+    }
+  return SCM_UNSPECIFIED;
+}
+
diff --git a/lily/include/file-name-map.hh b/lily/include/file-name-map.hh
new file mode 100644 (file)
index 0000000..6ae1425
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+  file-name-map.hh -- declare map_file_name()
+
+  source file of the GNU LilyPond music typesetter
+
+  (c) 2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
+
+*/
+
+#ifndef FILE_NAME_MAP_HH
+#define FILE_NAME_MAP_HH
+
+#include "string.hh"
+
+String map_file_name (String s);
+
+#endif /* FILE_NAME_MAP_HH */
+
index 693fc792d36b883875ea76106a3fc305917e63b4..9443d33eff0cf2d580cd36a7d413a9bd6c227a63 100644 (file)
@@ -90,10 +90,11 @@ Key_performer::try_music (Music *ev)
 {
   if (Event *kc = dynamic_cast<Event *> (ev))
     {
-      if (key_ev_)
-       warning (_ ("FIXME: key change merge"));
-
-      key_ev_ = kc;
+      if (!key_ev_)
+       {
+         key_ev_ = kc;
+       }
+      
       return true;
     }
 
index 4a46421089164013065170f7fceca1a84678b787..030b55ce091aeea01eb098c669272dd8e9fed995 100644 (file)
@@ -19,6 +19,7 @@
 #include "output-def.hh"
 #include "book.hh"
 #include "paper-book.hh"
+#include "file-name-map.hh"
 
 /* Do not append `!' suffix, since 1st argument is not modified. */
 LY_DEFINE (ly_set_point_and_click, "ly:set-point-and-click",
@@ -82,7 +83,8 @@ LY_DEFINE (ly_parse_file, "ly:parse-file",
       Sources sources;
       sources.set_path (&global_path);
 
-      progress_indication (_f ("Processing `%s'", file_name.to_str0 ()));
+      String mapped_fn = map_file_name (file_name);
+      progress_indication (_f ("Processing `%s'", mapped_fn.to_str0 ()));
       progress_indication ("\n");
 
       Lily_parser *parser = new Lily_parser (&sources);
index c20fce8fb50a7e9db63843f40465d0d03a13f083..236e24735e78cb4b5e19d396fb9821b11f78a4c9 100644 (file)
@@ -20,6 +20,7 @@
 #endif
 
 #include "warn.hh"
+#include "file-name-map.hh"
 
 void
 Source_file::load_stdin ()
@@ -142,7 +143,7 @@ Source_file::file_line_column_string (char const *context_str0) const
 String
 Source_file::name_string () const
 {
-  return name_;
+  return map_file_name (name_);
 }
 
 Source_file::~Source_file ()
index 6f26c1ff841038221dc8266246f863ca69d79b74..3b568991fb4cbd631775b608b31ee8510e13db8f 100644 (file)
@@ -800,21 +800,23 @@ class Chunk:
                return 0
 
 class Substring (Chunk):
-       def __init__ (self, source, start, end):
+       def __init__ (self, source, start, end, line_number):
                self.source = source
                self.start = start
                self.end = end
+               self.line_number = line_number
 
        def replacement_text (self):
                return self.source[self.start:self.end]
 
 class Snippet (Chunk):
-       def __init__ (self, type, match, format):
+       def __init__ (self, type, match, format, line_number):
                self.type = type
                self.match = match
                self.hash = 0
                self.options = []
                self.format = format
+               self.line_number = line_number
 
        def replacement_text (self):
                return self.match.group ('match')
@@ -837,8 +839,8 @@ class Include_snippet (Snippet):
                return re.sub (f, self.processed_filename (), s)
 
 class Lilypond_snippet (Snippet):
-       def __init__ (self, type, match, format):
-               Snippet.__init__ (self, type, match, format)
+       def __init__ (self, type, match, format, line_number):
+               Snippet.__init__ (self, type, match, format, line_number)
                os = match.group ('options')
                if os:
                        self.options = split_options (os)
@@ -1033,6 +1035,22 @@ snippet_type_to_class = {
        'include': Include_snippet,
 }
 
+def find_linestarts (s):
+       nls = [0]
+       start = 0
+       end = len (s)
+       while 1:
+               i = s.find ('\n', start)
+               if i < 0:
+                       break
+
+               i = i + 1 
+               nls.append (i)
+               start = i
+
+       nls.append (len (s))
+       return nls
+
 def find_toplevel_snippets (s, types):
        res = {}
        for i in types:
@@ -1047,6 +1065,8 @@ def find_toplevel_snippets (s, types):
        map (lambda x, f = found: f.setdefault (x, None),
             types)
 
+       line_starts = find_linestarts (s)
+       line_start_idx = 0
        # We want to search for multiple regexes, without searching
        # the string multiple times for one regex.
        # Hence, we use earlier results to limit the string portion
@@ -1067,7 +1087,13 @@ def find_toplevel_snippets (s, types):
                                cl = Snippet
                                if snippet_type_to_class.has_key (type):
                                        cl = snippet_type_to_class[type]
-                               snip = cl (type, m, format)
+
+                               line_number = line_start_idx
+                               while (line_starts[line_number] < index):
+                                       line_number += 1
+
+                               line_number ++
+                               snip = cl (type, m, format, line_number)
                                start = index + m.start ('match')
                                found[type] = (start, snip)
 
@@ -1089,11 +1115,14 @@ def find_toplevel_snippets (s, types):
                                endex = found[first][0]
 
                if not first:
-                       snippets.append (Substring (s, index, len (s)))
+                       snippets.append (Substring (s, index, len (s), line_start_idx))
                        break
 
+               while (start > line_starts[line_start_idx+1]):
+                       line_start_idx += 1
+               
                (start, snip) = found[first]
-               snippets.append (Substring (s, index, start))
+               snippets.append (Substring (s, index, start, line_start_idx + 1))
                snippets.append (snip)
                found[first] = None
                index = start + len (snip.match.group ('match'))
@@ -1163,12 +1192,12 @@ def process_snippets (cmd, ly_snippets, texstr_snippets, png_snippets):
        # it is too generic for lilypond-book.
        if texstr_names and re.search ('^[0-9A-Za-z/]*lilypond', cmd):
 
-               my_system (string.join ([cmd + ' --backend texstr ' ] + texstr_names))
+               my_system (string.join ([cmd,'--backend texstr', 'snippet-map.ly'] + texstr_names))
                for l in texstr_names:
                        my_system ('latex %s.texstr' % l)
 
        if ly_names:
-               my_system (string.join ([cmd] + ly_names))
+               my_system (string.join ([cmd, 'snippet-map.ly'] + ly_names))
 
 LATEX_DOCUMENT = r'''
 %(preamble)s
@@ -1227,7 +1256,22 @@ format2ext = {
 class Compile_error:
        pass
 
-def do_process_cmd (chunks):
+def write_file_map (lys, name):
+       snippet_map = open ('snippet-map.ly', 'w')
+       snippet_map.write ("\n#(ly:add-file-name-alist '(")
+       for ly in lys:
+               snippet_map.write ('("%s" . "%s:%d (%s.ly)")\n' % (ly.basename(),
+                                          name,
+                                          ly.line_number,
+                                          ly.basename()))
+
+       snippet_map.write ('))\n')
+
+def do_process_cmd (chunks, input_name):
+       all_lys = filter(lambda x: is_derived_class (x.__class__, Lilypond_snippet),
+                        chunks)
+       
+       write_file_map (all_lys, input_name)
        ly_outdated = \
          filter (lambda x: is_derived_class (x.__class__,
                                              Lilypond_snippet)
@@ -1361,7 +1405,7 @@ def do_file (input_filename):
                                                 for c in chunks])
 
                elif process_cmd:
-                       do_process_cmd (chunks)
+                       do_process_cmd (chunks, input_fullname)
                        ly.progress (_ ("Compiling %s...") % output_filename)
                        output_file.writelines ([s.replacement_text () \
                                                 for s in chunks])