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