]> git.lyx.org Git - lyx.git/blobdiff - src/support/path_defines.C.in
tostr -> convert and some bformat work
[lyx.git] / src / support / path_defines.C.in
index b746ec738731280bd21345cdfb926e66c8d56793..dfe7062efb274395531da49a61478c172be4b5a8 100644 (file)
@@ -40,6 +40,8 @@ string build_lyxdir_;
 // Store for the path to the user-level support files.
 string user_lyxdir_;
 
+// Store for the path to the locale directory.
+string localedir_;
 
 /* The absolute path to the system-level lyx support files.
  * (Make-time value.)
@@ -50,22 +52,22 @@ string const & lyx_dir()
        return ld;
 }
 
+} // namespace anon
+
+
+namespace lyx {
+namespace support {
+
 
 /* The absolute path to the top of the lyx build tree.
  * (Make-time value.)
  */
-string const & lyx_top_srcdir()
+string const & top_srcdir()
 {
        static string const lts = "%TOP_SRCDIR%";
        return lts;
 }
 
-} // namespace anon
-
-
-namespace lyx {
-namespace support {
-
 
 /* The absolute path to the system-level lyx locale directory.
  * (Make-time value.)
@@ -73,7 +75,10 @@ namespace support {
 string const & lyx_localedir()
 {
        static string const ll = "%LOCALEDIR%";
-       return ll;
+       if (localedir_.empty())
+               return ll;
+       else
+               return localedir_;
 }
 
 
@@ -149,7 +154,7 @@ bool setLyxPaths()
 
        string const buildlyxdir = MakeAbsPath("../lib", binpath);
        if (!FileSearch(buildlyxdir, "lyxrc.defaults").empty()) {
-               searchpath += AddPath(lyx_top_srcdir(), "lib") + ';';
+               searchpath += AddPath(top_srcdir(), "lib") + ';';
                build_lyxdir(buildlyxdir);
                lyxerr[Debug::INIT] << "Checking whether LyX is run in "
                        "place... yes" << endl;
@@ -190,7 +195,7 @@ bool setLyxPaths()
        }
 
        // Path of binary/../Resources/
-       searchpath += NormalizePath(AddPath(binpath, "../Resources/") + 
+       searchpath += NormalizePath(AddPath(binpath, "../Resources/") +
                                    OnlyFilename(binname)) + ';';
 
        string fullbinpath = binpath;
@@ -212,8 +217,18 @@ bool setLyxPaths()
        bool followlink;
        do {
                // Path of binary/../share/name of binary/
-               searchpath += NormalizePath(AddPath(binpath, "../share/") +
-                     OnlyFilename(binname)) + ';';
+               string const exe_name = OnlyFilename(binname);
+#ifdef _WIN32
+               string const lyx_system_dir_name =
+                       suffixIs(exe_name, ".exe") ?
+                               ChangeExtension(exe_name, "") :
+                               exe_name;
+#else
+               string const lyx_system_dir_name = exe_name;
+#endif
+               string const shared_dir_name =
+                       NormalizePath(AddPath(binpath, "../share/"));
+               searchpath += shared_dir_name + lyx_system_dir_name + ';';
 
                // Follow Symlinks
                FileInfo file(fullbinpath, true);
@@ -233,7 +248,7 @@ bool setLyxPaths()
        } while (followlink);
 
        // <absolute top srcdir>/lib
-       searchpath += AddPath(lyx_top_srcdir(), "lib") + ';';
+       searchpath += AddPath(top_srcdir(), "lib") + ';';
        // Hardcoded dir
        searchpath += lyx_dir();
 
@@ -287,22 +302,49 @@ bool setLyxPaths()
                lyxerr[Debug::INIT] << "System directory: '"
                                    << system_lyxdir_ << '\'' << endl;
 
+       // This is true when we are running from a Mac OS X bundle
+       // (for LyX/Mac)
+       bool const inOSXBundle =
+               system_lyxdir_ == NormalizePath(AddPath(binpath, "../Resources/")
+                                               + OnlyFilename(binname));
+       if (inOSXBundle)
+               lyxerr[Debug::INIT] << "Running from LyX/Mac bundle."
+                                   << endl;
+
        //
-       // Set PATH for LyX/Mac 
+       // Set PATH for LyX/Mac
        // LyX/Mac is a relocatable application bundle; here we add to
        // the PATH so it can find binaries like reLyX inside its own
        // application bundle, and also append PATH elements that it
        // needs to run latex, previewers, etc.
        //
 
-       if (system_lyxdir_ == NormalizePath(AddPath(binpath, "../Resources/")
-                                           + OnlyFilename(binname))) {
-         const string newpath = GetEnv("PATH") + ":" + binpath
-           + ":/sw/bin:/usr/local/bin"
-           + ":/usr/local/teTeX/bin/powerpc-apple-darwin-current";
-         lyx::support::putenv("PATH", newpath);
-         lyxerr[Debug::INIT] << "Running from LyX/Mac bundle. "
-           "Setting PATH to: " << GetEnv("PATH") << endl;
+       if (inOSXBundle) {
+               const string newpath = GetEnv("PATH") + ":" + binpath
+                       + ":/sw/bin:/usr/local/bin"
+                       + ":/usr/local/teTeX/bin/powerpc-apple-darwin-current";
+               lyx::support::putenv("PATH", newpath);
+               lyxerr[Debug::INIT] << "LyX/Mac: setting PATH to: "
+                                   << GetEnv("PATH") << endl;
+       }
+
+
+       //
+       // Determine locale directory
+       //
+       if (!GetEnv("LYX_LOCALEDIR").empty()) {
+               localedir_ = GetEnv("LYX_LOCALEDIR");
+               lyxerr[Debug::INIT] << "LYX_LOCALEDIR=" << localedir_ << endl;
+       } else if (inOSXBundle) {
+               string const maybe_localedir =
+                       NormalizePath(AddPath(system_lyxdir_, "../locale"));
+               FileInfo fi(maybe_localedir);
+               if (fi.isOK() && fi.isDir()) {
+                       lyxerr[Debug::INIT]
+                               << "LyX/Mac: setting locale directory to "
+                               << maybe_localedir << endl;
+                       localedir_ = maybe_localedir;
+               }
        }
 
        //
@@ -323,9 +365,13 @@ bool setLyxPaths()
 
                // default behaviour
                if (user_lyxdir_.empty())
-                       user_lyxdir_ = AddPath(GetEnvPath("HOME"),
-                                              string(".") + PACKAGE);
-                       explicit_userdir = false;
+                       if (inOSXBundle)
+                               user_lyxdir_ = AddPath(os::homepath(),
+                                                      "Library/Preferences/LyX");
+                       else
+                               user_lyxdir_ = AddPath(os::homepath(),
+                                                      string(".") + PACKAGE);
+               explicit_userdir = false;
        }
 
        lyxerr[Debug::INIT] << "User LyX directory: '"