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
16 #include "support/filetools.h"
17 #include "support/lstrings.h"
22 #include <sys/cygwin.h>
24 using namespace lyx::support;
41 void init(int * /* argc */, char ** argv[])
43 static bool initialized = false;
48 string tmp = *argv[0];
49 binname_ = OnlyFilename(tmp);
50 tmp = ExpandPath(tmp); // This expands ./ and ~/
52 if (!is_absolute_path(tmp)) {
53 string binsearchpath = GetEnvPath("PATH");
54 // This will make "src/lyx" work always :-)
55 binsearchpath += ";.";
57 tmp = FileOpenSearch(binsearchpath, tmp);
60 tmp = MakeAbsPath(OnlyPath(tmp));
62 // In case we are running in place and compiled with shared libraries
63 if (suffixIs(tmp, "/.libs/"))
64 tmp.erase(tmp.length()-6, string::npos);
69 void warn(string const & mesg)
71 MessageBox(0, mesg.c_str(), "LyX error",
72 MB_OK|MB_ICONSTOP|MB_SYSTEMMODAL);
82 string::size_type common_path(string const & p1, string const & p2)
84 string::size_type i = 0;
85 string::size_type p1_len = p1.length();
86 string::size_type p2_len = p2.length();
87 while (i < p1_len && i < p2_len && uppercase(p1[i]) == uppercase(p2[i]))
89 if ((i < p1_len && i < p2_len)
90 || (i < p1_len && p1[i] != '/' && i == p2_len)
91 || (i < p2_len && p2[i] != '/' && i == p1_len))
94 --i; // here was the last match
95 while (i && p1[i] != '/')
102 string slashify_path(string const & p)
104 return subst(p, '\\', '/');
108 string external_path(string const & p)
111 if (is_absolute_path(p)) {
113 cygwin_conv_to_full_win32_path(p.c_str(), dp);
114 dos_path = subst(dp,'\\','/');
117 << "<Win32 path correction> ["
119 << dos_path << ']' << endl;
124 // (Claus H.) Parsing the latex log file in an Win32 environment all
125 // files are mentioned in Win32/DOS syntax. Because LyX uses the dep file
126 // entries to check if any file has been changed we must retranslate
127 // the Win32/DOS pathnames into Cygwin pathnames.
128 string internal_path(string const & p)
131 cygwin_conv_to_posix_path(p.c_str(), pp);
132 string const posix_path = MakeLatexName(pp);
133 lyxerr[Debug::DEPEND]
134 << "<Win32 path correction> ["
136 << posix_path << ']' << endl;
141 // (Claus H.) On Win32 both Unix and Win32/DOS pathnames are used.
142 // Therefore an absolute path could be either a pathname starting
143 // with a slash (Unix) or a pathname starting with a drive letter
144 // followed by a colon. Because a colon is not valid in pathes in Unix
145 // and at another location in Win32 testing just for the existance
146 // of the colon in the 2nd position seems to be enough!
147 bool is_absolute_path(string const & p)
152 bool isDosPath = (p.length() > 1 && p[1] == ':');
153 bool isUnixPath = (p[0] == '/');
155 return isDosPath || isUnixPath;
159 // returns a string suitable to be passed to popen when
161 char const * popen_read_mode()
179 void setTmpDir(string const & p)
197 } // namespace support