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 docstring::size_type common_path(docstring const & p1, docstring const & p2)
40 docstring::size_type i = 0;
41 docstring::size_type const p1_len = p1.length();
42 docstring::size_type const 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 // this is what we would like to do but it seems that the
130 // viewer for PDF is often quicktime...
131 //LSRolesMask role = (mode == VIEW) ? kLSRolesViewer : kLSRolesEditor;
133 LSRolesMask role = kLSRolesAll;
136 LSGetApplicationForInfo(kLSUnknownType, kLSUnknownCreator,
137 cfs_ext, role, &outAppRef, NULL);
140 return status != kLSApplicationNotFoundErr;
142 // silence compiler warnings
146 // currently, no default viewer is tried for non-windows system
147 // support for KDE/Gnome/Macintosh may be added later
153 bool autoOpenFile(string const & filename, auto_open_mode const mode)
156 // Reference: http://developer.apple.com/documentation/Carbon/Reference/LaunchServicesReference/
159 FSPathMakeRef((UInt8 *) filename.c_str(), &fileref, NULL);
163 // this is what we would like to do but it seems that the
164 // viewer for PDF is often quicktime...
165 //LSRolesMask role = (mode == VIEW) ? kLSRolesViewer : kLSRolesEditor;
167 LSRolesMask role = kLSRolesAll;
170 status = LSGetApplicationForItem(&fileref, role, &outAppRef, NULL);
171 if (status == kLSApplicationNotFoundErr)
174 LSLaunchFSRefSpec inLaunchSpec;
175 inLaunchSpec.appRef = &outAppRef;
176 inLaunchSpec.numDocs = 1;
177 inLaunchSpec.itemRefs = &fileref;
178 inLaunchSpec.passThruParams = NULL;
179 inLaunchSpec.launchFlags = kLSLaunchDefaults;
180 inLaunchSpec.asyncRefCon = NULL;
181 status = LSOpenFromRefSpec(&inLaunchSpec, NULL);
183 return status != kLSApplicationNotFoundErr;
185 // silence compiler warnings
189 // currently, no default viewer is tried for non-windows system
190 // support for KDE/Gnome/Macintosh may be added later
196 } // namespace support