]> git.lyx.org Git - lyx.git/blobdiff - src/support/os_unix.cpp
an example for the sweave module, prepared by Gregor Gorjanc
[lyx.git] / src / support / os_unix.cpp
index 0378e369a3f651ae298ca0163e8e62b412ddf52b..eb8c1dfa4e3440433002c6ad76538ddd7b4687cd 100644 (file)
 #include <config.h>
 
 #include "support/os.h"
+#include "support/docstring.h"
+#include "support/FileName.h"
+#include "support/lstrings.h"
+
+#include <limits.h>
+#include <stdlib.h>
 
 #ifdef __APPLE__
-#include "debug.h"
 #include <Carbon/Carbon.h>
-#include <ApplicationServices/ApplicationServices.h>
-using std::endl;
 #endif
 
-using std::string;
-
+using namespace std;
 
 namespace lyx {
 namespace support {
@@ -38,6 +40,16 @@ string current_root()
 }
 
 
+bool isFilesystemCaseSensitive()
+{
+#ifdef __APPLE__
+       return false;
+#else
+       return true;
+#endif
+}
+
+
 docstring::size_type common_path(docstring const & p1, docstring const & p2)
 {
        docstring::size_type i = 0;
@@ -88,9 +100,20 @@ string latex_path(string const & p)
 }
 
 
-bool is_absolute_path(string const & p)
+bool is_valid_strftime(string const & p)
 {
-       return !p.empty() && p[0] == '/';
+       string::size_type pos = p.find_first_of('%');
+       while (pos != string::npos) {
+               if (pos + 1 == string::npos)
+                       break;
+               if (!containsOnly(p.substr(pos + 1, 1),
+                       "aAbBcCdDeEFgGhHIjklmMnOpPrRsStTuUVwWxXyYzZ%+"))
+                       return false;
+               if (pos + 2 == string::npos)
+                     break;
+               pos = p.find_first_of('%', pos + 2);
+       }
+       return true;
 }
 
 
@@ -107,6 +130,12 @@ string const & nulldev()
 }
 
 
+bool is_terminal(io_channel channel)
+{
+       return isatty(channel);
+}
+
+
 shell_type shell()
 {
        return UNIX;
@@ -135,7 +164,7 @@ bool canAutoOpenFile(string const & ext, auto_open_mode const mode)
        (void)mode;
        LSRolesMask role = kLSRolesAll;
        FSRef outAppRef;
-       OSStatus status = 
+       OSStatus status =
                LSGetApplicationForInfo(kLSUnknownType, kLSUnknownCreator,
                                        cfs_ext, role, &outAppRef, NULL);
        CFRelease(cfs_ext);
@@ -158,11 +187,11 @@ bool autoOpenFile(string const & filename, auto_open_mode const mode)
 #ifdef __APPLE__
 // Reference: http://developer.apple.com/documentation/Carbon/Reference/LaunchServicesReference/
        FSRef fileref;
-       OSStatus status = 
+       OSStatus status =
                FSPathMakeRef((UInt8 *) filename.c_str(), &fileref, NULL);
        if (status != 0)
                return false;
-        
+
        // 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;
@@ -183,7 +212,7 @@ bool autoOpenFile(string const & filename, auto_open_mode const mode)
        inLaunchSpec.asyncRefCon = NULL;
        status = LSOpenFromRefSpec(&inLaunchSpec, NULL);
 
-       return status != kLSApplicationNotFoundErr;     
+       return status != kLSApplicationNotFoundErr;
 #else
        // silence compiler warnings
        (void)filename;
@@ -196,41 +225,13 @@ bool autoOpenFile(string const & filename, auto_open_mode const mode)
 }
 
 
-void addFontResources()
+string real_path(string const & path)
 {
-#ifdef __APPLE__
-       CFBundleRef  myAppBundle = CFBundleGetMainBundle();
-       CFURLRef  myAppResourcesURL, FontsURL;
-       FSRef  fontDirRef;
-       FSSpec  fontDirSpec;
-       CFStringRef  filePath = CFStringCreateWithBytes(kCFAllocatorDefault,
-                                       (UInt8 *) "fonts", strlen("fonts"),
-                                       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
+       char rpath[PATH_MAX + 1];
+       char * result = realpath(path.c_str(), rpath);
+       return FileName::fromFilesystemEncoding(result ? rpath : path).absFilename();
 }
 
-
-void restoreFontResources()
-{}
-
 } // namespace os
 } // namespace support
 } // namespace lyx