Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: shell/src/Main.cpp

Issue 10100009: FilterEngine API improvements (Closed)
Patch Set: Replace GetElementHidingRules by a domain-specific GetElementHidingSelectors Created April 5, 2013, 12:22 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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 "SubscriptionsCommand.h" 9 #include "SubscriptionsCommand.h"
9 #include "MatchesCommand.h" 10 #include "MatchesCommand.h"
10 11
11 namespace 12 namespace
12 { 13 {
13 class LibFileReader : public AdblockPlus::FileReader 14 class LibFileReader : public AdblockPlus::FileReader
14 { 15 {
15 public: 16 public:
16 std::auto_ptr<std::istream> Read(const std::string& path) const 17 std::auto_ptr<std::istream> Read(const std::string& path) const
17 { 18 {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 try 59 try
59 { 60 {
60 LibFileReader fileReader; 61 LibFileReader fileReader;
61 CerrErrorCallback errorCallback; 62 CerrErrorCallback errorCallback;
62 AdblockPlus::JsEngine jsEngine(&fileReader, 0); 63 AdblockPlus::JsEngine jsEngine(&fileReader, 0);
63 AdblockPlus::FilterEngine filterEngine(jsEngine); 64 AdblockPlus::FilterEngine filterEngine(jsEngine);
64 65
65 CommandMap commands; 66 CommandMap commands;
66 Add(commands, new GcCommand(jsEngine)); 67 Add(commands, new GcCommand(jsEngine));
67 Add(commands, new HelpCommand(commands)); 68 Add(commands, new HelpCommand(commands));
69 Add(commands, new FiltersCommand(filterEngine));
68 Add(commands, new SubscriptionsCommand(filterEngine)); 70 Add(commands, new SubscriptionsCommand(filterEngine));
69 Add(commands, new MatchesCommand(filterEngine)); 71 Add(commands, new MatchesCommand(filterEngine));
70 72
71 std::string commandLine; 73 std::string commandLine;
72 while (ReadCommandLine(commandLine)) 74 while (ReadCommandLine(commandLine))
73 { 75 {
74 std::string commandName; 76 std::string commandName;
75 std::string arguments; 77 std::string arguments;
76 ParseCommandLine(commandLine, commandName, arguments); 78 ParseCommandLine(commandLine, commandName, arguments);
77 const CommandMap::const_iterator it = commands.find(commandName); 79 const CommandMap::const_iterator it = commands.find(commandName);
78 try 80 try
79 { 81 {
80 if (it != commands.end()) 82 if (it != commands.end())
81 (*it->second)(arguments); 83 (*it->second)(arguments);
82 else 84 else
83 throw NoSuchCommandError(commandName); 85 throw NoSuchCommandError(commandName);
84 } 86 }
85 catch (NoSuchCommandError error) 87 catch (NoSuchCommandError error)
86 { 88 {
87 std::cout << error.what() << std::endl; 89 std::cout << error.what() << std::endl;
88 } 90 }
89 } 91 }
90 } 92 }
91 catch (const std::exception& e) 93 catch (const std::exception& e)
92 { 94 {
93 std::cerr << "Exception: " << e.what() << std::endl; 95 std::cerr << "Exception: " << e.what() << std::endl;
94 } 96 }
95 return 0; 97 return 0;
96 } 98 }
OLDNEW

Powered by Google App Engine
This is Rietveld