]> git.lyx.org Git - lyx.git/blobdiff - src/insets/ExternalSupport.C
* In the process of fixing the math background color bug, this commit transfer backgr...
[lyx.git] / src / insets / ExternalSupport.C
index 3b7d722ed4e2ab072334bd1a15ab17fffb866683..1f7669b7045a1fed3984387c3598f52962a519d3 100644 (file)
@@ -106,12 +106,16 @@ string const doSubstitution(InsetExternalParams const & params,
                string const masterpath = external_in_tmpdir ?
                        m_buffer->temppath() :
                        m_buffer->filePath();
+               // FIXME UNICODE
                string relToMasterPath = support::onlyPath(
-                               support::makeRelPath(absname, masterpath));
+                               to_utf8(support::makeRelPath(from_utf8(absname),
+                                                            from_utf8(masterpath))));
                if (relToMasterPath == "./")
                        relToMasterPath.clear();
+               // FIXME UNICODE
                string relToParentPath = support::onlyPath(
-                               support::makeRelPath(absname, parentpath));
+                               to_utf8(support::makeRelPath(from_utf8(absname),
+                                                            from_utf8(parentpath))));
                if (relToParentPath == "./")
                        relToParentPath.clear();
 
@@ -163,14 +167,19 @@ string const doSubstitution(InsetExternalParams const & params,
                        '.' + support::getExtension(filename), use_latex_path);
        result = subst_path(result, "$$Tempname", params.tempname().absFilename(), use_latex_path);
        result = subst_path(result, "$$Sysdir",
-                               support::package().system_support(), use_latex_path);
+                               support::package().system_support().absFilename(), use_latex_path);
 
        // Handle the $$Contents(filename) syntax
        if (support::contains(result, "$$Contents(\"")) {
-
-               string::size_type const pos = result.find("$$Contents(\"");
-               string::size_type const end = result.find("\")", pos);
-               string const file = result.substr(pos + 12, end - (pos + 12));
+               // Since use_latex_path may be true we must extract the file
+               // name from s instead of result and do the substitutions
+               // again, this time with use_latex_path false.
+               string::size_type const spos = s.find("$$Contents(\"");
+               string::size_type const send = s.find("\")", spos);
+               string const file_template = s.substr(spos + 12, send - (spos + 12));
+               string const file = doSubstitution(params, buffer,
+                                                  file_template, false,
+                                                  external_in_tmpdir, what);
                string contents;
 
                FileName const absfile(
@@ -178,9 +187,9 @@ string const doSubstitution(InsetExternalParams const & params,
                if (support::isFileReadable(absfile))
                        contents = support::getFileContents(absfile);
 
-               result = support::subst(result,
-                                       ("$$Contents(\"" + file + "\")").c_str(),
-                                       contents);
+               string::size_type const pos = result.find("$$Contents(\"");
+               string::size_type const end = result.find("\")", pos);
+               result.replace(pos, end + 2, contents);
        }
 
        return result;
@@ -235,14 +244,6 @@ void updateExternal(InsetExternalParams const & params,
        if (to_format.empty())
                return; // NOT_NEEDED
 
-       if (!theConverters().isReachable(from_format, to_format)) {
-               lyxerr[Debug::EXTERNAL]
-                       << "external::updateExternal. "
-                       << "Unable to convert from "
-                       << from_format << " to " << to_format << endl;
-               return; // FAILURE
-       }
-
        // The master buffer. This is useful when there are multiple levels
        // of include files
        Buffer const * m_buffer = buffer.getMasterBuffer();
@@ -259,7 +260,7 @@ void updateExternal(InsetExternalParams const & params,
                if (from_checksum != temp_checksum) {
                        Mover const & mover = getMover(from_format);
                        if (!mover.copy(params.filename, temp_file)) {
-                               lyxerr[Debug::EXTERNAL]
+                               LYXERR(Debug::EXTERNAL)
                                        << "external::updateExternal. "
                                        << "Unable to copy "
                                        << params.filename << " to " << temp_file << endl;
@@ -314,10 +315,17 @@ void updateExternal(InsetExternalParams const & params,
 
        // FIXME (Abdel 12/08/06): Is there a need to show these errors?
        ErrorList el;
-       /* bool const success = */
+       bool const success =
                theConverters().convert(&buffer, temp_file, abs_to_file,
                                   params.filename, from_format, to_format, el,
                                   Converters::try_default | Converters::try_cache);
+
+       if (!success)
+               LYXERR(Debug::EXTERNAL)
+                       << "external::updateExternal. "
+                       << "Unable to convert from "
+                       << from_format << " to " << to_format << endl;
+
        // return success
 }
 
@@ -345,7 +353,7 @@ int writeExternal(InsetExternalParams const & params,
 
        Template::Formats::const_iterator cit = et.formats.find(format);
        if (cit == et.formats.end()) {
-               lyxerr[Debug::EXTERNAL]
+               LYXERR(Debug::EXTERNAL)
                        << "External template format '" << format
                        << "' not specified in template "
                        << params.templatename() << endl;