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/lstrings.h"
23 #if defined(__CYGWIN__) || defined(__CYGWIN32__)
24 # include <sys/cygwin.h>
27 # include <direct.h> // _getdrive
38 void init(int, char *[])
44 #if defined(__CYGWIN__) || defined(__CYGWIN32__)
48 // _getdrive returns the current drive (1=A, 2=B, and so on).
49 char const drive = ::_getdrive() + 'A' - 1;
50 return string(1, drive) + ":/";
55 string::size_type common_path(string const & p1, string const & p2)
57 string::size_type i = 0;
58 string::size_type p1_len = p1.length();
59 string::size_type p2_len = p2.length();
60 while (i < p1_len && i < p2_len && uppercase(p1[i]) == uppercase(p2[i]))
62 if ((i < p1_len && i < p2_len)
63 || (i < p1_len && p1[i] != '/' && i == p2_len)
64 || (i < p2_len && p2[i] != '/' && i == p1_len))
67 --i; // here was the last match
68 while (i && p1[i] != '/')
75 string external_path(string const & p)
79 #if defined(__CYGWIN__) || defined(__CYGWIN32__)
80 // Translate from cygwin path syntax to dos path syntax
81 if (is_absolute_path(p)) {
83 cygwin_conv_to_full_win32_path(p.c_str(), dp);
84 dos_path = !dp ? "" : dp;
88 #else // regular Win32
92 //No backslashes in LaTeX files
93 dos_path = subst(dos_path,'\\','/');
96 << "<Win32 path correction> ["
98 << dos_path << ']' << endl;
103 // (Claus H.) Parsing the latex log file in an Win32 environment all
104 // files are mentioned in Win32/DOS syntax. Because LyX uses the dep file
105 // entries to check if any file has been changed we must retranslate
106 // the Win32/DOS pathnames into Cygwin pathnames.
107 string internal_path(string const & p)
109 #if defined(__CYGWIN__) || defined(__CYGWIN32__)
110 char posix_path[PATH_MAX];
111 posix_path[0] = '\0';
112 cygwin_conv_to_posix_path(p.c_str(), posix_path);
115 return subst(p,"\\","/");
120 // (Claus H.) On Win32 both Unix and Win32/DOS pathnames are used.
121 // Therefore an absolute path could be either a pathname starting
122 // with a slash (Unix) or a pathname starting with a drive letter
123 // followed by a colon. Because a colon is not valid in pathes in Unix
124 // and at another location in Win32 testing just for the existance
125 // of the colon in the 2nd position seems to be enough!
126 bool is_absolute_path(string const & p)
131 bool isDosPath = (p.length() > 1 && p[1] == ':');
132 bool isUnixPath = (p[0] == '/');
134 return isDosPath || isUnixPath;
138 // returns a string suitable to be passed to popen when
140 char const * popen_read_mode()
146 string const & nulldev()
148 #if defined(__CYGWIN__) || defined(__CYGWIN32__)
149 static string const nulldev_ = "/dev/null";
151 static string const nulldev_ = "nul";
159 #if defined(__CYGWIN__) || defined(__CYGWIN32__)
166 char path_separator()
176 } // namespace support