all repos — openbox @ d011a51039c4c4f4cf81db5f086a0fff192157b3

openbox fork - make it a bit more like ryudo

way sexier buildtree
Dana Jansens danakj@orodu.net
commit

d011a51039c4c4f4cf81db5f086a0fff192157b3

parent

a826509b51c03c55363f15356e73046158fe48aa

1 files changed, 20 insertions(+), 33 deletions(-)

jump to
M src/bindings.ccsrc/bindings.cc

@@ -90,50 +90,37 @@ b.key = XKeysymToKeycode(otk::OBDisplay::display, sym);

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)) + StringVect::const_reverse_iterator it, end = keylist.rend(); + for (it = keylist.rbegin(); it != end; ++it) { + p = ret; + ret = new BindingTree(id); + if (!p) ret->chain = false; + ret->first_child = p; + if (!translate(*it, ret->binding)) { + destroytree(ret); + ret = 0; break; - p->text = *it; - } - if (it != end) { - // build failed.. clean up and return 0 - p = ret; - while (p->first_child) { - BindingTree *c = p->first_child; - delete p; - p = c; } - 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() {