return b.key != 0;
}
+static void destroytree(BindingTree *tree)
+{
+ while (tree) {
+ BindingTree *c = tree->first_child;
+ delete tree;
+ tree = c;
+ }
+}
+
BindingTree *OBBindings::buildtree(const StringVect &keylist, int id)
{
if (keylist.empty()) return 0; // nothing in the list.. return 0
- BindingTree *ret = new BindingTree(id), *p = 0;
+ BindingTree *ret = 0, *p;
- StringVect::const_iterator it, end = keylist.end();
- for (it = keylist.begin(); it != end; ++it) {
- if (p)
- p = p->first_child = new BindingTree(id);
- else
- p = ret; // the first node
-
- if (!translate(*it, p->binding))
- break;
- p->text = *it;
- }
- if (it != end) {
- // build failed.. clean up and return 0
+ StringVect::const_reverse_iterator it, end = keylist.rend();
+ for (it = keylist.rbegin(); it != end; ++it) {
p = ret;
- while (p->first_child) {
- BindingTree *c = p->first_child;
- delete p;
- p = c;
+ ret = new BindingTree(id);
+ if (!p) ret->chain = false;
+ ret->first_child = p;
+ if (!translate(*it, ret->binding)) {
+ destroytree(ret);
+ ret = 0;
+ break;
}
- delete p;
- return 0;
- } else {
- // set the proper chain status on the last node
- p->chain = false;
+ ret->text = *it; // XXX: rm me
}
-
- // successfully built a tree
return ret;
}
-static void destroytree(BindingTree *tree)
-{
- while (tree) {
- BindingTree *c = tree->first_child;
- delete tree;
- tree = c;
- }
-}
OBBindings::OBBindings()
{