#include "config.hh"
+#include "file-name.hh"
#include "file-path.hh"
#include "international.hh"
#include "main.hh"
(yy_buffer_stack != 0 ? yy_buffer_stack[yy_buffer_stack_top] : 0)
#endif
+extern bool relative_includes;
+
Includable_lexer::Includable_lexer ()
{
#if HAVE_FLEXLEXER_YY_CURRENT_BUFFER
void
Includable_lexer::new_input (string name, Sources *sources)
{
- Source_file *file = sources->get_file (&name);
+ string current_dir = dir_name (main_input_name_);
+ if (relative_includes)
+ current_dir = include_stack_.size () ? dir_name (include_stack_.back ()->name_string ()) : "";
+
+ Source_file *file = sources->get_file (name, current_dir);
if (!file)
{
string msg = _f ("cannot find file: `%s'", name);
msg += "\n";
msg += _f ("(search path: `%s')",
- sources->path_->to_string ().c_str ());
+ (current_dir.length () ? (current_dir + PATHSEP) : "") + sources->path_->to_string ().c_str ());
LexerError (msg.c_str ());
return;
}
state_stack_.push_back (yy_current_buffer);
if (be_verbose_global)
- progress_indication (string ("[") + name);
+ progress_indication (string ("[") + file->name_string ());
include_stack_.push_back (file);
Includable_lexer ();
~Includable_lexer ();
+ string main_input_name_;
/// store dependencies for Makefile stuff.
vector<string> file_name_strings_;
int hidden_state_;
public:
vector<int> extra_token_types_;
- string main_input_name_;
void *lexval;
Input *lexloc;
bool is_main_input_;
Sources ();
~Sources ();
- Source_file *get_file (string *file_name);
- Source_file *get_sourcefile (char const *);
+ Source_file *get_file (string file_name, string const& currentpath);
void add (Source_file *sourcefile);
void set_path (File_path *);
file name. */
File_name out_file_name (file_name);
- global_path.append (out_file_name.dir_);
-
out_file_name.ext_ = "";
out_file_name.root_ = "";
if (ly_get_option (ly_symbol2scm ("gui")) != SCM_BOOL_T
bool debug_property_callbacks;
bool debug_page_breaking_scoring;
+bool relative_includes;
+
/*
Backwards compatibility.
*/
/* ignore input value. */
val = ly_string2scm (lilypond_datadir);
}
+ else if (var == ly_symbol2scm ("relative-includes"))
+ {
+ relative_includes = to_boolean (val);
+ val = scm_from_bool (to_boolean (val));
+ }
scm_hashq_set_x (option_hash, var, val);
#include "sources.hh"
+#include "config.hh"
#include "source-file.hh"
+#include "file-name.hh"
#include "file-path.hh"
Sources::Sources ()
}
/**
- open a file
+ Open a file. If the name is not absolute, look in CURRENT_DIR first.
+ Afterwards, check the rest of the path_.
- File_string the file to be opened, name might be changed if it is
- found in a search path.
+ FILE_STRING the name of the file to be opened.
+ CURRENT_DIR a path to a directory, either absolute or relative to the
+ working directory.
*/
Source_file *
-Sources::get_file (string *file_string) //UGH
-{
- if (*file_string != "-" && path_)
+Sources::get_file (string file_string, string const& current_dir)
+{
+ if (file_string != "-")
{
- string file_string_o = path_->find (*file_string);
- if ((file_string_o == "") && (*file_string != ""))
- return 0;
- *file_string = file_string_o;
+ // First, check for a path relative to the directory of the
+ // file currently being parsed.
+ if (current_dir.length ()
+ && file_string.length ()
+ && !File_name (file_string).is_absolute ()
+ && is_file (current_dir + DIRSEP + file_string))
+ file_string = current_dir + DIRSEP + file_string;
+
+ // Otherwise, check the rest of the path.
+ else if (path_)
+ {
+ string file_string_o = path_->find (file_string);
+ if ((file_string_o == "") && (file_string != ""))
+ return 0;
+
+ file_string = file_string_o;
+ }
}
- Source_file *f = new Source_file (*file_string);
+
+ Source_file *f = new Source_file (file_string);
add (f);
return f;
}
(resolution 101 "resolution for generating PNG bitmaps")
(read-file-list #f "Read files to be processed from command line arguments")
+ (relative-includes #f "When processing an \\include command, look for the included file
+relative to the current file (instead of the root file)")
(safe #f "Run safely")
(strict-infinity-checking #f "If yes, crash on encountering Inf/NaN.")