]> git.lyx.org Git - lyx.git/blobdiff - src/support/os_os2.C
Remove executable status info from typeIndicator.
[lyx.git] / src / support / os_os2.C
index 2c3e8a300871523feced13cab453adf76670aebb..ac4b33e98f9d59e3d723d0490ddd957bcaf91b24 100644 (file)
@@ -12,7 +12,7 @@
 
 #include <config.h>
 
-#include "os.h"
+#include "support/os.h"
 #include "support/filetools.h"
 #define INCL_DOSFILEMGR
 #define INCL_DOSMODULEMGR
 #define INCL_DOSERRORS
 #include <os2.h>
 
+#include <boost/scoped_array.hpp>
+
+using boost::scoped_array;
+
 namespace {
 
 string binpath_;
 string binname_;
 string tmpdir_;
+string homepath_;
+string nulldev_;
+
 os::shell_type shell_ = os::UNIX;
 unsigned long cp_ = 0;
 
@@ -35,40 +42,38 @@ unsigned long cp_ = 0;
 namespace os {
 
 
-void init(int * argc, char ** argv[])
+void init(int argc, char * argv[])
 {
-       if (argc != 0 /* This is a hack! */) {
-               _wildcard(argc, argv);
-               PTIB ptib = new TIB[1];
-               PPIB ppib = new PIB[1];
-               APIRET rc = DosGetInfoBlocks(&ptib, &ppib);
-               if (rc != NO_ERROR)
-                       exit(rc);
-               char* tmp = new char[256];
-               // This is the only reliable way to retrieve the executable name.
-               rc = DosQueryModuleName(ppib->pib_hmte, 256L, tmp);
-               if (rc != NO_ERROR)
-                       exit(rc);
-               string p = tmp;
-               p = slashify_path(p);
-               binname_ = OnlyFilename(p);
-               binname_.erase(binname_.length()-4, string::npos);
-               binpath_ = OnlyPath(p);
-
-               // OS/2 cmd.exe has another use for '&'
-               string sh = OnlyFilename(GetEnvPath("EMXSHELL"));
-               if (sh.empty()) {
-                       // COMSPEC is set, unless user unsets
-                       sh = OnlyFilename(GetEnvPath("COMSPEC"));
-                       if (sh.empty())
-                               sh = "cmd.exe";
-               }
-               sh = lowercase(sh);     // DosMapCase() is an overkill here
-               if (contains(sh, "cmd.exe") || contains(sh, "4os2.exe"))
-                       shell_ = os::CMD_EXE;
-               else
-                       shell_ = os::UNIX;
+       _wildcard(&argc, &argv);
+       PTIB ptib = new TIB[1];
+       PPIB ppib = new PIB[1];
+       APIRET rc = DosGetInfoBlocks(&ptib, &ppib);
+       if (rc != NO_ERROR)
+               exit(rc);
+       scoped_array<char> tmp(new char[256]);
+       // This is the only reliable way to retrieve the executable name.
+       rc = DosQueryModuleName(ppib->pib_hmte, 256L, tmp);
+       if (rc != NO_ERROR)
+               exit(rc);
+       string p = tmp.get();
+       p = internal_path(p);
+       binname_ = OnlyFilename(p);
+       binname_.erase(binname_.length()-4, string::npos);
+       binpath_ = OnlyPath(p);
+
+       // OS/2 cmd.exe has another use for '&'
+       string sh = OnlyFilename(GetEnvPath("EMXSHELL"));
+       if (sh.empty()) {
+               // COMSPEC is set, unless user unsets
+               sh = OnlyFilename(GetEnvPath("COMSPEC"));
+               if (sh.empty())
+                       sh = "cmd.exe";
        }
+       sh = lowercase(sh);     // DosMapCase() is an overkill here
+       if (contains(sh, "cmd.exe") || contains(sh, "4os2.exe"))
+               shell_ = os::CMD_EXE;
+       else
+               shell_ = os::UNIX;
 
        static bool initialized = false;
        if (initialized)
@@ -84,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";
 }
 
 
@@ -119,8 +128,8 @@ string::size_type common_path(string const & p1, string const & p2)
        COUNTRYCODE cntry;
        cntry.country = 0;
        cntry.codepage = cp_;
-       string temp1 = slashify_path(p1);
-       string temp2 = slashify_path(p2);
+       string temp1 = internal_path(p1);
+       string temp2 = internal_path(p2);
        char * tmp1 = const_cast<char *> (temp1.c_str());
        char * tmp2 = const_cast<char *> (temp2.c_str());
        /* rc = */ DosMapCase(p1.length(), &cntry, tmp1);
@@ -148,7 +157,7 @@ string::size_type common_path(string const & p1, string const & p2)
 }
 
 
-string slashify_path(string const & p)
+string internal_path(string const & p)
 {
        static bool initialized = false;
        static bool leadbyte[256] = {false};
@@ -193,12 +202,6 @@ string external_path(string const & p)
 }
 
 
-string internal_path(string const & p)
-{
-       return p;
-}
-
-
 bool is_absolute_path(string const & p)
 {
        return (p.length() > 1
@@ -215,13 +218,13 @@ char const * popen_read_mode()
 }
 
 
-string binpath()
+string const & binpath()
 {
        return binpath_;
 }
 
 
-string binname()
+string const & binname()
 {
        return binname_;
 }
@@ -233,12 +236,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_;