+bool LaTeX::runBibTeX(string const & f, DepTable & dep)
+{
+ // Since a run of Bibtex mandates more latex runs it is ok to
+ // remove all ".bib" and ".bst" files, it is also required to
+ // discover style and database changes.
+ dep.remove_files_with_extension(".bib");
+ dep.remove_files_with_extension(".bst");
+ ifstream ifs(f.c_str());
+ string token;
+ bool using_bibtex = false;
+ LRegex reg1("\\\\bibdata\\{([^}]+)\\}");
+ LRegex reg2("\\\\bibstyle\\{([^}]+)\\}");
+ while (getline(ifs, token)) {
+ if (reg1.exact_match(token)) {
+ using_bibtex = true;
+ LRegex::SubMatches const & sub = reg1.exec(token);
+ string data = LSubstring(token, sub[1].first,
+ sub[1].second);
+ // data is now all the bib files separated by ','
+ // get them one by one and pass them to the helper
+ string::size_type b;
+ do {
+ b = data.find_first_of(',', 0);
+ string l;
+ if (b == string::npos)
+ l = data;
+ else {
+ l = data.substr(0, b - 0);
+ data.erase(0, b + 1);
+ }
+ string full_l =
+ findtexfile(
+ ChangeExtension(l, "bib"),
+ "bib");
+ lyxerr[Debug::LATEX] << "Bibtex database: `"
+ << full_l << "'" << endl;
+ if (!full_l.empty()) {
+ // add full_l to the dep file.
+ dep.insert(full_l, true);
+ }
+ } while (b != string::npos);
+ } else if (reg2.exact_match(token)) {
+ using_bibtex = true;
+ LRegex::SubMatches const & sub = reg2.exec(token);
+ string style = LSubstring(token, sub[1].first,
+ sub[1].second);
+ // token is now the style file
+ // pass it to the helper
+ string full_l =
+ findtexfile(
+ ChangeExtension(style, "bst"),
+ "bst");
+ lyxerr[Debug::LATEX] << "Bibtex style: `"
+ << full_l << "'" << endl;
+ if (!full_l.empty()) {
+ // add full_l to the dep file.
+ dep.insert(full_l, true);
+ }