-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathmain.cpp
51 lines (47 loc) · 1.38 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
#include "SWI-cpp2.h"
#include <iostream>
int
main(int argc, char **argv) // TODO: char *argv[]
{ PlEngine e(argv[0]);
// PlEngine can throw PlEngineInitialisationFailed or
// PlOpenForeignFrameFailed
try
{ PlTermv av(1);
PlTerm_tail l(av[0]);
try
{ for(int i=0; i<argc; i++)
PlCheckFail(l.append(PlTerm_string(argv[i]))); // Can throw PlFail
PlCheckFail(l.close());
} catch ( const PlFail &ex )
{ std::cerr << "ERROR: append failed." << std::endl;
return 253;
}
{ PlQuery q1("writeln", av);
if ( !PlWrap<int>(q1.next_solution()) )
{ std::cerr << "*** q1 failed" << std::endl;
return 1;
}
if ( PlWrap<int>(q1.next_solution()) ) // There should be just 1 solution
{ std::cerr << "*** q1 2nd solution should have failed" << std::endl;
return 2;
}
}
{ PlQuery q3("fail", PlTermv());
if ( PlWrap<int>(q3.next_solution()) )
{ std::cerr << "*** q3 should have failed" << std::endl;
return 3;
}
}
{ PlQuery q4("writelnx", av);
if ( !PlWrap<int>(q4.next_solution()) )
{ std::cerr << "*** q4 failed" << std::endl;
return 4;
}
return 5; // writelnx should have thrown an existence error
}
} catch ( const PlException &ex )
{ std::cerr << "ERROR: " << ex.what() << std::endl;
return 254;
}
return 0;
}