About
User Reference
C++ API
luafaudes
Developer
Links
libFAUDES online
libFAUDES

Sections

Index

ref2html.cpp

Go to the documentation of this file.
00001 /** ref2html.cpp  Utility to generate a html documents from fref files */
00002 
00003 /* FAU Discrete Event Systems Library (libfaudes)
00004 
00005 Copyright (C) 2011 Thomas Moor
00006 
00007 This library is free software; you can redistribute it and/or
00008 modify it under the terms of the GNU Lesser General Public
00009 License as published by the Free Software Foundation; either
00010 version 2.1 of the License, or (at your option) any later version.
00011 
00012 This library is distributed in the hope that it will be useful,
00013 but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 Lesser General Public License for more details.
00016 
00017 You should have received a copy of the GNU Lesser General Public
00018 License along with this library; if not, write to the Free Software
00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
00020    
00021 
00022 /*
00023 
00024 Note: in ist current state, this utility is badly organized.
00025 Issues include
00026 - preformance (linear searchs)
00027 - normelized section labels etc
00028 - global configuration data 
00029 - embedded HTML fragments
00030 
00031 */
00032 
00033 
00034 
00035 #include <string>
00036 #include <cctype>
00037 #include <ctime>
00038 #include <iostream>
00039 #include <fstream>
00040 #include "corefaudes.h"
00041 
00042 
00043 using namespace faudes;
00044 
00045 // ******************************************************************
00046 // error exit
00047 // ******************************************************************
00048 
00049 void usage_exit(const std::string& rMessage="") {
00050   // ui hints
00051   if(rMessage!="") {
00052     std::cerr << rMessage << std::endl;
00053     std::cout << "" << std::endl;
00054   }
00055   std::cerr << "ref2html: " << FDVersionString()  << std::endl;
00056   std::cout << "" << std::endl;
00057   std::cerr << "utility to generate HTML from libFAUDES reference pages (*.fref)" << std::endl;
00058   std::cerr << std::endl << "usage: " << std::endl;
00059   std::cerr << " ref2html [options...]  <fref-file> <output-file>" << std::endl;
00060   std::cerr << "with options as follows:" << std::endl;
00061   std::cerr << " -rti  <rti-file>   use specified run-time-interface definition" << std::endl;
00062   std::cerr << " -flx  <flx-file>   use specified lua-extension file" << std::endl;
00063   std::cerr << " -css  <css-file>   use specified style sheet" << std::endl;
00064   std::cerr << " -cnav <fref-file>  use specified chapter navigation file" << std::endl;
00065   std::cerr << " -chapter <label>   overwrite chapter label" << std::endl;
00066   std::cerr << " -section <label>   overwrite section label" << std::endl;
00067   std::cerr << " -rel <prefix>      prefix to chapter documentation base" << std::endl;
00068   std::cerr << " -inc <fref-file>   include table of contents" << std::endl;
00069   std::cerr << " -app               no other libFAUDES chapters present" << std::endl;
00070   std::cerr << std::endl << std::endl;
00071   std::cerr << " ref2html -toc <fref-files> <output-file>" << std::endl;
00072   std::cerr << "to generate table of contents file" << std::endl;
00073   std::cerr << std::endl << std::endl;
00074   std::cerr << " ref2html -doxheader <output-file>" << std::endl;
00075   std::cerr << " ref2html -doxfooter <output-file>" << std::endl;
00076   std::cerr << "to generate header/footer for c++ api documentation" << std::endl;
00077   std::cerr << std::endl << std::endl;
00078   std::cerr << " ref2html -extract <input-file> <output-directory>" << std::endl;
00079   std::cerr << "to extract multiple reference pages from one file" << std::endl;
00080   std::cerr << std::endl;
00081   std::cerr << std::endl << "note: use \"-\" as output file for console output" << std::endl;
00082   exit(1);
00083 }
00084 
00085 
00086 // ******************************************************************
00087 // configuration
00088 // ******************************************************************
00089 
00090 bool mStandaloneReference = false;
00091 
00092 std::string mFrefTitle="";
00093 std::string mFrefChapter="";
00094 std::string mFrefSection="";
00095 std::string mFrefPage="";
00096 std::string mFrefLink="";
00097 
00098 std::string mRtiFile="";
00099 std::string mFlxFile="";
00100 std::string mHtmlFile="";
00101 std::string mFrefFile="";
00102 std::string mChapterFile="";
00103 std::string mIncludeFile="";
00104 
00105 std::string mBooksPrefix="../";
00106 std::string mChaptersPrefix="./";
00107 std::string mImagePrefix="./faudes_images/";
00108 std::string mRegistryPrefix="./registry/";
00109 std::string mCsourcePrefix="./csource/";
00110 std::string mLuafaudesPrefix="./luafaudes/";
00111 
00112 std::string mDownloadLink="http://www.rt.eei.uni-erlangen.de/FGdes/download.html";
00113 std::string mFaudesLink="http://www.rt.eei.uni-erlangen.de/FGdes/faudes";
00114 std::string mDestoolLink="http://www.rt.eei.uni-erlangen.de/FGdes/destool";
00115 std::string mLuafaudesLink="http://www.rt.eei.uni-erlangen.de/FGdes/faudes/luafaudes/";
00116 std::string mCsourceLink="http://www.rt.eei.uni-erlangen.de/FGdes/faudes/csource/";
00117 std::string mCssFile="faudes.css";
00118 
00119 std::string mThisChapterClass="chapter_this";
00120 std::string mOtherChapterClass="chapter_other";
00121 std::string mExitChapterClass="chapter_exit";
00122 
00123 void ChaptersPrefix(const std::string& prefix) {
00124   mChaptersPrefix=prefix;
00125   mBooksPrefix=prefix+"../";
00126   mImagePrefix=prefix+"faudes_images/";
00127   mRegistryPrefix=prefix+"registry/";
00128   mCsourcePrefix=prefix+"csource/";
00129   mLuafaudesPrefix=prefix+"luafaudes/";
00130 }
00131 
00132 // ******************************************************************
00133 // helper: time stamp
00134 // ******************************************************************
00135 
00136 std::string TimeStamp(void) {
00137   time_t now;
00138   struct tm * local;
00139   char buffer[80];
00140   time(&now );
00141   local=localtime(&now);
00142   strftime(buffer,80,"%Y.%m.%d",local);
00143   return std::string(buffer);
00144 }
00145 
00146 // ******************************************************************
00147 // helper: html header
00148 // ******************************************************************
00149 
00150 void HeaderHtml(std::ostream* pStream) {
00151   *pStream << "<html xmlns=\"http://www.w3.org/1999/xhtml\">" << std::endl; 
00152   *pStream << "<head>" << std::endl;
00153   *pStream << "<title>" << mFrefTitle << "</title>" << std::endl; 
00154   *pStream << "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />" << std::endl;
00155   *pStream << "<meta name=\"contents\" content=\"discrete event systems, libFAUDES, supervisory control, controller synthesis, automata, software library, regular languages, open source, GPL.\"/>"  << std::endl;
00156   *pStream << "<link href=\"" << mChaptersPrefix << mCssFile << "\" rel=\"stylesheet\" type=\"text/css\" />" << std::endl;
00157   *pStream << "<link rel=\"shortcut icon\" href=\""<< mImagePrefix << "des.ico\">" << std::endl;
00158   *pStream << "</head>" << std::endl;
00159   *pStream << "<body>" << std::endl;
00160 }
00161 
00162 // ******************************************************************
00163 // helper: html footer
00164 // ******************************************************************
00165 
00166 void FooterHtml(std::ostream* pStream) {
00167   *pStream << "<p class=\"bottom_line\"> " << std::endl;
00168   *pStream << "<a href=\"" << mFaudesLink << "\" target=\"_top\">" << FDVersionString() << "</a> " << std::endl;
00169   *pStream << "--- " << TimeStamp() <<  "  " << std::endl;
00170   if(FDPluginsString()!="" && mFrefChapter!="cppapi")
00171      *pStream << "--- with &quot;" << FDPluginsString() << "&quot; " << std::endl;
00172   if(mFrefChapter=="cppapi")
00173      *pStream << "--- c++ source docu by <a href=\"http://www.doxygen.org\" target=\"_top\">doxygen</a>" << std::endl;
00174   *pStream << "</p>" << std::endl;
00175   if(mFrefChapter=="reference") {
00176     *pStream << "<!--[if IE]>" << std::endl;
00177     *pStream << "<p class=\"bottom_line_warning\">" << std::endl;
00178     *pStream << "If MS Internet Explorer fails to display certain mathematical symbols," << std::endl;
00179     *pStream << "your system misses the corresponding unicode fonts." << std::endl; 
00180     *pStream << "<br>" << std::endl;
00181     *pStream << "You may either install &quot;Arial Unicode MS&quot; from a recent MS Office package" << std::endl;
00182     *pStream << "or the freely available" << std::endl; 
00183     *pStream << "&quot;<a href=\"http://greekfonts.teilar.gr/\">Symbola</a>&quot;" << std::endl;
00184     *pStream << "<br>" << std::endl;
00185     *pStream << "See also <a href=\"http://www.alanwood.net/\">Allan Woods</a> unicode page." << std::endl;
00186     *pStream << "B.t.w.: <a href=\"http://www.mozilla.com\">Firefox</a> will display" << std::endl;
00187     *pStream << "all relevant symbols out-of-the-box and nicely render SVG diagrams." << std::endl;
00188     *pStream << "<br>" << std::endl;
00189     *pStream << "<br>" << std::endl;
00190     *pStream << "</p>" << std::endl;
00191     *pStream << "<![endif]-->" << std::endl;
00192   }
00193   *pStream << "</body>" << std::endl;
00194   *pStream << "</html>" << std::endl;
00195 }
00196 
00197 // ******************************************************************
00198 // helper: html for image
00199 // ******************************************************************
00200 
00201 void ImageHtml(std::ostream* pStream, const std::string& rFileName) {
00202   *pStream << "<a class=\"faudes_image\" href=\"" << mImagePrefix << rFileName << ".html\">";
00203   *pStream << "<img src=\"" << mImagePrefix << rFileName << ".png\"/>";
00204   *pStream << "</a>" << std::endl;
00205 }
00206 
00207 // ******************************************************************
00208 // helper: html for linked type name
00209 // ******************************************************************
00210 
00211 void TypeHtml(std::ostream* pStream, const std::string& rTypeName) {
00212 
00213   // just text if unknown
00214   if(!TypeRegistry::G()->Exists(rTypeName)) {
00215     *pStream << rTypeName;
00216     return;
00217   }
00218 
00219   // retrieve definition
00220   const TypeDefinition& tdef=TypeRegistry::G()->Definition(rTypeName);
00221   std::string tyname = tdef.Name();
00222   std::string tyhtml = tdef.HtmlDoc();
00223   if(tyhtml=="" || tyhtml=="none") {
00224     *pStream << tyname;
00225   } else {
00226     *pStream << "<a href=\"" << mRegistryPrefix << tyhtml << "\">" << tyname << "</a>";
00227   }
00228 }
00229 
00230 
00231 // ******************************************************************
00232 // helper: html for linked function name
00233 // ******************************************************************
00234 
00235 void FunctionHtml(std::ostream* pStream, const std::string& rFunctionName) {
00236 
00237   // just text if unknown
00238   if(!FunctionRegistry::G()->Exists(rFunctionName)) {
00239     *pStream << rFunctionName;
00240     return;
00241   }
00242 
00243   // retrieve definition
00244   const FunctionDefinition& fdef=FunctionRegistry::G()->Definition(rFunctionName);
00245   std::string fname = fdef.Name();
00246   std::string fhtml = fdef.HtmlDoc();
00247   if(fhtml=="" || fhtml=="none") {
00248     *pStream << fname;
00249   } else {
00250     *pStream << "<a href=\"" << mRegistryPrefix << fhtml << "\">" << fname << "</a>";
00251   }
00252 }
00253 
00254 // ******************************************************************
00255 // helper: html for ascii text
00256 // ******************************************************************
00257 
00258 void TextHtml(std::ostream* pStream, const std::string& rText) {
00259   std::string buff;
00260   buff=StringSubstitute(buff,"<","&lt;");
00261   buff=StringSubstitute(buff,">","&gt;");
00262   buff=StringSubstitute(buff,"&","&amp;");
00263   *pStream << buff;
00264 }
00265 
00266 // ******************************************************************
00267 // helper: html for math
00268 // (we really need at least regex here!)
00269 // ******************************************************************
00270 
00271 // resolve simple one-arg macros
00272 std::string TexMacroSubstitute1(const std::string& rTexString, const std::string& rMacro, const std::string& rSubst) {
00273   // prep result
00274   std::string res;
00275   std::size_t pos=0; 
00276   // loop over occurences of "macro"
00277   while(pos<rTexString.length()) {
00278     std::size_t next=rTexString.find(rMacro,pos);
00279     if(next==std::string::npos) break;
00280     res.append(rTexString.substr(pos,next-pos));
00281     std::string arg;
00282     pos=next+rMacro.length();
00283     if(!(pos+1<rTexString.length())) continue;
00284     if(rTexString.at(pos)!='{') continue;
00285     std::size_t aend=rTexString.find('}',pos);
00286     if(aend==std::string::npos) break;
00287     arg=rTexString.substr(pos+1,aend-pos-1);
00288     arg=StringSubstitute(rSubst,"#1",arg);
00289     res.append(arg);
00290     pos=aend+1;
00291   }
00292   // get end
00293   if(pos<rTexString.length()) 
00294     res.append(rTexString.substr(pos));
00295   // done
00296   return res;
00297 }
00298    
00299 
00300 // mimique tex spacing
00301 std::string TexSpacing(const std::string& rTexString) {
00302   // prep result
00303   std::string res;
00304   std::size_t pos=0; 
00305   bool math=true;
00306   // traverse string 
00307   while(pos<rTexString.length()) {
00308     // explict: "\ "
00309     if(pos+1 < rTexString.length())
00310     if(rTexString.substr(pos,2)=="\\ ")
00311       {pos+=2; res.append("&nbsp;"); continue;}
00312     // explicit: "\," 
00313     if(pos+1 < rTexString.length())
00314     if(rTexString.substr(pos,2)=="\\,")
00315       {pos+=2; res.append("&ensp;"); continue;}
00316     // explicit: "\;" 
00317     if(pos+1 < rTexString.length())
00318     if(rTexString.substr(pos,2)=="\\;")
00319       {pos+=2; res.append("&ensp;"); continue;}
00320     // explict: "\quad"
00321     if(pos+4 < rTexString.length())
00322     if(rTexString.substr(pos,5)=="\\quad")
00323       {pos+=5; res.append("&nbsp;&nbsp;&nbsp;&nbsp;"); continue;}
00324     // math swallow space
00325     if(math)
00326     if(isspace(rTexString.at(pos)))
00327       { pos+=1; continue;}
00328     // sense end of math mode
00329     if(math)
00330     if(pos+5 < rTexString.length())
00331     if(rTexString.substr(pos,6)=="\\text{")
00332       {pos+=6; math=false; continue;};
00333     // sense end of text mode
00334     if(!math)
00335     if(rTexString.at(pos)=='}')
00336       { pos+=1; math=true; continue;}
00337     // default: copy
00338     res.append(1,rTexString.at(pos));
00339     pos+=1;
00340     }
00341   return res;
00342 }
00343 
00344 // mimique tex scripts
00345 std::string TexScripts(const std::string& rTexString) {
00346   // prep result
00347   std::string res;
00348   std::size_t pos=0; 
00349   int c0=-1;
00350   int cm1=-1;
00351   int cm2=-1;
00352   // traverse string 
00353   while(pos<rTexString.length()) {
00354     // fill buffer
00355     cm2=cm1; cm1=c0; c0=rTexString.at(pos);
00356     // full script
00357     if(cm1=='^' || cm1=='_')
00358     if(c0=='{') {
00359       std::size_t aend=rTexString.find('}',pos);
00360       if(aend==std::string::npos) break;
00361       std::string script=rTexString.substr(pos+1,aend-pos-1);
00362       res.append(1,cm1);
00363       res.append(script);
00364       cm1=-1; cm2=-1; pos=aend+1;
00365       continue;
00366     }
00367     // superscript uparrow
00368     if(cm1=='^')
00369     if(c0=='\\') {
00370       size_t mpos=rTexString.find("\\uparrow",pos);
00371       if(mpos==pos) {
00372         res.append("<span class=\"faudes_sup\">&uarr;</span>");
00373         cm1=-1; cm2=-1; pos+=8;
00374         continue;
00375       }
00376     }
00377     // digit subscript
00378     if(cm1=='_')
00379     if(isalpha(cm2)) 
00380     if(isdigit(c0)) {
00381       res.append(1,c0);
00382       cm1=-1; cm2=-1; pos+=1;
00383       continue;
00384     }
00385     // lower subscript
00386     if(cm1=='_')
00387     if(islower(c0)) 
00388     if(isupper(cm2)) {
00389       res.append(1,c0);
00390       cm1=-1; cm2=-1; pos+=1;
00391       continue;
00392     }
00393     // super star
00394     if(cm1=='^')
00395     if(c0=='*' || c0=='+') { 
00396       res.append(1,c0);
00397       cm1=-1; cm2=-1; pos+=1;
00398       continue;
00399     }
00400     // other script
00401     if(cm1=='^' || cm1=='_') {
00402       res.append(1,cm1);
00403       res.append(1,c0);
00404       cm1=-1; cm2=-1; pos+=1;
00405       continue;
00406     }     
00407     // plain copy default
00408     if(c0!='_')
00409     if(c0!='^') {
00410       res.append(1,c0);
00411     }
00412     // continue
00413     pos+=1;
00414   }
00415   return res;
00416 }
00417 
00418   
00419 // over all tex processing
00420 void MathHtml(std::ostream* pStream, const std::string& rMathString) {
00421   std::string buff=rMathString;
00422   // xml quote
00423   buff=StringSubstitute(buff,"&","&amp;");
00424   // tex quote
00425   buff=StringSubstitute(buff,"#","&hash;");
00426   // greek letters 
00427   buff=StringSubstitute(buff,"\\Sigma","Sigma");
00428   buff=StringSubstitute(buff,"\\sigma","o");
00429   buff=StringSubstitute(buff,"\\delta","delta");
00430   buff=StringSubstitute(buff,"\\epsilon","epsilon");
00431   buff=StringSubstitute(buff,"\\omega","w");
00432   // one-arg macros
00433   buff=TexMacroSubstitute1(buff,"\\ProInv","Pinv#1");
00434   buff=TexMacroSubstitute1(buff,"\\Pro","P#1");
00435   buff=TexMacroSubstitute1(buff,"\\Closure","Closure(#1)");
00436   buff=TexMacroSubstitute1(buff,"\\Prefix","Prefix(#1)");
00437   // tex math spacing and plain text
00438   buff=TexMacroSubstitute1(buff,"\\texttt","\\text{<tt>#1</tt>}");
00439   buff=TexMacroSubstitute1(buff,"\\textit","\\text{<i>#1</i>}");
00440   buff=TexSpacing(buff);
00441   // super- and subscripts
00442   buff=TexScripts(buff);
00443   // symbols
00444   buff=StringSubstitute(buff,"\\{","{");
00445   buff=StringSubstitute(buff,"\\}","}");
00446   buff=StringSubstitute(buff,"\\[","[");
00447   buff=StringSubstitute(buff,"\\]","]");
00448   buff=StringSubstitute(buff,"=","&nbsp;=&nbsp;");
00449   buff=StringSubstitute(buff,"class&nbsp;=&nbsp;","class=");     // fix csss class
00450   buff=StringSubstitute(buff,":&nbsp;=&nbsp;","&nbsp;:=&nbsp;"); //fix :=
00451   buff=StringSubstitute(buff,"\\neq","&nbsp&ne;&nbsp;");
00452   buff=StringSubstitute(buff,"\\lt","&nbsp;&lt;&nbsp;");
00453   buff=StringSubstitute(buff,"\\gt","&nbsp;&gt;&nbsp;");
00454   buff=StringSubstitute(buff,"\\le","&nbsp;&le;&nbsp;");
00455   buff=StringSubstitute(buff,"\\ge","&nbsp;&ge;&nbsp;");
00456   buff=StringSubstitute(buff,"\\emptyset","0");
00457   buff=StringSubstitute(buff,"\\times","&nbsp;x&nbsp;");
00458   buff=StringSubstitute(buff,"\\ldots","...");
00459   buff=StringSubstitute(buff,"\\cdots","...");
00460   buff=StringSubstitute(buff,"\\cdot",".");
00461   buff=StringSubstitute(buff,"\\infty","&infin;");
00462   buff=StringSubstitute(buff,"\\nin","&nbsp;&notin;&nbsp;");
00463   buff=StringSubstitute(buff,"\\not\\in","&nbsp;&notin;&nbsp;");
00464   buff=StringSubstitute(buff,"\\in","&nbsp;&isin;&nbsp;");
00465   buff=StringSubstitute(buff,"\\subseteq","&nbsp;&sube;&nbsp;");
00466   buff=StringSubstitute(buff,"\\subset","&nbsp;&sub;&nbsp;");
00467   buff=StringSubstitute(buff,"\\supseteq","&nbsp;&supe;&nbsp;");
00468   buff=StringSubstitute(buff,"\\supset","&nbsp;&sup;&nbsp;");
00469   buff=StringSubstitute(buff,"\\cup","&cup;");
00470   buff=StringSubstitute(buff,"\\dcup","&cup;"); // should be "&cup;&#775;" for "dot above"
00471   buff=StringSubstitute(buff,"\\cap","&cap;");
00472   buff=StringSubstitute(buff,"\\sup","sup");
00473   buff=StringSubstitute(buff,"\\inf","inf");
00474   buff=StringSubstitute(buff,"\\max","max");
00475   buff=StringSubstitute(buff,"\\min","min");
00476   buff=StringSubstitute(buff,"\\parallel","||");
00477   buff=StringSubstitute(buff,"\\forall","&forall;&nbsp;");
00478   buff=StringSubstitute(buff,"\\exists","&exist;&nbsp;");
00479   buff=StringSubstitute(buff,"\\leftarrow","&larr;");
00480   buff=StringSubstitute(buff,"\\rightarrow","&rarr;");
00481   buff=StringSubstitute(buff,"\\leftrightarrow","&harr;");
00482   buff=StringSubstitute(buff,"\\Leftarrow","&lArr;");
00483   buff=StringSubstitute(buff,"\\Rightarrow","&rArr;");
00484   buff=StringSubstitute(buff,"\\Leftrightarrow","&hArr;");
00485   buff=StringSubstitute(buff,"\\uparrow","&uarr;");
00486   buff=StringSubstitute(buff,"\\downarrow","&darr;");
00487   // ie7 fallback symbols
00488   buff=StringSubstitute(buff,"&isin;","<span class=\"faudes_fmath\">&isin;</span>"); 
00489   buff=StringSubstitute(buff,"&notin;","<span class=\"faudes_fmath\">&notin;</span>"); 
00490   buff=StringSubstitute(buff,"&exist;","<span class=\"faudes_fmath\">&exist;</span>"); 
00491   buff=StringSubstitute(buff,"&forall;","<span class=\"faudes_fmath\">&forall;</span>"); 
00492   buff=StringSubstitute(buff,"&cup;","<span class=\"faudes_fmath\">&cup;</span>"); 
00493   buff=StringSubstitute(buff,"&dcup;","<span class=\"faudes_fmath\">&cup;</span>"); // see above
00494   buff=StringSubstitute(buff,"&cap;","<span class=\"faudes_fmath\">&cap;</span>"); 
00495   buff=StringSubstitute(buff,"&larr;","<span class=\"faudes_fmath\">&larr;</span>"); 
00496   buff=StringSubstitute(buff,"&rarr;","<span class=\"faudes_fmath\">&rarr;</span>"); 
00497   buff=StringSubstitute(buff,"&harr;","<span class=\"faudes_fmath\">&harr;</span>"); 
00498   buff=StringSubstitute(buff,"&lArr;","<span class=\"faudes_fmath\">&lArr;</span>"); 
00499   buff=StringSubstitute(buff,"&rArr;","<span class=\"faudes_fmath\">&rArr;</span>"); 
00500   buff=StringSubstitute(buff,"&hArr;","<span class=\"faudes_fmath\">&hArr;</span>"); 
00501   buff=StringSubstitute(buff,"&sub;","<span class=\"faudes_fmath\">&sub;</span>"); 
00502   buff=StringSubstitute(buff,"&sube;","<span class=\"faudes_fmath\">&sube;</span>"); 
00503   buff=StringSubstitute(buff,"&sup;","<span class=\"faudes_fmath\">&sup;</span>"); 
00504   buff=StringSubstitute(buff,"&supe;","<span class=\"faudes_fmath\">&supe;</span>"); 
00505   // done
00506   *pStream << buff;
00507 }
00508 
00509 // ******************************************************************
00510 // record pages
00511 // ******************************************************************
00512 
00513 // record
00514 class PageRecord {
00515 public:
00516   std::string mTitle;
00517   std::string mChapter;
00518   std::string mSection;
00519   std::string mPage;
00520   std::string mLink;
00521 };
00522 
00523 // data
00524 std::vector<PageRecord> mPages;
00525 
00526 // extract page data
00527 void RecordPages(TokenReader& rTr) {
00528   // record my level
00529   int clevel = rTr.Level();
00530   // std::cerr << "process level " << clevel << "\n";
00531   // token loop
00532   while(true) {
00533     // skip plain text
00534     std::string text=rTr.ReadCharacterData();
00535     if(text.size()>0) continue;
00536     // break on no token or end of my level
00537     Token token;
00538     if(!rTr.Peek(token)) break;
00539     if(token.IsEnd() && !token.IsBegin() && rTr.Level()==clevel) 
00540       break;
00541     // get token, ignore irrelevant
00542     rTr.Get(token);
00543     if(!token.IsBegin("ReferencePage")) continue;
00544     // extract page data      
00545     mFrefChapter="";
00546     if(token.ExistsAttributeString("chapter")) 
00547       mFrefChapter=token.AttributeStringValue("chapter");
00548     mFrefSection="";
00549     if(token.ExistsAttributeString("section")) 
00550       mFrefSection=token.AttributeStringValue("section");
00551     mFrefPage="";
00552     if(token.ExistsAttributeString("page")) 
00553       mFrefPage=token.AttributeStringValue("page");
00554     mFrefTitle="";
00555     if(token.ExistsAttributeString("title")) 
00556       mFrefTitle=token.AttributeStringValue("title");
00557     mFrefLink=ExtractBasename(rTr.FileName())+".html";;
00558     if(token.ExistsAttributeString("link")) 
00559       mFrefLink=token.AttributeStringValue("link");
00560     // report
00561     // std::cerr << "ref2html: found chapter \"" << mFrefChapter << "\" section \"" << mFrefSection << "\"" << std::endl;
00562     // record
00563     PageRecord pagerec;
00564     pagerec.mChapter = mFrefChapter;
00565     pagerec.mSection = mFrefSection;
00566     pagerec.mPage = mFrefPage;
00567     pagerec.mTitle = mFrefTitle;
00568     pagerec.mLink = mFrefLink;
00569     // normalize
00570     std::transform(mFrefChapter.begin(), mFrefChapter.end(), mFrefChapter.begin(), tolower);
00571     std::transform(mFrefSection.begin(), mFrefSection.end(), mFrefSection.begin(), tolower);
00572     // insert entry
00573     if(mFrefChapter!="")
00574     if(mFrefChapter!="none")
00575       mPages.push_back(pagerec);
00576   }
00577 }
00578 
00579 
00580 // dump page records to include file
00581 void DumpPages(TokenWriter& rTw) {
00582   // loop records
00583   std::vector<PageRecord>::iterator pit;
00584   for(pit=mPages.begin(); pit!=mPages.end(); pit++) {
00585     Token btag;
00586     btag.SetEmpty("ReferencePage");
00587     btag.InsAttributeString("title",pit->mTitle);
00588     btag.InsAttributeString("chapter",pit->mChapter);
00589     btag.InsAttributeString("section",pit->mSection);
00590     btag.InsAttributeString("page",pit->mPage);
00591     btag.InsAttributeString("link",pit->mLink);
00592     rTw << btag << "\n";
00593   }
00594 }
00595 
00596 
00597 // ******************************************************************
00598 // search for types
00599 // ******************************************************************
00600 
00601 void ListTypesHtml(std::ostream* pIndexFile, const std::string& key="") {
00602 
00603   // table output 
00604   *pIndexFile << "<table class=\"plain\">" << std::endl;
00605   // traverse type registry
00606   bool found=false;
00607   for(TypeRegistry::Iterator tit=TypeRegistry::G()->Begin(); 
00608     tit!=TypeRegistry::G()->End(); tit++) {
00609     // test for exact key
00610     if(key!="") {
00611       std::string section= tit->second->Name();
00612       std::transform(section.begin(), section.end(), section.begin(), tolower);
00613       if(section!=key) continue;
00614     }
00615     // test for user doc
00616     if(tit->second->TextDoc()=="") continue;
00617     // table row
00618     *pIndexFile << "<tr><td valign=\"top\">";
00619     TypeHtml(pIndexFile,tit->second->Name());
00620     *pIndexFile << "</td><td valign=\"top\">";
00621     TypeHtml(pIndexFile,tit->second->TextDoc());
00622     *pIndexFile << "</td><tr>" << std::endl;
00623     // record success
00624     found=true;
00625   }
00626   // no matches
00627   if(!found) *pIndexFile << "<td><i>no matches found</i></td>" << std::endl;
00628   // table output 
00629   *pIndexFile << "</table>" << std::endl;
00630 }
00631 
00632 // ******************************************************************
00633 // search for functions
00634 // ******************************************************************
00635 
00636 void ListFunctionsHtml(std::ostream* pIndexFile, const std::string& key="") {
00637 
00638   // table output 
00639   *pIndexFile << "<table class=\"plain\">" << std::endl;
00640   // traverse function registry
00641   bool found=false;
00642   for(FunctionRegistry::Iterator fit=FunctionRegistry::G()->Begin(); 
00643     fit!=FunctionRegistry::G()->End(); fit++) {
00644     // test for exact key
00645     if(key!="") {
00646       std::string section= fit->second->Name();
00647       std::transform(section.begin(), section.end(), section.begin(), tolower);
00648       if(section!=key) continue;
00649     }
00650     // test for user doc
00651     if(fit->second->TextDoc()=="") continue;
00652     // table row
00653     *pIndexFile << "<tr><td valign=\"top\">";
00654     FunctionHtml(pIndexFile,fit->second->Name());
00655     *pIndexFile << "</td><td valign=\"top\">";
00656     TypeHtml(pIndexFile,fit->second->TextDoc());
00657     *pIndexFile << "</td><tr>" << std::endl;
00658     // record success
00659     found=true;
00660   }
00661   // no matches
00662   if(!found) *pIndexFile << "<td><i>no matches found</i></td>" << std::endl;
00663   // table output 
00664   *pIndexFile << "</table>" << std::endl;
00665 }
00666 
00667 // ******************************************************************
00668 // search for sections
00669 // ******************************************************************
00670 
00671 void ListSectionsHtml(std::ostream* pIndexFile, const std::string& key="") {
00672 
00673   // prepare list of all sections
00674   std::set< std::string > sections;
00675   for(TypeRegistry::Iterator tit=TypeRegistry::G()->Begin(); 
00676       tit!=TypeRegistry::G()->End(); tit++) {
00677     std::string section= tit->second->KeywordAt(0);
00678     // bail out on trivial
00679     if(section=="") continue;
00680     // test for exact key
00681     if(key!="") {
00682       std::transform(section.begin(), section.end(), section.begin(), tolower);
00683       if(section!=key) continue;
00684     }
00685     // record
00686     sections.insert(tit->second->KeywordAt(0));
00687   }
00688   for(FunctionRegistry::Iterator fit=FunctionRegistry::G()->Begin(); 
00689       fit!=FunctionRegistry::G()->End(); fit++) {
00690     std::string section=fit->second->KeywordAt(0);
00691     // bail out on trivial
00692     if(section=="") continue;
00693     // test for exact key
00694     if(key!="") {
00695       std::transform(section.begin(), section.end(), section.begin(), tolower);
00696       if(section!=key) continue;
00697     }
00698     // record
00699     sections.insert(fit->second->KeywordAt(0));
00700   }
00701 
00702   // list sections as links
00703   std::set< std::string >::iterator pit;
00704   for(pit=sections.begin(); pit != sections.end(); pit++) {
00705     // get nice name
00706     std::string sname = *pit;
00707     // have link
00708     std::string shtml = sname+"_index.html";
00709     std::transform(shtml.begin(),shtml.end(),shtml.begin(),tolower);
00710     // have entry as link
00711     if(pit!=sections.begin()) *pIndexFile << "," << std::endl;
00712     *pIndexFile << "<a href=\"" << shtml << "\">" << sname << "</a>";
00713   }
00714 }
00715 
00716 
00717 
00718 
00719 // ******************************************************************
00720 // type index by keyword (aka section name)
00721 // ******************************************************************
00722 
00723 void TypeIndexHtml(std::ostream* pIndexFile, const std::string& key="") {
00724 
00725   // traverse type registry
00726   bool head=false;
00727   for(TypeRegistry::Iterator tit=TypeRegistry::G()->Begin(); 
00728     tit!=TypeRegistry::G()->End(); tit++) 
00729   {
00730     // test for exact key
00731     if(key!="") {
00732       std::string section= tit->second->KeywordAt(0);
00733       std::transform(section.begin(), section.end(), section.begin(), tolower);
00734       if(section!=key) continue;
00735     }
00736     // test for user doc
00737     if(tit->second->TextDoc()=="") continue;
00738     // head line
00739     if(!head) {
00740       head=true;
00741       *pIndexFile << "<div class=\"registry_heading\"><strong>Types</strong></div>" << std::endl;
00742     }
00743     // index entry for this type
00744     *pIndexFile << "<div class=\"registry_index\">";
00745     TypeHtml(pIndexFile,tit->second->Name());
00746     *pIndexFile << "</div>" << std::endl;
00747   }
00748   // done
00749   if(head) *pIndexFile << "<br>" << std::endl;
00750 }
00751 
00752 // ******************************************************************
00753 // function index by keyword (aka plugin)
00754 // ******************************************************************
00755 
00756 void FunctionIndexHtml(std::ostream* pIndexFile, const std::string& key="") {
00757 
00758   // have lower case key
00759   std::string lkey=key;
00760   std::transform(lkey.begin(), lkey.end(), lkey.begin(), tolower);
00761   
00762   // traverse function registry
00763   bool head=false;
00764   for(FunctionRegistry::Iterator fit=FunctionRegistry::G()->Begin(); 
00765     fit!=FunctionRegistry::G()->End(); fit++) 
00766   {
00767     // test for key
00768     if(lkey!="") {
00769       std::string section= fit->second->KeywordAt(0);
00770       std::transform(section.begin(), section.end(), section.begin(), tolower);
00771       if(section!=lkey) continue;
00772     }
00773     // test for user doc
00774     if(fit->second->TextDoc()=="") continue;
00775     // index entry for this function
00776     std::string fname = fit->second->Name();
00777     std::string fhtml = fit->second->HtmlDoc();
00778     if(fhtml=="") continue;
00779     // head line
00780     if(!head){
00781       head=true;
00782       *pIndexFile << "<div class=\"registry_heading\"><strong>Functions</strong></div>" << std::endl;
00783     }
00784     // list entry
00785     if(fhtml=="none") {
00786       *pIndexFile << "<div class=\"registry_index\"> "<< fhtml << "</div>" << std::endl;
00787       continue;
00788     }
00789     *pIndexFile << "<div class=\"registry_index\"><a href=\"" << fhtml << "\">" 
00790       << fname << "</a></div>" << std::endl;
00791   }
00792 
00793   // done
00794   if(head) *pIndexFile << "<br>" << std::endl;
00795 
00796 }
00797 
00798 // ******************************************************************
00799 // reference index by keyword (aka section)
00800 // ******************************************************************
00801 
00802 void ReferenceIndexHtml(std::ostream* pIndexFile, const std::string& key="") {
00803 
00804   // prepare list of all sections
00805   std::map< std::string , std::string > sections;
00806   std::vector< PageRecord >::iterator pit;
00807   for(pit=mPages.begin(); pit != mPages.end(); pit++) {
00808     std::string chap=pit->mChapter;
00809     std::transform(chap.begin(), chap.end(), chap.begin(), tolower);
00810     std::string sect=pit->mSection;
00811     std::transform(sect.begin(), sect.end(), sect.begin(), tolower);
00812     // my chapter only
00813     if(chap!="reference") continue;
00814     if(sect=="none") continue;
00815     if(sect=="") continue;
00816     // get nice name
00817     std::string pname = pit->mSection;
00818     // have link
00819     std::string phtml = sect+"_index.html";
00820     // record
00821     sections[pname]=phtml;
00822   }
00823 
00824   // sections headline
00825   if(sections.size()!=0) 
00826     *pIndexFile << "<div class=\"registry_heading\"><strong>Sections</strong></div>" << std::endl;
00827 
00828   // produce sorted index, have corefaudes first
00829   if(sections["CoreFaudes"]!="")
00830     *pIndexFile << "<div class=\"registry_index\"><a href=\"" << sections["CoreFaudes"] << "\">CoreFaudes</a></div>" << std::endl;
00831   sections["CoreFaudes"]="";
00832   std::map< std::string , std::string >::iterator sit;
00833   for(sit=sections.begin(); sit!=sections.end(); sit++) {
00834     if(sit->second=="") continue;
00835     // have entry
00836     *pIndexFile << "<div class=\"registry_index\"><a href=\"" << sit->second << "\">" 
00837       << sit->first << "</a></div>" << std::endl;
00838   }
00839   
00840 
00841   // sections done
00842   if(sections.size()!=0) 
00843     *pIndexFile << "<br>" << std::endl;
00844 
00845   // list types
00846   if(key!="") TypeIndexHtml(pIndexFile,key);
00847 
00848   // list functions
00849   if(key!="") FunctionIndexHtml(pIndexFile,key);
00850 }
00851 
00852 // ******************************************************************
00853 // signature
00854 // ******************************************************************
00855 
00856 void SignatureHtml(std::ostream* pOutFile, std::string function) {
00857 
00858   // bail out on non existence
00859   if(!FunctionRegistry::G()->Exists(function)) return;
00860 
00861   // function definition
00862   const FunctionDefinition& fdef=FunctionRegistry::G()->Definition(function);
00863   
00864   // bail out if there is no signature
00865   if(fdef.VariantsSize()==0) return;
00866 
00867   // start signature box
00868   *pOutFile << "<div class=\"registry_signature\">" << std::endl;
00869   *pOutFile << "<p><strong>Signature:</strong></p>" << std::endl;
00870   *pOutFile << "<p>" << std::endl;
00871 
00872   // loop signatures
00873   for(int i=0; i< fdef.VariantsSize(); i++) {
00874     const Signature& sigi=fdef.Variant(i);
00875     *pOutFile << fdef.Name() << "(";
00876     // loop params
00877     for(int j=0; j < sigi.Size(); j++) {
00878       if(j!=0) *pOutFile << ", ";
00879       const Parameter& parj=sigi.At(j);
00880       *pOutFile << "+" << Parameter::AStr(parj.Attribute()) << "+ ";
00881       TypeHtml(pOutFile,parj.Type());
00882       *pOutFile << " <i>" << parj.Name() << "</i>";
00883     }
00884     *pOutFile << ")<br>" << std::endl;
00885   }
00886   *pOutFile << "</p>" << std::endl;
00887 
00888 
00889   // close signature box
00890   *pOutFile << std::endl << "</div>" << std::endl;
00891 }
00892 
00893 // ******************************************************************
00894 // short doc
00895 // ******************************************************************
00896 
00897 void ShortdocHtml(std::ostream* pOutFile, std::string fname) {
00898 
00899   // its a function
00900   if(FunctionRegistry::G()->Exists(fname)) {
00901 
00902     // function definition
00903     const FunctionDefinition& fdef=FunctionRegistry::G()->Definition(fname);
00904   
00905     // stream doc
00906     *pOutFile << "<div class=\"registry_signature\">" << std::endl;
00907     *pOutFile << "<p>" << fdef.TextDoc() << "</p>" << std::endl;
00908     *pOutFile << "</div>" << std::endl;
00909 
00910     // stream signature
00911     SignatureHtml(pOutFile,fname);
00912   }
00913 
00914   // its a type
00915   if(TypeRegistry::G()->Exists(fname)) {
00916 
00917     // type definition
00918     const TypeDefinition& tdef=TypeRegistry::G()->Definition(fname);
00919   
00920     // stream doc
00921     *pOutFile << "<div class=\"registry_signature\">" << std::endl;
00922     *pOutFile << "<p>" << tdef.TextDoc() << "<p>" << std::endl;
00923     *pOutFile << "</div>" << std::endl;
00924 
00925   }
00926 
00927 }
00928 
00929 
00930 
00931 
00932 // ******************************************************************
00933 // record literature
00934 // ******************************************************************
00935 
00936 // record
00937 class LiteratureRecord {
00938 public:
00939   std::string mLabel;
00940   std::string mLink;
00941   std::string mAuthors;
00942   std::string mTitle;
00943   std::string mJournal;
00944   std::string mPublisher;
00945   std::string mYear;
00946 };
00947 
00948 // data
00949 std::map<std::string,LiteratureRecord> mLiterature;
00950 
00951 // extract all from a section
00952 void RecordLiterature(TokenReader& rTr) {
00953   // record my level
00954   int clevel = rTr.Level();
00955   // std::cerr << "process level " << clevel << "\n";
00956   // token loop
00957   while(true) {
00958     // skip plain text
00959     std::string text=rTr.ReadCharacterData();
00960     if(text.size()>0) continue;
00961     // break on no token or end of my level
00962     Token token;
00963     if(!rTr.Peek(token)) break;
00964     if(token.IsEnd() && !token.IsBegin() && rTr.Level()==clevel) 
00965       break;
00966     // track where we are
00967     if(token.IsBegin("ReferencePage")) {
00968       mFrefChapter="";
00969       if(token.ExistsAttributeString("chapter")) 
00970         mFrefChapter=token.AttributeStringValue("chapter");
00971       mFrefSection="";
00972       if(token.ExistsAttributeString("section")) 
00973         mFrefSection=token.AttributeStringValue("section");
00974       std::transform(mFrefChapter.begin(), mFrefChapter.end(), mFrefChapter.begin(), tolower);
00975       std::transform(mFrefSection.begin(), mFrefSection.end(), mFrefSection.begin(), tolower);
00976      // report
00977      // std::cerr << "ref2html: found chapter \"" << mFrefChapter << "\" section \"" << mFrefSection << "\"" << std::endl;
00978     }
00979     // ignore other tokens
00980     if(!token.IsBegin("fliterature")) {
00981       rTr.Get(token);
00982       continue;
00983     }
00984     // do my special tag: fliterature
00985     rTr.ReadBegin("fliterature");
00986     std::string label=token.AttributeStringValue("name");
00987     //std::cerr << "process literature " << label << "\n";
00988     LiteratureRecord litrec;
00989     litrec.mLabel=label;
00990     litrec.mLink = mFrefSection + "_index.html#lit_" + label;
00991     //process entries
00992     while(!rTr.Eos("fliterature")) {
00993       Token token;
00994       rTr.Peek(token);
00995       //std::cerr << "process literature peek " << token.Str() << "\n";
00996       if(token.IsBegin("fauthors")) {
00997         rTr.ReadBegin("fauthors");
00998         litrec.mAuthors=rTr.ReadSection();
00999         rTr.ReadEnd("fauthors");
01000         continue;
01001       }
01002       if(token.IsBegin("ftitle")) {
01003         rTr.ReadBegin("ftitle");
01004         litrec.mTitle=rTr.ReadSection();
01005         rTr.ReadEnd("ftitle");
01006         continue;
01007       }
01008       if(token.IsBegin("fjournal")) {
01009         rTr.ReadBegin("fjournal");
01010         litrec.mJournal=rTr.ReadSection();
01011         rTr.ReadEnd("fjournal");
01012         continue;
01013       }
01014       if(token.IsBegin("fyear")) {
01015         rTr.ReadBegin("fyear");
01016         litrec.mYear=rTr.ReadSection();
01017         rTr.ReadEnd("fyear");
01018         continue;
01019       }
01020       if(token.IsBegin("flink")) {
01021         rTr.ReadBegin("flink");
01022         litrec.mLink=rTr.ReadSection();
01023         rTr.ReadEnd("flink");
01024         continue;
01025       }
01026       if(token.IsBegin()) {
01027         rTr.ReadBegin(token.StringValue());
01028         rTr.ReadEnd(token.StringValue());
01029         continue;
01030       }
01031       rTr.Get(token);
01032     }
01033     // insert entry
01034     if(litrec.mLabel!="")
01035       mLiterature[litrec.mLabel]=litrec;
01036     // done
01037     rTr.ReadEnd("fliterature");
01038   }
01039 }
01040 
01041 
01042 // dump literature records to include file
01043 void DumpLiterature(TokenWriter& rTw) {
01044   // loop records
01045   std::map<std::string,LiteratureRecord>::iterator lit;
01046   for(lit=mLiterature.begin(); lit!=mLiterature.end(); lit++) {
01047     Token btag;
01048     btag.SetBegin("fliterature");
01049     btag.InsAttributeString("name",lit->second.mLabel);
01050     rTw << btag << "\n";
01051     if(lit->second.mAuthors!="") {
01052       rTw.WriteBegin("fauthors");
01053       rTw.WriteCharacterData(lit->second.mAuthors); 
01054       rTw.WriteEnd("fauthors");
01055       rTw <<"\n";
01056     }
01057     if(lit->second.mTitle!="") {
01058       rTw.WriteBegin("ftitle");
01059       rTw.WriteCharacterData(lit->second.mTitle); 
01060       rTw.WriteEnd("ftitle");
01061       rTw <<"\n";
01062     }
01063     if(lit->second.mJournal!="") {
01064       rTw.WriteBegin("fjournal");
01065       rTw.WriteCharacterData(lit->second.mJournal); 
01066       rTw.WriteEnd("fjournal");
01067       rTw <<"\n";
01068     }
01069     if(lit->second.mPublisher!="") {
01070       rTw.WriteBegin("fpublisher");
01071       rTw.WriteCharacterData(lit->second.mPublisher); 
01072       rTw.WriteEnd("fpublisher");
01073       rTw <<"\n";
01074     }
01075     if(lit->second.mYear!="") {
01076       rTw.WriteBegin("fyear");
01077       rTw.WriteCharacterData(lit->second.mYear); 
01078       rTw.WriteEnd("fyear");
01079       rTw <<"\n";
01080     }
01081     if(lit->second.mLink!="") {
01082       rTw.WriteBegin("flink");
01083       rTw.WriteCharacterData(lit->second.mLink); 
01084       rTw.WriteEnd("flink");
01085       rTw <<"\n";
01086     }
01087     rTw.WriteEnd("fliterature"); rTw <<"\n";
01088     rTw.Endl();
01089   }
01090 }
01091 
01092 
01093 // html for (one) literature reference
01094 void LiteratureHtml(std::ostream* pStream, const std::string& rLabel="") {
01095   // loop records
01096   std::map<std::string,LiteratureRecord>::iterator lit;
01097   for(lit=mLiterature.begin(); lit!=mLiterature.end(); lit++) {
01098     // skip for no match
01099     if(rLabel!="")
01100     if(rLabel!=lit->second.mLabel) continue;
01101     // produce html
01102     *pStream << "<p>" << std::endl;
01103     *pStream << "<a id=\"" << "lit_" << lit->second.mLabel << "\">[" << lit->second.mLabel << "]</a>" << std::endl;
01104     *pStream << lit->second.mAuthors << ": ";
01105     *pStream << "<i>" << lit->second.mTitle << "</i>";
01106     if(lit->second.mJournal!="")   *pStream << ", " << lit->second.mJournal;
01107     if(lit->second.mPublisher!="") *pStream << ", " << lit->second.mPublisher;
01108     if(lit->second.mYear!="")      *pStream << ", " << lit->second.mYear;
01109     *pStream << ".</p>" << std::endl;
01110   }
01111 }
01112 
01113 
01114 // html for literature cittion
01115 void CiteHtml(std::ostream* pStream, const std::string& rLabel) {
01116   // prepare
01117   std::string link="reference_index.html#literature";
01118   // find records
01119   std::map<std::string,LiteratureRecord>::iterator lit;
01120   lit=mLiterature.find(rLabel);
01121   if(lit!=mLiterature.end()) link=lit->second.mLink;
01122   // produce HTML
01123   *pStream << "<a href=\"" << link << "\">[" << rLabel << "]</a>";
01124 }
01125 
01126 
01127 // ******************************************************************
01128 // extract pages
01129 // ******************************************************************
01130 
01131 void  XtractPages(TokenReader& src,const std::string& rDstDir) {
01132 
01133   // scan for reference page sections
01134   Token btag;
01135   while(src.Peek(btag)) {
01136     // skip tokens
01137     if(!btag.IsBegin("ReferencePage")) {
01138       src.Get(btag);
01139       continue;
01140     }
01141     // read begin tag
01142     src.ReadBegin("ReferencePage",btag);
01143     // extract title & friends
01144     mFrefTitle="libFAUDES Reference";
01145     if(btag.ExistsAttributeString("title")) 
01146       mFrefTitle=btag.AttributeStringValue("title");
01147     mFrefChapter="Reference";
01148     if(btag.ExistsAttributeString("chapter")) 
01149       mFrefChapter=btag.AttributeStringValue("chapter");
01150     mFrefSection="";
01151     if(btag.ExistsAttributeString("section")) 
01152       mFrefSection=btag.AttributeStringValue("section");
01153     mFrefPage="";
01154     if(btag.ExistsAttributeString("page")) 
01155       mFrefPage=btag.AttributeStringValue("page");
01156     // insist in page and section
01157     if(mFrefSection=="" || mFrefPage=="") {
01158       std::cerr << "ref2html: skipping undefined page at " << src.FileLine() << std::endl;
01159       src.ReadEnd("ReferencePage");
01160       continue;
01161     } 
01162     // normalize & report 
01163     std::transform(mFrefChapter.begin(), mFrefChapter.end(), mFrefChapter.begin(), tolower);
01164     std::transform(mFrefSection.begin(), mFrefSection.end(), mFrefSection.begin(), tolower);
01165     std::transform(mFrefPage.begin(), mFrefPage.end(), mFrefPage.begin(), tolower);
01166     // dst file
01167     std::string dstfile=rDstDir + DirSeparator() + mFrefSection + "_" + mFrefPage +".fref";
01168     std::cerr << "ref2html: extracting page to \"" << dstfile << "\"" << std::endl;
01169     TokenWriter dst(dstfile);
01170     // copy section
01171     dst.Write(btag);
01172     std::string scttext = src.ReadSection();
01173     dst.WriteCharacterData(scttext);
01174     dst.WriteEnd("ReferencePage");    
01175     // read end tag
01176     src.ReadEnd("ReferencePage");
01177   }  
01178 }
01179 
01180 // ******************************************************************
01181 // extract files
01182 // ******************************************************************
01183 
01184 void  XtractFiles(TokenReader& src,const std::string& rDstDir) {
01185 
01186   // scan for file  sections
01187   Token btag;
01188   while(src.Peek(btag)) {
01189     // skip tokens
01190     if(!btag.IsBegin("ImageFile")) {
01191       src.Get(btag);
01192       continue;
01193     }
01194     // read begin tag
01195     src.ReadBegin("ImageFile",btag);
01196     std::string name=btag.AttributeStringValue("name");
01197     if(name==""){
01198       std::cerr << "ref2html: skipping undefined image file at " << src.FileLine() << std::endl;
01199       src.ReadEnd("ImageFile");
01200       continue;
01201     } 
01202     // read data
01203     Token data;
01204     src.Get(data);
01205     if(!data.IsBinary()){
01206       std::cerr << "ref2html: skipping invalid image file at " << src.FileLine() << std::endl;
01207       src.ReadEnd("ImageFile");
01208       continue;
01209     } 
01210     // dst file
01211     std::string dstfile=rDstDir + DirSeparator() + "faudes_images" + 
01212       DirSeparator() + name;
01213     std::transform(dstfile.begin(), dstfile.end(), dstfile.begin(), tolower);
01214     std::cerr << "ref2html: extracting image file to \"" << dstfile << "\"" << std::endl;
01215     // setup stream
01216     std::fstream fsout;
01217     fsout.exceptions(std::ios::badbit|std::ios::failbit);
01218     try{
01219       fsout.open(dstfile.c_str(), std::ios::out | std::ios::binary); 
01220       fsout.write(data.StringValue().c_str(),data.StringValue().size());
01221       fsout.close();
01222     } 
01223     catch (std::ios::failure&) {
01224       std::cerr << "ref2html: file io error when writing  \"" << dstfile << "\"" << std::endl;
01225     }
01226     // read end tag
01227     src.ReadEnd("ImageFile");
01228   }  
01229 }
01230 
01231 // ******************************************************************
01232 // luafaudes index 
01233 // ******************************************************************
01234 
01235 void LuafaudesIndexHtml(std::ostream* pIndexFile) {
01236 
01237   // prepare list of all sections
01238   std::map< std::string , std::string > pages;
01239   std::vector< PageRecord >::iterator pit;
01240   for(pit=mPages.begin(); pit != mPages.end(); pit++) {
01241     // my chapter only
01242     if(pit->mChapter!="luafaudes") continue;
01243     if(pit->mSection=="none") continue;
01244     if(pit->mSection=="") continue;
01245     if(pit->mPage=="") continue;
01246     // get nice name
01247     std::string pname = pit->mPage;
01248     // have link
01249     std::string phtml = pit->mLink;
01250     // record
01251     pages[pname]=phtml;
01252   }
01253   // produce sorted index
01254   std::map< std::string , std::string >::iterator sit;
01255   for(sit=pages.begin(); sit!=pages.end(); sit++) {
01256     // have entry
01257     *pIndexFile << "<div class=\"registry_index\"><a href=\"" << sit->second << "\">" 
01258       << sit->first << "</a></div>" << std::endl;
01259   }
01260   // empty
01261   if(pages.size()==0) {
01262     *pIndexFile << "<div class=\"registry_index\">" << "none" << "</div>" << std::endl;
01263   }
01264 }
01265 
01266 // ******************************************************************
01267 // process current section
01268 // ******************************************************************
01269 
01270 void ProcessSection(TokenWriter& rTw, TokenReader& rTr) {
01271 
01272   // record my level
01273   int clevel = rTr.Level();
01274 
01275   // std::cerr << "process level " << clevel << "\n";
01276 
01277   // token copy loop
01278   while(true) {
01279     // see whether we can grab and copy some plain text
01280     std::string text=rTr.ReadCharacterData();
01281     if(text.size()>0) {
01282       //std::cerr << "copy text \"" << text << "\"\n";
01283       *rTw.Streamp() << text;
01284       continue;
01285     }
01286     // break on no token or end of my level
01287     Token token;
01288     if(!rTr.Peek(token)) break;
01289     if(token.IsEnd() && !token.IsBegin() && rTr.Level()==clevel) 
01290       break;
01291     // do my special tags: ftype
01292     if(token.IsBegin("ftype")) {
01293   rTr.ReadBegin("ftype");
01294         std::string ftype=rTr.ReadText();
01295         TypeHtml(rTw.Streamp(),ftype);
01296   rTr.ReadEnd("ftype");
01297   continue;
01298     }
01299     // do my special tags: ffnct
01300     if(token.IsBegin("ffnct")) {
01301   rTr.ReadBegin("ffnct");
01302         std::string ffnct=rTr.ReadText();
01303         FunctionHtml(rTw.Streamp(),ffnct);
01304   rTr.ReadEnd("ffnct");
01305   continue;
01306     }
01307     // do my special tags: fimage
01308     if(token.IsBegin("fimage")) {
01309         rTr.ReadBegin("fimage", token);
01310         std::string fsrc=token.AttributeStringValue("fsrc");
01311         ImageHtml(rTw.Streamp(),fsrc);
01312   rTr.ReadEnd("fimage");
01313   continue;
01314     }
01315     // do my special tags: dmath
01316     if(token.IsBegin("fdmath")) {
01317         rTr.ReadBegin("fdmath", token);
01318         std::string mtext=rTr.ReadCharacterData();
01319         *rTw.Streamp()<< "<span class=\"faudes_dmath\">";
01320         MathHtml(rTw.Streamp(),mtext);
01321         *rTw.Streamp()<< "</span>";
01322   rTr.ReadEnd("fdmath");
01323   continue;
01324     }
01325     // do my special tags: dmath
01326     if(token.IsBegin("fimath")) {
01327         rTr.ReadBegin("fimath", token);
01328         std::string mtext=rTr.ReadCharacterData();
01329         *rTw.Streamp()<< "<span class=\"faudes_imath\">";
01330         MathHtml(rTw.Streamp(),mtext);
01331         *rTw.Streamp()<< "</span>";
01332   rTr.ReadEnd("fimath");
01333   continue;
01334     }
01335     // do my special tags: ffnct_reference
01336     if(token.IsBegin("ffnct_reference")) {
01337         rTr.ReadBegin("ffnct_reference", token);
01338         std::string ffnct = token.AttributeStringValue("name");
01339         *rTw.Streamp() << "<div class=\"registry_function\"> <h2>" 
01340      << "<a id=\"" << ffnct << "\">" << ffnct << "</a></h2>" << std::endl;
01341         ShortdocHtml(rTw.Streamp(),ffnct);
01342         ProcessSection(rTw,rTr);
01343         *rTw.Streamp() << "</div>" << std::endl;
01344   rTr.ReadEnd("ffnct_reference");
01345   continue;
01346     }
01347     // do my special tags: ftype_reference
01348     if(token.IsBegin("ftype_reference")) {
01349         rTr.ReadBegin("ftype_reference", token);
01350         std::string ffnct = token.AttributeStringValue("name");
01351         *rTw.Streamp() << "<div class=\"registry_type\"> <h2>" 
01352      << "<a id=\"" << ffnct << "\">" << ffnct << "</a></h2>" << std::endl;
01353         ShortdocHtml(rTw.Streamp(),ffnct);
01354         ProcessSection(rTw,rTr);
01355         *rTw.Streamp() << "</div>" << std::endl;
01356   rTr.ReadEnd("ftype_reference");
01357   continue;
01358     }
01359     // do my special tags: fdetails
01360     if(token.IsBegin("fdetails")) {
01361         rTr.ReadBegin("fdetails", token);
01362         *rTw.Streamp() << "<p><strong>Detailed description:</strong></p>" << std::endl;
01363   rTr.ReadEnd("fdetails");
01364   continue;
01365     }
01366     // do my special tags: fconditions
01367     if(token.IsBegin("fconditions")) {
01368         rTr.ReadBegin("fconditions", token);
01369         *rTw.Streamp() << "<p><strong>Parameter Conditions:</strong></p>" << std::endl;
01370   rTr.ReadEnd("fconditions");
01371   continue;
01372     }
01373     // do my special tags: fexample
01374     if(token.IsBegin("fexample")) {
01375         rTr.ReadBegin("fexample", token);
01376         *rTw.Streamp() << "<p><strong>Example:</strong></p>" << std::endl;
01377   rTr.ReadEnd("fexample");
01378   continue;
01379     }
01380     // do my special tags: falltypes
01381     if(token.IsBegin("falltypes")) {
01382         rTr.ReadBegin("falltypes", token);
01383         ListTypesHtml(rTw.Streamp());
01384   rTr.ReadEnd("falltypes");
01385   continue;
01386     }
01387     // do my special tags: fallfncts
01388     if(token.IsBegin("fallfncts")) {
01389         rTr.ReadBegin("fallfncts", token);
01390         ListFunctionsHtml(rTw.Streamp());
01391   rTr.ReadEnd("fallfncts");
01392   continue;
01393     }
01394     // do my special tags: fallsects
01395     if(token.IsBegin("fallsects")) {
01396         rTr.ReadBegin("fallsects", token);
01397         ListSectionsHtml(rTw.Streamp());
01398   rTr.ReadEnd("fallsects");
01399   continue;
01400     }
01401     // do my special tags: fliteratur (list all)
01402     if(token.IsBegin("falllit")) {
01403         rTr.ReadBegin("falllit");
01404         LiteratureHtml(rTw.Streamp());
01405   rTr.ReadEnd("falllit");
01406   continue;
01407     }
01408     // do my special tags: fliteratur (definition of)
01409     if(token.IsBegin("fliterature")) {
01410         rTr.ReadBegin("fliterature", token);
01411   std::string label=token.AttributeStringValue("name");
01412         LiteratureHtml(rTw.Streamp(),label);
01413   rTr.ReadEnd("fliterature");
01414   continue;
01415     }
01416     // do my special tags: fcontributors
01417     if(token.IsBegin("fcontributors")) {
01418         rTr.ReadBegin("fcontributors");
01419         *rTw.Streamp() << FDContributorsString();
01420   rTr.ReadEnd("fcontributors");
01421   continue;
01422     }
01423     // do my special tags: flink
01424     if(token.IsBegin("fcite")) {
01425         rTr.ReadBegin("fcite", token);
01426         std::string label=token.AttributeStringValue("name");
01427         CiteHtml(rTw.Streamp(),label);
01428   rTr.ReadEnd("fcite");
01429   continue;
01430     }
01431     // do my special tags: fix br for HTML
01432     if(token.IsBegin("br")) {
01433         rTr.ReadBegin("br");
01434   Token etag;
01435         rTr.Peek(etag); 
01436         if(etag.IsEnd("br")) rTr.ReadEnd("br"); // optionally accept balanced <br>
01437         token.ClrEnd();
01438         rTw.Write(token); // intentionall write unbalanced <br> for HTML
01439   continue;
01440     }
01441     // get token to do my special attributes
01442     rTr.Get(token);
01443     //std::cerr << "copy token (lv " << rTr.Level() << "): " << token.Str() << "\n";
01444     // sense chapter classes
01445     if(token.ExistsAttributeString("ftcclass")) {
01446       mThisChapterClass=token.AttributeStringValue("ftcclass");
01447       token.ClrAttribute("ftcclass");
01448     }
01449     if(token.ExistsAttributeString("focclass"))  {
01450       mOtherChapterClass=token.AttributeStringValue("focclass");  
01451       token.ClrAttribute("focclass");
01452     }
01453     if(token.ExistsAttributeString("fxcclass"))  {
01454       mExitChapterClass=token.AttributeStringValue("fxcclass");  
01455       token.ClrAttribute("fxcclass");
01456     }
01457     // chapter attribute
01458     if(token.ExistsAttributeString("fchapter")) {
01459       std::string chapter = token.AttributeStringValue("fchapter");
01460       std::string cclass=mOtherChapterClass;
01461       if(chapter==mFrefChapter) cclass=mThisChapterClass;
01462       if(chapter=="exit") cclass=mExitChapterClass;
01463       token.InsAttributeString("class",cclass);
01464       token.ClrAttribute("fchapter");
01465     }
01466     // fhref attribute: ref only
01467     if(token.ExistsAttributeString("fhref") && mStandaloneReference) {
01468       std::string href = token.AttributeStringValue("fhref");
01469       href = StringSubstitute(href,"FAUDES_BOOKS/",mBooksPrefix);
01470       href = StringSubstitute(href,"FAUDES_CHAPTERS/",mChaptersPrefix);
01471       href = StringSubstitute(href,"FAUDES_IMAGES/",mImagePrefix);
01472       href = StringSubstitute(href,"FAUDES_REGISTRY/",mRegistryPrefix);
01473       href = StringSubstitute(href,"FAUDES_CSOURCE/",mCsourceLink);
01474       href = StringSubstitute(href,"FAUDES_LUAFAUDES/",mLuafaudesLink);
01475       href = StringSubstitute(href,"FAUDES_ONLINE",mFaudesLink);
01476       href = StringSubstitute(href,"FAUDES_GETLINUX",mDownloadLink+"#Linux");
01477       href = StringSubstitute(href,"FAUDES_GETMSWIN",mDownloadLink+"#MsWin");
01478       href = StringSubstitute(href,"DESTOOL_ONLINE",mDestoolLink);
01479       token.InsAttributeString("href",href);
01480       token.ClrAttribute("fhref");
01481     }
01482     // fhref attribute
01483     if(token.ExistsAttributeString("fhref")  && !mStandaloneReference) {
01484       std::string href = token.AttributeStringValue("fhref");
01485       href = StringSubstitute(href,"FAUDES_BOOKS/",mBooksPrefix);
01486       href = StringSubstitute(href,"FAUDES_CHAPTERS/",mChaptersPrefix);
01487       href = StringSubstitute(href,"FAUDES_IMAGES/",mImagePrefix);
01488       href = StringSubstitute(href,"FAUDES_REGISTRY/",mRegistryPrefix);
01489       href = StringSubstitute(href,"FAUDES_CSOURCE/",mCsourcePrefix);
01490       href = StringSubstitute(href,"FAUDES_LUAFAUDES/",mLuafaudesPrefix);
01491       href = StringSubstitute(href,"FAUDES_ONLINE",mFaudesLink);
01492       href = StringSubstitute(href,"FAUDES_GETLINUX",mDownloadLink+"#Linux");
01493       href = StringSubstitute(href,"FAUDES_GETMSWIN",mDownloadLink+"#MsWin");
01494       href = StringSubstitute(href,"DESTOOL_ONLINE",mDestoolLink);
01495       token.InsAttributeString("href",href);
01496       token.ClrAttribute("fhref");
01497     }
01498     // fsrc attribute
01499     if(token.ExistsAttributeString("fsrc")) {
01500       std::string fsrc = token.AttributeStringValue("fsrc");
01501       fsrc = StringSubstitute(fsrc,"FAUDES_IMAGES/",mImagePrefix);
01502       fsrc = StringSubstitute(fsrc,"FAUDES_CSOURCE/",mCsourcePrefix);
01503       fsrc = StringSubstitute(fsrc,"FAUDES_LUAFAUDES/",mLuafaudesPrefix);
01504       token.InsAttributeString("src",fsrc);
01505       token.ClrAttribute("fsrc");
01506     }
01507     rTw.Write(token);
01508   }
01509 }
01510 
01511 
01512 // ******************************************************************
01513 // reference page
01514 // ******************************************************************
01515 
01516 void RefpageHtml(std::ostream* pOutFile, std::string inputfile) {
01517 
01518   // setup token io
01519   TokenReader src(inputfile);
01520   TokenWriter dst(*pOutFile);
01521 
01522   // find the reference page section
01523   Token btag;
01524   src.SeekBegin("ReferencePage");
01525   src.ReadBegin("ReferencePage",btag);
01526 
01527   // extract title & friends
01528   mFrefTitle="libFAUDES Reference";
01529   if(btag.ExistsAttributeString("title")) 
01530     mFrefTitle=btag.AttributeStringValue("title");
01531   mFrefChapter="";
01532   if(btag.ExistsAttributeString("chapter")) 
01533     mFrefChapter=btag.AttributeStringValue("chapter");
01534   mFrefSection="";
01535   if(btag.ExistsAttributeString("section")) 
01536     mFrefSection=btag.AttributeStringValue("section");
01537   std::transform(mFrefChapter.begin(), mFrefChapter.end(), mFrefChapter.begin(), tolower);
01538   std::transform(mFrefSection.begin(), mFrefSection.end(), mFrefSection.begin(), tolower);
01539 
01540   // report
01541   // std::cerr << "ref2html: found chapter \"" << mFrefChapter << "\" section \"" << mFrefSection << "\"" << std::endl;
01542 
01543   // generate generic html header
01544   dst.Flush();
01545   HeaderHtml(pOutFile);
01546 
01547   // begin body
01548   dst.Flush();
01549 
01550   // include chapter level navigation
01551   if(mChapterFile!="") {
01552     TokenReader inc(mChapterFile);
01553     ProcessSection(dst,inc);
01554   }
01555 
01556   // include section level navigation, part 1
01557   if(mFrefChapter=="reference") {
01558     *pOutFile << "<table id=\"registry_page\">" << std::endl;
01559     *pOutFile << "<tr id=\"registry_row\">" << std::endl;
01560     *pOutFile << "<td id=\"registry_index\">" << std::endl;
01561     *pOutFile << "<div class=\"registry_heading\"><strong>libFAUDES</strong></div>" << std::endl;
01562     *pOutFile << "<div class=\"registry_index\"><a href=\"reference_index.html\">Reference</a></div>" << std::endl;
01563     *pOutFile << "<div class=\"registry_index\"><a href=\"reference_index.html#types\">Type Index</a></div>" << std::endl;
01564     *pOutFile << "<div class=\"registry_index\"><a href=\"reference_index.html#functions\">Function Index</a></div>" << std::endl;
01565     *pOutFile << "<div class=\"registry_index\"><a href=\"reference_index.html#literature\">Literature</a></div>" << std::endl;
01566     *pOutFile << "<br>" << std::endl;
01567     ReferenceIndexHtml(pOutFile, mFrefSection);
01568     *pOutFile << "</td>" << std::endl;
01569     *pOutFile << "<td id=\"registry_content\">" << std::endl;
01570   }
01571 
01572   // include section level navigation, part 1
01573   if(mFrefChapter=="luafaudes") {
01574     *pOutFile << "<table id=\"registry_page\">" << std::endl;
01575     *pOutFile << "<tr id=\"registry_row\">" << std::endl;
01576     *pOutFile << "<td id=\"registry_index\">" << std::endl;
01577     *pOutFile << "<div class=\"registry_heading\"><strong>luafaudes</strong></div>" << std::endl;
01578     *pOutFile << "<div class=\"registry_index\"><a href=\"index.html\">Overview</a></div>" << std::endl;
01579     *pOutFile << "<div class=\"registry_index\"><a href=\"faudes_luatech.html\">Technical Details</a></div>" << std::endl;
01580     *pOutFile << "<div class=\"registry_index\"><a href=\"faudes_luaext.html\">LuaExtensions</a></div>" << std::endl;
01581     *pOutFile << "<br>" << std::endl;
01582     *pOutFile << "<div class=\"registry_heading\"><strong>Tutorials</strong></div>" << std::endl;
01583     LuafaudesIndexHtml(pOutFile);
01584     *pOutFile << "</td>" << std::endl;
01585     *pOutFile << "<td id=\"registry_content\">" << std::endl;
01586   }
01587 
01588   // process src
01589   ProcessSection(dst,src);
01590   src.ReadEnd("ReferencePage");
01591 
01592   // include section level navigation, part 2
01593   if(mFrefChapter=="reference") {
01594     *pOutFile << "</td>" << std::endl;
01595     *pOutFile << "</tr>" << std::endl;
01596     *pOutFile << "</table>" << std::endl;
01597   }
01598 
01599   // include section level navigation, part 2
01600   if(mFrefChapter=="luafaudes") {
01601     *pOutFile << "</td>" << std::endl;
01602     *pOutFile << "</tr>" << std::endl;
01603     *pOutFile << "</table>" << std::endl;
01604   }
01605 
01606   // end page
01607   dst.Flush();
01608   FooterHtml(pOutFile);
01609 
01610 }
01611 
01612 
01613 
01614 // ******************************************************************
01615 // Doxygen header and footer
01616 // ******************************************************************
01617 
01618 void DoxygenHeader(std::ostream* pOutFile) {
01619 
01620   // setup token io
01621   TokenWriter dst(*pOutFile);
01622 
01623   // configure
01624   mFrefTitle="C++ API";
01625   mFrefChapter="cppapi";
01626   mFrefSection="none";
01627 
01628   // generate generic html header
01629   dst.Flush();
01630   HeaderHtml(pOutFile);
01631 
01632   // include chapter level navigation
01633   if(mChapterFile!="") {
01634     TokenReader inc(mChapterFile);
01635     ProcessSection(dst,inc);
01636   }
01637 
01638   // include section level navigation, part 1
01639   *pOutFile << "<table id=\"registry_page\">" << std::endl;
01640   *pOutFile << "<tr id=\"registry_row\">" << std::endl;
01641   *pOutFile << "<td id=\"registry_index\">" << std::endl;
01642   *pOutFile << "<div class=\"registry_heading\"><strong>libFAUDES</strong></div>" << std::endl;
01643   *pOutFile << "<div class=\"registry_index\"><a href=\"main.html\">C++ API</a></div>" << std::endl;
01644   *pOutFile << "<br>" << std::endl;  
01645   *pOutFile << "<div class=\"registry_heading\"><strong>Sections</strong></div>" << std::endl;
01646   *pOutFile << "<div class=\"registry_index\"><a href=\"group__ContainerClasses.html\">Sets</a></div>" << std::endl;
01647   *pOutFile << "<div class=\"registry_index\"><a href=\"group__GeneratorClasses.html\">Generators</a></div>" << std::endl;
01648   *pOutFile << "<div class=\"registry_index\"><a href=\"group__GeneratorFunctions.html\">Functions</a></div>" << std::endl;
01649   *pOutFile << "<div class=\"registry_index\"><a href=\"group__AllPlugins.html\">PlugIns</a></div>" << std::endl;
01650   *pOutFile << "<div class=\"registry_index\"><a href=\"group__Tutorials.html\">Tutorials</a></div>" << std::endl;
01651   *pOutFile << "<br>" << std::endl;  
01652   *pOutFile << "<div class=\"registry_heading\"><strong>Index</strong></div>" << std::endl;
01653   *pOutFile << "<div class=\"registry_index\"><a href=\"classes.html\">Classes</a></div>" << std::endl;
01654   *pOutFile << "<div class=\"registry_index\"><a href=\"namespacefaudes.html\">Namespace</a></div>" << std::endl;
01655   *pOutFile << "<div class=\"registry_index\"><a href=\"files.html\">Files</a></div>" << std::endl;
01656   *pOutFile << "<br>" << std::endl;  
01657   *pOutFile << "</td>" << std::endl;
01658   *pOutFile << "<td id=\"registry_content\">" << std::endl;
01659 }
01660 
01661 
01662 void DoxygenFooter(std::ostream* pOutFile) {
01663 
01664   // setup token io
01665   TokenWriter dst(*pOutFile);
01666 
01667   // configure
01668   mFrefTitle="C++ API";
01669   mFrefChapter="cppapi";
01670   mFrefSection="none";
01671 
01672   // include section level navigation, part 2
01673   *pOutFile << "</td>" << std::endl;
01674   *pOutFile << "</tr>" << std::endl;
01675   *pOutFile << "</table>" << std::endl;
01676 
01677   // end page
01678   dst.Flush();
01679   FooterHtml(pOutFile);
01680 
01681 }
01682 
01683 // ******************************************************************
01684 // command line ui
01685 // ******************************************************************
01686 
01687 
01688 int main(int argc, char *argv[]) {
01689 
01690   // local config 
01691   bool dotoc=false;
01692   bool dodhd=false;
01693   bool dodft=false;
01694   bool xpage=false;
01695 
01696   // min args
01697   if(argc < 3) usage_exit();
01698 
01699   // primitive commad line parsing
01700   int i;
01701   for(i=1; i<argc; i++) {
01702     std::string option(argv[i]);
01703     // option: rti file
01704     if(option=="-rti") { 
01705       i++; if(i>=argc) usage_exit();
01706       mRtiFile=argv[i];
01707       continue;
01708     }
01709     // option: flx file
01710     if(option=="-flx") { 
01711       i++; if(i>=argc) usage_exit();
01712       mFlxFile=argv[i];
01713       continue;
01714     }
01715     // option: css file
01716     if(option=="-css") { 
01717       i++; if(i>=argc) usage_exit();
01718       mCssFile=argv[i];
01719       continue;
01720     }
01721     // option: navigation include
01722     if(option=="-cnav") {
01723       i++; if(i>=argc) usage_exit();
01724       mChapterFile=argv[i];
01725       continue;
01726     }
01727     // option: toc include
01728     if(option=="-inc") { 
01729       i++; if(i>=argc) usage_exit();
01730       mIncludeFile=argv[i];
01731       continue;
01732     }
01733     // option: target prefix
01734     if(option=="-rel") {
01735       i++; if(i>=argc) usage_exit();
01736       ChaptersPrefix(argv[i]);
01737       continue;
01738     }
01739     // option: overwrite chapter
01740     if(option=="-chapter") {
01741       i++; if(i>=argc) usage_exit();
01742       mFrefChapter=argv[i];
01743       continue;
01744     }
01745     // option: overwrite section
01746     if(option=="-section") {
01747       i++; if(i>=argc) usage_exit();
01748       mFrefSection=argv[i];
01749       continue;
01750     }
01751     // option: extrac multiple pages
01752     if(option=="-extract") {
01753       if(i+2!=argc-1) usage_exit();
01754       xpage=true;
01755       break;
01756     }
01757     // option: generate toc (break)
01758     if(option=="-toc") {
01759       i++; if(i+1>=argc) usage_exit();
01760       dotoc=true;
01761       mHtmlFile = argv[argc-1];
01762       break;
01763     }
01764     // option: generate doxygen header (break)
01765     if(option=="-doxheader") {
01766       i++; if(i>=argc) usage_exit();
01767       dodhd=true;
01768       mHtmlFile = argv[argc-1];
01769       break;
01770     }
01771     // option: generate doxygen footer (break)
01772     if(option=="-doxfooter") {
01773       i++; if(i>=argc) usage_exit();
01774       dodft=true;
01775       mHtmlFile = argv[argc-1];
01776       break;
01777     }
01778     // option: generate doxygen footer (break)
01779     if(option=="-app") {
01780       mStandaloneReference=true;
01781       continue;
01782     }
01783     // option: help
01784     if((option=="-?") || (option=="--help")) {
01785       usage_exit();
01786       continue;
01787     }
01788     // option: unknown
01789     if(option.size()>1)
01790     if(option.at(0)=='-') {
01791       usage_exit("unknown option " + option);
01792       continue;
01793     }
01794     // filename: input
01795     if(mFrefFile=="") {
01796        mFrefFile=option;
01797        continue;
01798     }
01799     // filename: output
01800     if(mHtmlFile=="") {
01801        mHtmlFile=option;
01802        continue;
01803     }
01804     // too many filenames
01805     usage_exit("more than one filname specified" );
01806   }
01807 
01808 
01809   // load registry 
01810   if(mRtiFile!="") {
01811     LoadRegistry(mRtiFile);
01812   }
01813 
01814   // extend registry 
01815   if(mFlxFile!="") {
01816     FunctionRegistry::G()->MergeDocumentation(mFlxFile);
01817   }
01818 
01819   // special case: xtract fref
01820   if(xpage) {
01821     mFrefFile=argv[i+1];
01822     std::string dstdir =argv[i+2];
01823     std::cerr << "ref2html: extract pages from " << mFrefFile << std::endl;
01824     TokenReader tr(mFrefFile);
01825     XtractPages(tr,dstdir);
01826     tr.Rewind();
01827     XtractFiles(tr,dstdir);
01828     exit(0);
01829   }
01830 
01831 
01832   // output file
01833   std::ostream* hout= &std::cout;
01834   std::ofstream fout;
01835   if(mHtmlFile != "-") {
01836     fout.open(argv[argc-1], std::ios::out);
01837     hout = &fout;
01838   }
01839   
01840   // special case: generate toc
01841   if(dotoc) {
01842     // process all input 
01843     for(;i<argc-1;i++) {
01844       mFrefFile=argv[i];
01845       std::cerr << "ref2html: process toc " << mFrefFile << std::endl;
01846       TokenReader tr(mFrefFile);
01847       RecordLiterature(tr);
01848       tr.Rewind();
01849       RecordPages(tr);
01850     }
01851     // dump
01852     TokenWriter dst(*hout);
01853     DumpPages(dst);
01854     DumpLiterature(dst);
01855     dst.Flush();
01856     exit(0);
01857   }
01858 
01859   // special case: generate dox header
01860   if(dodhd) {
01861     DoxygenHeader(hout);
01862     exit(0);
01863   }
01864 
01865   // special case: generate dox footer
01866   if(dodft) {
01867     DoxygenFooter(hout);
01868     exit(0);
01869   }
01870 
01871   // include to
01872   if(mIncludeFile!="") {
01873     TokenReader tr(mIncludeFile);
01874     RecordLiterature(tr);
01875     tr.Rewind();
01876     RecordPages(tr);
01877   }
01878 
01879   // std: process reference page
01880   RefpageHtml(hout,mFrefFile);
01881   return 0;
01882 
01883   // error
01884   usage_exit();
01885   return(1);
01886 }

libFAUDES 2.20s --- 2011.10.12 --- c++ source docu by doxygen