]> git.lyx.org Git - features.git/commitdiff
introduce the lyx_dir() of Package, automatically set LyXDir environment, correct...
authorStephan Witt <switt@lyx.org>
Tue, 25 Jan 2011 21:10:49 +0000 (21:10 +0000)
committerStephan Witt <switt@lyx.org>
Tue, 25 Jan 2011 21:10:49 +0000 (21:10 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37326 a592a061-630c-0410-9148-cb99ea01b6c8

src/LyX.cpp
src/support/Package.cpp
src/support/Package.h
src/support/filetools.cpp

index 3f43e1d956a3cfe72cab0abcc9dd87186f5cf441..e65ef903209b06b3d589cd49528327e182a72ea7 100644 (file)
@@ -745,6 +745,12 @@ bool LyX::init()
                                              "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 @@ bool LyX::init()
                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 @@ bool LyX::init()
 
        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())
index 5e4e7c163ae6e27e5df4c5aadb41cc2306add981..a2e8b17ebfcb72ccbc9bdf350378c0f486749f49 100644 (file)
@@ -116,6 +116,10 @@ Package::Package(string const & command_line_arg0,
        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_);
index cb48bb2fe59db78f47cca74ede1ba0ceef6fde64..0398f54bab6bfe1216c17b5bb09bd3bcd32c4145 100644 (file)
@@ -78,6 +78,11 @@ public:
         */
        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 @@ public:
 private:
        FileName binary_dir_;
        FileName lyx_binary_;
+       FileName lyx_dir_;
        FileName system_support_dir_;
        FileName build_support_dir_;
        FileName user_support_dir_;
index 27a21672b6a6d160ce2b52a606b5229c53e89da8..78255429d85d02a26f1ded87a3c953e18bf66a14 100644 (file)
@@ -547,23 +547,17 @@ string const replaceEnvironmentPath(string const & path)
        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;
 }