+vector<docstring> const Buffer::prepareBibFilePaths(OutputParams const & runparams,
+ FileNamePairList const bibfilelist,
+ bool const add_extension) const
+{
+ // If we are processing the LaTeX file in a temp directory then
+ // copy the .bib databases to this temp directory, mangling their
+ // names in the process. Store this mangled name in the list of
+ // all databases.
+ // (We need to do all this because BibTeX *really*, *really*
+ // can't handle "files with spaces" and Windows users tend to
+ // use such filenames.)
+ // Otherwise, store the (maybe absolute) path to the original,
+ // unmangled database name.
+
+ vector<docstring> res;
+
+ // determine the export format
+ string const tex_format = flavor2format(runparams.flavor);
+
+ // check for spaces in paths
+ bool found_space = false;
+
+ FileNamePairList::const_iterator it = bibfilelist.begin();
+ FileNamePairList::const_iterator en = bibfilelist.end();
+ for (; it != en; ++it) {
+ string utf8input = to_utf8(it->first);
+ string database =
+ prepareFileNameForLaTeX(utf8input, ".bib", runparams.nice);
+ FileName const try_in_file =
+ makeAbsPath(database + ".bib", filePath());
+ bool const not_from_texmf = try_in_file.isReadableFile();
+
+ if (!runparams.inComment && !runparams.dryrun && !runparams.nice &&
+ not_from_texmf) {
+ // mangledFileName() needs the extension
+ DocFileName const in_file = DocFileName(try_in_file);
+ database = removeExtension(in_file.mangledFileName());
+ FileName const out_file = makeAbsPath(database + ".bib",
+ masterBuffer()->temppath());
+ bool const success = in_file.copyTo(out_file);
+ if (!success) {
+ LYXERR0("Failed to copy '" << in_file
+ << "' to '" << out_file << "'");
+ }
+ } else if (!runparams.inComment && runparams.nice && not_from_texmf) {
+ runparams.exportdata->addExternalFile(tex_format, try_in_file, database + ".bib");
+ if (!isValidLaTeXFileName(database)) {
+ frontend::Alert::warning(_("Invalid filename"),
+ _("The following filename will cause troubles "
+ "when running the exported file through LaTeX: ") +
+ from_utf8(database));
+ }
+ if (!isValidDVIFileName(database)) {
+ frontend::Alert::warning(_("Problematic filename for DVI"),
+ _("The following filename can cause troubles "
+ "when running the exported file through LaTeX "
+ "and opening the resulting DVI: ") +
+ from_utf8(database), true);
+ }
+ }
+
+ if (add_extension)
+ database += ".bib";
+
+ // FIXME UNICODE
+ docstring const path = from_utf8(latex_path(database));
+
+ if (contains(path, ' '))
+ found_space = true;
+
+ if (find(res.begin(), res.end(), path) == res.end())
+ res.push_back(path);
+ }
+
+ // Check if there are spaces in the path and warn BibTeX users, if so.
+ // (biber can cope with such paths)
+ if (!prefixIs(runparams.bibtex_command, "biber")) {
+ // Post this warning only once.
+ static bool warned_about_spaces = false;
+ if (!warned_about_spaces &&
+ runparams.nice && found_space) {
+ warned_about_spaces = true;
+ Alert::warning(_("Export Warning!"),
+ _("There are spaces in the paths to your BibTeX databases.\n"
+ "BibTeX will be unable to find them."));
+ }
+ }
+
+ return res;