X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Flily-parser-scheme.cc;h=1657438212786785c5a37a102f23fa11a76f394c;hb=2d807340ff4a9b9d8f82b7d99f557ece8534582c;hp=006e5560272fce6ac11b836df4cd8563f8513aaa;hpb=8b9415d65ee46aa7cb27f0fc3cd0d19565669056;p=lilypond.git diff --git a/lily/lily-parser-scheme.cc b/lily/lily-parser-scheme.cc index 006e556027..1657438212 100644 --- a/lily/lily-parser-scheme.cc +++ b/lily/lily-parser-scheme.cc @@ -3,20 +3,22 @@ source file of the GNU LilyPond music typesetter - (c) 2005 Han-Wen Nienhuys + (c) 2005--2006 Han-Wen Nienhuys */ #include +#include "file-name-map.hh" #include "file-name.hh" #include "file-path.hh" -#include "main.hh" -#include "lily-parser.hh" -#include "warn.hh" -#include "source.hh" +#include "international.hh" #include "lily-lexer.hh" +#include "lily-parser.hh" #include "ly-module.hh" -#include "file-name-map.hh" +#include "main.hh" +#include "program-option.hh" +#include "source.hh" +#include "warn.hh" /* Do not append `!' suffix, since 1st argument is not modified. */ LY_DEFINE (ly_set_point_and_click, "ly:set-point-and-click", @@ -37,7 +39,7 @@ LY_DEFINE (ly_parse_file, "ly:parse-file", char const *file = scm_i_string_chars (name); char const *extensions[] = {"ly", "", 0}; - String file_name = global_path.find (file, extensions); + string file_name = global_path.find (file, extensions); /* By default, use base name of input file for output file name, write output to cwd; do not use root and directory parts of input @@ -51,8 +53,8 @@ LY_DEFINE (ly_parse_file, "ly:parse-file", out_file_name.dir_ = ""; /* When running from gui, generate output in .ly source directory. */ - if (output_name_global.is_empty () - && scm_call_0 (ly_lily_module_constant ("running-from-gui?")) == SCM_BOOL_T) + if (output_name_global.empty () + && ly_get_option (ly_symbol2scm ("gui")) == SCM_BOOL_T) { File_name f (file); f.base_ = ""; @@ -60,57 +62,57 @@ LY_DEFINE (ly_parse_file, "ly:parse-file", output_name_global = f.to_string (); } - if (!output_name_global.is_empty ()) + if (!output_name_global.empty ()) { /* Interpret --output=DIR to mean --output=DIR/BASE. */ + string dir; if (is_dir (output_name_global)) { - char cwd[PATH_MAX]; - getcwd (cwd, PATH_MAX); - - if (output_name_global != cwd) - { - global_path.prepend (cwd); - message (_f ("Changing working directory to `%s'", - output_name_global.to_str0 ())); - chdir (output_name_global.to_str0 ()); - - } + dir = output_name_global; output_name_global = ""; } - else + else + dir = dir_name (output_name_global); + if (dir != "" && dir != "." && dir != get_working_directory ()) + { + global_path.prepend (get_working_directory ()); + message (_f ("Changing working directory to `%s'", + dir.c_str ())); + chdir (dir.c_str ()); + } + else out_file_name = File_name (output_name_global); } - String init; - if (!init_name_global.is_empty ()) + string init; + if (!init_name_global.empty ()) init = init_name_global; else init = "init.ly"; - String out_file = out_file_name.to_string (); + string out_file = out_file_name.to_string (); - if (init.length () && global_path.find (init).is_empty ()) + if (init.length () && global_path.find (init).empty ()) { warning (_f ("can't find init file: `%s'", init)); warning (_f ("(search path: `%s')", - global_path.to_string ().to_str0 ())); + global_path.to_string ().c_str ())); exit (2); } - if ((file_name != "-") && global_path.find (file_name).is_empty ()) + if ((file_name != "-") && global_path.find (file_name).empty ()) { warning (_f ("can't find file: `%s'", file_name)); scm_throw (ly_symbol2scm ("ly-file-failed"), - scm_list_1 (scm_makfrom0str (file_name.to_str0 ()))); + scm_list_1 (scm_makfrom0str (file_name.c_str ()))); } else { Sources sources; sources.set_path (&global_path); - String mapped_fn = map_file_name (file_name); - message (_f ("Processing `%s'", mapped_fn.to_str0 ())); + string mapped_fn = map_file_name (file_name); + message (_f ("Processing `%s'", mapped_fn.c_str ())); progress_indication ("\n"); Lily_parser *parser = new Lily_parser (&sources); @@ -118,12 +120,12 @@ LY_DEFINE (ly_parse_file, "ly:parse-file", parser->parse_file (init, file_name, out_file); bool error = parser->error_level_; - scm_gc_unprotect_object (parser->self_scm ()); + parser->unprotect (); parser = 0; if (error) /* TODO: pass renamed input file too. */ scm_throw (ly_symbol2scm ("ly-file-failed"), - scm_list_1 (scm_makfrom0str (file_name.to_str0 ()))); + scm_list_1 (scm_makfrom0str (file_name.c_str ()))); } return SCM_UNSPECIFIED; } @@ -139,7 +141,7 @@ LY_DEFINE (ly_parse_string, "ly:parse-string", sources.set_path (&global_path); Lily_parser *parser = new Lily_parser (&sources); parser->parse_string (ly_scm2string (ly_code)); - scm_gc_unprotect_object (parser->self_scm ()); + parser->unprotect (); parser = 0; return SCM_UNSPECIFIED; @@ -152,10 +154,10 @@ LY_DEFINE (ly_clone_parser, "ly:clone-parser", Lily_parser *parser = unsmob_lily_parser (parser_smob); Lily_parser *clone = new Lily_parser (*parser); - return scm_gc_unprotect_object (clone->self_scm ()); + return clone->unprotect (); } -LY_DEFINE (ly_parser_define, "ly:parser-define", +LY_DEFINE (ly_parser_define, "ly:parser-define!", 3, 0, 0, (SCM parser_smob, SCM symbol, SCM val), "Bind SYMBOL to VAL in PARSER_SMOB's module.") { @@ -216,3 +218,15 @@ LY_DEFINE (ly_parser_set_note_names, "ly:parser-set-note-names", return SCM_UNSPECIFIED; } + +LY_DEFINE (ly_parser_output_name, "ly:parser-output-name", + 1, 0, 0, (SCM parser), + "Return the base name of the output file.") +{ + Lily_parser *p = unsmob_lily_parser (parser); + SCM_ASSERT_TYPE (p, parser, SCM_ARG1, __FUNCTION__, "Lilypond parser"); + + return scm_makfrom0str (p->output_basename_.c_str ()); +} + +