X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fsources.cc;h=3bedc8cc676a5b9a82519bd14d1772d84651001b;hb=1f8f8075de6d90783386aea28af67755ed57da16;hp=05717455e0c4aa038b5b0fd93ff95838ed2c9a40;hpb=e344ae579fa1d81fc6c6f3049494697872fd39f9;p=lilypond.git diff --git a/lily/sources.cc b/lily/sources.cc index 05717455e0..3bedc8cc67 100644 --- a/lily/sources.cc +++ b/lily/sources.cc @@ -3,12 +3,14 @@ source file of the LilyPond music typesetter - (c) 1997--2008 Han-Wen Nienhuys + (c) 1997--2009 Han-Wen Nienhuys */ #include "sources.hh" +#include "config.hh" #include "source-file.hh" +#include "file-name.hh" #include "file-path.hh" Sources::Sources () @@ -30,22 +32,38 @@ Sources::set_path (File_path *f) } /** - open a file + Open a file. If the name is not absolute, look in CURRENT_DIR first. + Afterwards, check the rest of the path_. - File_string the file to be opened, name might be changed if it is - found in a search path. + FILE_STRING the name of the file to be opened. + CURRENT_DIR a path to a directory, either absolute or relative to the + working directory. */ Source_file * -Sources::get_file (string *file_string) //UGH -{ - if (*file_string != "-" && path_) +Sources::get_file (string file_string, string const& current_dir) +{ + if (file_string != "-") { - string file_string_o = path_->find (*file_string); - if ((file_string_o == "") && (*file_string != "")) - return 0; - *file_string = file_string_o; + // First, check for a path relative to the directory of the + // file currently being parsed. + if (current_dir.length () + && file_string.length () + && !File_name (file_string).is_absolute () + && is_file (current_dir + DIRSEP + file_string)) + file_string = current_dir + DIRSEP + file_string; + + // Otherwise, check the rest of the path. + else if (path_) + { + string file_string_o = path_->find (file_string); + if ((file_string_o == "") && (file_string != "")) + return 0; + + file_string = file_string_o; + } } - Source_file *f = new Source_file (*file_string); + + Source_file *f = new Source_file (file_string); add (f); return f; }