]> git.donarmstrong.com Git - lilypond.git/blob - lily/source.cc
9d978d4fae93d9b5e20e8b86fed9f6daa7b331ba
[lilypond.git] / lily / source.cc
1 /*
2   source.cc -- implement Sources
3
4   source file of the LilyPond music typesetter
5
6   (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "source.hh"
10
11 #include "source-file.hh"
12 #include "file-path.hh"
13
14 Sources::Sources ()
15 {
16   path_ = 0;
17   is_binary_ = false;
18 }
19
20 void
21 Sources::set_binary (bool bo)
22 {
23   is_binary_ = bo;
24 }
25
26 void
27 Sources::set_path (File_path *f)
28 {
29   path_ = f;
30 }
31
32 /**
33    open a file
34
35    File_string the file to be opened, name might be changed if it is
36    found in a search path.
37 */
38 Source_file *
39 Sources::get_file (string *file_string) //UGH
40 {
41   if (*file_string != "-" && path_)
42     {
43       string file_string_o = path_->find (*file_string);
44       if ((file_string_o == "") && (*file_string != ""))
45         return 0;
46       *file_string = file_string_o;
47     }
48   Source_file *f = new Source_file (*file_string);
49   add (f);
50   return f;
51 }
52
53 void
54 Sources::add (Source_file *sourcefile)
55 {
56   sourcefiles_.push_back (sourcefile);
57 }
58
59 Sources::~Sources ()
60 {
61   for (vsize i = 0; i < sourcefiles_.size (); i++)
62     {
63       sourcefiles_[i]->unprotect ();
64     }
65 }
66
67 Source_file *
68 Sources::get_sourcefile (char const *str0)
69 {
70   for (vector<Source_file*>::iterator i = sourcefiles_.begin();
71        i != sourcefiles_.end (); i++)
72     {
73       if ((*i)->contains (str0))
74         return *i;
75     }
76
77   return 0;
78 }
79