+int LaTeX::scanBlgFile(DepTable & dep, TeXErrors & terr)
+{
+ FileName const blg_file(changeExtension(file.absFileName(), "blg"));
+ LYXERR(Debug::LATEX, "Scanning blg file: " << blg_file);
+
+ ifstream ifs(blg_file.toFilesystemEncoding().c_str());
+ string token;
+ static regex const reg1(".*Found (bibtex|BibTeX) data (file|source) '([^']+).*");
+ static regex const bibtexError("^(.*---line [0-9]+ of file).*$");
+ static regex const bibtexError2("^(.*---while reading file).*$");
+ static regex const bibtexError3("(A bad cross reference---).*");
+ static regex const bibtexError4("(Sorry---you've exceeded BibTeX's).*");
+ static regex const bibtexError5("\\*Please notify the BibTeX maintainer\\*");
+ static regex const biberError("^.*> (FATAL|ERROR) - (.*)$");
+ int retval = NO_ERRORS;
+
+ string prevtoken;
+ while (getline(ifs, token)) {
+ token = rtrim(token, "\r");
+ smatch sub;
+ // FIXME UNICODE: We assume that citation keys and filenames
+ // in the aux file are in the file system encoding.
+ token = to_utf8(from_filesystem8bit(token));
+ if (regex_match(token, sub, reg1)) {
+ string data = sub.str(3);
+ if (!data.empty()) {
+ LYXERR(Debug::LATEX, "Found bib file: " << data);
+ handleFoundFile(data, dep);
+ }
+ }
+ else if (regex_match(token, sub, bibtexError)
+ || regex_match(token, sub, bibtexError2)
+ || regex_match(token, sub, bibtexError4)
+ || regex_match(token, sub, bibtexError5)) {
+ retval |= BIBTEX_ERROR;
+ string errstr = N_("BibTeX error: ") + token;
+ string message;
+ if ((prefixIs(token, "while executing---line")
+ || prefixIs(token, "---line ")
+ || prefixIs(token, "*Please notify the BibTeX"))
+ && !prevtoken.empty()) {
+ errstr = N_("BibTeX error: ") + prevtoken;
+ message = prevtoken + '\n';
+ }
+ message += token;
+ terr.insertError(0,
+ from_local8bit(errstr),
+ from_local8bit(message));
+ } else if (regex_match(prevtoken, sub, bibtexError3)) {
+ retval |= BIBTEX_ERROR;
+ string errstr = N_("BibTeX error: ") + prevtoken;
+ string message = prevtoken + '\n' + token;
+ terr.insertError(0,
+ from_local8bit(errstr),
+ from_local8bit(message));
+ } else if (regex_match(token, sub, biberError)) {
+ retval |= BIBTEX_ERROR;
+ string errstr = N_("Biber error: ") + sub.str(2);
+ string message = token;
+ terr.insertError(0,
+ from_local8bit(errstr),
+ from_local8bit(message));
+ }
+ prevtoken = token;
+ }
+ return retval;
+}
+
+