- // the database string
- string adb;
- string db_in = getContents();
- db_in = split(db_in, adb, ',');
- // If we generate in a temp dir, we might need to give an
- // absolute path there. This is a bit complicated since we can
- // have a comma-separated list of bibliographies
- string db_out;
- while (!adb.empty()) {
- db_out += latex_path(normalize_name(buffer, runparams, adb, ".bib"));
- db_out += ',';
- db_in = split(db_in, adb,',');
+ // Database(s)
+ // 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.
+ typedef boost::char_separator<char_type> Separator;
+ typedef boost::tokenizer<Separator, docstring::const_iterator, docstring> Tokenizer;
+
+ Separator const separator(from_ascii(",").c_str());
+ // The tokenizer must not be called with temporary strings, since
+ // it does not make a copy and uses iterators of the string further
+ // down. getParam returns a reference, so this is OK.
+ Tokenizer const tokens(getParam("bibfiles"), separator);
+ Tokenizer::const_iterator const begin = tokens.begin();
+ Tokenizer::const_iterator const end = tokens.end();
+
+ odocstringstream dbs;
+ for (Tokenizer::const_iterator it = begin; it != end; ++it) {
+ docstring const input = trim(*it);
+ // FIXME UNICODE
+ string utf8input(to_utf8(input));
+ string database =
+ normalize_name(buffer, runparams, utf8input, ".bib");
+ FileName const try_in_file(makeAbsPath(database + ".bib", buffer.filePath()));
+ bool const not_from_texmf = isFileReadable(try_in_file);
+
+ 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",
+ buffer.getMasterBuffer()->temppath()));
+
+ bool const success = copy(in_file, out_file);
+ if (!success) {
+ lyxerr << "Failed to copy '" << in_file
+ << "' to '" << out_file << "'"
+ << endl;
+ }
+ }
+
+ if (it != begin)
+ dbs << ',';
+ // FIXME UNICODE
+ dbs << from_utf8(latex_path(database));
+ }
+ docstring const db_out = dbs.str();
+
+ // Post this warning only once.
+ static bool warned_about_spaces = false;
+ if (!warned_about_spaces &&
+ runparams.nice && db_out.find(' ') != docstring::npos) {
+ 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."));
+