Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 4dee1e71 authored by Alexander Semke's avatar Alexander Semke

In maximasession:

1. initialize the members in the initializer list
2. added MaximaSessin::write() to simplify writing to stdout on linux and win.
parent 27b6f3d6
......@@ -46,16 +46,14 @@
//the Expressions are encapsulated in () to allow capturing for the text
const QRegExp MaximaSession::MaximaOutputPrompt=QRegExp(QLatin1String("(\\(\\s*%\\s*O\\s*[0-9\\s]*\\))")); //Text, maxima outputs, before any output
static QString initCmd=QLatin1String(":lisp($load \"%1\")\n");
static QString initCmd=QLatin1String(":lisp($load \"%1\")");
MaximaSession::MaximaSession( Cantor::Backend* backend ) : Session(backend)
MaximaSession::MaximaSession( Cantor::Backend* backend ) : Session(backend),
m_initState(MaximaSession::NotInitialized),
m_process(0),
m_justRestarted(false),
m_variableModel(new MaximaVariableModel(this))
{
m_initState=MaximaSession::NotInitialized;
//m_maxima=0;
m_process=0;
m_justRestarted=false;
m_variableModel=new MaximaVariableModel(this);
}
MaximaSession::~MaximaSession()
......@@ -67,39 +65,27 @@ void MaximaSession::login()
qDebug()<<"login";
if (m_process)
m_process->deleteLater();
#ifndef Q_OS_WIN
m_process=new KPtyProcess(this);
m_process->setPtyChannels(KPtyProcess::StdinChannel|KPtyProcess::StdoutChannel);
m_process->pty()->setEcho(false);
connect(m_process->pty(), SIGNAL(readyRead()), this, SLOT(readStdOut()));
#else
m_process=new KProcess(this);
m_process->setOutputChannelMode(KProcess::SeparateChannels);
connect(m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(readStdOut()));
#endif
m_process->setProgram(MaximaSettings::self()->path().toLocalFile());
m_process->start();
connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(restartMaxima()));
#ifndef Q_OS_WIN
connect(m_process->pty(), SIGNAL(readyRead()), this, SLOT(readStdOut()));
#else
connect(m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(readStdOut()));
#endif
connect(m_process, SIGNAL(readyReadStandardError()), this, SLOT(readStdErr()));
connect(m_process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(reportProcessError(QProcess::ProcessError)));
QString initFile=QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1String("cantor/maximabackend/cantor-initmaxima.lisp"));
qDebug()<<"initFile: "<<initFile;
QString cmd=initCmd.arg(initFile);
qDebug()<<"sending cmd: "<<cmd<<endl;
#ifndef Q_OS_WIN
m_process->pty()->write(cmd.toUtf8());
#else
m_process->write(cmd.toUtf8());
#endif
const QString initFile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1String("cantor/maximabackend/cantor-initmaxima.lisp"));
write(initCmd.arg(initFile));
Cantor::Expression* expr=evaluateExpression(QLatin1String("print(____END_OF_INIT____);"),
Cantor::Expression::DeleteOnFinish);
......@@ -125,7 +111,6 @@ void MaximaSession::login()
}
runFirstExpression();
}
void MaximaSession::logout()
......@@ -139,11 +124,7 @@ void MaximaSession::logout()
if(status()==Cantor::Session::Done)
{
#ifndef Q_OS_WIN
m_process->pty()->write("quit();\n");
#else
m_process->write("quit();\n");
#endif
write(QLatin1String("quit();\n"));
#ifdef Q_OS_WIN
//Give maxima time to clean up
......@@ -175,11 +156,9 @@ void MaximaSession::logout()
Cantor::Expression* MaximaSession::evaluateExpression(const QString& cmd, Cantor::Expression::FinishingBehavior behave)
{
qDebug()<<"evaluating: "<<cmd;
MaximaExpression* expr=new MaximaExpression(this);
MaximaExpression* expr = new MaximaExpression(this);
expr->setFinishingBehavior(behave);
expr->setCommand(cmd);
expr->evaluate();
return expr;
......@@ -325,7 +304,6 @@ void MaximaSession::currentExpressionChangedStatus(Cantor::Expression::Status st
runFirstExpression();
}
}
}
void MaximaSession::runFirstExpression()
......@@ -350,16 +328,11 @@ void MaximaSession::runFirstExpression()
{
qDebug()<<"empty command";
expr->forceDone();
}else
}
else
{
qDebug()<<"writing "<<command+QLatin1Char('\n')<<" to the process";
m_cache.clear();
QString cmd=(command+QLatin1Char('\n'));
#ifndef Q_OS_WIN
m_process->pty()->write(cmd.toUtf8());
#else
m_process->write(cmd.toUtf8());
#endif
write(command + QLatin1Char('\n'));
}
}
}
......@@ -395,12 +368,7 @@ void MaximaSession::sendInputToProcess(const QString& input)
{
qDebug()<<"WARNING: use this method only if you know what you're doing. Use evaluateExpression to run commands";
qDebug()<<"running "<<input;
#ifndef Q_OS_WIN
m_process->pty()->write(input.toUtf8());
#else
m_process->write(input.toUtf8());
#endif
write(input);
}
void MaximaSession::restartMaxima()
......@@ -464,4 +432,13 @@ QAbstractItemModel* MaximaSession::variableModel()
return m_variableModel;
}
void MaximaSession::write(const QString& exp) {
qDebug()<<"sending expression to maxima process: " << exp << endl;
#ifndef Q_OS_WIN
m_process->pty()->write(exp.toUtf8());
#else
m_process->write(exp.toUtf8());
#endif
}
#include "maximasession.moc"
......@@ -76,6 +76,8 @@ class MaximaSession : public Cantor::Session
void reportProcessError(QProcess::ProcessError error);
private:
void write(const QString&);
//windows doesn't support Pty
#ifdef Q_OS_WIN
KProcess* m_process;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment