3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Ruurd A. Reitsma
7 * \author Claus Hentschel
8 * \author Angus Leeming
10 * Full author contact details are available in file CREDITS.
12 * Various OS specific functions
17 #include "support/os.h"
18 #include "support/lstrings.h"
25 #include <sys/cygwin.h>
35 void os::init(int, char *[])
45 string::size_type common_path(string const & p1, string const & p2)
47 string::size_type i = 0;
48 string::size_type p1_len = p1.length();
49 string::size_type p2_len = p2.length();
50 while (i < p1_len && i < p2_len && uppercase(p1[i]) == uppercase(p2[i]))
52 if ((i < p1_len && i < p2_len)
53 || (i < p1_len && p1[i] != '/' && i == p2_len)
54 || (i < p2_len && p2[i] != '/' && i == p1_len))
57 --i; // here was the last match
58 while (i && p1[i] != '/')
67 bool cygwin_path_fix_ = false;
72 string external_path(string const & p)
76 // Translate from cygwin path syntax to dos path syntax
77 if (cygwin_path_fix_ && is_absolute_path(p)) {
79 cygwin_conv_to_full_win32_path(p.c_str(), dp);
80 dos_path = !dp ? "" : dp;
85 //No backslashes in LaTeX files
86 dos_path = subst(dos_path,'\\','/');
89 << "<Cygwin path correction> ["
91 << dos_path << ']' << endl;
96 string internal_path(string const & p)
98 char posix_path[PATH_MAX];
100 cygwin_conv_to_posix_path(p.c_str(), posix_path);
105 string latex_path(string const & p)
107 // We may need a posix style path or a windows style path (depending
108 // on cygwin_path_fix_), but we use always forward slashes, since it
109 // gets written into a .tex file.
110 return external_path(p);
114 bool is_absolute_path(string const & p)
119 bool isDosPath = (p.length() > 1 && p[1] == ':');
120 bool isUnixPath = (p[0] == '/');
122 return isDosPath || isUnixPath;
126 // returns a string suitable to be passed to popen when
128 char const * popen_read_mode()
134 string const & nulldev()
136 static string const nulldev_ = "/dev/null";
147 char path_separator()
153 void cygwin_path_fix(bool use_cygwin_paths)
155 cygwin_path_fix_ = use_cygwin_paths;
159 } // namespace support