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;
42 void init(int * /* argc */, char ** argv[])
44 static bool initialized = false;
49 string tmp = *argv[0];
50 binname_ = OnlyFilename(tmp);
51 tmp = ExpandPath(tmp); // This expands ./ and ~/
53 if (!is_absolute_path(tmp)) {
54 string binsearchpath = GetEnvPath("PATH");
55 // This will make "src/lyx" work always :-)
56 binsearchpath += ";.";
58 tmp = FileOpenSearch(binsearchpath, tmp);
61 tmp = MakeAbsPath(OnlyPath(tmp));
63 // In case we are running in place and compiled with shared libraries
64 if (suffixIs(tmp, "/.libs/"))
65 tmp.erase(tmp.length()-6, string::npos);
70 void warn(string const & mesg)
72 MessageBox(0, mesg.c_str(), "LyX error",
73 MB_OK|MB_ICONSTOP|MB_SYSTEMMODAL);
83 string::size_type common_path(string const & p1, string const & p2)
85 string::size_type i = 0;
86 string::size_type p1_len = p1.length();
87 string::size_type p2_len = p2.length();
88 while (i < p1_len && i < p2_len && uppercase(p1[i]) == uppercase(p2[i]))
90 if ((i < p1_len && i < p2_len)
91 || (i < p1_len && p1[i] != '/' && i == p2_len)
92 || (i < p2_len && p2[i] != '/' && i == p1_len))
95 --i; // here was the last match
96 while (i && p1[i] != '/')
103 string slashify_path(string const & p)
105 return subst(p, '\\', '/');
109 string external_path(string const & p)
112 if (is_absolute_path(p)) {
114 cygwin_conv_to_full_win32_path(p.c_str(), dp);
115 dos_path = subst(dp,'\\','/');
118 << "<Win32 path correction> ["
120 << dos_path << ']' << endl;
125 // (Claus H.) Parsing the latex log file in an Win32 environment all
126 // files are mentioned in Win32/DOS syntax. Because LyX uses the dep file
127 // entries to check if any file has been changed we must retranslate
128 // the Win32/DOS pathnames into Cygwin pathnames.
129 string internal_path(string const & p)
132 cygwin_conv_to_posix_path(p.c_str(), pp);
133 string const posix_path = MakeLatexName(pp);
134 lyxerr[Debug::DEPEND]
135 << "<Win32 path correction> ["
137 << posix_path << ']' << endl;
142 // (Claus H.) On Win32 both Unix and Win32/DOS pathnames are used.
143 // Therefore an absolute path could be either a pathname starting
144 // with a slash (Unix) or a pathname starting with a drive letter
145 // followed by a colon. Because a colon is not valid in pathes in Unix
146 // and at another location in Win32 testing just for the existance
147 // of the colon in the 2nd position seems to be enough!
148 bool is_absolute_path(string const & p)
153 bool isDosPath = (p.length() > 1 && p[1] == ':');
154 bool isUnixPath = (p[0] == '/');
156 return isDosPath || isUnixPath;
160 // returns a string suitable to be passed to popen when
162 char const * popen_read_mode()
180 void setTmpDir(string const & p)
198 } // namespace support