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

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

Issue 10802049: Functional prefs implementation (Closed)
Patch Set: Cleaned up init.js a bit Created June 5, 2013, 9:44 a.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 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2013 Eyeo GmbH 3 * Copyright (C) 2006-2013 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #include <AdblockPlus.h> 18 #include <AdblockPlus.h>
19 #include <iostream> 19 #include <iostream>
20 #include <sstream> 20 #include <sstream>
21 21
22 #include "GcCommand.h" 22 #include "GcCommand.h"
23 #include "HelpCommand.h" 23 #include "HelpCommand.h"
24 #include "FiltersCommand.h" 24 #include "FiltersCommand.h"
25 #include "MatchesCommand.h"
26 #include "PrefsCommand.h"
25 #include "SubscriptionsCommand.h" 27 #include "SubscriptionsCommand.h"
26 #include "MatchesCommand.h"
27 28
28 namespace 29 namespace
29 { 30 {
30 void Add(CommandMap& commands, Command* command) 31 void Add(CommandMap& commands, Command* command)
31 { 32 {
32 commands[command->name] = command; 33 commands[command->name] = command;
33 } 34 }
34 35
35 bool ReadCommandLine(std::string& commandLine) 36 bool ReadCommandLine(std::string& commandLine)
36 { 37 {
(...skipping 24 matching lines...) Expand all
61 appInfo.locale = "en-US"; 62 appInfo.locale = "en-US";
62 AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New(appInfo)); 63 AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New(appInfo));
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));
68 Add(commands, new FiltersCommand(filterEngine)); 69 Add(commands, new FiltersCommand(filterEngine));
69 Add(commands, new SubscriptionsCommand(filterEngine)); 70 Add(commands, new SubscriptionsCommand(filterEngine));
70 Add(commands, new MatchesCommand(filterEngine)); 71 Add(commands, new MatchesCommand(filterEngine));
72 Add(commands, new PrefsCommand(filterEngine));
71 73
72 std::string commandLine; 74 std::string commandLine;
73 while (ReadCommandLine(commandLine)) 75 while (ReadCommandLine(commandLine))
74 { 76 {
75 std::string commandName; 77 std::string commandName;
76 std::string arguments; 78 std::string arguments;
77 ParseCommandLine(commandLine, commandName, arguments); 79 ParseCommandLine(commandLine, commandName, arguments);
78 const CommandMap::const_iterator it = commands.find(commandName); 80 const CommandMap::const_iterator it = commands.find(commandName);
79 try 81 try
80 { 82 {
81 if (it != commands.end()) 83 if (it != commands.end())
82 (*it->second)(arguments); 84 (*it->second)(arguments);
83 else 85 else
84 throw NoSuchCommandError(commandName); 86 throw NoSuchCommandError(commandName);
85 } 87 }
86 catch (NoSuchCommandError error) 88 catch (NoSuchCommandError error)
87 { 89 {
88 std::cout << error.what() << std::endl; 90 std::cout << error.what() << std::endl;
89 } 91 }
90 } 92 }
91 } 93 }
92 catch (const std::exception& e) 94 catch (const std::exception& e)
93 { 95 {
94 std::cerr << "Exception: " << e.what() << std::endl; 96 std::cerr << "Exception: " << e.what() << std::endl;
95 } 97 }
96 return 0; 98 return 0;
97 } 99 }
OLDNEW

Powered by Google App Engine
This is Rietveld