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