2 source.cc -- implement Sources
4 source file of the LilyPond music typesetter
6 (c) 1997--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
12 #include "source-file.hh"
13 #include "file-name.hh"
14 #include "file-path.hh"
22 Sources::Sources (Sources
const &)
29 Sources::set_path (File_path
*f
)
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
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.
58 string file_string_o
= path_
->find (file_string
);
59 if ((file_string_o
== "") && (file_string
!= ""))
62 file_string
= file_string_o
;
66 Source_file
*f
= new Source_file (file_string
);
72 Sources::add (Source_file
*sourcefile
)
74 sourcefiles_
.push_back (sourcefile
);
79 for (vsize i
= 0; i
< sourcefiles_
.size (); i
++)
81 sourcefiles_
[i
]->unprotect ();