diff options
Diffstat (limited to 'src/FbTk/MacroCommand.cc')
-rw-r--r-- | src/FbTk/MacroCommand.cc | 48 |
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 | |||
26 | namespace FbTk { | 31 | namespace FbTk { |
27 | 32 | ||
33 | namespace { | ||
34 | |||
35 | template <typename M> | ||
36 | M *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 | |||
62 | Command *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 | |||
71 | REGISTER_COMMAND_PARSER(macrocmd, parseMacroCmd); | ||
72 | REGISTER_COMMAND_PARSER(togglecmd, parseMacroCmd); | ||
73 | |||
74 | }; // end anonymous namespace | ||
75 | |||
28 | void MacroCommand::add(RefCount<Command> &com) { | 76 | void MacroCommand::add(RefCount<Command> &com) { |
29 | m_commandlist.push_back(com); | 77 | m_commandlist.push_back(com); |
30 | } | 78 | } |