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
8 * Full author contact details are available in file CREDITS.
10 * Various OS specific functions
15 #include "support/os.h"
16 #include "support/docstring.h"
17 #include "support/FileName.h"
18 #include "support/lstrings.h"
24 #include <Carbon/Carbon.h>
35 string stdoutdev_ = "/dev/stdout";
36 string stderrdev_ = "/dev/stderr";
40 void init(int, char *[])
42 // Check whether /dev/stdout and /dev/stderr are available,
43 // otherwise default to /dev/tty.
44 if (access(stdoutdev_.c_str(), W_OK) != 0
45 || access(stderrdev_.c_str(), W_OK) != 0) {
46 stdoutdev_ = "/dev/tty";
47 stderrdev_ = "/dev/tty";
58 bool isFilesystemCaseSensitive()
68 docstring::size_type common_path(docstring const & p1, docstring const & p2)
70 docstring::size_type i = 0;
71 docstring::size_type const p1_len = p1.length();
72 docstring::size_type const p2_len = p2.length();
73 while (i < p1_len && i < p2_len && p1[i] == p2[i])
75 if ((i < p1_len && i < p2_len)
76 || (i < p1_len && p1[i] != '/' && i == p2_len)
77 || (i < p2_len && p2[i] != '/' && i == p1_len))
80 --i; // here was the last match
81 while (i && p1[i] != '/')
88 string external_path(string const & p)
94 string internal_path(string const & p)
100 string external_path_list(string const & p)
106 string internal_path_list(string const & p)
112 string latex_path(string const & p)
118 bool is_valid_strftime(string const & p)
120 string::size_type pos = p.find_first_of('%');
121 while (pos != string::npos) {
122 if (pos + 1 == string::npos)
124 if (!containsOnly(p.substr(pos + 1, 1),
125 "aAbBcCdDeEFgGhHIjklmMnOpPrRsStTuUVwWxXyYzZ%+"))
127 if (pos + 2 == string::npos)
129 pos = p.find_first_of('%', pos + 2);
135 char const * popen_read_mode()
141 string const & nulldev()
143 static string const nulldev_ = "/dev/null";
148 string const & stdoutdev()
154 string const & stderrdev()
160 bool terminal_output()
162 return isatty(1) && isatty(2);
172 char path_separator()
178 void windows_style_tex_paths(bool)
181 bool canAutoOpenFile(string const & ext, auto_open_mode const mode)
184 // Reference: http://developer.apple.com/documentation/Carbon/Reference/LaunchServicesReference/
185 CFStringRef cfs_ext = CFStringCreateWithBytes(kCFAllocatorDefault,
186 (UInt8 *) ext.c_str(), ext.length(),
187 kCFStringEncodingISOLatin1, false);
188 // this is what we would like to do but it seems that the
189 // viewer for PDF is often quicktime...
190 //LSRolesMask role = (mode == VIEW) ? kLSRolesViewer : kLSRolesEditor;
192 LSRolesMask role = kLSRolesAll;
195 LSGetApplicationForInfo(kLSUnknownType, kLSUnknownCreator,
196 cfs_ext, role, &outAppRef, NULL);
199 return status != kLSApplicationNotFoundErr;
201 // silence compiler warnings
205 // currently, no default viewer is tried for non-windows system
206 // support for KDE/Gnome/Macintosh may be added later
212 bool autoOpenFile(string const & filename, auto_open_mode const mode)
215 // Reference: http://developer.apple.com/documentation/Carbon/Reference/LaunchServicesReference/
218 FSPathMakeRef((UInt8 *) filename.c_str(), &fileref, NULL);
222 // this is what we would like to do but it seems that the
223 // viewer for PDF is often quicktime...
224 //LSRolesMask role = (mode == VIEW) ? kLSRolesViewer : kLSRolesEditor;
226 LSRolesMask role = kLSRolesAll;
229 status = LSGetApplicationForItem(&fileref, role, &outAppRef, NULL);
230 if (status == kLSApplicationNotFoundErr)
233 LSLaunchFSRefSpec inLaunchSpec;
234 inLaunchSpec.appRef = &outAppRef;
235 inLaunchSpec.numDocs = 1;
236 inLaunchSpec.itemRefs = &fileref;
237 inLaunchSpec.passThruParams = NULL;
238 inLaunchSpec.launchFlags = kLSLaunchDefaults;
239 inLaunchSpec.asyncRefCon = NULL;
240 status = LSOpenFromRefSpec(&inLaunchSpec, NULL);
242 return status != kLSApplicationNotFoundErr;
244 // silence compiler warnings
248 // currently, no default viewer is tried for non-windows system
249 // support for KDE/Gnome/Macintosh may be added later
255 string real_path(string const & path)
257 char rpath[PATH_MAX + 1];
258 char * result = realpath(path.c_str(), rpath);
259 return FileName::fromFilesystemEncoding(result ? rpath : path).absFilename();
263 } // namespace support