33#include <unordered_map>
75 std::map< std::string,std::unique_ptr<CiteInfoImpl> >
entries;
92 QCString lowerCaseLabel = label.
lower();
93 p->entries.emplace(lowerCaseLabel.
str(),std::make_unique<CiteInfoImpl>(lowerCaseLabel));
98 auto it =
p->entries.find(label.
lower().
str());
99 if (it!=
p->entries.end())
101 return it->second.get();
114 return (numFiles==0 ||
p->entries.empty());
134 FileInfo fi(bibFile.
str());
137 err(
"bib file %s not found!\n",
qPrint(bibFile));
143 err(
"could not open file %s for reading\n",
qPrint(bibFile));
152 while (getline(f,lineStr))
155 QCString line(lineStr);
160 int j = line.
find(
'{');
162 while (j==-1 && getline(f,lineStr))
170 if (!f.eof() && j!=-1)
172 int k = line.
find(
',',j);
176 while (!f.eof() && citeName.
isEmpty())
180 citeName = line.
mid(
static_cast<size_t>(j),
static_cast<size_t>(k-j));
184 citeName = line.
mid(
static_cast<size_t>(j));
188 if (citeName.
isEmpty() && getline(f,lineStr))
199 std::string lCiteName = citeName.
lower().
str();
200 auto it =
p->citePosition.find(lCiteName);
201 if (it !=
p->citePosition.end())
203 warn(bibFile,
lineCount,
"multiple use of citation name '%s', (first occurrence: %s, line %d)",
204 qPrint(lCiteName),
qPrint(it->second.fileName),it->second.lineNr);
208 p->citePosition.emplace(lCiteName,CitePosition(bibFile,
lineCount));
212 else if ((i=line.
find(
"crossref"))!=-1 && !citeName.
isEmpty())
214 int j = line.
find(
'{',i);
215 int k = line.
find(
'}',i);
218 QCString crossrefName = line.
mid(
static_cast<size_t>(j+1),
static_cast<uint32_t
>(k-j-1));
221 if (
find(citeName) && !
find(crossrefName))
237 bool insideFormula =
false;
238 int citeFormulaCnt = 1;
239 const size_t tmpLen = 30;
241 const char *ps=s.
data();
259 insideFormula =
false;
265 p->formulaCite.emplace(citeFormulaCnt,std::string(
"\\f$") + formulaBuf.
get() +
"\\f$");
271 insideFormula =
false;
289 insideFormula =
true;
304 return growBuf.
get();
315 t += s.
mid(pos,i-pos);
317 int markerId = atoi(s.
mid(i+markerSize,6).
data());
318 auto it =
p->formulaCite.find(markerId);
319 if (it !=
p->formulaCite.end()) t += it->second;
320 pos = i + markerSize+6;
338 for (
const auto &bibdata : citeDataList)
340 QCString bibFile =
getBibFile(QCString(bibdata));
346 QCString citeListFile = outputDir+
"/citelist.doc";
351 err(
"could not open file %s for writing\n",
qPrint(citeListFile));
353 t <<
"<!-- BEGIN CITATIONS -->\n";
355 for (
const auto &it :
p->entries)
357 t <<
"\\citation{" << it.second->label() <<
"}\n";
360 t <<
"<!-- END CITATIONS -->\n";
361 t <<
"<!-- BEGIN BIBLIOGRAPHY -->\n";
362 t <<
"<!-- END BIBLIOGRAPHY -->\n";
367 QCString bib2xhtmlFile = outputDir+
"/bib2xhtml.pl";
371 QCString doxygenBstFile = outputDir+
"/doxygen.bst";
378 QCString bibOutputDir = outputDir+
"/"+
bibTmpDir;
379 QCString bibOutputFiles =
"";
383 err(
"Failed to create temporary output directory '%s', skipping citations\n",
qPrint(bibOutputDir));
387 for (
const auto &bibdata : citeDataList)
389 QCString bibFile =
getBibFile(QCString(bibdata));
390 FileInfo fi(bibFile.
str());
397 if (!f_org.is_open())
399 err(
"could not open file %s for reading\n",
qPrint(bibFile));
402 if (!f_out.is_open())
404 err(
"could not open file %s for reading\n",
qPrint(bibOutputDir +
bibTmpFile + QCString().setNum(i) +
".bib"));
408 while (getline(f_org,lineStr))
410 docs += lineStr +
"\n";
414 if (f_org.is_open()) f_org.close();
415 if (f_out.is_open()) f_out.close();
426 QCString perlArgs =
"\""+bib2xhtmlFile+
"\" "+bibOutputFiles+
" \""+ citeListFile+
"\"";
427 if (citeDebug) perlArgs+=
" -d";
431 err(
"Problems running bibtex. Verify that the command 'perl --version' works from the command line. Exit code: %d\n",
443 err(
"could not open file %s for reading\n",
qPrint(citeListFile));
446 bool insideBib=
FALSE;
449 while (getline(f,lineStr))
451 QCString line(lineStr);
454 if (line.
find(
"<!-- BEGIN BIBLIOGRAPHY")!=-1) insideBib=
TRUE;
455 else if (line.
find(
"<!-- END BIBLIOGRAPH")!=-1) insideBib=
FALSE;
457 if (insideBib && ((i=line.
find(
"name=\"CITEREF_"))!=-1 || (i=line.
find(
"name=\"#CITEREF_"))!=-1))
459 int j=line.
find(
"\">[");
460 int k=line.
find(
"]</a>");
463 size_t ui=
static_cast<size_t>(i);
464 size_t uj=
static_cast<size_t>(j);
465 size_t uk=
static_cast<size_t>(k);
466 QCString label = line.
mid(ui+14,uj-ui-14);
467 QCString number = line.
mid(uj+2,uk-uj-1);
469 auto it =
p->entries.find(label.
lower().
str());
471 if (it!=
p->entries.end())
473 it->second->setText(number);
477 if (insideBib) doc+=line+
"\n";
486 bool needsEntry =
false;
487 CommentScanner commentScanner;
520 for (
const auto &bibdata : citeDataList)
522 QCString bibFile =
getBibFile(QCString(bibdata));
523 FileInfo fi(bibFile.
str());
536 err(
"bib file %s not found!\n",
qPrint(bibFile));
550 for (
size_t j = 1; j <= citeDataList.size(); j++)
552 QCString bibFile = bibOutputDir +
bibTmpFile + QCString().
setNum(
static_cast<int>(j)) +
".bib";
564 for (
const auto &bibdata : citeDataList)
566 QCString bibFile =
getBibFile(QCString(bibdata));
567 FileInfo fi(bibFile.
str());
572 if (i) result +=
",";
575 result += QCString().
setNum(i);
static QCString getBibFile(const QCString &inFile)
const std::string g_formulaMarker
void insertCrossReferencesForBibFile(const QCString &bibFile)
QCString anchorPrefix() const
std::unique_ptr< Private > p
const CiteInfo * find(const QCString &label) const
Return the citation info for a given label.
QCString latexBibFiles()
lists the bibtex cite files in a comma separated list
static CitationManager & instance()
void clear()
clears the database
QCString replaceFormulas(const QCString &s)
void insert(const QCString &label)
Insert a citation identified by label into the database.
CitationManager()
Create the database, with an expected maximum of size entries.
QCString fileName() const
bool isEmpty() const
return TRUE if there are no citations.
void generatePage()
Generate the citations page.
QCString getFormulas(const QCString &s)
void setText(const QCString &s)
QCString label() const override
QCString text() const override
CiteInfoImpl(const QCString &label, const QCString &text=QCString())
CitePosition(const QCString &fn, int l)
static bool isFlagSet(const DebugMask mask)
static std::string currentDirPath()
bool mkdir(const std::string &path, bool acceptsAbsPath=true) const
bool remove(const std::string &path, bool acceptsAbsPath=true) const
bool rmdir(const std::string &path, bool acceptsAbsPath=true) const
static bool setCurrent(const std::string &path)
QCString doc
documentation block (partly parsed)
void addStr(const QCString &s)
This is an alternative implementation of QCString.
int find(char c, int index=0, bool cs=TRUE) const
size_t length() const
Returns the length of the string, not counting the 0-terminator.
bool startsWith(const char *s) const
QCString mid(size_t index, size_t len=static_cast< size_t >(-1)) const
bool endsWith(const char *s) const
bool isEmpty() const
Returns TRUE iff the string is empty.
QCString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
const std::string & str() const
QCString & setNum(short n)
QCString right(size_t len) const
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
QCString left(size_t len) const
static ResourceMgr & instance()
Returns the one and only instance of this class.
bool copyResource(const QCString &name, const QCString &targetDir) const
Copies a registered resource to a given target directory.
virtual QCString trCiteReferences()=0
#define Config_getList(name)
#define Config_getBool(name)
#define Config_getString(name)
std::vector< std::string > StringVector
#define lineCount(s, len)
static void addRelatedPage(Entry *root)
Translator * theTranslator
#define warn(file, line, fmt,...)
std::ifstream openInputStream(const QCString &name, bool binary=false, bool openAtEnd=false)
std::ofstream openOutputStream(const QCString &name, bool append=false)
int system(const QCString &command, const QCString &args, bool commandHasConsole=true)
Portable versions of functions that are platform dependent.
const char * qPrint(const char *s)
std::map< std::string, std::unique_ptr< CiteInfoImpl > > entries
std::unordered_map< std::string, CitePosition > citePosition
std::unordered_map< int, std::string > formulaCite
Protection
Protection level of members.
bool copyFile(const QCString &src, const QCString &dest)
Copies the contents of file with name src to the newly created file with name dest.
A bunch of utility functions.