-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic_console.cc
53 lines (48 loc) · 1.1 KB
/
basic_console.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
#include <iostream>
#include <vector>
#include <string>
#include <limits>
#include <sstream>
#include "bintree.h"
#include "trie.h"
using namespace std;
void error( string errortext ) {
cout << "{\"type\":\"ERROR\",\"error\":\"" << errortext << "\"}" << endl;
exit(0);
}
void timeout() {
cout << "{\"type\":\"TIMEOUT\"}" << endl;
exit(0);
}
void succes( const vector<binary_tree>& proof ) {
cout << "{\"type\":\"SUCCESS\",\"result\":[";
bool comma = false;
for( const auto& line : proof ) {
if( comma )
cout << ",";
comma = true;
cout << "\"" << line << "\"";
}
cout << "]}" << endl;
}
int main( int argc, char** argv ) {
if( argc <= 2 )
error("Insufficient arguments");
try {
string s = argv[1];
subtree_equivalence equi( s );
vector<subtree_equivalence> premises;
for( int i = 2; i < argc; ++i )
premises.emplace_back( string( argv[i] ) );
try {
auto proof = equi.prove( premises );
proof = mend_proof( premises, proof, equi.side(1) );
succes( proof );
} catch( computation_timeout ) {
timeout();
}
} catch( std::runtime_error e ) {
error( e.what() );
}
return 0;
}