]> git.lyx.org Git - lyx.git/blob - src/support/os_unix.C
fix typo that put too many include paths for most people
[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 #include "support/lstrings.h"
9
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;
15
16 void os::init(int * /*argc*/, char ** argv[]) /* :cp_(0), _shell(os::UNIX) */ {
17         static bool initialized = false;
18
19         if (initialized)
20                 return;
21
22         initialized = true;
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);
31         }
32
33         tmp = MakeAbsPath(OnlyPath(tmp));
34
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);
38         binpath_ = tmp;
39 }
40
41 void os::warn(string /*mesg*/) {
42         return;
43 }
44
45 string os::current_root() {
46         return string("/");
47 }
48
49 string::size_type os::common_path(string const &p1, string const &p2) {
50         string::size_type i = 0,
51                         p1_len = p1.length(),
52                         p2_len = p2.length();
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;
59         }
60         return i;
61 }
62
63 string os::slashify_path(string p) {
64         return p;
65 }
66
67 string os::external_path(string const &p) {
68         return p;
69 }
70
71 string os::internal_path(string const &p) {
72         return p;
73 }
74
75 bool os::is_absolute_path(string const & p)
76 {
77         return (!p.empty() && p[0] == '/');
78 }
79
80 // returns a string suitable to be passed to fopen/popen when
81 // reading a file
82 char const * os::read_mode()
83 {
84         return "r";
85 }