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