2003-06-18 09:56:10 +00:00
|
|
|
/**
|
|
|
|
* \file os_unix.C
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Ruurd A. Reitsma
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-06-18 09:56:10 +00:00
|
|
|
*
|
|
|
|
* Various OS specific functions
|
|
|
|
*/
|
2001-05-17 15:11:01 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2004-11-07 13:22:51 +00:00
|
|
|
#include "support/os.h"
|
2001-05-17 15:11:01 +00:00
|
|
|
#include "support/filetools.h"
|
2001-07-29 15:34:18 +00:00
|
|
|
#include "support/lstrings.h"
|
2001-05-17 15:11:01 +00:00
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
|
2003-02-10 10:22:05 +00:00
|
|
|
namespace {
|
2001-05-17 15:11:01 +00:00
|
|
|
|
2003-02-10 10:22:05 +00:00
|
|
|
string binpath_;
|
|
|
|
string binname_;
|
|
|
|
string tmpdir_;
|
2004-12-15 19:35:43 +00:00
|
|
|
string homepath_;
|
|
|
|
string nulldev_;
|
2003-02-10 10:22:05 +00:00
|
|
|
|
|
|
|
}
|
2001-05-17 15:11:01 +00:00
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace support {
|
2003-02-10 10:22:05 +00:00
|
|
|
namespace os {
|
|
|
|
|
2004-12-14 16:20:07 +00:00
|
|
|
void init(int /*argc*/, char * argv[])
|
2003-02-10 10:22:05 +00:00
|
|
|
{
|
|
|
|
static bool initialized = false;
|
2001-05-17 15:11:01 +00:00
|
|
|
if (initialized)
|
|
|
|
return;
|
|
|
|
initialized = true;
|
2003-02-10 10:22:05 +00:00
|
|
|
|
2004-12-14 16:20:07 +00:00
|
|
|
string tmp = argv[0];
|
2001-05-17 15:11:01 +00:00
|
|
|
binname_ = OnlyFilename(tmp);
|
|
|
|
tmp = ExpandPath(tmp); // This expands ./ and ~/
|
2003-02-10 10:22:05 +00:00
|
|
|
if (!is_absolute_path(tmp)) {
|
2001-05-17 15:11:01 +00:00
|
|
|
string binsearchpath = GetEnvPath("PATH");
|
|
|
|
// This will make "src/lyx" work always :-)
|
|
|
|
binsearchpath += ";.";
|
|
|
|
tmp = FileOpenSearch(binsearchpath, tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = MakeAbsPath(OnlyPath(tmp));
|
|
|
|
|
|
|
|
// In case we are running in place and compiled with shared libraries
|
|
|
|
if (suffixIs(tmp, "/.libs/"))
|
2001-10-08 14:09:06 +00:00
|
|
|
tmp.erase(tmp.length() - 6, string::npos);
|
2001-05-17 15:11:01 +00:00
|
|
|
binpath_ = tmp;
|
2004-12-15 19:35:43 +00:00
|
|
|
|
|
|
|
tmpdir_ = "/tmp";
|
|
|
|
homepath_ = GetEnvPath("HOME");
|
|
|
|
nulldev_ = "/dev/null";
|
2001-05-17 15:11:01 +00:00
|
|
|
}
|
|
|
|
|
2003-02-10 10:22:05 +00:00
|
|
|
|
|
|
|
void warn(string const & /*mesg*/)
|
|
|
|
{
|
2001-05-17 15:11:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-02-10 10:22:05 +00:00
|
|
|
|
|
|
|
string current_root()
|
|
|
|
{
|
|
|
|
return "/";
|
2001-05-17 15:11:01 +00:00
|
|
|
}
|
|
|
|
|
2003-02-10 10:22:05 +00:00
|
|
|
|
|
|
|
string::size_type common_path(string const & p1, string const & p2)
|
|
|
|
{
|
|
|
|
string::size_type i = 0;
|
|
|
|
string::size_type p1_len = p1.length();
|
|
|
|
string::size_type p2_len = p2.length();
|
|
|
|
while (i < p1_len && i < p2_len && p1[i] == p2[i])
|
|
|
|
++i;
|
2001-05-17 15:11:01 +00:00
|
|
|
if ((i < p1_len && i < p2_len)
|
|
|
|
|| (i < p1_len && p1[i] != '/' && i == p2_len)
|
2003-02-10 10:22:05 +00:00
|
|
|
|| (i < p2_len && p2[i] != '/' && i == p1_len))
|
|
|
|
{
|
|
|
|
if (i)
|
|
|
|
--i; // here was the last match
|
|
|
|
while (i && p1[i] != '/')
|
|
|
|
--i;
|
2001-05-17 15:11:01 +00:00
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2003-02-10 10:22:05 +00:00
|
|
|
|
|
|
|
string external_path(string const & p)
|
|
|
|
{
|
2001-05-17 15:11:01 +00:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2003-02-10 10:22:05 +00:00
|
|
|
|
|
|
|
string internal_path(string const & p)
|
|
|
|
{
|
2001-10-04 09:57:02 +00:00
|
|
|
return p;
|
|
|
|
}
|
2001-10-08 14:09:06 +00:00
|
|
|
|
2003-02-10 10:22:05 +00:00
|
|
|
|
|
|
|
bool is_absolute_path(string const & p)
|
2001-10-08 14:09:06 +00:00
|
|
|
{
|
2003-02-10 10:22:05 +00:00
|
|
|
return !p.empty() && p[0] == '/';
|
2001-10-08 14:09:06 +00:00
|
|
|
}
|
2002-02-08 14:32:17 +00:00
|
|
|
|
2003-02-10 10:22:05 +00:00
|
|
|
|
|
|
|
char const * popen_read_mode()
|
2002-02-08 14:32:17 +00:00
|
|
|
{
|
|
|
|
return "r";
|
|
|
|
}
|
2002-09-23 16:03:11 +00:00
|
|
|
|
2003-02-10 10:22:05 +00:00
|
|
|
|
2004-12-15 19:35:43 +00:00
|
|
|
string const & binpath()
|
2002-09-23 16:03:11 +00:00
|
|
|
{
|
2003-02-10 10:22:05 +00:00
|
|
|
return binpath_;
|
2002-09-23 16:03:11 +00:00
|
|
|
}
|
2003-02-10 10:22:05 +00:00
|
|
|
|
|
|
|
|
2004-12-15 19:35:43 +00:00
|
|
|
string const & binname()
|
2003-02-10 10:22:05 +00:00
|
|
|
{
|
|
|
|
return binname_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void setTmpDir(string const & p)
|
|
|
|
{
|
|
|
|
tmpdir_ = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-12-15 19:35:43 +00:00
|
|
|
string const & getTmpDir()
|
2003-02-10 10:22:05 +00:00
|
|
|
{
|
|
|
|
return tmpdir_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-12-15 19:35:43 +00:00
|
|
|
string const & homepath()
|
|
|
|
{
|
|
|
|
return homepath_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string const & nulldev()
|
|
|
|
{
|
|
|
|
return nulldev_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-10 10:22:05 +00:00
|
|
|
shell_type shell()
|
|
|
|
{
|
|
|
|
return UNIX;
|
|
|
|
}
|
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
} // namespace os
|
|
|
|
} // namespace support
|
|
|
|
} // namespace lyx
|