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";
133 bool is_terminal(io_channel channel)
135 return isatty(channel);
145 char path_separator()
151 void windows_style_tex_paths(bool)
154 bool canAutoOpenFile(string const & ext, auto_open_mode const mode)
157 // Reference: http://developer.apple.com/documentation/Carbon/Reference/LaunchServicesReference/
158 CFStringRef cfs_ext = CFStringCreateWithBytes(kCFAllocatorDefault,
159 (UInt8 *) ext.c_str(), ext.length(),
160 kCFStringEncodingISOLatin1, false);
161 // this is what we would like to do but it seems that the
162 // viewer for PDF is often quicktime...
163 //LSRolesMask role = (mode == VIEW) ? kLSRolesViewer : kLSRolesEditor;
165 LSRolesMask role = kLSRolesAll;
168 LSGetApplicationForInfo(kLSUnknownType, kLSUnknownCreator,
169 cfs_ext, role, &outAppRef, NULL);
172 return status != kLSApplicationNotFoundErr;
174 // silence compiler warnings
178 // currently, no default viewer is tried for non-windows system
179 // support for KDE/Gnome/Macintosh may be added later
185 bool autoOpenFile(string const & filename, auto_open_mode const mode)
188 // Reference: http://developer.apple.com/documentation/Carbon/Reference/LaunchServicesReference/
191 FSPathMakeRef((UInt8 *) filename.c_str(), &fileref, NULL);
195 // this is what we would like to do but it seems that the
196 // viewer for PDF is often quicktime...
197 //LSRolesMask role = (mode == VIEW) ? kLSRolesViewer : kLSRolesEditor;
199 LSRolesMask role = kLSRolesAll;
202 status = LSGetApplicationForItem(&fileref, role, &outAppRef, NULL);
203 if (status == kLSApplicationNotFoundErr)
206 LSLaunchFSRefSpec inLaunchSpec;
207 inLaunchSpec.appRef = &outAppRef;
208 inLaunchSpec.numDocs = 1;
209 inLaunchSpec.itemRefs = &fileref;
210 inLaunchSpec.passThruParams = NULL;
211 inLaunchSpec.launchFlags = kLSLaunchDefaults;
212 inLaunchSpec.asyncRefCon = NULL;
213 status = LSOpenFromRefSpec(&inLaunchSpec, NULL);
215 return status != kLSApplicationNotFoundErr;
217 // silence compiler warnings
221 // currently, no default viewer is tried for non-windows system
222 // support for KDE/Gnome/Macintosh may be added later
228 string real_path(string const & path)
230 char rpath[PATH_MAX + 1];
231 char * result = realpath(path.c_str(), rpath);
232 return FileName::fromFilesystemEncoding(result ? rpath : path).absFilename();
236 } // namespace support