]> git.lyx.org Git - lyx.git/blobdiff - src/support/filetools.cpp
add generic helper class for calling functions in gui thread
[lyx.git] / src / support / filetools.cpp
index db65c6a710fb0b4f1903156c359faa72a32825c7..82d8766cff36bf118a95f0a4e7ce6372c7973008 100644 (file)
@@ -36,7 +36,7 @@
 #include <QDir>
 
 #include "support/lassert.h"
-#include <boost/regex.hpp>
+#include "support/regex.h"
 
 #include <fcntl.h>
 
@@ -74,7 +74,14 @@ bool isSGMLFileName(string const & filename)
 
 bool isValidLaTeXFileName(string const & filename)
 {
-       string const invalid_chars("#$%{}()[]\"^");
+       string const invalid_chars("#%\"");
+       return filename.find_first_of(invalid_chars) == string::npos;
+}
+
+
+bool isValidDVIFileName(string const & filename)
+{
+       string const invalid_chars("${}()[]^");
        return filename.find_first_of(invalid_chars) == string::npos;
 }
 
@@ -355,7 +362,7 @@ FileName const createLyXTmpDir(FileName const & deflt)
        if (deflt.empty() || deflt == package().system_temp_dir())
                return createTmpDir(package().system_temp_dir(), "lyx_tmpdir");
 
-       if (deflt.createDirectory(0777)) 
+       if (deflt.createDirectory(0777))
                return deflt;
 
        if (deflt.isDirWritable()) {
@@ -537,9 +544,9 @@ string const replaceEnvironmentPath(string const & path)
        // $\{[A-Za-z_][A-Za-z_0-9]*\}
        static string const envvar = "[$]([A-Za-z_][A-Za-z_0-9]*)";
 
-       static boost::regex envvar_br_re("(.*)" + envvar_br + "(.*)");
-       static boost::regex envvar_re("(.*)" + envvar + "(.*)");
-       boost::smatch what;
+       static regex envvar_br_re("(.*)" + envvar_br + "(.*)");
+       static regex envvar_re("(.*)" + envvar + "(.*)");
+       smatch what;
        string result;
        string remaining = path;
        while (1) {
@@ -741,9 +748,9 @@ docstring const makeDisplayPath(string const & path, unsigned int threshold)
 }
 
 
+#ifdef HAVE_READLINK
 bool readLink(FileName const & file, FileName & link)
 {
-#ifdef HAVE_READLINK
        char linkbuffer[PATH_MAX + 1];
        string const encoded = file.toFilesystemEncoding();
        int const nRead = ::readlink(encoded.c_str(),
@@ -753,10 +760,13 @@ bool readLink(FileName const & file, FileName & link)
        linkbuffer[nRead] = '\0'; // terminator
        link = makeAbsPath(linkbuffer, onlyPath(file.absFileName()));
        return true;
+}
 #else
+bool readLink(FileName const &, FileName &)
+{
        return false;
-#endif
 }
+#endif
 
 
 cmd_ret const runCommand(string const & cmd)
@@ -772,24 +782,24 @@ cmd_ret const runCommand(string const & cmd)
        // variants ipstream, opstream
 
 #if defined (_WIN32)
-       int fno; 
-       STARTUPINFO startup; 
-       PROCESS_INFORMATION process; 
-       SECURITY_ATTRIBUTES security; 
+       int fno;
+       STARTUPINFO startup;
+       PROCESS_INFORMATION process;
+       SECURITY_ATTRIBUTES security;
        HANDLE in, out;
        FILE * inf = 0;
-    
-       security.nLength = sizeof(SECURITY_ATTRIBUTES); 
-       security.bInheritHandle = TRUE; 
-       security.lpSecurityDescriptor = NULL; 
 
-       if (CreatePipe(&in, &out, &security, 0)) { 
+       security.nLength = sizeof(SECURITY_ATTRIBUTES);
+       security.bInheritHandle = TRUE;
+       security.lpSecurityDescriptor = NULL;
+
+       if (CreatePipe(&in, &out, &security, 0)) {
                memset(&startup, 0, sizeof(STARTUPINFO));
                memset(&process, 0, sizeof(PROCESS_INFORMATION));
-    
+
                startup.cb = sizeof(STARTUPINFO);
                startup.dwFlags = STARTF_USESTDHANDLES;
-  
+
                startup.hStdError = GetStdHandle(STD_ERROR_HANDLE);
                startup.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
                startup.hStdOutput = out;
@@ -921,13 +931,13 @@ string const readBB_from_PSFile(FileName const & file)
                return string();
        }
 
-       static boost::regex bbox_re(
+       static lyx::regex bbox_re(
                "^%%BoundingBox:\\s*([[:digit:]]+)\\s+([[:digit:]]+)\\s+([[:digit:]]+)\\s+([[:digit:]]+)");
        ifstream is(file_.toFilesystemEncoding().c_str());
        while (is) {
                string s;
                getline(is,s);
-               boost::smatch what;
+               lyx::smatch what;
                if (regex_match(s, what, bbox_re)) {
                        // Our callers expect the tokens in the string
                        // separated by single spaces.