Author: switt
Date: Tue Jan 25 22:10:49 2011
New Revision: 37326
URL: http://www.lyx.org/trac/changeset/37326

Log:
introduce the lyx_dir() of Package, automatically set LyXDir environment, 
correct the replaceEnvironmentPath() function (see #4177) and replace 
environment variables in path_prefix at runtime

Modified:
   lyx-devel/trunk/src/LyX.cpp
   lyx-devel/trunk/src/support/Package.cpp
   lyx-devel/trunk/src/support/Package.h
   lyx-devel/trunk/src/support/filetools.cpp

Modified: lyx-devel/trunk/src/LyX.cpp
==============================================================================
--- lyx-devel/trunk/src/LyX.cpp Tue Jan 25 15:50:13 2011        (r37325)
+++ lyx-devel/trunk/src/LyX.cpp Tue Jan 25 22:10:49 2011        (r37326)
@@ -745,6 +745,12 @@
                                              "templates");
        }
 
+       // init LyXDir environment variable
+       string const lyx_dir = package().lyx_dir().absFileName();
+       LYXERR(Debug::INIT, "Setting LyXDir... to \"" << lyx_dir << "\"");
+       if (!setEnv("LyXDir", lyx_dir))
+               LYXERR(Debug::INIT, "\t... failed!");
+
        //
        // Read configuration files
        //
@@ -764,7 +770,7 @@
                prependEnvPath("PATH", package().binary_dir().absFileName());
 #endif
        if (!lyxrc.path_prefix.empty())
-               prependEnvPath("PATH", lyxrc.path_prefix);
+               prependEnvPath("PATH", 
replaceEnvironmentPath(lyxrc.path_prefix));
 
        // Check that user LyX directory is ok.
        if (queryUserLyXDir(package().explicit_user_support()))
@@ -842,7 +848,7 @@
 
        os::windows_style_tex_paths(lyxrc.windows_style_tex_paths);
        if (!lyxrc.path_prefix.empty())
-               prependEnvPath("PATH", lyxrc.path_prefix);
+               prependEnvPath("PATH", 
replaceEnvironmentPath(lyxrc.path_prefix));
 
        FileName const document_path(lyxrc.document_path);
        if (document_path.exists() && document_path.isDirectory())

Modified: lyx-devel/trunk/src/support/Package.cpp
==============================================================================
--- lyx-devel/trunk/src/support/Package.cpp     Tue Jan 25 15:50:13 2011        
(r37325)
+++ lyx-devel/trunk/src/support/Package.cpp     Tue Jan 25 22:10:49 2011        
(r37326)
@@ -116,6 +116,10 @@
        FileName const abs_binary = 
abs_path_from_binary_name(command_line_arg0);
        binary_dir_ = FileName(onlyPath(abs_binary.absFileName()));
 
+       // the LyX package directory
+       lyx_dir_ = FileName(addPath(binary_dir_.absFileName(), "../"));
+       lyx_dir_ = FileName(lyx_dir_.realPath());
+
        // Is LyX being run in-place from the build tree?
        buildDirs(abs_binary, top_build_dir_location,
                build_support_dir_, system_support_dir_);

Modified: lyx-devel/trunk/src/support/Package.h
==============================================================================
--- lyx-devel/trunk/src/support/Package.h       Tue Jan 25 15:50:13 2011        
(r37325)
+++ lyx-devel/trunk/src/support/Package.h       Tue Jan 25 22:10:49 2011        
(r37326)
@@ -78,6 +78,11 @@
         */
        FileName const & lyx_binary() const { return lyx_binary_; }
 
+       /** The absolute path to the LyX package directory.
+        *  This is one level up from the binary dir.
+        */
+       FileName const & lyx_dir() const { return lyx_dir_; }
+
        /** The top of the LyX source code tree.
         */
        static FileName const & top_srcdir();
@@ -142,6 +147,7 @@
 private:
        FileName binary_dir_;
        FileName lyx_binary_;
+       FileName lyx_dir_;
        FileName system_support_dir_;
        FileName build_support_dir_;
        FileName user_support_dir_;

Modified: lyx-devel/trunk/src/support/filetools.cpp
==============================================================================
--- lyx-devel/trunk/src/support/filetools.cpp   Tue Jan 25 15:50:13 2011        
(r37325)
+++ lyx-devel/trunk/src/support/filetools.cpp   Tue Jan 25 22:10:49 2011        
(r37326)
@@ -547,23 +547,17 @@
        static regex envvar_br_re("(.*)" + envvar_br + "(.*)");
        static regex envvar_re("(.*)" + envvar + "(.*)");
        smatch what;
-       string result;
-       string remaining = path;
+       string result = path;
        while (1) {
-               regex_match(remaining, what, envvar_br_re);
+               regex_match(result, what, envvar_br_re);
                if (!what[0].matched) {
-                       regex_match(remaining, what, envvar_re);
+                       regex_match(result, what, envvar_re);
                        if (!what[0].matched) {
-                               result += remaining;
                                break;
                        }
                }
                string env_var = getEnv(what.str(2));
-               if (!env_var.empty())
-                       result += what.str(1) + env_var;
-               else
-                       result += what.str(1) + "$" + what.str(2);
-               remaining = what.str(3);
+               result = what.str(1) + env_var + what.str(3);
        }
        return result;
 }

Reply via email to