2003-06-18 09:56:10 +00:00
|
|
|
/**
|
|
|
|
* \file os_win32.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>
|
|
|
|
|
|
|
|
#include "os.h"
|
|
|
|
#include "support/filetools.h"
|
2001-12-20 16:27:02 +00:00
|
|
|
#include "support/lstrings.h"
|
|
|
|
#include "debug.h"
|
2001-05-17 15:11:01 +00:00
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <io.h>
|
|
|
|
#include <sys/cygwin.h>
|
|
|
|
|
2003-07-01 21:31:06 +00:00
|
|
|
using namespace lyx::support;
|
2003-02-10 10:22:05 +00:00
|
|
|
using std::endl;
|
2003-10-08 08:38:05 +00:00
|
|
|
using std::string;
|
2001-05-17 15:11:01 +00:00
|
|
|
|
|
|
|
|
2003-02-10 10:22:05 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
string binpath_;
|
|
|
|
string binname_;
|
|
|
|
string tmpdir_;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-02-11 10:07:28 +00:00
|
|
|
|
2003-07-01 21:31:06 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace support {
|
2003-02-10 10:22:05 +00:00
|
|
|
namespace os {
|
|
|
|
|
|
|
|
void init(int * /* argc */, char ** argv[])
|
|
|
|
{
|
2001-05-17 15:11:01 +00:00
|
|
|
static bool initialized = false;
|
2003-02-10 10:22:05 +00:00
|
|
|
if (initialized)
|
|
|
|
return;
|
2001-05-17 15:11:01 +00:00
|
|
|
initialized = true;
|
2003-02-10 10:22:05 +00:00
|
|
|
|
2001-05-17 15:11:01 +00:00
|
|
|
string tmp = *argv[0];
|
|
|
|
binname_ = OnlyFilename(tmp);
|
|
|
|
tmp = ExpandPath(tmp); // This expands ./ and ~/
|
|
|
|
|
2001-10-08 14:09:06 +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 = *argv[0];
|
|
|
|
tmp = FileOpenSearch(binsearchpath, tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = MakeAbsPath(OnlyPath(tmp));
|
|
|
|
|
|
|
|
// In case we are running in place and compiled with shared libraries
|
|
|
|
if (suffixIs(tmp, "/.libs/"))
|
|
|
|
tmp.erase(tmp.length()-6, string::npos);
|
|
|
|
binpath_ = tmp;
|
|
|
|
}
|
|
|
|
|
2003-02-10 10:22:05 +00:00
|
|
|
|
|
|
|
void warn(string const & mesg)
|
|
|
|
{
|
2001-05-17 15:11:01 +00:00
|
|
|
MessageBox(0, mesg.c_str(), "LyX error",
|
|
|
|
MB_OK|MB_ICONSTOP|MB_SYSTEMMODAL);
|
2003-02-10 10:22:05 +00:00
|
|
|
}
|
|
|
|
|
2001-05-17 15:11:01 +00:00
|
|
|
|
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 && uppercase(p1[i]) == uppercase(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 slashify_path(string const & p)
|
|
|
|
{
|
|
|
|
return subst(p, '\\', '/');
|
2001-05-17 15:11:01 +00:00
|
|
|
}
|
|
|
|
|
2003-02-10 10:22:05 +00:00
|
|
|
|
|
|
|
string external_path(string const & p)
|
|
|
|
{
|
|
|
|
string dos_path = p;
|
2001-10-08 14:09:06 +00:00
|
|
|
if (is_absolute_path(p)) {
|
2001-05-17 15:11:01 +00:00
|
|
|
char dp[255];
|
|
|
|
cygwin_conv_to_full_win32_path(p.c_str(), dp);
|
2003-02-10 10:22:05 +00:00
|
|
|
dos_path = subst(dp,'\\','/');
|
2001-05-17 15:11:01 +00:00
|
|
|
}
|
|
|
|
lyxerr[Debug::LATEX]
|
|
|
|
<< "<Win32 path correction> ["
|
|
|
|
<< p << "]->>["
|
2002-11-27 10:30:28 +00:00
|
|
|
<< dos_path << ']' << endl;
|
2001-05-17 15:11:01 +00:00
|
|
|
return dos_path;
|
2001-10-04 09:57:02 +00:00
|
|
|
}
|
|
|
|
|
2001-10-08 14:09:06 +00:00
|
|
|
|
2001-10-04 09:57:02 +00:00
|
|
|
// (Claus H.) Parsing the latex log file in an Win32 environment all
|
|
|
|
// files are mentioned in Win32/DOS syntax. Because LyX uses the dep file
|
|
|
|
// entries to check if any file has been changed we must retranslate
|
|
|
|
// the Win32/DOS pathnames into Cygwin pathnames.
|
2003-02-10 10:22:05 +00:00
|
|
|
string internal_path(string const & p)
|
|
|
|
{
|
2001-10-04 09:57:02 +00:00
|
|
|
char pp[256];
|
|
|
|
cygwin_conv_to_posix_path(p.c_str(), pp);
|
|
|
|
string const posix_path = MakeLatexName(pp);
|
|
|
|
lyxerr[Debug::DEPEND]
|
|
|
|
<< "<Win32 path correction> ["
|
|
|
|
<< p << "]->>["
|
2002-11-27 10:30:28 +00:00
|
|
|
<< posix_path << ']' << endl;
|
2001-10-04 09:57:02 +00:00
|
|
|
return posix_path;
|
|
|
|
}
|
2001-10-08 14:09:06 +00:00
|
|
|
|
2003-02-10 10:22:05 +00:00
|
|
|
|
2001-10-08 14:09:06 +00:00
|
|
|
// (Claus H.) On Win32 both Unix and Win32/DOS pathnames are used.
|
|
|
|
// Therefore an absolute path could be either a pathname starting
|
|
|
|
// with a slash (Unix) or a pathname starting with a drive letter
|
|
|
|
// followed by a colon. Because a colon is not valid in pathes in Unix
|
|
|
|
// and at another location in Win32 testing just for the existance
|
|
|
|
// of the colon in the 2nd position seems to be enough!
|
2003-02-10 10:22:05 +00:00
|
|
|
bool is_absolute_path(string const & p)
|
2001-10-08 14:09:06 +00:00
|
|
|
{
|
|
|
|
if (p.empty())
|
|
|
|
return false;
|
|
|
|
|
2001-12-20 16:27:02 +00:00
|
|
|
bool isDosPath = (p.length() > 1 && p[1] == ':');
|
|
|
|
bool isUnixPath = (p[0] == '/');
|
2001-10-08 14:09:06 +00:00
|
|
|
|
2003-02-10 10:22:05 +00:00
|
|
|
return isDosPath || isUnixPath;
|
2001-10-08 14:09:06 +00:00
|
|
|
}
|
2002-02-08 14:32:17 +00:00
|
|
|
|
2002-09-23 16:03:11 +00:00
|
|
|
|
|
|
|
// returns a string suitable to be passed to popen when
|
|
|
|
// reading a pipe
|
2003-02-10 10:22:05 +00:00
|
|
|
char const * popen_read_mode()
|
2002-09-23 16:03:11 +00:00
|
|
|
{
|
|
|
|
return "r";
|
|
|
|
}
|
2003-02-10 10:22:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
string binpath()
|
|
|
|
{
|
|
|
|
return binpath_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string binname()
|
|
|
|
{
|
|
|
|
return binname_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void setTmpDir(string const & p)
|
|
|
|
{
|
|
|
|
tmpdir_ = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string getTmpDir()
|
|
|
|
{
|
|
|
|
return tmpdir_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
shell_type shell()
|
|
|
|
{
|
|
|
|
return UNIX;
|
|
|
|
}
|
|
|
|
|
2003-07-01 21:31:06 +00:00
|
|
|
} // namespace os
|
|
|
|
} // namespace support
|
|
|
|
} // namespace lyx
|