-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
62 lines (50 loc) · 1.66 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
/*
*
* lp2pb: ASP to PB translator
*
*/
#include "include/parse.h"
#include "include/translate.h"
#include "include/util.h"
#include <csignal>
using namespace std;
#define VERSION 1.0
void signalHandler(int signum) {
cout << "lp2pb: INTERRUPTED\n";
exit(signum);
}
int main(int argc, char* argv[]) {
// Load signalhandler
signal(SIGINT, signalHandler);
// Usage
string usage_message = "Usage: ./lp2pb <-i inputfile1> <-o outputfile>\n";
if(argc == 2 && cmdOptionExists(argv+1, argv+argc, "--version")) {
cout << "lp2pb v" << VERSION << "\n";
} else if(argc == 5 || argc == 3 || argc == 1) {
string inputfile = "pipe";
Executor executor;
Translator translator;
Parser parser;
parser.translator = &translator;
translator.executor = &executor;
if(argc == 5) {
if(cmdOptionExists(argv+1, argv+argc, "-o") && cmdOptionExists(argv+1, argv+argc, "-i")) {
translator.outputfile = getCmdOption(argv+1, argv+argc, "-o");
inputfile = getCmdOption(argv+1, argv+argc, "-i");
} else {
cout << usage_message;
return 0;
}
} else if(argc == 3) {
if(cmdOptionExists(argv+1, argv+argc, "-o")) translator.outputfile = getCmdOption(argv+1, argv+argc, "-o");
else if(cmdOptionExists(argv+1, argv+argc, "-i")) inputfile = getCmdOption(argv+1, argv+argc, "-i");
else {
cout << usage_message;
return 0;
}
}
// Start parsing
parser.parse(inputfile);
} else cout << usage_message;
return 0;
}