]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/bcp/bcp_imp.cpp
3 * Copyright (c) 2003 Dr John Maddock
4 * Use, modification and distribution is subject to the
5 * Boost Software License, Version 1.0. (See accompanying file
6 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 * This file implements the bcp_implementation virtuals.
11 #include "bcp_imp.hpp"
12 #include "licence_info.hpp"
13 #include <boost/filesystem/operations.hpp>
14 #include <boost/filesystem/fstream.hpp>
17 #include <boost/regex.hpp>
20 bcp_implementation::bcp_implementation()
21 : m_list_mode(false), m_list_summary_mode(false), m_license_mode(false), m_cvs_mode(false),
22 m_svn_mode(false), m_unix_lines(false), m_scan_mode(false), m_bsl_convert_mode(false),
23 m_bsl_summary_mode(false), m_namespace_alias(false), m_list_namespaces(false)
27 bcp_implementation::~bcp_implementation()
31 bcp_application::~bcp_application()
35 void bcp_implementation::enable_list_mode()
40 void bcp_implementation::enable_summary_list_mode()
43 m_list_summary_mode
= true;
46 void bcp_implementation::enable_cvs_mode()
51 void bcp_implementation::enable_svn_mode()
56 void bcp_implementation::enable_scan_mode()
61 void bcp_implementation::enable_license_mode()
63 m_license_mode
= true;
66 void bcp_implementation::enable_bsl_convert_mode()
68 m_bsl_convert_mode
= true;
71 void bcp_implementation::enable_bsl_summary_mode()
73 m_bsl_summary_mode
= true;
76 void bcp_implementation::enable_unix_lines()
81 void bcp_implementation::set_boost_path(const char* p
)
83 // Hack to strip trailing slashes from the path
84 m_boost_path
= (fs::path(p
) / "boost").parent_path();
85 fs::path check
= m_boost_path
/ "boost" / "version.hpp";
86 if(!fs::exists(check
))
88 std::string s
= "The Boost path appears to have been incorrectly set: could not find boost/version.hpp in ";
89 s
+= m_boost_path
.string();
90 std::runtime_error
e(s
);
95 void bcp_implementation::set_destination(const char* p
)
97 m_dest_path
= fs::path(p
);
100 void bcp_implementation::add_module(const char* p
)
102 m_module_list
.push_back(p
);
105 void bcp_implementation::set_namespace(const char* name
)
107 m_namespace_name
= name
;
110 void bcp_implementation::set_namespace_alias(bool b
)
112 m_namespace_alias
= b
;
115 void bcp_implementation::set_namespace_list(bool b
)
117 m_list_namespaces
= b
;
121 fs::path
get_short_path(const fs::path
& p
)
123 // truncate path no more than "x/y":
124 std::string s
= p
.generic_string();
125 std::string::size_type n
= s
.find('/');
126 if(n
!= std::string::npos
)
128 n
= s
.find('/', n
+1);
129 if(n
!= std::string::npos
)
135 int bcp_implementation::run()
138 // check output path is OK:
140 if(!m_list_mode
&& !m_license_mode
&& !fs::exists(m_dest_path
))
142 std::string
msg("Destination path does not exist: ");
143 msg
.append(m_dest_path
.string());
144 std::runtime_error
e(msg
);
145 boost::throw_exception(e
);
148 // Check Boost path is OK if it hasn't been checked already:
150 if(m_boost_path
== "")
154 // start by building a list of permitted files
155 // if m_cvs_mode is true:
158 std::cerr
<< "CAUTION: Boost is no longer in CVS, cvs mode may not work anymore!!!" << std::endl
;
159 scan_cvs_path(fs::path());
163 scan_svn_path(fs::path());
166 // if in license mode, try to load more/blanket_permission.txt
168 fs::path
blanket_permission(m_boost_path
/ "more" / "blanket-permission.txt");
169 if (fs::exists(blanket_permission
)) {
170 fs::ifstream
in(blanket_permission
);
172 while (std::getline(in
, line
)) {
173 static const boost::regex
e("([^(]+)\\(");
174 boost::smatch result
;
175 if (boost::regex_search(line
, result
, e
))
176 m_bsl_authors
.insert(format_authors_name(result
[1]));
181 // scan through modules looking for the equivalent
182 // file to add to our list:
184 std::list
<std::string
>::const_iterator i
= m_module_list
.begin();
185 std::list
<std::string
>::const_iterator j
= m_module_list
.end();
189 // convert *i to a path - could be native or portable:
193 module
= fs::path(*i
);
194 exmodule
= fs::path(*i
+ ".hpp");
198 // in scan mode each module must be a real file:
199 add_file_dependencies(module
, true);
204 if(fs::exists(m_boost_path
/ "tools" / module
))
206 add_path(fs::path("tools") / module
);
209 if(fs::exists(m_boost_path
/ "libs" / module
))
211 add_path(fs::path("libs") / module
);
214 if(fs::exists(m_boost_path
/ "boost" / module
))
216 add_path(fs::path("boost") / module
);
219 if(fs::exists(m_boost_path
/ "boost" / exmodule
))
221 add_path(fs::path("boost") / exmodule
);
224 if(fs::exists(m_boost_path
/ module
))
233 // now perform output:
235 if(m_list_namespaces
)
237 // List the namespaces, in two lists, headers and source files
238 // first, then everything else afterwards:
240 boost::regex
important_file("boost/.*|libs/[^/]*/(?:[^/]*/)?/src/.*");
241 std::map
<std::string
, fs::path
>::const_iterator i
, j
;
242 i
= m_top_namespaces
.begin();
243 j
= m_top_namespaces
.end();
244 std::cout
<< "\n\nThe top level namespaces found for header and source files were:\n";
247 if(regex_match(i
->second
.generic_string(), important_file
))
248 std::cout
<< i
->first
<< " (from " << i
->second
<< ")" << std::endl
;
252 i
= m_top_namespaces
.begin();
253 std::cout
<< "\n\nThe top level namespaces found for all other source files were:\n";
256 if(!regex_match(i
->second
.generic_string(), important_file
))
257 std::cout
<< i
->first
<< " (from " << i
->second
<< ")" << std::endl
;
262 std::set
<fs::path
, path_less
>::iterator m
, n
;
263 std::set
<fs::path
, path_less
> short_paths
;
264 m
= m_copy_paths
.begin();
265 n
= m_copy_paths
.end();
270 if(m_list_summary_mode
)
272 fs::path p
= get_short_path(*m
);
273 if(short_paths
.find(p
) == short_paths
.end())
275 short_paths
.insert(p
);
276 std::cout
<< p
.string() << "\n";
280 std::cout
<< m
->string() << "\n";
287 output_license_info();
291 pbcp_application
bcp_application::create()
293 pbcp_application
result(static_cast<bcp_application
*>(new bcp_implementation()));