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"
18 #include "support/lstrings.h"
21 #include <Carbon/Carbon.h>
30 void init(int, char *[])
40 bool isFilesystemCaseSensitive()
50 docstring::size_type common_path(docstring const & p1, docstring const & p2)
52 docstring::size_type i = 0;
53 docstring::size_type const p1_len = p1.length();
54 docstring::size_type const p2_len = p2.length();
55 while (i < p1_len && i < p2_len && p1[i] == p2[i])
57 if ((i < p1_len && i < p2_len)
58 || (i < p1_len && p1[i] != '/' && i == p2_len)
59 || (i < p2_len && p2[i] != '/' && i == p1_len))
62 --i; // here was the last match
63 while (i && p1[i] != '/')
70 string external_path(string const & p)
76 string internal_path(string const & p)
82 string external_path_list(string const & p)
88 string internal_path_list(string const & p)
94 string latex_path(string const & p)
100 bool is_valid_strftime(string const & p)
102 string::size_type pos = p.find_first_of('%');
103 while (pos != string::npos) {
104 if (pos + 1 == string::npos)
106 if (!containsOnly(p.substr(pos + 1, 1),
107 "aAbBcCdDeEFgGhHIjklmMnOpPrRsStTuUVwWxXyYzZ%+"))
109 if (pos + 2 == string::npos)
111 pos = p.find_first_of('%', pos + 2);
117 char const * popen_read_mode()
123 string const & nulldev()
125 static string const nulldev_ = "/dev/null";
136 char path_separator()
142 void windows_style_tex_paths(bool)
145 bool canAutoOpenFile(string const & ext, auto_open_mode const mode)
148 // Reference: http://developer.apple.com/documentation/Carbon/Reference/LaunchServicesReference/
149 CFStringRef cfs_ext = CFStringCreateWithBytes(kCFAllocatorDefault,
150 (UInt8 *) ext.c_str(), ext.length(),
151 kCFStringEncodingISOLatin1, false);
152 // this is what we would like to do but it seems that the
153 // viewer for PDF is often quicktime...
154 //LSRolesMask role = (mode == VIEW) ? kLSRolesViewer : kLSRolesEditor;
156 LSRolesMask role = kLSRolesAll;
159 LSGetApplicationForInfo(kLSUnknownType, kLSUnknownCreator,
160 cfs_ext, role, &outAppRef, NULL);
163 return status != kLSApplicationNotFoundErr;
165 // silence compiler warnings
169 // currently, no default viewer is tried for non-windows system
170 // support for KDE/Gnome/Macintosh may be added later
176 bool autoOpenFile(string const & filename, auto_open_mode const mode)
179 // Reference: http://developer.apple.com/documentation/Carbon/Reference/LaunchServicesReference/
182 FSPathMakeRef((UInt8 *) filename.c_str(), &fileref, NULL);
186 // this is what we would like to do but it seems that the
187 // viewer for PDF is often quicktime...
188 //LSRolesMask role = (mode == VIEW) ? kLSRolesViewer : kLSRolesEditor;
190 LSRolesMask role = kLSRolesAll;
193 status = LSGetApplicationForItem(&fileref, role, &outAppRef, NULL);
194 if (status == kLSApplicationNotFoundErr)
197 LSLaunchFSRefSpec inLaunchSpec;
198 inLaunchSpec.appRef = &outAppRef;
199 inLaunchSpec.numDocs = 1;
200 inLaunchSpec.itemRefs = &fileref;
201 inLaunchSpec.passThruParams = NULL;
202 inLaunchSpec.launchFlags = kLSLaunchDefaults;
203 inLaunchSpec.asyncRefCon = NULL;
204 status = LSOpenFromRefSpec(&inLaunchSpec, NULL);
206 return status != kLSApplicationNotFoundErr;
208 // silence compiler warnings
212 // currently, no default viewer is tried for non-windows system
213 // support for KDE/Gnome/Macintosh may be added later
219 } // namespace support