|
18 | 18 | #include <iostream> // for std::cerr, std::cout
|
19 | 19 | #include <ostream> // for std::endl
|
20 | 20 |
|
21 |
| - |
22 | 21 | // 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 |
| - |
| 22 | +std::streamsize const buffer_size = 1024; |
30 | 23 |
|
31 | 24 | // 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 |
| - } |
| 25 | +int main(int argc, char const *argv[]) { |
| 26 | + try { |
| 27 | + boost::crc_32_type result; |
| 28 | + |
| 29 | + for (int i = 1; i < argc; ++i) { |
| 30 | + std::ifstream ifs(argv[i], std::ios_base::binary); |
| 31 | + |
| 32 | + if (ifs) { |
| 33 | + do { |
| 34 | + char buffer[buffer_size]; |
| 35 | + |
| 36 | + ifs.read(buffer, buffer_size); |
| 37 | + result.process_bytes(buffer, ifs.gcount()); |
| 38 | + } while (ifs); |
| 39 | + } else { |
| 40 | + std::cerr << "Failed to open file '" << argv[i] << "'." << std::endl; |
| 41 | + } |
61 | 42 | }
|
62 | 43 |
|
63 | 44 | std::cout << std::hex << std::uppercase << result.checksum() << std::endl;
|
64 | 45 | return EXIT_SUCCESS;
|
65 |
| -} |
66 |
| -catch ( std::exception &e ) |
67 |
| -{ |
| 46 | + } catch (std::exception &e) { |
68 | 47 | std::cerr << "Found an exception with '" << e.what() << "'." << std::endl;
|
69 | 48 | return EXIT_FAILURE;
|
70 |
| -} |
71 |
| -catch ( ... ) |
72 |
| -{ |
| 49 | + } catch (...) { |
73 | 50 | std::cerr << "Found an unknown exception." << std::endl;
|
74 | 51 | return EXIT_FAILURE;
|
| 52 | + } |
75 | 53 | }
|
0 commit comments