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