]> git.lyx.org Git - lyx.git/blob - src/support/os_unix.C
small changes read changelog
[lyx.git] / src / support / os_unix.C
1 // os_unix.C
2
3 // Various OS specific functions
4 #include <config.h>
5
6 #include "os.h"
7 #include "support/filetools.h"
8
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;
14
15 void os::init(int * /*argc*/, char ** argv[]) /* :cp_(0), _shell(os::UNIX) */ {
16         static bool initialized = false;
17
18         if (initialized)
19                 return;
20
21         initialized = true;
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);
30         }
31
32         tmp = MakeAbsPath(OnlyPath(tmp));
33
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);
37         binpath_ = tmp;
38 }
39
40 void os::warn(string /*mesg*/) {
41         return;
42 }
43
44 string os::current_root() {
45         return string("/");
46 }
47
48 string::size_type os::common_path(string const &p1, string const &p2) {
49         string::size_type i = 0,
50                         p1_len = p1.length(),
51                         p2_len = p2.length();
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;
58         }
59         return i;
60 }
61
62 string os::slashify_path(string p) {
63         return p;
64 }
65
66 string os::external_path(string p) {
67         return p;
68 }
69