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"
24 #include <Carbon/Carbon.h>
33 void init(int, char *[])
43 bool isFilesystemCaseSensitive()
53 docstring::size_type common_path(docstring const & p1, docstring const & p2)
55 docstring::size_type i = 0;
56 docstring::size_type const p1_len = p1.length();
57 docstring::size_type const p2_len = p2.length();
58 while (i < p1_len && i < p2_len && p1[i] == p2[i])
60 if ((i < p1_len && i < p2_len)
61 || (i < p1_len && p1[i] != '/' && i == p2_len)
62 || (i < p2_len && p2[i] != '/' && i == p1_len))
65 --i; // here was the last match
66 while (i && p1[i] != '/')
73 string external_path(string const & p)
79 string internal_path(string const & p)
85 string external_path_list(string const & p)
91 string internal_path_list(string const & p)
97 string latex_path(string const & p)
103 bool is_valid_strftime(string const & p)
105 string::size_type pos = p.find_first_of('%');
106 while (pos != string::npos) {
107 if (pos + 1 == string::npos)
109 if (!containsOnly(p.substr(pos + 1, 1),
110 "aAbBcCdDeEFgGhHIjklmMnOpPrRsStTuUVwWxXyYzZ%+"))
112 if (pos + 2 == string::npos)
114 pos = p.find_first_of('%', pos + 2);
120 char const * popen_read_mode()
126 string const & nulldev()
128 static string const nulldev_ = "/dev/null";
139 char path_separator()
145 void windows_style_tex_paths(bool)
148 bool canAutoOpenFile(string const & ext, auto_open_mode const mode)
151 // Reference: http://developer.apple.com/documentation/Carbon/Reference/LaunchServicesReference/
152 CFStringRef cfs_ext = CFStringCreateWithBytes(kCFAllocatorDefault,
153 (UInt8 *) ext.c_str(), ext.length(),
154 kCFStringEncodingISOLatin1, false);
155 // this is what we would like to do but it seems that the
156 // viewer for PDF is often quicktime...
157 //LSRolesMask role = (mode == VIEW) ? kLSRolesViewer : kLSRolesEditor;
159 LSRolesMask role = kLSRolesAll;
162 LSGetApplicationForInfo(kLSUnknownType, kLSUnknownCreator,
163 cfs_ext, role, &outAppRef, NULL);
166 return status != kLSApplicationNotFoundErr;
168 // silence compiler warnings
172 // currently, no default viewer is tried for non-windows system
173 // support for KDE/Gnome/Macintosh may be added later
179 bool autoOpenFile(string const & filename, auto_open_mode const mode)
182 // Reference: http://developer.apple.com/documentation/Carbon/Reference/LaunchServicesReference/
185 FSPathMakeRef((UInt8 *) filename.c_str(), &fileref, NULL);
189 // this is what we would like to do but it seems that the
190 // viewer for PDF is often quicktime...
191 //LSRolesMask role = (mode == VIEW) ? kLSRolesViewer : kLSRolesEditor;
193 LSRolesMask role = kLSRolesAll;
196 status = LSGetApplicationForItem(&fileref, role, &outAppRef, NULL);
197 if (status == kLSApplicationNotFoundErr)
200 LSLaunchFSRefSpec inLaunchSpec;
201 inLaunchSpec.appRef = &outAppRef;
202 inLaunchSpec.numDocs = 1;
203 inLaunchSpec.itemRefs = &fileref;
204 inLaunchSpec.passThruParams = NULL;
205 inLaunchSpec.launchFlags = kLSLaunchDefaults;
206 inLaunchSpec.asyncRefCon = NULL;
207 status = LSOpenFromRefSpec(&inLaunchSpec, NULL);
209 return status != kLSApplicationNotFoundErr;
211 // silence compiler warnings
215 // currently, no default viewer is tried for non-windows system
216 // support for KDE/Gnome/Macintosh may be added later
222 string real_path(string const & path)
224 char rpath[PATH_MAX + 1];
225 char * result = realpath(path.c_str(), rpath);
226 return FileName::fromFilesystemEncoding(result ? rpath : path).absFilename();
230 } // namespace support