]> git.donarmstrong.com Git - lilypond.git/blob - lib/source.cc
5d384f757e5bbb1246d441833e0e707bf8cd329c
[lilypond.git] / lib / source.cc
1 /*
2   source.cc -- implement Sources
3
4   source file of the LilyPond music typesetter
5
6   (c)  1997--1998 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9
10 #include <assert.h>
11
12 #include "binary-source-file.hh"
13 #include "string.hh"
14 #include "proto.hh"
15 #include "plist.hh"
16 #include "source-file.hh"
17 #include "source.hh"
18 #include "file-path.hh"
19
20 Sources::Sources ()
21 {
22   path_C_= 0;
23   binary_b_ = false;
24 }
25
26 void
27 Sources::set_binary (bool bo)
28 {
29   binary_b_ = bo;
30 }
31
32 void
33 Sources::set_path (File_path *f_C)
34 {
35   path_C_ = f_C;
36 }
37
38 /**
39   open a file
40
41   @param file_str 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_l (String &file_str) //UGH
48 {
49   if (path_C_)
50     {
51       String file_str_o = path_C_->find (file_str); 
52       if ((file_str_o == "") && (file_str != ""))
53         return 0;
54       file_str = file_str_o;
55     }
56   Source_file * f_p= (!binary_b_) ?
57     new Source_file (file_str) : new Binary_source_file (file_str);
58   add (f_p);
59   return f_p;
60 }
61
62 void
63 Sources::add (Source_file* sourcefile_p)
64 {
65   sourcefile_p_list_.bottom ().add (sourcefile_p);
66 }
67
68 /**
69   search the list for file whose map contains pointer #ch_C#
70
71   @return 0 if not found.
72   */
73 Source_file*
74 Sources::sourcefile_l (char const* ch_C)
75 {
76   PCursor<Source_file*> sourcefile_l_pcur (sourcefile_p_list_.top ());
77   for (; sourcefile_l_pcur.ok (); sourcefile_l_pcur++)
78     if (sourcefile_l_pcur->in_b (ch_C)) 
79       return *sourcefile_l_pcur;
80   return 0;
81 }
82