| Left: | ||
| Right: |
| 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 "FiltersCommand.h" | 8 #include "FiltersCommand.h" |
| 9 #include "SubscriptionsCommand.h" | 9 #include "SubscriptionsCommand.h" |
| 10 #include "MatchesCommand.h" | 10 #include "MatchesCommand.h" |
| 11 | 11 |
| 12 namespace | 12 namespace |
| 13 { | 13 { |
| 14 class LibFileReader : public AdblockPlus::FileReader | 14 class LibFileSystem : public AdblockPlus::FileSystem |
| 15 { | 15 { |
| 16 public: | 16 public: |
| 17 std::auto_ptr<std::istream> Read(const std::string& path) const | 17 std::auto_ptr<std::istream> Read(const std::string& path) const |
| 18 { | 18 { |
| 19 std::ifstream* file = new std::ifstream; | 19 std::ifstream* file = new std::ifstream; |
| 20 file->open(("lib/" + path).c_str()); | 20 file->open(("lib/" + path).c_str()); |
|
Wladimir Palant
2013/04/12 16:10:35
I don't think this dummy implementation is useful.
Felix Dahlke
2013/04/15 03:43:34
Fair enough, will do that.
| |
| 21 return std::auto_ptr<std::istream>(file); | 21 return std::auto_ptr<std::istream>(file); |
| 22 } | 22 } |
| 23 | |
| 24 void Write(const std::string& path, const std::string& content) | |
| 25 { | |
| 26 throw std::runtime_error("Write is not implemented"); | |
| 27 } | |
| 28 | |
| 29 void Move(const std::string& fromPath, const std::string& toPath) | |
| 30 { | |
| 31 throw std::runtime_error("Move is not implemented"); | |
| 32 } | |
| 33 | |
| 34 void Remove(const std::string& path) | |
| 35 { | |
| 36 throw std::runtime_error("Remove is not implemented"); | |
| 37 } | |
| 38 | |
| 39 StatResult Stat(const std::string& path) const | |
| 40 { | |
| 41 throw std::runtime_error("Stat is not implemented"); | |
| 42 } | |
| 23 }; | 43 }; |
| 24 | 44 |
| 25 class CerrErrorCallback : public AdblockPlus::ErrorCallback | 45 class CerrErrorCallback : public AdblockPlus::ErrorCallback |
| 26 { | 46 { |
| 27 public: | 47 public: |
| 28 void operator()(const std::string& message) | 48 void operator()(const std::string& message) |
| 29 { | 49 { |
| 30 std::cerr << "Error: " << message << std::endl; | 50 std::cerr << "Error: " << message << std::endl; |
| 31 } | 51 } |
| 32 }; | 52 }; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 51 std::istringstream lineStream(commandLine); | 71 std::istringstream lineStream(commandLine); |
| 52 lineStream >> name; | 72 lineStream >> name; |
| 53 std::getline(lineStream, arguments); | 73 std::getline(lineStream, arguments); |
| 54 } | 74 } |
| 55 } | 75 } |
| 56 | 76 |
| 57 int main() | 77 int main() |
| 58 { | 78 { |
| 59 try | 79 try |
| 60 { | 80 { |
| 61 LibFileReader fileReader; | 81 LibFileSystem fileSystem; |
| 62 AdblockPlus::DefaultWebRequest webRequest; | 82 AdblockPlus::DefaultWebRequest webRequest; |
| 63 CerrErrorCallback errorCallback; | 83 CerrErrorCallback errorCallback; |
| 64 AdblockPlus::JsEngine jsEngine(&fileReader, &webRequest, &errorCallback); | 84 AdblockPlus::JsEngine jsEngine(&fileSystem, &webRequest, &errorCallback); |
| 65 AdblockPlus::FilterEngine filterEngine(jsEngine); | 85 AdblockPlus::FilterEngine filterEngine(jsEngine); |
| 66 | 86 |
| 67 CommandMap commands; | 87 CommandMap commands; |
| 68 Add(commands, new GcCommand(jsEngine)); | 88 Add(commands, new GcCommand(jsEngine)); |
| 69 Add(commands, new HelpCommand(commands)); | 89 Add(commands, new HelpCommand(commands)); |
| 70 Add(commands, new FiltersCommand(filterEngine)); | 90 Add(commands, new FiltersCommand(filterEngine)); |
| 71 Add(commands, new SubscriptionsCommand(filterEngine)); | 91 Add(commands, new SubscriptionsCommand(filterEngine)); |
| 72 Add(commands, new MatchesCommand(filterEngine)); | 92 Add(commands, new MatchesCommand(filterEngine)); |
| 73 | 93 |
| 74 std::string commandLine; | 94 std::string commandLine; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 90 std::cout << error.what() << std::endl; | 110 std::cout << error.what() << std::endl; |
| 91 } | 111 } |
| 92 } | 112 } |
| 93 } | 113 } |
| 94 catch (const std::exception& e) | 114 catch (const std::exception& e) |
| 95 { | 115 { |
| 96 std::cerr << "Exception: " << e.what() << std::endl; | 116 std::cerr << "Exception: " << e.what() << std::endl; |
| 97 } | 117 } |
| 98 return 0; | 118 return 0; |
| 99 } | 119 } |
| OLD | NEW |