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"
30 void init(int * /*argc*/, char ** argv[])
32 static bool initialized = false;
37 string tmp = *argv[0];
38 binname_ = OnlyFilename(tmp);
39 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 += ";.";
44 tmp = FileOpenSearch(binsearchpath, tmp);
47 tmp = MakeAbsPath(OnlyPath(tmp));
49 // In case we are running in place and compiled with shared libraries
50 if (suffixIs(tmp, "/.libs/"))
51 tmp.erase(tmp.length() - 6, string::npos);
56 void warn(string const & /*mesg*/)
68 string::size_type common_path(string const & p1, string const & p2)
70 string::size_type i = 0;
71 string::size_type p1_len = p1.length();
72 string::size_type p2_len = p2.length();
73 while (i < p1_len && i < p2_len && p1[i] == p2[i])
75 if ((i < p1_len && i < p2_len)
76 || (i < p1_len && p1[i] != '/' && i == p2_len)
77 || (i < p2_len && p2[i] != '/' && i == p1_len))
80 --i; // here was the last match
81 while (i && p1[i] != '/')
88 string slashify_path(string const & p)
94 string external_path(string const & p)
100 string internal_path(string const & p)
106 bool is_absolute_path(string const & p)
108 return !p.empty() && p[0] == '/';
112 char const * popen_read_mode()
130 void setTmpDir(string const & p)
147 } // end namespace os