]> git.lyx.org Git - lyx.git/blob - src/support/os_win32.C
split LyXText::rowlist_ into individual Paragraph::rows_ chunks
[lyx.git] / src / support / os_win32.C
1 /**
2  * \file os_win32.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 #include "debug.h"
19
20 #include <windows.h>
21 #include <io.h>
22 #include <sys/cygwin.h>
23
24 using namespace lyx::support;
25 using std::endl;
26
27
28 namespace {
29
30 string binpath_;
31 string binname_;
32 string tmpdir_;
33
34 }
35
36
37 namespace lyx {
38 namespace support {
39 namespace os {
40
41 void init(int * /* argc */, char ** argv[])
42 {
43         static bool initialized = false;
44         if (initialized)
45                 return;
46         initialized = true;
47
48         string tmp = *argv[0];
49         binname_ = OnlyFilename(tmp);
50         tmp = ExpandPath(tmp); // This expands ./ and ~/
51
52         if (!is_absolute_path(tmp)) {
53                 string binsearchpath = GetEnvPath("PATH");
54                 // This will make "src/lyx" work always :-)
55                 binsearchpath += ";.";
56                 tmp = *argv[0];
57                 tmp = FileOpenSearch(binsearchpath, tmp);
58         }
59
60         tmp = MakeAbsPath(OnlyPath(tmp));
61
62         // In case we are running in place and compiled with shared libraries
63         if (suffixIs(tmp, "/.libs/"))
64                 tmp.erase(tmp.length()-6, string::npos);
65         binpath_ = tmp;
66 }
67
68
69 void warn(string const & mesg)
70 {
71         MessageBox(0, mesg.c_str(), "LyX error",
72         MB_OK|MB_ICONSTOP|MB_SYSTEMMODAL);
73 }
74
75
76 string current_root()
77 {
78         return "/";
79 }
80
81
82 string::size_type common_path(string const & p1, string const & p2)
83 {
84         string::size_type i = 0;
85         string::size_type       p1_len = p1.length();
86         string::size_type       p2_len = p2.length();
87         while (i < p1_len && i < p2_len && uppercase(p1[i]) == uppercase(p2[i]))
88                 ++i;
89         if ((i < p1_len && i < p2_len)
90             || (i < p1_len && p1[i] != '/' && i == p2_len)
91             || (i < p2_len && p2[i] != '/' && i == p1_len))
92         {
93                 if (i)
94                         --i;     // here was the last match
95                 while (i && p1[i] != '/')
96                         --i;
97         }
98         return i;
99 }
100
101
102 string slashify_path(string const & p)
103 {
104         return subst(p, '\\', '/');
105 }
106
107
108 string external_path(string const & p)
109 {
110         string dos_path = p;
111         if (is_absolute_path(p)) {
112                 char dp[255];
113                 cygwin_conv_to_full_win32_path(p.c_str(), dp);
114                 dos_path = subst(dp,'\\','/');
115         }
116         lyxerr[Debug::LATEX]
117                 << "<Win32 path correction> ["
118                 << p << "]->>["
119                 << dos_path << ']' << endl;
120         return dos_path;
121 }
122
123
124 // (Claus H.) Parsing the latex log file in an Win32 environment all
125 // files are mentioned in Win32/DOS syntax. Because LyX uses the dep file
126 // entries to check if any file has been changed we must retranslate
127 // the Win32/DOS pathnames into Cygwin pathnames.
128 string internal_path(string const & p)
129 {
130         char pp[256];
131         cygwin_conv_to_posix_path(p.c_str(), pp);
132         string const posix_path = MakeLatexName(pp);
133         lyxerr[Debug::DEPEND]
134                 << "<Win32 path correction> ["
135                 << p << "]->>["
136                 << posix_path << ']' << endl;
137         return posix_path;
138 }
139
140
141 // (Claus H.) On Win32 both Unix and Win32/DOS pathnames are used.
142 // Therefore an absolute path could be either a pathname starting
143 // with a slash (Unix) or a pathname starting with a drive letter
144 // followed by a colon. Because a colon is not valid in pathes in Unix
145 // and at another location in Win32 testing just for the existance
146 // of the colon in the 2nd position seems to be enough!
147 bool is_absolute_path(string const & p)
148 {
149         if (p.empty())
150                 return false;
151
152         bool isDosPath = (p.length() > 1 && p[1] == ':');
153         bool isUnixPath = (p[0] == '/');
154
155         return isDosPath || isUnixPath;
156 }
157
158
159 // returns a string suitable to be passed to popen when
160 // reading a pipe
161 char const * popen_read_mode()
162 {
163         return "r";
164 }
165
166
167 string binpath()
168 {
169         return binpath_;
170 }
171
172
173 string binname()
174 {
175         return binname_;
176 }
177
178
179 void setTmpDir(string const & p)
180 {
181         tmpdir_ = p;
182 }
183
184
185 string getTmpDir()
186 {
187         return tmpdir_;
188 }
189
190
191 shell_type shell()
192 {
193         return UNIX;
194 }
195
196 } // namespace os
197 } // namespace support
198 } // namespace lyx