From: Han-Wen Nienhuys Date: Tue, 5 Apr 2005 09:27:44 +0000 (+0000) Subject: * lily/lily-parser-scheme.cc: print mapped file name for progress X-Git-Tag: release/2.5.18~7 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=e837c7556a0a39cbb7a6d948ffa7101d22df1f33;hp=65094dec43c85ff8275fc9732ee89e39404a4220;p=lilypond.git * 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. --- diff --git a/ChangeLog b/ChangeLog index 505b86ba05..4b504977fb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2005-04-05 Han-Wen Nienhuys + * 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 diff --git a/Documentation/user/GNUmakefile b/Documentation/user/GNUmakefile index 0209740d6c..7a4e6cb9bf 100644 --- a/Documentation/user/GNUmakefile +++ b/Documentation/user/GNUmakefile @@ -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 index 0000000000..c569f4538d --- /dev/null +++ b/lily/file-name-map.cc @@ -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 + +*/ + +#include + +#include "file-name-map.hh" +#include "lily-guile.hh" + +std::map 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 index 0000000000..6ae14254df --- /dev/null +++ b/lily/include/file-name-map.hh @@ -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 + +*/ + +#ifndef FILE_NAME_MAP_HH +#define FILE_NAME_MAP_HH + +#include "string.hh" + +String map_file_name (String s); + +#endif /* FILE_NAME_MAP_HH */ + diff --git a/lily/key-performer.cc b/lily/key-performer.cc index 693fc792d3..9443d33eff 100644 --- a/lily/key-performer.cc +++ b/lily/key-performer.cc @@ -90,10 +90,11 @@ Key_performer::try_music (Music *ev) { if (Event *kc = dynamic_cast (ev)) { - if (key_ev_) - warning (_ ("FIXME: key change merge")); - - key_ev_ = kc; + if (!key_ev_) + { + key_ev_ = kc; + } + return true; } diff --git a/lily/lily-parser-scheme.cc b/lily/lily-parser-scheme.cc index 4a46421089..030b55ce09 100644 --- a/lily/lily-parser-scheme.cc +++ b/lily/lily-parser-scheme.cc @@ -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); diff --git a/lily/source-file.cc b/lily/source-file.cc index c20fce8fb5..236e24735e 100644 --- a/lily/source-file.cc +++ b/lily/source-file.cc @@ -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 () diff --git a/scripts/lilypond-book.py b/scripts/lilypond-book.py index 6f26c1ff84..3b568991fb 100644 --- a/scripts/lilypond-book.py +++ b/scripts/lilypond-book.py @@ -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])