34#include <unordered_map>
82 std::map< std::string,std::unique_ptr<CiteInfoImpl> >
entries;
100 p->entries.emplace(lowerCaseLabel.
str(),std::make_unique<CiteInfoImpl>(lowerCaseLabel));
105 if (
auto it =
p->entries.find(label.
lower().
str()); it !=
p->entries.end())
107 return it->second.get();
120 return (numFiles==0 ||
p->entries.empty());
143 err(
"bib file {} not found!\n",bibFile);
149 err(
"could not open file {} for reading\n",bibFile);
158 while (getline(f,lineStr))
166 size_t j = line.
find(
'{');
178 size_t k = line.
find(
',',j);
182 while (!f.eof() && citeName.
empty())
186 citeName = line.
mid(j,k-j);
190 citeName = line.
mid(j);
194 if (citeName.
empty() && getline(f,lineStr))
203 if (!citeName.
empty())
205 std::string lCiteName = citeName.
lower().
str();
206 auto it =
p->citePosition.find(lCiteName);
207 if (it !=
p->citePosition.end())
209 warn(bibFile,
lineCount,
"multiple use of citation name '{}', (first occurrence: {}, line {})",
210 lCiteName,it->second.fileName,it->second.lineNr);
220 size_t j = line.
find(
'{',i);
221 size_t k = line.
find(
'}',i);
227 if (
find(citeName) && !
find(crossrefName))
240 if (s.
empty())
return s;
245 bool insideFormula =
false;
246 int citeFormulaCnt = 1;
247 const char *ps=s.
data();
264 insideFormula =
false;
269 const size_t idLen = 30;
272 p->formulaCite.emplace(citeFormulaCnt,std::string(
"\\f$") + formula.
str() +
"\\f$");
278 insideFormula =
false;
297 insideFormula =
true;
315 if (s.
empty())
return s;
321 t += s.
mid(pos,i-pos);
323 int markerId = atoi(s.
mid(i+markerSize,6).
data());
324 auto it =
p->formulaCite.find(markerId);
325 if (it !=
p->formulaCite.end()) t += it->second;
326 pos = i + markerSize+6;
344 for (
const auto &bibdata : citeDataList)
352 DString citeListFile = outputDir+
"/citelist.doc";
357 err(
"could not open file {} for writing\n",citeListFile);
359 t <<
"<!-- BEGIN CITATIONS -->\n";
361 for (
const auto &it :
p->entries)
363 t <<
"\\citation{" << it.second->label() <<
"}\n";
366 t <<
"<!-- END CITATIONS -->\n";
367 t <<
"<!-- BEGIN BIBLIOGRAPHY -->\n";
368 t <<
"<!-- END BIBLIOGRAPHY -->\n";
373 DString bib2xhtmlFile = outputDir+
"/bib2xhtml.pl";
377 DString doxygenBstFile = outputDir+
"/doxygen.bst";
389 err(
"Failed to create temporary output directory '{}', skipping citations\n",bibOutputDir);
393 for (
const auto &bibdata : citeDataList)
399 if (!bibFile.
empty())
403 if (!f_org.is_open())
405 err(
"could not open file {} for reading\n",bibFile);
408 if (!f_out.is_open())
410 err(
"could not open file {}{}{:d}{} for reading\n",bibOutputDir,
bibTmpFile,i,
".bib");
414 while (getline(f_org,lineStr))
416 docs += lineStr +
"\n";
420 if (f_org.is_open()) f_org.close();
421 if (f_out.is_open()) f_out.close();
432 DString perlArgs =
"\""+bib2xhtmlFile+
"\" "+bibOutputFiles+
" \""+ citeListFile+
"\"";
433 if (citeDebug) perlArgs+=
" -d";
437 err(
"Problems running bibtex. Verify that the command 'perl --version' works from the command line. Exit code: {}\n",
449 err(
"could not open file {} for reading\n",citeListFile);
452 bool insideBib=
false;
455 while (getline(f,lineStr))
465 size_t j=line.
find(
"\">[");
466 size_t j1=line.
find(
"<!--[");
467 size_t k=line.
find(
"]<!--");
468 size_t k1=line.
find(
"]-->");
474 DString shortAuthor = optList[1];
476 if (optList.size() == 3)
480 line = line.
left(i+14) + label + line.
mid(j);
481 auto it =
p->entries.find(label.
lower().
str());
483 if (it!=
p->entries.end())
485 it->second->setText(number);
486 it->second->setShortAuthor(shortAuthor);
491 if (insideBib) doc+=line+
"\n";
500 bool needsEntry =
false;
534 for (
const auto &bibdata : citeDataList)
540 if (!bibFile.
empty())
550 err(
"bib file {} not found!\n",bibFile);
564 for (
size_t j = 1; j <= citeDataList.size(); j++)
578 for (
const auto &bibdata : citeDataList)
584 if (i) result +=
",";
static const std::string g_formulaMarker
static DString getBibFile(const DString &inFile)
std::unique_ptr< Private > p
void insert(const DString &label)
Insert a citation identified by label into the database.
const CiteInfo * find(const DString &label) const
Return the citation info for a given label.
static CitationManager & instance()
void clear()
clears the database
bool empty() const
return true if there are no citations.
DString anchorPrefix() const
DString latexBibFiles()
lists the bibtex cite files in a comma separated list
void insertCrossReferencesForBibFile(const DString &bibFile)
DString replaceFormulas(const DString &s)
CitationManager()
Create the database, with an expected maximum of size entries.
DString getFormulas(const DString &s)
void generatePage()
Generate the citations page.
DString label() const override
DString year() const override
DString shortAuthor() const override
DString text() const override
void setYear(const DString &s)
void setText(const DString &s)
void setShortAuthor(const DString &s)
CiteInfoImpl(const DString &label, const DString &text=DString())
CitePosition(const DString &fn, int l)
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
DString & setNum(short n)
DString mid(size_t index, size_t len=npos) const
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
static constexpr size_t npos
value used to indicate 'not found' or 'to the end of the string', matching std::string::npos
size_t find(char c, size_t pos=0) const
void reserve(size_t size)
Reserve space for size bytes without changing the string contents.
DString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
DString left(size_t len) const
const std::string & str() const
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
bool startsWith(const char *s) const
bool endsWith(const char *s) const
size_t length() const
Returns the length of the string, not counting the 0-terminator.
static bool isFlagSet(const DebugMask mask)
Class representing a directory in the file system.
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)
Represents an unstructured piece of information, about an entity found in the sources.
DString doc
documentation block (partly parsed)
Minimal replacement for QFileInfo.
static ResourceMgr & instance()
Returns the one and only instance of this class.
bool copyResource(const DString &name, const DString &targetDir) const
Copies a registered resource to a given target directory.
virtual DString trCiteReferences()=0
#define Config_getList(name)
#define Config_getBool(name)
#define Config_getString(name)
std::vector< std::string > StringVector
#define lineCount(s, len)
Translator * theTranslator
#define warn(file, line, fmt,...)
std::ifstream openInputStream(const DString &name, bool binary=false, bool openAtEnd=false)
int system(const DString &command, const DString &args, bool commandHasConsole=true)
std::ofstream openOutputStream(const DString &name, bool append=false)
PageDef * addRelatedPage(const DString &name, const DString &ptitle, const DString &doc, const DString &fileName, int docLine, int startLine, const RefItemVector &sli, GroupDef *gd, const TagInfo *tagInfo, bool xref, SrcLangExt lang)
Portable versions of functions that are platform dependent.
Some helper functions for std::string.
StringVector split(const std::string &s, const std::string &delimiter)
split input string s by string delimiter delimiter.
std::map< std::string, std::unique_ptr< CiteInfoImpl > > entries
std::unordered_map< std::string, CitePosition > citePosition
std::unordered_map< int, std::string > formulaCite
bool copyFile(const DString &src, const DString &dest)
Copies the contents of file with name src to the newly created file with name dest.
A bunch of utility functions.