]> 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 e2c772522168a5c502210683cf30f4bfd91e39a1..eb8c1dfa4e3440433002c6ad76538ddd7b4687cd 100644 (file)
 
 #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 <Carbon/Carbon.h>
 #endif
 
-using std::string;
-
+using namespace std;
 
 namespace lyx {
 namespace support {
@@ -36,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;
@@ -86,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;
 }
 
 
@@ -105,6 +130,12 @@ string const & nulldev()
 }
 
 
+bool is_terminal(io_channel channel)
+{
+       return isatty(channel);
+}
+
+
 shell_type shell()
 {
        return UNIX;
@@ -193,6 +224,14 @@ bool autoOpenFile(string const & filename, auto_open_mode const mode)
 #endif
 }
 
+
+string real_path(string const & path)
+{
+       char rpath[PATH_MAX + 1];
+       char * result = realpath(path.c_str(), rpath);
+       return FileName::fromFilesystemEncoding(result ? rpath : path).absFilename();
+}
+
 } // namespace os
 } // namespace support
 } // namespace lyx