X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Finput-file-results.cc;h=9c9b29a3fc14125e8bcacc335a534afe5bd02dff;hb=b1c38855c678139f2927f64873a0bc4e36985d09;hp=ef55dee50cdb0719066000af6ceafdda02b3757f;hpb=fd58a98a46a3def26b80a895f1f7b81c92590fc3;p=lilypond.git diff --git a/lily/input-file-results.cc b/lily/input-file-results.cc index ef55dee50c..9c9b29a3fc 100644 --- a/lily/input-file-results.cc +++ b/lily/input-file-results.cc @@ -3,7 +3,7 @@ source file of the GNU LilyPond music typesetter - (c) 1997--2003 Han-Wen Nienhuys + (c) 1997--2004 Han-Wen Nienhuys */ #include "config.h" @@ -34,6 +34,9 @@ bool store_locations_global_b; +/* + TODO: should merge with My_lily_parser. + */ /* no ! suffix since it doesn't modify 1st argument. @@ -88,7 +91,7 @@ write_dependency_file (String fn, out = " "; } String dep = deps[i]; - if (!dependency_prefix_global.empty_b ()) + if (!dependency_prefix_global.is_empty ()) { if (dep.index ('/') < 0) dep = dependency_prefix_global + dep; @@ -144,28 +147,96 @@ Input_file_results::Input_file_results (String init, String in_file, String out_ if (parser.error_level_) { exit_status_global = 1; + failed_files.push (in_file); } do_deps (out_file); } +/* Distill full input file name from command argument. PATH describes + file name with added default extension, ".ly" if none. "-" is + STDIN. */ +Path +distill_inname (String str) +{ + Path p = split_path (str); + if (str.is_empty () || str == "-") + p.base = "-"; + else + { + String orig_ext = p.ext; + char const *extensions[] = {"ly", "", 0}; + for (int i = 0; extensions[i]; i++) + { + p.ext = orig_ext; + if (*extensions[i] && !p.ext.is_empty ()) + p.ext += "."; + p.ext += extensions[i]; + if (!global_path.find (p.to_string ()).is_empty ()) + break; + } + /* Reshuffle extension */ + p = split_path (p.to_string ()); + } + return p; +} +/* ugr. */ void -do_one_file (String init, String in_file, String out_file) +do_one_file (char const *file) { - if (init.length () && global_path.find (init).empty_b ()) + String infile (file); + Path inpath = distill_inname (infile); + + /* By default, use base name of input file for output file name */ + Path outpath = inpath; + if (inpath.to_string () != "-") + outpath.ext = output_format_global; + + /* By default, write output to cwd; do not copy directory part + of input file name */ + outpath.root = ""; + outpath.dir = ""; + + if (!output_name_global.is_empty ()) + outpath = split_path (output_name_global); + + String init; + if (!init_name_global.is_empty ()) + init = init_name_global; + else + init = "init.ly"; + + String in_file = inpath.to_string (); + String out_file = outpath.to_string (); + +#if 0 + /* Code to debug memory leaks. Cannot call from within .ly + since then we get the protects from the parser state too. */ + static SCM proc ; + if (!proc) + proc = scm_c_eval_string ("dump-gc-protects"); + scm_gc (); + scm_call_0 (proc); +#endif + + if (init.length () && global_path.find (init).is_empty ()) { warning (_f ("can't find file: `%s'", init)); warning (_f ("(search path: `%s')", global_path.to_string ().to_str0 ())); return; } - if ((in_file != "-") && global_path.find (in_file).empty_b ()) + if ((in_file != "-") && global_path.find (in_file).is_empty ()) { warning (_f ("can't find file: `%s'", in_file)); return; } + static SCM proc; + if (!proc) + proc = scm_c_eval_string ("dump-gc-protects"); + Input_file_results inp_file (init, in_file, out_file); }