]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/quickbook/test/src/text_diff.cpp
2 // Copyright (c) 2005 João Abecasis
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
15 #include <boost/spirit/include/classic_scanner.hpp>
16 #include <boost/spirit/include/classic_primitives.hpp>
18 namespace spirit
= boost::spirit::classic
;
20 typedef std::istream_iterator
<char, char> iterator
;
21 typedef spirit::scanner
<iterator
> scanner
;
23 int main(int argc
, char * argv
[])
25 std::vector
<char*> args
;
26 bool usage_error
= false;
28 for (int i
= 1; i
< argc
; ++i
) {
29 if (std::strncmp(argv
[i
], "--", 2) == 0) {
30 if (strcmp(argv
[i
], "--strict") == 0) {
31 // Ignore --strict because the build file accidentally
32 // uses it. Why yes, this is a horrible hack.
34 std::cerr
<< "ERROR: Invalid flag: " << argv
[i
] << std::endl
;
38 args
.push_back(argv
[i
]);
42 if (!usage_error
&& args
.size() != 2)
44 std::cerr
<< "ERROR: Wrong number of arguments." << std::endl
;
49 std::cout
<< "Usage:\n\t" << argv
[0] << " file1 file2" << std::endl
;
54 file1(args
[0], std::ios_base::binary
| std::ios_base::in
),
55 file2(args
[1], std::ios_base::binary
| std::ios_base::in
);
59 std::cerr
<< "ERROR: Unable to open one or both files." << std::endl
;
63 file1
.unsetf(std::ios_base::skipws
);
64 file2
.unsetf(std::ios_base::skipws
);
71 scan1(iter_file1
, iterator()),
72 scan2(iter_file2
, iterator());
74 std::size_t line
= 1, column
= 1;
76 while (!scan1
.at_end() && !scan2
.at_end())
78 if (spirit::eol_p
.parse(scan1
))
80 if (!spirit::eol_p
.parse(scan2
))
82 std::cout
<< "Files differ at line " << line
<< ", column " <<
83 column
<< '.' << std::endl
;
93 std::cout
<< "Files differ at line " << line
<< ", column " <<
94 column
<< '.' << std::endl
;
98 ++scan1
, ++scan2
, ++column
;
101 if (scan1
.at_end() != scan2
.at_end())
103 std::cout
<< "Files differ in length." << std::endl
;