]> git.lyx.org Git - lyx.git/blob - src/support/os_cygwin.C
make "make distcheck" work
[lyx.git] / src / support / os_cygwin.C
1 /**
2  * \file os_cygwin.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Ruurd A. Reitsma
7  * \author Claus Hentschel
8  * \author Angus Leeming
9  *
10  * Full author contact details are available in file CREDITS.
11  *
12  * Various OS specific functions
13  */
14
15 #include <config.h>
16
17 #include "support/os.h"
18 #include "support/lstrings.h"
19
20 #include "debug.h"
21
22 #include <windows.h>
23 #include <io.h>
24
25 #include <sys/cygwin.h>
26
27 using std::endl;
28 using std::string;
29
30
31 namespace lyx {
32 namespace support {
33 namespace os {
34
35 void os::init(int, char *[])
36 {}
37
38
39 string current_root()
40 {
41         return string("/");
42 }
43
44
45 string::size_type common_path(string const & p1, string const & p2)
46 {
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]))
51                 ++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))
55         {
56                 if (i)
57                         --i;     // here was the last match
58                 while (i && p1[i] != '/')
59                         --i;
60         }
61         return i;
62 }
63
64
65 namespace {
66
67 bool cygwin_path_fix_ = false;
68
69 } // namespace anon
70
71
72 string external_path(string const & p)
73 {
74         string dos_path;
75
76         // Translate from cygwin path syntax to dos path syntax
77         if (cygwin_path_fix_ && is_absolute_path(p)) {
78                 char dp[PATH_MAX];
79                 cygwin_conv_to_full_win32_path(p.c_str(), dp);
80                 dos_path = !dp ? "" : dp;
81         }
82
83         else return p;
84
85         //No backslashes in LaTeX files
86         dos_path = subst(dos_path,'\\','/');
87
88         lyxerr[Debug::LATEX]
89                 << "<Cygwin path correction> ["
90                 << p << "]->>["
91                 << dos_path << ']' << endl;
92         return dos_path;
93 }
94
95
96 string internal_path(string const & p)
97 {
98         char posix_path[PATH_MAX];
99         posix_path[0] = '\0';
100         cygwin_conv_to_posix_path(p.c_str(), posix_path);
101         return posix_path;
102 }
103
104
105 bool is_absolute_path(string const & p)
106 {
107         if (p.empty())
108                 return false;
109
110         bool isDosPath = (p.length() > 1 && p[1] == ':');
111         bool isUnixPath = (p[0] == '/');
112
113         return isDosPath || isUnixPath;
114 }
115
116
117 // returns a string suitable to be passed to popen when
118 // reading a pipe
119 char const * popen_read_mode()
120 {
121         return "r";
122 }
123
124
125 string const & nulldev()
126 {
127         static string const nulldev_ = "/dev/null";
128         return nulldev_;
129 }
130
131
132 shell_type shell()
133 {
134         return UNIX;
135 }
136
137
138 char path_separator()
139 {
140         return ':';
141 }
142
143
144 void cygwin_path_fix(bool use_cygwin_paths)
145 {
146         cygwin_path_fix_ = use_cygwin_paths;
147 }
148
149 } // namespace os
150 } // namespace support
151 } // namespace lyx