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"
25 #include <Carbon/Carbon.h>
34 void init(int, char *[])
44 bool isFilesystemCaseSensitive()
54 docstring::size_type common_path(docstring const & p1, docstring const & p2)
56 docstring::size_type i = 0;
57 docstring::size_type const p1_len = p1.length();
58 docstring::size_type const p2_len = p2.length();
59 while (i < p1_len && i < p2_len && p1[i] == p2[i])
61 if ((i < p1_len && i < p2_len)
62 || (i < p1_len && p1[i] != '/' && i == p2_len)
63 || (i < p2_len && p2[i] != '/' && i == p1_len))
66 --i; // here was the last match
67 while (i && p1[i] != '/')
74 string external_path(string const & p)
80 string internal_path(string const & p)
86 string external_path_list(string const & p)
92 string internal_path_list(string const & p)
98 string latex_path(string const & p)
104 bool is_valid_strftime(string const & p)
106 string::size_type pos = p.find_first_of('%');
107 while (pos != string::npos) {
108 if (pos + 1 == string::npos)
110 if (!containsOnly(p.substr(pos + 1, 1),
111 "aAbBcCdDeEFgGhHIjklmMnOpPrRsStTuUVwWxXyYzZ%+"))
113 if (pos + 2 == string::npos)
115 pos = p.find_first_of('%', pos + 2);
121 char const * popen_read_mode()
127 string const & nulldev()
129 static string const nulldev_ = "/dev/null";
140 char path_separator()
146 void windows_style_tex_paths(bool)
149 bool canAutoOpenFile(string const & ext, auto_open_mode const mode)
152 // Reference: http://developer.apple.com/documentation/Carbon/Reference/LaunchServicesReference/
153 CFStringRef cfs_ext = CFStringCreateWithBytes(kCFAllocatorDefault,
154 (UInt8 *) ext.c_str(), ext.length(),
155 kCFStringEncodingISOLatin1, false);
156 // this is what we would like to do but it seems that the
157 // viewer for PDF is often quicktime...
158 //LSRolesMask role = (mode == VIEW) ? kLSRolesViewer : kLSRolesEditor;
160 LSRolesMask role = kLSRolesAll;
163 LSGetApplicationForInfo(kLSUnknownType, kLSUnknownCreator,
164 cfs_ext, role, &outAppRef, NULL);
167 return status != kLSApplicationNotFoundErr;
169 // silence compiler warnings
173 // currently, no default viewer is tried for non-windows system
174 // support for KDE/Gnome/Macintosh may be added later
180 bool autoOpenFile(string const & filename, auto_open_mode const mode)
183 // Reference: http://developer.apple.com/documentation/Carbon/Reference/LaunchServicesReference/
186 FSPathMakeRef((UInt8 *) filename.c_str(), &fileref, NULL);
190 // this is what we would like to do but it seems that the
191 // viewer for PDF is often quicktime...
192 //LSRolesMask role = (mode == VIEW) ? kLSRolesViewer : kLSRolesEditor;
194 LSRolesMask role = kLSRolesAll;
197 status = LSGetApplicationForItem(&fileref, role, &outAppRef, NULL);
198 if (status == kLSApplicationNotFoundErr)
201 LSLaunchFSRefSpec inLaunchSpec;
202 inLaunchSpec.appRef = &outAppRef;
203 inLaunchSpec.numDocs = 1;
204 inLaunchSpec.itemRefs = &fileref;
205 inLaunchSpec.passThruParams = NULL;
206 inLaunchSpec.launchFlags = kLSLaunchDefaults;
207 inLaunchSpec.asyncRefCon = NULL;
208 status = LSOpenFromRefSpec(&inLaunchSpec, NULL);
210 return status != kLSApplicationNotFoundErr;
212 // silence compiler warnings
216 // currently, no default viewer is tried for non-windows system
217 // support for KDE/Gnome/Macintosh may be added later
223 bool isSameFile(string const & fileone, string const & filetwo)
228 if (::stat(fileone.c_str(), &st1) == 0
229 && ::stat(filetwo.c_str(), &st2) == 0) {
230 return st1.st_ino == st2.st_ino && st1.st_dev == st2.st_dev;
233 // One or both files cannot be accessed.
238 string real_path(string const & path)
240 char rpath[PATH_MAX + 1];
241 char * result = realpath(path.c_str(), rpath);
242 return FileName::fromFilesystemEncoding(result ? rpath : path).absFilename();
246 } // namespace support