Missing long option.
[libdcp.git] / tools / dcpdiff.cc
1 #include <getopt.h>
2 #include "dcp.h"
3
4 using namespace std;
5 using namespace libdcp;
6
7 static void
8 help (string n)
9 {
10         cerr << "Syntax: " << n << " [OPTION] <DCP> <DCP>\n"
11              << "  -b, --bitwise      bitwise check\n"
12              << "  -v, --version      show libdcp version\n"
13              << "  -h, --help         show this help\n"
14              << "\n"
15              << "The <DCP>s are the DCP directories to compare.\n"
16              << "Default is to compare metadata and content ignoring timestamps\n"
17              << "and differing UUIDs.  Pass -b to perform a bitwise comparison.\n";
18 }
19
20 int
21 main (int argc, char* argv[])
22 {
23         bool bitwise = false;
24         
25         int option_index = 0;
26         while (1) {
27                 static struct option long_options[] = {
28                         { "bitwise", no_argument, 0, 'b'},
29                         { "version", no_argument, 0, 'v'},
30                         { "help", no_argument, 0, 'h'},
31                         { 0, 0, 0, 0 }
32                 };
33
34                 int c = getopt_long (argc, argv, "bvh", long_options, &option_index);
35
36                 if (c == -1) {
37                         break;
38                 }
39
40                 switch (c) {
41                 case 'b':
42                         bitwise = true;
43                         break;
44                 case 'v':
45                         cout << "dcpdiff version " << LIBDCP_VERSION << "\n";
46                         exit (EXIT_SUCCESS);
47                 case 'h':
48                         help (argv[0]);
49                         exit (EXIT_SUCCESS);
50                 }
51         }
52
53         if (argc <= optind || argc > (optind + 2)) {
54                 help (argv[0]);
55                 exit (EXIT_FAILURE);
56         }
57
58         DCP a (argv[optind]);
59         DCP b (argv[optind + 1]);
60
61         EqualityFlags flags = EqualityFlags (LIBDCP_METADATA | MXF_INSPECT);
62         if (bitwise) {
63                 flags = EqualityFlags (flags | MXF_BITWISE);
64         }
65
66         list<string> notes = a.equals (b, flags);
67         if (notes.empty ()) {
68                 cout << "DCPs identical\n";
69                 exit (EXIT_SUCCESS);
70         }
71
72         for (list<string>::iterator i = notes.begin(); i != notes.end(); ++i) {
73                 cout << "  " << *i << "\n";
74         }
75
76         exit (EXIT_FAILURE);
77 }