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