OLD | NEW |
1 #include <AdblockPlus.h> | 1 #include <AdblockPlus.h> |
2 #include <fstream> | 2 #include <fstream> |
3 #include <iostream> | 3 #include <iostream> |
4 #include <sstream> | 4 #include <sstream> |
5 | 5 |
6 #include "GcCommand.h" | 6 #include "GcCommand.h" |
7 #include "HelpCommand.h" | 7 #include "HelpCommand.h" |
8 #include "SubscriptionsCommand.h" | 8 #include "SubscriptionsCommand.h" |
9 #include "MatchesCommand.h" | 9 #include "MatchesCommand.h" |
10 | 10 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 } | 53 } |
54 } | 54 } |
55 | 55 |
56 int main() | 56 int main() |
57 { | 57 { |
58 try | 58 try |
59 { | 59 { |
60 LibFileReader fileReader; | 60 LibFileReader fileReader; |
61 CerrErrorCallback errorCallback; | 61 CerrErrorCallback errorCallback; |
62 AdblockPlus::JsEngine jsEngine(&fileReader, 0); | 62 AdblockPlus::JsEngine jsEngine(&fileReader, 0); |
63 jsEngine.Load("adblockplus_compat.js"); | 63 AdblockPlus::FilterEngine filterEngine(jsEngine); |
64 jsEngine.Load("adblockplus.js"); | |
65 | 64 |
66 CommandMap commands; | 65 CommandMap commands; |
67 Add(commands, new GcCommand(jsEngine)); | 66 Add(commands, new GcCommand(jsEngine)); |
68 Add(commands, new HelpCommand(commands)); | 67 Add(commands, new HelpCommand(commands)); |
69 Add(commands, new SubscriptionsCommand(jsEngine)); | 68 Add(commands, new SubscriptionsCommand(filterEngine)); |
70 Add(commands, new MatchesCommand()); | 69 Add(commands, new MatchesCommand(filterEngine)); |
71 | 70 |
72 std::string commandLine; | 71 std::string commandLine; |
73 while (ReadCommandLine(commandLine)) | 72 while (ReadCommandLine(commandLine)) |
74 { | 73 { |
75 std::string commandName; | 74 std::string commandName; |
76 std::string arguments; | 75 std::string arguments; |
77 ParseCommandLine(commandLine, commandName, arguments); | 76 ParseCommandLine(commandLine, commandName, arguments); |
78 const CommandMap::const_iterator it = commands.find(commandName); | 77 const CommandMap::const_iterator it = commands.find(commandName); |
79 try | 78 try |
80 { | 79 { |
81 if (it != commands.end()) | 80 if (it != commands.end()) |
82 (*it->second)(arguments); | 81 (*it->second)(arguments); |
83 else | 82 else |
84 throw NoSuchCommandError(commandName); | 83 throw NoSuchCommandError(commandName); |
85 } | 84 } |
86 catch (NoSuchCommandError error) | 85 catch (NoSuchCommandError error) |
87 { | 86 { |
88 std::cout << error.what() << std::endl; | 87 std::cout << error.what() << std::endl; |
89 } | 88 } |
90 } | 89 } |
91 } | 90 } |
92 catch (const std::exception& e) | 91 catch (const std::exception& e) |
93 { | 92 { |
94 std::cerr << "Exception: " << e.what() << std::endl; | 93 std::cerr << "Exception: " << e.what() << std::endl; |
95 } | 94 } |
96 return 0; | 95 return 0; |
97 } | 96 } |
OLD | NEW |