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"
35 void init(int * /*argc*/, char ** argv[])
37 static bool initialized = false;
42 string tmp = *argv[0];
43 binname_ = OnlyFilename(tmp);
44 tmp = ExpandPath(tmp); // This expands ./ and ~/
45 if (!is_absolute_path(tmp)) {
46 string binsearchpath = GetEnvPath("PATH");
47 // This will make "src/lyx" work always :-)
48 binsearchpath += ";.";
49 tmp = FileOpenSearch(binsearchpath, tmp);
52 tmp = MakeAbsPath(OnlyPath(tmp));
54 // In case we are running in place and compiled with shared libraries
55 if (suffixIs(tmp, "/.libs/"))
56 tmp.erase(tmp.length() - 6, string::npos);
61 void warn(string const & /*mesg*/)
73 string::size_type common_path(string const & p1, string const & p2)
75 string::size_type i = 0;
76 string::size_type p1_len = p1.length();
77 string::size_type p2_len = p2.length();
78 while (i < p1_len && i < p2_len && p1[i] == p2[i])
80 if ((i < p1_len && i < p2_len)
81 || (i < p1_len && p1[i] != '/' && i == p2_len)
82 || (i < p2_len && p2[i] != '/' && i == p1_len))
85 --i; // here was the last match
86 while (i && p1[i] != '/')
93 string slashify_path(string const & p)
99 string external_path(string const & p)
105 string internal_path(string const & p)
111 bool is_absolute_path(string const & p)
113 return !p.empty() && p[0] == '/';
117 char const * popen_read_mode()
135 void setTmpDir(string const & p)
153 } // namespace support