]> git.lyx.org Git - lyx.git/blobdiff - src/support/Package.cpp
Replace the text class shared ptr by good old index-into-global-list.
[lyx.git] / src / support / Package.cpp
index 0244a2f2eb5fc48e8ae5bbdcf995e207993902d6..774bcc043de3dc3cdabb785e60c6ea344537b183 100644 (file)
@@ -1,6 +1,6 @@
 // -*- C++ -*-
 /**
- * \file package.C
+ * \file package.cpp
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
 
 #include "support/Package.h"
 
-#include "debug.h"
-#include "gettext.h"
-
+#include "support/debug.h"
 #include "support/environment.h"
+#include "support/ExceptionMessage.h"
 #include "support/filetools.h"
+#include "support/gettext.h"
 #include "support/lstrings.h"
-#include "support/ExceptionMessage.h"
 #include "support/os.h"
 
 #if defined (USE_WINDOWS_PACKAGING)
 # include "support/os_win32.h"
 #endif
 
-#include <boost/filesystem/operations.hpp>
-#include <boost/tuple/tuple.hpp>
 
 #include <list>
-#include <utility>
 
 #if !defined (USE_WINDOWS_PACKAGING) && \
     !defined (USE_MACOSX_PACKAGING) && \
@@ -42,9 +38,7 @@
 # include <CoreServices/CoreServices.h> // FSFindFolder, FSRefMakePath
 #endif
 
-using std::string;
-
-namespace fs = boost::filesystem;
+using namespace std;
 
 namespace lyx {
 namespace support {
@@ -88,9 +82,9 @@ namespace {
 
 FileName const abs_path_from_binary_name(string const & exe);
 
-std::pair<FileName, FileName> const
-get_build_dirs(FileName const & abs_binary,
-              exe_build_dir_to_top_build_dir top_build_dir_location);
+void buildDirs(FileName const & abs_binary,
+       exe_build_dir_to_top_build_dir top_build_dir_location,
+       FileName &, FileName &);
 
 FileName const get_document_dir(FileName const & home_dir);
 
@@ -105,9 +99,8 @@ FileName const get_temp_dir();
 
 FileName const get_default_user_support_dir(FileName const & home_dir);
 
-std::pair<FileName, bool> const
-get_user_support_dir(FileName const & default_user_support_dir,
-                    string const & command_line_user_support_dir);
+bool userSupportDir(FileName const & default_user_support_dir,
+                    string const & command_line_user_support_dir, FileName & result);
 
 
 string const & with_version_suffix();
@@ -135,8 +128,8 @@ Package::Package(string const & command_line_arg0,
                binary_dir_ = FileName(bdir);
 
        // Is LyX being run in-place from the build tree?
-       boost::tie(build_support_dir_, system_support_dir_) =
-               get_build_dirs(abs_binary, top_build_dir_location);
+       buildDirs(abs_binary, top_build_dir_location,
+               build_support_dir_, system_support_dir_);
 
        if (build_support_dir_.empty())
                system_support_dir_ =
@@ -147,17 +140,16 @@ Package::Package(string const & command_line_arg0,
 
        FileName const default_user_support_dir =
                get_default_user_support_dir(home_dir_);
-       boost::tie(user_support_dir_, explicit_user_support_dir_) =
-               get_user_support_dir(default_user_support_dir,
-                                    command_line_user_support_dir);
+
+       explicit_user_support_dir_ = userSupportDir(default_user_support_dir,
+                                    command_line_user_support_dir, user_support_dir_);
 
        FileName const configure_script(addName(system_support().absFilename(), "configure.py"));
        configure_command_ = os::python() + ' ' +
                        quoteName(configure_script.toFilesystemEncoding()) +
                        with_version_suffix();
 
-       lyxerr[Debug::INIT]
-               << "<package>\n"
+       LYXERR(Debug::INIT, "<package>\n"
                << "\tbinary_dir " << binary_dir().absFilename() << '\n'
                << "\tsystem_support " << system_support().absFilename() << '\n'
                << "\tbuild_support " << build_support().absFilename() << '\n'
@@ -166,7 +158,7 @@ Package::Package(string const & command_line_arg0,
                << "\tdocument_dir " << document_dir().absFilename() << '\n'
                << "\ttemp_dir " << temp_dir().absFilename() << '\n'
                << "\thome_dir " << home_dir().absFilename() << '\n'
-               << "</package>\n" << std::endl;
+               << "</package>\n");
 }
 
 
@@ -241,8 +233,7 @@ string const fix_dir_name(string const & name)
 }
 
 
-FileName const
-get_build_support_dir(string const & binary_dir,
+FileName buildSupportDir(string const & binary_dir,
                      exe_build_dir_to_top_build_dir top_build_dir_location)
 {
        string indirection;
@@ -254,13 +245,13 @@ get_build_support_dir(string const & binary_dir,
                indirection = "../../lib";
                break;
        }
-       return FileName(normalizePath(addPath(binary_dir, indirection)));
+       return FileName(addPath(binary_dir, indirection));
 }
 
 
-std::pair<FileName, FileName> const
-get_build_dirs(FileName const & abs_binary,
-              exe_build_dir_to_top_build_dir top_build_dir_location)
+void buildDirs(FileName const & abs_binary,
+  exe_build_dir_to_top_build_dir top_build_dir_location,
+       FileName & build_support_dir, FileName & system_support_dir)
 {
        string const check_text = "Checking whether LyX is run in place...";
 
@@ -279,23 +270,21 @@ get_build_dirs(FileName const & abs_binary,
                // We may be using libtools with static linking.
                if (suffixIs(binary_dir, ".libs/"))
                        binary_dir = addPath(binary_dir, "../");
-               FileName const build_support_dir =
-                       get_build_support_dir(binary_dir, top_build_dir_location);
+               build_support_dir = buildSupportDir(binary_dir, top_build_dir_location);
                if (!fileSearch(build_support_dir.absFilename(), "Makefile").empty()) {
                        // Try and find "chkconfig.ltx".
-                       string const system_support_dir =
-                               addPath(Package::top_srcdir().absFilename(), "lib");
+                       system_support_dir =
+                               FileName(addPath(Package::top_srcdir().absFilename(), "lib"));
 
-                       if (!fileSearch(system_support_dir, "chkconfig.ltx").empty()) {
-                               lyxerr[Debug::INIT] << check_text << " yes"
-                                                   << std::endl;
-                               return std::make_pair(build_support_dir, system_support_dir);
+                       if (!fileSearch(system_support_dir.absFilename(), "chkconfig.ltx").empty()) {
+                               LYXERR(Debug::INIT, check_text << " yes");
+                               return;
                        }
                }
 
                // Check whether binary is a symbolic link.
                // If so, resolve it and repeat the exercise.
-               if (!fs::symbolic_link_exists(binary.toFilesystemEncoding()))
+               if (!binary.isSymLink())
                        break;
 
                FileName link;
@@ -307,8 +296,9 @@ get_build_dirs(FileName const & abs_binary,
                }
        }
 
-       lyxerr[Debug::INIT] << check_text << " no" << std::endl;
-       return std::make_pair(FileName(), FileName());
+       LYXERR(Debug::INIT, check_text << " no");
+       system_support_dir = FileName();
+       build_support_dir = FileName();
 }
 
 
@@ -353,15 +343,15 @@ FileName const get_locale_dir(FileName const & system_support_dir)
        // 2. Search for system_support_dir / <relative locale dir>
        // The <relative locale dir> is OS-dependent. (On Unix, it will
        // be "../locale/".)
-       FileName path(normalizePath(addPath(system_support_dir.absFilename(),
-                                           relative_locale_dir())));
+       FileName path(addPath(system_support_dir.absFilename(),
+               relative_locale_dir()));
 
-       if (path.exists() && fs::is_directory(path.toFilesystemEncoding()))
+       if (path.exists() && path.isDirectory())
                return path;
 
        // 3. Fall back to the hard-coded LOCALEDIR.
        path = hardcoded_localedir();
-       if (path.exists() && fs::is_directory(path.toFilesystemEncoding()))
+       if (path.exists() && path.isDirectory())
                return path;
 
        return FileName();
@@ -376,7 +366,7 @@ FileName const get_temp_dir()
        // Typical example: C:/TEMP/.
        char path[MAX_PATH];
        GetTempPath(MAX_PATH, path);
-       return FileName(os::internal_path(to_utf8(from_local8bit(path))));
+       return FileName(to_utf8(from_local8bit(path)));
 #else // Posix-like.
        return FileName("/tmp");
 #endif
@@ -389,8 +379,9 @@ FileName const abs_path_from_command_line(string const & command_line)
        if (command_line.empty())
                return FileName();
 
-       string const path = fix_dir_name(command_line);
-       return os::is_absolute_path(path) ? FileName(path) : makeAbsPath(path);
+       string const str_path = fix_dir_name(command_line);
+       FileName path(str_path);
+       return path.isAbsolute() ? path : makeAbsPath(str_path);
 }
 
 
@@ -407,8 +398,9 @@ FileName const get_binary_path(string const & exe)
 #else
        string const exe_path = os::internal_path(exe);
 #endif
-       if (os::is_absolute_path(exe_path))
-               return FileName(exe_path);
+       FileName exepath(exe_path);
+       if (exepath.isAbsolute())
+               return exepath;
 
        // Two possibilities present themselves.
        // 1. The binary is relative to the CWD.
@@ -422,9 +414,9 @@ FileName const get_binary_path(string const & exe)
        if (exe_name != exe_path)
                return FileName();
 
-       std::vector<string> const path = getEnvPath("PATH");
-       std::vector<string>::const_iterator it = path.begin();
-       std::vector<string>::const_iterator const end = path.end();
+       vector<string> const path = getEnvPath("PATH");
+       vector<string>::const_iterator it = path.begin();
+       vector<string>::const_iterator const end = path.end();
        for (; it != end; ++it) {
                // This will do nothing if *it is already absolute.
                string const exe_dir = makeAbsPath(*it).absFilename();
@@ -465,7 +457,7 @@ get_system_support_dir(FileName const & abs_binary,
 
        // searched_dirs is used for diagnostic purposes only in the case
        // that "chkconfig.ltx" is not found.
-       std::list<FileName> searched_dirs;
+       list<FileName> searched_dirs;
 
        // 1. Use the -sysdir command line parameter.
        FileName path = abs_path_from_command_line(command_line_system_support_dir);
@@ -497,8 +489,7 @@ get_system_support_dir(FileName const & abs_binary,
                // Try and find "chkconfig.ltx".
                string const binary_dir = onlyPath(binary.absFilename());
 
-               FileName const lyxdir(
-                       normalizePath(addPath(binary_dir, relative_lyxdir)));
+               FileName const lyxdir(addPath(binary_dir, relative_lyxdir));
                searched_dirs.push_back(lyxdir);
 
                if (!fileSearch(lyxdir.absFilename(), chkconfig_ltx).empty()) {
@@ -508,7 +499,7 @@ get_system_support_dir(FileName const & abs_binary,
 
                // Check whether binary is a symbolic link.
                // If so, resolve it and repeat the exercise.
-               if (!fs::symbolic_link_exists(binary.toFilesystemEncoding()))
+               if (!binary.isSymLink())
                        break;
 
                FileName link;
@@ -526,7 +517,7 @@ get_system_support_dir(FileName const & abs_binary,
                // This time test whether the directory is a symbolic link
                // *before* looking for "chkconfig.ltx".
                // (We've looked relative to the original already.)
-               if (!fs::symbolic_link_exists(binary.toFilesystemEncoding()))
+               if (!binary.isSymLink())
                        break;
 
                FileName link;
@@ -538,8 +529,8 @@ get_system_support_dir(FileName const & abs_binary,
                }
 
                // Try and find "chkconfig.ltx".
-               FileName const lyxdir(
-                       normalizePath(addPath(binary_dir.absFilename(), relative_lyxdir)));
+               FileName const lyxdir(addPath(binary_dir.absFilename(),
+                       relative_lyxdir));
                searched_dirs.push_back(lyxdir);
 
                if (!fileSearch(lyxdir.absFilename(), chkconfig_ltx).empty()) {
@@ -556,7 +547,7 @@ get_system_support_dir(FileName const & abs_binary,
        // Everything has failed :-(
        // So inform the user and exit.
        string searched_dirs_str;
-       typedef std::list<FileName>::const_iterator iterator;
+       typedef list<FileName>::const_iterator iterator;
        iterator const begin = searched_dirs.begin();
        iterator const end = searched_dirs.end();
        for (iterator it = begin; it != end; ++it) {
@@ -584,26 +575,22 @@ get_system_support_dir(FileName const & abs_binary,
 // Returns the absolute path to the user lyxdir, together with a flag
 // indicating whether this directory was specified explicitly (as -userdir
 // or through an environment variable) or whether it was deduced.
-std::pair<FileName, bool> const
-get_user_support_dir(FileName const & default_user_support_dir,
-                    string const & command_line_user_support_dir)
+bool userSupportDir(FileName const & default_user_support_dir,
+       string const & command_line_user_support_dir, FileName & result)
 {
-       bool explicit_userdir = true;
-
        // 1. Use the -userdir command line parameter.
-       FileName path =
-               abs_path_from_command_line(command_line_user_support_dir);
-       if (!path.empty())
-               return std::make_pair(path, explicit_userdir);
+       result = abs_path_from_command_line(command_line_user_support_dir);
+       if (!result.empty())
+               return true;
 
        // 2. Use the LYX_USERDIR_15x environment variable.
-       path = extract_env_var_dir("LYX_USERDIR_15x");
-       if (!path.empty())
-               return std::make_pair(path, explicit_userdir);
+       result = extract_env_var_dir("LYX_USERDIR_15x");
+       if (!result.empty())
+               return true;
 
        // 3. Use the OS-dependent default_user_support_dir
-       explicit_userdir = false;
-       return std::make_pair(default_user_support_dir, explicit_userdir);
+       result = default_user_support_dir;
+       return false;
 }
 
 
@@ -695,8 +682,7 @@ bool check_env_var_dir(FileName const & dir,
 bool check_env_var_dir(FileName const & dir,
                       string const & env_var)
 {
-       string const encoded = dir.toFilesystemEncoding();
-       bool const success = (dir.exists() && fs::is_directory(encoded));
+       bool const success = dir.exists() && dir.isDirectory();
 
        if (!success) {
                // Put this string on a single line so that the gettext