aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/LogicCommands.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk/LogicCommands.cc')
-rw-r--r--src/FbTk/LogicCommands.cc56
1 files changed, 23 insertions, 33 deletions
diff --git a/src/FbTk/LogicCommands.cc b/src/FbTk/LogicCommands.cc
index df5f2d5..f9e8ab7 100644
--- a/src/FbTk/LogicCommands.cc
+++ b/src/FbTk/LogicCommands.cc
@@ -26,6 +26,8 @@
26#include "ObjectRegistry.hh" 26#include "ObjectRegistry.hh"
27#include "StringUtil.hh" 27#include "StringUtil.hh"
28 28
29#include <vector>
30
29using FbTk::StringUtil::removeFirstWhitespace; 31using FbTk::StringUtil::removeFirstWhitespace;
30using FbTk::StringUtil::toLower; 32using FbTk::StringUtil::toLower;
31using std::string; 33using std::string;
@@ -36,20 +38,16 @@ namespace {
36 38
37template <typename M> 39template <typename M>
38M *addCommands(M *macro, const string &args, bool trusted) { 40M *addCommands(M *macro, const string &args, bool trusted) {
39 int pos = 0, err = 0; 41 std::string blah;
40 string cmd; 42 std::vector<std::string> cmds;
41 43 StringUtil::stringTokensBetween(cmds, args, blah, '{', '}');
42 while (true) { 44 RefCount<BoolCommand> cmd(0);
43 RefCount<BoolCommand> tmp(0); 45
44 err = StringUtil::getStringBetween(cmd, args.c_str() + pos, 46 std::vector<std::string>::iterator it = cmds.begin(), it_end = cmds.end();
45 '{', '}', " \t\n", true); 47 for (; it != it_end; ++it) {
46 pos += err; 48 cmd = ObjectRegistry<BoolCommand>::instance().parse(*it, trusted);
47 if (err == 0) 49 if (*cmd)
48 break; 50 macro->add(cmd);
49
50 tmp = ObjectRegistry<BoolCommand>::instance().parse(cmd, trusted);
51 if (*tmp)
52 macro->add(tmp);
53 } 51 }
54 52
55 if (macro->size() > 0) 53 if (macro->size() > 0)
@@ -85,31 +83,23 @@ REGISTER_OBJECT_PARSER(xor, parseLogicCommand, BoolCommand);
85 83
86Command *IfCommand::parse(const std::string &command, const std::string &args, 84Command *IfCommand::parse(const std::string &command, const std::string &args,
87 bool trusted) { 85 bool trusted) {
88 std::string cmd; 86 std::string blah;
89 int err = 0, pos = 0; 87 std::vector<std::string> cmds;
90 RefCount<BoolCommand> cond(0); 88 RefCount<BoolCommand> cond(0);
91 RefCount<Command> t(0), f(0); 89 RefCount<Command> t(0), f(0);
92 90
93 err = StringUtil::getStringBetween(cmd, args.c_str(), 91 StringUtil::stringTokensBetween(cmds, args, blah, '{', '}');
94 '{', '}', " \t\n", true); 92 if (cmds.size() < 3)
95 if (err > 0)
96 cond = ObjectRegistry<BoolCommand>::instance().parse(cmd, trusted);
97 if (err == 0 || *cond == 0)
98 return 0; 93 return 0;
99 94
100 pos = err; 95 cond = ObjectRegistry<BoolCommand>::instance().parse(cmds[0], trusted);
101 err = StringUtil::getStringBetween(cmd, args.c_str() + pos, 96 if (*cond == 0)
102 '{', '}', " \t\n", true);
103 if (err == 0)
104 return 0; 97 return 0;
105 t = ObjectRegistry<Command>::instance().parse(cmd, trusted); 98
106 99 t = ObjectRegistry<Command>::instance().parse(cmds[1], trusted);
107 pos += err; 100 if (cmds.size() >= 3)
108 err = StringUtil::getStringBetween(cmd, args.c_str() + pos, 101 f = ObjectRegistry<Command>::instance().parse(cmds[2], trusted);
109 '{', '}', " \t\n", true); 102 if (*t == 0 && *f == 0)
110 if (err > 0)
111 f = ObjectRegistry<Command>::instance().parse(cmd, trusted);
112 if (err == 0 || *t == 0 && *f == 0)
113 return 0; 103 return 0;
114 104
115 return new IfCommand(cond, t, f); 105 return new IfCommand(cond, t, f);