-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTraceConverterMain.cc
63 lines (51 loc) · 1.33 KB
/
TraceConverterMain.cc
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
#include <unistd.h>
#include <cstring>
#include <iostream>
#include "TraceConverter.hh"
using namespace TraceConverter;
#define EXIT_INVALID_OPTION 1
#define EXIT_INVALID_ARGUMENTS 2
#define EXIT_INPUT_NOT_FOUND 3
#define EXIT_OUTPUT_EXISTS 4
void usage(int exit_code = -1);
int main(int argc, char* argv[]) {
signed char opt;
std::string out_fname;
bool force { false };
while ((opt = getopt(argc, argv, "fho:")) != -1) {
switch (opt) {
case 'f':
force = true;
break;
case 'h':
usage(0);
break;
case 'o':
out_fname = optarg;
break;
case '?':
default:
usage(EXIT_INVALID_OPTION);
}
}
argc -= optind;
argv += optind;
if (argc < 1 || (argc > 1 && !out_fname.empty())) usage(EXIT_INVALID_ARGUMENTS);
if (!out_fname.empty()) {
const std::string in_fname { argv[0] };
convert(in_fname, out_fname, force);
} else {
for (int i = 0; i < argc; i++) {
const std::string in_fname { argv[i] };
const std::string out_fname = make_default_outname(in_fname);
convert(in_fname, out_fname, force);
}
}
return 0;
}
void usage(int exit_code) {
std::cout << "Usage:\n";
std::cout << " convert-trace [-f] [-o OUTPUT] INPUT\n";
std::cout << " convert-trace [-f] INPUT...\n";
std::exit(exit_code);
}