1 | /* |
---|
2 | * |
---|
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) |
---|
7 | * |
---|
8 | * This file implements the bcp_implementation virtuals. |
---|
9 | */ |
---|
10 | |
---|
11 | #include "bcp_imp.hpp" |
---|
12 | #include "licence_info.hpp" |
---|
13 | #include <boost/filesystem/operations.hpp> |
---|
14 | #include <boost/filesystem/fstream.hpp> |
---|
15 | #include <iostream> |
---|
16 | #include <stdexcept> |
---|
17 | #include <boost/regex.hpp> |
---|
18 | #include <string> |
---|
19 | |
---|
20 | bcp_implementation::bcp_implementation() |
---|
21 | : m_list_mode(false), m_license_mode(false), m_cvs_mode(false), m_unix_lines(false), m_scan_mode(false), m_bsl_convert_mode(false), m_bsl_summary_mode(false) |
---|
22 | { |
---|
23 | } |
---|
24 | |
---|
25 | bcp_implementation::~bcp_implementation() |
---|
26 | { |
---|
27 | } |
---|
28 | |
---|
29 | bcp_application::~bcp_application() |
---|
30 | { |
---|
31 | } |
---|
32 | |
---|
33 | void bcp_implementation::enable_list_mode() |
---|
34 | { |
---|
35 | m_list_mode = true; |
---|
36 | } |
---|
37 | |
---|
38 | void bcp_implementation::enable_cvs_mode() |
---|
39 | { |
---|
40 | m_cvs_mode = true; |
---|
41 | } |
---|
42 | |
---|
43 | void bcp_implementation::enable_scan_mode() |
---|
44 | { |
---|
45 | m_scan_mode = true; |
---|
46 | } |
---|
47 | |
---|
48 | void bcp_implementation::enable_license_mode() |
---|
49 | { |
---|
50 | m_license_mode = true; |
---|
51 | } |
---|
52 | |
---|
53 | void bcp_implementation::enable_bsl_convert_mode() |
---|
54 | { |
---|
55 | m_bsl_convert_mode = true; |
---|
56 | } |
---|
57 | |
---|
58 | void bcp_implementation::enable_bsl_summary_mode() |
---|
59 | { |
---|
60 | m_bsl_summary_mode = true; |
---|
61 | } |
---|
62 | |
---|
63 | void bcp_implementation::enable_unix_lines() |
---|
64 | { |
---|
65 | m_unix_lines = true; |
---|
66 | } |
---|
67 | |
---|
68 | void bcp_implementation::set_boost_path(const char* p) |
---|
69 | { |
---|
70 | m_boost_path = fs::path(p, fs::native); |
---|
71 | fs::path check = m_boost_path / "boost" / "version.hpp"; |
---|
72 | if(!fs::exists(check)) |
---|
73 | { |
---|
74 | std::string s = "The Boost path appears to have been incorrectly set: could not find boost/version.hpp in "; |
---|
75 | s += m_boost_path.string(); |
---|
76 | std::runtime_error e(s); |
---|
77 | throw e; |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | void bcp_implementation::set_destination(const char* p) |
---|
82 | { |
---|
83 | m_dest_path = fs::path(p, fs::native); |
---|
84 | } |
---|
85 | |
---|
86 | void bcp_implementation::add_module(const char* p) |
---|
87 | { |
---|
88 | m_module_list.push_back(p); |
---|
89 | } |
---|
90 | |
---|
91 | int bcp_implementation::run() |
---|
92 | { |
---|
93 | // |
---|
94 | // check output path is OK: |
---|
95 | // |
---|
96 | if(!m_list_mode && !m_license_mode && !fs::exists(m_dest_path)) |
---|
97 | { |
---|
98 | std::string msg("Destination path does not exist: "); |
---|
99 | msg.append(m_dest_path.native_file_string()); |
---|
100 | std::runtime_error e(msg); |
---|
101 | boost::throw_exception(e); |
---|
102 | } |
---|
103 | // start by building a list of permitted files |
---|
104 | // if m_cvs_mode is true: |
---|
105 | if(m_cvs_mode) |
---|
106 | { |
---|
107 | scan_cvs_path(fs::path()); |
---|
108 | } |
---|
109 | // |
---|
110 | // if in license mode, try to load more/blanket_permission.txt |
---|
111 | // |
---|
112 | fs::path blanket_permission(m_boost_path / "more" / "blanket-permission.txt"); |
---|
113 | if (fs::exists(blanket_permission)) { |
---|
114 | fs::ifstream in(blanket_permission); |
---|
115 | std::string line; |
---|
116 | while (std::getline(in, line)) { |
---|
117 | boost::regex e("([^(]+)\\("); |
---|
118 | boost::smatch result; |
---|
119 | if (boost::regex_search(line, result, e)) |
---|
120 | m_bsl_authors.insert(format_authors_name(result[1])); |
---|
121 | } |
---|
122 | } |
---|
123 | |
---|
124 | // |
---|
125 | // scan through modules looking for the equivalent |
---|
126 | // file to add to our list: |
---|
127 | // |
---|
128 | std::list<std::string>::const_iterator i = m_module_list.begin(); |
---|
129 | std::list<std::string>::const_iterator j = m_module_list.end(); |
---|
130 | while(i != j) |
---|
131 | { |
---|
132 | // |
---|
133 | // convert *i to a path - could be native or portable: |
---|
134 | // |
---|
135 | fs::path module; |
---|
136 | fs::path exmodule; |
---|
137 | try{ |
---|
138 | module = fs::path(*i); |
---|
139 | exmodule = fs::path(*i + ".hpp"); |
---|
140 | } |
---|
141 | catch(...) |
---|
142 | { |
---|
143 | module = fs::path(*i, fs::native); |
---|
144 | exmodule = fs::path(*i + ".hpp", fs::native); |
---|
145 | } |
---|
146 | |
---|
147 | if(m_scan_mode) |
---|
148 | { |
---|
149 | // in scan mode each module must be a real file: |
---|
150 | add_file_dependencies(module, true); |
---|
151 | } |
---|
152 | else |
---|
153 | { |
---|
154 | int count = 0; |
---|
155 | if(fs::exists(m_boost_path / "tools" / module)) |
---|
156 | { |
---|
157 | add_path(fs::path("tools") / module); |
---|
158 | ++count; |
---|
159 | } |
---|
160 | if(fs::exists(m_boost_path / "libs" / module)) |
---|
161 | { |
---|
162 | add_path(fs::path("libs") / module); |
---|
163 | ++count; |
---|
164 | } |
---|
165 | if(fs::exists(m_boost_path / "boost" / module)) |
---|
166 | { |
---|
167 | add_path(fs::path("boost") / module); |
---|
168 | ++count; |
---|
169 | } |
---|
170 | if(fs::exists(m_boost_path / "boost" / exmodule)) |
---|
171 | { |
---|
172 | add_path(fs::path("boost") / exmodule); |
---|
173 | ++count; |
---|
174 | } |
---|
175 | if(fs::exists(m_boost_path / module)) |
---|
176 | { |
---|
177 | add_path(module); |
---|
178 | ++count; |
---|
179 | } |
---|
180 | } |
---|
181 | ++i; |
---|
182 | } |
---|
183 | // |
---|
184 | // now perform output: |
---|
185 | // |
---|
186 | std::set<fs::path, path_less>::iterator m, n; |
---|
187 | m = m_copy_paths.begin(); |
---|
188 | n = m_copy_paths.end(); |
---|
189 | if(!m_license_mode) |
---|
190 | { |
---|
191 | while(m != n) |
---|
192 | { |
---|
193 | if(m_list_mode) |
---|
194 | std::cout << m->string() << "\n"; |
---|
195 | else |
---|
196 | copy_path(*m); |
---|
197 | ++m; |
---|
198 | } |
---|
199 | } |
---|
200 | else |
---|
201 | output_license_info(); |
---|
202 | return 0; |
---|
203 | } |
---|
204 | |
---|
205 | pbcp_application bcp_application::create() |
---|
206 | { |
---|
207 | pbcp_application result(static_cast<bcp_application*>(new bcp_implementation())); |
---|
208 | return result; |
---|
209 | } |
---|