1 // os_win32.C copyright "Ruurd A. Reitsma" <R.A.Reitsma@wbmt.tudelft.nl>
3 // Various OS specific functions
7 #include "support/filetools.h"
8 #include "support/lstrings.h"
13 #include <sys/cygwin.h>
16 string os::binpath_ = string();
17 string os::binname_ = string();
18 string os::tmpdir_ = string();
19 os::shell_type os::_shell = os::UNIX;
20 unsigned long os::cp_ = 0;
22 void os::init(int * /* argc */, char ** argv[]) {
23 static bool initialized = false;
24 if (initialized) return;
26 string tmp = *argv[0];
27 binname_ = OnlyFilename(tmp);
28 tmp = ExpandPath(tmp); // This expands ./ and ~/
30 if (!is_absolute_path(tmp)) {
31 string binsearchpath = GetEnvPath("PATH");
32 // This will make "src/lyx" work always :-)
33 binsearchpath += ";.";
35 tmp = FileOpenSearch(binsearchpath, tmp);
38 tmp = MakeAbsPath(OnlyPath(tmp));
40 // In case we are running in place and compiled with shared libraries
41 if (suffixIs(tmp, "/.libs/"))
42 tmp.erase(tmp.length()-6, string::npos);
46 void os::warn(string mesg) {
47 MessageBox(0, mesg.c_str(), "LyX error",
48 MB_OK|MB_ICONSTOP|MB_SYSTEMMODAL);
51 string os::current_root() {
55 string::size_type os::common_path(string const &p1, string const &p2) {
56 string::size_type i = 0,
59 while (i < p1_len && i < p2_len && uppercase(p1[i]) == uppercase(p2[i])) ++i;
60 if ((i < p1_len && i < p2_len)
61 || (i < p1_len && p1[i] != '/' && i == p2_len)
62 || (i < p2_len && p2[i] != '/' && i == p1_len)) {
63 if (i) --i; // here was the last match
64 while (i && p1[i] != '/') --i;
69 string os::slashify_path(string p) {
70 return subst(p, '\\', '/');
73 string os::external_path(string const & p) {
75 if (is_absolute_path(p)) {
77 cygwin_conv_to_full_win32_path(p.c_str(), dp);
78 dos_path=subst(dp,'\\','/');
81 << "<Win32 path correction> ["
83 << dos_path << "]" << endl;
88 // (Claus H.) Parsing the latex log file in an Win32 environment all
89 // files are mentioned in Win32/DOS syntax. Because LyX uses the dep file
90 // entries to check if any file has been changed we must retranslate
91 // the Win32/DOS pathnames into Cygwin pathnames.
92 string os::internal_path(string const &p) {
94 cygwin_conv_to_posix_path(p.c_str(), pp);
95 string const posix_path = MakeLatexName(pp);
97 << "<Win32 path correction> ["
99 << posix_path << "]" << endl;
103 // (Claus H.) On Win32 both Unix and Win32/DOS pathnames are used.
104 // Therefore an absolute path could be either a pathname starting
105 // with a slash (Unix) or a pathname starting with a drive letter
106 // followed by a colon. Because a colon is not valid in pathes in Unix
107 // and at another location in Win32 testing just for the existance
108 // of the colon in the 2nd position seems to be enough!
109 bool os::is_absolute_path(string const & p)
114 bool isDosPath = (p.length() > 1 && p[1] == ':');
115 bool isUnixPath = (p[0] == '/');
117 return isDosPath | isUnixPath;