Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r53925 - in trunk/tools/inspect: . build
From: daniel_james_at_[hidden]
Date: 2009-06-15 03:38:00


Author: danieljames
Date: 2009-06-15 03:37:59 EDT (Mon, 15 Jun 2009)
New Revision: 53925
URL: http://svn.boost.org/trac/boost/changeset/53925

Log:
Check that all C and C++ files end with a newline. Fixes #3174
Added:
   trunk/tools/inspect/end_check.cpp (contents, props changed)
   trunk/tools/inspect/end_check.hpp (contents, props changed)
Text files modified:
   trunk/tools/inspect/build/Jamfile.v2 | 2 +-
   trunk/tools/inspect/inspect.cpp | 8 ++++++++
   trunk/tools/inspect/run_inspect.sh | 1 +
   3 files changed, 10 insertions(+), 1 deletions(-)

Modified: trunk/tools/inspect/build/Jamfile.v2
==============================================================================
--- trunk/tools/inspect/build/Jamfile.v2 (original)
+++ trunk/tools/inspect/build/Jamfile.v2 2009-06-15 03:37:59 EDT (Mon, 15 Jun 2009)
@@ -14,7 +14,7 @@
 
 exe inspect
     :
- inspect.cpp license_check.cpp link_check.cpp path_name_check.cpp tab_check.cpp crlf_check.cpp unnamed_namespace_check.cpp ascii_check.cpp
+ inspect.cpp license_check.cpp link_check.cpp path_name_check.cpp tab_check.cpp crlf_check.cpp end_check.cpp unnamed_namespace_check.cpp ascii_check.cpp
     copyright_check.cpp minmax_check.cpp
     /boost//filesystem/<link>static
     /boost//regex/<link>static

Added: trunk/tools/inspect/end_check.cpp
==============================================================================
--- (empty file)
+++ trunk/tools/inspect/end_check.cpp 2009-06-15 03:37:59 EDT (Mon, 15 Jun 2009)
@@ -0,0 +1,58 @@
+// end_check implementation -------------------------------------------------//
+
+// Copyright Beman Dawes 2002.
+// Copyright Daniel James 2009.
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include "end_check.hpp"
+#include <boost/next_prior.hpp>
+
+namespace boost
+{
+ namespace inspect
+ {
+ end_check::end_check() : m_files_with_errors(0)
+ {
+ register_signature( ".c" );
+ register_signature( ".cpp" );
+ register_signature( ".cxx" );
+ register_signature( ".h" );
+ register_signature( ".hpp" );
+ register_signature( ".hxx" );
+ register_signature( ".ipp" );
+ }
+
+ void end_check::inspect(
+ const string & library_name,
+ const path & full_path, // example: c:/foo/boost/filesystem/path.hpp
+ const string & contents ) // contents of file to be inspected
+ {
+ if (contents.find( "boostinspect:" "noend" ) != string::npos) return;
+
+ // this file deliberately contains errors
+ const char test_file_name[] = "wrong_line_ends_test.cpp";
+
+ char final_char = contents.begin() == contents.end() ? '\0'
+ : *(boost::prior(contents.end()));
+
+ bool failed = final_char != '\n' && final_char != '\r';
+
+ if (failed && full_path.leaf() != test_file_name)
+ {
+ ++m_files_with_errors;
+ error( library_name, full_path, string(name()) + ' ' + desc() );
+ }
+
+ if (!failed && full_path.leaf() == test_file_name)
+ {
+ ++m_files_with_errors;
+ error( library_name, full_path, string(name()) + " should not end with a newline" );
+ }
+ }
+ } // namespace inspect
+} // namespace boost
+
+

Added: trunk/tools/inspect/end_check.hpp
==============================================================================
--- (empty file)
+++ trunk/tools/inspect/end_check.hpp 2009-06-15 03:37:59 EDT (Mon, 15 Jun 2009)
@@ -0,0 +1,40 @@
+// end_check header ---------------------------------------------------------//
+
+// Copyright Beman Dawes 2002.
+// Copyright Rene Rivera 2004.
+// Copyright Daniel James 2009.
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_END_CHECK_HPP
+#define BOOST_END_CHECK_HPP
+
+#include "inspector.hpp"
+
+namespace boost
+{
+ namespace inspect
+ {
+ class end_check : public inspector
+ {
+ long m_files_with_errors;
+ public:
+
+ end_check();
+ virtual const char * name() const { return "*END*"; }
+ virtual const char * desc() const { return "file doesn't end with a newline"; }
+
+ virtual void inspect(
+ const std::string & library_name,
+ const path & full_path,
+ const std::string & contents );
+
+ virtual ~end_check()
+ { std::cout << " " << m_files_with_errors << " files that don't end with a newline" << line_break(); }
+ };
+ }
+}
+
+#endif // BOOST_END_CHECK_HPP

Modified: trunk/tools/inspect/inspect.cpp
==============================================================================
--- trunk/tools/inspect/inspect.cpp (original)
+++ trunk/tools/inspect/inspect.cpp 2009-06-15 03:37:59 EDT (Mon, 15 Jun 2009)
@@ -32,6 +32,7 @@
 // the inspectors
 #include "copyright_check.hpp"
 #include "crlf_check.hpp"
+#include "end_check.hpp"
 #include "license_check.hpp"
 #include "link_check.hpp"
 #include "path_name_check.hpp"
@@ -523,6 +524,7 @@
          " -license\n"
          " -copyright\n"
          " -crlf\n"
+ " -end\n"
          " -link\n"
          " -path_name\n"
          " -tab\n"
@@ -692,6 +694,7 @@
   bool license_ck = true;
   bool copyright_ck = true;
   bool crlf_ck = true;
+ bool end_ck = true;
   bool link_ck = true;
   bool path_name_ck = true;
   bool tab_ck = true;
@@ -723,6 +726,7 @@
     license_ck = false;
     copyright_ck = false;
     crlf_ck = false;
+ end_ck = false;
     link_ck = false;
     path_name_ck = false;
     tab_ck = false;
@@ -740,6 +744,8 @@
       copyright_ck = true;
     else if ( std::strcmp( argv[1], "-crlf" ) == 0 )
         crlf_ck = true;
+ else if ( std::strcmp( argv[1], "-end" ) == 0 )
+ end_ck = true;
     else if ( std::strcmp( argv[1], "-link" ) == 0 )
       link_ck = true;
     else if ( std::strcmp( argv[1], "-path_name" ) == 0 )
@@ -781,6 +787,8 @@
     inspectors.push_back( inspector_element( new boost::inspect::copyright_check ) );
   if ( crlf_ck )
     inspectors.push_back( inspector_element( new boost::inspect::crlf_check ) );
+ if ( end_ck )
+ inspectors.push_back( inspector_element( new boost::inspect::end_check ) );
   if ( link_ck )
     inspectors.push_back( inspector_element( new boost::inspect::link_check ) );
   if ( path_name_ck )

Modified: trunk/tools/inspect/run_inspect.sh
==============================================================================
--- trunk/tools/inspect/run_inspect.sh (original)
+++ trunk/tools/inspect/run_inspect.sh 2009-06-15 03:37:59 EDT (Mon, 15 Jun 2009)
@@ -34,6 +34,7 @@
 cd boost_${cvs_branch}
 opt=""
 opt="${opt} -crlf"
+opt="${opt} -end"
 opt="${opt} -link"
 opt="${opt} -long_name"
 opt="${opt} -tab"


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