Boost logo

Boost-Commit :

From: bdawes_at_[hidden]
Date: 2008-06-29 14:00:13


Author: bemandawes
Date: 2008-06-29 14:00:13 EDT (Sun, 29 Jun 2008)
New Revision: 46871
URL: http://svn.boost.org/trac/boost/changeset/46871

Log:
Rework path_name_check to give better coverage, more accurate results
Text files modified:
   trunk/tools/inspect/path_name_check.cpp | 97 +++++++++++++++++++++------------------
   trunk/tools/inspect/path_name_check.hpp | 11 ----
   2 files changed, 53 insertions(+), 55 deletions(-)

Modified: trunk/tools/inspect/path_name_check.cpp
==============================================================================
--- trunk/tools/inspect/path_name_check.cpp (original)
+++ trunk/tools/inspect/path_name_check.cpp 2008-06-29 14:00:13 EDT (Sun, 29 Jun 2008)
@@ -12,33 +12,23 @@
 #include "boost/filesystem/operations.hpp"
 #include "boost/lexical_cast.hpp"
 
-#include <locale>
+#include <string>
 #include <algorithm>
+#include <cctype>
 
-namespace { namespace aux {
+using std::string;
 
-bool starts_with_nonalnum( path const & p )
+namespace
 {
- const string & x = p.string();
- assert(!x.empty());
-
- const string::value_type first = x[0];
-
- return !std::isalnum( first, std::locale::classic() )
- && first != '_'
- && x != ".cvsignore"
- && x != ".svn"
- ;
+ const char allowable[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-.";
+ const char initial_char[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
 }
 
-}}
-
-
 namespace boost
 {
   namespace inspect
   {
- const char file_name_check::limits::name[] = "ISO 9660:1999 Level 3";
+
 
     file_name_check::file_name_check() : m_name_errors(0) {}
 
@@ -46,31 +36,60 @@
       const string & library_name,
       const path & full_path )
     {
- std::string const leaf( full_path.leaf() );
+ string::size_type pos;
+
+ // called for each file and directory, so only the leaf need be tested
+ string const leaf( full_path.leaf() );
 
- if ( *leaf.rbegin() == '.' )
+ // includes only allowable characters
+ if ( (pos = leaf.find_first_not_of( allowable )) != string::npos )
       {
         ++m_name_errors;
         error( library_name, full_path, string(name())
- + " filename ends with the dot character ('.')" );
+ + " file or directory name contains unacceptable character '"
+ + leaf[pos] + "'" );
       }
 
- path const relative_path(
- relative_to( full_path, filesystem::initial_path() )
- , &filesystem::no_check );
-
-
- // checks on the directory name --------------------------- //
-
- if( aux::starts_with_nonalnum( path(leaf)) )
+ // begins with an alphabetic character
+ if ( std::strchr( initial_char, leaf[0] ) == 0 )
       {
         ++m_name_errors;
         error( library_name, full_path, string(name())
- + " leading character of \""
- + leaf + "\""
- + " is not alphanumeric" );
+ + " file or directory name begins with an unacceptable character" );
+ }
+
+ // rules for dot characters differ slightly for directories and files
+ if ( filesystem::is_directory( full_path ) )
+ {
+ if ( std::strchr( leaf.c_str(), '.' ) )
+ {
+ ++m_name_errors;
+ error( library_name, full_path, string(name())
+ + " directory name contains a dot character ('.')" );
+ }
+ }
+ else // not a directory
+ {
+ // includes at most one dot character
+ const char * first_dot = std::strchr( leaf.c_str(), '.' );
+ if ( first_dot && std::strchr( first_dot+1, '.' ) )
+ {
+ ++m_name_errors;
+ error( library_name, full_path, string(name())
+ + " file name with more than one dot character ('.')" );
+ }
+
+ // does not end with a dot character
+ if ( *leaf.rbegin() == '.' )
+ {
+ ++m_name_errors;
+ error( library_name, full_path, string(name())
+ + " file name ends with a dot character ('.')" );
+ }
       }
 
+ // the path, including a presumed root, does not exceed the maximum size
+ path const relative_path( relative_to( full_path, filesystem::initial_path() ) );
       const unsigned max_relative_path = 207; // ISO 9660:1999 sets this limit
       const string generic_root( "boost_X_XX_X/" );
       if ( relative_path.string().size() >
@@ -79,25 +98,13 @@
         ++m_name_errors;
         error( library_name, full_path,
             string(name())
- + " file path will exceed "
+ + " path will exceed "
             + boost::lexical_cast<string>(max_relative_path)
- + " characters in a directory tree with a root of the form "
+ + " characters in a directory tree with a root in the form "
             + generic_root + ", and this exceeds ISO 9660:1999 limit of 207" )
             ;
       }
 
- if (relative_path.leaf() != ".cvsignore" && relative_path.leaf() != ".svn")
- {
- try
- {
- path const check_portability( relative_path.string(), &filesystem::portable_name );
- }
- catch ( filesystem::filesystem_error const& )
- {
- ++m_name_errors;
- error( library_name, full_path, string(name()) + " nonportable path" );
- }
- }
     }
 
     file_name_check::~file_name_check()

Modified: trunk/tools/inspect/path_name_check.hpp
==============================================================================
--- trunk/tools/inspect/path_name_check.hpp (original)
+++ trunk/tools/inspect/path_name_check.hpp 2008-06-29 14:00:13 EDT (Sun, 29 Jun 2008)
@@ -21,22 +21,13 @@
     {
       long m_name_errors;
 
- // ISO 9660 Level 3
- //
- struct iso_9660_limits
- {
- static const char name[];
- };
-
     public:
 
- typedef iso_9660_limits limits;
-
       file_name_check();
       virtual ~file_name_check();
 
       virtual const char * name() const { return "*N*"; }
- virtual const char * desc() const { return "file/directory names issues"; }
+ virtual const char * desc() const { return "file and directory name issues"; }
 
       virtual void inspect(
         const string & library_name,


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