]> git.lyx.org Git - lyx.git/blob - src/support/os_unix.C
remove unused stuff
[lyx.git] / src / support / os_unix.C
1 /**
2  * \file os_unix.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Ruurd A. Reitsma
7  *
8  * Full author contact details are available in file CREDITS.
9  *
10  * Various OS specific functions
11  */
12
13 #include <config.h>
14
15 #include "support/os.h"
16
17 #ifdef __APPLE__
18 #include <Carbon/Carbon.h>
19 #endif
20
21 using std::string;
22
23
24 namespace lyx {
25 namespace support {
26 namespace os {
27
28 void init(int, char *[])
29 {}
30
31
32 string current_root()
33 {
34         return "/";
35 }
36
37
38 string::size_type common_path(string const & p1, string const & p2)
39 {
40         string::size_type i = 0;
41         string::size_type p1_len = p1.length();
42         string::size_type p2_len = p2.length();
43         while (i < p1_len && i < p2_len && p1[i] == p2[i])
44                 ++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))
48         {
49                 if (i)
50                         --i;     // here was the last match
51                 while (i && p1[i] != '/')
52                         --i;
53         }
54         return i;
55 }
56
57
58 string external_path(string const & p)
59 {
60         return p;
61 }
62
63
64 string internal_path(string const & p)
65 {
66         return p;
67 }
68
69
70 string external_path_list(string const & p)
71 {
72         return p;
73 }
74
75
76 string internal_path_list(string const & p)
77 {
78         return p;
79 }
80
81
82 string latex_path(string const & p)
83 {
84         return p;
85 }
86
87
88 bool is_absolute_path(string const & p)
89 {
90         return !p.empty() && p[0] == '/';
91 }
92
93
94 char const * popen_read_mode()
95 {
96         return "r";
97 }
98
99
100 string const & nulldev()
101 {
102         static string const nulldev_ = "/dev/null";
103         return nulldev_;
104 }
105
106
107 shell_type shell()
108 {
109         return UNIX;
110 }
111
112
113 char path_separator()
114 {
115         return ':';
116 }
117
118
119 void windows_style_tex_paths(bool)
120 {}
121
122 bool canAutoOpenFile(string const & ext, auto_open_mode const mode)
123 {
124 #ifdef __APPLE__
125 // Reference: http://developer.apple.com/documentation/Carbon/Reference/LaunchServicesReference/
126         CFStringRef cfs_ext = CFStringCreateWithBytes(kCFAllocatorDefault,
127                                         (UInt8 *) ext.c_str(), ext.length(),
128                                         kCFStringEncodingISOLatin1, false);
129         LSRolesMask role = (mode == VIEW) ? kLSRolesViewer :  kLSRolesEditor;
130         FSRef outAppRef;
131         OSStatus status = 
132                 LSGetApplicationForInfo(kLSUnknownType, kLSUnknownCreator,
133                                         cfs_ext, role, &outAppRef, NULL);
134         CFRelease(cfs_ext);
135
136         return status != kLSApplicationNotFoundErr;
137 #else
138         // silence compiler warnings
139         (void)ext;
140         (void)mode;
141
142         // currently, no default viewer is tried for non-windows system
143         // support for KDE/Gnome/Macintosh may be added later
144         return false;
145 #endif
146 }
147
148
149 bool autoOpenFile(string const & filename, auto_open_mode const mode)
150 {
151 #ifdef __APPLE__
152 // Reference: http://developer.apple.com/documentation/Carbon/Reference/LaunchServicesReference/
153     FSRef fileref;
154     OSStatus status = 
155         FSPathMakeRef((UInt8 *) filename.c_str(), &fileref, NULL);
156     if (status != 0)
157         return false;
158         
159         LSRolesMask role = (mode == VIEW) ? kLSRolesViewer :  kLSRolesEditor;
160         FSRef outAppRef;
161
162         status = LSGetApplicationForItem(&fileref, role, &outAppRef, NULL);
163         if (status == kLSApplicationNotFoundErr)
164                 return false;
165
166         LSLaunchFSRefSpec inLaunchSpec;
167         inLaunchSpec.appRef = &outAppRef;
168         inLaunchSpec.numDocs = 1;
169         inLaunchSpec.itemRefs = &fileref;
170         inLaunchSpec.passThruParams = NULL;
171         inLaunchSpec.launchFlags = kLSLaunchDefaults;
172         inLaunchSpec.asyncRefCon = NULL;
173         status = LSOpenFromRefSpec(&inLaunchSpec, NULL);
174
175         return status != kLSApplicationNotFoundErr;     
176 #else
177         // silence compiler warnings
178         (void)filename;
179         (void)mode;
180
181         // currently, no default viewer is tried for non-windows system
182         // support for KDE/Gnome/Macintosh may be added later
183         return false;
184 #endif
185 }
186
187 } // namespace os
188 } // namespace support
189 } // namespace lyx