-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathab-convert.c
76 lines (66 loc) · 1.73 KB
/
ab-convert.c
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <stdio.h>
#include <getopt.h>
#include <stdlib.h>
#include "src/aerial-berlin.h"
#include "src/tile.h"
int main(int argc, char **argv)
{
options *opts = create_options();
int opt;
const char *shortopts = "+b:qvh";
const struct option longopts[] = {
{"bands", required_argument, NULL, 'b'},
{"quiet", no_argument, NULL, 'q'},
{"version", no_argument, NULL, 'v'},
{"help", no_argument, NULL, 'h'},
{0, 0, 0, 0}
};
while ((opt = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
switch (opt) {
case 'b':
if (parse_bands(opts, optarg))
exit(EXIT_FAILURE);
break;
case 'q':
opts->verbose = 1;
break;
case 'v':
print_version();
destroy_options(opts);
return 0;
case 'h':
print_convert_help();
destroy_options(opts);
return 0;
case '?':
break;
}
}
if (argc - optind == 2) {
opts->indir = argv[optind++];
opts->outdir = argv[optind++];
} else {
fprintf(stderr,
"ERROR: Expected 2 positional argument: input directory and output directory. Found %d\n",
argc - optind);
destroy_options(opts);
return 1;
}
if (opts->verbose)
print_options(opts);
if (check_dir(opts->indir)) {
fprintf(stderr, "ERROR: Could not access directory '%s'\n", opts->indir);
destroy_options(opts);
return 1;
}
if (check_dir(opts->outdir)) {
fprintf(stderr, "ERROR: Could not access directory '%s'\n", opts->outdir);
destroy_options(opts);
return 1;
}
List *files = gather_files(opts->indir);
convert_files(files, opts);
delete_list(files);
destroy_options(opts);
return 0;
}