]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
index: re-order functions so prototypes are not needed
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Fri, 2 Dec 2011 12:15:00 +0000 (10:15 -0200)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Fri, 2 Dec 2011 12:15:00 +0000 (10:15 -0200)
libkmod/libkmod-index.c

index b4d8f43bba4995fa98934a0e175f437ac3c697f8..fca6966e0f5cdce6865e6a9f17ef39e1ac086be4 100644 (file)
@@ -598,27 +598,6 @@ void index_dump(struct index_file *in, FILE *out, const char *prefix)
        buf_destroy(buf);
 }
 
-/*
- * Search the index for a key
- *
- * Returns the value of the first match
- *
- * The recursive functions free their node argument (using index_close).
- */
-
-static char *index_search__node(struct index_node_f *node, const char *key, int i);
-
-char *index_search(struct index_file *in, const char *key)
-{
-       struct index_node_f *root;
-       char *value;
-
-       root = index_readroot(in);
-       value = index_search__node(root, key, 0);
-
-       return value;
-}
-
 static char *index_search__node(struct index_node_f *node, const char *key, int i)
 {
        char *value;
@@ -657,43 +636,79 @@ static char *index_search__node(struct index_node_f *node, const char *key, int
 }
 
 /*
- * Search the index for a key.  The index may contain wildcards.
+ * Search the index for a key
  *
- * Returns a list of all the values of matching keys.
+ * Returns the value of the first match
+ *
+ * The recursive functions free their node argument (using index_close).
  */
+char *index_search(struct index_file *in, const char *key)
+{
+       struct index_node_f *root;
+       char *value;
 
+       root = index_readroot(in);
+       value = index_search__node(root, key, 0);
+
+       return value;
+}
 
-/* Level 2: descend the tree (until we hit a wildcard) */
-static void index_searchwild__node(struct index_node_f *node,
-                                  struct buffer *buf,
-                                  const char *key, int i,
-                                  struct index_value **out);
 
-/* Level 3: traverse a sub-keyspace which starts with a wildcard,
-            looking for matches.
-*/
-static void index_searchwild__all(struct index_node_f *node, int j,
-                                 struct buffer *buf,
-                                 const char *subkey,
-                                 struct index_value **out);
 
 /* Level 4: add all the values from a matching node */
 static void index_searchwild__allvalues(struct index_node_f *node,
-                                       struct index_value **out);
+                                       struct index_value **out)
+{
+       struct index_value *v;
 
+       for (v = node->values; v != NULL; v = v->next)
+               add_value(out, v->value, v->priority);
 
-/* Level 1: interface function */
-struct index_value *index_searchwild(struct index_file *in, const char *key)
+       index_close(node);
+}
+
+/*
+ * Level 3: traverse a sub-keyspace which starts with a wildcard,
+ * looking for matches.
+ */
+static void index_searchwild__all(struct index_node_f *node, int j,
+                                 struct buffer *buf,
+                                 const char *subkey,
+                                 struct index_value **out)
 {
-       struct index_node_f *root = index_readroot(in);
-       struct buffer *buf = buf_create();
-       struct index_value *out = NULL;
+       int pushed = 0;
+       int ch;
 
-       index_searchwild__node(root, buf, key, 0, &out);
-       buf_destroy(buf);
-       return out;
+       while (node->prefix[j]) {
+               ch = node->prefix[j];
+
+               buf_pushchar(buf, ch);
+               pushed++;
+               j++;
+       }
+
+       for (ch = node->first; ch <= node->last; ch++) {
+               struct index_node_f *child = index_readchild(node, ch);
+
+               if (!child)
+                       continue;
+
+               buf_pushchar(buf, ch);
+               index_searchwild__all(child, 0, buf, subkey, out);
+               buf_popchar(buf);
+       }
+
+       if (node->values) {
+               if (fnmatch(buf_str(buf), subkey, 0) == 0)
+                       index_searchwild__allvalues(node, out);
+       } else {
+               index_close(node);
+       }
+
+       buf_popchars(buf, pushed);
 }
 
+/* Level 2: descend the tree (until we hit a wildcard) */
 static void index_searchwild__node(struct index_node_f *node,
                                   struct buffer *buf,
                                   const char *key, int i,
@@ -754,50 +769,18 @@ static void index_searchwild__node(struct index_node_f *node,
        }
 }
 
-static void index_searchwild__all(struct index_node_f *node, int j,
-                                 struct buffer *buf,
-                                 const char *subkey,
-                                 struct index_value **out)
-{
-       int pushed = 0;
-       int ch;
-
-       while (node->prefix[j]) {
-               ch = node->prefix[j];
-
-               buf_pushchar(buf, ch);
-               pushed++;
-               j++;
-       }
-
-       for (ch = node->first; ch <= node->last; ch++) {
-               struct index_node_f *child = index_readchild(node, ch);
-
-               if (!child)
-                       continue;
-
-               buf_pushchar(buf, ch);
-               index_searchwild__all(child, 0, buf, subkey, out);
-               buf_popchar(buf);
-       }
-
-       if (node->values) {
-               if (fnmatch(buf_str(buf), subkey, 0) == 0)
-                       index_searchwild__allvalues(node, out);
-       } else {
-               index_close(node);
-       }
-
-       buf_popchars(buf, pushed);
-}
-
-static void index_searchwild__allvalues(struct index_node_f *node,
-                                       struct index_value **out)
+/*
+ * Search the index for a key.  The index may contain wildcards.
+ *
+ * Returns a list of all the values of matching keys.
+ */
+struct index_value *index_searchwild(struct index_file *in, const char *key)
 {
-       struct index_value *v;
-
-       for (v = node->values; v != NULL; v = v->next)
-               add_value(out, v->value, v->priority);
+       struct index_node_f *root = index_readroot(in);
+       struct buffer *buf = buf_create();
+       struct index_value *out = NULL;
 
-       index_close(node);
+       index_searchwild__node(root, buf, key, 0, &out);
+       buf_destroy(buf);
+       return out;
 }