From 465e157b6028db5a2ae32676db17f9bd424d7650 Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Tue, 16 Jan 2007 18:11:43 +0000 Subject: [PATCH] Pass input data to a CAS program through a file instead of piping it to stdin * src/mathed/math_extern.C: (captureOutput): redirect stdin from a file. (pipeThroughMaxima, pipeThroughOctave, pipeThroughMathematica): use "output:" instead of "out:" in the informational messages in order to better match the "input:" message from captureOutput. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_4_X@16710 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/ChangeLog | 8 ++++++++ src/mathed/math_extern.C | 34 ++++++++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index 327547387c..2a808239ee 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,11 @@ +2007-01-16 Enrico Forestieri + + * src/mathed/math_extern.C (captureOutput): redirect stdin from a file. + (pipeThroughMaxima, pipeThroughOctave, pipeThroughMathematica): use + "output:" instead of "out:" in the informational messages in order to + better match the "input:" message from captureOutput. + + 2007-01-08 Enrico Forestieri * src/mathed/math_extern.C (pipeThroughOctave): take into account diff --git a/src/mathed/math_extern.C b/src/mathed/math_extern.C index 7ac04e960e..cde41156e5 100644 --- a/src/mathed/math_extern.C +++ b/src/mathed/math_extern.C @@ -35,15 +35,20 @@ #include "debug.h" #include "support/filetools.h" #include "support/lstrings.h" +#include "support/lyxlib.h" #include "frontends/controllers/ControlMath.h" #include #include +#include using lyx::support::cmd_ret; using lyx::support::getVectorFromString; using lyx::support::LibFileSearch; using lyx::support::RunCommand; +using lyx::support::QuoteName; +using lyx::support::tempName; +using lyx::support::unlink; using lyx::support::subst; using lyx::frontend::function_names; @@ -1014,9 +1019,22 @@ namespace { string captureOutput(string const & cmd, string const & data) { - string command = "echo '" + data + "' | " + cmd; - lyxerr << "calling: " << command << endl; + // In order to avoid parsing problems with command interpreters + // we pass input data through a file + string const cas_tmpfile = tempName(string(), "casinput"); + if (cas_tmpfile.empty()) { + lyxerr << "Warning: cannot create temporary file." + << endl; + return string(); + } + std::ofstream os(cas_tmpfile.c_str()); + os << data << endl; + os.close(); + string command = cmd + " < " + QuoteName(cas_tmpfile); + lyxerr << "calling: " << cmd + << "\ninput: '" << data << "'" << endl; cmd_ret const ret = RunCommand(command); + unlink(cas_tmpfile); return ret.second; } @@ -1106,7 +1124,7 @@ namespace { return MathArray(); out = subst(tmp[1],"\\>", ""); - lyxerr << "out: '" << out << "'" << endl; + lyxerr << "output: '" << out << "'" << endl; // Ugly code that tries to make the result prettier @@ -1122,7 +1140,7 @@ namespace { out = out.substr(0,i) + mid + out.substr(k + 1); - //lyxerr << "out: " << out << endl; + //lyxerr << "output: " << out << endl; i = out.find("\\mathchoice", i); break; } @@ -1138,7 +1156,7 @@ namespace { + out.substr(j,i - j) + out.substr(i + 5,k - i - 4) + out.substr(k + 2); - //lyxerr << "out: " << out << endl; + //lyxerr << "output: " << out << endl; i = out.find("\\over", i + 4); } MathArray res; @@ -1244,7 +1262,7 @@ namespace { // lyxerr << "checking expr: '" << expr << "'" << endl; out = captureOutput("octave -q 2>&1", expr); - lyxerr << "checking out: '" << out << "'" << endl; + lyxerr << "output: '" << out << "'" << endl; // leave loop if expression syntax is probably ok if (out.find("parse error:") == string::npos) @@ -1336,7 +1354,7 @@ namespace { + (roman ? "\\mathrm{" : "") + (translate ? fromMathematicaName(name) : name) + out.substr(roman ? j : j + 1); - //lyxerr << "out: " << out << endl; + //lyxerr << "output: " << out << endl; i = out.find(macro, i); } } @@ -1354,7 +1372,7 @@ namespace { string const full = "TeXForm[" + expr + "]"; out = captureOutput("math", full); - lyxerr << "out: '" << out << "'" << endl; + lyxerr << "output: '" << out << "'" << endl; string::size_type pos1 = out.find("Out[1]//TeXForm= "); string::size_type pos2 = out.find("In[2]:=");