-
Notifications
You must be signed in to change notification settings - Fork 3
/
stakk_server.cc
65 lines (57 loc) · 1.53 KB
/
stakk_server.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
64
65
#include "stakk_server.h"
using namespace stakk;
int main(int argc, char *argv[]) {
//parse option
int result;
int port = 50000;
string dictionary_ = "data/dictionary.txt";
string connection_ = "data/connection.txt";
string id_def = "data/id.def";
bool reverse = false;
try { locale::global(locale("")); } catch (...) {}
while((result = getopt(argc, argv, "d:c:i:p:br")) != -1) {
switch(result) {
case 'd':
dictionary_ = optarg;
break;
case 'c':
connection_ = optarg;
break;
case 'i':
id_def = optarg;
break;
case 'p':
port = atoi(optarg);
break;
case 'r':
reverse = true;
break;
}
}
wcout << "loading dictionary" << endl;
WideTrie trie;
int field = reverse ? 4 : 0;
if (!trie.load(dictionary_, field, L'\t')) {
cout << dictionary_ << " is not found." << endl;
exit(0);
}
wcout << "loading connection" << endl;
Connection connection;
if (!connection.load(connection_)) {
cout << connection_ << " is not found." << endl;
exit(0);
}
wcout << "loading id definition" << endl;
Definition definition;
if (!definition.load(id_def)) {
cout << id_def << " is not found." << endl;
exit(0);
}
//initialize action objects using data object reference.
Stakk stakk(trie, connection);
Converter converter(trie, connection, definition);
StakkServer server(port, trie, stakk, converter);
wcout << "server ready" << endl;
result = server.communicate();
return result;
}