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"
23 #include <Carbon/Carbon.h>
32 void init(int, char *[])
42 bool isFilesystemCaseSensitive()
52 docstring::size_type common_path(docstring const & p1, docstring const & p2)
54 docstring::size_type i = 0;
55 docstring::size_type const p1_len = p1.length();
56 docstring::size_type const p2_len = p2.length();
57 while (i < p1_len && i < p2_len && p1[i] == p2[i])
59 if ((i < p1_len && i < p2_len)
60 || (i < p1_len && p1[i] != '/' && i == p2_len)
61 || (i < p2_len && p2[i] != '/' && i == p1_len))
64 --i; // here was the last match
65 while (i && p1[i] != '/')
72 string external_path(string const & p)
78 string internal_path(string const & p)
84 string external_path_list(string const & p)
90 string internal_path_list(string const & p)
96 string latex_path(string const & p)
102 bool is_valid_strftime(string const & p)
104 string::size_type pos = p.find_first_of('%');
105 while (pos != string::npos) {
106 if (pos + 1 == string::npos)
108 if (!containsOnly(p.substr(pos + 1, 1),
109 "aAbBcCdDeEFgGhHIjklmMnOpPrRsStTuUVwWxXyYzZ%+"))
111 if (pos + 2 == string::npos)
113 pos = p.find_first_of('%', pos + 2);
119 char const * popen_read_mode()
125 string const & nulldev()
127 static string const nulldev_ = "/dev/null";
138 char path_separator()
144 void windows_style_tex_paths(bool)
147 bool canAutoOpenFile(string const & ext, auto_open_mode const mode)
150 // Reference: http://developer.apple.com/documentation/Carbon/Reference/LaunchServicesReference/
151 CFStringRef cfs_ext = CFStringCreateWithBytes(kCFAllocatorDefault,
152 (UInt8 *) ext.c_str(), ext.length(),
153 kCFStringEncodingISOLatin1, false);
154 // this is what we would like to do but it seems that the
155 // viewer for PDF is often quicktime...
156 //LSRolesMask role = (mode == VIEW) ? kLSRolesViewer : kLSRolesEditor;
158 LSRolesMask role = kLSRolesAll;
161 LSGetApplicationForInfo(kLSUnknownType, kLSUnknownCreator,
162 cfs_ext, role, &outAppRef, NULL);
165 return status != kLSApplicationNotFoundErr;
167 // silence compiler warnings
171 // currently, no default viewer is tried for non-windows system
172 // support for KDE/Gnome/Macintosh may be added later
178 bool autoOpenFile(string const & filename, auto_open_mode const mode)
181 // Reference: http://developer.apple.com/documentation/Carbon/Reference/LaunchServicesReference/
184 FSPathMakeRef((UInt8 *) filename.c_str(), &fileref, NULL);
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 status = LSGetApplicationForItem(&fileref, role, &outAppRef, NULL);
196 if (status == kLSApplicationNotFoundErr)
199 LSLaunchFSRefSpec inLaunchSpec;
200 inLaunchSpec.appRef = &outAppRef;
201 inLaunchSpec.numDocs = 1;
202 inLaunchSpec.itemRefs = &fileref;
203 inLaunchSpec.passThruParams = NULL;
204 inLaunchSpec.launchFlags = kLSLaunchDefaults;
205 inLaunchSpec.asyncRefCon = NULL;
206 status = LSOpenFromRefSpec(&inLaunchSpec, NULL);
208 return status != kLSApplicationNotFoundErr;
210 // silence compiler warnings
214 // currently, no default viewer is tried for non-windows system
215 // support for KDE/Gnome/Macintosh may be added later
221 bool isSameFile(string const & fileone, string const & filetwo)
226 if (::stat(fileone.c_str(), &st1) == 0
227 && ::stat(filetwo.c_str(), &st2) == 0) {
228 return st1.st_ino == st2.st_ino && st1.st_dev == st2.st_dev;
231 // One or both files cannot be accessed.
236 } // namespace support