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>
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 char const * popen_read_mode()
94 string const & nulldev()
96 static string const nulldev_ = "/dev/null";
107 char path_separator()
113 void windows_style_tex_paths(bool)
116 bool canAutoOpenFile(string const & ext, auto_open_mode const mode)
119 // Reference: http://developer.apple.com/documentation/Carbon/Reference/LaunchServicesReference/
120 CFStringRef cfs_ext = CFStringCreateWithBytes(kCFAllocatorDefault,
121 (UInt8 *) ext.c_str(), ext.length(),
122 kCFStringEncodingISOLatin1, false);
123 // this is what we would like to do but it seems that the
124 // viewer for PDF is often quicktime...
125 //LSRolesMask role = (mode == VIEW) ? kLSRolesViewer : kLSRolesEditor;
127 LSRolesMask role = kLSRolesAll;
130 LSGetApplicationForInfo(kLSUnknownType, kLSUnknownCreator,
131 cfs_ext, role, &outAppRef, NULL);
134 return status != kLSApplicationNotFoundErr;
136 // silence compiler warnings
140 // currently, no default viewer is tried for non-windows system
141 // support for KDE/Gnome/Macintosh may be added later
147 bool autoOpenFile(string const & filename, auto_open_mode const mode)
150 // Reference: http://developer.apple.com/documentation/Carbon/Reference/LaunchServicesReference/
153 FSPathMakeRef((UInt8 *) filename.c_str(), &fileref, NULL);
157 // this is what we would like to do but it seems that the
158 // viewer for PDF is often quicktime...
159 //LSRolesMask role = (mode == VIEW) ? kLSRolesViewer : kLSRolesEditor;
161 LSRolesMask role = kLSRolesAll;
164 status = LSGetApplicationForItem(&fileref, role, &outAppRef, NULL);
165 if (status == kLSApplicationNotFoundErr)
168 LSLaunchFSRefSpec inLaunchSpec;
169 inLaunchSpec.appRef = &outAppRef;
170 inLaunchSpec.numDocs = 1;
171 inLaunchSpec.itemRefs = &fileref;
172 inLaunchSpec.passThruParams = NULL;
173 inLaunchSpec.launchFlags = kLSLaunchDefaults;
174 inLaunchSpec.asyncRefCon = NULL;
175 status = LSOpenFromRefSpec(&inLaunchSpec, NULL);
177 return status != kLSApplicationNotFoundErr;
179 // silence compiler warnings
183 // currently, no default viewer is tried for non-windows system
184 // support for KDE/Gnome/Macintosh may be added later
190 } // namespace support