-
Notifications
You must be signed in to change notification settings - Fork 70
/
main.c
80 lines (65 loc) · 1.34 KB
/
main.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
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <errno.h>
#include <string.h>
#include "pes.h"
static void report(const char *fmt, va_list params)
{
vfprintf(stderr, fmt, params);
}
static void die(const char *fmt, ...)
{
va_list params;
va_start(params, fmt);
report(fmt, params);
va_end(params);
exit(1);
}
int main(int argc, char **argv)
{
double density = 1.0;
int i, outputsize = -1;
const char *output = NULL;
struct region region;
struct pes pes = {
.min_x = 65535, .max_x = -65535,
.min_y = 65535, .max_y = -65535,
.blocks = NULL,
.last = NULL,
};
for (i = 1; i < argc; i++) {
const char *arg = argv[i];
if (*arg == '-') {
switch (arg[1]) {
case 's':
outputsize = atoi(argv[i+1]);
i++;
continue;
case 'd':
density = atof(argv[i+1]);
i++;
continue;
}
die("Unknown argument '%s'\n", arg);
}
if (!pes.blocks) {
if (read_path(arg, ®ion))
die("Unable to read file %s (%s)\n", arg, strerror(errno));
if (parse_pes(®ion, &pes) < 0)
die("Unable to parse PES file\n");
continue;
}
if (!output) {
output = arg;
continue;
}
die("Too many arguments (%s)\n", arg);
}
if (!pes.blocks)
die("Need an input PES file\n");
if (!output)
die("Need a png output file name\n");
output_cairo(&pes, output, outputsize, density);
return 0;
}