1 // os_win32.C copyright "Ruurd A. Reitsma" <R.A.Reitsma@wbmt.tudelft.nl>
3 // Various OS specific functions
7 #include "support/filetools.h"
8 #include "support/lstrings.h"
13 #include <sys/cygwin.h>
29 void init(int * /* argc */, char ** argv[])
31 static bool initialized = false;
36 string tmp = *argv[0];
37 binname_ = OnlyFilename(tmp);
38 tmp = ExpandPath(tmp); // This expands ./ and ~/
40 if (!is_absolute_path(tmp)) {
41 string binsearchpath = GetEnvPath("PATH");
42 // This will make "src/lyx" work always :-)
43 binsearchpath += ";.";
45 tmp = FileOpenSearch(binsearchpath, tmp);
48 tmp = MakeAbsPath(OnlyPath(tmp));
50 // In case we are running in place and compiled with shared libraries
51 if (suffixIs(tmp, "/.libs/"))
52 tmp.erase(tmp.length()-6, string::npos);
57 void warn(string const & mesg)
59 MessageBox(0, mesg.c_str(), "LyX error",
60 MB_OK|MB_ICONSTOP|MB_SYSTEMMODAL);
70 string::size_type common_path(string const & p1, string const & p2)
72 string::size_type i = 0;
73 string::size_type p1_len = p1.length();
74 string::size_type p2_len = p2.length();
75 while (i < p1_len && i < p2_len && uppercase(p1[i]) == uppercase(p2[i]))
77 if ((i < p1_len && i < p2_len)
78 || (i < p1_len && p1[i] != '/' && i == p2_len)
79 || (i < p2_len && p2[i] != '/' && i == p1_len))
82 --i; // here was the last match
83 while (i && p1[i] != '/')
90 string slashify_path(string const & p)
92 return subst(p, '\\', '/');
96 string external_path(string const & p)
99 if (is_absolute_path(p)) {
101 cygwin_conv_to_full_win32_path(p.c_str(), dp);
102 dos_path = subst(dp,'\\','/');
105 << "<Win32 path correction> ["
107 << dos_path << ']' << endl;
112 // (Claus H.) Parsing the latex log file in an Win32 environment all
113 // files are mentioned in Win32/DOS syntax. Because LyX uses the dep file
114 // entries to check if any file has been changed we must retranslate
115 // the Win32/DOS pathnames into Cygwin pathnames.
116 string internal_path(string const & p)
119 cygwin_conv_to_posix_path(p.c_str(), pp);
120 string const posix_path = MakeLatexName(pp);
121 lyxerr[Debug::DEPEND]
122 << "<Win32 path correction> ["
124 << posix_path << ']' << endl;
129 // (Claus H.) On Win32 both Unix and Win32/DOS pathnames are used.
130 // Therefore an absolute path could be either a pathname starting
131 // with a slash (Unix) or a pathname starting with a drive letter
132 // followed by a colon. Because a colon is not valid in pathes in Unix
133 // and at another location in Win32 testing just for the existance
134 // of the colon in the 2nd position seems to be enough!
135 bool is_absolute_path(string const & p)
140 bool isDosPath = (p.length() > 1 && p[1] == ':');
141 bool isUnixPath = (p[0] == '/');
143 return isDosPath || isUnixPath;
147 // returns a string suitable to be passed to popen when
149 char const * popen_read_mode()
167 void setTmpDir(string const & p)
184 } // end namespace os