OS Abstraction of "HOME" and the null device.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_3_X@9375 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2004-12-15 19:35:11 +00:00
parent 6793a2b9cd
commit c855de6c0d
12 changed files with 87 additions and 22 deletions

View File

@ -1,3 +1,11 @@
2004-12-14 Angus Leeming <leeming@lyx.org>
* LaTeX.C: (operator()): use os::nulldev() rather than "/dev/null".
* bufferlist.C (emergencyWrite):
* lyx_main.C (init, 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

@ -380,11 +380,7 @@ int LaTeX::run(TeXErrors & terr, LyXFunc * lfun)
int LaTeX::operator()()
{
#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

@ -36,6 +36,7 @@
#include "support/lyxmanip.h"
#include "support/lyxfunctional.h"
#include "support/LAssert.h"
#include "support/os.h"
#include <boost/bind.hpp>
#include "BoostFormat.h"
@ -359,7 +360,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-07 Angus Leeming <leeming@lyx.org>
* *.[Ch]: remove all traces of #pragma interface/implementation

View File

@ -26,6 +26,7 @@ using std::sort;
#include "support/FileInfo.h"
#include "support/lyxlib.h"
#include "support/lstrings.h"
#include "support/os.h"
#include "gettext.h"
#include "frontends/Dialogs.h"
#include "forms_gettext.h"
@ -535,7 +536,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_->SetMask(fl_get_input(file_dlg_form_->PatBox));
current_dlg_->Reread();
break;

View File

@ -434,8 +434,8 @@ void LyX::init(bool gui)
// default behaviour
if (user_lyxdir.empty())
user_lyxdir = AddPath(GetEnvPath("HOME"),
string(".") + PACKAGE);
user_lyxdir = AddPath(os::homepath(),
string(".") + PACKAGE);
explicit_userdir = false;
}
@ -643,7 +643,7 @@ void LyX::queryUserLyXDir(bool explicit_userdir)
_("Should I try to set it up for you (recommended)?"))) {
lyxerr << _("Running without personal LyX directory.") << endl;
// No, let's use $HOME instead.
user_lyxdir = GetEnvPath("HOME");
user_lyxdir = os::homepath();
return;
}
@ -660,7 +660,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();
#if USE_BOOST_FORMAT
lyxerr << boost::format(_("Failed. Will use %1$s instead."))
% user_lyxdir

View File

@ -1,3 +1,14 @@
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): 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

@ -730,7 +730,7 @@ string const ExpandPath(string const & path)
return lyx::getcwd() /*GetCWD()*/ + '/' + RTemp;
}
if (Temp == "~") {
return GetEnvPath("HOME") + '/' + RTemp;
return os::homepath() + '/' + RTemp;
}
if (Temp == "..") {
return MakeAbsPath(copy);
@ -1213,7 +1213,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

@ -18,17 +18,20 @@ public:
static void init(int argc, char * argv[]);
//
static string binpath() {return binpath_;}
static string const & binpath() {return binpath_;}
//
static string binname() {return binname_;}
static string const & binname() {return binname_;}
//
static string const & homepath() {return homepath_;}
//
static string const & nulldev() {return nulldev_;}
// system_tempdir actually doesn't belong here.
// I put it here only to avoid a global variable.
static void setTmpDir(string p) {tmpdir_ = p;}
//
static string getTmpDir() {return tmpdir_;}
static string const & getTmpDir() {return tmpdir_;}
//
static string current_root();
@ -59,6 +62,8 @@ private:
static string binpath_;
static string binname_;
static string tmpdir_;
static string homepath_;
static string nulldev_;
static os::shell_type _shell;
// Used only on OS/2 to determine file system encoding.
static unsigned long cp_;

View File

@ -14,7 +14,9 @@
string os::binpath_ = string();
string os::binname_ = string();
string os::tmpdir_ = string();
string os::tmpdir_;
string os::homepath_;
string os::nulldev_;
os::shell_type os::_shell = os::UNIX;
unsigned long os::cp_ = 0;
@ -63,6 +65,10 @@ void os::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";
}
void os::warn(string /*mesg*/) {

View File

@ -9,7 +9,9 @@
string os::binpath_ = string();
string os::binname_ = string();
string os::tmpdir_ = string();
string os::tmpdir_;
string os::homepath_;
string os::nulldev_;
os::shell_type os::_shell = os::UNIX;
unsigned long os::cp_ = 0;
@ -37,6 +39,10 @@ void os::init(int /*argc*/, char * argv[]) /* :cp_(0), _shell(os::UNIX) */
if (suffixIs(tmp, "/.libs/"))
tmp.erase(tmp.length() - 6, string::npos);
binpath_ = tmp;
tmpdir_ = "/tmp";
homepath_ = GetEnvPath("HOME");
nulldev_ = "/dev/null";
}
void os::warn(string /*mesg*/) {

View File

@ -10,13 +10,26 @@
#include <windows.h>
#include <io.h>
#include <sys/cygwin.h>
#include <fcntl.h>
#ifdef __CYGWIN__
#include <sys/cygwin.h>
#include <cstdlib>
#endif
string os::binpath_ = string();
string os::binname_ = string();
string os::tmpdir_ = string();
string os::tmpdir_;
string os::homepath_;
string os::nulldev_;
#ifdef __CYGWIN__
os::shell_type os::_shell = os::UNIX;
#else
os::shell_type os::_shell = os::CMD_EXE;
#endif
unsigned long os::cp_ = 0;
using std::endl;
@ -43,12 +56,25 @@ void os::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
// Use own tempdir
tmp.erase(tmp.length()-4,4);
tmpdir_ = tmp + "tmp";
homepath_ = GetEnvPath("HOMEDRIVE") + GetEnvPath("HOMEPATH");
nulldev_ = "nul";
#endif
}
void os::warn(string mesg) {
MessageBox(0, mesg.c_str(), "LyX error",
MB_OK|MB_ICONSTOP|MB_SYSTEMMODAL);
}
}
string os::current_root() {
return string("/");