about summary refs log tree commit diff
path: root/cli/btinfo.c
blob: f451c85a0dde386586fccbf3ccc60f888aa0c282 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <sys/types.h>

#include <err.h>
#include <errno.h>
#include <getopt.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>

#include "metainfo.h"

static void
usage()
{
    fprintf(stderr, "Usage: btinfo file ...\n\n");
    exit(1);
}

static struct option longopts[] = {
    { "help", no_argument, NULL, 1 },
    { NULL, 0, NULL, 0 }
};

int
main(int argc, char **argv)
{
    int ch;

    while ((ch = getopt_long(argc, argv, "", longopts, NULL)) != -1)
        usage();

    argc -= optind;
    argv += optind;

    if (argc < 1)
        usage();

    while (argc > 0) {
        struct metainfo *mi;

        if ((errno = load_metainfo(*argv, -1, 1, &mi)) != 0)
            err(1, "load_metainfo: %s", *argv);

        print_metainfo(mi);
        clear_metainfo(mi);
        free(mi);

        argc--;
        argv++;
    }

    return 0;
}