3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Ruurd A. Reitsma
8 * Full author contact details are available in file CREDITS.
10 * Various OS specific functions
15 #include "support/os.h"
16 #include "support/filetools.h"
17 #define INCL_DOSFILEMGR
18 #define INCL_DOSMODULEMGR
19 #define INCL_DOSPROCESS
21 #define INCL_DOSERRORS
31 shell_type shell_ = UNIX;
32 unsigned long cp_ = 0;
37 void init(int argc, char * argv[])
39 _wildcard(&argc, &argv);
40 PTIB ptib = new TIB[1];
41 PPIB ppib = new PIB[1];
42 APIRET rc = DosGetInfoBlocks(&ptib, &ppib);
46 // OS/2 cmd.exe has another use for '&'
47 string sh = OnlyFilename(getEnvPath("EMXSHELL"));
49 // COMSPEC is set, unless user unsets
50 sh = OnlyFilename(getEnvPath("COMSPEC"));
54 sh = lowercase(sh); // DosMapCase() is an overkill here
55 if (contains(sh, "cmd.exe") || contains(sh, "4os2.exe"))
60 static bool initialized = false;
65 ULONG CPList[3] = {0};
67 APIRET rc = DosQueryCp(3 * sizeof(ULONG), CPList, &CPList_size);
70 // CPList[0] == process current codepage,
71 // CPList[1] == system default codepage, the rest are auxilary.
72 // Once cp_ is correctly set, you can call other routines.
82 rc = DosQueryCurrentDisk(&drv_num, &drv_map);
85 char drive = 'A' + drv_num -1;
92 string::size_type common_path(string const & p1, string const & p2)
94 static bool initialized = false;
102 cntry.codepage = cp_;
103 string temp1 = internal_path(p1);
104 string temp2 = internal_path(p2);
105 char * tmp1 = const_cast<char *> (temp1.c_str());
106 char * tmp2 = const_cast<char *> (temp2.c_str());
107 /* rc = */ DosMapCase(p1.length(), &cntry, tmp1);
108 // if (rc != NO_ERROR)
110 /* rc = */ DosMapCase(p2.length(), &cntry, tmp2);
111 // if (rc != NO_ERROR)
113 // This algorithm works only if paths are slashified on DBCS systems.
114 string::size_type i = 0;
115 string::size_type p1_len = p1.length();
116 string::size_type p2_len = p2.length();
117 while (i < p1_len && i < p2_len && tmp1[i] == tmp2[i])
119 if ((i < p1_len && i < p2_len)
120 || (i < p1_len && tmp1[i] != '/' && i == p2_len)
121 || (i < p2_len && tmp2[i] != '/' && i == p1_len))
124 --i; // here was the last match
125 while (i && tmp1[i] != '/')
132 string internal_path(string const & p)
134 static bool initialized = false;
135 static bool leadbyte[256] = {false};
140 cntry.codepage = cp_;
141 unsigned char *DBCSinfo = new unsigned char[12];
142 /* rc = */ DosQueryDBCSEnv(12, &cntry, (char*) DBCSinfo);
143 // if (rc != NO_ERROR)
145 for (int j = 1; j < 12; j += 2)
148 bool isLeadByte = false;
149 while (*DBCSinfo != 0) {
150 if (i == *DBCSinfo) {
151 isLeadByte = !isLeadByte;
154 leadbyte[i++] = isLeadByte;
158 string::iterator lit = p.begin();
159 string::iterator end = p.end();
160 for (; lit < end; ++lit) {
161 if (leadbyte[(*lit)])
166 p = subst(p, "//", "/");
171 string external_path(string const & p)
177 bool is_absolute_path(string const & p)
179 return (p.length() > 1
180 && isalpha(static_cast<unsigned char>(p[0]))
185 // returns a string suitable to be passed to popen when
187 char const * popen_read_mode()
193 string const & nulldev()
195 static string const nulldev_ = "null";
206 char path_separator()
212 void cygwin_path_fix(bool)
216 } // namespace support