-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathab-tile.c
101 lines (91 loc) · 2.51 KB
/
ab-tile.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <curl/multi.h>
#include <gdal/cpl_error.h>
#include <stdio.h>
#include <dirent.h>
#include <getopt.h>
#include <gdal/gdal.h>
#include <gdal/cpl_conv.h>
#include <stdlib.h>
#include <unistd.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 = "+p:r:c:qvh";
const struct option longopts[] = {
{"prefix", required_argument, NULL, 'p'},
{"row", required_argument, NULL, 'r'},
{"column", required_argument, NULL, 'c'},
{"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 'p':
opts->prefix = optarg;
break;
case 'r':
opts->rsize = atoi(optarg);
if (opts->rsize == 0) {
fprintf(stderr,
"ERROR: Either specified 0 as number of rows per tile or conversion of '%s' to integer failed\n",
optarg);
destroy_options(opts);
}
break;
case 'c':
opts->csize = atoi(optarg);
if (opts->csize == 0) {
fprintf(stderr,
"ERROR: Either specified 0 as number of columns per tile or conversion of '%s' to integer failed\n",
optarg);
destroy_options(opts);
}
break;
case 'q':
opts->verbose = 1;
break;
case 'v':
print_version();
destroy_options(opts);
return 0;
case 'h':
print_tile_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 *file_list = gather_files(opts->indir);
tile_files(file_list, opts);
delete_list(file_list);
destroy_options(opts);
return 0;
}