]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/quickbook/src/dependency_tracker.cpp
1 /*=============================================================================
2 Copyright (c) 2013 Daniel James
4 Use, modification and distribution is subject to the Boost Software
5 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 http://www.boost.org/LICENSE_1_0.txt)
7 =============================================================================*/
9 #include "dependency_tracker.hpp"
11 #include <boost/filesystem/operations.hpp>
12 #include <boost/filesystem/fstream.hpp>
13 #include <boost/foreach.hpp>
17 static char const* control_escapes
[16] = {
18 "\\000", "\\001", "\\002", "\\003",
19 "\\004", "\\005", "\\006", "\\a",
20 "\\b", "\\t", "\\n", "\\v",
21 "\\f", "\\r", "\\016", "\\017"
24 static std::string
escaped_path(std::string
const& generic
)
27 result
.reserve(generic
.size());
29 BOOST_FOREACH(char c
, generic
)
31 if (c
>= 0 && c
< 16) {
32 result
+= control_escapes
[(unsigned int) c
];
48 static std::string
get_path(fs::path
const& path
,
49 dependency_tracker::flags f
)
51 std::string generic
= quickbook::detail::path_to_generic(path
);
53 if (f
& dependency_tracker::escaped
) {
54 generic
= escaped_path(generic
);
60 dependency_tracker::dependency_tracker() :
61 dependencies(), glob_dependencies(),
62 last_glob(glob_dependencies
.end()) {}
64 bool dependency_tracker::add_dependency(fs::path
const& f
) {
65 bool found
= fs::exists(fs::status(f
));
66 dependencies
[f
] |= found
;
70 void dependency_tracker::add_glob(fs::path
const& f
) {
71 std::pair
<glob_list::iterator
, bool> r
= glob_dependencies
.insert(
72 std::make_pair(f
, glob_list::mapped_type()));
76 void dependency_tracker::add_glob_match(fs::path
const& f
) {
77 assert(last_glob
!= glob_dependencies
.end());
78 last_glob
->second
.insert(f
);
81 void dependency_tracker::write_dependencies(fs::path
const& file_out
,
84 fs::ofstream
out(file_out
);
87 throw std::runtime_error(
88 "Error opening dependency file " +
89 quickbook::detail::path_to_generic(file_out
));
92 out
.exceptions(std::ios::badbit
);
93 write_dependencies(out
, f
);
96 void dependency_tracker::write_dependencies(std::ostream
& out
,
100 BOOST_FOREACH(dependency_list::value_type
const& d
, dependencies
)
102 out
<< (d
.second
? "+ " : "- ")
103 << get_path(d
.first
, f
) << std::endl
;
106 BOOST_FOREACH(glob_list::value_type
const& g
, glob_dependencies
)
109 << get_path(g
.first
, f
) << std::endl
;
111 BOOST_FOREACH(fs::path
const& p
, g
.second
)
113 out
<< "+ " << get_path(p
, f
) << std::endl
;
118 std::set
<std::string
> paths
;
120 BOOST_FOREACH(dependency_list::value_type
const& d
, dependencies
)
123 paths
.insert(get_path(d
.first
, f
));
127 BOOST_FOREACH(glob_list::value_type
const& g
, glob_dependencies
)
129 BOOST_FOREACH(fs::path
const& p
, g
.second
)
131 paths
.insert(get_path(p
, f
));
135 BOOST_FOREACH(std::string
const& p
, paths
)
137 out
<< p
<< std::endl
;