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"
18 #include <Carbon/Carbon.h>
28 void init(int, char *[])
38 string::size_type common_path(string const & p1, string const & p2)
40 string::size_type i = 0;
41 string::size_type p1_len = p1.length();
42 string::size_type p2_len = p2.length();
43 while (i < p1_len && i < p2_len && p1[i] == p2[i])
45 if ((i < p1_len && i < p2_len)
46 || (i < p1_len && p1[i] != '/' && i == p2_len)
47 || (i < p2_len && p2[i] != '/' && i == p1_len))
50 --i; // here was the last match
51 while (i && p1[i] != '/')
58 string external_path(string const & p)
64 string internal_path(string const & p)
70 string external_path_list(string const & p)
76 string internal_path_list(string const & p)
82 string latex_path(string const & p)
88 bool is_absolute_path(string const & p)
90 return !p.empty() && p[0] == '/';
94 char const * popen_read_mode()
100 string const & nulldev()
102 static string const nulldev_ = "/dev/null";
113 char path_separator()
119 void windows_style_tex_paths(bool)
122 bool canAutoOpenFile(string const & ext, auto_open_mode const mode)
125 // Reference: http://developer.apple.com/documentation/Carbon/Reference/LaunchServicesReference/
126 CFStringRef cfs_ext = CFStringCreateWithBytes(kCFAllocatorDefault,
127 (UInt8 *) ext.c_str(), ext.length(),
128 kCFStringEncodingISOLatin1, false);
129 LSRolesMask role = (mode == VIEW) ? kLSRolesViewer : kLSRolesEditor;
132 LSGetApplicationForInfo(kLSUnknownType, kLSUnknownCreator,
133 cfs_ext, role, &outAppRef, NULL);
136 return status != kLSApplicationNotFoundErr;
138 // silence compiler warnings
142 // currently, no default viewer is tried for non-windows system
143 // support for KDE/Gnome/Macintosh may be added later
149 bool autoOpenFile(string const & filename, auto_open_mode const mode)
152 // Reference: http://developer.apple.com/documentation/Carbon/Reference/LaunchServicesReference/
155 FSPathMakeRef((UInt8 *) filename.c_str(), &fileref, NULL);
159 LSRolesMask role = (mode == VIEW) ? kLSRolesViewer : kLSRolesEditor;
162 status = LSGetApplicationForItem(&fileref, role, &outAppRef, NULL);
163 if (status == kLSApplicationNotFoundErr)
166 LSLaunchFSRefSpec inLaunchSpec;
167 inLaunchSpec.appRef = &outAppRef;
168 inLaunchSpec.numDocs = 1;
169 inLaunchSpec.itemRefs = &fileref;
170 inLaunchSpec.passThruParams = NULL;
171 inLaunchSpec.launchFlags = kLSLaunchDefaults;
172 inLaunchSpec.asyncRefCon = NULL;
173 status = LSOpenFromRefSpec(&inLaunchSpec, NULL);
175 return status != kLSApplicationNotFoundErr;
177 // silence compiler warnings
181 // currently, no default viewer is tried for non-windows system
182 // support for KDE/Gnome/Macintosh may be added later
188 } // namespace support