|
libFAUDES
Sections
Index
|
rti2html.cppGo to the documentation of this file.00001 /** rti2hmtl.cpp Utility to generate a html documents from rti files */ 00002 00003 /* FAU Discrete Event Systems Library (libfaudes) 00004 00005 Copyright (C) 2009 Ruediger Berndt 00006 Copyright (C) 2009 Thomas Moor 00007 00008 This library is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU Lesser General Public 00010 License as published by the Free Software Foundation; either 00011 version 2.1 of the License, or (at your option) any later version. 00012 00013 This library is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 Lesser General Public License for more details. 00017 00018 You should have received a copy of the GNU Lesser General Public 00019 License along with this library; if not, write to the Free Software 00020 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 00021 00022 00023 #include <string> 00024 #include <cctype> 00025 #include <iostream> 00026 #include <fstream> 00027 #include "corefaudes.h" 00028 00029 00030 using namespace faudes; 00031 00032 // ****************************************************************** 00033 // error exit 00034 // ****************************************************************** 00035 00036 void Usage(const std::string& rMessage="") { 00037 // ui hints 00038 if(rMessage!="") { 00039 std::cerr << rMessage << std::endl; 00040 std::cout << "" << std::endl; 00041 } 00042 std::cerr << "rti2html: " << FDVersionString() << std::endl; 00043 std::cout << "" << std::endl; 00044 std::cerr << "utility to generate an html snippets from an libFAUDES" << std::endl; 00045 std::cerr << "run-time interface definition file" << std::endl; 00046 std::cerr << std::endl << "usage: " << std::endl; 00047 std::cerr << " rti2html <rti input file> -dump" << std::endl; 00048 std::cerr << " rti2html <rti input file> -index <html output file>" << std::endl; 00049 std::cerr << " rti2html <rti input file> -section <plugin name> <html output file>" << std::endl; 00050 std::cerr << " rti2html <rti input file> -type <type name> <html output file>" << std::endl; 00051 std::cerr << " rti2html <rti input file> -function <function name> <html output file>" << std::endl; 00052 std::cerr << " rti2html <rti input file> -alltypes <html output file>" << std::endl; 00053 std::cerr << " rti2html <rti input file> -allfunctions <html output file>" << std::endl; 00054 std::cerr << " rti2html <rti input file> -allsections <html output file>" << std::endl; 00055 std::cerr << " rti2html <rti input file> -signature <function name> <html output file>" << std::endl; 00056 std::cerr << " rti2html <rti input file> -shortdoc <function/type name> <html output file>" << std::endl; 00057 std::cerr << " rti2html <rti input file> -contrib <html output file>" << std::endl; 00058 std::cerr << std::endl << "note: use \"-\" as output file for console output" << std::endl; 00059 exit(1); 00060 } 00061 00062 00063 // ****************************************************************** 00064 // helper: html for linked type name 00065 // ****************************************************************** 00066 00067 void TypeHtml(std::ostream* pStream, const std::string& rTypeName) { 00068 00069 // just text if unknown 00070 if(!TypeRegistry::G()->Exists(rTypeName)) { 00071 *pStream << rTypeName; 00072 return; 00073 } 00074 00075 // retrieve definition 00076 const TypeDefinition& tdef=TypeRegistry::G()->Definition(rTypeName); 00077 std::string tyname = tdef.Name(); 00078 std::string tyhtml = tdef.HtmlDoc(); 00079 if(tyhtml=="" || tyhtml=="none") { 00080 *pStream << tyname; 00081 } else { 00082 *pStream << "<a href=\"" << tyhtml << "\">" << tyname << "</a>"; 00083 } 00084 } 00085 00086 // ****************************************************************** 00087 // helper: html for linked function name 00088 // ****************************************************************** 00089 00090 void FunctionHtml(std::ostream* pStream, const std::string& rFunctionName) { 00091 00092 // just text if unknown 00093 if(!FunctionRegistry::G()->Exists(rFunctionName)) { 00094 *pStream << rFunctionName; 00095 return; 00096 } 00097 00098 // retrieve definition 00099 const FunctionDefinition& fdef=FunctionRegistry::G()->Definition(rFunctionName); 00100 std::string fname = fdef.Name(); 00101 std::string fhtml = fdef.HtmlDoc(); 00102 if(fhtml=="" || fhtml=="none") { 00103 *pStream << fname; 00104 } else { 00105 *pStream << "<a href=\"" << fhtml << "\">" << fname << "</a>"; 00106 } 00107 } 00108 00109 // ****************************************************************** 00110 // search for types 00111 // ****************************************************************** 00112 00113 void SearchTypesHtml(std::ostream* pIndexFile, const std::string& key="") { 00114 00115 // traverse type registry 00116 bool found=false; 00117 for(TypeRegistry::Iterator tit=TypeRegistry::G()->Begin(); 00118 tit!=TypeRegistry::G()->End(); tit++) 00119 { 00120 // test for exact key 00121 if(key!="") { 00122 std::string section= tit->second->Name(); 00123 std::transform(section.begin(), section.end(), section.begin(), tolower); 00124 if(section!=key) continue; 00125 } 00126 // test for user doc 00127 if(tit->second->TextDoc()=="") continue; 00128 // fine tune format 00129 if(found) *pIndexFile << "," << std::endl; 00130 // record success 00131 if(!found) found=true; 00132 // link for this type 00133 TypeHtml(pIndexFile,tit->second->Name()); 00134 } 00135 // done 00136 if(!found) *pIndexFile << "<i>no matches found</i>" << std::endl; 00137 } 00138 00139 // ****************************************************************** 00140 // search for functions 00141 // ****************************************************************** 00142 00143 void SearchFunctionsHtml(std::ostream* pIndexFile, const std::string& key="") { 00144 00145 // traverse function registry 00146 bool found=false; 00147 for(FunctionRegistry::Iterator fit=FunctionRegistry::G()->Begin(); 00148 fit!=FunctionRegistry::G()->End(); fit++) 00149 { 00150 // test for exact key 00151 if(key!="") { 00152 std::string section= fit->second->Name(); 00153 std::transform(section.begin(), section.end(), section.begin(), tolower); 00154 if(section!=key) continue; 00155 } 00156 // test for user doc 00157 if(fit->second->TextDoc()=="") continue; 00158 // fine tune format 00159 if(found) *pIndexFile << "," << std::endl; 00160 // record success 00161 if(!found) found=true; 00162 // link for this type 00163 FunctionHtml(pIndexFile,fit->second->Name()); 00164 } 00165 // done 00166 if(!found) *pIndexFile << "<i>no matches found</i>" << std::endl; 00167 } 00168 00169 // ****************************************************************** 00170 // search for sections 00171 // ****************************************************************** 00172 00173 void SearchSectionsHtml(std::ostream* pIndexFile, const std::string& key="") { 00174 00175 // prepare list of all sections 00176 std::set< std::string > sections; 00177 for(TypeRegistry::Iterator tit=TypeRegistry::G()->Begin(); 00178 tit!=TypeRegistry::G()->End(); tit++) 00179 { 00180 std::string section= tit->second->KeywordAt(0); 00181 // bail out on trivial 00182 if(section=="") continue; 00183 // test for exact key 00184 if(key!="") { 00185 std::transform(section.begin(), section.end(), section.begin(), tolower); 00186 if(section!=key) continue; 00187 } 00188 // record 00189 sections.insert(tit->second->KeywordAt(0)); 00190 } 00191 for(FunctionRegistry::Iterator fit=FunctionRegistry::G()->Begin(); 00192 fit!=FunctionRegistry::G()->End(); fit++) 00193 { 00194 std::string section=fit->second->KeywordAt(0); 00195 // bail out on trivial 00196 if(section=="") continue; 00197 // test for exact key 00198 if(key!="") { 00199 std::transform(section.begin(), section.end(), section.begin(), tolower); 00200 if(section!=key) continue; 00201 } 00202 // record 00203 sections.insert(fit->second->KeywordAt(0)); 00204 } 00205 00206 // list sections as links 00207 std::set< std::string >::iterator pit; 00208 for(pit=sections.begin(); pit != sections.end(); pit++) { 00209 // get nice name 00210 std::string sname = *pit; 00211 // have link 00212 std::string shtml = sname+"_index.html"; 00213 std::transform(shtml.begin(),shtml.end(),shtml.begin(),tolower); 00214 // have entry as link 00215 if(pit!=sections.begin()) *pIndexFile << "," << std::endl; 00216 *pIndexFile << "<a href=\"" << shtml << "\">" << sname << "</a>"; 00217 } 00218 } 00219 00220 00221 00222 00223 // ****************************************************************** 00224 // type index by keyword (aka section name) 00225 // ****************************************************************** 00226 00227 void TypeIndexHtml(std::ostream* pIndexFile, const std::string& key="") { 00228 00229 // traverse type registry 00230 bool head=false; 00231 for(TypeRegistry::Iterator tit=TypeRegistry::G()->Begin(); 00232 tit!=TypeRegistry::G()->End(); tit++) 00233 { 00234 // test for exact key 00235 if(key!="") { 00236 std::string section= tit->second->KeywordAt(0); 00237 std::transform(section.begin(), section.end(), section.begin(), tolower); 00238 if(section!=key) continue; 00239 } 00240 // test for user doc 00241 if(tit->second->TextDoc()=="") continue; 00242 // head line 00243 if(!head) { 00244 head=true; 00245 *pIndexFile << "<div class=\"registry_heading\"><strong>Types</strong></div>" << std::endl; 00246 } 00247 // index entry for this type 00248 *pIndexFile << "<div class=\"registry_index\">"; 00249 TypeHtml(pIndexFile,tit->second->Name()); 00250 *pIndexFile << "</div>" << std::endl; 00251 } 00252 // done 00253 if(head) *pIndexFile << "<br>" << std::endl; 00254 } 00255 00256 // ****************************************************************** 00257 // function index by keyword (aka plugin) 00258 // ****************************************************************** 00259 00260 void FunctionIndexHtml(std::ostream* pIndexFile, const std::string& key="") { 00261 00262 // traverse function registry 00263 bool head=false; 00264 for(FunctionRegistry::Iterator fit=FunctionRegistry::G()->Begin(); 00265 fit!=FunctionRegistry::G()->End(); fit++) 00266 { 00267 // test for key 00268 if(key!="") { 00269 std::string section= fit->second->KeywordAt(0); 00270 std::transform(section.begin(), section.end(), section.begin(), tolower); 00271 if(section!=key) continue; 00272 } 00273 // test for user doc 00274 if(fit->second->TextDoc()=="") continue; 00275 // index entry for this function 00276 std::string fname = fit->second->Name(); 00277 std::string fhtml = fit->second->HtmlDoc(); 00278 if(fhtml=="") continue; 00279 // head line 00280 if(!head){ 00281 head=true; 00282 *pIndexFile << "<div class=\"registry_heading\"><strong>Functions</strong></div>" << std::endl; 00283 } 00284 // list entry 00285 if(fhtml=="none") { 00286 *pIndexFile << "<div class=\"registry_index\"> "<< fhtml << "</div>" << std::endl; 00287 continue; 00288 } 00289 *pIndexFile << "<div class=\"registry_index\"><a href=\"" << fhtml << "\">" 00290 << fname << "</a></div>" << std::endl; 00291 } 00292 00293 // done 00294 if(head) *pIndexFile << "<br>" << std::endl; 00295 00296 } 00297 00298 // ****************************************************************** 00299 // html index by keyword (aka section) 00300 // ****************************************************************** 00301 00302 void IndexHtml(std::ostream* pIndexFile, const std::string& key="") { 00303 00304 // prepare list of all sections 00305 std::set< std::string > sections; 00306 for(TypeRegistry::Iterator tit=TypeRegistry::G()->Begin(); 00307 tit!=TypeRegistry::G()->End(); tit++) 00308 { 00309 std::string sec=tit->second->KeywordAt(0); 00310 if(sec!="") sections.insert(sec); 00311 } 00312 for(FunctionRegistry::Iterator fit=FunctionRegistry::G()->Begin(); 00313 fit!=FunctionRegistry::G()->End(); fit++) 00314 { 00315 std::string sec=fit->second->KeywordAt(0); 00316 if(sec!="") sections.insert(sec); 00317 } 00318 00319 // sections headline 00320 if(sections.size()!=0) 00321 *pIndexFile << "<div class=\"registry_heading\"><strong>Sections</strong></div>" << std::endl; 00322 00323 // list sections 00324 std::set< std::string >::iterator pit; 00325 for(pit=sections.begin(); pit != sections.end(); pit++) { 00326 // get nice name 00327 std::string sname = *pit; 00328 // have link 00329 std::string shtml = sname+"_index.html"; 00330 std::transform(shtml.begin(),shtml.end(),shtml.begin(),tolower); 00331 // have entry 00332 *pIndexFile << "<div class=\"registry_index\"><a href=\"" << shtml << "\">" 00333 << sname << "</a></div>" << std::endl; 00334 } 00335 00336 // sections done 00337 if(sections.size()!=0) 00338 *pIndexFile << "<br>" << std::endl; 00339 00340 // list types 00341 TypeIndexHtml(pIndexFile,key); 00342 00343 // list functions 00344 FunctionIndexHtml(pIndexFile,key); 00345 } 00346 00347 // ****************************************************************** 00348 // signature 00349 // ****************************************************************** 00350 00351 void SignatureHtml(std::ostream* pOutFile, std::string function) { 00352 00353 // bail out on non existence 00354 if(!FunctionRegistry::G()->Exists(function)) return; 00355 00356 // function definition 00357 const FunctionDefinition& fdef=FunctionRegistry::G()->Definition(function); 00358 00359 // bail out if there is no signature 00360 if(fdef.VariantsSize()==0) return; 00361 00362 // start signature box 00363 *pOutFile << "<div class=\"registry_signature\">" << std::endl; 00364 *pOutFile << "<p><strong>Signature:</strong></p>" << std::endl; 00365 *pOutFile << "<p>" << std::endl; 00366 00367 // loop signatures 00368 for(int i=0; i< fdef.VariantsSize(); i++) { 00369 const Signature& sigi=fdef.Variant(i); 00370 *pOutFile << fdef.Name() << "("; 00371 // loop params 00372 for(int j=0; j < sigi.Size(); j++) { 00373 if(j!=0) *pOutFile << ", "; 00374 const Parameter& parj=sigi.At(j); 00375 *pOutFile << "+" << Parameter::AStr(parj.Attribute()) << "+ "; 00376 TypeHtml(pOutFile,parj.Type()); 00377 *pOutFile << " <i>" << parj.Name() << "</i>"; 00378 } 00379 *pOutFile << ")<br>" << std::endl; 00380 } 00381 *pOutFile << "</p>" << std::endl; 00382 00383 00384 // close signature box 00385 *pOutFile << std::endl << "</div>" << std::endl; 00386 } 00387 00388 // ****************************************************************** 00389 // short doc 00390 // ****************************************************************** 00391 00392 void ShortdocHtml(std::ostream* pOutFile, std::string fname) { 00393 00394 // its a function 00395 if(FunctionRegistry::G()->Exists(fname)) { 00396 00397 // function definition 00398 const FunctionDefinition& fdef=FunctionRegistry::G()->Definition(fname); 00399 00400 // stream doc 00401 *pOutFile << "<div class=\"registry_signature\">" << std::endl; 00402 *pOutFile << "<p>" << fdef.TextDoc() << "<p>" << std::endl; 00403 *pOutFile << "</div>" << std::endl; 00404 00405 // stream signature 00406 SignatureHtml(pOutFile,fname); 00407 } 00408 00409 // its a type 00410 if(TypeRegistry::G()->Exists(fname)) { 00411 00412 // type definition 00413 const TypeDefinition& tdef=TypeRegistry::G()->Definition(fname); 00414 00415 // stream doc 00416 *pOutFile << "<div class=\"registry_signature\">" << std::endl; 00417 *pOutFile << "<p>" << tdef.TextDoc() << "<p>" << std::endl; 00418 *pOutFile << "</div>" << std::endl; 00419 00420 } 00421 00422 00423 } 00424 00425 // ****************************************************************** 00426 // command line ui 00427 // ****************************************************************** 00428 00429 00430 int main(int argc, char *argv[]) { 00431 00432 // min args 00433 if(argc < 3) Usage(); 00434 00435 // load registry 00436 LoadRegistry(argv[1]); 00437 00438 // dump registry 00439 if(std::string(argv[2])=="-dump") { 00440 // bail out 00441 if(argc != 3) Usage(); 00442 // dump 00443 TypeRegistry::G()->Write(); 00444 FunctionRegistry::G()->Write(); 00445 return 0; 00446 } 00447 00448 // output file 00449 std::ostream* hout= &std::cout; 00450 std::ofstream fout; 00451 if(std::string(argv[argc-1]) != "-") { 00452 fout.open(argv[argc-1], std::ios::out); 00453 hout = &fout; 00454 } 00455 00456 // generate global index 00457 if(std::string(argv[2])=="-index") { 00458 // bail out 00459 if(argc != 4) Usage(); 00460 // run and done 00461 IndexHtml(hout); 00462 return 0; 00463 } 00464 00465 // generate section index 00466 if(std::string(argv[2])=="-section") { 00467 // bail out 00468 if(argc != 5) Usage(); 00469 // have lower case plugin pattern 00470 std::string pattern=std::string(argv[3]); 00471 std::transform(pattern.begin(), pattern.end(), pattern.begin(), tolower); 00472 // run and done 00473 IndexHtml(hout,pattern); 00474 return 0; 00475 } 00476 00477 // generate linked function 00478 if(std::string(argv[2])=="-function") { 00479 // bail out 00480 if(argc != 5) Usage(); 00481 // run and done 00482 FunctionHtml(hout,argv[3]); 00483 return 0; 00484 } 00485 00486 // generate linked function list 00487 if(std::string(argv[2])=="-allfunctions") { 00488 // bail out 00489 if(argc != 4) Usage(); 00490 // run and done 00491 SearchFunctionsHtml(hout); 00492 return 0; 00493 } 00494 00495 // generate linked type 00496 if(std::string(argv[2])=="-type") { 00497 // bail out 00498 if(argc != 5) Usage(); 00499 // run and done 00500 TypeHtml(hout,argv[3]); 00501 return 0; 00502 } 00503 00504 // generate all types 00505 if(std::string(argv[2])=="-alltypes") { 00506 // bail out 00507 if(argc != 4) Usage(); 00508 // run and done 00509 SearchTypesHtml(hout); 00510 return 0; 00511 } 00512 00513 // generate all sections 00514 if(std::string(argv[2])=="-allsections") { 00515 // bail out 00516 if(argc != 4) Usage(); 00517 // run and done 00518 SearchSectionsHtml(hout); 00519 return 0; 00520 } 00521 00522 // generate signature 00523 if(std::string(argv[2])=="-signature") { 00524 // bail out 00525 if(argc != 5) Usage(); 00526 // run and done 00527 SignatureHtml(hout,argv[3]); 00528 return 0; 00529 } 00530 00531 // generate short doc 00532 if(std::string(argv[2])=="-shortdoc") { 00533 // bail out 00534 if(argc != 5) Usage(); 00535 // run and done 00536 ShortdocHtml(hout,argv[3]); 00537 return 0; 00538 } 00539 00540 // plain text contributers 00541 if(std::string(argv[2])=="-contrib") { 00542 // bail out 00543 if(argc != 4) Usage(); 00544 // run and done 00545 *hout << FDContributorsString(); 00546 return 0; 00547 } 00548 00549 // error 00550 Usage(); 00551 return(1); 00552 } |
libFAUDES 2.16b --- 2010-9-8 --- c++ source docu by doxygen 1.6.3