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 (!is_absolute_path(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 const & p) {
73 if (is_absolute_path(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;
86 // (Claus H.) Parsing the latex log file in an Win32 environment all
87 // files are mentioned in Win32/DOS syntax. Because LyX uses the dep file
88 // entries to check if any file has been changed we must retranslate
89 // the Win32/DOS pathnames into Cygwin pathnames.
90 string os::internal_path(string const &p) {
92 cygwin_conv_to_posix_path(p.c_str(), pp);
93 string const posix_path = MakeLatexName(pp);
95 << "<Win32 path correction> ["
97 << posix_path << "]" << endl;
101 // (Claus H.) On Win32 both Unix and Win32/DOS pathnames are used.
102 // Therefore an absolute path could be either a pathname starting
103 // with a slash (Unix) or a pathname starting with a drive letter
104 // followed by a colon. Because a colon is not valid in pathes in Unix
105 // and at another location in Win32 testing just for the existance
106 // of the colon in the 2nd position seems to be enough!
107 bool os::is_absolute_path(string const & p)
112 bool isDosPath = (path.length() > 1 && path[1] == ':');
113 bool isUnixPath = (path[0] == '/');
115 return isDosPath | isUnixPath;