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"
19 #include <Carbon/Carbon.h>
29 void init(int, char *[])
39 docstring::size_type common_path(docstring const & p1, docstring const & p2)
41 docstring::size_type i = 0;
42 docstring::size_type const p1_len = p1.length();
43 docstring::size_type const p2_len = p2.length();
44 while (i < p1_len && i < p2_len && p1[i] == p2[i])
46 if ((i < p1_len && i < p2_len)
47 || (i < p1_len && p1[i] != '/' && i == p2_len)
48 || (i < p2_len && p2[i] != '/' && i == p1_len))
51 --i; // here was the last match
52 while (i && p1[i] != '/')
59 string external_path(string const & p)
65 string internal_path(string const & p)
71 string external_path_list(string const & p)
77 string internal_path_list(string const & p)
83 string latex_path(string const & p)
89 bool is_absolute_path(string const & p)
91 return !p.empty() && p[0] == '/';
95 char const * popen_read_mode()
101 string const & nulldev()
103 static string const nulldev_ = "/dev/null";
114 char path_separator()
120 void windows_style_tex_paths(bool)
123 bool canAutoOpenFile(string const & ext, auto_open_mode const mode)
126 // Reference: http://developer.apple.com/documentation/Carbon/Reference/LaunchServicesReference/
127 CFStringRef cfs_ext = CFStringCreateWithBytes(kCFAllocatorDefault,
128 (UInt8 *) ext.c_str(), ext.length(),
129 kCFStringEncodingISOLatin1, false);
130 // this is what we would like to do but it seems that the
131 // viewer for PDF is often quicktime...
132 //LSRolesMask role = (mode == VIEW) ? kLSRolesViewer : kLSRolesEditor;
134 LSRolesMask role = kLSRolesAll;
137 LSGetApplicationForInfo(kLSUnknownType, kLSUnknownCreator,
138 cfs_ext, role, &outAppRef, NULL);
141 return status != kLSApplicationNotFoundErr;
143 // silence compiler warnings
147 // currently, no default viewer is tried for non-windows system
148 // support for KDE/Gnome/Macintosh may be added later
154 bool autoOpenFile(string const & filename, auto_open_mode const mode)
157 // Reference: http://developer.apple.com/documentation/Carbon/Reference/LaunchServicesReference/
160 FSPathMakeRef((UInt8 *) filename.c_str(), &fileref, NULL);
164 // this is what we would like to do but it seems that the
165 // viewer for PDF is often quicktime...
166 //LSRolesMask role = (mode == VIEW) ? kLSRolesViewer : kLSRolesEditor;
168 LSRolesMask role = kLSRolesAll;
171 status = LSGetApplicationForItem(&fileref, role, &outAppRef, NULL);
172 if (status == kLSApplicationNotFoundErr)
175 LSLaunchFSRefSpec inLaunchSpec;
176 inLaunchSpec.appRef = &outAppRef;
177 inLaunchSpec.numDocs = 1;
178 inLaunchSpec.itemRefs = &fileref;
179 inLaunchSpec.passThruParams = NULL;
180 inLaunchSpec.launchFlags = kLSLaunchDefaults;
181 inLaunchSpec.asyncRefCon = NULL;
182 status = LSOpenFromRefSpec(&inLaunchSpec, NULL);
184 return status != kLSApplicationNotFoundErr;
186 // silence compiler warnings
190 // currently, no default viewer is tried for non-windows system
191 // support for KDE/Gnome/Macintosh may be added later
197 } // namespace support