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
15 #include "support/os.h"
16 #include "support/filetools.h"
17 #include "support/lstrings.h"
37 void init(int /*argc*/, char * argv[])
39 static bool initialized = false;
45 binname_ = OnlyFilename(tmp);
46 tmp = ExpandPath(tmp); // This expands ./ and ~/
47 if (!is_absolute_path(tmp)) {
48 string binsearchpath = GetEnvPath("PATH");
49 // This will make "src/lyx" work always :-)
50 binsearchpath += ";.";
51 tmp = FileOpenSearch(binsearchpath, tmp);
54 tmp = MakeAbsPath(OnlyPath(tmp));
56 // In case we are running in place and compiled with shared libraries
57 if (suffixIs(tmp, "/.libs/"))
58 tmp.erase(tmp.length() - 6, string::npos);
62 homepath_ = GetEnvPath("HOME");
63 nulldev_ = "/dev/null";
67 void warn(string const & /*mesg*/)
79 string::size_type common_path(string const & p1, string const & p2)
81 string::size_type i = 0;
82 string::size_type p1_len = p1.length();
83 string::size_type p2_len = p2.length();
84 while (i < p1_len && i < p2_len && p1[i] == p2[i])
86 if ((i < p1_len && i < p2_len)
87 || (i < p1_len && p1[i] != '/' && i == p2_len)
88 || (i < p2_len && p2[i] != '/' && i == p1_len))
91 --i; // here was the last match
92 while (i && p1[i] != '/')
99 string slashify_path(string const & p)
105 string external_path(string const & p)
111 string internal_path(string const & p)
117 bool is_absolute_path(string const & p)
119 return !p.empty() && p[0] == '/';
123 char const * popen_read_mode()
129 string const & binpath()
135 string const & binname()
141 void setTmpDir(string const & p)
147 string const & getTmpDir()
153 string const & homepath()
159 string const & nulldev()
171 } // namespace support