#include <QDir>
#include "support/lassert.h"
-#include <boost/regex.hpp>
+#include "support/regex.h"
#include <fcntl.h>
#include <fstream>
#include <sstream>
+#if defined (_WIN32)
+#include <io.h>
+#include <windows.h>
+#endif
+
using namespace std;
#define USE_QPROCESS
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;
}
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()) {
// $\{[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) {
}
+#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(),
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)
// pstream (process stream), with the
// variants ipstream, opstream
-#if defined (HAVE_POPEN)
+#if defined (_WIN32)
+ 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)) {
+ 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;
+
+ if (CreateProcess(0, (LPTSTR)cmd.c_str(), &security, &security,
+ TRUE, CREATE_NO_WINDOW, 0, 0, &startup, &process)) {
+
+ CloseHandle(process.hThread);
+ fno = _open_osfhandle((long)in, _O_RDONLY);
+ CloseHandle(out);
+ inf = _fdopen(fno, "r");
+ }
+ }
+#elif defined (HAVE_POPEN)
FILE * inf = ::popen(cmd.c_str(), os::popen_read_mode());
#elif defined (HAVE__POPEN)
FILE * inf = ::_popen(cmd.c_str(), os::popen_read_mode());
c = fgetc(inf);
}
-#if defined (HAVE_PCLOSE)
+#if defined (_WIN32)
+ WaitForSingleObject(process.hProcess, INFINITE);
+ CloseHandle(process.hProcess);
+ int const pret = fclose(inf);
+#elif defined (HAVE_PCLOSE)
int const pret = pclose(inf);
#elif defined (HAVE__PCLOSE)
int const pret = _pclose(inf);
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.