3 // Various OS specific functions
7 #include "support/filetools.h"
8 #include "support/lstrings.h"
21 void init(int * /*argc*/, char ** argv[])
23 static bool initialized = false;
28 string tmp = *argv[0];
29 binname_ = OnlyFilename(tmp);
30 tmp = ExpandPath(tmp); // This expands ./ and ~/
31 if (!is_absolute_path(tmp)) {
32 string binsearchpath = GetEnvPath("PATH");
33 // This will make "src/lyx" work always :-)
34 binsearchpath += ";.";
35 tmp = FileOpenSearch(binsearchpath, tmp);
38 tmp = MakeAbsPath(OnlyPath(tmp));
40 // In case we are running in place and compiled with shared libraries
41 if (suffixIs(tmp, "/.libs/"))
42 tmp.erase(tmp.length() - 6, string::npos);
47 void warn(string const & /*mesg*/)
59 string::size_type common_path(string const & p1, string const & p2)
61 string::size_type i = 0;
62 string::size_type p1_len = p1.length();
63 string::size_type p2_len = p2.length();
64 while (i < p1_len && i < p2_len && p1[i] == p2[i])
66 if ((i < p1_len && i < p2_len)
67 || (i < p1_len && p1[i] != '/' && i == p2_len)
68 || (i < p2_len && p2[i] != '/' && i == p1_len))
71 --i; // here was the last match
72 while (i && p1[i] != '/')
79 string slashify_path(string const & p)
85 string external_path(string const & p)
91 string internal_path(string const & p)
97 bool is_absolute_path(string const & p)
99 return !p.empty() && p[0] == '/';
103 char const * popen_read_mode()
121 void setTmpDir(string const & p)
138 } // end namespace os