forked from boostorg/bcp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bcp_imp.cpp
310 lines (284 loc) · 7.54 KB
/
bcp_imp.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
/*
*
* Copyright (c) 2003 Dr John Maddock
* Use, modification and distribution is subject to 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)
*
* This file implements the bcp_implementation virtuals.
*/
#include "bcp_imp.hpp"
#include "licence_info.hpp"
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/fstream.hpp>
#include <iostream>
#include <stdexcept>
#include <boost/regex.hpp>
#include <string>
bcp_implementation::bcp_implementation()
: m_list_mode(false), m_list_summary_mode(false), m_license_mode(false), m_cvs_mode(false),
m_svn_mode(false), m_unix_lines(false), m_scan_mode(false), m_bsl_convert_mode(false),
m_bsl_summary_mode(false), m_namespace_alias(false), m_list_namespaces(false)
{
}
bcp_implementation::~bcp_implementation()
{
}
bcp_application::~bcp_application()
{
}
void bcp_implementation::enable_list_mode()
{
m_list_mode = true;
}
void bcp_implementation::enable_summary_list_mode()
{
m_list_mode = true;
m_list_summary_mode = true;
}
void bcp_implementation::enable_cvs_mode()
{
m_cvs_mode = true;
}
void bcp_implementation::enable_svn_mode()
{
m_svn_mode = true;
}
void bcp_implementation::enable_scan_mode()
{
m_scan_mode = true;
}
void bcp_implementation::enable_license_mode()
{
m_license_mode = true;
}
void bcp_implementation::enable_bsl_convert_mode()
{
m_bsl_convert_mode = true;
}
void bcp_implementation::enable_bsl_summary_mode()
{
m_bsl_summary_mode = true;
}
void bcp_implementation::enable_unix_lines()
{
m_unix_lines = true;
}
void bcp_implementation::set_boost_path(const char* p)
{
// Hack to strip trailing slashes from the path
m_boost_path = (fs::path(p) / "boost").parent_path();
fs::path check = m_boost_path / "boost" / "version.hpp";
if(!fs::exists(check))
{
std::string s = "The Boost path appears to have been incorrectly set: could not find boost/version.hpp in ";
s += m_boost_path.string();
std::runtime_error e(s);
throw e;
}
}
void bcp_implementation::set_destination(const char* p)
{
m_dest_path = fs::path(p);
}
void bcp_implementation::add_module(const char* p)
{
m_module_list.push_back(p);
}
void bcp_implementation::set_namespace(const char* name)
{
m_namespace_name = name;
}
void bcp_implementation::set_namespace_alias(bool b)
{
m_namespace_alias = b;
}
void bcp_implementation::set_namespace_list(bool b)
{
m_list_namespaces = b;
m_list_mode = b;
}
void bcp_implementation::add_excluded(const char* p)
{
if (!fs::exists(p))
{
std::cerr << "CAUTION: excluded path " << p << " does not exist." << std::endl;
return;
}
m_excluded.insert(p);
}
fs::path get_short_path(const fs::path& p)
{
// truncate path no more than "x/y":
std::string s = p.generic_string();
std::string::size_type n = s.find('/');
if(n != std::string::npos)
{
n = s.find('/', n+1);
if(n != std::string::npos)
s.erase(n);
}
return s;
}
int bcp_implementation::run()
{
//
// check output path is OK:
//
if(!m_list_mode && !m_license_mode && !fs::exists(m_dest_path))
{
std::string msg("Destination path does not exist: ");
msg.append(m_dest_path.string());
std::runtime_error e(msg);
boost::throw_exception(e);
}
//
// Check Boost path is OK if it hasn't been checked already:
//
if(m_boost_path == "")
{
set_boost_path("");
}
// start by building a list of permitted files
// if m_cvs_mode is true:
if(m_cvs_mode)
{
std::cerr << "CAUTION: Boost is no longer in CVS, cvs mode may not work anymore!!!" << std::endl;
scan_cvs_path(fs::path());
}
if(m_svn_mode)
{
scan_svn_path(fs::path());
}
//
// if in license mode, try to load more/blanket_permission.txt
//
fs::path blanket_permission(m_boost_path / "more" / "blanket-permission.txt");
if (fs::exists(blanket_permission)) {
fs::ifstream in(blanket_permission);
std::string line;
while (std::getline(in, line)) {
static const boost::regex e("([^(]+)\\(");
boost::smatch result;
if (boost::regex_search(line, result, e))
m_bsl_authors.insert(format_authors_name(result[1]));
}
}
//
// scan through modules looking for the equivalent
// file to add to our list:
//
std::list<std::string>::const_iterator i = m_module_list.begin();
std::list<std::string>::const_iterator j = m_module_list.end();
while(i != j)
{
//
// convert *i to a path - could be native or portable:
//
fs::path module;
fs::path exmodule;
module = fs::path(*i);
exmodule = fs::path(*i + ".hpp");
if(m_scan_mode)
{
// in scan mode each module must be a real file:
add_file_dependencies(module, true);
}
else
{
int count = 0;
if(fs::exists(m_boost_path / "tools" / module))
{
add_path(fs::path("tools") / module);
++count;
}
if(fs::exists(m_boost_path / "libs" / module))
{
add_path(fs::path("libs") / module);
++count;
}
if(fs::exists(m_boost_path / "boost" / module))
{
add_path(fs::path("boost") / module);
++count;
}
if(fs::exists(m_boost_path / "boost" / exmodule))
{
add_path(fs::path("boost") / exmodule);
++count;
}
if(fs::exists(m_boost_path / module))
{
add_path(module);
++count;
}
}
++i;
}
while (!m_pending_paths.empty())
{
add_path(m_pending_paths.front());
m_pending_paths.pop();
}
//
// now perform output:
//
if(m_list_namespaces)
{
// List the namespaces, in two lists, headers and source files
// first, then everything else afterwards:
//
boost::regex important_file("boost/.*|libs/[^/]*/(?:[^/]*/)?/src/.*");
std::map<std::string, fs::path>::const_iterator i, j;
i = m_top_namespaces.begin();
j = m_top_namespaces.end();
std::cout << "\n\nThe top level namespaces found for header and source files were:\n";
while(i != j)
{
if(regex_match(i->second.generic_string(), important_file))
std::cout << i->first << " (from " << i->second << ")" << std::endl;
++i;
}
i = m_top_namespaces.begin();
std::cout << "\n\nThe top level namespaces found for all other source files were:\n";
while(i != j)
{
if(!regex_match(i->second.generic_string(), important_file))
std::cout << i->first << " (from " << i->second << ")" << std::endl;
++i;
}
return 0;
}
std::set<fs::path, path_less>::iterator m, n;
std::set<fs::path, path_less> short_paths;
m = m_copy_paths.begin();
n = m_copy_paths.end();
if(!m_license_mode)
{
while(m != n)
{
if(m_list_summary_mode)
{
fs::path p = get_short_path(*m);
if(short_paths.find(p) == short_paths.end())
{
short_paths.insert(p);
std::cout << p.string() << "\n";
}
}
else if(m_list_mode)
std::cout << m->string() << "\n";
else
copy_path(*m);
++m;
}
}
else
output_license_info();
return 0;
}
pbcp_application bcp_application::create()
{
pbcp_application result(static_cast<bcp_application*>(new bcp_implementation()));
return result;
}