X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fconverter.C;h=c37a0028855308fd9db5a3156a92a895167c8caf;hb=2523638092e2024bac408eee98ad2094bc4e4089;hp=0e72ca8958e9022b0292f1892a4c76d9b4bb39f0;hpb=6280787bdb6da8181afb704a9dad8921cd41ef5c;p=lyx.git diff --git a/src/converter.C b/src/converter.C index 0e72ca8958..c37a002885 100644 --- a/src/converter.C +++ b/src/converter.C @@ -14,26 +14,28 @@ #pragma implementation #endif -#include - #include "converter.h" #include "lyxrc.h" #include "buffer.h" #include "bufferview_funcs.h" #include "LaTeX.h" -#include "frontends/LyXView.h" #include "lyx_cb.h" // ShowMessage() #include "gettext.h" #include "BufferView.h" #include "debug.h" #include "frontends/Alert.h" +#include "frontends/LyXView.h" #include "support/filetools.h" #include "support/lyxfunctional.h" #include "support/path.h" #include "support/systemcall.h" +#include "BoostFormat.h" + +#include + #ifndef CXX_GLOBAL_CSTD using std::isdigit; #endif @@ -46,14 +48,12 @@ using std::find_if; using std::reverse; using std::sort; -extern string system_lyxdir; - namespace { string const token_from("$$i"); string const token_base("$$b"); string const token_to("$$o"); -string const token_lib("$$s"); +string const token_path("$$p"); ////////////////////////////////////////////////////////////////////////////// @@ -177,9 +177,15 @@ bool Formats::view(Buffer const * buffer, string const & filename, format->isChildFormat()) format = getFormat(format->parentFormat()); if (!format || format->viewer().empty()) { +#if USE_BOOST_FORMAT + Alert::alert(_("Cannot view file"), + boost::io::str(boost::format(_("No information for viewing %1$s")) + % prettyName(format_name))); +#else Alert::alert(_("Cannot view file"), - _("No information for viewing ") - + prettyName(format_name)); + _("No information for viewing ") + + prettyName(format_name)); +#endif return false; } @@ -187,17 +193,22 @@ bool Formats::view(Buffer const * buffer, string const & filename, if (format_name == "dvi" && !lyxrc.view_dvi_paper_option.empty()) { - command += " " + lyxrc.view_dvi_paper_option; + command += ' ' + lyxrc.view_dvi_paper_option; string paper_size = converters.papersize(buffer); if (paper_size == "letter") paper_size = "us"; - command += " " + paper_size; + command += ' ' + paper_size; if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE) command += 'r'; } - command += " " + QuoteName(OnlyFilename((filename))); + if (!contains(command, token_from)) + command += ' ' + token_from; + + command = subst(command, token_from, + QuoteName(OnlyFilename(filename))); + command = subst(command, token_path, QuoteName(OnlyPath(filename))); lyxerr[Debug::FILES] << "Executing command: " << command << endl; ShowMessage(buffer, _("Executing command:"), command); @@ -612,6 +623,14 @@ bool Converters::convert(Buffer const * buffer, subst(conv.result_file, token_base, OnlyFilename(from_base))); + // if input and output files are equal, we use a + // temporary file as intermediary (JMarc) + string real_outfile; + if (outfile == infile) { + real_outfile = infile; + outfile = AddName(buffer->tmppath, "tmpfile.out"); + } + if (conv.latex) { run_latex = true; string command = subst(conv.command, token_from, ""); @@ -627,15 +646,16 @@ bool Converters::convert(Buffer const * buffer, runLaTeX(buffer, latex_command_); } - string const infile2 = (conv.original_dir) + string infile2 = (conv.original_dir) ? infile : MakeRelPath(infile, path); - string const outfile2 = (conv.original_dir) + string outfile2 = (conv.original_dir) ? outfile : MakeRelPath(outfile, path); + string command = conv.command; command = subst(command, token_from, QuoteName(infile2)); command = subst(command, token_base, QuoteName(from_base)); command = subst(command, token_to, QuoteName(outfile2)); - command = subst(command, token_lib, system_lyxdir + "scripts"); + command = LibScriptSearch(command); if (!conv.parselog.empty()) command += " 2> " + QuoteName(infile2 + ".out"); @@ -661,6 +681,16 @@ bool Converters::convert(Buffer const * buffer, } else res = one.startscript(type, command); + if (!real_outfile.empty()) { + if (!lyx::rename(outfile, real_outfile)) + res = -1; + else + lyxerr[Debug::FILES] + << "renaming file " << outfile + << " to " << real_outfile + << endl; + } + if (!conv.parselog.empty()) { string const logfile = infile2 + ".log"; string const script = LibScriptSearch(conv.parselog); @@ -678,7 +708,7 @@ bool Converters::convert(Buffer const * buffer, _("You should try to fix them.")); else Alert::alert(_("Cannot convert file"), - "Error while executing", + _("Error while executing"), command.substr(0, 50)); return false; } @@ -700,8 +730,13 @@ bool Converters::convert(Buffer const * buffer, string to = subst(conv.result_dir, token_base, to_base); if (!lyx::rename(from, to)) { +#if USE_BOOST_FORMAT + Alert::alert(_("Error while trying to move directory:"), + from, boost::io::str(boost::format(_("to %1$s")) % to)); +#else Alert::alert(_("Error while trying to move directory:"), - from, ("to ") + to); + from, _("to ") + to); +#endif return false; } } @@ -710,6 +745,7 @@ bool Converters::convert(Buffer const * buffer, return move(outfile, to_file, conv.latex); } + // If from = /path/file.ext and to = /path2/file2.ext2 then this method // moves each /path/file*.ext file to /path2/file2*.ext2' bool Converters::move(string const & from, string const & to, bool copy) @@ -736,8 +772,13 @@ bool Converters::move(string const & from, string const & to, bool copy) ? lyx::copy(from2, to2) : lyx::rename(from2, to2); if (!moved && no_errors) { +#if USE_BOOST_FORMAT + Alert::alert(_("Error while trying to move file:"), + from2, boost::io::str(boost::format(_("to %1$s")) % to2)); +#else Alert::alert(_("Error while trying to move file:"), from2, _("to ") + to2); +#endif no_errors = false; } } @@ -823,8 +864,13 @@ bool Converters::scanLog(Buffer const * buffer, string const & command, } string head; split(command, head, ' '); +#if USE_BOOST_FORMAT + Alert::alert(boost::io::str(boost::format(_("There were errors during running of %1$s")) % head), + s, t); +#else Alert::alert(_("There were errors during running of ") + head, s, t); +#endif return false; } else if (result & LaTeX::NO_OUTPUT) { string const s = _("The operation resulted in"); @@ -854,7 +900,7 @@ bool Converters::runLaTeX(Buffer const * buffer, string const & command) LaTeX latex(command, name, buffer->filePath()); TeXErrors terr; int result = latex.run(terr, - bv ? bv->owner()->getLyXFunc() : 0); + bv ? &bv->owner()->getLyXFunc() : 0); if (bv) { if ((result & LaTeX::ERRORS)) {