]> git.donarmstrong.com Git - lilypond.git/blob - lib/source.cc
release: 0.0.44
[lilypond.git] / lib / source.cc
1 /*
2   source.cc -- implement Source
3
4   source file of the LilyPond music typesetter
5
6   (c) 1997 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
19 void
20 Sources::set_path(File_path *f_C)
21 {
22     path_C_ = f_C;
23 }
24
25 /**
26   open a file
27
28   @param file_str the file to be opened, name might be changed if it
29   is found in a search path.
30
31   @return 0 if no file found
32   */
33 Source_file*
34 Sources::get_file_l(String &file_str )
35 {
36     if (path_C_){
37         file_str = path_C_->find(file_str); 
38         if (file_str== "")
39             return 0;
40     }
41     Source_file * f_p= (!binary_b_) ?
42         new Source_file(file_str) : new Binary_source_file(file_str);
43     add(f_p);
44     return f_p;
45 }
46
47 Sources::Sources()
48 {
49     path_C_= 0;
50     binary_b_ = false;
51 }
52
53 void
54 Sources::add( Source_file* sourcefile_p )
55 {
56     sourcefile_p_iplist_.bottom().add( sourcefile_p );
57 }
58
59 /**
60   search the list for file whose map contains pointer #ch_C#
61
62   @return 0 if not found.
63   */
64 Source_file*
65 Sources::sourcefile_l( char const* ch_C )
66 {
67     PCursor<Source_file*> sourcefile_l_pcur( sourcefile_p_iplist_.top() );
68     for ( ; sourcefile_l_pcur.ok(); sourcefile_l_pcur++ )
69         if ( sourcefile_l_pcur->in_b( ch_C ) )  
70             return *sourcefile_l_pcur;
71     return 0;
72 }