| [12] | 1 | // Boost CRC example program file ------------------------------------------// |
|---|
| 2 | |
|---|
| 3 | // Copyright 2003 Daryle Walker. Use, modification, and distribution are |
|---|
| 4 | // subject to the Boost Software License, Version 1.0. (See accompanying file |
|---|
| 5 | // LICENSE_1_0.txt or a copy at <http://www.boost.org/LICENSE_1_0.txt>.) |
|---|
| 6 | |
|---|
| 7 | // See <http://www.boost.org/libs/crc/> for the library's home page. |
|---|
| 8 | |
|---|
| 9 | // Revision History |
|---|
| 10 | // 17 Jun 2003 Initial version (Daryle Walker) |
|---|
| 11 | |
|---|
| 12 | #include <boost/crc.hpp> // for boost::crc_32_type |
|---|
| 13 | |
|---|
| 14 | #include <cstdlib> // for EXIT_SUCCESS, EXIT_FAILURE |
|---|
| 15 | #include <exception> // for std::exception |
|---|
| 16 | #include <fstream> // for std::ifstream |
|---|
| 17 | #include <ios> // for std::ios_base, etc. |
|---|
| 18 | #include <iostream> // for std::cerr, std::cout |
|---|
| 19 | #include <ostream> // for std::endl |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | // Redefine this to change to processing buffer size |
|---|
| 23 | #ifndef PRIVATE_BUFFER_SIZE |
|---|
| 24 | #define PRIVATE_BUFFER_SIZE 1024 |
|---|
| 25 | #endif |
|---|
| 26 | |
|---|
| 27 | // Global objects |
|---|
| 28 | std::streamsize const buffer_size = PRIVATE_BUFFER_SIZE; |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | // Main program |
|---|
| 32 | int |
|---|
| 33 | main |
|---|
| 34 | ( |
|---|
| 35 | int argc, |
|---|
| 36 | char const * argv[] |
|---|
| 37 | ) |
|---|
| 38 | try |
|---|
| 39 | { |
|---|
| 40 | boost::crc_32_type result; |
|---|
| 41 | |
|---|
| 42 | for ( int i = 1 ; i < argc ; ++i ) |
|---|
| 43 | { |
|---|
| 44 | std::ifstream ifs( argv[i], std::ios_base::binary ); |
|---|
| 45 | |
|---|
| 46 | if ( ifs ) |
|---|
| 47 | { |
|---|
| 48 | do |
|---|
| 49 | { |
|---|
| 50 | char buffer[ buffer_size ]; |
|---|
| 51 | |
|---|
| 52 | ifs.read( buffer, buffer_size ); |
|---|
| 53 | result.process_bytes( buffer, ifs.gcount() ); |
|---|
| 54 | } while ( ifs ); |
|---|
| 55 | } |
|---|
| 56 | else |
|---|
| 57 | { |
|---|
| 58 | std::cerr << "Failed to open file '" << argv[i] << "'." |
|---|
| 59 | << std::endl; |
|---|
| 60 | } |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | std::cout << std::hex << std::uppercase << result.checksum() << std::endl; |
|---|
| 64 | return EXIT_SUCCESS; |
|---|
| 65 | } |
|---|
| 66 | catch ( std::exception &e ) |
|---|
| 67 | { |
|---|
| 68 | std::cerr << "Found an exception with '" << e.what() << "'." << std::endl; |
|---|
| 69 | return EXIT_FAILURE; |
|---|
| 70 | } |
|---|
| 71 | catch ( ... ) |
|---|
| 72 | { |
|---|
| 73 | std::cerr << "Found an unknown exception." << std::endl; |
|---|
| 74 | return EXIT_FAILURE; |
|---|
| 75 | } |
|---|