lyx_mirror/src/support/SystemcallPrivate.h

103 lines
2.0 KiB
C
Raw Normal View History

// -*- 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>
#include <QProcess>
#include <string>
namespace lyx {
namespace support {
class Systemcall;
/**
* Outputs to the console terminal the line buffered standard output and
* error of a spawned process when there is a controlling terminal and
* stdout/stderr have not been redirected.
*/
class SystemcallPrivate : public QObject
{
Q_OBJECT
public:
SystemcallPrivate(std::string const & infile, std::string const & outfile,
std::string const & errfile);
~SystemcallPrivate();
enum State {
Starting,
Running,
Finished,
Error
};
State state;
bool waitWhile(State, bool processEvents, int timeout = -1);
Introduce the possibility of setting a prefix for the TEXINPUTS environment variable. This is done in the preferences, much like as the PATH prefix. A single '.' in the paths will get replaced with the current document dir and also non-absolute paths will be prefixed with that dir. The default semantics of TEXINPUTS apply, such that, for example, if a path is terminated with a double slash, all subdirectories will be also searched by both the TeX engine and ancillary programs such as dvi previewers or dvips. As an example, if the prefix is set to ".:figs", the TEXINPUTS variable will be set as ".:<docdir>:<docdir>/figs:$ORIGTEXINPUTS", where <docdir> is the document directory. The initial '.' is necessary to address the actual current dir (this will be the temp dir at preview time), while if TEXINPUTS was initially unset, such that $ORIGTEXINPUTS is empty, a colon (or semicolon on Windows) will end the path list. This is very important, because we don't want to replace the system directories but to complement them and, in order to do that, an empty element has to be present in the list. Indeed, according to the TEXINPUTS semantics, an empty element means the standard search path. This works whether TEXINPUTS is originally set or not, because if the original TEXINPUTS starts with a colon (meaning that the standard search path is wanted there) we will have an empty element at that point, otherwise the final colon will simply serve as a path separator. Of course, on Windows a ';' has to be used as a path separator. LyX will take care of transforming the platform path list into one understandable by the TeX engine. For example, this will be the case for a Cygwin version of LyX using a native Windows TeX engine or viceversa. I tested all of this and it works for me. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@38681 a592a061-630c-0410-9148-cb99ea01b6c8
2011-05-09 23:25:51 +00:00
void startProcess(QString const & cmd, std::string const & path);
int exitCode();
QString errorMessage() const;
QString exitStatusMessage() const;
QProcess* releaseProcess();
static void killProcess(QProcess * p);
public Q_SLOTS:
void stdOut();
void stdErr();
void processError(QProcess::ProcessError);
void processStarted();
void processFinished(int, QProcess::ExitStatus status);
private:
/// Pointer to the process to monitor.
QProcess * process_;
/// Index to the standard output buffer.
size_t out_index_;
/// Index to the standard error buffer.
size_t err_index_;
///
std::string in_file_;
///
std::string out_file_;
///
std::string err_file_;
/// Size of buffers.
static size_t const buffer_size_ = 200;
/// Standard output buffer.
char out_data_[buffer_size_];
/// Standard error buffer.
char err_data_[buffer_size_];
QString cmd_;
bool process_events_;
void waitAndProcessEvents();
void processEvents();
void killProcess();
};
} // namespace support
} // namespace lyx
#endif // SYSTEMCALLPRIVATE_H