LifeV
long_name_check.cpp
Go to the documentation of this file.
1 // long_name_check implementation ------------------------------------------//
2 
3 // Copyright Beman Dawes 2002.
4 // Distributed under the Boost Software License, Version 1.0.
5 // (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 
9 
10 #include <boost/filesystem/operations.hpp>
11 #include <boost/filesystem/exception.hpp>
12 #include <boost/bind.hpp>
13 #include <boost/next_prior.hpp>
14 
15 #include <locale>
16 #include <algorithm>
17 
18 namespace
19 {
20 namespace aux
21 {
22 
23 bool starts_with_nonalpha ( std::string const& x )
24 {
25  return !std::isalpha ( *x.begin(), std::locale::classic() )
26  && *x.begin() != '_'
27  && x != ".cvsignore"
28  ;
29 }
30 
31 bool contains_dot ( std::string const& x )
32 {
33  return x.find ( '.' ) != std::string::npos;
34 }
35 
36 }
37 }
38 
39 
40 namespace boost
41 {
42 namespace inspect
43 {
45 
46 void long_name_check::inspect (
47  const string& library_name,
48  const path& full_path )
49 {
50  std::string const leaf ( full_path.leaf() );
51 
52  if ( leaf.size() > 31 )
53  {
55  error ( library_name, full_path, "filename > 31 chars" );
56  }
57 
58  if ( std::count ( leaf.begin(), leaf.end(), '.' ) > 1 )
59  {
61  error ( library_name, full_path, "filename contains more than one dot character ('.')" );
62  }
63 
64  if ( *leaf.rbegin() == '.' )
65  {
67  error ( library_name, full_path, "filename ends with the dot character ('.')" );
68  }
69 
70  path const relative_path ( relative_to ( full_path, filesystem::initial_path() ), &filesystem::no_check );
71 
72  if ( std::find_if ( relative_path.begin(), relative_path.end(), boost::bind ( &aux::starts_with_nonalpha, _1 ) )
73  != relative_path.end() )
74  {
76  error ( library_name, full_path, "leading character of one of the path compontents is not alphabetic" );
77  }
78 
79  if ( std::find_if ( relative_path.begin(), boost::prior ( relative_path.end() )
80  , boost::bind ( &aux::contains_dot, _1 ) ) != boost::prior ( relative_path.end() ) )
81  {
83  error ( library_name, full_path, "directory name contains the dot character ('.')" );
84  }
85 
86  if ( std::distance ( relative_path.begin(), boost::prior ( relative_path.end() ) ) >= 8 )
87  {
89  error ( library_name, full_path, "file's directory depth will exceed 8 levels if placed on a CD" );
90  }
91 
92  if ( relative_path.string().size() > ( 100 - string ( "boost_X_XX_X/" ).size() ) )
93  {
95  error ( library_name, full_path, "file path will be > 100 chars if placed on a CD" );
96  }
97 
98  try
99  {
100  path const check_portability ( relative_path.string(), &filesystem::portable_name );
101  }
102  catch ( filesystem::filesystem_error const& )
103  {
105  error ( library_name, full_path, "nonportable path" );
106  }
107 
108 }
109 
111 {
112  std::cout << " " << m_long_name_errors << " " << desc() << '\n';
113 }
114 
115 
116 } // namespace inspect
117 } // namespace boost