namespace ob {
#include <stdio.h>
-static void print_branch(BindingTree *first, std::string str)
+static void print_branch(const BindingTree *first, std::string str)
{
- BindingTree *p = first;
+ const BindingTree *p = first;
while (p) {
if (p->first_child)
return true;
}
-bool OBBindings::translate(const std::string &str, Binding &b, bool askey)
+bool OBBindings::translate(const std::string &str, Binding &b,
+ bool askey) const
{
// parse out the base key name
std::string::size_type keybegin = str.find_last_of('-');
}
}
-BindingTree *OBBindings::buildtree(const StringVect &keylist, int id)
+BindingTree *OBBindings::buildtree(const StringVect &keylist, int id) const
{
if (keylist.empty()) return 0; // nothing in the list.. return 0
for (it = keylist.rbegin(); it != end; ++it) {
p = ret;
ret = new BindingTree(id);
- if (!p) ret->chain = false;
+ if (!p) ret->chain = false; // only the first built node
ret->first_child = p;
if (!translate(*it, ret->binding, true)) {
destroytree(ret);
{
BindingTree *a, *b, *tmp, *last;
- printf("node=%lx\n", (long)node);
if (!_keytree.first_child) {
// there are no nodes at this level yet
_keytree.first_child = node;
- return;
} else {
a = _keytree.first_child;
last = a;
b = node;
while (a) {
- printf("in while.. b=%lx\n", (long)b);
last = a;
if (a->binding != b->binding) {
a = a->next_sibling;
} else {
- printf("a: %s %d %d\n", a->text.c_str(), a->binding.key, a->binding.modifiers);
- printf("b: %s %d %d\n", b->text.c_str(), b->binding.key, b->binding.modifiers);
- printf("moving up one in b\n");
tmp = b;
b = b->first_child;
delete tmp;
a = a->first_child;
}
}
- printf("after while.. b=%lx\n", (long)b);
if (last->binding != b->binding)
last->next_sibling = b;
- else
+ else {
last->first_child = b->first_child;
- delete b;
+ delete b;
+ }
}
}
-int OBBindings::find_key(BindingTree *search) {
+int OBBindings::find_key(BindingTree *search) const {
BindingTree *a, *b;
a = _keytree.first_child;
b = search;
a = a->next_sibling;
} else {
if (a->chain == b->chain) {
- if (!a->chain)
+ if (!a->chain) {
return a->id; // found it! (return the actual id, not the search's)
- } else
- return -2; // the chain status' don't match (conflict!)
+ }
+ } else {
+ return -2; // the chain status' don't match (conflict!)
+ }
b = b->first_child;
a = a->first_child;
}
// assimilate this built tree into the main tree
assimilate(tree); // assimilation destroys/uses the tree
+
return true;
}