Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/tools/quickbook/test/src/text_diff.cpp @ 45

Last change on this file since 45 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 2.0 KB
Line 
1//
2//  Copyright (c) 2005 João Abecasis
3//
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)
7//
8
9#include <fstream>
10#include <iostream>
11#include <iterator>
12
13#include <boost/spirit/core/scanner/scanner.hpp>
14#include <boost/spirit/core/primitives/primitives.hpp>
15
16namespace spirit = boost::spirit;
17
18typedef std::istream_iterator<char, char> iterator;
19typedef spirit::scanner<iterator> scanner;
20
21int main(int argc, char * argv[])
22{
23    if (argc != 3)
24    {
25        std::cerr << "ERROR: Wrong number of arguments." << std::endl;
26        std::cout << "Usage:\n\t" << argv[0] << " file1 file2" << std::endl;
27
28        return 1;
29    }
30
31    std::ifstream
32        file1(argv[1], std::ios_base::binary | std::ios_base::in),
33        file2(argv[2], std::ios_base::binary | std::ios_base::in);
34
35    if (!file1 || !file2)
36    {
37        std::cerr << "ERROR: Unable to open one or both files." << std::endl;
38        return 2;
39    }
40
41    file1.unsetf(std::ios_base::skipws);
42    file2.unsetf(std::ios_base::skipws);
43
44    iterator
45        iter_file1(file1),
46        iter_file2(file2);
47
48    scanner
49        scan1(iter_file1, iterator()),
50        scan2(iter_file2, iterator());
51
52    std::size_t line = 1, column = 1;
53
54    while (!scan1.at_end() && !scan2.at_end())
55    {
56        if (spirit::eol_p.parse(scan1))
57        {
58            if (!spirit::eol_p.parse(scan2))
59            {
60                std::cout << "Files differ at line " << line << ", column " <<
61                    column << '.' << std::endl;
62                return 3;
63            }
64
65            ++line, column = 1;
66            continue;
67        }
68
69        if (*scan1 != *scan2)
70        {
71            std::cout << "Files differ at line " << line << ", column " <<
72                column << '.' << std::endl;
73            return 4;
74        }
75
76        ++scan1, ++scan2, ++column;
77    }
78
79    if (scan1.at_end() != scan2.at_end())
80    {
81        std::cout << "Files differ in length." << std::endl;
82        return 5;
83    }
84}
Note: See TracBrowser for help on using the repository browser.