]> git.lyx.org Git - features.git/commitdiff
OS Abstraction of "HOME" and the null device.
authorAngus Leeming <leeming@lyx.org>
Wed, 15 Dec 2004 19:35:43 +0000 (19:35 +0000)
committerAngus Leeming <leeming@lyx.org>
Wed, 15 Dec 2004 19:35:43 +0000 (19:35 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9376 a592a061-630c-0410-9148-cb99ea01b6c8

13 files changed:
src/ChangeLog
src/LaTeX.C
src/bufferlist.C
src/frontends/xforms/ChangeLog
src/frontends/xforms/FormFiledialog.C
src/lyx_main.C
src/support/ChangeLog
src/support/filetools.C
src/support/os.h
src/support/os_os2.C
src/support/os_unix.C
src/support/os_win32.C
src/support/path_defines.C.in

index c9fbafc9b236cdacafdd88d7c7349580e18fc91c..2dba8c29081c01d73d742a14a77eabcd3e59709d 100644 (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.
index d63ce35b994b8740e7c0e4f18b2fe36d1bde831a..8609c3ed53dc20f92c5167fc0305b71f8574d928 100644 (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);
 }
index 9eedebeffe85d29ab31e61d66f98691674297872..47c45028774724df68e408dc2fa868f6f082793f 100644 (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)) {
index 150bbb222bc7552f3b8f9aaa7896ade8a4ec3d61..a57c27380bf51af17cf88d67cbb127fd79973e4d 100644 (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"@
index 1c8aec402417cf13c4c52ed5313c3c84a7bed979..8a67e7192fe1584d075f742a5b4d3673f839e384 100644 (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;
index 879e9c2df6560862ac6feee6ae955ed82ad59053..a4113088c3a102e58e71efa1e0ff02873f510ba0 100644 (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;
index a3a774dd59555775e9b10558940a3748cd46b444..842d35d4caed9f5a5d569810455e08636e5e1cc9 100644 (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
index 776f89c1136d3e42e647c676310ae3c97d99d61b..78149fa4c57020d2c16bb47073b5435e8694cb3c 100644 (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))
index 331d61e9e81b8a7a637ce49953a61f6a3db7f6af..86b44e1bb7c347d578113f707d547c6a0b07298a 100644 (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();
 //
index 495a19e5ea00091f2bd934a3f60dad9e85082515..1b7c1465cc56c7895ac040c361aace2110f4c657 100644 (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_;
index 758ac1bfde0a350344ee5c582a93eb34ebf68717..1d13cd50861e4700bf102e1e819e35a9be269dd9 100644 (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;
index 109e5825bee906538c790e2a484dca341ecf4a43..862d7431642b3584fdaa40791e5493156e8ca7ef 100644 (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
index 873773b1793580303773bc0851bfe50330bbd655..e6b6e558755ae92f345d9973c0416aa1c80b9f65 100644 (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;
        }