]> git.lyx.org Git - features.git/commitdiff
OS/2 patch from Miyata
authorLars Gullik Bjønnes <larsbj@gullik.org>
Mon, 1 Nov 1999 04:22:28 +0000 (04:22 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Mon, 1 Nov 1999 04:22:28 +0000 (04:22 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@270 a592a061-630c-0410-9148-cb99ea01b6c8

ChangeLog
src/lyx_cb.C
src/lyxserver.C
src/support/filetools.C
src/support/lyxlib.h
src/support/path.h

index 58772aa88632f800cab4eb988d55e7f72cf81139..2727b6760b43f0c51699c51d44c5151ee7aecf72 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+1999-11-01  Lars Gullik Bjønnes  <larsbj@lyx.org>
+
+       * added patch for OS/2 from SMiyata.
+
 1999-10-28  Jean-Marc Lasgouttes  <Jean-Marc.Lasgouttes@inria.fr>
 
        * src/support/syscall.C (Systemcalls::kill): 
index 8b46912c9bd9ceb136885cc7c151b3f51bb408d1..7adbc5328f0efa82dbb1baebe2cbec9a2822dc8d 100644 (file)
@@ -601,8 +601,9 @@ bool RunScript(Buffer *buffer, bool wait,
                                if (sh.empty())
                                        sh = "cmd.exe";
                        }
-                        sh = lowercase(sh);
-                        if (sh.contains("cmd.exe") || sh.contains("4os2.exe"))
+                        sh = lowercase(sh);
+                        if (contains(sh, "cmd.exe")
+                           || contains(sh, "4os2.exe"))
                                 cmd = "start /min/n " + cmd;
                         else
                                 cmd += " &";
@@ -1076,13 +1077,14 @@ Buffer * NewLyxFile(string const & filename)
 {
        // Split argument by :
        string name;
-       string tmpname=split(filename, name, ':');
+       string tmpname = split(filename, name, ':');
 #ifdef __EMX__ // Fix me! lyx_cb.C may not be low level enough to allow this.
-       if (name.length() == 1 && isalpha((unsigned char) name[0]) &&
-           (tmpname.prefixIs("/") || tmpname.prefixIs("\\"))) {
+       if (name.length() == 1
+           && isalpha(static_cast<unsigned char>(name[0]))
+           && (prefixIs(tmpname, "/") || prefixIs(tmpname, "\\"))) {
                name += ':';
-               name += tmpname.token(':');
-               tmpname = split(tmpname, ':');
+               name += token(tmpname, ':', 0);
+               tmpname = split(tmpname, ':');
        }
 #endif
        lyxerr.debug() << "Arg is " << filename
index 719412757e8930080993a5691f35a3dabbed1ee7..9dafa73de03d39f75f065451b9873495829a8f23 100644 (file)
@@ -139,8 +139,8 @@ void LyXComm::openConnection() {
        rc = DosConnectNPipe(fd);
        if (rc != NO_ERROR && rc != ERROR_PIPE_NOT_CONNECTED) {
                errnum = TranslateOS2Error(rc);
-               lyxerr <<"LyXComm: Could not create pipe " + tmp);
-               lyxerr <<strerror(errnum);
+               lyxerr <<"LyXComm: Could not create pipe " << tmp
+                      << strerror(errnum) << endl;
                return;
        };
        // Imported handles can be used both with OS/2 APIs and emx
@@ -386,8 +386,8 @@ void LyXComm::send(string const & msg) {
        rc = DosResetBuffer(outfd);     // To avoid synchronization problems.
        if (rc != NO_ERROR) {
                errnum = TranslateOS2Error(rc);
-               lyxerr <<"LyXComm: Message could not be flushed: " +msg);
-               lyxerr <<strerror(errnum));
+               lyxerr << "LyXComm: Message could not be flushed: " << msg
+                      << '\n' << strerror(errnum) << endl;
        }
 #endif
 }
index bc295d32c07bb1dc5f466b869bfd18034e4f439c..fe7c3d456cd7ca025fad31f1c94361c01a4814da 100644 (file)
@@ -28,6 +28,7 @@
 #include "support/path.h"        // I know it's OS/2 specific (SMiyata)
 #include "gettext.h"
 #include "LAssert.h"
+#include "lyxlib.h"
 
 // Which part of this is still necessary? (JMarc).
 #if HAVE_DIRENT_H
@@ -330,15 +331,7 @@ bool PutEnv(string const & envstr)
 
 bool PutEnvPath(string const & envstr)
 {
-        string pathlist = envstr;
-#ifdef WITH_WARNINGS
-#warning Verify that this is correct.
-#endif
-#ifdef __EMX__
-        pathlist = subst(pathlist, ':', ';');
-        pathlist = subst(pathlist, '/', '\\');
-#endif
-        return PutEnv(pathlist);
+        return PutEnv(envstr);
 }
 
 
@@ -386,14 +379,11 @@ string CreateTmpDir (string const & tempdir, string const & mask)
 static
 int DestroyTmpDir (string const & tmpdir, bool Allfiles)
 {
-       if ((Allfiles) && (DeleteAllFilesInDir (tmpdir))) return -1;
-       if (rmdir(tmpdir.c_str())) { 
 #ifdef __EMX__
-               if (errno == EBUSY) {
-                       chdir(user_lyxdir.c_str()); // They are in the same drive.
-                       if (!rmdir(tmpdir.c_str())) return 0;
-               }
+       Path p(user_lyxdir);
 #endif
+       if (Allfiles && DeleteAllFilesInDir(tmpdir)) return -1;
+       if (rmdir(tmpdir.c_str())) { 
                WriteFSAlert(_("Error! Couldn't delete temporary directory:"), 
                             tmpdir);
                return -1;
@@ -421,23 +411,17 @@ string CreateLyXTmpDir (string const & deflt)
        if ((!deflt.empty()) && (deflt  != "/tmp")) {
                if (mkdir (deflt.c_str(), 0777)) {
 #ifdef __EMX__
-                        PathPush(user_lyxdir);
+                        Path p(user_lyxdir);
 #endif
                        t = CreateTmpDir (deflt.c_str(), "lyx_tmp");
-#ifdef __EMX__
-                        PathPop();
-#endif
                         return t;
                } else
                         return deflt;
        } else {
 #ifdef __EMX__
-               PathPush(user_lyxdir);
+               Path p(user_lyxdir);
 #endif
                t = CreateTmpDir ("/tmp", "lyx_tmp");
-#ifdef __EMX__
-               PathPop();
-#endif
                return t;
        }
 }
@@ -473,15 +457,15 @@ string GetCWD ()
 {
        int n = 256;    // Assume path is less than 256 chars
        char * err;
-       char * tbuf = new char [n];
+       char * tbuf = new char[n];
        string result;
        
        // Safe. Hopefully all getcwds behave this way!
-       while (((err = getcwd (tbuf, n)) == 0) && (errno == ERANGE)) {
+       while (((err = lyx::getcwd (tbuf, n)) == 0) && (errno == ERANGE)) {
                // Buffer too small, double the buffersize and try again
                delete[] tbuf;
-               n = 2*n;
-               tbuf = new char [n];
+               n = 2 * n;
+               tbuf = new char[n];
        }
 
        if (err) result = tbuf;
@@ -498,7 +482,7 @@ string OnlyPath(string const & Filename)
 
        // Find last / or start of filename
        string::size_type j = Filename.rfind('/');
-       if (j==string::npos)
+       if (j == string::npos)
                return "./";
        return Filename.substr(0, j + 1);
 }
@@ -512,7 +496,7 @@ string MakeAbsPath(string const & RelPath, string const & BasePath)
        // checks for already absolute path
        if (AbsolutePath(RelPath))
 #ifdef __EMX__
-               if(RelPath[0]!='/' || RelPath[0]!='\\')
+               if(RelPath[0]!='/' && RelPath[0]!='\\')
 #endif
                return RelPath;
 
@@ -534,7 +518,7 @@ string MakeAbsPath(string const & RelPath, string const & BasePath)
                TempBase = GetCWD();
 #ifdef __EMX__
        if (AbsolutePath(TempRel))
-               return TempBase[0] + TempRel;
+               return TempBase.substr(0, 2) + TempRel;
 #endif
 
        // Handle /./ at the end of the path
@@ -554,13 +538,13 @@ string MakeAbsPath(string const & RelPath, string const & BasePath)
                        // Remove one level of TempBase
                        int i = TempBase.length()-2;
 #ifndef __EMX__
-                       if (i<0) i=0;
-                       while (i>0 && TempBase[i] != '/') --i;
-                       if (i>0)
+                       if (i < 0) i = 0;
+                       while (i > 0 && TempBase[i] != '/') --i;
+                       if (i > 0)
 #else
-                               if (i<2) i=2;
-                       while (i>2 && TempBase[i] != '/') --i;
-                       if (i>2)
+                       if (i < 2) i = 2;
+                       while (i > 2 && TempBase[i] != '/') --i;
+                       if (i > 2)
 #endif
                                TempBase.erase(i, string::npos);
                        else
@@ -619,7 +603,7 @@ bool AbsolutePath(string const & path)
 #ifndef __EMX__
        return (!path.empty() && path[0] == '/');
 #else
-       return (!path.empty() && path[0]=='/' || (isalpha((unsigned char) path[0]) && path[1]==':'));
+       return (!path.empty() && (path[0]=='/' || (isalpha((unsigned char) path[0]) && path.length()>1 && path[1]==':')));
 #endif
 }
 
index 87a5aaee80043f9170072a2cc42596dd3978b851..fc894c8707596fde1f18478b11af0d3b95ff4882 100644 (file)
@@ -13,6 +13,8 @@
 #define LYX_LIB_H
 
 #include <ctime>
+#include <unistd.h>
+
 #include "LString.h"
 #include "gettext.h"
 #include "support/filetools.h"
@@ -44,4 +46,22 @@ inline string getUserName()
                userName = _("unknown");
        return userName;
 }
+
+// This should have been a namespace
+struct lyx {
+       static char * getcwd(char * buffer, size_t size) {
+#ifndef __EMX__
+               return ::getcwd(buffer, size);
+#else
+               return ::_getcwd2(buffer, size);
+#endif
+       };
+       static chdir(const char * name) {
+#ifndef __EMX__
+               return ::chdir(name);
+#else
+               return ::_chdir2(name);
+#endif
+       };
+};
 #endif
index ad5a905b4008aa0989d14c68835a515fad08de20..532e808d4f819a9d95a365d5e910c63a3db48152 100644 (file)
@@ -7,6 +7,7 @@
 #include "gettext.h"
 #include "support/filetools.h"
 #include "lyx_gui_misc.h"
+#include "lyxlib.h"
 
 class Path {
 public:
@@ -16,7 +17,7 @@ public:
        {
                if (!path.empty()) { 
                        pushedDir_ = GetCWD();
-                       if (pushedDir_.empty() || chdir(path.c_str())) {
+                       if (pushedDir_.empty() || lyx::chdir(path.c_str())) {
                                WriteFSAlert(_("Error: Could not change to directory: "), 
                                             path);
                        }
@@ -37,7 +38,7 @@ public:
                                     pushedDir_);
                        return 0;
                }
-               if (chdir(pushedDir_.c_str())) {
+               if (lyx::chdir(pushedDir_.c_str())) {
                        WriteFSAlert(
                                _("Error: Could not change to directory: "), 
                                pushedDir_);