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"
22 #if defined(__CYGWIN__) || defined(__CYGWIN32__)
23 # include <sys/cygwin.h>
26 # include <direct.h> // _getdrive
37 void init(int, char *[])
43 #if defined(__CYGWIN__) || defined(__CYGWIN32__)
47 // _getdrive returns the current drive (1=A, 2=B, and so on).
48 char const drive = ::_getdrive() + 'A' - 1;
49 return string(1, drive) + ":/";
54 string::size_type common_path(string const & p1, string const & p2)
56 string::size_type i = 0;
57 string::size_type p1_len = p1.length();
58 string::size_type p2_len = p2.length();
59 while (i < p1_len && i < p2_len && uppercase(p1[i]) == uppercase(p2[i]))
61 if ((i < p1_len && i < p2_len)
62 || (i < p1_len && p1[i] != '/' && i == p2_len)
63 || (i < p2_len && p2[i] != '/' && i == p1_len))
66 --i; // here was the last match
67 while (i && p1[i] != '/')
74 string external_path(string const & p)
78 #if defined(__CYGWIN__) || defined(__CYGWIN32__)
79 // Translate from cygwin path syntax to dos path syntax
80 if (is_absolute_path(p)) {
82 cygwin_conv_to_full_win32_path(p.c_str(), dp);
83 dos_path = !dp ? "" : dp;
87 #else // regular Win32
91 //No backslashes in LaTeX files
92 dos_path = subst(dos_path,'\\','/');
95 << "<Win32 path correction> ["
97 << dos_path << ']' << endl;
102 // (Claus H.) Parsing the latex log file in an Win32 environment all
103 // files are mentioned in Win32/DOS syntax. Because LyX uses the dep file
104 // entries to check if any file has been changed we must retranslate
105 // the Win32/DOS pathnames into Cygwin pathnames.
106 string internal_path(string const & p)
108 #if defined(__CYGWIN__) || defined(__CYGWIN32__)
109 char posix_path[PATH_MAX];
110 posix_path[0] = '\0';
111 cygwin_conv_to_posix_path(p.c_str(), posix_path);
114 return subst(p,"\\","/");
119 // (Claus H.) On Win32 both Unix and Win32/DOS pathnames are used.
120 // Therefore an absolute path could be either a pathname starting
121 // with a slash (Unix) or a pathname starting with a drive letter
122 // followed by a colon. Because a colon is not valid in pathes in Unix
123 // and at another location in Win32 testing just for the existance
124 // of the colon in the 2nd position seems to be enough!
125 bool is_absolute_path(string const & p)
130 bool isDosPath = (p.length() > 1 && p[1] == ':');
131 bool isUnixPath = (p[0] == '/');
133 return isDosPath || isUnixPath;
137 // returns a string suitable to be passed to popen when
139 char const * popen_read_mode()
145 string const & nulldev()
147 #if defined(__CYGWIN__) || defined(__CYGWIN32__)
148 static string const nulldev_ = "/dev/null";
150 static string const nulldev_ = "nul";
158 #if defined(__CYGWIN__) || defined(__CYGWIN32__)
166 } // namespace support