]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
index: mmap: add support for searching node
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Fri, 2 Dec 2011 19:45:01 +0000 (17:45 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Sat, 3 Dec 2011 06:07:16 +0000 (04:07 -0200)
Almost a clean copy & paste from the previous implementation.

libkmod/libkmod-index.c

index c21eec7662cff4d0ee8a4e942f0498e24ea7e9a9..b20aeec10f75c0a6c74793faf3384766de1edb9e 100644 (file)
@@ -717,3 +717,42 @@ static struct index_mm_node *index_mm_readchild(const struct index_mm_node *pare
 
        return NULL;
 }
+
+static char *index_mm_search_node(struct index_mm_node *node, const char *key,
+                                                                       int i)
+{
+       char *value;
+       struct index_mm_node *child;
+       int ch;
+       int j;
+
+       while(node) {
+               for (j = 0; node->prefix[j]; j++) {
+                       ch = node->prefix[j];
+
+                       if (ch != key[i+j]) {
+                               index_mm_free_node(node);
+                               return NULL;
+                       }
+               }
+
+               i += j;
+
+               if (key[i] == '\0') {
+                       if (node->values) {
+                               value = strdup(node->values[0].value);
+                               index_mm_free_node(node);
+                               return value;
+                       } else {
+                               return NULL;
+                       }
+               }
+
+               child = index_mm_readchild(node, key[i]);
+               index_mm_free_node(node);
+               node = child;
+               i++;
+       }
+
+       return NULL;
+}