From 768d5234945d5e47912c28247b4bdbf7b961d681 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Sat, 1 Apr 2006 10:49:58 +0000 Subject: [PATCH] Fix bug 2186 (from Bo Peng): * src/insets/insetbibtex.C (InsetBibtex::latex): mangle filename of bst file for "non-nice" .tex files * src/insets/insetgraphics.C (RemoveExtension): move ... * src/support/filetools.[Ch] (removeExtension): ... here git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13540 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/insets/insetbibtex.C | 36 ++++++++++++++++++++++++++++++++++-- src/insets/insetgraphics.C | 20 ++++++-------------- src/support/filetools.C | 6 ++++++ src/support/filetools.h | 3 +++ 4 files changed, 49 insertions(+), 16 deletions(-) diff --git a/src/insets/insetbibtex.C b/src/insets/insetbibtex.C index 259f18ff69..6e33f4c823 100644 --- a/src/insets/insetbibtex.C +++ b/src/insets/insetbibtex.C @@ -50,6 +50,7 @@ using lyx::support::MakeAbsPath; using lyx::support::MakeRelPath; using lyx::support::Path; using lyx::support::prefixIs; +using lyx::support::removeExtension; using lyx::support::rtrim; using lyx::support::split; using lyx::support::subst; @@ -163,7 +164,8 @@ int InsetBibtex::latex(Buffer const & buffer, ostream & os, if (!runparams.inComment && !runparams.nice && IsFileReadable(in_file)) { - database = FileName(database).mangledFilename(); + // mangledFilename() needs the extension + database = removeExtension(FileName(in_file).mangledFilename()); string const out_file = MakeAbsPath(database + ".bib", buffer.getMasterBuffer()->temppath()); @@ -207,12 +209,42 @@ int InsetBibtex::latex(Buffer const & buffer, ostream & os, int nlines = 0; if (!style.empty()) { + string base = + normalize_name(buffer, runparams, style, ".bst"); + string const in_file = base + ".bst"; + // If this style does not come from texmf and we are not + // exporting to .tex copy it to the tmp directory. + // This prevents problems with spaces and 8bit charcaters + // in the file name. + if (!runparams.inComment && !runparams.nice && + IsFileReadable(in_file)) { + // use new style name + base = removeExtension( + FileName(in_file).mangledFilename()); + string const out_file = MakeAbsPath(base + ".bst", + buffer.getMasterBuffer()->temppath()); + bool const success = copy(in_file, out_file); + if (!success) { + lyxerr << "Failed to copy '" << in_file + << "' to '" << out_file << "'" + << endl; + } + } os << "\\bibliographystyle{" - << latex_path(normalize_name(buffer, runparams, style, ".bst")) + << latex_path(normalize_name(buffer, runparams, base, ".bst")) << "}\n"; nlines += 1; } + // Post this warning only once. + static bool warned_about_bst_spaces = false; + if (!warned_about_bst_spaces && runparams.nice && contains(style, ' ')) { + warned_about_bst_spaces = true; + Alert::warning(_("Export Warning!"), + _("There are spaces in the path to your BibTeX style file.\n" + "BibTeX will be unable to find it.")); + } + if (!db_out.empty() && buffer.params().use_bibtopic){ os << "\\begin{btSect}{" << db_out << "}\n"; string btprint = getSecOptions(); diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index 7633929c32..1d14772ccf 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -101,6 +101,7 @@ using lyx::support::GetExtension; using lyx::support::IsFileReadable; using lyx::support::latex_path; using lyx::support::OnlyFilename; +using lyx::support::removeExtension; using lyx::support::rtrim; using lyx::support::subst; using lyx::support::Systemcall; @@ -119,15 +120,6 @@ using std::ostringstream; namespace { -// This function is a utility function -// ... that should be with ChangeExtension ... -inline -string const RemoveExtension(string const & filename) -{ - return ChangeExtension(filename, string()); -} - - /// Find the most suitable image format for images in \p format /// Note that \p format may be unknown (i. e. an empty string) string findTargetFormat(string const & format, OutputParams const & runparams) @@ -510,7 +502,7 @@ copyToDirIfNeeded(string const & file_in, string const & dir, bool zipped) // extension removed, because base.eps and base.eps.gz may // have different content but would get the same mangled // name in this case. - string const base = RemoveExtension(unzippedFileName(file_in)); + string const base = removeExtension(unzippedFileName(file_in)); string::size_type const ext_len = file_in.length() - base.length(); mangled[mangled.length() - ext_len] = '.'; } @@ -534,7 +526,7 @@ string const stripExtensionIfPossible(string const & file) lyx::support::EXCLUDE_EXTENSION); if (contains(latex_name, '"')) return latex_name; - return latex_path(RemoveExtension(file), + return latex_path(removeExtension(file), lyx::support::PROTECT_EXTENSION, lyx::support::ESCAPE_DOTS); } @@ -882,7 +874,7 @@ void InsetGraphics::validate(LaTeXFeatures & features) const return; features.includeFile(graphic_label, - RemoveExtension(params().filename.absFilename())); + removeExtension(params().filename.absFilename())); features.require("graphicx"); @@ -890,9 +882,9 @@ void InsetGraphics::validate(LaTeXFeatures & features) const Buffer const * m_buffer = features.buffer().getMasterBuffer(); string basename = params().filename.outputFilename(m_buffer->filePath()); - basename = RemoveExtension(basename); + basename = removeExtension(basename); if(params().filename.isZipped()) - basename = RemoveExtension(basename); + basename = removeExtension(basename); if (contains(basename, ".")) features.require("lyxdot"); } diff --git a/src/support/filetools.C b/src/support/filetools.C index 5a0a6d4bf6..f1a31e86cb 100644 --- a/src/support/filetools.C +++ b/src/support/filetools.C @@ -744,6 +744,12 @@ string const ChangeExtension(string const & oldname, string const & extension) } +string const removeExtension(string const & name) +{ + return ChangeExtension(name, string()); +} + + /// Return the extension of the file (not including the .) string const GetExtension(string const & name) { diff --git a/src/support/filetools.h b/src/support/filetools.h index 11142403c6..7c0262cf26 100644 --- a/src/support/filetools.h +++ b/src/support/filetools.h @@ -154,6 +154,9 @@ std::string const AddPath(std::string const & path, std::string const & path2); std::string const ChangeExtension(std::string const & oldname, std::string const & extension); +/// Remove the extension from \p name +std::string const removeExtension(std::string const & name); + /// Return the extension of the file (not including the .) std::string const GetExtension(std::string const & name); -- 2.39.2