Repository navigation
Expand file tree
/
Copy pathsearch-shell.cpp
More file actions
70 lines (55 loc) · 1.6 KB
/
Copy pathsearch-shell.cpp
File metadata and controls
70 lines (55 loc) · 1.6 KB
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
66
67
68
69
70
#include <iostream>
#include <fstream>
#include "searcheng.h"
#include "searchui.h"
#include "md_parser.h"
#include "txt_parser.h"
#include "cmdhandler.h"
using namespace std;
int main(int argc, char* argv[])
{
if (argc < 2) {
cout << "Must provide an index file" << endl;
return 1;
}
// Declare the search engine
SearchEng seng;
// ---------------------- [TO BE COMPLETED] -------------------------------
// Create and register appropriate parsers for .md and .txt files
seng.register_parser("md", new MDParser());
seng.register_parser("txt", new TXTParser());
// Create the SearchUI object
SearchUI ui(&seng);
// Create and add appropriate Command Handlers to the SearchU
ui.add_handler(new QuitHandler());
ui.add_handler(new PrintHandler());
ui.add_handler(new AndHandler());
ui.add_handler(new OrHandler());
ui.add_handler(new DiffHandler());
ui.add_handler(new IncomingHandler());
ui.add_handler(new OutgoingHandler());
// ------------------------------------------------------------------------
try {
seng.read_pages_from_index(argv[1]);
}
catch (std::exception& e) {
cout << e.what() << endl;
return 1;
}
if (argc == 2)
{
ui.run(cin, cout);
}
else if (argc == 3) {
ifstream in_file(argv[2]);
ui.run(in_file, cout);
}
else {
ifstream in_file(argv[2]);
ofstream out_file(argv[3]);
ui.run(in_file, out_file);
}
// You may add cleanup code here though you likely do not
// need to.
return 0;
}