The following commit has been merged in the master branch:
commit fed0b802b21f21408ae97ac3de1f31c9f7e6d01c
Author: Guillem Jover <[email protected]>
Date:   Mon Sep 14 21:52:41 2009 +0200

    libdpkg: Create a new pkg_list structure and functions
    
    A new functions to construct and free a list and prepend to a list.

diff --git a/lib/dpkg/Makefile.am b/lib/dpkg/Makefile.am
index a1eedd6..d45bcd4 100644
--- a/lib/dpkg/Makefile.am
+++ b/lib/dpkg/Makefile.am
@@ -41,6 +41,7 @@ libdpkg_a_SOURCES = \
        parsedump.h \
        path.c path.h \
        pkg-array.c pkg-array.h \
+       pkg-list.c pkg-list.h \
        progress.c progress.h \
        showpkg.c \
        string.c string.h \
diff --git a/lib/dpkg/pkg-array.h b/lib/dpkg/pkg-list.c
similarity index 60%
copy from lib/dpkg/pkg-array.h
copy to lib/dpkg/pkg-list.c
index 939b386..c3619cc 100644
--- a/lib/dpkg/pkg-array.h
+++ b/lib/dpkg/pkg-list.c
@@ -1,6 +1,6 @@
 /*
  * dpkg - main program for package management
- * pkg-array.h - primitives for pkg array handling
+ * pkg-list.c - primitives for pkg linked list handling
  *
  * Copyright © 2009 Guillem Jover <[email protected]>
  *
@@ -19,27 +19,43 @@
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-#ifndef DPKG_PKG_ARRAY_H
-#define DPKG_PKG_ARRAY_H
-
 #include <config.h>
 #include <compat.h>
 
+#include <stdlib.h>
+
+#include <dpkg/dpkg.h>
 #include <dpkg/dpkg-db.h>
+#include <dpkg/pkg-list.h>
+
+struct pkg_list *
+pkg_list_new(struct pkginfo *pkg, struct pkg_list *next)
+{
+       struct pkg_list *node;
+
+       node = m_malloc(sizeof(*node));
+       node->pkg = pkg;
+       node->next = next;
 
-DPKG_BEGIN_DECLS
+       return node;
+}
 
-typedef int pkg_sorter_func(const void *a, const void *b);
+void
+pkg_list_free(struct pkg_list *head)
+{
+       while (head) {
+               struct pkg_list *node;
 
-struct pkg_array {
-       int n_pkgs;
-       struct pkginfo **pkgs;
-};
+               node = head;
+               head = head->next;
 
-void pkg_array_init_from_db(struct pkg_array *a);
-void pkg_array_sort(struct pkg_array *a, pkg_sorter_func *pkg_sort);
-void pkg_array_free(struct pkg_array *a);
+               free(node);
+       }
+}
 
-DPKG_END_DECLS
+void
+pkg_list_prepend(struct pkg_list **head, struct pkginfo *pkg)
+{
+       *head = pkg_list_new(pkg, *head);
+}
 
-#endif /* DPKG_PKG_ARRAY_H */
diff --git a/lib/dpkg/pkg-array.h b/lib/dpkg/pkg-list.h
similarity index 68%
copy from lib/dpkg/pkg-array.h
copy to lib/dpkg/pkg-list.h
index 939b386..10635b2 100644
--- a/lib/dpkg/pkg-array.h
+++ b/lib/dpkg/pkg-list.h
@@ -1,6 +1,6 @@
 /*
  * dpkg - main program for package management
- * pkg-array.h - primitives for pkg array handling
+ * pkg-list.h - primitives for pkg linked list handling
  *
  * Copyright © 2009 Guillem Jover <[email protected]>
  *
@@ -19,8 +19,8 @@
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-#ifndef DPKG_PKG_ARRAY_H
-#define DPKG_PKG_ARRAY_H
+#ifndef DPKG_PKG_LIST_H
+#define DPKG_PKG_LIST_H
 
 #include <config.h>
 #include <compat.h>
@@ -29,17 +29,15 @@
 
 DPKG_BEGIN_DECLS
 
-typedef int pkg_sorter_func(const void *a, const void *b);
-
-struct pkg_array {
-       int n_pkgs;
-       struct pkginfo **pkgs;
+struct pkg_list {
+       struct pkg_list *next;
+       struct pkginfo *pkg;
 };
 
-void pkg_array_init_from_db(struct pkg_array *a);
-void pkg_array_sort(struct pkg_array *a, pkg_sorter_func *pkg_sort);
-void pkg_array_free(struct pkg_array *a);
+struct pkg_list *pkg_list_new(struct pkginfo *pkg, struct pkg_list *next);
+void pkg_list_free(struct pkg_list *head);
+void pkg_list_prepend(struct pkg_list **head, struct pkginfo *pkg);
 
 DPKG_END_DECLS
 
-#endif /* DPKG_PKG_ARRAY_H */
+#endif /* DPKG_PKG_LIST_H */

-- 
dpkg's main repository


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to