16 #include <boost/shared_ptr.hpp> 17 #include <boost/filesystem/exception.hpp> 18 #include <boost/filesystem/operations.hpp> 19 #include <boost/filesystem/fstream.hpp> 40 namespace fs =
boost::filesystem;
47 " font: 100% \"Lucida Grande\", Verdana, Lucida, Helvetica, Arial, sans-serif;\n" 48 " background-color: White;\n" 52 " /* background: #eeeeee;*/\n" 53 " /*background: #FFE;\n" 54 " margin-left: 0em;\n" 55 " margin-right: 0em;\n" 56 " font-family: \"Arial\", \"Helvetica\", sans-serif;*/\n" 57 " /* line-height: 1.35; */ /* This would break MacIE 3 */\n" 61 " margin: 1em 1em 1em 1em;\n" 62 " line-height: 1.5em;\n" 65 " text-decoration: underline;\n" 69 " background-color: transparent;\n" 73 " background-color: transparent;\n" 79 "h1, h2, h3, h4, h5, h6 {\n" 81 " background-color: transparent;\n" 82 " font-family: \"Lucida Grande\", Verdana, Lucida, Helvetica, Arial, sans-serif;\n" 84 " font-weight: normal;\n" 86 " padding-top: 0.5em;\n" 87 " border-bottom: 1px solid #8cacbb;\n" 96 " color: Black ! important; \n" 100 " font-size: 180%;\n" 104 " font-size: 160%;\n" 108 " font-size: 130%;\n" 109 " border-bottom: none;\n" 110 " /*font-weight: bold;*/\n" 111 " margin-left: 1em;\n" 115 " font-size: 120%;\n" 116 " border-bottom: none;\n" 117 " font-weight: bold;\n" 118 " text-align: right;\n" 119 " text-transform: capitalize\n" 123 " font-size: 100%;\n" 124 " border-bottom: none;\n" 125 " font-weight: bold;\n" 130 " border-bottom: none;\n" 131 " font-weight: bold;\n" 137 " border: 1px dashed #8cacbb;\n" 139 " background-color: #dee7ec;\n" 143 " text-decoration: underline;\n" 146 "div.error{ color: #ff0000;font-size: 120%;font-weight: bold }\n" 147 "div.command{ margin-left:2em;margin-right:2em}\n" 149 "#topmenu {position: absolute; top: 2em; right: 0; width: 15em; margin: 0; padding: 0; font-family: Arial, sans-serif;}\n" 150 "#topmenu ul {padding: 0; margin: 0; border-bottom: 1px solid silver; font: 1em sans-serif;}\n" 151 "#topmenu ul li {list-style-type: none; border: 1px solid silver; border-width: 1px 1px 0 3px; position: relative; margin: 0; padding: 0;}\n" 152 "#topmenu ul ul {display: none;}\n" 153 "#topmenu ul li:hover > ul {display: block; position: absolute; top: -1px; left: 100%;}\n" 154 "#topmenu li > a {display: block; padding: 5px 7px; text-decoration: none; background: #ffff00; margin-left: -10.2em; }\n" 156 "#topmenu li:hover {background-color: #EED;display: block; }\n" 157 "#topmenu li.sub:hover {margin-left: -10.2em; border: 1px solid gray; background: #DDB;}\n" 158 "#topmenu li.sub:hover > a {color: #330;}\n" 159 "#topmenu li.sub:hover > ul {top: 1.75em; left: -1px; background: #FEFEFC;}*/\n" 160 "#topmenu ul li a:hover {background: #DDB;display:block;}\n" 161 "#topmenu li.sub > a {font-weight: bold; background: #DDB;}\n" 162 "#topmenu ul {width: 15em;}\n" 163 "#topmenu ul > li:hover > ul {width: 10em; top: 1.5em; left: -3px;}\n" 165 "#rtnv { position: absolute; top: 2em; right: 0; width: 15em; \n" 166 " margin: 0; padding: 0; font-family: Arial, sans-serif;background: #dddddd fixed;\n" 167 " position: fixed; float:right; border: 1px solid black; border-width:\n" 168 "1px; /*opacity: .5;-khtml-opacity: .5*/\n" 170 "/*#rtnv > ul {width: 9em; margin-left: -1px; font-size: 85%;}\n" 171 "#rtnv ul {border: 1px solid silver; border-width: 0 0 0 1px}*/\n" 172 "#rtnv ul {padding: 0; margin: 0; border-bottom: 1px solid silver; font: 1em sans-serif;}\n" 173 "#rtnv ul li {list-style-type: none; border: 1px solid silver; border-width:\n" 174 "1px 1px 0 3px; position: relative; margin: 0; padding:\n" 175 "0;text-align=left;}\n" 176 "#rtnv ul ul {display: none;}\n" 177 "/*#rtnv ul li {list-style-type: none; border-width: 1px 0; border-color: white; padding: 0 0 0 5px; line-height: 1.25em;}\n" 178 "#rtnv ul ul {border-width: 0 1px 1px 1px; border-color: gray silver gray gray;}*/\n" 179 "#rtnv ul ul li {border-color: #FEFEFC;}\n" 180 "#rtnv ul li:hover > ul {display: block; position: absolute; top: -1px; left: 100%;}\n" 181 "#rtnv li > a {background-color: transparent; padding: 3px;display: block; }\n" 182 "#rtnv li a:hover {background-color: #EED;display: block; }\n" 183 "#rtnv li.sub:hover {margin-left: -15em; border: 1px solid gray; background: #DDB;}\n" 184 "#rtnv li.sub:hover > a {color: #330;}\n" 185 "#rtnv li.sub:hover > ul {top: 1.75em; left: -1px; background: #DDA;}\n";
246 string leaf ( pth.leaf() );
252 && leaf !=
"autom4te.cache" 253 && leaf !=
"Templates" 264 string::size_type pos ( content.find (
"www.boost.org/libs/" ) );
266 if ( pos == string::npos )
273 while ( content[pos] !=
' ' 274 && content[pos] !=
'/' 275 && content[pos] !=
'\n' 276 && content[pos] !=
'\r' 277 && content[pos] !=
'\t' )
279 lib += content[pos++];
289 string name ( file_path.leaf() );
290 if ( signatures.find ( name ) == signatures.end() )
292 string::size_type pos ( name.rfind (
'.' ) );
293 if ( pos == string::npos
294 || signatures.find ( name.substr ( pos ) )
295 == signatures.end() )
314 fs::ifstream fin ( file_path, std::ios_base::in | std::ios_base::binary );
317 throw string (
"could not open input file: " ) + file_path.string();
319 std::getline ( fin, target,
'\0' );
325 const path& pth,
const string& content,
const inspector_list& insp_list )
328 for ( inspector_list::const_iterator itr = insp_list.begin();
329 itr != insp_list.end(); ++itr )
331 itr->inspector->inspect ( lib, pth );
332 if ( find_signature ( pth, itr->inspector->signatures() ) )
334 itr->inspector->inspect ( lib, pth, content );
341 template<
class DirectoryIterator >
345 static DirectoryIterator end_itr;
348 for ( DirectoryIterator itr ( dir_path ); itr != end_itr; ++itr )
351 if ( fs::is_directory ( *itr ) )
353 if ( visit_predicate ( *itr ) )
356 check ( cur_lib, *itr,
"", insps );
357 visit_all<DirectoryIterator> ( cur_lib, *itr, insps );
364 load_content ( *itr, content );
365 check ( lib ==
"unknown" 366 ? library_from_content ( content ) : lib, *itr, content, insps );
375 std::cout <<
" <tr><td><a href=\"#" 377 <<
"\">" << current_library
378 <<
"</a></td><td align=\"center\">" 379 << err_count <<
"</td></tr>\n";
386 std::cout <<
"</pre>\n" 388 "<table border=\"1\" cellpadding=\"5\" cellspacing=\"0\">\n" 390 " <td><b>Library</b></td>\n" 391 " <td><b>Problems</b></td>\n" 394 string current_library ( msgs.begin()->library );
396 for ( error_msg_vector::iterator itr ( msgs.begin() );
397 itr != msgs.end(); ++itr )
399 if ( current_library != itr->library )
401 display_summary_helper ( current_library, err_count );
402 current_library = itr->library;
409 std::cout <<
"</table>\n";
417 std::cout <<
"<h2>Details</h2>\n";
423 for ( error_msg_vector::iterator itr ( msgs.begin() );
424 itr != msgs.end(); ++itr )
426 if ( current.library != itr->library )
430 std::cout <<
"</pre>\n";
432 std::cout <<
"\n<h3><a name=\"" << itr->library
433 <<
"\">" << itr->library <<
"</a></h3>\n<pre>";
435 if ( current.library != itr->library
436 || current.rel_path != itr->rel_path )
439 std::cout << itr->rel_path;
442 if ( current.library != itr->library
443 || current.rel_path != itr->rel_path
444 || current.msg != itr->msg )
446 std::cout << sep << itr->msg;
449 current.library = itr->library;
450 current.rel_path = itr->rel_path;
451 current.msg = itr->msg;
454 std::cout <<
"</pre>\n";
467 "default is all checks on; otherwise options specify desired checks\n";
479 void inspector::register_signature (
const string& signature )
481 m_signatures.insert ( signature );
482 content_signatures.insert ( signature );
488 const path& full_path,
const string& msg )
495 msgs.push_back ( err_msg );
506 register_signature (
".c" );
507 register_signature (
".cpp" );
508 register_signature (
".css" );
509 register_signature (
".cxx" );
510 register_signature (
".h" );
511 register_signature (
".hpp" );
512 register_signature (
".hxx" );
513 register_signature (
".inc" );
514 register_signature (
".ipp" );
517 register_signature (
"Jamfile" );
518 register_signature (
".jam" );
519 register_signature (
".v2" );
522 register_signature (
"configure.in.in" );
523 register_signature (
"GNUmakefile" );
524 register_signature (
"Makefile.am" );
525 register_signature (
".bat" );
526 register_signature (
".mak" );
527 register_signature (
".pl" );
528 register_signature (
".py" );
529 register_signature (
".sh" );
532 register_signature (
"news" );
533 register_signature (
"readme" );
534 register_signature (
"todo" );
535 register_signature (
"NEWS" );
536 register_signature (
"README" );
537 register_signature (
"TODO" );
538 register_signature (
".boostbook" );
539 register_signature (
".htm" );
540 register_signature (
".html" );
541 register_signature (
".rst" );
542 register_signature (
".sgml" );
543 register_signature (
".shtml" );
544 register_signature (
".txt" );
545 register_signature (
".xml" );
546 register_signature (
".xsd" );
547 register_signature (
".xsl" );
552 register_signature (
".htm" );
553 register_signature (
".html" );
554 register_signature (
".shtml" );
561 path relative ( relative_to ( full_dir_path, fs::initial_path() ),
563 if ( relative.empty() )
567 string first ( *relative.begin() );
569 ++relative.begin() == relative.end()
570 ? string() : *++relative.begin();
572 if ( first ==
"life" )
574 return second.empty() ? string (
"unknown" ) : second;
577 return ( ( first ==
"testsuite" || first ==
"tools" ) && !second.empty() )
586 #include <boost/test/included/prg_exec_monitor.hpp> 592 if ( argc > 1 && (std::strcmp ( argv[1],
"-help" ) == 0
593 || std::strcmp ( argv[1],
"--help" ) == 0 ) )
595 std::clog <<
"Usage: inspect [-cvs] [options...]\n" 601 bool license_ck =
true;
602 bool copyright_ck =
true;
605 bool long_name_ck =
true;
607 bool minmax_ck =
true;
610 if ( argc > 1 && std::strcmp ( argv[1],
"-cvs" ) == 0 )
617 if ( argc > 1 && *argv[1] ==
'-' )
620 copyright_ck =
false;
623 long_name_ck =
false;
628 for (; argc > 1; --argc, ++argv )
630 if ( std::strcmp ( argv[1],
"-license" ) == 0 )
634 else if ( std::strcmp ( argv[1],
"-copyright" ) == 0 )
638 else if ( std::strcmp ( argv[1],
"-crlf" ) == 0 )
642 else if ( std::strcmp ( argv[1],
"-link" ) == 0 )
646 else if ( std::strcmp ( argv[1],
"-long_name" ) == 0 )
650 else if ( std::strcmp ( argv[1],
"-tab" ) == 0 )
654 else if ( std::strcmp ( argv[1],
"-minmax" ) == 0 )
660 std::cerr <<
"unknown option: " << argv[1]
661 <<
"\nvalid options are:\n" 671 inspectors.push_back ( inspector_element (
new boost::inspect::license_check ) );
675 inspectors.push_back ( inspector_element (
new boost::inspect::copyright_check ) );
679 inspectors.push_back ( inspector_element (
new boost::inspect::crlf_check ) );
685 inspectors.push_back ( inspector_element (
new boost::inspect::long_name_check ) );
689 inspectors.push_back ( inspector_element (
new boost::inspect::tab_check ) );
693 inspectors.push_back ( inspector_element (
new boost::inspect::minmax_check ) );
698 visit_all<hack::cvs_iterator> (
"lifev-root",
699 fs::initial_path(), inspectors );
701 visit_all<fs::directory_iterator> (
"lifev-root",
702 fs::initial_path(), inspectors );
705 for ( inspector_list::iterator itr = inspectors.begin();
706 itr != inspectors.end(); ++itr )
708 itr->inspector->close();
714 std::strftime ( run_date,
sizeof (run_date),
715 "%X UTC, %A %d %B %Y", std::gmtime ( &tod ) );
717 std::cout <<
"<html>\n" 719 "<title>LifeV Inspection Report</title>\n" 720 "<style type=\"text/css\">\n" 724 "<body bgcolor=\"#ffffff\" text=\"#000000\">\n" 725 "<h1>LifeV Inspection Report(95% based on Boost Inspection tool)</h1>\n" 726 "<p><b>Run Date:</b> " << run_date <<
"</p>\n" 727 "<h2>Introduction</h2>\n" 728 "<p>The <a href=\"http://www.boost.org/tools/inspect/index.html\">inspection\n" 729 "program</a> checks each file in the current Life CVS for various problems,\n" 730 "generating this web page as output. Problems detected include tabs in files,\n" 731 "missing copyrights, broken URL's, and similar misdemeanors.</p>\n";
734 "<p> Differences between <tt>LifeV::inspect</tt> and <tt>boost::inspect</tt>\n" 736 "<li>LifeV::inspect is good looking thanks to proper css usage :)</li>\n" 737 "<li>LifeV::inspect does not check in admin, Templates and autom4te.cache</li>\n" 738 "<li>LifeV::inspect checks for GPL and LGPL presence in header and not Boost License</li>\n" 739 "<li>LifeV::inspect does not check for links</li>\n" 742 std::cout <<
"<h2>Totals</h2>\n<pre>" 743 << file_count <<
" files scanned\n" 744 << directory_count <<
" directories scanned\n" 745 << error_count <<
" problems reported\n";
747 std::cout <<
"\nproblem counts:\n";
749 for ( inspector_list::iterator itr = inspectors.begin();
750 itr != inspectors.end(); ++itr )
752 itr->inspector.reset();
755 std::sort ( msgs.begin(), msgs.end() );
763 std::cout <<
"</body>\n" string impute_library(const path &full_dir_path)
int cpp_main(int argc, char *argv[])
inspector_element(boost::inspect::inspector *p)
bool operator<(const error_msg &rhs) const
std::vector< error_msg > error_msg_vector
void visit_all(const string &lib, const path &dir_path, const inspector_list &insps)
void load_content(const path &file_path, string &target)
bool(* pred_type)(const path &)
std::set< string > string_set
string relative_to(const path &src_arg, const path &base_arg)
void check(const string &lib, const path &pth, const string &content, const inspector_list &insp_list)
std::shared_ptr< boost::inspect::inspector > inspector_ptr
boost::inspect::string_set content_signatures
std::list< inspector_element > inspector_list
void display_summary_helper(const string ¤t_library, int err_count)
string library_from_content(const string &content)
bool find_signature(const path &file_path, const boost::inspect::string_set &signatures)
bool visit_predicate(const path &pth)