3 // Various OS specific functions
7 #include "support/filetools.h"
8 #include "support/lstrings.h"
10 string os::binpath_ = string();
11 string os::binname_ = string();
12 string os::tmpdir_ = string();
13 os::shell_type os::_shell = os::UNIX;
14 unsigned long os::cp_ = 0;
16 void os::init(int * /*argc*/, char ** argv[]) /* :cp_(0), _shell(os::UNIX) */ {
17 static bool initialized = false;
23 string tmp = *argv[0];
24 binname_ = OnlyFilename(tmp);
25 tmp = ExpandPath(tmp); // This expands ./ and ~/
26 if (!os::is_absolute_path(tmp)) {
27 string binsearchpath = GetEnvPath("PATH");
28 // This will make "src/lyx" work always :-)
29 binsearchpath += ";.";
30 tmp = FileOpenSearch(binsearchpath, tmp);
33 tmp = MakeAbsPath(OnlyPath(tmp));
35 // In case we are running in place and compiled with shared libraries
36 if (suffixIs(tmp, "/.libs/"))
37 tmp.erase(tmp.length() - 6, string::npos);
41 void os::warn(string /*mesg*/) {
45 string os::current_root() {
49 string::size_type os::common_path(string const &p1, string const &p2) {
50 string::size_type i = 0,
53 while (i < p1_len && i < p2_len && p1[i] == p2[i]) ++i;
54 if ((i < p1_len && i < p2_len)
55 || (i < p1_len && p1[i] != '/' && i == p2_len)
56 || (i < p2_len && p2[i] != '/' && i == p1_len)) {
57 if (i) --i; // here was the last match
58 while (i && p1[i] != '/') --i;
63 string os::slashify_path(string p) {
67 string os::external_path(string const &p) {
71 string os::internal_path(string const &p) {
75 bool os::is_absolute_path(string const & p)
77 return (!p.empty() && p[0] == '/');