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