]> git.lyx.org Git - lyx.git/blobdiff - src/Converter.cpp
revert r37459 and add a note to the sources:
[lyx.git] / src / Converter.cpp
index 14f4522968138dc78558fe97057e4061b435f400..f208b7415f90fad9b8508c343596b6ac1d2d7a1a 100644 (file)
 
 #include "Converter.h"
 
-#include "ConverterCache.h"
 #include "Buffer.h"
 #include "buffer_funcs.h"
 #include "BufferParams.h"
+#include "ConverterCache.h"
+#include "Encoding.h"
 #include "ErrorList.h"
 #include "Format.h"
 #include "Language.h"
@@ -49,7 +50,7 @@ string const token_base("$$b");
 string const token_to("$$o");
 string const token_path("$$p");
 string const token_orig_path("$$r");
-
+string const token_encoding("$$e");
 
 
 string const add_options(string const & command, string const & options)
@@ -107,9 +108,11 @@ void Converter::readFlags()
                string flag_name, flag_value;
                flag_list = split(flag_list, flag_value, ',');
                flag_value = split(flag_value, flag_name, '=');
-               if (flag_name == "latex")
+               if (flag_name == "latex") {
                        latex = true;
-               else if (flag_name == "xml")
+                       latex_flavor = flag_value.empty() ?
+                               "latex" : flag_value;
+               } else if (flag_name == "xml")
                        xml = true;
                else if (flag_name == "needaux")
                        need_aux = true;
@@ -185,11 +188,12 @@ void Converters::add(string const & from, string const & to,
        }
        converter.readFlags();
 
-       if (converter.latex && (latex_command_.empty() || to == "dvi"))
-               latex_command_ = subst(command, token_from, "");
        // If we have both latex & pdflatex, we set latex_command to latex.
        // The latex_command is used to update the .aux file when running
        // a converter that uses it.
+       if (converter.latex
+           && (latex_command_.empty() || converter.latex_flavor == "latex"))
+               latex_command_ = subst(command, token_from, "");
 
        if (it == converterlist_.end()) {
                converterlist_.push_back(converter);
@@ -254,9 +258,11 @@ OutputParams::FLAVOR Converters::getFlavor(Graph::EdgePath const & path)
             cit != path.end(); ++cit) {
                Converter const & conv = converterlist_[*cit];
                if (conv.latex)
-                       if (contains(conv.from, "xetex"))
+                       if (conv.latex_flavor == "xelatex")
                                return OutputParams::XETEX;
-                       if (contains(conv.to, "pdf"))
+                       if (conv.latex_flavor == "lualatex")
+                               return OutputParams::LUATEX;
+                       if (conv.latex_flavor == "pdflatex")
                                return OutputParams::PDFLATEX;
                if (conv.xml)
                        return OutputParams::XML;
@@ -325,7 +331,7 @@ bool Converters::convert(Buffer const * buffer,
        // used anyway.
        OutputParams runparams(buffer ? &buffer->params().encoding() : 0);
        runparams.flavor = getFlavor(edgepath);
-       
+
        if (buffer) {
                runparams.use_japanese = buffer->bufferFormat() == "platex";
                runparams.use_indices = buffer->params().use_indices;
@@ -397,17 +403,18 @@ bool Converters::convert(Buffer const * buffer,
                        }
 
                        // FIXME UNICODE
-                       string const infile2 = 
+                       string const infile2 =
                                to_utf8(makeRelPath(from_utf8(infile.absFileName()), from_utf8(path)));
-                       string const outfile2 = 
+                       string const outfile2 =
                                to_utf8(makeRelPath(from_utf8(outfile.absFileName()), from_utf8(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_path, quoteName(infile.onlyPath().absFileName()));
-                       command = subst(command, token_orig_path, quoteName(orig_from.onlyPath().absFileName()));
+                       command = subst(command, token_path, quoteName(onlyPath(infile.absFileName())));
+                       command = subst(command, token_orig_path, quoteName(onlyPath(orig_from.absFileName())));
+                       command = subst(command, token_encoding, buffer ? buffer->params().encoding().iconvName() : string());
                        command = libScriptSearch(command);
 
                        if (!conv.parselog.empty())
@@ -468,8 +475,8 @@ bool Converters::convert(Buffer const * buffer,
 // FIXME: this should go out of here. For example, here we cannot say if
 // it is a document (.lyx) or something else. Same goes for elsewhere.
                                        Alert::error(_("Cannot convert file"),
-                                               bformat(_("An error occurred whilst running %1$s"),
-                                               from_utf8(command.substr(0, 50))));
+                                               bformat(_("An error occurred while running:\n%1$s"),
+                                               wrapParas(from_utf8(command))));
                                }
                                return false;
                        }
@@ -706,8 +713,9 @@ vector<Format const *> Converters::importableFormats()
 {
        vector<string> l = loaders();
        vector<Format const *> result = getReachableTo(l[0], true);
-       for (vector<string>::const_iterator it = l.begin() + 1;
-            it != l.end(); ++it) {
+       vector<string>::const_iterator it = l.begin() + 1;
+       vector<string>::const_iterator en = l.end();
+       for (; it != en; ++it) {
                vector<Format const *> r = getReachableTo(*it, false);
                result.insert(result.end(), r.begin(), r.end());
        }
@@ -719,8 +727,9 @@ vector<Format const *> Converters::exportableFormats(bool only_viewable)
 {
        vector<string> s = savers();
        vector<Format const *> result = getReachable(s[0], only_viewable, true);
-       for (vector<string>::const_iterator it = s.begin() + 1;
-            it != s.end(); ++it) {
+       vector<string>::const_iterator it = s.begin() + 1;
+       vector<string>::const_iterator en = s.end();
+       for (; it != en; ++it) {
                vector<Format const *> r =
                        getReachable(*it, only_viewable, false);
                result.insert(result.end(), r.begin(), r.end());
@@ -745,6 +754,7 @@ vector<string> Converters::savers() const
        v.push_back("docbook");
        v.push_back("latex");
        v.push_back("literate");
+       v.push_back("luatex");
        v.push_back("lyx");
        v.push_back("xhtml");
        v.push_back("pdflatex");