Tidy up equality options slightly.
[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              << "  -b, --bitwise      bitwise check\n"
16              << "  -v, --version      show libdcp version\n"
17              << "  -d, --verbose      be verbose\n"
18              << "  -h, --help         show this help\n"
19              << "\n"
20              << "The <DCP>s are the DCP directories to compare.\n"
21              << "Default is to compare metadata and content ignoring timestamps\n"
22              << "and differing UUIDs.  Pass -b to perform a bitwise comparison.\n";
23 }
24
25 int
26 main (int argc, char* argv[])
27 {
28         EqualityOptions options;
29         options.flags = EqualityFlags (LIBDCP_METADATA | MXF_INSPECT);
30         options.verbose = false;
31         
32         int option_index = 0;
33         while (1) {
34                 static struct option long_options[] = {
35                         { "bitwise", no_argument, 0, 'b'},
36                         { "version", no_argument, 0, 'v'},
37                         { "help", no_argument, 0, 'h'},
38                         { "verbose", no_argument, 0, 'd'},
39                         { 0, 0, 0, 0 }
40                 };
41
42                 int c = getopt_long (argc, argv, "bvhd", long_options, &option_index);
43
44                 if (c == -1) {
45                         break;
46                 }
47
48                 switch (c) {
49                 case 'b':
50                         options.flags = EqualityFlags (options.flags | MXF_BITWISE);
51                         break;
52                 case 'v':
53                         cout << "dcpdiff version " << LIBDCP_VERSION << "\n";
54                         exit (EXIT_SUCCESS);
55                 case 'h':
56                         help (argv[0]);
57                         exit (EXIT_SUCCESS);
58                 case 'd':
59                         options.verbose = true;
60                         break;
61                 }
62         }
63
64         if (argc <= optind || argc > (optind + 2)) {
65                 help (argv[0]);
66                 exit (EXIT_FAILURE);
67         }
68
69         if (!filesystem::exists (argv[optind])) {
70                 cerr << argv[0] << ": DCP " << argv[optind] << " not found.\n";
71                 exit (EXIT_FAILURE);
72         }
73
74         if (!filesystem::exists (argv[optind + 1])) {
75                 cerr << argv[0] << ": DCP " << argv[optind + 1] << " not found.\n";
76                 exit (EXIT_FAILURE);
77         }
78
79         DCP* a = 0;
80         try {
81                 a = new DCP (argv[optind]);
82         } catch (FileError& e) {
83                 cerr << "Could not read DCP " << argv[optind] << "; " << e.what() << " " << e.filename() << "\n";
84                 exit (EXIT_FAILURE);
85         }
86
87         DCP* b = 0;
88         try {
89                 b = new DCP (argv[optind + 1]);
90         } catch (FileError& e) {
91                 cerr << "Could not read DCP " << argv[optind + 1] << "; " << e.what() << " " << e.filename() << "\n";
92                 exit (EXIT_FAILURE);
93         }
94
95         options.max_mean_pixel_error = 5;
96         options.max_std_dev_pixel_error = 5;
97
98         list<string> notes = a->equals (*b, options);
99         if (notes.empty ()) {
100                 cout << "DCPs equal\n";
101                 exit (EXIT_SUCCESS);
102         }
103
104         for (list<string>::iterator i = notes.begin(); i != notes.end(); ++i) {
105                 cout << "  " << *i << "\n";
106         }
107
108         exit (EXIT_FAILURE);
109 }