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;
24 void os::init(int * /* argc */, char ** argv[]) {
25 static bool initialized = false;
26 if (initialized) return;
28 string tmp = *argv[0];
29 binname_ = OnlyFilename(tmp);
30 tmp = ExpandPath(tmp); // This expands ./ and ~/
32 if (!is_absolute_path(tmp)) {
33 string binsearchpath = GetEnvPath("PATH");
34 // This will make "src/lyx" work always :-)
35 binsearchpath += ";.";
37 tmp = FileOpenSearch(binsearchpath, tmp);
40 tmp = MakeAbsPath(OnlyPath(tmp));
42 // In case we are running in place and compiled with shared libraries
43 if (suffixIs(tmp, "/.libs/"))
44 tmp.erase(tmp.length()-6, string::npos);
48 void os::warn(string mesg) {
49 MessageBox(0, mesg.c_str(), "LyX error",
50 MB_OK|MB_ICONSTOP|MB_SYSTEMMODAL);
53 string os::current_root() {
57 string::size_type os::common_path(string const &p1, string const &p2) {
58 string::size_type i = 0,
61 while (i < p1_len && i < p2_len && uppercase(p1[i]) == uppercase(p2[i])) ++i;
62 if ((i < p1_len && i < p2_len)
63 || (i < p1_len && p1[i] != '/' && i == p2_len)
64 || (i < p2_len && p2[i] != '/' && i == p1_len)) {
65 if (i) --i; // here was the last match
66 while (i && p1[i] != '/') --i;
71 string os::slashify_path(string p) {
72 return subst(p, '\\', '/');
75 string os::external_path(string const & p) {
77 if (is_absolute_path(p)) {
79 cygwin_conv_to_full_win32_path(p.c_str(), dp);
80 dos_path=subst(dp,'\\','/');
83 << "<Win32 path correction> ["
85 << dos_path << "]" << endl;
90 // (Claus H.) Parsing the latex log file in an Win32 environment all
91 // files are mentioned in Win32/DOS syntax. Because LyX uses the dep file
92 // entries to check if any file has been changed we must retranslate
93 // the Win32/DOS pathnames into Cygwin pathnames.
94 string os::internal_path(string const &p) {
96 cygwin_conv_to_posix_path(p.c_str(), pp);
97 string const posix_path = MakeLatexName(pp);
99 << "<Win32 path correction> ["
101 << posix_path << "]" << endl;
105 // (Claus H.) On Win32 both Unix and Win32/DOS pathnames are used.
106 // Therefore an absolute path could be either a pathname starting
107 // with a slash (Unix) or a pathname starting with a drive letter
108 // followed by a colon. Because a colon is not valid in pathes in Unix
109 // and at another location in Win32 testing just for the existance
110 // of the colon in the 2nd position seems to be enough!
111 bool os::is_absolute_path(string const & p)
116 bool isDosPath = (p.length() > 1 && p[1] == ':');
117 bool isUnixPath = (p[0] == '/');
119 return isDosPath | isUnixPath;
122 // returns a string suitable to be passed to fopen/popen when
124 char const * os::read_mode()