]> git.donarmstrong.com Git - lilypond.git/blob - lily/sources.cc
Web-ja: update introduction
[lilypond.git] / lily / sources.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "sources.hh"
21
22 #include "config.hh"
23 #include "source-file.hh"
24 #include "file-name.hh"
25 #include "file-path.hh"
26
27 Sources::Sources ()
28 {
29   path_ = 0;
30 }
31
32 void
33 Sources::set_path (File_path *f)
34 {
35   path_ = f;
36 }
37
38 /**
39    Open a file. If the name is not absolute, look in CURRENT_DIR first.
40    Afterwards, check the rest of the path_.
41
42    FILE_STRING the name of the file to be opened.
43    CURRENT_DIR a path to a directory, either absolute or relative to the
44      working directory.
45 */
46 Source_file *
47 Sources::get_file (string file_string, string const &current_dir)
48 {
49   if (file_string != "-")
50     {
51       // First, check for a path relative to the directory of the
52       // file currently being parsed.
53       if (current_dir.length ()
54           && file_string.length ()
55           && !File_name (file_string).is_absolute ()
56           && is_file (current_dir + DIRSEP + file_string))
57         file_string = current_dir + DIRSEP + file_string;
58
59       // Otherwise, check the rest of the path.
60       else if (path_)
61         {
62           string file_string_o = path_->find (file_string);
63           if ((file_string_o == "") && (file_string != ""))
64             return 0;
65
66           file_string = file_string_o;
67         }
68     }
69
70   Source_file *f = new Source_file (file_string);
71   add (f);
72   return f;
73 }
74
75 void
76 Sources::add (Source_file *sourcefile)
77 {
78   sourcefiles_.push_back (sourcefile);
79 }
80
81 Sources::~Sources ()
82 {
83   for (vsize i = 0; i < sourcefiles_.size (); i++)
84     {
85       sourcefiles_[i]->unprotect ();
86     }
87 }
88
89 #include "lily-parser.hh"
90 #include "lily-lexer.hh"
91 #include "lily-imports.hh"
92 #include "fluid.hh"
93
94 LY_DEFINE (ly_source_files, "ly:source-files", 0, 1, 0,
95            (SCM parser_smob),
96            "A list of LilyPond files being processed;"
97            "a PARSER may optionally be specified.")
98 {
99
100   if (SCM_UNBNDP (parser_smob))
101     parser_smob = scm_fluid_ref (Lily::f_parser);
102   Lily_parser *parser = LY_ASSERT_SMOB (Lily_parser, parser_smob, 1);
103   Includable_lexer *lex = parser->lexer_;
104
105   SCM lst = SCM_EOL;
106   for (vector<string>::const_iterator
107        i = lex->file_name_strings_.begin();
108        i != lex->file_name_strings_.end(); ++i)
109        {
110          lst = scm_cons (ly_string2scm (*i), lst);
111        }
112   return scm_reverse_x (lst, SCM_EOL);
113 }