]> git.lyx.org Git - lyx.git/blobdiff - src/support/Systemcall.cpp
Less expensive OP first as this might be called often.
[lyx.git] / src / support / Systemcall.cpp
index d0ff9ae993f1111bad555976db32d16d992f3d24..7c4eaabc979490ae61930b290425582e83e262e5 100644 (file)
@@ -59,22 +59,22 @@ class ProgressDummy : public ProgressInterface
 public:
        ProgressDummy() {}
 
-       void processStarted(QString const &) {}
-       void processFinished(QString const &) {}
-       void appendMessage(QString const &) {}
-       void appendError(QString const &) {}
-       void clearMessages() {}
-       void lyxerrFlush() {}
-
-       void lyxerrConnect() {}
-       void lyxerrDisconnect() {}
-
-       void warning(QString const &, QString const &) {}
-       void toggleWarning(QString const &, QString const &, QString const &) {}
-       void error(QString const &, QString const &, QString const &) {}
-       void information(QString const &, QString const &) {}
+       void processStarted(QString const &) override {}
+       void processFinished(QString const &) override {}
+       void appendMessage(QString const &) override {}
+       void appendError(QString const &) override {}
+       void clearMessages() override {}
+       void lyxerrFlush() override {}
+
+       void lyxerrConnect() override {}
+       void lyxerrDisconnect() override {}
+
+       void warning(QString const &, QString const &) override {}
+       void toggleWarning(QString const &, QString const &, QString const &) override {}
+       void error(QString const &, QString const &, QString const &) override {}
+       void information(QString const &, QString const &) override {}
        int prompt(docstring const &, docstring const &, int default_but, int,
-                  docstring const &, docstring const &) { return default_but; }
+                  docstring const &, docstring const &) override { return default_but; }
 };
 
 
@@ -169,7 +169,7 @@ string const parsecmd(string const & incmd, string & infile, string & outfile,
        bool in_single_quote = false;
        bool in_double_quote = false;
        bool escaped = false;
-       string const python_call = "python -tt";
+       string const python_call = os::python();
        vector<string> outcmd(4);
        size_t start = 0;
 
@@ -217,6 +217,21 @@ string const parsecmd(string const & incmd, string & infile, string & outfile,
                        }
                } else if (c == '<' && !(in_double_quote || escaped)) {
                        o = 3;
+#if defined (USE_MACOSX_PACKAGING)
+               } else if (o == 0 && i > 4 && c == ' ' && !(in_double_quote || escaped)) {
+                       // if a macOS app is detected with an additional argument
+                       // use open command as prefix to get it work
+                       const size_t apos = outcmd[o].rfind(".app");
+                       const size_t len = outcmd[o].length();
+                       const bool quoted = outcmd[o].at(len - 1) == '"' && outcmd[o].at(0) == '"';
+                       const string & ocmd = "open -a ";
+                       if (apos != string::npos &&
+                               (apos == (len - 4) || (apos == (len - 5) && quoted)) &&
+                               !prefixIs(trim(outcmd[o]), ocmd)) {
+                               outcmd[o] = ocmd + outcmd[o];
+                       }
+                       outcmd[o] += c;
+#endif
                } else {
                        if (escaped && in_double_quote)
                                outcmd[o] += '\\';
@@ -275,7 +290,7 @@ int Systemcall::startscript(Starttype how, string const & what,
        }
 
        if (!d.waitWhile(SystemcallPrivate::Running, do_events,
-                        os::timeout_min() * 60 * 1000)) {
+                        os::timeout_ms())) {
                if (d.state == SystemcallPrivate::Killed) {
                        LYXERR0("Killed: " << cmd);
                        return KILLED;
@@ -368,6 +383,28 @@ void SystemcallPrivate::startProcess(QString const & cmd, string const & path,
                                      string const & lpath, bool detached)
 {
        cmd_ = cmd;
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
+       // FIXME pass command and arguments separated in the first place
+       /* The versions of startDetached() and start() that accept a
+        * QStringList object exist since Qt4, but it is only in Qt 5.15
+        * that splitCommand() was introduced and the plain versions of
+        * start/startDetached() have been deprecated.
+        * The cleanest solution would be to have parsecmd() produce a
+        * QStringList for arguments, instead of transforming the string
+        * into something that the QProcess splitter accepts.
+        *
+        * Another reason for doing that is that the Qt parser ignores
+        * empty "" arguments, which are needed in some instances (see
+        * e.g. the work around for modules in Converter:convert. See
+        * QTBUG-80640 for a discussion.
+       */
+       QStringList arguments = QProcess::splitCommand(toqstr(latexEnvCmdPrefix(path, lpath)) + cmd_);
+       QString command = (arguments.empty()) ? QString() : arguments.first();
+       if (arguments.size() == 1)
+               arguments.clear();
+       else if (!arguments.empty())
+               arguments.removeFirst();
+#endif
        if (detached) {
                state = SystemcallPrivate::Running;
 #ifdef Q_OS_WIN32
@@ -379,7 +416,11 @@ void SystemcallPrivate::startProcess(QString const & cmd, string const & path,
                if (err_file_.empty())
                        process_->setStandardErrorFile(QProcess::nullDevice());
 #endif
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
+               if (!QProcess::startDetached(command, arguments)) {
+#else
                if (!QProcess::startDetached(toqstr(latexEnvCmdPrefix(path, lpath)) + cmd_)) {
+#endif
                        state = SystemcallPrivate::Error;
                        return;
                }
@@ -387,7 +428,11 @@ void SystemcallPrivate::startProcess(QString const & cmd, string const & path,
                delete released;
        } else if (process_) {
                state = SystemcallPrivate::Starting;
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
+               process_->start(command, arguments);
+#else
                process_->start(toqstr(latexEnvCmdPrefix(path, lpath)) + cmd_);
+#endif
        }
 }
 
@@ -440,7 +485,7 @@ bool SystemcallPrivate::waitWhile(State waitwhile, bool process_events, int time
                        while (!timedout) {
                                if (process_->waitForFinished(timeout))
                                        return true;
-                               bool stop = queryStopCommand(cmd_);
+                               bool const stop = queryStopCommand(cmd_);
                                // The command may have finished in the meantime
                                if (process_->state() == QProcess::NotRunning)
                                        return true;
@@ -475,7 +520,7 @@ bool SystemcallPrivate::waitWhile(State waitwhile, bool process_events, int time
                        return false;
 
                if (timer.elapsed() > timeout) {
-                       bool stop = queryStopCommand(cmd_);
+                       bool const stop = queryStopCommand(cmd_);
                        // The command may have finished in the meantime
                        if (process_->state() == QProcess::NotRunning)
                                break;