]> git.lyx.org Git - lyx.git/blob - src/support/os_unix.C
Fix natbib bug spotted by JMarc.
[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 namespace {
11
12 string binpath_;
13 string binname_;
14 string tmpdir_;
15
16 }
17
18
19 namespace os {
20
21 void init(int * /*argc*/, char ** argv[])
22 {
23         static bool initialized = false;
24         if (initialized)
25                 return;
26         initialized = true;
27
28         string tmp = *argv[0];
29         binname_ = OnlyFilename(tmp);
30         tmp = ExpandPath(tmp); // This expands ./ and ~/
31         if (!is_absolute_path(tmp)) {
32                 string binsearchpath = GetEnvPath("PATH");
33                 // This will make "src/lyx" work always :-)
34                 binsearchpath += ";.";
35                 tmp = FileOpenSearch(binsearchpath, tmp);
36         }
37
38         tmp = MakeAbsPath(OnlyPath(tmp));
39
40         // In case we are running in place and compiled with shared libraries
41         if (suffixIs(tmp, "/.libs/"))
42                 tmp.erase(tmp.length() - 6, string::npos);
43         binpath_ = tmp;
44 }
45
46
47 void warn(string const & /*mesg*/)
48 {
49         return;
50 }
51
52
53 string current_root()
54 {
55         return "/";
56 }
57
58
59 string::size_type common_path(string const & p1, string const & p2)
60 {
61         string::size_type i = 0;
62         string::size_type p1_len = p1.length();
63         string::size_type p2_len = p2.length();
64         while (i < p1_len && i < p2_len && p1[i] == p2[i])
65                 ++i;
66         if ((i < p1_len && i < p2_len)
67             || (i < p1_len && p1[i] != '/' && i == p2_len)
68             || (i < p2_len && p2[i] != '/' && i == p1_len))
69         {
70                 if (i)
71                         --i;     // here was the last match
72                 while (i && p1[i] != '/')
73                         --i;
74         }
75         return i;
76 }
77
78
79 string slashify_path(string const & p)
80 {
81         return p;
82 }
83
84
85 string external_path(string const & p)
86 {
87         return p;
88 }
89
90
91 string internal_path(string const & p)
92 {
93         return p;
94 }
95
96
97 bool is_absolute_path(string const & p)
98 {
99         return !p.empty() && p[0] == '/';
100 }
101
102
103 char const * popen_read_mode()
104 {
105         return "r";
106 }
107
108
109 string binpath()
110 {
111         return binpath_;
112 }
113
114
115 string binname()
116 {
117         return binname_;
118 }
119
120
121 void setTmpDir(string const & p)
122 {
123         tmpdir_ = p;
124 }
125
126
127 string getTmpDir()
128 {
129         return tmpdir_;
130 }
131
132
133 shell_type shell()
134 {
135         return UNIX;
136 }
137
138 } // end namespace os