2003-06-18 09:56:10 +00:00
|
|
|
/**
|
|
|
|
* \file os_unix.C
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Ruurd A. Reitsma
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-06-18 09:56:10 +00:00
|
|
|
*
|
|
|
|
* Various OS specific functions
|
|
|
|
*/
|
2001-05-17 15:11:01 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2004-11-07 13:22:51 +00:00
|
|
|
#include "support/os.h"
|
2003-10-06 15:43:21 +00:00
|
|
|
|
2006-05-29 16:41:51 +00:00
|
|
|
#ifdef __APPLE__
|
2007-01-11 21:22:18 +00:00
|
|
|
#include "debug.h"
|
2006-05-29 16:41:51 +00:00
|
|
|
#include <Carbon/Carbon.h>
|
2007-01-11 21:22:18 +00:00
|
|
|
#include <ApplicationServices/ApplicationServices.h>
|
|
|
|
using std::endl;
|
2006-05-29 16:41:51 +00:00
|
|
|
#endif
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
using std::string;
|
|
|
|
|
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace support {
|
2003-02-10 10:22:05 +00:00
|
|
|
namespace os {
|
|
|
|
|
2005-01-10 19:17:43 +00:00
|
|
|
void init(int, char *[])
|
|
|
|
{}
|
2001-05-17 15:11:01 +00:00
|
|
|
|
2003-02-10 10:22:05 +00:00
|
|
|
|
|
|
|
string current_root()
|
|
|
|
{
|
|
|
|
return "/";
|
2001-05-17 15:11:01 +00:00
|
|
|
}
|
|
|
|
|
2003-02-10 10:22:05 +00:00
|
|
|
|
2007-03-13 10:22:10 +00:00
|
|
|
docstring::size_type common_path(docstring const & p1, docstring const & p2)
|
2003-02-10 10:22:05 +00:00
|
|
|
{
|
2007-03-13 10:22:10 +00:00
|
|
|
docstring::size_type i = 0;
|
|
|
|
docstring::size_type const p1_len = p1.length();
|
|
|
|
docstring::size_type const p2_len = p2.length();
|
2003-02-10 10:22:05 +00:00
|
|
|
while (i < p1_len && i < p2_len && p1[i] == p2[i])
|
|
|
|
++i;
|
2001-05-17 15:11:01 +00:00
|
|
|
if ((i < p1_len && i < p2_len)
|
|
|
|
|| (i < p1_len && p1[i] != '/' && i == p2_len)
|
2003-02-10 10:22:05 +00:00
|
|
|
|| (i < p2_len && p2[i] != '/' && i == p1_len))
|
|
|
|
{
|
|
|
|
if (i)
|
|
|
|
--i; // here was the last match
|
|
|
|
while (i && p1[i] != '/')
|
|
|
|
--i;
|
2001-05-17 15:11:01 +00:00
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2003-02-10 10:22:05 +00:00
|
|
|
|
|
|
|
string external_path(string const & p)
|
|
|
|
{
|
2001-05-17 15:11:01 +00:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2003-02-10 10:22:05 +00:00
|
|
|
|
|
|
|
string internal_path(string const & p)
|
|
|
|
{
|
2001-10-04 09:57:02 +00:00
|
|
|
return p;
|
|
|
|
}
|
2001-10-08 14:09:06 +00:00
|
|
|
|
2003-02-10 10:22:05 +00:00
|
|
|
|
2006-04-05 19:26:08 +00:00
|
|
|
string external_path_list(string const & p)
|
|
|
|
{
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string internal_path_list(string const & p)
|
|
|
|
{
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-24 12:48:37 +00:00
|
|
|
string latex_path(string const & p)
|
|
|
|
{
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-10 10:22:05 +00:00
|
|
|
bool is_absolute_path(string const & p)
|
2001-10-08 14:09:06 +00:00
|
|
|
{
|
2003-02-10 10:22:05 +00:00
|
|
|
return !p.empty() && p[0] == '/';
|
2001-10-08 14:09:06 +00:00
|
|
|
}
|
2002-02-08 14:32:17 +00:00
|
|
|
|
2003-02-10 10:22:05 +00:00
|
|
|
|
|
|
|
char const * popen_read_mode()
|
2002-02-08 14:32:17 +00:00
|
|
|
{
|
|
|
|
return "r";
|
|
|
|
}
|
2002-09-23 16:03:11 +00:00
|
|
|
|
2003-02-10 10:22:05 +00:00
|
|
|
|
2004-12-15 19:35:43 +00:00
|
|
|
string const & nulldev()
|
|
|
|
{
|
2005-01-10 19:17:43 +00:00
|
|
|
static string const nulldev_ = "/dev/null";
|
2004-12-15 19:35:43 +00:00
|
|
|
return nulldev_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-10 10:22:05 +00:00
|
|
|
shell_type shell()
|
|
|
|
{
|
|
|
|
return UNIX;
|
|
|
|
}
|
|
|
|
|
2005-01-14 15:53:30 +00:00
|
|
|
|
2005-01-13 10:10:16 +00:00
|
|
|
char path_separator()
|
|
|
|
{
|
|
|
|
return ':';
|
|
|
|
}
|
|
|
|
|
2005-01-14 15:53:30 +00:00
|
|
|
|
2006-06-27 10:51:24 +00:00
|
|
|
void windows_style_tex_paths(bool)
|
2005-01-14 15:53:30 +00:00
|
|
|
{}
|
|
|
|
|
2006-05-29 16:41:51 +00:00
|
|
|
bool canAutoOpenFile(string const & ext, auto_open_mode const mode)
|
2006-05-17 22:13:33 +00:00
|
|
|
{
|
2006-05-29 16:41:51 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
// Reference: http://developer.apple.com/documentation/Carbon/Reference/LaunchServicesReference/
|
|
|
|
CFStringRef cfs_ext = CFStringCreateWithBytes(kCFAllocatorDefault,
|
|
|
|
(UInt8 *) ext.c_str(), ext.length(),
|
|
|
|
kCFStringEncodingISOLatin1, false);
|
2007-01-08 13:20:19 +00:00
|
|
|
// this is what we would like to do but it seems that the
|
|
|
|
// viewer for PDF is often quicktime...
|
|
|
|
//LSRolesMask role = (mode == VIEW) ? kLSRolesViewer : kLSRolesEditor;
|
|
|
|
(void)mode;
|
|
|
|
LSRolesMask role = kLSRolesAll;
|
2006-05-29 16:41:51 +00:00
|
|
|
FSRef outAppRef;
|
|
|
|
OSStatus status =
|
|
|
|
LSGetApplicationForInfo(kLSUnknownType, kLSUnknownCreator,
|
|
|
|
cfs_ext, role, &outAppRef, NULL);
|
|
|
|
CFRelease(cfs_ext);
|
|
|
|
|
|
|
|
return status != kLSApplicationNotFoundErr;
|
|
|
|
#else
|
|
|
|
// silence compiler warnings
|
|
|
|
(void)ext;
|
|
|
|
(void)mode;
|
|
|
|
|
2006-05-17 22:13:33 +00:00
|
|
|
// currently, no default viewer is tried for non-windows system
|
|
|
|
// support for KDE/Gnome/Macintosh may be added later
|
|
|
|
return false;
|
2006-05-29 16:41:51 +00:00
|
|
|
#endif
|
2006-05-17 22:13:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-29 16:41:51 +00:00
|
|
|
bool autoOpenFile(string const & filename, auto_open_mode const mode)
|
2006-05-17 22:13:33 +00:00
|
|
|
{
|
2006-05-29 16:41:51 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
// Reference: http://developer.apple.com/documentation/Carbon/Reference/LaunchServicesReference/
|
2007-01-08 13:20:19 +00:00
|
|
|
FSRef fileref;
|
|
|
|
OSStatus status =
|
|
|
|
FSPathMakeRef((UInt8 *) filename.c_str(), &fileref, NULL);
|
|
|
|
if (status != 0)
|
|
|
|
return false;
|
2006-05-29 16:41:51 +00:00
|
|
|
|
2007-01-08 13:20:19 +00:00
|
|
|
// this is what we would like to do but it seems that the
|
|
|
|
// viewer for PDF is often quicktime...
|
|
|
|
//LSRolesMask role = (mode == VIEW) ? kLSRolesViewer : kLSRolesEditor;
|
|
|
|
(void)mode;
|
|
|
|
LSRolesMask role = kLSRolesAll;
|
2006-05-29 16:41:51 +00:00
|
|
|
FSRef outAppRef;
|
|
|
|
|
|
|
|
status = LSGetApplicationForItem(&fileref, role, &outAppRef, NULL);
|
|
|
|
if (status == kLSApplicationNotFoundErr)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
LSLaunchFSRefSpec inLaunchSpec;
|
|
|
|
inLaunchSpec.appRef = &outAppRef;
|
|
|
|
inLaunchSpec.numDocs = 1;
|
|
|
|
inLaunchSpec.itemRefs = &fileref;
|
|
|
|
inLaunchSpec.passThruParams = NULL;
|
|
|
|
inLaunchSpec.launchFlags = kLSLaunchDefaults;
|
|
|
|
inLaunchSpec.asyncRefCon = NULL;
|
|
|
|
status = LSOpenFromRefSpec(&inLaunchSpec, NULL);
|
|
|
|
|
|
|
|
return status != kLSApplicationNotFoundErr;
|
|
|
|
#else
|
|
|
|
// silence compiler warnings
|
|
|
|
(void)filename;
|
|
|
|
(void)mode;
|
|
|
|
|
2006-05-17 22:13:33 +00:00
|
|
|
// currently, no default viewer is tried for non-windows system
|
|
|
|
// support for KDE/Gnome/Macintosh may be added later
|
|
|
|
return false;
|
2006-05-29 16:41:51 +00:00
|
|
|
#endif
|
2006-05-17 22:13:33 +00:00
|
|
|
}
|
|
|
|
|
2007-01-11 21:22:18 +00:00
|
|
|
|
|
|
|
void addFontResources()
|
|
|
|
{
|
|
|
|
#ifdef __APPLE__
|
|
|
|
CFBundleRef myAppBundle = CFBundleGetMainBundle();
|
|
|
|
CFURLRef myAppResourcesURL, FontsURL;
|
|
|
|
FSRef fontDirRef;
|
|
|
|
FSSpec fontDirSpec;
|
|
|
|
CFStringRef filePath = CFStringCreateWithBytes(kCFAllocatorDefault,
|
2007-04-25 14:05:03 +00:00
|
|
|
(UInt8 *) "fonts", strlen("fonts"),
|
2007-01-11 21:22:18 +00:00
|
|
|
kCFStringEncodingISOLatin1, false);
|
|
|
|
|
|
|
|
myAppResourcesURL = CFBundleCopyResourcesDirectoryURL(myAppBundle);
|
|
|
|
FontsURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorDefault,
|
|
|
|
myAppResourcesURL, filePath, true);
|
|
|
|
if (lyxerr.debugging(Debug::FONT)) {
|
|
|
|
UInt8 buf[255];
|
|
|
|
if (CFURLGetFileSystemRepresentation(FontsURL, true, buf, 255))
|
|
|
|
lyxerr << "Adding Fonts directory: " << buf << endl;
|
|
|
|
}
|
|
|
|
CFURLGetFSRef (FontsURL, &fontDirRef);
|
|
|
|
OSStatus err = FSGetCatalogInfo (&fontDirRef, kFSCatInfoNone,
|
|
|
|
NULL, NULL, &fontDirSpec, NULL);
|
|
|
|
if (err)
|
|
|
|
lyxerr << "FSGetCatalogInfo err = " << err << endl;
|
|
|
|
err = FMActivateFonts (&fontDirSpec, NULL, NULL,
|
|
|
|
kFMLocalActivationContext);
|
|
|
|
if (err)
|
|
|
|
lyxerr << "FMActivateFonts err = " << err << endl;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void restoreFontResources()
|
|
|
|
{}
|
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
} // namespace os
|
|
|
|
} // namespace support
|
|
|
|
} // namespace lyx
|