+Aux_Info const LaTeX::scanAuxFile(string const & file)
+{
+ Aux_Info result;
+ result.aux_file = file;
+ scanAuxFile(file, result);
+ return result;
+}
+
+
+void LaTeX::scanAuxFile(string const & file, Aux_Info & aux_info)
+{
+ lyxerr[Debug::LATEX] << "Scanning aux file: " << file << endl;
+
+ ifstream ifs(file.c_str());
+ string token;
+ regex reg1("\\\\citation\\{([^}]+)\\}");
+ regex reg2("\\\\bibdata\\{([^}]+)\\}");
+ regex reg3("\\\\bibstyle\\{([^}]+)\\}");
+ regex reg4("\\\\@input\\{([^}]+)\\}");
+
+ while (getline(ifs, token)) {
+ token = rtrim(token, "\r");
+#ifndef USE_INCLUDED_STRING
+ smatch sub;
+#else
+ cmatch sub;
+#endif
+ if (regex_match(STRCONV(token), sub, reg1)) {
+ string data = STRCONV(sub.str(1));
+ while (!data.empty()) {
+ string citation;
+ data = split(data, citation, ',');
+ lyxerr[Debug::LATEX] << "Citation: "
+ << citation << endl;
+ aux_info.citations.insert(citation);
+ }
+ } else if (regex_match(STRCONV(token), sub, reg2)) {
+ string data = sub.STRCONV(str(1));
+ // data is now all the bib files separated by ','
+ // get them one by one and pass them to the helper
+ while (!data.empty()) {
+ string database;
+ data = split(data, database, ',');
+ database = ChangeExtension(database, "bib");
+ lyxerr[Debug::LATEX] << "BibTeX database: `"
+ << database << '\'' << endl;
+ aux_info.databases.insert(database);
+ }
+ } else if (regex_match(STRCONV(token), sub, reg3)) {
+ string style = STRCONV(sub.str(1));
+ // token is now the style file
+ // pass it to the helper
+ style = ChangeExtension(style, "bst");
+ lyxerr[Debug::LATEX] << "BibTeX style: `"
+ << style << '\'' << endl;
+ aux_info.styles.insert(style);
+ } else if (regex_match(STRCONV(token), sub, reg4)) {
+ string const file2 = STRCONV(sub.str(1));
+ scanAuxFile(file2, aux_info);
+ }
+ }
+}
+
+
+void LaTeX::updateBibtexDependencies(DepTable & dep,
+ vector<Aux_Info> const & bibtex_info)
+{
+ // Since a run of Bibtex mandates more latex runs it is ok to
+ // remove all ".bib" and ".bst" files.
+ dep.remove_files_with_extension(".bib");
+ dep.remove_files_with_extension(".bst");
+ //string aux = OnlyFilename(ChangeExtension(file, ".aux"));
+
+ for (vector<Aux_Info>::const_iterator it = bibtex_info.begin();
+ it != bibtex_info.end(); ++it) {
+ for (set<string>::const_iterator it2 = it->databases.begin();
+ it2 != it->databases.end(); ++it2) {
+ string file = findtexfile(*it2, "bib");
+ if (!file.empty())
+ dep.insert(file, true);
+ }
+
+ for (set<string>::const_iterator it2 = it->styles.begin();
+ it2 != it->styles.end(); ++it2) {
+ string file = findtexfile(*it2, "bst");
+ if (!file.empty())
+ dep.insert(file, true);