1 // os_win32.C copyright "Ruurd A. Reitsma" <R.A.Reitsma@wbmt.tudelft.nl>
3 // Various OS specific functions
7 #include "support/filetools.h"
11 #include <sys/cygwin.h>
14 string os::binpath_ = string();
15 string os::binname_ = string();
16 string os::tmpdir_ = string();
17 os::shell_type os::_shell = os::UNIX;
18 unsigned long os::cp_ = 0;
20 void os::init(int * argc, char ** argv[]) {
21 static bool initialized = false;
22 if (initialized) return;
24 string tmp = *argv[0];
25 binname_ = OnlyFilename(tmp);
26 tmp = ExpandPath(tmp); // This expands ./ and ~/
28 if (!AbsolutePath(tmp)) {
29 string binsearchpath = GetEnvPath("PATH");
30 // This will make "src/lyx" work always :-)
31 binsearchpath += ";.";
33 tmp = FileOpenSearch(binsearchpath, tmp);
36 tmp = MakeAbsPath(OnlyPath(tmp));
38 // In case we are running in place and compiled with shared libraries
39 if (suffixIs(tmp, "/.libs/"))
40 tmp.erase(tmp.length()-6, string::npos);
44 void os::warn(string mesg) {
45 MessageBox(0, mesg.c_str(), "LyX error",
46 MB_OK|MB_ICONSTOP|MB_SYSTEMMODAL);
49 string os::current_root() {
53 string::size_type os::common_path(string const &p1, string const &p2) {
54 string::size_type i = 0,
57 while (i < p1_len && i < p2_len && uppercase(p1[i]) == uppercase(p2[i])) ++i;
58 if ((i < p1_len && i < p2_len)
59 || (i < p1_len && p1[i] != '/' && i == p2_len)
60 || (i < p2_len && p2[i] != '/' && i == p1_len)) {
61 if (i) --i; // here was the last match
62 while (i && p1[i] != '/') --i;
67 string os::slashify_path(string p) {
68 return subst(p, '\\', '/');
71 string os::external_path(string p) {
73 if (AbsolutePath(p)) {
75 cygwin_conv_to_full_win32_path(p.c_str(), dp);
76 dos_path=subst(dp,'\\','/');
79 << "<Win32 path correction> ["
81 << dos_path << "]" << endl;