OS Abstraction of "HOME" and the null device.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9376 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2004-12-15 19:35:43 +00:00
parent b7e87f4b11
commit 4b7891d873
13 changed files with 117 additions and 21 deletions

View File

@ -1,3 +1,11 @@
2004-12-14 Angus Leeming <leeming@lyx.org>
* LaTeX.C: (startscript): use os::nulldev() rather than "/dev/null".
* bufferlist.C (emergencyWrite):
* lyx_main.C (queryUserLyXDir): use os::homepath(), not
GetEnvPath("HOME").
2004-12-14 Angus Leeming <leeming@lyx.org>
* main.C: (main): no longer pass pointers to os::init.

View File

@ -384,11 +384,7 @@ int LaTeX::run(TeXErrors & terr)
int LaTeX::startscript()
{
#ifndef __EMX__
string tmp = cmd + ' ' + QuoteName(file) + " > /dev/null";
#else // cmd.exe (OS/2) causes SYS0003 error at "/dev/null"
string tmp = cmd + ' ' + file + " > nul";
#endif
string tmp = cmd + ' ' + QuoteName(file) + " > " + os::nulldev();
Systemcall one;
return one.startscript(Systemcall::Wait, tmp);
}

View File

@ -27,6 +27,7 @@
#include "frontends/Alert.h"
#include "support/filetools.h"
#include "support/os.h"
#include <boost/bind.hpp>
@ -55,6 +56,7 @@ using std::vector;
using std::back_inserter;
using std::transform;
namespace os = lyx::support::os;
BufferList::BufferList()
{}
@ -309,7 +311,7 @@ void BufferList::emergencyWrite(Buffer * buf)
}
// 2) In HOME directory.
string s = AddName(GetEnvPath("HOME"), buf->fileName());
string s = AddName(os::homepath(), buf->fileName());
s += ".emergency";
lyxerr << ' ' << s << endl;
if (buf->writeFile(s)) {

View File

@ -1,3 +1,8 @@
2004-12-14 Angus Leeming <leeming@lyx.org>
* FormFiledialog.C: (FileDlgCB): use os::homepath(), not
GetEnvPath("HOME").
2004-12-05 Angus Leeming <leeming@lyx.org>
* pch.h: s@<X11/forms.h>@"lyx_forms.h"@

View File

@ -25,6 +25,7 @@
#include "support/globbing.h"
#include "support/lstrings.h"
#include "support/lyxlib.h"
#include "support/os.h"
#include "support/tostr.h"
#include "lyx_forms.h"
@ -82,6 +83,7 @@ using std::map;
using std::vector;
using namespace lyx::frontend;
namespace os = lyx::support::os;
namespace {
@ -617,7 +619,7 @@ void FileDialog::Private::FileDlgCB(FL_OBJECT *, long arg)
break;
case 11: // home
current_dlg_->SetDirectory(GetEnvPath("HOME"));
current_dlg_->SetDirectory(os::homepath());
current_dlg_->SetFilters(fl_get_input(file_dlg_form_->PatBox));
current_dlg_->Reread();
break;

View File

@ -77,6 +77,8 @@ using lyx::support::user_lyxdir;
using lyx::support::os::getTmpDir;
using lyx::support::os::setTmpDir;
namespace os = lyx::support::os;
using std::endl;
using std::string;
using std::vector;
@ -552,7 +554,7 @@ void LyX::queryUserLyXDir(bool explicit_userdir)
if (!createDirectory(user_lyxdir(), 0755)) {
// Failed, let's use $HOME instead.
user_lyxdir(GetEnvPath("HOME"));
user_lyxdir(os::homepath());
lyxerr << bformat(_("Failed. Will use %1$s instead."),
user_lyxdir()) << endl;
return;

View File

@ -1,3 +1,15 @@
2004-12-14 Angus Leeming <leeming@lyx.org>
* os.h, os_os2.C, os_unix.C, os_win32.C:
(binpath, binname, getTmpDir): return a const reference rather than
a copy of the data.
(homepath, nulldev): new functions returning the name of "HOME" and
the null device, respectively.
* filetools.C: (ExpandPath, MakeDisplayPath):
* path_defines.C.in (setLyxPaths): use os::homepath(), not
GetEnvPath("HOME").
2004-12-14 Angus Leeming <leeming@lyx.org>
* os.h, os_{os2,unix,win32}.C (init): change interface to no longer

View File

@ -690,7 +690,7 @@ string const ExpandPath(string const & path)
return getcwd() + '/' + RTemp;
}
if (Temp == "~") {
return GetEnvPath("HOME") + '/' + RTemp;
return os::homepath() + '/' + RTemp;
}
if (Temp == "..") {
return MakeAbsPath(copy);
@ -1111,7 +1111,7 @@ string const MakeDisplayPath(string const & path, unsigned int threshold)
{
string str = path;
string const home(GetEnvPath("HOME"));
string const home(os::homepath());
// replace /home/blah with ~/
if (prefixIs(str, home))

View File

@ -30,13 +30,17 @@ enum shell_type {
// do some work just once
void init(int argc, char * argv[]);
// returns path of LyX binary
std::string binpath();
std::string const & binpath();
// returns name of LyX binary
std::string binname();
std::string const & binname();
//
void setTmpDir(std::string const & p);
//
std::string getTmpDir();
std::string const & getTmpDir();
// Returns the user's home directory ($HOME in the unix world).
std::string const & homepath();
// Returns the name of the NULL device (/dev/null, null).
std::string const & nulldev();
//
std::string current_root();
//

View File

@ -30,6 +30,9 @@ namespace {
string binpath_;
string binname_;
string tmpdir_;
string homepath_;
string nulldev_;
os::shell_type shell_ = os::UNIX;
unsigned long cp_ = 0;
@ -86,6 +89,10 @@ void init(int argc, char * argv[])
// CPList[1] == system default codepage, the rest are auxilary.
// Once cp_ is correctly set, you can call other routines.
cp_ = CPList[1];
tmpdir_ = "/tmp";
homepath_ = GetEnvPath("HOME");
nulldev_ = "null";
}
@ -217,13 +224,13 @@ char const * popen_read_mode()
}
string binpath()
string const & binpath()
{
return binpath_;
}
string binname()
string const & binname()
{
return binname_;
}
@ -235,12 +242,24 @@ void setTmpDir(string const & p)
}
string getTmpDir()
string const & getTmpDir()
{
return tmpdir_;
}
string const & homepath()
{
return homepath_;
}
string const & nulldev()
{
return nulldev_;
}
shell_type shell()
{
return shell_;

View File

@ -25,6 +25,8 @@ namespace {
string binpath_;
string binname_;
string tmpdir_;
string homepath_;
string nulldev_;
}
@ -55,6 +57,10 @@ void init(int /*argc*/, char * argv[])
if (suffixIs(tmp, "/.libs/"))
tmp.erase(tmp.length() - 6, string::npos);
binpath_ = tmp;
tmpdir_ = "/tmp";
homepath_ = GetEnvPath("HOME");
nulldev_ = "/dev/null";
}
@ -120,13 +126,13 @@ char const * popen_read_mode()
}
string binpath()
string const & binpath()
{
return binpath_;
}
string binname()
string const & binname()
{
return binname_;
}
@ -138,12 +144,24 @@ void setTmpDir(string const & p)
}
string getTmpDir()
string const & getTmpDir()
{
return tmpdir_;
}
string const & homepath()
{
return homepath_;
}
string const & nulldev()
{
return nulldev_;
}
shell_type shell()
{
return UNIX;

View File

@ -32,6 +32,8 @@ namespace {
string binpath_;
string binname_;
string tmpdir_;
string homepath_;
string nulldev_;
}
@ -65,6 +67,16 @@ void init(int /* argc */, char * argv[])
if (suffixIs(tmp, "/.libs/"))
tmp.erase(tmp.length()-6, string::npos);
binpath_ = tmp;
#ifdef __CYGWIN__
tmpdir_ = "/tmp";
homepath_ = GetEnvPath("HOME");
nulldev_ = "/dev/null";
#else
tmpdir_ = string();
homepath_ = GetEnvPath("HOMEDRIVE") + GetEnvPath("HOMEPATH");
nulldev_ = "nul";
#endif
}
@ -190,9 +202,25 @@ string getTmpDir()
}
string const & homepath()
{
return homepath_;
}
string const & nulldev()
{
return nulldev_;
}
shell_type shell()
{
#ifdef __CYGWIN__
return UNIX;
#else
return CMD_EXE;
#endif
}
} // namespace os

View File

@ -356,10 +356,10 @@ bool setLyxPaths()
// default behaviour
if (user_lyxdir_.empty())
if (inOSXBundle)
user_lyxdir_ = AddPath(GetEnvPath("HOME"),
user_lyxdir_ = AddPath(os::homepath(),
"Library/Preferences/LyX");
else
user_lyxdir_ = AddPath(GetEnvPath("HOME"),
user_lyxdir_ = AddPath(os::homepath(),
string(".") + PACKAGE);
explicit_userdir = false;
}