Use boost::function for making notes during equals operations.
[libdcp.git] / tools / dcpdiff.cc
1 #include <iostream>
2 #include <boost/filesystem.hpp>
3 #include <getopt.h>
4 #include "dcp.h"
5 #include "exceptions.h"
6
7 using namespace std;
8 using namespace boost;
9 using namespace libdcp;
10
11 static void
12 help (string n)
13 {
14         cerr << "Syntax: " << n << " [OPTION] <DCP> <DCP>\n"
15              << "  -v, --version      show libdcp version\n"
16              << "  -h, --help         show this help\n"
17              << "\n"
18              << "The <DCP>s are the DCP directories to compare.\n"
19              << "Comparison is of metadata and content, ignoring timestamps\n"
20              << "and differing UUIDs.\n";
21 }
22
23 void
24 note (string n)
25 {
26         cout << " " << n << "\n";
27 }
28
29 int
30 main (int argc, char* argv[])
31 {
32         EqualityOptions options;
33         
34         int option_index = 0;
35         while (1) {
36                 static struct option long_options[] = {
37                         { "version", no_argument, 0, 'v'},
38                         { "help", no_argument, 0, 'h'},
39                         { 0, 0, 0, 0 }
40                 };
41
42                 int c = getopt_long (argc, argv, "vh", long_options, &option_index);
43
44                 if (c == -1) {
45                         break;
46                 }
47
48                 switch (c) {
49                 case 'v':
50                         cout << "dcpdiff version " << LIBDCP_VERSION << "\n";
51                         exit (EXIT_SUCCESS);
52                 case 'h':
53                         help (argv[0]);
54                         exit (EXIT_SUCCESS);
55                 }
56         }
57
58         if (argc <= optind || argc > (optind + 2)) {
59                 help (argv[0]);
60                 exit (EXIT_FAILURE);
61         }
62
63         if (!filesystem::exists (argv[optind])) {
64                 cerr << argv[0] << ": DCP " << argv[optind] << " not found.\n";
65                 exit (EXIT_FAILURE);
66         }
67
68         if (!filesystem::exists (argv[optind + 1])) {
69                 cerr << argv[0] << ": DCP " << argv[optind + 1] << " not found.\n";
70                 exit (EXIT_FAILURE);
71         }
72
73         DCP* a = 0;
74         try {
75                 a = new DCP (argv[optind]);
76                 a->read ();
77         } catch (FileError& e) {
78                 cerr << "Could not read DCP " << argv[optind] << "; " << e.what() << " " << e.filename() << "\n";
79                 exit (EXIT_FAILURE);
80         }
81
82         DCP* b = 0;
83         try {
84                 b = new DCP (argv[optind + 1]);
85                 b->read ();
86         } catch (FileError& e) {
87                 cerr << "Could not read DCP " << argv[optind + 1] << "; " << e.what() << " " << e.filename() << "\n";
88                 exit (EXIT_FAILURE);
89         }
90
91         options.max_mean_pixel_error = 5;
92         options.max_std_dev_pixel_error = 5;
93         /* I think this is just below the LSB at 16-bits (ie the 8th most significant bit at 24-bit) */
94         options.max_audio_sample_error = 255;
95
96         bool const equals = a->equals (*b, options, boost::bind (note, _1));
97
98         if (equals) {
99                 exit (EXIT_SUCCESS);
100         }
101
102         exit (EXIT_FAILURE);
103 }