-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
82 lines (73 loc) · 1.79 KB
/
main.cpp
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
/*
* CLI for bin-packing optimizer
* Takes an input file in the format specified in README.md
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <iostream>
#include <unistd.h>
#include "bin.h"
#include "parse.h"
void usage() {
fprintf(stderr, "-f /path/to/input [-o /path/to/output]\n");
}
int threads_per_block = 1;
int main(int argc, char *argv[]) {
char *infile = NULL;
char *outfile = NULL;
bool bfd_flag = false;
int opt;
opterr = 0;
while ((opt = getopt(argc, argv, "f:o:bt:")) != -1) {
switch (opt) {
case 'f':
infile = optarg;
break;
case 'o':
outfile = optarg;
break;
case 'b':
bfd_flag = true;
break;
case 't':
threads_per_block = atoi(optarg);
break;
case '?':
if (optopt == 'f') {
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
} else if (optopt == 'o') {
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
} else if (optopt == 't') {
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
} else if (isprint (optopt)) {
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
} else {
fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
usage();
return 1;
}
default:
fprintf(stderr, "Malformed input arguments. Aborting.\n");
usage();
return 1;
}
}
if (infile==NULL) {
fprintf(stderr, "Input file unspecified\n");
usage();
return 1;
}
if (!parse(infile)) {
fprintf(stderr, "Failed to parse input\n");
}
if(!bfd_flag){
run();
} else {
runBFD();
}
if (!dump(outfile)) {
fprintf(stderr, "Failed to write output\n");
}
return 0;
}