2009-05-16 15:55:08 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
|
|
|
* \file SystemcallPrivate.h
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Enrico Forestieri
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SYSTEMCALLPRIVATE_H
|
|
|
|
#define SYSTEMCALLPRIVATE_H
|
|
|
|
|
|
|
|
#include <QObject>
|
2009-12-04 09:51:13 +00:00
|
|
|
#include <QProcess>
|
2009-05-16 15:55:08 +00:00
|
|
|
|
2010-01-24 13:57:45 +00:00
|
|
|
#include <string>
|
|
|
|
|
2009-05-16 15:55:08 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace support {
|
|
|
|
|
2009-12-04 09:51:13 +00:00
|
|
|
class Systemcall;
|
|
|
|
|
2009-05-16 15:55:08 +00:00
|
|
|
/**
|
|
|
|
* Outputs to the console terminal the line buffered standard output and
|
2017-07-03 17:45:58 +00:00
|
|
|
* error of a spawned process when there is a controlling terminal and
|
2009-05-16 15:55:08 +00:00
|
|
|
* stdout/stderr have not been redirected.
|
|
|
|
*/
|
2009-12-04 09:51:13 +00:00
|
|
|
class SystemcallPrivate : public QObject
|
2009-05-16 15:55:08 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2010-07-16 06:08:12 +00:00
|
|
|
|
2009-05-16 15:55:08 +00:00
|
|
|
public:
|
2012-01-22 12:35:07 +00:00
|
|
|
SystemcallPrivate(std::string const & infile, std::string const & outfile,
|
|
|
|
std::string const & errfile);
|
2009-12-04 09:51:13 +00:00
|
|
|
~SystemcallPrivate();
|
2009-05-16 15:55:08 +00:00
|
|
|
|
2009-12-04 09:51:13 +00:00
|
|
|
enum State {
|
|
|
|
Starting,
|
|
|
|
Running,
|
|
|
|
Finished,
|
2017-12-21 23:45:52 +00:00
|
|
|
Error,
|
|
|
|
Killed
|
2009-12-04 09:51:13 +00:00
|
|
|
};
|
|
|
|
State state;
|
|
|
|
|
|
|
|
bool waitWhile(State, bool processEvents, int timeout = -1);
|
Fix bug #4812 (Layout in local directory lost on Save As, Copying)
The "save-as" part of the bug is fixed by extending the \textclass tag
such that, if a local layout file is used, its path relative to the
document directory is now stored together with the name. If a relative
path cannot be used, an absolute one is used but, in this case, the
document is not usable on a different platform.
The "copy" part is fixed by introducing a new \origin tag, which is
written when the file is saved. This tag stores the absolute path of
the document directory. If the document is manually copied to a
different location, the local layout file is retrivied by using
\origin (which is only updated on save).
This new tag may prove useful also for locating other files when the
document is manually moved to a different directory.
As in the original implementation the files needed for the layout
(for example, a latex class) had to be in the same directory as the
layout file, this directory has also to be added to TEXINPUTS.
2015-05-13 19:40:51 +00:00
|
|
|
void startProcess(QString const & cmd, std::string const & path,
|
|
|
|
std::string const & lpath, bool detach);
|
2017-07-03 17:45:58 +00:00
|
|
|
|
2009-12-04 10:11:06 +00:00
|
|
|
int exitCode();
|
|
|
|
|
2009-12-04 09:51:13 +00:00
|
|
|
QString errorMessage() const;
|
|
|
|
QString exitStatusMessage() const;
|
|
|
|
|
2009-12-04 10:35:32 +00:00
|
|
|
QProcess* releaseProcess();
|
2017-07-03 17:45:58 +00:00
|
|
|
|
2009-12-04 10:11:06 +00:00
|
|
|
static void killProcess(QProcess * p);
|
2009-12-04 09:51:13 +00:00
|
|
|
|
2018-01-01 23:23:27 +00:00
|
|
|
// when true, kill any running script ASAP
|
|
|
|
static bool kill_script;
|
|
|
|
|
2010-07-16 06:08:12 +00:00
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
void stdOut();
|
|
|
|
void stdErr();
|
|
|
|
void processError(QProcess::ProcessError);
|
|
|
|
void processStarted();
|
|
|
|
void processFinished(int, QProcess::ExitStatus status);
|
|
|
|
|
|
|
|
|
2009-05-16 15:55:08 +00:00
|
|
|
private:
|
|
|
|
/// Pointer to the process to monitor.
|
2010-07-16 06:08:12 +00:00
|
|
|
QProcess * process_;
|
|
|
|
|
2009-05-16 15:55:08 +00:00
|
|
|
/// Index to the standard output buffer.
|
2010-07-16 08:09:38 +00:00
|
|
|
size_t out_index_;
|
2009-05-16 15:55:08 +00:00
|
|
|
/// Index to the standard error buffer.
|
2010-07-16 08:09:38 +00:00
|
|
|
size_t err_index_;
|
2009-12-04 10:11:06 +00:00
|
|
|
///
|
2012-01-22 12:35:07 +00:00
|
|
|
std::string in_file_;
|
|
|
|
///
|
2010-07-16 08:09:38 +00:00
|
|
|
std::string out_file_;
|
2011-10-31 02:02:27 +00:00
|
|
|
///
|
|
|
|
std::string err_file_;
|
2010-07-16 06:08:12 +00:00
|
|
|
|
2009-05-16 15:55:08 +00:00
|
|
|
/// Size of buffers.
|
2010-07-16 14:30:46 +00:00
|
|
|
static size_t const buffer_size_ = 200;
|
2009-05-16 15:55:08 +00:00
|
|
|
/// Standard output buffer.
|
2010-07-16 14:30:46 +00:00
|
|
|
char out_data_[buffer_size_];
|
2009-05-16 15:55:08 +00:00
|
|
|
/// Standard error buffer.
|
2010-07-16 14:30:46 +00:00
|
|
|
char err_data_[buffer_size_];
|
2010-07-16 08:09:38 +00:00
|
|
|
|
|
|
|
QString cmd_;
|
|
|
|
bool process_events_;
|
2009-05-16 15:55:08 +00:00
|
|
|
|
2009-12-04 09:51:13 +00:00
|
|
|
void waitAndProcessEvents();
|
2009-12-04 11:08:24 +00:00
|
|
|
void processEvents();
|
2017-07-03 17:45:58 +00:00
|
|
|
void killProcess();
|
2009-12-20 14:26:55 +00:00
|
|
|
|
2017-12-21 23:45:52 +00:00
|
|
|
/// returns false if we killed the process
|
|
|
|
/// actually returns Systemcall::ReturnValue
|
|
|
|
bool waitAndCheck();
|
2009-05-16 15:55:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace support
|
|
|
|
} // namespace lyx
|
|
|
|
|
|
|
|
#endif // SYSTEMCALLPRIVATE_H
|