-static void trie_search_f(struct trie_f *trie, const char *search,
- void (*cb)(struct trie_f *trie, const char *key, const char *value)) {
- struct linebuf buf;
- const struct trie_node_f *node;
- size_t i = 0;
-
- linebuf_init(&buf);
-
- node = trie_node_from_off(trie, trie->head->nodes_root_off);
- while (node) {
- const struct trie_node_f *child;
- size_t p = 0;
-
- if (node->prefix_off) {
- uint8_t c;
-
- for (; (c = trie_string(trie, node->prefix_off)[p]); p++) {
- if (c == '*' || c == '?' || c == '[') {
- trie_fnmatch_f(trie, node, p, &buf, search + i + p, cb);
- return;
- }
- if (c != search[i + p])
- return;
- }
- i += p;
- }
-
- child = node_lookup_f(trie, node, '*');
- if (child) {
- linebuf_add_char(&buf, '*');
- trie_fnmatch_f(trie, child, 0, &buf, search + i, cb);
- linebuf_rem_char(&buf);
- }
-
- child = node_lookup_f(trie, node, '?');
- if (child) {
- linebuf_add_char(&buf, '?');
- trie_fnmatch_f(trie, child, 0, &buf, search + i, cb);
- linebuf_rem_char(&buf);
- }
-
- child = node_lookup_f(trie, node, '[');
- if (child) {
- linebuf_add_char(&buf, '[');
- trie_fnmatch_f(trie, child, 0, &buf, search + i, cb);
- linebuf_rem_char(&buf);
- }