2003-07-27 19:26:36 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
|
|
|
* \file path_defines.C
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Angus Leeming
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS
|
|
|
|
*
|
|
|
|
* Warning! This file is autogenerated from path_defines.C.in.
|
|
|
|
* All changes to this file will be lost.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "path_defines.h"
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
#include "gettext.h"
|
|
|
|
|
|
|
|
#include "FileInfo.h"
|
|
|
|
#include "filetools.h"
|
|
|
|
#include "lstrings.h"
|
|
|
|
#include "os.h"
|
|
|
|
|
|
|
|
using std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
string user_lyxdir;
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2003-07-27 21:04:02 +00:00
|
|
|
// Store for the path to the lyx support files we're actually going to use.
|
|
|
|
string system_lyxdir_;
|
|
|
|
|
2003-07-27 19:26:36 +00:00
|
|
|
/* The absolute path to the system-level lyx support files.
|
2003-07-27 20:17:31 +00:00
|
|
|
* (Make-time value.)
|
2003-07-27 19:26:36 +00:00
|
|
|
*/
|
|
|
|
string const & lyx_dir()
|
|
|
|
{
|
|
|
|
static string const ld = "%LYX_DIR%";
|
|
|
|
return ld;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* The absolute path to the top of the lyx build tree.
|
2003-07-27 20:17:31 +00:00
|
|
|
* (Make-time value.)
|
2003-07-27 19:26:36 +00:00
|
|
|
*/
|
|
|
|
string const & lyx_top_srcdir()
|
|
|
|
{
|
|
|
|
static string const lts = "%TOP_SRCDIR%";
|
|
|
|
return lts;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* The absolute path to the system-level lyx locale directory.
|
2003-07-27 20:17:31 +00:00
|
|
|
* (Make-time value.)
|
2003-07-27 19:26:36 +00:00
|
|
|
*/
|
|
|
|
string const & lyx_localedir()
|
|
|
|
{
|
|
|
|
static string const ll = "%LOCALEDIR%";
|
|
|
|
return ll;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace support {
|
|
|
|
|
2003-07-27 20:17:31 +00:00
|
|
|
string const & build_lyxdir()
|
|
|
|
{
|
|
|
|
static string const bl = "%BUILDDIR%";
|
|
|
|
return bl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-27 21:04:02 +00:00
|
|
|
string const & system_lyxdir()
|
|
|
|
{
|
|
|
|
return system_lyxdir_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void system_lyxdir(string const & sld)
|
|
|
|
{
|
|
|
|
system_lyxdir_ = sld;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-27 19:26:36 +00:00
|
|
|
bool setLyxPaths()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Determine path of binary
|
|
|
|
//
|
|
|
|
|
|
|
|
string binpath = os::binpath();
|
|
|
|
string binname = os::binname();
|
|
|
|
string fullbinname = MakeAbsPath(binname, binpath);
|
|
|
|
|
|
|
|
if (binpath.empty()) {
|
|
|
|
lyxerr << _("Warning: could not determine path of binary.")
|
|
|
|
<< "\n"
|
|
|
|
<< _("If you have problems, try starting LyX with an absolute path.")
|
|
|
|
<< endl;
|
|
|
|
}
|
|
|
|
lyxerr[Debug::INIT] << "Name of binary: " << binname << endl;
|
|
|
|
lyxerr[Debug::INIT] << "Path of binary: " << binpath << endl;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Determine system directory.
|
|
|
|
//
|
|
|
|
|
|
|
|
// Directories are searched in this order:
|
|
|
|
// 1) -sysdir command line parameter
|
|
|
|
// 2) LYX_DIR_14x environment variable
|
|
|
|
// 3) Maybe <path of binary>/TOP_SRCDIR/lib
|
|
|
|
// 4) <path of binary>/../share/<name of binary>/
|
|
|
|
// 4a) repeat 4 after following the Symlink if <path of
|
|
|
|
// binary> is a symbolic link.
|
|
|
|
// 5) hardcoded lyx_dir
|
|
|
|
// The directory is checked for the presence of the file
|
|
|
|
// "chkconfig.ltx", and if that is present, the directory
|
|
|
|
// is accepted as the system directory.
|
|
|
|
// If no chkconfig.ltx file is found, a warning is given,
|
|
|
|
// and the hardcoded lyx_dir is used.
|
|
|
|
|
2003-07-27 21:04:02 +00:00
|
|
|
// If we had a command line switch, system_lyxdir_ is already set
|
2003-07-27 19:26:36 +00:00
|
|
|
string searchpath;
|
2003-07-27 21:04:02 +00:00
|
|
|
if (!system_lyxdir_.empty())
|
|
|
|
searchpath = MakeAbsPath(system_lyxdir_) + ';';
|
2003-07-27 19:26:36 +00:00
|
|
|
|
|
|
|
string const lyxdir = GetEnvPath("LYX_DIR_14x");
|
|
|
|
|
|
|
|
if (!lyxdir.empty()) {
|
|
|
|
lyxerr[Debug::INIT] << "LYX_DIR_14x: " << lyxdir << endl;
|
|
|
|
searchpath += lyxdir + ';';
|
|
|
|
}
|
|
|
|
|
|
|
|
string fullbinpath = binpath;
|
|
|
|
FileInfo file(fullbinname, true);
|
|
|
|
if (file.isLink()) {
|
|
|
|
lyxerr[Debug::INIT] << "binary is a link" << endl;
|
|
|
|
string link;
|
|
|
|
if (LyXReadLink(fullbinname, link, true)) {
|
|
|
|
// Path of binary/../share/name of binary/
|
|
|
|
searchpath += NormalizePath(AddPath(binpath,
|
|
|
|
"../share/")
|
|
|
|
+ OnlyFilename(binname));
|
|
|
|
searchpath += ';';
|
|
|
|
fullbinpath = link;
|
|
|
|
binpath = MakeAbsPath(OnlyPath(fullbinpath));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool followlink;
|
|
|
|
do {
|
|
|
|
// Path of binary/../share/name of binary/
|
|
|
|
searchpath += NormalizePath(AddPath(binpath, "../share/") +
|
|
|
|
OnlyFilename(binname)) + ';';
|
|
|
|
|
|
|
|
// Follow Symlinks
|
|
|
|
FileInfo file(fullbinpath, true);
|
|
|
|
followlink = file.isLink();
|
|
|
|
if (followlink) {
|
|
|
|
lyxerr[Debug::INIT] << " directory " << fullbinpath
|
|
|
|
<< " is a link" << endl;
|
|
|
|
string link;
|
|
|
|
if (LyXReadLink(fullbinpath, link, true)) {
|
|
|
|
fullbinpath = link;
|
|
|
|
binpath = MakeAbsPath(OnlyPath(fullbinpath));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
followlink = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (followlink);
|
|
|
|
|
|
|
|
// <absolute top srcdir>/lib
|
|
|
|
searchpath += AddPath(lyx_top_srcdir(), "lib") + ';';
|
|
|
|
// Hardcoded dir
|
|
|
|
searchpath += lyx_dir();
|
|
|
|
|
|
|
|
lyxerr[Debug::INIT] << "System directory search path: "
|
|
|
|
<< searchpath << endl;
|
|
|
|
|
|
|
|
string const filename = "chkconfig.ltx";
|
|
|
|
string const temp = FileOpenSearch(searchpath, filename, string());
|
2003-07-27 21:04:02 +00:00
|
|
|
system_lyxdir_ = OnlyPath(temp);
|
2003-07-27 19:26:36 +00:00
|
|
|
|
|
|
|
// Reduce "path/../path" stuff out of system directory
|
2003-07-27 21:04:02 +00:00
|
|
|
system_lyxdir_ = NormalizePath(system_lyxdir_);
|
2003-07-27 19:26:36 +00:00
|
|
|
|
|
|
|
bool path_shown = false;
|
|
|
|
|
|
|
|
// Warn if environment variable is set, but unusable
|
|
|
|
if (!lyxdir.empty()) {
|
2003-07-27 21:04:02 +00:00
|
|
|
if (system_lyxdir_ != NormalizePath(lyxdir)) {
|
2003-07-27 19:26:36 +00:00
|
|
|
lyxerr <<_("LYX_DIR_14x environment variable no good.")
|
|
|
|
<< '\n'
|
|
|
|
<< _("System directory set to: ")
|
2003-07-27 21:04:02 +00:00
|
|
|
<< system_lyxdir_ << endl;
|
2003-07-27 19:26:36 +00:00
|
|
|
path_shown = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Warn the user if we couldn't find "chkconfig.ltx"
|
2003-07-27 21:04:02 +00:00
|
|
|
if (system_lyxdir_ == "./") {
|
2003-07-27 19:26:36 +00:00
|
|
|
lyxerr <<_("LyX Warning! Couldn't determine system directory. ")
|
|
|
|
<<_("Try the '-sysdir' command line parameter or ")
|
|
|
|
<<_("set the environment variable LYX_DIR_14x to the "
|
|
|
|
"LyX system directory ")
|
|
|
|
<< _("containing the file `chkconfig.ltx'.") << endl;
|
|
|
|
if (!path_shown) {
|
|
|
|
FileInfo fi(lyx_dir());
|
|
|
|
if (!fi.exist()) {
|
|
|
|
lyxerr << "Couldn't even find the default LYX_DIR." << endl
|
|
|
|
<< "Giving up." << endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
lyxerr << bformat(_("Using built-in default %1$s but expect problems."),
|
|
|
|
lyx_dir()) << endl;
|
|
|
|
} else {
|
|
|
|
lyxerr << _("Expect problems.") << endl;
|
|
|
|
}
|
2003-07-27 21:04:02 +00:00
|
|
|
system_lyxdir_ = lyx_dir();
|
2003-07-27 19:26:36 +00:00
|
|
|
path_shown = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!path_shown)
|
|
|
|
lyxerr[Debug::INIT] << "System directory: '"
|
2003-07-27 21:04:02 +00:00
|
|
|
<< system_lyxdir_ << '\'' << endl;
|
2003-07-27 19:26:36 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Determine user lyx-dir
|
|
|
|
//
|
|
|
|
|
|
|
|
// Directories are searched in this order:
|
|
|
|
// 1) -userdir command line parameter
|
|
|
|
// 2) LYX_USERDIR_14x environment variable
|
|
|
|
// 3) $HOME/.<name of binary>
|
|
|
|
|
|
|
|
// If we had a command line switch, user_lyxdir is already set
|
|
|
|
bool explicit_userdir = true;
|
|
|
|
if (user_lyxdir.empty()) {
|
|
|
|
|
|
|
|
// LYX_USERDIR_14x environment variable
|
|
|
|
user_lyxdir = GetEnvPath("LYX_USERDIR_14x");
|
|
|
|
|
|
|
|
// default behaviour
|
|
|
|
if (user_lyxdir.empty())
|
|
|
|
user_lyxdir = AddPath(GetEnvPath("HOME"),
|
|
|
|
string(".") + PACKAGE);
|
|
|
|
explicit_userdir = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
lyxerr[Debug::INIT] << "User LyX directory: '"
|
|
|
|
<< user_lyxdir << '\'' << endl;
|
|
|
|
return explicit_userdir;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace support
|
|
|
|
} // namespace lyx
|