From 32cc6f6a34620a03fd5e73fec21ce441dd253491 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Sun, 11 Apr 2004 15:12:44 +0000 Subject: [PATCH] * lily/main.cc (main_with_guile): call lilypond-main * scm/lily.scm (lilypond-main): new function: handle multiple files. * lily/input-file-results.cc (LY_DEFINE): throw ly-file-failed exception. * lily/my-lily-parser.cc: remove paper_description function * lily/main.cc: remove global_score_count. * lily/ly-module.cc (ly_make_anonymous_module): don't protect anonymous modules globally. Let's hope they get GCd --- ChangeLog | 9 ++++++ lily/input-file-results.cc | 58 +++++++++++++++++++++----------------- lily/ly-module.cc | 3 +- lily/main.cc | 39 +++++++++++-------------- lily/my-lily-parser.cc | 1 - scm/lily.scm | 27 ++++++++++++++++++ 6 files changed, 85 insertions(+), 52 deletions(-) diff --git a/ChangeLog b/ChangeLog index 135cf3ea30..f6d75da182 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2004-04-11 Han-Wen Nienhuys + * lily/main.cc (main_with_guile): call lilypond-main + + * scm/lily.scm (lilypond-main): new function: handle multiple files. + + * lily/input-file-results.cc (LY_DEFINE): throw ly-file-failed + exception. + + * lily/my-lily-parser.cc: remove paper_description function + * lily/music-output-def.cc (LY_DEFINE): ly:output-description new function. diff --git a/lily/input-file-results.cc b/lily/input-file-results.cc index 5c900200c7..5049a6bcac 100644 --- a/lily/input-file-results.cc +++ b/lily/input-file-results.cc @@ -130,7 +130,7 @@ distill_inname (String str) LY_DEFINE(ly_parse_file, "ly:parse-file", 1,0,0, (SCM name), - "Parse a single @code{.ly} file." + "Parse a single @code{.ly} file. If this fails, then throw @code{ly-file-failed} key. " ) { SCM_ASSERT_TYPE (is_string (name), name, SCM_ARG1, __FUNCTION__, "string"); @@ -161,45 +161,51 @@ LY_DEFINE(ly_parse_file, "ly:parse-file", String in_file = inpath.to_string (); String out_file = outpath.to_string (); + if (init.length () && global_path.find (init).is_empty ()) { - warning (_f ("can't find file: `%s'", init)); + warning (_f ("can't find init file: `%s'", init)); warning (_f ("(search path: `%s')", global_path.to_string ().to_str0 ())); - return SCM_UNSPECIFIED; + exit (2); } if ((in_file != "-") && global_path.find (in_file).is_empty ()) { warning (_f ("can't find file: `%s'", in_file)); - return SCM_UNSPECIFIED; + scm_throw (ly_symbol2scm ("ly-file-failed"), scm_list_1 (scm_makfrom0str (in_file.to_str0 ()))); } + else + { + Sources sources; + sources.set_path (&global_path); - Sources sources; - sources.set_path (&global_path); - - progress_indication (_f ("Now processing `%s'", in_file.to_str0 ())); - progress_indication ("\n"); + progress_indication (_f ("Now processing `%s'", in_file.to_str0 ())); + progress_indication ("\n"); - My_lily_parser parser (&sources); - parser.parse_file (init, in_file, out_file); + My_lily_parser parser (&sources); + parser.parse_file (init, in_file, out_file); - if (parser.error_level_) - { - exit_status_global = 1; - failed_files.push (in_file); - } + #if 0 - // fixme dependencies - if (dependency_global_b) - { - Path p = split_path (output); - p.ext = "dep"; - write_dependency_file (p.to_string (), - target_strings_, - inclusion_names_); - } + // fixme dependencies + if (dependency_global_b) + { + Path p = split_path (output); + p.ext = "dep"; + write_dependency_file (p.to_string (), + target_strings_, + inclusion_names_); + } #endif - + + if (parser.error_level_) + { + /* + TODO: pass renamed input file too. + */ + scm_throw (ly_symbol2scm ("ly-file-failed"), scm_list_1 (scm_makfrom0str (in_file.to_str0 ()))); + } + } return SCM_UNSPECIFIED; } diff --git a/lily/ly-module.cc b/lily/ly-module.cc index d7d72fce5b..1921c9084e 100644 --- a/lily/ly-module.cc +++ b/lily/ly-module.cc @@ -113,11 +113,10 @@ ly_modules_lookup (SCM modules, SCM sym) } -SCM export_function; - void ly_export (SCM module, SCM namelist) { + static SCM export_function; if (!export_function) export_function = scm_permanent_object (scm_c_lookup ("module-export!")); diff --git a/lily/main.cc b/lily/main.cc index c9a60ca970..7431bce28d 100644 --- a/lily/main.cc +++ b/lily/main.cc @@ -34,8 +34,6 @@ #include "global-ctor.hh" #include "kpath.hh" -Array failed_files; - /* * Global options that can be overridden through command line. */ @@ -78,8 +76,6 @@ String init_scheme_code_string = "(begin #t "; /* * Miscellaneous global stuff. */ - -int exit_status_global; File_path global_path; @@ -281,38 +277,35 @@ main_with_guile (void *, int, char **) /* We accept multiple independent music files on the command line to reduce compile time when processing lots of small files. Starting the GUILE engine is very time consuming. */ + + SCM files = SCM_EOL; + SCM *tail = &files; bool first = true; while (char const *arg = option_parser->get_next_arg ()) { -#if 0 - /* Code to debug memory leaks. Cannot call from within .ly - since then we get the protects from the parser state too. */ - scm_gc (); - scm_call_0 (ly_scheme_function ("dump-gc-protects")); -#endif - ly_parse_file (scm_makfrom0str (arg)); - first = false; + *tail = scm_cons (scm_makfrom0str (arg), SCM_EOL); + tail = SCM_CDRLOC(*tail); } delete option_parser; option_parser = 0; - /* No FILE arguments is now a usage error to help newbies. If you + if (files == SCM_EOL) + { + /* No FILE arguments is now a usage error to help newbies. If you want a filter, you're not a newbie and should know to use file argument `-'. */ - if (first) - { usage (); exit (2); } - if (exit_status_global) - { - printf ("Failed files: "); - for (int i = 0; i < failed_files.size (); i++) - printf ("%s ", failed_files[i].to_str0 ()); - printf ("\n"); - } - exit (exit_status_global); + SCM result = scm_call_1 (ly_scheme_function ("lilypond-main"), + files); + + + /* + unreachable. + */ + exit (0); } static void diff --git a/lily/my-lily-parser.cc b/lily/my-lily-parser.cc index 7c5e9b1607..097a941bd7 100644 --- a/lily/my-lily-parser.cc +++ b/lily/my-lily-parser.cc @@ -82,7 +82,6 @@ My_lily_parser::parser_error (String s) { here_input ().error (s); error_level_ = 1; - exit_status_global = 1; } diff --git a/scm/lily.scm b/scm/lily.scm index 0e994112d9..f163d26c71 100644 --- a/scm/lily.scm +++ b/scm/lily.scm @@ -515,3 +515,30 @@ L1 is copied, L2 not. )) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(define-public (lilypond-main files) + "Entry point for Lilypond" + (let* + ((failed '()) + (handler (lambda (key arg) + (set! failed (cons arg failed)))) + ) + + (for-each + (lambda (fn) + (catch 'ly-file-failed + (lambda () (ly:parse-file fn)) + handler)) + + files) + + (if (pair? failed) + (begin + (display (string-append "\n *** Failed files: " (string-join failed) "\n" )) + (exit 1)) + (exit 0)) + + )) + + -- 2.39.2