aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/MacroCommand.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk/MacroCommand.cc')
-rw-r--r--src/FbTk/MacroCommand.cc48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/FbTk/MacroCommand.cc b/src/FbTk/MacroCommand.cc
index 491b01e..20e91e4 100644
--- a/src/FbTk/MacroCommand.cc
+++ b/src/FbTk/MacroCommand.cc
@@ -23,8 +23,56 @@
23 23
24#include "MacroCommand.hh" 24#include "MacroCommand.hh"
25 25
26#include "CommandRegistry.hh"
27#include "StringUtil.hh"
28
29#include <string>
30
26namespace FbTk { 31namespace FbTk {
27 32
33namespace {
34
35template <typename M>
36M *addCommands(M *macro, const std::string &args, bool trusted) {
37
38 std::string cmd;
39 int err = 0;
40 int pos = 0;
41
42 while (true) {
43 RefCount<Command> next(0);
44 pos += err;
45 err = StringUtil::getStringBetween(cmd, args.c_str() + pos,
46 '{', '}', " \t\n", true);
47 if (err == 0)
48 break;
49 if (err > 0)
50 next = CommandRegistry::instance().parseLine(cmd, trusted);
51 if (*next != 0)
52 macro->add(next);
53 }
54
55 if (macro->size() > 0)
56 return macro;
57
58 delete macro;
59 return 0;
60}
61
62Command *parseMacroCmd(const std::string &command, const std::string &args,
63 bool trusted) {
64 if (command == "macrocmd")
65 return addCommands<MacroCommand>(new MacroCommand, args, trusted);
66 else if (command == "togglecmd")
67 return addCommands<ToggleCommand>(new ToggleCommand, args, trusted);
68 return 0;
69}
70
71REGISTER_COMMAND_PARSER(macrocmd, parseMacroCmd);
72REGISTER_COMMAND_PARSER(togglecmd, parseMacroCmd);
73
74}; // end anonymous namespace
75
28void MacroCommand::add(RefCount<Command> &com) { 76void MacroCommand::add(RefCount<Command> &com) {
29 m_commandlist.push_back(com); 77 m_commandlist.push_back(com);
30} 78}