A big mess of changes all at once.
[dvdrip] / dvd-id.c
1 #include "lib.h"
2
3 static void usage(FILE *fp) { fprintf(fp, "usage: %s DEVICE\n", prog); }
4
5 static void puthex(const unsigned char *p, size_t sz, FILE *fp)
6 { while (sz) { fprintf(fp, "%02x", *p++); sz--; } }
7
8 int main(int argc, char *argv[])
9 {
10 char volid[33];
11 unsigned char volsetid[16], discid[16];
12 int rc, opt;
13 unsigned f = 0;
14 static dvd_reader_t *dvd;
15 #define f_bogus 1u
16
17 set_prog(argv[0]);
18 for (;;) {
19 opt = getopt(argc, argv, "h"); if (opt < 0) break;
20 switch (opt) {
21 case 'h': usage(stderr); exit(0);
22 default: f |= f_bogus; break;
23 }
24 }
25 if (argc - optind != 1) f |= f_bogus;
26 if (f&f_bogus) { usage(stderr); exit(2); }
27 setlocale(LC_ALL, "");
28 progress_init(&progress);
29
30 open_dvd(argv[optind], 0, &dvd);
31
32 rc = DVDUDFVolumeInfo(dvd,
33 volid, sizeof(volid),
34 volsetid, sizeof(volsetid));
35 if (rc) {
36 moan("failed to read volume info");
37 strcpy(volid, "<error reading volume info>");
38 memset(volsetid, 0xff, sizeof(volsetid));
39 }
40
41 rc = DVDDiscID(dvd, discid);
42 if (rc) {
43 moan("failed to determine disc id");
44 memset(discid, 0xff, sizeof(discid));
45 }
46
47 fputs(volid, stdout); fputc('-', stdout);
48 puthex(volsetid, sizeof(volsetid), stdout); fputc(':', stdout);
49 puthex(discid, sizeof(discid), stdout); fputc('\n', stdout);
50
51 if (dvd) DVDClose(dvd);
52 progress_free(&progress);
53 return (0);
54 }