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");
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;
}
#include "global-ctor.hh"
#include "kpath.hh"
-Array<String> failed_files;
-
/*
* Global options that can be overridden through command line.
*/
/*
* Miscellaneous global stuff.
*/
-
-int exit_status_global;
File_path global_path;
/* 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