From 9e16f14464c0188edb87ebc294bfcec4d396e0e5 Mon Sep 17 00:00:00 2001 From: Stephan Witt Date: Tue, 25 Jan 2011 21:10:49 +0000 Subject: [PATCH] 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 git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37326 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/LyX.cpp | 10 ++++++++-- src/support/Package.cpp | 4 ++++ src/support/Package.h | 6 ++++++ src/support/filetools.cpp | 14 ++++---------- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/LyX.cpp b/src/LyX.cpp index 3f43e1d956..e65ef90320 100644 --- a/src/LyX.cpp +++ b/src/LyX.cpp @@ -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()) diff --git a/src/support/Package.cpp b/src/support/Package.cpp index 5e4e7c163a..a2e8b17ebf 100644 --- a/src/support/Package.cpp +++ b/src/support/Package.cpp @@ -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_); diff --git a/src/support/Package.h b/src/support/Package.h index cb48bb2fe5..0398f54bab 100644 --- a/src/support/Package.h +++ b/src/support/Package.h @@ -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_; diff --git a/src/support/filetools.cpp b/src/support/filetools.cpp index 27a21672b6..78255429d8 100644 --- a/src/support/filetools.cpp +++ b/src/support/filetools.cpp @@ -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; } -- 2.39.5