Fixes Issue 1504, allowing feather beam line breaking.
[lilypond/patrick.git] / lily / sources.cc
blob0b33c92f9ed89da3952bfdf78fe9d34c50e41007
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "sources.hh"
22 #include "config.hh"
23 #include "source-file.hh"
24 #include "file-name.hh"
25 #include "file-path.hh"
27 Sources::Sources ()
29 path_ = 0;
33 Sources::Sources (Sources const &)
35 assert (false);
39 void
40 Sources::set_path (File_path *f)
42 path_ = f;
45 /**
46 Open a file. If the name is not absolute, look in CURRENT_DIR first.
47 Afterwards, check the rest of the path_.
49 FILE_STRING the name of the file to be opened.
50 CURRENT_DIR a path to a directory, either absolute or relative to the
51 working directory.
53 Source_file *
54 Sources::get_file (string file_string, string const& current_dir)
56 if (file_string != "-")
58 // First, check for a path relative to the directory of the
59 // file currently being parsed.
60 if (current_dir.length ()
61 && file_string.length ()
62 && !File_name (file_string).is_absolute ()
63 && is_file (current_dir + DIRSEP + file_string))
64 file_string = current_dir + DIRSEP + file_string;
66 // Otherwise, check the rest of the path.
67 else if (path_)
69 string file_string_o = path_->find (file_string);
70 if ((file_string_o == "") && (file_string != ""))
71 return 0;
73 file_string = file_string_o;
77 Source_file *f = new Source_file (file_string);
78 add (f);
79 return f;
82 void
83 Sources::add (Source_file *sourcefile)
85 sourcefiles_.push_back (sourcefile);
88 Sources::~Sources ()
90 for (vsize i = 0; i < sourcefiles_.size (); i++)
92 sourcefiles_[i]->unprotect ();