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"
31 void init(int * /*argc*/, char ** argv[])
33 static bool initialized = false;
38 string tmp = *argv[0];
39 binname_ = OnlyFilename(tmp);
40 tmp = ExpandPath(tmp); // This expands ./ and ~/
41 if (!is_absolute_path(tmp)) {
42 string binsearchpath = GetEnvPath("PATH");
43 // This will make "src/lyx" work always :-)
44 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*/)
69 string::size_type common_path(string const & p1, string const & p2)
71 string::size_type i = 0;
72 string::size_type p1_len = p1.length();
73 string::size_type p2_len = p2.length();
74 while (i < p1_len && i < p2_len && p1[i] == p2[i])
76 if ((i < p1_len && i < p2_len)
77 || (i < p1_len && p1[i] != '/' && i == p2_len)
78 || (i < p2_len && p2[i] != '/' && i == p1_len))
81 --i; // here was the last match
82 while (i && p1[i] != '/')
89 string slashify_path(string const & p)
95 string external_path(string const & p)
101 string internal_path(string const & p)
107 bool is_absolute_path(string const & p)
109 return !p.empty() && p[0] == '/';
113 char const * popen_read_mode()
131 void setTmpDir(string const & p)
149 } // namespace support