diff -r f4761f529b9e -r 4866573c6944 librazor/iterator.c --- a/librazor/iterator.c Tue Jul 01 09:44:46 2008 -0400 +++ b/librazor/iterator.c Thu Feb 05 22:43:29 2009 +0000 @@ -1,6 +1,7 @@ /* * Copyright (C) 2008 Kristian Høgsberg * Copyright (C) 2008 Red Hat, Inc + * Copyright (C) 2009 J. Ali Harlow * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -229,6 +230,83 @@ free(pi); } +RAZOR_EXPORT struct razor_file_iterator * +razor_file_iterator_create(struct razor_set *set, struct razor_package *package) +{ + struct razor_file_iterator *fi; + + assert (set != NULL); + assert (package != NULL); + + fi = zalloc(sizeof *fi); + fi->set = set; + fi->index = list_first(&package->files, &set->file_pool); + array_init(&fi->path); + + return fi; +} + +RAZOR_EXPORT int +razor_file_iterator_next(struct razor_file_iterator *fi, + const char **name) +{ + struct razor_entry *e, *dir, *entries; + char *pool, *s, *f; + + assert (fi != NULL); + + if (!fi->index) { + *name = NULL; + return 0; + } + + entries = (struct razor_entry *) fi->set->files.data; + pool = fi->set->file_string_pool.data; + + dir = entries; + fi->path.size = 0; + for(;;) { + e = dir; + do { + if (entries + fi->index->data == e) { + f = pool + e->name; + s = array_add(&fi->path, strlen(f) + 1); + strcpy(s, f); + if (fi->path.size == 1) { + array_add(&fi->path, 1); + strcpy(fi->path.data, "/"); + } + *name = fi->path.data; + fi->index = list_next(fi->index); + return 1; + } + } while (!((e++)->flags & RAZOR_ENTRY_LAST)); + for(e--; e >= dir; e--) + if (e->start && fi->index->data >= e->start) + break; + if (e < dir) + break; + f = pool + e->name; + s = array_add(&fi->path, strlen(f) + 1); + strcpy(s, f); + s += strlen(f); + *s = '/'; + dir = entries + e->start; + } + + printf("file_iterator_next: Failed to find file %d\n",fi->index->data); + *name = NULL; + return 0; +} + +RAZOR_EXPORT void razor_file_iterator_destroy(struct razor_file_iterator *fi) +{ + assert (fi != NULL); + + array_release(&fi->path); + free(fi); +} + struct razor_package_query { struct razor_set *set; char *vector;