Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r59138 - trunk/tools/inspect
From: bdawes_at_[hidden]
Date: 2010-01-19 07:48:40


Author: bemandawes
Date: 2010-01-19 07:48:39 EST (Tue, 19 Jan 2010)
New Revision: 59138
URL: http://svn.boost.org/trac/boost/changeset/59138

Log:
Show line numbers where applicable. Apple macro clash show name. Optimize html line output spacing
Text files modified:
   trunk/tools/inspect/apple_macro_check.cpp | 6 +-
   trunk/tools/inspect/ascii_check.cpp | 3 +
   trunk/tools/inspect/inspect.cpp | 31 +++++++++++----
   trunk/tools/inspect/inspector.hpp | 3 +
   trunk/tools/inspect/link_check.cpp | 80 +++++++++++++++++++++++++++-------------
   trunk/tools/inspect/link_check.hpp | 3 +
   trunk/tools/inspect/unnamed_namespace_check.cpp | 3 -
   7 files changed, 87 insertions(+), 42 deletions(-)

Modified: trunk/tools/inspect/apple_macro_check.cpp
==============================================================================
--- trunk/tools/inspect/apple_macro_check.cpp (original)
+++ trunk/tools/inspect/apple_macro_check.cpp 2010-01-19 07:48:39 EST (Tue, 19 Jan 2010)
@@ -80,9 +80,9 @@
           }
 
           ++m_files_with_errors;
- error( library_name, full_path, string(name())
- + " violation of Boost apple-macro guidelines on line "
- + boost::lexical_cast<string>( line_number ) );
+ error( library_name, full_path,
+ "Apple macro clash: " + std::string((*cur)[0].first, (*cur)[0].second-1),
+ line_number );
         }
       }
     }

Modified: trunk/tools/inspect/ascii_check.cpp
==============================================================================
--- trunk/tools/inspect/ascii_check.cpp (original)
+++ trunk/tools/inspect/ascii_check.cpp 2010-01-19 07:48:39 EST (Tue, 19 Jan 2010)
@@ -91,8 +91,9 @@
       if ( bad_char != contents.end ())
       {
         ++m_files_with_errors;
+ int ln = std::count( contents.begin(), bad_char, '\n' ) + 1;
         string the_line = find_line ( contents, bad_char );
- error( library_name, full_path, string ( name()) + " non-ASCII: " + the_line );
+ error( library_name, full_path, "Non-ASCII: " + the_line, ln );
       }
     }
   } // namespace inspect

Modified: trunk/tools/inspect/inspect.cpp
==============================================================================
--- trunk/tools/inspect/inspect.cpp (original)
+++ trunk/tools/inspect/inspect.cpp 2010-01-19 07:48:39 EST (Tue, 19 Jan 2010)
@@ -22,6 +22,7 @@
 #include <cstring>
 
 #include "boost/shared_ptr.hpp"
+#include "boost/lexical_cast.hpp"
 #include "boost/filesystem/operations.hpp"
 #include "boost/filesystem/fstream.hpp"
 
@@ -76,6 +77,7 @@
     string library;
     string rel_path;
     string msg;
+ int line_number;
 
     bool operator<( const error_msg & rhs ) const
     {
@@ -83,6 +85,8 @@
       if ( library > rhs.library ) return false;
       if ( rel_path < rhs.rel_path ) return true;
       if ( rel_path > rhs.rel_path ) return false;
+ if ( line_number < rhs.line_number ) return true;
+ if ( line_number > rhs.line_number ) return false;
       return msg < rhs.msg;
     }
   };
@@ -400,11 +404,11 @@
       }
       std::cout << "\n";
     }
- else
+ else // html
     {
       // display error messages with group indication
       error_msg current;
- string sep;
+ bool first_sep = true;
       bool first = true;
       for ( error_msg_vector::iterator itr ( msgs.begin() );
         itr != msgs.end(); ++itr )
@@ -420,16 +424,26 @@
         {
           std::cout << "\n";
           std::cout << itr->rel_path;
-// sep = ": ";
- sep = ":<br>&nbsp;&nbsp;&nbsp; ";
+ first_sep = true;
         }
         if ( current.library != itr->library
           || current.rel_path != itr->rel_path
           || current.msg != itr->msg )
         {
- std::cout << sep << itr->msg;
-// sep = ", ";
- sep = "<br>&nbsp;&nbsp;&nbsp; ";
+ std::string sep;
+ if (first_sep)
+ if (itr->line_number) sep = ":<br>&nbsp;&nbsp;&nbsp; ";
+ else sep = ": ";
+ else
+ if (itr->line_number) sep = "<br>&nbsp;&nbsp;&nbsp; ";
+ else sep = ", ";
+
+ // print the message
+ if (itr->line_number)
+ std::cout << sep << "(line " << itr->line_number << ") " << itr->msg;
+ else std::cout << sep << itr->msg;
+
+ first_sep = false;
         }
         current.library = itr->library;
         current.rel_path = itr->rel_path;
@@ -583,13 +597,14 @@
 // error -------------------------------------------------------------------//
 
     void inspector::error( const string & library_name,
- const path & full_path, const string & msg )
+ const path & full_path, const string & msg, int line_number )
     {
       ++error_count;
       error_msg err_msg;
       err_msg.library = library_name;
       err_msg.rel_path = relative_to( full_path, fs::initial_path() );
       err_msg.msg = msg;
+ err_msg.line_number = line_number;
       msgs.push_back( err_msg );
 
 // std::cout << library_name << ": "

Modified: trunk/tools/inspect/inspector.hpp
==============================================================================
--- trunk/tools/inspect/inspector.hpp (original)
+++ trunk/tools/inspect/inspector.hpp 2010-01-19 07:48:39 EST (Tue, 19 Jan 2010)
@@ -64,7 +64,8 @@
       void error(
         const string & library_name,
         const path & full_path,
- const string & msg );
+ const string & msg,
+ int line_number =0 ); // 0 if not available or not applicable
 
     private:
       string_set m_signatures;

Modified: trunk/tools/inspect/link_check.cpp
==============================================================================
--- trunk/tools/inspect/link_check.cpp (original)
+++ trunk/tools/inspect/link_check.cpp 2010-01-19 07:48:39 EST (Tue, 19 Jan 2010)
@@ -148,9 +148,9 @@
       {
         while( boost::regex_search( a_start, a_end, a_what, html_bookmark_regex, a_flags) )
         {
- // what[0] contains the whole string iterators.
- // what[1] contains the tag iterators.
- // what[3] contains the bookmark iterators.
+ // a_what[0] contains the whole string iterators.
+ // a_what[1] contains the tag iterators.
+ // a_what[3] contains the bookmark iterators.
 
           string tag( a_what[1].first, a_what[1].second );
           boost::algorithm::to_lower(tag);
@@ -171,8 +171,8 @@
             if (!result.second)
             {
               ++m_duplicate_bookmark_errors;
- error( library_name, full_path, string(name()) +
- " duplicate bookmark: " + bookmark );
+ int ln = std::count( contents.begin(), a_what[3].first, '\n' ) + 1;
+ error( library_name, full_path, "Duplicate bookmark: " + bookmark, ln );
             }
           }
 
@@ -202,7 +202,7 @@
           // TODO: Complain if 'link' tags use external stylesheets.
           do_url( string( what[3].first, what[3].second ),
             library_name, full_path, no_link_errors,
- type == "a" || type == "link" );
+ type == "a" || type == "link", contents.begin(), what[3].first );
 
           start = what[0].second; // update search position
           flags |= boost::match_prev_avail; // update flags
@@ -215,7 +215,8 @@
         // what[0] contains the whole string iterators.
         // what[2] contains the URL iterators.
         do_url( string( what[2].first, what[2].second ),
- library_name, full_path, no_link_errors, false );
+ library_name, full_path, no_link_errors, false,
+ contents.begin(), what[3].first );
 
         start = what[0].second; // update search position
         flags |= boost::match_prev_avail; // update flags
@@ -226,12 +227,14 @@
 // do_url ------------------------------------------------------------------//
 
     void link_check::do_url( const string & url, const string & library_name,
- const path & source_path, bool no_link_errors, bool allow_external_content )
+ const path & source_path, bool no_link_errors, bool allow_external_content,
+ std::string::const_iterator contents_begin, std::string::const_iterator url_start )
         // precondition: source_path.is_complete()
     {
       if(!no_link_errors && url.empty()) {
         ++m_invalid_errors;
- error( library_name, source_path, string(name()) + " empty URL." );
+ int ln = std::count( contents_begin, url_start, '\n' ) + 1;
+ error( library_name, source_path, "Empty URL.", ln );
         return;
       }
 
@@ -240,7 +243,9 @@
       if(decoded_url.empty()) {
         if(!no_link_errors) {
           ++m_invalid_errors;
- error( library_name, source_path, string(name()) + " invalid URL (invalid ampersand encodings): " + url );
+ int ln = std::count( contents_begin, url_start, '\n' ) + 1;
+ error( library_name, source_path,
+ "Invalid URL (invalid ampersand encodings): " + url, ln );
         }
         return;
       }
@@ -249,7 +254,8 @@
       if(!boost::regex_match(decoded_url, m, url_decompose_regex)) {
         if(!no_link_errors) {
           ++m_invalid_errors;
- error( library_name, source_path, string(name()) + " invalid URL: " + decoded_url );
+ int ln = std::count( contents_begin, url_start, '\n' ) + 1;
+ error( library_name, source_path, "Invalid URL: " + decoded_url, ln );
         }
         return;
       }
@@ -269,7 +275,8 @@
       if(!allow_external_content && (authority_matched || scheme_matched)) {
         if(!no_link_errors) {
           ++m_invalid_errors;
- error( library_name, source_path, string(name()) + " external content: " + decoded_url );
+ int ln = std::count( contents_begin, url_start, '\n' ) + 1;
+ error( library_name, source_path, "External content: " + decoded_url, ln );
         }
       }
 
@@ -282,7 +289,8 @@
           if(!authority_matched) {
             if(!no_link_errors) {
               ++m_invalid_errors;
- error( library_name, source_path, string(name()) + " no hostname: " + decoded_url );
+ int ln = std::count( contents_begin, url_start, '\n' ) + 1;
+ error( library_name, source_path, "No hostname: " + decoded_url, ln );
             }
           }
 
@@ -291,19 +299,24 @@
         else if(scheme == "file") {
           if(!no_link_errors) {
             ++m_invalid_errors;
- error( library_name, source_path, string(name()) + " invalid URL (hardwired file): " + decoded_url );
+ int ln = std::count( contents_begin, url_start, '\n' ) + 1;
+ error( library_name, source_path,
+ "Invalid URL (hardwired file): " + decoded_url, ln );
           }
         }
         else if(scheme == "mailto" || scheme == "ftp" || scheme == "news" || scheme == "javascript") {
           if ( !no_link_errors && is_css(source_path) ) {
             ++m_invalid_errors;
- error( library_name, source_path, string(name()) + " invalid protocol for css: " + decoded_url );
+ int ln = std::count( contents_begin, url_start, '\n' ) + 1;
+ error( library_name, source_path,
+ "Invalid protocol for css: " + decoded_url, ln );
           }
         }
         else {
           if(!no_link_errors) {
             ++m_invalid_errors;
- error( library_name, source_path, string(name()) + " unknown protocol: " + decoded_url );
+ int ln = std::count( contents_begin, url_start, '\n' ) + 1;
+ error( library_name, source_path, "Unknown protocol: " + decoded_url, ln );
           }
         }
 
@@ -314,7 +327,9 @@
       if(authority_matched) {
         if(!no_link_errors) {
           ++m_invalid_errors;
- error( library_name, source_path, string(name()) + " invalid URL (hostname without protocol): " + decoded_url );
+ int ln = std::count( contents_begin, url_start, '\n' ) + 1;
+ error( library_name, source_path,
+ "Invalid URL (hostname without protocol): " + decoded_url, ln );
         }
       }
 
@@ -323,14 +338,17 @@
         if ( is_css(source_path) ) {
             if ( !no_link_errors ) {
               ++m_invalid_errors;
- error( library_name, source_path, string(name()) + " fragment link in CSS: " + decoded_url );
+ int ln = std::count( contents_begin, url_start, '\n' ) + 1;
+ error( library_name, source_path,
+ "Fragment link in CSS: " + decoded_url, ln );
             }
         }
         else {
           if ( !no_link_errors && fragment.find( '#' ) != string::npos )
           {
             ++m_bookmark_errors;
- error( library_name, source_path, string(name()) + " invalid bookmark: " + decoded_url );
+ int ln = std::count( contents_begin, url_start, '\n' ) + 1;
+ error( library_name, source_path, "Invalid bookmark: " + decoded_url, ln );
           }
           else if ( !no_link_errors && url_path.empty() && !fragment.empty()
             // w3.org recommends case-sensitive broken bookmark checking
@@ -338,7 +356,8 @@
             && bookmarks.find(decode_percents(fragment)) == bookmarks.end() )
           {
             ++m_bookmark_errors;
- error( library_name, source_path, string(name()) + " unknown bookmark: " + decoded_url );
+ int ln = std::count( contents_begin, url_start, '\n' ) + 1;
+ error( library_name, source_path, "Unknown bookmark: " + decoded_url, ln );
           }
         }
 
@@ -350,14 +369,18 @@
       if ( !no_link_errors && decoded_url.find_first_of( " <>\"{}|\\^[]'" ) != string::npos )
       {
         ++m_invalid_errors;
- error( library_name, source_path, string(name()) + " invalid character in URL: " + decoded_url );
+ int ln = std::count( contents_begin, url_start, '\n' ) + 1;
+ error( library_name, source_path,
+ "Invalid character in URL: " + decoded_url, ln );
       }
 
       // Check that we actually have a path.
       if(url_path.empty()) {
         if(!no_link_errors) {
           ++m_invalid_errors;
- error( library_name, source_path, string(name()) + " invalid URL (empty path in relative url): " + decoded_url );
+ int ln = std::count( contents_begin, url_start, '\n' ) + 1;
+ error( library_name, source_path,
+ "Invalid URL (empty path in relative url): " + decoded_url, ln );
         }
       }
 
@@ -366,7 +389,9 @@
       if(decoded_path.empty()) {
         if(!no_link_errors) {
           ++m_invalid_errors;
- error( library_name, source_path, string(name()) + " invalid URL (invalid character encodings): " + decoded_url );
+ int ln = std::count( contents_begin, url_start, '\n' ) + 1;
+ error( library_name, source_path,
+ "Invalid URL (invalid character encodings): " + decoded_url, ln );
         }
         return;
       }
@@ -381,8 +406,10 @@
       catch ( const fs::filesystem_error & )
       {
         if(!no_link_errors) {
+ int ln = std::count( contents_begin, url_start, '\n' ) + 1;
           ++m_invalid_errors;
- error( library_name, source_path, string(name()) + " invalid URL (error resolving path): " + decoded_url );
+ error( library_name, source_path,
+ "Invalid URL (error resolving path): " + decoded_url, ln );
         }
         return;
       }
@@ -404,7 +431,8 @@
       if ( !no_link_errors && (itr->second & m_present) == 0 )
       {
         ++m_broken_errors;
- error( library_name, source_path, string(name()) + " broken link: " + decoded_url );
+ int ln = std::count( contents_begin, url_start, '\n' ) + 1;
+ error( library_name, source_path, "Broken link: " + decoded_url, ln );
       }
     }
 
@@ -427,7 +455,7 @@
        {
          ++m_unlinked_errors;
          path full_path( fs::initial_path() / path(itr->first, fs::no_check) );
- error( impute_library( full_path ), full_path, string(name()) + " unlinked file" );
+ error( impute_library( full_path ), full_path, "Unlinked file" );
        }
      }
    }

Modified: trunk/tools/inspect/link_check.hpp
==============================================================================
--- trunk/tools/inspect/link_check.hpp (original)
+++ trunk/tools/inspect/link_check.hpp 2010-01-19 07:48:39 EST (Tue, 19 Jan 2010)
@@ -34,7 +34,8 @@
 
       void do_url( const string & url, const string & library_name,
         const path & full_source_path, bool no_link_errors,
- bool allow_external_links );
+ bool allow_external_links,
+ std::string::const_iterator contents_begin, std::string::const_iterator url_start);
     public:
 
       link_check();

Modified: trunk/tools/inspect/unnamed_namespace_check.cpp
==============================================================================
--- trunk/tools/inspect/unnamed_namespace_check.cpp (original)
+++ trunk/tools/inspect/unnamed_namespace_check.cpp 2010-01-19 07:48:39 EST (Tue, 19 Jan 2010)
@@ -51,8 +51,7 @@
         const string::size_type
          ln = std::count( contents.begin(), (*cur)[0].first, '\n' ) + 1;
 
- error( library_name, full_path, string(name()) + " unnamed namespace at line "
- + lexical_cast<string>(ln) );
+ error( library_name, full_path, "Unnamed namespace", ln );
       }
 
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk