]> git.lyx.org Git - lyx.git/blob - src/support/os_unix.C
zlib stuff
[lyx.git] / src / support / os_unix.C
1 /**
2  * \file os_unix.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Ruurd A. Reitsma
7  *
8  * Full author contact details are available in file CREDITS
9  *
10  * Various OS specific functions
11  */
12
13 #include <config.h>
14
15 #include "os.h"
16 #include "support/filetools.h"
17 #include "support/lstrings.h"
18
19 namespace {
20
21 string binpath_;
22 string binname_;
23 string tmpdir_;
24
25 }
26
27 namespace lyx {
28 namespace support {
29 namespace os {
30
31 void init(int * /*argc*/, char ** argv[])
32 {
33         static bool initialized = false;
34         if (initialized)
35                 return;
36         initialized = true;
37
38         string tmp = *argv[0];
39         binname_ = OnlyFilename(tmp);
40         tmp = ExpandPath(tmp); // This expands ./ and ~/
41         if (!is_absolute_path(tmp)) {
42                 string binsearchpath = GetEnvPath("PATH");
43                 // This will make "src/lyx" work always :-)
44                 binsearchpath += ";.";
45                 tmp = FileOpenSearch(binsearchpath, tmp);
46         }
47
48         tmp = MakeAbsPath(OnlyPath(tmp));
49
50         // In case we are running in place and compiled with shared libraries
51         if (suffixIs(tmp, "/.libs/"))
52                 tmp.erase(tmp.length() - 6, string::npos);
53         binpath_ = tmp;
54 }
55
56
57 void warn(string const & /*mesg*/)
58 {
59         return;
60 }
61
62
63 string current_root()
64 {
65         return "/";
66 }
67
68
69 string::size_type common_path(string const & p1, string const & p2)
70 {
71         string::size_type i = 0;
72         string::size_type p1_len = p1.length();
73         string::size_type p2_len = p2.length();
74         while (i < p1_len && i < p2_len && p1[i] == p2[i])
75                 ++i;
76         if ((i < p1_len && i < p2_len)
77             || (i < p1_len && p1[i] != '/' && i == p2_len)
78             || (i < p2_len && p2[i] != '/' && i == p1_len))
79         {
80                 if (i)
81                         --i;     // here was the last match
82                 while (i && p1[i] != '/')
83                         --i;
84         }
85         return i;
86 }
87
88
89 string slashify_path(string const & p)
90 {
91         return p;
92 }
93
94
95 string external_path(string const & p)
96 {
97         return p;
98 }
99
100
101 string internal_path(string const & p)
102 {
103         return p;
104 }
105
106
107 bool is_absolute_path(string const & p)
108 {
109         return !p.empty() && p[0] == '/';
110 }
111
112
113 char const * popen_read_mode()
114 {
115         return "r";
116 }
117
118
119 string binpath()
120 {
121         return binpath_;
122 }
123
124
125 string binname()
126 {
127         return binname_;
128 }
129
130
131 void setTmpDir(string const & p)
132 {
133         tmpdir_ = p;
134 }
135
136
137 string getTmpDir()
138 {
139         return tmpdir_;
140 }
141
142
143 shell_type shell()
144 {
145         return UNIX;
146 }
147
148 } // namespace os
149 } // namespace support
150 } // namespace lyx