Use scalar instead of embedded_scm for context mod overrides.
[lilypond/mpolesky.git] / lily / sources.cc
blob3bedc8cc676a5b9a82519bd14d1772d84651001b
1 /*
2 source.cc -- implement Sources
4 source file of the LilyPond music typesetter
6 (c) 1997--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "sources.hh"
11 #include "config.hh"
12 #include "source-file.hh"
13 #include "file-name.hh"
14 #include "file-path.hh"
16 Sources::Sources ()
18 path_ = 0;
22 Sources::Sources (Sources const &)
24 assert (false);
28 void
29 Sources::set_path (File_path *f)
31 path_ = f;
34 /**
35 Open a file. If the name is not absolute, look in CURRENT_DIR first.
36 Afterwards, check the rest of the path_.
38 FILE_STRING the name of the file to be opened.
39 CURRENT_DIR a path to a directory, either absolute or relative to the
40 working directory.
42 Source_file *
43 Sources::get_file (string file_string, string const& current_dir)
45 if (file_string != "-")
47 // First, check for a path relative to the directory of the
48 // file currently being parsed.
49 if (current_dir.length ()
50 && file_string.length ()
51 && !File_name (file_string).is_absolute ()
52 && is_file (current_dir + DIRSEP + file_string))
53 file_string = current_dir + DIRSEP + file_string;
55 // Otherwise, check the rest of the path.
56 else if (path_)
58 string file_string_o = path_->find (file_string);
59 if ((file_string_o == "") && (file_string != ""))
60 return 0;
62 file_string = file_string_o;
66 Source_file *f = new Source_file (file_string);
67 add (f);
68 return f;
71 void
72 Sources::add (Source_file *sourcefile)
74 sourcefiles_.push_back (sourcefile);
77 Sources::~Sources ()
79 for (vsize i = 0; i < sourcefiles_.size (); i++)
81 sourcefiles_[i]->unprotect ();