My Project
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Attributes | List of all members
CiteDict Class Reference

Cite database access class. More...

#include <cite.h>

Public Member Functions

 CiteDict (int size)
 
void insert (const char *label)
 
CiteInfofind (const char *label) const
 
void generatePage () const
 
void clear ()
 
bool isEmpty () const
 
void writeLatexBibliography (FTextStream &t)
 

Private Attributes

QDict< CiteInfom_entries
 
QCString m_baseFileName
 

Detailed Description

Cite database access class.

This class provides access do the database of bibliographic references through the bibtex backend.

Definition at line 56 of file cite.h.

Constructor & Destructor Documentation

CiteDict::CiteDict ( int  size)

Create the database, with an expected maximum of size entries

Definition at line 36 of file cite.cpp.

References m_entries.

: m_entries(size, FALSE)
{
m_entries.setAutoDelete(TRUE);
}

Member Function Documentation

void CiteDict::clear ( )

clears the database

Definition at line 103 of file cite.cpp.

References m_entries.

{
m_entries.clear();
}
CiteInfo * CiteDict::find ( const char *  label) const

Return the citation info for a given label

Definition at line 98 of file cite.cpp.

References m_entries.

Referenced by DocAnchor::DocAnchor(), and DocCite::DocCite().

{
return label ? m_entries.find(label) : 0;
}
void CiteDict::generatePage ( ) const

Generate the citations page

Definition at line 114 of file cite.cpp.

References addRelatedPage(), bibTmpDir(), bibTmpFile(), Config_getBool, Config_getList, Config_getString, copyFile(), ResourceMgr::copyResource(), doc, endl(), err(), CiteConsts::fileName, ResourceMgr::instance(), isEmpty(), CiteInfo::label, m_entries, portable_system(), portable_sysTimerStop(), CiteInfo::text, theTranslator, and Translator::trCiteReferences().

Referenced by parseInput().

{
//printf("** CiteDict::generatePage() count=%d\n",m_ordering.count());
// do not generate an empty citations page
if (isEmpty()) return; // nothing to cite
// 1. generate file with markers and citations to OUTPUT_DIRECTORY
QFile f;
QCString outputDir = Config_getString(OUTPUT_DIRECTORY);
QCString citeListFile = outputDir+"/citelist.doc";
f.setName(citeListFile);
if (!f.open(IO_WriteOnly))
{
err("could not open file %s for writing\n",citeListFile.data());
}
FTextStream t(&f);
t << "<!-- BEGIN CITATIONS -->" << endl;
t << "<!--" << endl;
QDictIterator<CiteInfo> it(m_entries);
CiteInfo *ci;
for (it.toFirst();(ci=it.current());++it)
{
t << "\\citation{" << ci->label << "}" << endl;
}
t << "-->" << endl;
t << "<!-- END CITATIONS -->" << endl;
t << "<!-- BEGIN BIBLIOGRAPHY -->" << endl;
t << "<!-- END BIBLIOGRAPHY -->" << endl;
f.close();
// 2. generate bib2xhtml
QCString bib2xhtmlFile = outputDir+"/bib2xhtml.pl";
ResourceMgr::instance().copyResource("bib2xhtml.pl",outputDir);
// 3. generate doxygen.bst
QCString doxygenBstFile = outputDir+"/doxygen.bst";
ResourceMgr::instance().copyResource("doxygen.bst",outputDir);
// 4. for all formats we just copy the bib files to as special output directory
// so bibtex can find them without path (bibtex doesn't support paths or
// filenames with spaces!)
// Strictly not required when only latex is generated
QStrList &citeDataList = Config_getList(CITE_BIB_FILES);
QCString bibOutputDir = outputDir+"/"+bibTmpDir;
QCString bibOutputFiles = "";
QDir thisDir;
thisDir.mkdir(bibOutputDir);
const char *bibdata = citeDataList.first();
int i = 0;
while (bibdata)
{
QCString bibFile = bibdata;
if (!bibFile.isEmpty() && bibFile.right(4)!=".bib") bibFile+=".bib";
QFileInfo fi(bibFile);
if (fi.exists())
{
if (!bibFile.isEmpty())
{
++i;
copyFile(bibFile,bibOutputDir + bibTmpFile + QCString().setNum(i) + ".bib");
bibOutputFiles = bibOutputFiles + " " + bibTmpDir + bibTmpFile + QCString().setNum(i) + ".bib";
}
}
else if (!fi.exists())
{
err("bib file %s not found!\n",bibFile.data());
}
bibdata = citeDataList.next();
}
QString oldDir = QDir::currentDirPath();
QDir::setCurrent(outputDir);
// 5. run bib2xhtml perl script on the generated file which will insert the
// bibliography in citelist.doc
int exitCode;
if ((exitCode=portable_system("perl","\""+bib2xhtmlFile+"\" "+bibOutputFiles+" \""+
citeListFile+"\"")) != 0)
{
err("Problems running bibtex. Verify that the command 'perl --version' works from the command line. Exit code: %d\n",
exitCode);
}
QDir::setCurrent(oldDir);
// 6. read back the file
f.setName(citeListFile);
if (!f.open(IO_ReadOnly))
{
err("could not open file %s for reading\n",citeListFile.data());
}
bool insideBib=FALSE;
QCString doc;
QFileInfo fi(citeListFile);
QCString input(fi.size()+1);
f.readBlock(input.rawData(),fi.size());
f.close();
input.at(fi.size())='\0';
int p=0,s;
//printf("input=[%s]\n",input.data());
while ((s=input.find('\n',p))!=-1)
{
QCString line = input.mid(p,s-p);
//printf("p=%d s=%d line=[%s]\n",p,s,line.data());
p=s+1;
if (line.find("<!-- BEGIN BIBLIOGRAPHY")!=-1) insideBib=TRUE;
else if (line.find("<!-- END BIBLIOGRAPH")!=-1) insideBib=FALSE;
else if (insideBib) doc+=line+"\n";
int i;
// determine text to use at the location of the @cite command
if (insideBib && (i=line.find("name=\"CITEREF_"))!=-1)
{
int j=line.find("\">[");
int k=line.find("]</a>");
if (j!=-1 && k!=-1)
{
QCString label = line.mid(i+14,j-i-14);
QCString number = line.mid(j+2,k-j-1);
CiteInfo *ci = m_entries.find(label);
//printf("label='%s' number='%s' => %p\n",label.data(),number.data(),ci);
if (ci)
{
ci->text = number;
}
}
}
}
//printf("doc=[%s]\n",doc.data());
// 7. add it as a page
// 8. for latex we just copy the bib files to the output and let
// latex do this work.
if (Config_getBool(GENERATE_LATEX))
{
// copy bib files to the latex output dir
QStrList &citeDataList = Config_getList(CITE_BIB_FILES);
QCString latexOutputDir = Config_getString(LATEX_OUTPUT)+"/";
int i = 0;
const char *bibdata = citeDataList.first();
while (bibdata)
{
QCString bibFile = bibdata;
// Note: file can now have multiple dots
if (!bibFile.isEmpty() && bibFile.right(4)!=".bib") bibFile+=".bib";
QFileInfo fi(bibFile);
if (fi.exists())
{
if (!bibFile.isEmpty())
{
// bug_700510, multile times the same name were overwriting; creating new names
// also for names with spaces
++i;
copyFile(bibFile,latexOutputDir + bibTmpFile + QCString().setNum(i) + ".bib");
}
}
else
{
err("bib file %s not found!\n",bibFile.data());
}
bibdata = citeDataList.next();
}
}
// 9. Remove temporary files
thisDir.remove(citeListFile);
thisDir.remove(doxygenBstFile);
thisDir.remove(bib2xhtmlFile);
// we might try to remove too many files as empty files didn't get a coresponding new file
// but the remove function does not emit an error for it and we don't catch the error return
// so no problem.
for (unsigned int j = 1; j <= citeDataList.count(); j++)
{
thisDir.remove(bibOutputDir + bibTmpFile + QCString().setNum(j) + ".bib");
}
thisDir.rmdir(bibOutputDir);
}
void CiteDict::insert ( const char *  label)

Resolve references to citations Insert a citation identified by label into the database

Definition at line 93 of file cite.cpp.

References m_entries.

{
m_entries.insert(label,new CiteInfo(label));
}
bool CiteDict::isEmpty ( ) const

return TRUE if there are no citations. Only valid after calling resolve()

Definition at line 108 of file cite.cpp.

References Config_getList, and m_entries.

Referenced by generatePage(), writeLatexMakefile(), and writeMakeBat().

{
QStrList &citeBibFiles = Config_getList(CITE_BIB_FILES);
return (citeBibFiles.count()==0 || m_entries.isEmpty());
}
void CiteDict::writeLatexBibliography ( FTextStream t)

writes the latex code for the standard bibliography section to text stream t

Definition at line 41 of file cite.cpp.

References bibTmpFile(), Config_getBool, Config_getList, Config_getString, m_entries, theTranslator, and Translator::trCiteReferences().

Referenced by writeDefaultFooter().

{
if (m_entries.isEmpty())
return;
QCString style = Config_getString(LATEX_BIB_STYLE);
if (style.isEmpty())
style="plain";
QCString unit;
if (Config_getBool(COMPACT_LATEX))
unit = "section";
else
unit = "chapter";
t << "% Bibliography\n"
"\\newpage\n"
"\\phantomsection\n";
bool pdfHyperlinks = Config_getBool(PDF_HYPERLINKS);
if (!pdfHyperlinks)
{
t << "\\clearemptydoublepage\n";
t << "\\addcontentsline{toc}{" << unit << "}{" << theTranslator->trCiteReferences() << "}\n";
}
t << "\\bibliographystyle{" << style << "}\n"
"\\bibliography{";
QStrList &citeDataList = Config_getList(CITE_BIB_FILES);
int i = 0;
const char *bibdata = citeDataList.first();
while (bibdata)
{
QCString bibFile = bibdata;
// Note: file can now have multiple dots
if (!bibFile.isEmpty() && bibFile.right(4)!=".bib") bibFile+=".bib";
QFileInfo fi(bibFile);
if (fi.exists())
{
if (!bibFile.isEmpty())
{
if (i) t << ",";
i++;
t << bibTmpFile << QString().setNum(i);
}
}
bibdata = citeDataList.next();
}
t << "}\n";
if (pdfHyperlinks)
{
t << "\\addcontentsline{toc}{" << unit << "}{" << theTranslator->trCiteReferences() << "}\n";
}
t << "\n";
}

Member Data Documentation

QCString CiteDict::m_baseFileName
private

Definition at line 95 of file cite.h.

QDict<CiteInfo> CiteDict::m_entries
private

Definition at line 93 of file cite.h.

Referenced by CiteDict(), clear(), find(), generatePage(), insert(), isEmpty(), and writeLatexBibliography().


The documentation for this class was generated from the following files: