]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/relocate.cc
[MINGW32]: Prepend cwd to PATH. Fixes invoking as "lilypond.exe".
[lilypond.git] / lily / relocate.cc
index 2ff9fc44d37e7721780bf791d07d4398ac588f1e..178e7d9ca879d018e1ddcdac3dec240b22c7f0ea 100644 (file)
@@ -1,10 +1,20 @@
 /*
-  relocate.cc -- implement relocation based on argv0
+  This file is part of LilyPond, the GNU music typesetter.
 
-  source file of the GNU LilyPond music typesetter
+  Copyright (C) 2005--2010 Han-Wen Nienhuys <hanwen@xs4all.nl>
 
-  (c) 2005--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
+  LilyPond is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
 
+  LilyPond is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "relocate.hh"
@@ -191,17 +201,18 @@ setup_paths (char const *argv0_ptr)
              File_path path;
              path.parse_path (getenv ("PATH"));
 
-             if (be_verbose_global)
-               warning (_f ("Relocation: from PATH=%s\nargv0=%s",
-                            path.to_string ().c_str (), argv0_ptr));
-
 #ifndef __MINGW32__
              argv0_abs = path.find (argv0_filename.to_string ());
 #else /* __MINGW32__ */
+             path.prepend (get_working_directory ());
              char const *ext[] = {"exe", "", 0 };
              argv0_abs = path.find (argv0_filename.to_string (), ext);
 #endif /* __MINGW32__ */
 
+             if (be_verbose_global)
+               warning (_f ("Relocation: from PATH=%s\nargv0=%s",
+                            path.to_string ().c_str (), argv0_ptr));
+
              if (argv0_abs.empty ())
                programming_error ("cannot find absolute argv0");
            }
@@ -230,12 +241,8 @@ setup_paths (char const *argv0_ptr)
 
   if (char const *env = getenv ("LILYPOND_DATADIR"))
     {
-#ifdef __MINGW32__
       /* Normalize file name.  */
       lilypond_datadir = File_name (env).to_string ();
-#else
-      lilypond_datadir = env;
-#endif
     }
 
   /* When running from build dir, a full LILYPOND_DATADIR is set-up at
@@ -245,6 +252,9 @@ setup_paths (char const *argv0_ptr)
   if (!is_dir (lilypond_datadir.c_str ())
       && is_dir (build_datadir_current.c_str ()))
     lilypond_datadir = build_datadir_current;
+
+
+  lilypond_datadir = File_name (lilypond_datadir).canonicalized().to_string();
   
   global_path.append ("");
 
@@ -270,20 +280,20 @@ setup_paths (char const *argv0_ptr)
 string
 expand_environment_variables (string orig)
 {
-  const char *start_ptr = orig.c_str ();
-  const char *ptr = orig.c_str ();
+  char const *start_ptr = orig.c_str ();
+  char const *ptr = orig.c_str ();
   size_t len = orig.length ();
 
   string out;
   while (ptr < start_ptr + len)
     {
-      char *dollar = strchr (ptr, '$');
+      char const *dollar = strchr (ptr, '$');
       
       if (dollar != NULL)
        {
-         char *start_var = dollar + 1;
-         char *end_var = start_var;
-         char *start_next = end_var;
+         char const *start_var = dollar + 1;
+         char const *end_var = start_var;
+         char const *start_next = end_var;
          
          out += string (ptr, dollar - ptr);
          ptr = dollar;
@@ -320,7 +330,7 @@ expand_environment_variables (string orig)
          if (start_var < end_var)
            {
              string var_name (start_var, end_var - start_var);
-             const char *value = getenv (var_name.c_str ());
+             char const *value = getenv (var_name.c_str ());
              if (value != NULL)
                out += string (value);
 
@@ -337,7 +347,7 @@ expand_environment_variables (string orig)
   return out;
 }
 
-
+// Ugh - very inefficient, but safer than fgets.
 static string
 read_line (FILE *f)
 {
@@ -345,7 +355,7 @@ read_line (FILE *f)
   
   int c = 0;
   while ((c = fgetc (f)) != EOF && c != '\n')
-    out += c;
+    out += char(c);
 
   return out;
 }