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"
20 #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 char const * popen_read_mode()
95 string const & nulldev()
97 static string const nulldev_ = "/dev/null";
108 char path_separator()
114 void windows_style_tex_paths(bool)
117 bool canAutoOpenFile(string const & ext, auto_open_mode const mode)
120 // Reference: http://developer.apple.com/documentation/Carbon/Reference/LaunchServicesReference/
121 CFStringRef cfs_ext = CFStringCreateWithBytes(kCFAllocatorDefault,
122 (UInt8 *) ext.c_str(), ext.length(),
123 kCFStringEncodingISOLatin1, false);
124 // this is what we would like to do but it seems that the
125 // viewer for PDF is often quicktime...
126 //LSRolesMask role = (mode == VIEW) ? kLSRolesViewer : kLSRolesEditor;
128 LSRolesMask role = kLSRolesAll;
131 LSGetApplicationForInfo(kLSUnknownType, kLSUnknownCreator,
132 cfs_ext, role, &outAppRef, NULL);
135 return status != kLSApplicationNotFoundErr;
137 // silence compiler warnings
141 // currently, no default viewer is tried for non-windows system
142 // support for KDE/Gnome/Macintosh may be added later
148 bool autoOpenFile(string const & filename, auto_open_mode const mode)
151 // Reference: http://developer.apple.com/documentation/Carbon/Reference/LaunchServicesReference/
154 FSPathMakeRef((UInt8 *) filename.c_str(), &fileref, NULL);
158 // this is what we would like to do but it seems that the
159 // viewer for PDF is often quicktime...
160 //LSRolesMask role = (mode == VIEW) ? kLSRolesViewer : kLSRolesEditor;
162 LSRolesMask role = kLSRolesAll;
165 status = LSGetApplicationForItem(&fileref, role, &outAppRef, NULL);
166 if (status == kLSApplicationNotFoundErr)
169 LSLaunchFSRefSpec inLaunchSpec;
170 inLaunchSpec.appRef = &outAppRef;
171 inLaunchSpec.numDocs = 1;
172 inLaunchSpec.itemRefs = &fileref;
173 inLaunchSpec.passThruParams = NULL;
174 inLaunchSpec.launchFlags = kLSLaunchDefaults;
175 inLaunchSpec.asyncRefCon = NULL;
176 status = LSOpenFromRefSpec(&inLaunchSpec, NULL);
178 return status != kLSApplicationNotFoundErr;
180 // silence compiler warnings
184 // currently, no default viewer is tried for non-windows system
185 // support for KDE/Gnome/Macintosh may be added later
191 } // namespace support