Am Donnerstag, 30. März 2006 21:29 schrieb Bo Peng: > Then, this is not my fault. :-)
I did not say that it was yours. > I definitely agree, but a speedier review would be welcome. No problem if you can extend each day by some extra hours ;-) > The patch works, but I do not like the one line function > remove_extension. If it is used only here, I prefer to put it with the > code. If it will be used elsewhere, it should go to support/filetools > (or similar.) That is the intention. We have a similar function in insetgraphics. Now you made me spend more time on this than I wanted, and I am putting this in tomorrow. Georg Log: 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
Index: src/insets/insetbibtex.C =================================================================== --- src/insets/insetbibtex.C (Revision 13535) +++ src/insets/insetbibtex.C (Arbeitskopie) @@ -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 & bu 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 & bu 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(); Index: src/insets/insetgraphics.C =================================================================== --- src/insets/insetgraphics.C (Revision 13535) +++ src/insets/insetgraphics.C (Arbeitskopie) @@ -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 // 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(st 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(LaTeXFeatur return; features.includeFile(graphic_label, - RemoveExtension(params().filename.absFilename())); + removeExtension(params().filename.absFilename())); features.require("graphicx"); @@ -890,9 +882,9 @@ void InsetGraphics::validate(LaTeXFeatur 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"); } Index: src/support/filetools.C =================================================================== --- src/support/filetools.C (Revision 13535) +++ src/support/filetools.C (Arbeitskopie) @@ -744,6 +744,12 @@ string const ChangeExtension(string cons } +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) { Index: src/support/filetools.h =================================================================== --- src/support/filetools.h (Revision 13535) +++ src/support/filetools.h (Arbeitskopie) @@ -154,6 +154,9 @@ std::string const AddPath(std::string co 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);