- //
- // Determine path of binary
- //
-
- string fullbinpath;
- string binpath = os::binpath();
- string binname = os::binname();
- fullbinpath = 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] << "Path of binary: " << binpath << endl;
-
- //
- // Determine system directory.
- //
-
- // Directories are searched in this order:
- // 1) -sysdir command line parameter
- // 2) LYX_DIR_11x 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.
-
- // If we had a command line switch, system_lyxdir is already set
- string searchpath;
- if (!system_lyxdir.empty())
- searchpath= MakeAbsPath(system_lyxdir) + ';';
-
- // LYX_DIR_11x environment variable
- string const lyxdir = GetEnvPath("LYX_DIR_11x");
-
- if (!lyxdir.empty()) {
- lyxerr[Debug::INIT] << "LYX_DIR_11x: " << lyxdir << endl;
- searchpath += lyxdir + ';';
- }
-
- // <path of binary>/TOP_SRCDIR/lib
- build_lyxdir = MakeAbsPath("../lib", binpath);
- if (!FileSearch(build_lyxdir, "lyxrc.defaults").empty()) {
- searchpath += MakeAbsPath(AddPath(TOP_SRCDIR, "lib"),
- binpath) + ';';
- lyxerr[Debug::INIT] << "Checking whether LyX is run in "
- "place... yes" << endl;
- } else {
- lyxerr[Debug::INIT]
- << "Checking whether LyX is run in place... no"
- << endl;
- build_lyxdir.erase();
- }
-
- 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) {
- string link;
- if (LyXReadLink(fullbinpath, link)) {
- fullbinpath = link;
- binpath = MakeAbsPath(OnlyPath(fullbinpath));
- }
- else {
- followlink = false;
- }
- }
- } while (followlink);
-
- // Hardcoded dir
- searchpath += LYX_DIR;
-
- // If debugging, show complete search path
- lyxerr[Debug::INIT] << "System directory search path: "
- << searchpath << endl;
-
- string const filename = "chkconfig.ltx";
- string const temp = FileOpenSearch(searchpath, filename, string());
- system_lyxdir = OnlyPath(temp);
-
- // Reduce "path/../path" stuff out of system directory
- system_lyxdir = NormalizePath(system_lyxdir);
-
- bool path_shown = false;
-
- // Warn if environment variable is set, but unusable
- if (!lyxdir.empty()) {
- if (system_lyxdir != NormalizePath(lyxdir)) {
- lyxerr <<_("LYX_DIR_11x environment variable no good.")
- << '\n'
- << _("System directory set to: ")
- << system_lyxdir << endl;
- path_shown = true;
- }
- }
-
- // Warn the user if we couldn't find "chkconfig.ltx"
- if (system_lyxdir == "./") {
- lyxerr <<_("LyX Warning! Couldn't determine system directory. ")
- <<_("Try the '-sysdir' command line parameter or ")
- <<_("set the environment variable LYX_DIR_11x 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 << _("Using built-in default ")
- << LYX_DIR << _(" but expect problems.")
- << endl;
- } else {
- lyxerr << _("Expect problems.") << endl;
- }
- system_lyxdir = LYX_DIR;
- path_shown = true;
- }
-
- // Report the system directory if debugging is on
- if (!path_shown)
- lyxerr[Debug::INIT] << "System directory: '"
- << system_lyxdir << '\'' << endl;
-
- //
- // Determine user lyx-dir
- //
-
- // Directories are searched in this order:
- // 1) -userdir command line parameter
- // 2) LYX_USERDIR_11x 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_11x environment variable
- user_lyxdir = GetEnvPath("LYX_USERDIR_11x");
-
- // 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;