]> git.donarmstrong.com Git - lilypond.git/blob - lily/source.cc
2003 -> 2004
[lilypond.git] / lily / source.cc
1 /*
2   source.cc -- implement Sources
3
4   source file of the LilyPond music typesetter
5
6   (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9
10 #include <assert.h>
11
12 #include "killing-cons.tcc"
13 #include "string.hh"
14 #include "flower-proto.hh"
15 #include "source-file.hh"
16 #include "source.hh"
17 #include "file-path.hh"
18
19 Sources::Sources ()
20 {
21   sourcefile_list_ = 0;
22   path_C_= 0;
23   is_binary_ = false;
24 }
25
26 void
27 Sources::set_binary (bool bo)
28 {
29   is_binary_ = bo;
30 }
31
32 void
33 Sources::set_path (File_path *f)
34 {
35   path_C_ = f;
36 }
37
38 /**
39   open a file
40
41   @param file_string the file to be opened, name might be changed if it
42   is found in a search path. UGH!
43
44   @return 0 if no file found
45   */
46 Source_file*
47 Sources::get_file (String &file_string) //UGH
48 {
49   if ((file_string != "-") && path_C_)
50     {
51       String file_string_o = path_C_->find (file_string); 
52       if ((file_string_o == "") && (file_string != ""))
53         return 0;
54       file_string = file_string_o;
55     }
56   Source_file * f = new Source_file (file_string) ;
57   add (f);
58   return f;
59 }
60
61 void
62 Sources::add (Source_file* sourcefile)
63 {
64   sourcefile_list_ = new Killing_cons<Source_file> (sourcefile, sourcefile_list_);
65 }
66
67 Sources::~Sources ()
68 {
69   delete sourcefile_list_;
70 }
71 /**
72   search the list for file whose map contains pointer #str0#
73
74   @return 0 if not found.
75   */
76 Source_file*
77 Sources::get_sourcefile (char const* str0)
78 {
79
80   for (Cons<Source_file> *i = sourcefile_list_; i; i = i->next_)
81     if (i->car_->in_b (str0))   
82       return i->car_;
83   return 0;
84 }
85