Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=c736af86636021525709a376e4412b1359580862

commit c736af86636021525709a376e4412b1359580862
Author: Michel Hermier <[email protected]>
Date:   Sat Dec 21 17:58:36 2013 +0100

libpacman: Split list.h in flist.h and fptrlist.h.

diff --git a/lib/libpacman/CMakeLists.txt b/lib/libpacman/CMakeLists.txt
index 17164c4..51317b5 100644
--- a/lib/libpacman/CMakeLists.txt
+++ b/lib/libpacman/CMakeLists.txt
@@ -16,10 +16,14 @@ set(FLIB_SOURCES
io/ffilelock.c
io/ftp.c
util/fcallback.h
+       util/flist.c
+       util/flist.h
util/ffilelogger.c
util/ffilelogger.h
util/flogger.c
util/flogger.h
+       util/fptrlist.c
+       util/fptrlist.h
util/fsyslogger.c
util/fsyslogger.h
util/list.c
diff --git a/lib/libpacman/util/flist.c b/lib/libpacman/util/flist.c
new file mode 100644
index 0000000..5bc5387
--- /dev/null
+++ b/lib/libpacman/util/flist.c
@@ -0,0 +1,104 @@
+/*
+ *  flist.c
+ *
+ *  Copyright (c) 2002-2006 by Judd Vinet <[email protected]>
+ *  Copyright (c) 2013 by Michel Hermier <[email protected]>
+ *
+ *  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
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ *  USA.
+ */
+
+#include "config.h"
+
+#include "util/flist.h"
+
+#include "fstdlib.h"
+
+int f_listitem_delete(FListItem *self, FVisitor *visitor)
+{
+       ASSERT(self != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
+
+       f_visit(self, visitor);
+       free(self);
+       return 0;
+}
+
+FList *f_list_new()
+{
+       return NULL;
+}
+
+int f_list_all_match(const FList *list, const FMatcher *matcher)
+{
+       const FListItem *it;
+
+       if(f_list_empty(list)) {
+               return 0;
+       }
+
+       for(it = list; it != NULL; it = it->next) {
+               if(f_match(it, matcher) == 0) {
+                       return 0;
+               }
+       }
+       return 1;
+}
+
+int f_list_any_match(const FList *list, const FMatcher *matcher)
+{
+       const FListItem *it;
+
+       for(it = list; it != NULL; it = it->next) {
+               if(f_match(it, matcher) != 0) {
+                       return 1;
+               }
+       }
+       return 0;
+}
+
+int f_list_contains(const FList *list, FListItemComparatorFunc comparator, 
const void *comparator_data)
+{
+       return f_list_find(list, comparator, comparator_data) != NULL;
+}
+
+int f_list_count(const FList *list)
+{
+       int i;
+
+       for(i = 0; list; list = list->next, i++);
+       return i;
+}
+
+int f_list_empty(const FList *list)
+{
+       return list == NULL;
+}
+
+FListItem *f_list_find(const FList *list, FListItemComparatorFunc comparator, 
const void *comparator_data)
+{
+       for(; list != NULL; list = list->next) {
+               if(comparator(list, comparator_data) == 0) {
+                       break;
+               }
+       }
+       return (FListItem *)list;
+}
+
+void f_list_foreach(const FList *list, FListItemVisitorFunc visitor, void 
*visitor_data)
+{
+       for(; list != NULL; list = list->next) {
+               visitor((FListItem *)list, visitor_data);
+       }
+}
diff --git a/lib/libpacman/util/flist.h b/lib/libpacman/util/flist.h
new file mode 100644
index 0000000..e95b461
--- /dev/null
+++ b/lib/libpacman/util/flist.h
@@ -0,0 +1,57 @@
+/*
+ *  flist.h
+ *
+ *  Copyright (c) 2002-2006 by Judd Vinet <[email protected]>
+ *  Copyright (c) 2013 by Michel Hermier <[email protected]>
+ *
+ *  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
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ *  USA.
+ */
+#ifndef F_LIST_H
+#define F_LIST_H
+
+#include "pacman.h"
+
+#include "util/fcallback.h"
+
+typedef struct __pmlist_t FList;
+typedef struct __pmlist_t FListItem;
+
+typedef int (*FListItemComparatorFunc)(const FListItem *item, const void 
*comparator_data);
+typedef void (*FListItemVisitorFunc)(FListItem *item, void *visitor_data);
+
+/* Chained list struct */
+struct __pmlist_t {
+       struct __pmlist_t *prev;
+       struct __pmlist_t *next;
+       void *data;
+       struct __pmlist_t *last; /* Quick access to last item in list */
+};
+
+int f_listitem_delete(FListItem *self, FVisitor *visitor);
+
+FList *f_list_new(void);
+
+int f_list_all_match(const FList *list, const FMatcher *matcher);
+int f_list_any_match(const FList *list, const FMatcher *matcher);
+int f_list_contains(const FList *list, FListItemComparatorFunc comparator, 
const void *comparator_data);
+int f_list_count(const FList *list);
+int f_list_empty(const FList *list);
+FListItem *f_list_find(const FList *list, FListItemComparatorFunc comparator, 
const void *comparator_data);
+void f_list_foreach(const FList *list, FListItemVisitorFunc visitor, void 
*visitor_data);
+
+#endif /* F_LIST_H */
+
+/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libpacman/util/fptrlist.c b/lib/libpacman/util/fptrlist.c
new file mode 100644
index 0000000..a1bc2c2
--- /dev/null
+++ b/lib/libpacman/util/fptrlist.c
@@ -0,0 +1,154 @@
+/*
+ *  fptrlist.c
+ *
+ *  Copyright (c) 2002-2006 by Judd Vinet <[email protected]>
+ *  Copyright (c) 2013 by Michel Hermier <[email protected]>
+ *
+ *  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
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ *  USA.
+ */
+
+#include "config.h"
+
+#include "util/fptrlist.h"
+
+#include "fstdlib.h"
+
+FPtrListItem *f_ptrlistitem_new(void *ptr)
+{
+       FPtrListItem *item = f_zalloc(sizeof(*item));
+
+       if(item != NULL) {
+               item->data = ptr;
+       }
+       return item;
+}
+
+int f_ptrlistitem_delete(FListItem *self, FVisitor *visitor)
+{
+       ASSERT(self != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
+
+       return f_listitem_delete(self, visitor);
+}
+
+void *f_ptrlistitem_data(const FPtrListItem *self)
+{
+       ASSERT(self != NULL, RET_ERR(PM_ERR_WRONG_ARGS, NULL));
+
+       return self->data;
+}
+
+int f_ptrlistitem_match(const FListItem *item, const FMatcher *matcher) {
+       return f_match(item->data, matcher);
+}
+
+int f_ptrlistitem_ptrcmp(const FListItem *item, const void *ptr) {
+       return f_ptrcmp(item->data, ptr);
+}
+
+FPtrList *f_ptrlist_new(void)
+{
+       FPtrListItem *item = f_ptrlistitem_new(NULL);
+       item->last = item;
+       return (FPtrList *)item;
+}
+
+int f_ptrlist_delete(FPtrList *list, FVisitor *visitor)
+{
+       return f_ptrlist_clear(list, visitor);
+}
+
+int f_ptrlist_all_match(const FPtrList *list, const FMatcher *matcher)
+{
+       FMatcher itemmatcher = {
+               .fn = (FMatcherFunc)f_ptrlistitem_match,
+               .data = matcher,
+       };
+
+       return f_list_all_match(list, &itemmatcher);
+}
+
+int f_ptrlist_any_match(const FPtrList *list, const FMatcher *matcher)
+{
+       FMatcher itemmatcher = {
+               .fn = (FMatcherFunc)f_ptrlistitem_match,
+               .data = matcher,
+       };
+
+       return f_list_any_match(list, &itemmatcher);
+}
+
+pmlist_t *f_ptrlist_append(pmlist_t *list, void *data)
+{
+       pmlist_t *ptr, *lp;
+
+       ptr = list;
+       if(ptr == NULL) {
+               ptr = f_ptrlist_new();
+               if(ptr == NULL) {
+                       return(NULL);
+               }
+       }
+
+       lp = _pacman_list_last(ptr);
+       if(lp == ptr && lp->data == NULL) {
+               /* nada */
+       } else {
+               lp->next = f_ptrlist_new();
+               if(lp->next == NULL) {
+                       return(NULL);
+               }
+               lp->next->prev = lp;
+               lp->last = NULL;
+               lp = lp->next;
+       }
+
+       lp->data = data;
+       ptr->last = lp;
+
+       return(ptr);
+}
+
+int f_ptrlist_clear(FPtrList *list, FVisitor *visitor)
+{
+       FPtrList *next;
+
+       while(list != NULL) {
+               next = list->next;
+               if(visitor != NULL) {
+                       f_visit(list->data, visitor);
+               }
+               free(list);
+               list = next;
+       }
+       return 0;
+}
+
+int f_ptrlist_contains_ptr(const FPtrList *list, const void *ptr)
+{
+       return f_ptrlist_contains(list, f_ptrlistitem_ptrcmp, ptr);
+}
+
+FPtrList *f_ptrlist_filter(const FPtrList *list, const FMatcher *matcher)
+{
+       FPtrList *retlist = NULL;
+
+       for(; list != NULL; list = list->next) {
+               if(f_match(list->data, matcher)) {
+                       retlist = f_ptrlist_append(retlist, list->data);
+               }
+       }
+       return retlist;
+}
diff --git a/lib/libpacman/util/fptrlist.h b/lib/libpacman/util/fptrlist.h
new file mode 100644
index 0000000..e9e89e9
--- /dev/null
+++ b/lib/libpacman/util/fptrlist.h
@@ -0,0 +1,55 @@
+/*
+ *  fptrlist.h
+ *
+ *  Copyright (c) 2002-2006 by Judd Vinet <[email protected]>
+ *  Copyright (c) 2013 by Michel Hermier <[email protected]>
+ *
+ *  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
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ *  USA.
+ */
+#ifndef F_PTRLIST_H
+#define F_PTRLIST_H
+
+#include "pacman.h"
+
+#include "util/flist.h"
+
+typedef struct __pmlist_t FPtrList;
+typedef struct __pmlist_t FPtrListItem;
+
+FPtrListItem *f_ptrlistitem_new(void *data);
+int f_ptrlistitem_delete(FListItem *self, FVisitor *visitor);
+
+void *f_ptrlistitem_data(const FPtrListItem *self);
+
+int f_ptrlistitem_match(const FListItem *item, const FMatcher *matcher);
+int f_ptrlistitem_ptrcmp(const FListItem *item, const void *ptr);
+
+FPtrList *f_ptrlist_new(void);
+int f_ptrlist_delete(FPtrList *list, FVisitor *visitor);
+
+int f_ptrlist_all_match(const FPtrList *list, const FMatcher *matcher);
+int f_ptrlist_any_match(const FPtrList *list, const FMatcher *matcher);
+pmlist_t *f_ptrlist_append(pmlist_t *list, void *data);
+int f_ptrlist_clear(FPtrList *list, FVisitor *visitor);
+#define f_ptrlist_contains f_list_contains
+int f_ptrlist_contains_ptr(const FPtrList *list, const void *ptr);
+#define f_ptrlist_count f_list_count
+#define f_ptrlist_empty f_list_empty
+FPtrList *f_ptrlist_filter(const FPtrList *list, const FMatcher *matcher);
+
+#endif /* F_PTRLIST_H */
+
+/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libpacman/util/list.c b/lib/libpacman/util/list.c
index 367d373..05c7115 100644
--- a/lib/libpacman/util/list.c
+++ b/lib/libpacman/util/list.c
@@ -30,86 +30,6 @@
#include "fstdlib.h"
#include "util.h"

-int f_listitem_delete(FListItem *self, FVisitor *visitor)
-{
-       ASSERT(self != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
-
-       f_visit(self, visitor);
-       free(self);
-       return 0;
-}
-
-FList *f_list_new()
-{
-       return NULL;
-}
-
-int f_list_contains(const FList *list, FListItemComparatorFunc comparator, 
const void *comparator_data)
-{
-       return f_list_find(list, comparator, comparator_data) != NULL;
-}
-
-int f_list_count(const FList *list)
-{
-       int i;
-
-       for(i = 0; list; list = list->next, i++);
-       return i;
-}
-
-int f_list_empty(const FList *list)
-{
-       return list == NULL;
-}
-
-void f_list_foreach(const FList *list, FListItemVisitorFunc visitor, void 
*visitor_data)
-{
-       for(; list != NULL; list = list->next) {
-               visitor((FListItem *)list, visitor_data);
-       }
-}
-
-FListItem *f_list_find(const FList *list, FListItemComparatorFunc comparator, 
const void *comparator_data)
-{
-       for(; list != NULL; list = list->next) {
-               if(comparator(list, comparator_data) == 0) {
-                       break;
-               }
-       }
-       return (FListItem *)list;
-}
-
-pmlist_t *f_ptrlist_append(pmlist_t *list, void *data)
-{
-       pmlist_t *ptr, *lp;
-
-       ptr = list;
-       if(ptr == NULL) {
-               ptr = _pacman_list_new();
-               if(ptr == NULL) {
-                       return(NULL);
-               }
-       }
-
-       lp = _pacman_list_last(ptr);
-       if(lp == ptr && lp->data == NULL) {
-               /* nada */
-       } else {
-               lp->next = _pacman_list_new();
-               if(lp->next == NULL) {
-                       return(NULL);
-               }
-               lp->next->prev = lp;
-               lp->last = NULL;
-               lp = lp->next;
-       }
-
-       lp->data = data;
-       ptr->last = lp;
-
-       return(ptr);
-}
-
/* Add items to a list in sorted order. Use the given comparison function to
* determine order.
*/
@@ -156,34 +76,6 @@ pmlist_t *_pacman_list_add_sorted(pmlist_t *list, void 
*data, _pacman_fn_cmp fn)
return(list);
}

-int f_list_all_match(const FList *list, const FMatcher *matcher)
-{
-       const FListItem *it;
-
-       if(f_list_empty(list)) {
-               return 0;
-       }
-
-       for(it = list; it != NULL; it = it->next) {
-               if(f_match(it, matcher) == 0) {
-                       return 0;
-               }
-       }
-       return 1;
-}
-
-int f_list_any_match(const FList *list, const FMatcher *matcher)
-{
-       const FListItem *it;
-
-       for(it = list; it != NULL; it = it->next) {
-               if(f_match(it, matcher) != 0) {
-                       return 1;
-               }
-       }
-       return 0;
-}
-
/* Remove an item in a list. Use the given comparison function to find the
* item.
* If the item is found, 'data' is pointing to the removed element.
@@ -267,100 +159,4 @@ pmlist_t *_pacman_list_reverse(pmlist_t *list)
return(newlist);
}

-FPtrListItem *f_ptrlistitem_new(void *ptr)
-{
-       FPtrListItem *item = f_zalloc(sizeof(*item));
-
-       if(item != NULL) {
-               item->data = ptr;
-       }
-       return item;
-}
-
-int f_ptrlistitem_delete(FListItem *self, FVisitor *visitor)
-{
-       ASSERT(self != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
-
-       return f_listitem_delete(self, visitor);
-}
-
-void *f_ptrlistitem_data(const FPtrListItem *self)
-{
-       ASSERT(self != NULL, RET_ERR(PM_ERR_WRONG_ARGS, NULL));
-
-       return self->data;
-}
-
-int f_ptrlistitem_match(const FListItem *item, const FMatcher *matcher) {
-       return f_match(item->data, matcher);
-}
-
-int f_ptrlistitem_ptrcmp(const FListItem *item, const void *ptr) {
-       return f_ptrcmp(item->data, ptr);
-}
-
-FPtrList *f_ptrlist_new(void)
-{
-       FPtrListItem *item = f_ptrlistitem_new(NULL);
-       item->last = item;
-       return (FPtrList *)item;
-}
-
-int f_ptrlist_delete(FPtrList *list, FVisitor *visitor)
-{
-       return f_ptrlist_clear(list, visitor);
-}
-
-int f_ptrlist_all_match(const FPtrList *list, const FMatcher *matcher)
-{
-       FMatcher itemmatcher = {
-               .fn = (FMatcherFunc)f_ptrlistitem_match,
-               .data = matcher,
-       };
-
-       return f_list_all_match(list, &itemmatcher);
-}
-
-int f_ptrlist_any_match(const FPtrList *list, const FMatcher *matcher)
-{
-       FMatcher itemmatcher = {
-               .fn = (FMatcherFunc)f_ptrlistitem_match,
-               .data = matcher,
-       };
-
-       return f_list_any_match(list, &itemmatcher);
-}
-
-int f_ptrlist_clear(FPtrList *list, FVisitor *visitor)
-{
-       FPtrList *next;
-
-       while(list != NULL) {
-               next = list->next;
-               if(visitor != NULL) {
-                       f_visit(list->data, visitor);
-               }
-               free(list);
-               list = next;
-       }
-       return 0;
-}
-
-int f_ptrlist_contains_ptr(const FPtrList *list, const void *ptr)
-{
-       return f_ptrlist_contains(list, f_ptrlistitem_ptrcmp, ptr);
-}
-
-FPtrList *f_ptrlist_filter(const FPtrList *list, const FMatcher *matcher)
-{
-       FPtrList *retlist = NULL;
-
-       for(; list != NULL; list = list->next) {
-               if(f_match(list->data, matcher)) {
-                       retlist = f_ptrlist_append(retlist, list->data);
-               }
-       }
-       return retlist;
-}
-
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libpacman/util/list.h b/lib/libpacman/util/list.h
index a6a8caa..8dfdd9d 100644
--- a/lib/libpacman/util/list.h
+++ b/lib/libpacman/util/list.h
@@ -23,21 +23,8 @@

#include "pacman.h"

-#include "util/fcallback.h"
-
-typedef struct __pmlist_t FList;
-typedef struct __pmlist_t FListItem;
-
-typedef int (*FListItemComparatorFunc)(const FListItem *item, const void 
*comparator_data);
-typedef void (*FListItemVisitorFunc)(FListItem *item, void *visitor_data);
-
-/* Chained list struct */
-struct __pmlist_t {
-       struct __pmlist_t *prev;
-       struct __pmlist_t *next;
-       void *data;
-       struct __pmlist_t *last; /* Quick access to last item in list */
-};
+#include "util/flist.h"
+#include "util/fptrlist.h"

#define _FREELIST(p, f) do { if(p) { FVisitor visitor = { .fn = 
(FVisitorFunc)f, .data = NULL, }; f_ptrlist_delete(p, &visitor); p = NULL; } } 
while(0)
#define FREELIST(p) _FREELIST(p, free)
@@ -52,47 +39,11 @@ typedef int (*_pacman_fn_cmp)(const void *, const void *);
#define _pacman_list_count f_ptrlist_count
#define _pacman_list_empty f_ptrlist_empty

-int f_listitem_delete(FListItem *self, FVisitor *visitor);
-
-FList *f_list_new(void);
-
-int f_list_contains(const FList *list, FListItemComparatorFunc comparator, 
const void *comparator_data);
-int f_list_count(const FList *list);
-int f_list_empty(const FList *list);
-FListItem *f_list_find(const FList *list, FListItemComparatorFunc comparator, 
const void *comparator_data);
-void f_list_foreach(const FList *list, FListItemVisitorFunc visitor, void 
*visitor_data);
-
-pmlist_t *f_ptrlist_append(pmlist_t *list, void *data);
pmlist_t *_pacman_list_add_sorted(pmlist_t *list, void *data, _pacman_fn_cmp 
fn);
-int f_list_all_match(const FList *list, const FMatcher *matcher);
-int f_list_any_match(const FList *list, const FMatcher *matcher);
pmlist_t *_pacman_list_remove(pmlist_t *haystack, void *needle, _pacman_fn_cmp 
fn, void **data);
pmlist_t *_pacman_list_last(pmlist_t *list);
pmlist_t *_pacman_list_reverse(pmlist_t *list);

-typedef struct __pmlist_t FPtrList;
-typedef struct __pmlist_t FPtrListItem;
-
-FPtrListItem *f_ptrlistitem_new(void *data);
-int f_ptrlistitem_delete(FListItem *self, FVisitor *visitor);
-
-void *f_ptrlistitem_data(const FPtrListItem *self);
-
-int f_ptrlistitem_match(const FListItem *item, const FMatcher *matcher);
-int f_ptrlistitem_ptrcmp(const FListItem *item, const void *ptr);
-
-FPtrList *f_ptrlist_new(void);
-int f_ptrlist_delete(FPtrList *list, FVisitor *visitor);
-
-int f_ptrlist_all_match(const FPtrList *list, const FMatcher *matcher);
-int f_ptrlist_any_match(const FPtrList *list, const FMatcher *matcher);
-int f_ptrlist_clear(FPtrList *list, FVisitor *visitor);
-#define f_ptrlist_contains f_list_contains
-int f_ptrlist_contains_ptr(const FPtrList *list, const void *ptr);
-#define f_ptrlist_count f_list_count
-#define f_ptrlist_empty f_list_empty
-FPtrList *f_ptrlist_filter(const FPtrList *list, const FMatcher *matcher);
-
#endif /* _PACMAN_LIST_H */

/* vim: set ts=2 sw=2 noet: */
_______________________________________________
Frugalware-git mailing list
[email protected]
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to