diff options
author | Mark Tiefenbruck <mark@fluxbox.org> | 2007-12-20 20:52:20 (GMT) |
---|---|---|
committer | Mark Tiefenbruck <mark@fluxbox.org> | 2007-12-20 20:52:20 (GMT) |
commit | aef3155784f11d2a7238f314049228e46080374e (patch) | |
tree | 0b11cb88c1bef1b908b4552e1c6cb211d88fd3b5 /src/FbTk | |
parent | 03dce043b78103a977bd6c48b81bb1b462aaac5f (diff) | |
download | fluxbox-aef3155784f11d2a7238f314049228e46080374e.zip fluxbox-aef3155784f11d2a7238f314049228e46080374e.tar.bz2 |
convert macro command parsing to use new StringUtil function
Diffstat (limited to 'src/FbTk')
-rw-r--r-- | src/FbTk/LogicCommands.cc | 56 | ||||
-rw-r--r-- | src/FbTk/MacroCommand.cc | 26 |
2 files changed, 34 insertions, 48 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 | |||
29 | using FbTk::StringUtil::removeFirstWhitespace; | 31 | using FbTk::StringUtil::removeFirstWhitespace; |
30 | using FbTk::StringUtil::toLower; | 32 | using FbTk::StringUtil::toLower; |
31 | using std::string; | 33 | using std::string; |
@@ -36,20 +38,16 @@ namespace { | |||
36 | 38 | ||
37 | template <typename M> | 39 | template <typename M> |
38 | M *addCommands(M *macro, const string &args, bool trusted) { | 40 | M *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 | ||
86 | Command *IfCommand::parse(const std::string &command, const std::string &args, | 84 | Command *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); |
diff --git a/src/FbTk/MacroCommand.cc b/src/FbTk/MacroCommand.cc index 55d403c..3a05179 100644 --- a/src/FbTk/MacroCommand.cc +++ b/src/FbTk/MacroCommand.cc | |||
@@ -26,6 +26,7 @@ | |||
26 | #include "ObjectRegistry.hh" | 26 | #include "ObjectRegistry.hh" |
27 | #include "StringUtil.hh" | 27 | #include "StringUtil.hh" |
28 | 28 | ||
29 | #include <list> | ||
29 | #include <string> | 30 | #include <string> |
30 | 31 | ||
31 | namespace FbTk { | 32 | namespace FbTk { |
@@ -35,21 +36,16 @@ namespace { | |||
35 | template <typename M> | 36 | template <typename M> |
36 | M *addCommands(M *macro, const std::string &args, bool trusted) { | 37 | M *addCommands(M *macro, const std::string &args, bool trusted) { |
37 | 38 | ||
38 | std::string cmd; | 39 | std::string blah; |
39 | int err = 0; | 40 | std::list<std::string> cmds; |
40 | int pos = 0; | 41 | StringUtil::stringTokensBetween(cmds, args, blah, '{', '}'); |
41 | 42 | RefCount<Command> cmd(0); | |
42 | while (true) { | 43 | |
43 | RefCount<Command> next(0); | 44 | std::list<std::string>::iterator it = cmds.begin(), it_end = cmds.end(); |
44 | pos += err; | 45 | for (; it != it_end; ++it) { |
45 | err = StringUtil::getStringBetween(cmd, args.c_str() + pos, | 46 | cmd = ObjectRegistry<Command>::instance().parse(*it, trusted); |
46 | '{', '}', " \t\n", true); | 47 | if (*cmd) |
47 | if (err == 0) | 48 | macro->add(cmd); |
48 | break; | ||
49 | if (err > 0) | ||
50 | next = ObjectRegistry<Command>::instance().parse(cmd, trusted); | ||
51 | if (*next != 0) | ||
52 | macro->add(next); | ||
53 | } | 49 | } |
54 | 50 | ||
55 | if (macro->size() > 0) | 51 | if (macro->size() > 0) |