⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 htmlgen.cpp

📁 doxygen(一个自动从源代码生成文档的工具)的源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************** * * $Id: htmlgen.cpp,v 1.56 2001/03/19 19:27:40 root Exp $ * * Copyright (C) 1997-2001 by Dimitri van Heesch. * * Permission to use, copy, modify, and distribute this software and its * documentation under the terms of the GNU General Public License is hereby  * granted. No representations are made about the suitability of this software  * for any purpose. It is provided "as is" without express or implied warranty. * See the GNU General Public License for more details. * * Documents produced by Doxygen are derivative works derived from the * input used in their production; they are not affected by this license. * */#include <stdlib.h>#include "qtbc.h"#include <qdir.h>#include "message.h"#include "htmlgen.h"#include "config.h"#include "util.h"#include "doxygen.h"#include "logos.h"#include "diagram.h"#include "version.h"#include "dot.h"#include "language.h"#include "htmlhelp.h"#define GROUP_COLOR "#ff8080"//#define DBG_HTML(x) x;#define DBG_HTML(x) static const char *defaultStyleSheet =       "H1 { text-align: center; }\n"      "A.qindex {}\n"      "A.qindexRef {}\n"      "A.el { text-decoration: none; font-weight: bold }\n"      "A.elRef { font-weight: bold }\n"      "A.code { text-decoration: none; font-weight: normal; color: #4444ee }\n"      "A.codeRef { font-weight: normal; color: #4444ee }\n"      "A:hover { text-decoration: none; background-color: #f2f2ff }\n"      "DL.el { margin-left: -1cm }\n"      "DIV.fragment { width: 100%; border: none; background-color: #eeeeee }\n"      "DIV.ah { background-color: black; font-weight: bold; color: #ffffff; margin-bottom: 3px; margin-top: 3px }\n"      "TD.md { background-color: #f2f2ff; font-weight: bold; }\n"      "TD.mdname1 { background-color: #f2f2ff; font-weight: bold; color: #602020; }\n"      "TD.mdname { background-color: #f2f2ff; font-weight: bold; color: #602020; width: 600px; }\n"      "DIV.groupHeader { margin-left: 16px; margin-top: 12px; margin-bottom: 6px; font-weight: bold }\n"      "DIV.groupText { margin-left: 16px; font-style: italic; font-size: smaller }\n"      "FONT.keyword       { color: #008000 }\n"      "FONT.keywordtype   { color: #604020 }\n"      "FONT.keywordflow   { color: #e08000 }\n"      "FONT.comment       { color: #800000 }\n"      "FONT.preprocessor  { color: #806020 }\n"      "FONT.stringliteral { color: #002080 }\n"      "FONT.charliteral   { color: #008080 }\n";static QCString g_header;static QCString g_footer;HtmlGenerator::HtmlGenerator() : OutputGenerator(){  dir=Config_getString("HTML_OUTPUT");  col=0;  }HtmlGenerator::~HtmlGenerator(){  //printf("HtmlGenerator::~HtmlGenerator()\n");}void HtmlGenerator::append(const OutputGenerator *g){  t << g->getContents();  col+=((HtmlGenerator *)g)->col;}void HtmlGenerator::init(){  QCString dname=Config_getString("HTML_OUTPUT");  QDir d(dname);  if (!d.exists() && !d.mkdir(dname))  {    err("Could not create output directory %s\n",dname.data());    exit(1);  }  writeLogo(dname);  if (!Config_getString("HTML_HEADER").isEmpty()) g_header=fileToString(Config_getString("HTML_HEADER"));  if (!Config_getString("HTML_FOOTER").isEmpty()) g_footer=fileToString(Config_getString("HTML_FOOTER"));}void HtmlGenerator::writeStyleSheetFile(QFile &file){  QTextStream t(&file);  t << defaultStyleSheet;}static void writeDefaultHeaderFile(QTextStream &t,const char *title,                                   bool external){  t << "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n"    "<html><head>" /*"<meta name=\"robots\" content=\"noindex\">\n"*/    "<meta http-equiv=\"Content-Type\" content=\"text/html;charset="          << theTranslator->idLanguageCharset() << "\">\n"    "<title>" << title << "</title>\n";  t << "<link ";  if (external)     t << "doxygen=\"_doc:" << Config_getString("DOC_URL")       << "\" href=\"" << Config_getString("DOC_URL") << "/";  else    t << "href=\"";  if (Config_getString("HTML_STYLESHEET").isEmpty())  {    t << "doxygen.css";  }  else  {    QCString cssname=Config_getString("HTML_STYLESHEET");    QFileInfo cssfi(cssname);    if (!cssfi.exists())    {      err("Error: user specified HTML style sheet file does not exist!\n");    }    t << cssfi.fileName();  }  t << "\" rel=\"stylesheet\" type=\"text/css\">\n"    "</head><body bgcolor=\"#ffffff\">\n";}void HtmlGenerator::writeHeaderFile(QFile &file){  QTextStream t(&file);#if QT_VERSION >= 200  t.setEncoding(QTextStream::Latin1);#endif  writeDefaultHeaderFile(t,"$title",FALSE);}void HtmlGenerator::writeFooterFile(QFile &file){  QTextStream t(&file);  t << "<hr><address><small>\n";  t << theTranslator->trGeneratedAt( "$datetime", "$projectname" );  t << " <a href=\"http://www.doxygen.org/index.html\">\n"    << "<img src=\"doxygen.gif\" alt=\"doxygen\" "     << "align=\"middle\" border=0 width=110 height=53>\n"    << "</a> $doxygenversion " << theTranslator->trWrittenBy()    << " <a href=\"mailto:dimitri@stack.nl\">Dimitri van Heesch</a>,\n"    << " &copy;&nbsp;1997-2001</small></address>\n"    << "</body>\n"    << "</html>\n";}void HtmlGenerator::startFile(const char *name,const char *,                              const char *title,bool external){  //printf("HtmlGenerator::startFile(%s)\n",name);  QCString fileName=name;  lastTitle=title;  if (fileName.right(5)!=".html") fileName+=".html";  startPlainFile(fileName);  if (Config_getBool("GENERATE_HTMLHELP"))  {    HtmlHelp::getInstance()->addIndexFile(fileName);  }   lastFile = fileName;  if (g_header.isEmpty())   {    writeDefaultHeaderFile(t,title,external);  }  else  {    t << substituteKeywords(g_header,lastTitle);  }  t << "<!-- " << theTranslator->trGeneratedBy() << " Doxygen "     << versionString << " -->" << endl;}void HtmlGenerator::startQuickIndexItem(const char *s,const char *l){  QCString *dest;  if (s)   {    t << "<a class=\"qindexRef\" ";    t << "doxygen=\"" << s << ":";    if ((dest=Doxygen::tagDestinationDict[s])) t << *dest;    if (strcmp(s,"_cgi")!=0) t << "/"; // small hack to get the cgi binary link right    t << "\" ";  }  else  {    t << "<a class=\"qindex\" ";  }  t << "href=\"";   if (s)  {    if ((dest=Doxygen::tagDestinationDict[s])) t << *dest;    if (strcmp(s,"_cgi")!=0) t << "/";  }  t << l << "\">";}void HtmlGenerator::endQuickIndexItem(){  t << "</a> &nbsp; ";}void HtmlGenerator::writeFooter(int part,bool external){  switch (part)  {    case 0:      if (g_footer.isEmpty())        t << "<hr><address><small>";      else        t << substituteKeywords(g_footer,lastTitle);      break;    case 1:      if (g_footer.isEmpty())      {        t << endl << "<a href=\"http://www.doxygen.org/index.html\">";        t << endl << "<img ";        if (external)        {          t << "doxygen=\"_doc:" << Config_getString("DOC_URL")             << "\" src=\"" << Config_getString("DOC_URL") << "/";        }        else        {          t << "src=\"";        }        t << "doxygen.gif\" alt=\"doxygen\" "           << "align=\"middle\" border=0 " << endl <<              "width=110 height=53></a>" << versionString <<" ";      }      break;    default:      if (g_footer.isEmpty())        t << " <a href=\"mailto:dimitri@stack.nl\">Dimitri van Heesch</a>,\n &copy;&nbsp;"             "1997-2001</small></address>\n</body>\n</html>\n";      break;        }}void HtmlGenerator::endFile(){  endPlainFile();}void HtmlGenerator::startProjectNumber(){  t << "<h3 align=\"center\">";}void HtmlGenerator::endProjectNumber(){  t << "</h3>";}void HtmlGenerator::writeStyleInfo(int part){  if (part==0)  {    if (Config_getString("HTML_STYLESHEET").isEmpty()) // write default style sheet    {      startPlainFile("doxygen.css");             // alternative, cooler looking titles      //t << "H1 { text-align: center; border-width: thin none thin none;" << endl;      //t << "     border-style : double; border-color : blue; padding-left : 1em; padding-right : 1em }" << endl;      t << defaultStyleSheet;      endPlainFile();    }    else // write user defined style sheet    {      QCString cssname=Config_getString("HTML_STYLESHEET");      QFileInfo cssfi(cssname);      if (!cssfi.exists() || !cssfi.isFile() || !cssfi.isReadable())      {        err("Error: style sheet %s does not exist or is not readable!", Config_getString("HTML_STYLESHEET").data());      }      else      {        startPlainFile(cssfi.fileName());        t << fileToString(cssname);        endPlainFile();      }    }  }}void HtmlGenerator::startDoxyAnchor(const char *,const char *,                                    const char *anchor, const char *name){  t << "<a name=\"" << anchor << "\" doxytag=\"" << name << "\"></a>";}void HtmlGenerator::endDoxyAnchor(const char *,const char *){}void HtmlGenerator::newParagraph(){  t << endl << "<p>" << endl;}void HtmlGenerator::writeString(const char *text){  t << text;}void HtmlGenerator::writeIndexItem(const char *ref,const char *f,                                   const char *name){  //printf("HtmlGenerator::writeIndexItem(%s,%s,%s)\n",ref,f,name);  QCString *dest;  t << "<li>";  if (ref || f)  {    if (ref)     {      t << "<a class=\"elRef\" ";      t << "doxygen=\"" << ref << ":";      if ((dest=Doxygen::tagDestinationDict[ref])) t << *dest << "/";      t << "\" ";    }    else    {      t << "<a class=\"el\" ";    }    t << "href=\"";    if (ref)    {      if ((dest=Doxygen::tagDestinationDict[ref])) t << *dest << "/";    }    if (f) t << f << ".html\">";  }  else  {    t << "<b>";  }  docify(name);  if (ref || f)  {    t << "</a>" << endl;  }  else  {    t << "</b>";  }  //if (Config_getBool("GENERATE_HTMLHELP") && f)  //{  //  htmlHelp->addItem(name,((QCString)f)+".html");  //}}void HtmlGenerator::writeStartAnnoItem(const char *,const char *f,                                       const char *path,const char *name){  t << "<li>";  if (path) docify(path);  t << "<a class=\"el\" href=\"" << f << ".html\">";  docify(name);  t << "</a> ";  //if (Config_getBool("GENERATE_HTMLHELP") && f)  //{  //  htmlHelp->addItem(name, ((QCString)f)+".html");  //}}void HtmlGenerator::writeObjectLink(const char *ref,const char *f,                                    const char *anchor, const char *name){  QCString *dest;  if (ref)   {    t << "<a class=\"elRef\" ";    t << "doxygen=\"" << ref << ":";    if ((dest=Doxygen::tagDestinationDict[ref])) t << *dest << "/";    t << "\" ";  }  else  {    t << "<a class=\"el\" ";  }  t << "href=\"";  if (ref)  {    if ((dest=Doxygen::tagDestinationDict[ref])) t << *dest << "/";  }  if (f) t << f << ".html";  if (anchor) t << "#" << anchor;  t << "\">";  docify(name);  t << "</a>";}void HtmlGenerator::writeCodeLink(const char *ref,const char *f,                                  const char *anchor, const char *name){  QCString *dest;  if (ref)   {    t << "<a class=\"codeRef\" ";    t << "doxygen=\"" << ref << ":";    if ((dest=Doxygen::tagDestinationDict[ref])) t << *dest << "/";    t << "\" ";  }  else  {    t << "<a class=\"code\" ";  }  t << "href=\"";  if (ref)  {    if ((dest=Doxygen::tagDestinationDict[ref])) t << *dest << "/";  }  if (f) t << f << ".html";  if (anchor) t << "#" << anchor;  t << "\">";  docify(name);  t << "</a>";  col+=strlen(name);}void HtmlGenerator::startTextLink(const char *f,const char *anchor){  t << "<a href=\"";  if (f)   t << f << ".html";  if (anchor) t << "#" << anchor;  t << "\">"; }void HtmlGenerator::endTextLink(){  t << "</a>";}void HtmlGenerator::startHtmlLink(const char *url){  t << "<a ";  if (Config_getBool("GENERATE_TREEVIEW")) t << "target=\"top\" ";  t << "href=\"";  if (url) t << url;  t << "\">"; }void HtmlGenerator::endHtmlLink(){  t << "</a>";}void HtmlGenerator::writeMailLink(const char *url){  t << "<a href=\"mailto:" << url << "\">";  docify(url);   t << "</a>";}void HtmlGenerator::startGroupHeader(){  t << "<h2>";}void HtmlGenerator::endGroupHeader(){  t << "</h2>" << endl;}void HtmlGenerator::startSection(const char *lab,const char *,bool sub){  t << "<a name=\"" << lab << "\">";  if (sub) t << "<h3>"; else t << "<h2>";}void HtmlGenerator::endSection(const char *,bool sub){  if (sub) t << "</h3>"; else t << "</h2>";  t << "</a>" << endl;}void HtmlGenerator::writeSectionRef(const char *ref,const char *name,                                    const char *anchor,const char *title){  QCString *dest;  //printf("writeSectionRef(%s,%s,%s,%s)\n",ref,name,anchor,title);  QCString refName=name;  if (refName.right(5)!=".html") refName+=".html";  t << "<a ";   if (ref)   {    t << "doxygen=\"" << ref << ":";    if ((dest=Doxygen::tagDestinationDict[ref])) t << *dest << "/";    t << "\" ";  }  t << "href=\"";   if (ref)  {    if ((dest=Doxygen::tagDestinationDict[ref])) t << *dest << "/";  }  t << refName << "#" << anchor << "\">";  docify(title);  t << "</a>";}void HtmlGenerator::writeSectionRefItem(const char *name,const char *lab,                                    const char *title){  QCString refName=name;  if (refName.right(5)!=".html") refName+=".html";  t << "<a href=\"" << refName << "#" << lab << "\">";  docify(title);  t << "</a>";}void HtmlGenerator::docify(const char *str){  if (str)  {    const char *p=str;    char c;    while (*p)    {      c=*p++;      switch(c)      {        case '<':  t << "&lt;"; break;        case '>':  t << "&gt;"; break;        case '&':  t << "&amp;"; break;        case '\\':                   if (*p=='<')                     { t << "&lt;"; p++; }                   else if (*p=='>')                     { t << "&gt;"; p++; }                   else                     t << "\\";                   break;        default:   t << c;       }    }  }}void HtmlGenerator::codify(const char *str){  //docify(str);  //static char spaces[]="        ";  if (str)  {     const char *p=str;    char c;    int spacesToNextTabStop;    while (*p)    {      c=*p++;      switch(c)      {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -