]> git.donarmstrong.com Git - lilypond.git/commitdiff
Change behavior of nested includes.
authorJoe Neeman <joeneeman@gmail.com>
Thu, 11 Dec 2008 21:52:16 +0000 (13:52 -0800)
committerJoe Neeman <joeneeman@gmail.com>
Thu, 11 Dec 2008 21:52:16 +0000 (13:52 -0800)
We now search for a nested include file starting from the
directory of the file that included it (before we started the
search from the directory of the file that was specified
on the lilypond command line).

lily/includable-lexer.cc
lily/include/sources.hh
lily/lily-parser-scheme.cc
lily/sources.cc

index f0eed9eb6c48e9e2aea49f6b64a972f261d5b6ba..09b97da0178a3c5a7e15e16a8bf30ee73c0f8798 100644 (file)
@@ -13,6 +13,7 @@ using namespace std;
 
 #include "config.hh"
 
+#include "file-name.hh"
 #include "file-path.hh"
 #include "international.hh"
 #include "main.hh"
@@ -47,13 +48,16 @@ Includable_lexer::Includable_lexer ()
 void
 Includable_lexer::new_input (string name, Sources *sources)
 {
-  Source_file *file = sources->get_file (&name);
+  string 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;
     }
@@ -64,7 +68,7 @@ Includable_lexer::new_input (string name, Sources *sources)
     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);
 
index fe55fe72ba82d45fbb3f2c2235e62be8fe267501..a964a7bf6a8c802218e9285511a7c4639f6f0228 100644 (file)
@@ -19,8 +19,7 @@ public:
   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 *);
 
index fbeb7db5072d0f3aef51382291f377ed7e92dc11..d6a1c79ea6c343b2e3fa7bb36bf6ce8d6b8a5014 100644 (file)
@@ -47,8 +47,6 @@ LY_DEFINE (ly_parse_file, "ly:parse-file",
      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
index 05717455e0c4aa038b5b0fd93ff95838ed2c9a40..62ee7a1e9970112aea37d2005ec3ccd23634d97e 100644 (file)
@@ -8,7 +8,9 @@
 
 #include "sources.hh"
 
+#include "config.hh"
 #include "source-file.hh"
+#include "file-name.hh"
 #include "file-path.hh"
 
 Sources::Sources ()
@@ -30,22 +32,38 @@ Sources::set_path (File_path *f)
 }
 
 /**
-   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;
 }