Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=82976b4caf7cf5ef3a960da5461397a8cff02d8c
commit 82976b4caf7cf5ef3a960da5461397a8cff02d8c Author: Michel Hermier <[email protected]> Date: Mon Aug 18 15:21:33 2014 +0200 libpacman: Merge list.c in fptrlist.c diff --git a/lib/libpacman/CMakeLists.txt b/lib/libpacman/CMakeLists.txt index ebe5494..5b5c7bb 100644 --- a/lib/libpacman/CMakeLists.txt +++ b/lib/libpacman/CMakeLists.txt @@ -36,7 +36,6 @@ set(FLIB_SOURCES util/fptrlist.h util/fsyslogger.c util/fsyslogger.h - util/list.c util/log.c util/stringlist.c util/time.c diff --git a/lib/libpacman/cache.cpp b/lib/libpacman/cache.cpp index b4afab8..21b7559 100644 --- a/lib/libpacman/cache.cpp +++ b/lib/libpacman/cache.cpp @@ -34,7 +34,6 @@ #include "cache.h" #include "db/localdb_files.h" -#include "util/list.h" #include "util/log.h" #include "util/stringlist.h" #include "fstring.h" diff --git a/lib/libpacman/config_parser.cpp b/lib/libpacman/config_parser.cpp index 1a7d981..d896c98 100644 --- a/lib/libpacman/config_parser.cpp +++ b/lib/libpacman/config_parser.cpp @@ -43,7 +43,6 @@ #include "db/syncdb.h" #include "hash/md5.h" #include "hash/sha1.h" -#include "util/list.h" #include "util/log.h" #include "util/stringlist.h" #include "fstring.h" diff --git a/lib/libpacman/conflict.cpp b/lib/libpacman/conflict.cpp index 0f648cb..d52c7ab 100644 --- a/lib/libpacman/conflict.cpp +++ b/lib/libpacman/conflict.cpp @@ -34,7 +34,6 @@ #include "cache.h" #include "deps.h" -#include "util/list.h" #include "util/log.h" #include "util/stringlist.h" #include "fstdlib.h" diff --git a/lib/libpacman/db.cpp b/lib/libpacman/db.cpp index e45d4a4..455829c 100644 --- a/lib/libpacman/db.cpp +++ b/lib/libpacman/db.cpp @@ -38,7 +38,6 @@ #include "db/localdb.h" #include "db/syncdb.h" #include "io/ftp.h" -#include "util/list.h" #include "util/log.h" #include "util/time.h" #include "fstdlib.h" diff --git a/lib/libpacman/db/fakedb.cpp b/lib/libpacman/db/fakedb.cpp index e1a9bbf..33a7ca1 100644 --- a/lib/libpacman/db/fakedb.cpp +++ b/lib/libpacman/db/fakedb.cpp @@ -31,7 +31,6 @@ #include "package.h" #include "util.h" -#include "util/list.h" #include "util/stringlist.h" #include <time.h> diff --git a/lib/libpacman/deps.cpp b/lib/libpacman/deps.cpp index 6f847b9..b3c29df 100644 --- a/lib/libpacman/deps.cpp +++ b/lib/libpacman/deps.cpp @@ -31,7 +31,6 @@ #include "deps.h" #include "db/localdb_files.h" -#include "util/list.h" #include "util/log.h" #include "util/stringlist.h" #include "fstdlib.h" diff --git a/lib/libpacman/group.cpp b/lib/libpacman/group.cpp index 7f902d8..aa3c006 100644 --- a/lib/libpacman/group.cpp +++ b/lib/libpacman/group.cpp @@ -25,7 +25,7 @@ #include "pacman.h" -#include "util/list.h" +#include "util/fptrlist.h" #include "fstdlib.h" #include <string.h> diff --git a/lib/libpacman/handle.cpp b/lib/libpacman/handle.cpp index 931ca80..9da2b75 100644 --- a/lib/libpacman/handle.cpp +++ b/lib/libpacman/handle.cpp @@ -34,7 +34,6 @@ #include "server.h" #include "util.h" -#include "util/list.h" #include "util/log.h" #include "util/stringlist.h" #include "fstdlib.h" diff --git a/lib/libpacman/package.cpp b/lib/libpacman/package.cpp index cd75085..4effcff 100644 --- a/lib/libpacman/package.cpp +++ b/lib/libpacman/package.cpp @@ -36,7 +36,6 @@ #include "pacman.h" #include "io/archive.h" -#include "util/list.h" #include "util/log.h" #include "util/stringlist.h" #include "fstdlib.h" diff --git a/lib/libpacman/package/fpmpackage.cpp b/lib/libpacman/package/fpmpackage.cpp index 4a1c85e..167a3f8 100644 --- a/lib/libpacman/package/fpmpackage.cpp +++ b/lib/libpacman/package/fpmpackage.cpp @@ -35,7 +35,6 @@ #include "pacman.h" #include "io/archive.h" -#include "util/list.h" #include "util/log.h" #include "util/stringlist.h" #include "fstring.h" diff --git a/lib/libpacman/package/packagecache.cpp b/lib/libpacman/package/packagecache.cpp index 090af3a..f4438f4 100644 --- a/lib/libpacman/package/packagecache.cpp +++ b/lib/libpacman/package/packagecache.cpp @@ -27,7 +27,6 @@ /* pacman-g2 */ #include "package/packagecache.h" -#include "util/list.h" #include "package.h" #include "handle.h" diff --git a/lib/libpacman/packages_transaction.cpp b/lib/libpacman/packages_transaction.cpp index 60e52a8..4736e63 100644 --- a/lib/libpacman/packages_transaction.cpp +++ b/lib/libpacman/packages_transaction.cpp @@ -27,7 +27,6 @@ #include "util.h" -#include "util/list.h" #include "fstring.h" static const char *trigger_function_table[STATE_MAX] = { diff --git a/lib/libpacman/pacman.cpp b/lib/libpacman/pacman.cpp index 55b0503..dd6cd2b 100644 --- a/lib/libpacman/pacman.cpp +++ b/lib/libpacman/pacman.cpp @@ -47,7 +47,6 @@ #include "hash/md5.h" #include "hash/sha1.h" #include "package/packagecache.h" -#include "util/list.h" #include "util/log.h" #include "util/stringlist.h" #include "fstring.h" diff --git a/lib/libpacman/server.cpp b/lib/libpacman/server.cpp index 6843fa3..24adfa6 100644 --- a/lib/libpacman/server.cpp +++ b/lib/libpacman/server.cpp @@ -30,7 +30,6 @@ #include "handle.h" #include "io/archive.h" -#include "util/list.h" #include "util/log.h" #include "util/stringlist.h" #include "util/time.h" diff --git a/lib/libpacman/sync.cpp b/lib/libpacman/sync.cpp index a8396cd..0ec917d 100644 --- a/lib/libpacman/sync.cpp +++ b/lib/libpacman/sync.cpp @@ -46,7 +46,6 @@ #include "hash/md5.h" #include "hash/sha1.h" -#include "util/list.h" #include "util/log.h" #include "util/stringlist.h" #include "fstdlib.h" diff --git a/lib/libpacman/trans.cpp b/lib/libpacman/trans.cpp index 1c1d7ab..6655aed 100644 --- a/lib/libpacman/trans.cpp +++ b/lib/libpacman/trans.cpp @@ -46,7 +46,6 @@ #include "hash/md5.h" #include "hash/sha1.h" #include "io/archive.h" -#include "util/list.h" #include "util/log.h" #include "util/stringlist.h" #include "fstdlib.h" diff --git a/lib/libpacman/trans_sysupgrade.cpp b/lib/libpacman/trans_sysupgrade.cpp index 91bd9b7..c9abd99 100644 --- a/lib/libpacman/trans_sysupgrade.cpp +++ b/lib/libpacman/trans_sysupgrade.cpp @@ -35,7 +35,6 @@ /* pacman-g2 */ #include "trans.h" -#include "util/list.h" #include "util/log.h" #include "util/stringlist.h" #include "error.h" diff --git a/lib/libpacman/util.cpp b/lib/libpacman/util.cpp index f506271..70bf0b2 100644 --- a/lib/libpacman/util.cpp +++ b/lib/libpacman/util.cpp @@ -29,7 +29,6 @@ #include "util.h" #include "io/archive.h" -#include "util/list.h" #include "util/log.h" #include "fstdlib.h" #include "fstring.h" diff --git a/lib/libpacman/util/fptrlist.c b/lib/libpacman/util/fptrlist.c index bca5d96..d00f08a 100644 --- a/lib/libpacman/util/fptrlist.c +++ b/lib/libpacman/util/fptrlist.c @@ -30,6 +30,106 @@ #define previous prev #endif +/* Add items to a list in sorted order. Use the given comparison function to + * determine order. + */ +FPtrList *_pacman_list_add_sorted(FPtrList *list, void *data, _pacman_fn_cmp fn) +{ + FPtrListItem *add, *end = f_ptrlist_end(list), *prev = NULL, *iter = f_ptrlist_first(list); + + add = _pacman_list_new(); + add->data = data; + + /* Find insertion point. */ + while(iter != end) { + if(fn(add->data, iter->data) <= 0) break; + prev = iter; + iter = iter->next; + } + + /* Insert node before insertion point. */ + add->prev = prev; + add->next = iter; + + if(iter != NULL) { + iter->prev = add; /* Not at end. */ + } + + if(prev != NULL) { + prev->next = add; /* In middle. */ + } else { + list = add; /* Start or empty, new list head. */ + } + + return(list); +} + +/* 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. + * Otherwise, it is set to NULL. + * Return the new list (without the removed element). + */ +FPtrList *_pacman_list_remove(FPtrList *haystack, void *needle, _pacman_fn_cmp fn, void **data) +{ + FPtrListItem *end = f_ptrlist_end(haystack), *i = f_ptrlist_first(haystack); + + if(data != end) { + *data = NULL; + } + + while(i) { + if(i->data == NULL) { + continue; + } + if(fn(needle, i->data) == 0) { + break; + } + i = i->next; + } + + if(i) { + /* we found a matching item */ + if(i->next) { + i->next->prev = i->prev; + } + if(i->prev) { + i->prev->next = i->next; + } + if(i == haystack) { + /* The item found is the first in the chain */ + haystack = haystack->next; + } + + if(data) { + *data = i->data; + } + i->data = NULL; + free(i); + } + + return(haystack); +} + +/* Reverse the order of a list + * + * The caller is responsible for freeing the old list + */ +FPtrList *_pacman_list_reverse(FPtrList *list) +{ + /* simple but functional -- we just build a new list, starting + * with the old list's tail + */ + FPtrList *newlist = f_ptrlist_new(); + FPtrListItem *it; + + for(it = f_ptrlist_last(list); it; it = f_ptrlistitem_previous(it)) { + newlist = _pacman_list_add(newlist, it->data); + } + + return(newlist); +} + int f_listitem_delete(FListItem *self, FVisitor *visitor) { ASSERT(self != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1)); diff --git a/lib/libpacman/util/fptrlist.h b/lib/libpacman/util/fptrlist.h index f8a1fc0..0965069 100644 --- a/lib/libpacman/util/fptrlist.h +++ b/lib/libpacman/util/fptrlist.h @@ -24,6 +24,8 @@ #include "pacman.h" +#include "util/fcallback.h" + #ifdef __cplusplus extern "C" { #endif @@ -44,7 +46,6 @@ typedef struct FPtrListItem FPtrListItem; #endif #include "util/flist.h" -#include "util/list.h" #ifndef F_NOCOMPAT typedef struct __pmlist_t FList; @@ -54,6 +55,25 @@ typedef struct FList FList; typedef struct FListItem FListItem; #endif +#define _FREELIST(p, f) do { if(p) { FVisitor visitor = { (FVisitorFunc)f, NULL }; f_ptrlist_delete(p, &visitor); p = NULL; } } while(0) + +#define FREELIST(p) _FREELIST(p, free) +#define FREELISTPTR(p) _FREELIST(p, NULL) + +/* Sort comparison callback function declaration */ +typedef int (*_pacman_fn_cmp)(const void *, const void *); + +#define _pacman_list_new f_ptrlist_new + +#define _pacman_list_add f_ptrlist_append +#define _pacman_list_count f_ptrlist_count +#define _pacman_list_empty f_ptrlist_empty +#define _pacman_list_last f_ptrlist_last + +FPtrList *_pacman_list_add_sorted(FPtrList *list, void *data, _pacman_fn_cmp fn); +FPtrList *_pacman_list_remove(FPtrList *haystack, void *needle, _pacman_fn_cmp fn, void **data); +FPtrList *_pacman_list_reverse(FPtrList *list); + typedef int (*FListItemComparatorFunc)(const FListItem *item, const void *comparator_data); typedef void (*FListItemVisitorFunc)(FListItem *item, void *visitor_data); diff --git a/lib/libpacman/util/list.c b/lib/libpacman/util/list.c deleted file mode 100644 index 368f6ea..0000000 --- a/lib/libpacman/util/list.c +++ /dev/null @@ -1,134 +0,0 @@ -/* - * list.c - * - * Copyright (c) 2002-2006 by Judd Vinet <[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 <stdlib.h> -#include <stdio.h> -#include <assert.h> - -/* pacman-g2 */ -#include "list.h" -#include "fptrlist.h" - -#include "fstdlib.h" -#include "util.h" - -/* Add items to a list in sorted order. Use the given comparison function to - * determine order. - */ -FPtrList *_pacman_list_add_sorted(FPtrList *list, void *data, _pacman_fn_cmp fn) -{ - FPtrListItem *add, *end = f_ptrlist_end(list), *prev = NULL, *iter = f_ptrlist_first(list); - - add = _pacman_list_new(); - add->data = data; - - /* Find insertion point. */ - while(iter != end) { - if(fn(add->data, iter->data) <= 0) break; - prev = iter; - iter = iter->next; - } - - /* Insert node before insertion point. */ - add->prev = prev; - add->next = iter; - - if(iter != NULL) { - iter->prev = add; /* Not at end. */ - } - - if(prev != NULL) { - prev->next = add; /* In middle. */ - } else { - list = add; /* Start or empty, new list head. */ - } - - return(list); -} - -/* 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. - * Otherwise, it is set to NULL. - * Return the new list (without the removed element). - */ -FPtrList *_pacman_list_remove(FPtrList *haystack, void *needle, _pacman_fn_cmp fn, void **data) -{ - FPtrListItem *end = f_ptrlist_end(haystack), *i = f_ptrlist_first(haystack); - - if(data != end) { - *data = NULL; - } - - while(i) { - if(i->data == NULL) { - continue; - } - if(fn(needle, i->data) == 0) { - break; - } - i = i->next; - } - - if(i) { - /* we found a matching item */ - if(i->next) { - i->next->prev = i->prev; - } - if(i->prev) { - i->prev->next = i->next; - } - if(i == haystack) { - /* The item found is the first in the chain */ - haystack = haystack->next; - } - - if(data) { - *data = i->data; - } - i->data = NULL; - free(i); - } - - return(haystack); -} - -/* Reverse the order of a list - * - * The caller is responsible for freeing the old list - */ -FPtrList *_pacman_list_reverse(FPtrList *list) -{ - /* simple but functional -- we just build a new list, starting - * with the old list's tail - */ - FPtrList *newlist = f_ptrlist_new(); - FPtrListItem *it; - - for(it = f_ptrlist_last(list); it; it = f_ptrlistitem_previous(it)) { - newlist = _pacman_list_add(newlist, it->data); - } - - return(newlist); -} - -/* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libpacman/util/list.h b/lib/libpacman/util/list.h deleted file mode 100644 index ffd918b..0000000 --- a/lib/libpacman/util/list.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * list.h - * - * Copyright (c) 2002-2006 by Judd Vinet <[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 _PACMAN_LIST_H -#define _PACMAN_LIST_H - -#include "pacman.h" - -#include "util/fptrlist.h" - -#ifdef __cplusplus -extern "C" { - -#define _FREELIST(p, f) do { if(p) { FVisitor visitor((FVisitorFunc)f, NULL); f_ptrlist_delete(p, &visitor); p = NULL; } } while(0) -#else -#define _FREELIST(p, f) do { if(p) { FVisitor visitor = { .fn = (FVisitorFunc)f, .data = NULL, }; f_ptrlist_delete(p, &visitor); p = NULL; } } while(0) -#endif - -#define FREELIST(p) _FREELIST(p, free) -#define FREELISTPTR(p) _FREELIST(p, NULL) - -/* Sort comparison callback function declaration */ -typedef int (*_pacman_fn_cmp)(const void *, const void *); - -#define _pacman_list_new f_ptrlist_new - -#define _pacman_list_add f_ptrlist_append -#define _pacman_list_count f_ptrlist_count -#define _pacman_list_empty f_ptrlist_empty -#define _pacman_list_last f_ptrlist_last - -FPtrList *_pacman_list_add_sorted(FPtrList *list, void *data, _pacman_fn_cmp fn); -FPtrList *_pacman_list_remove(FPtrList *haystack, void *needle, _pacman_fn_cmp fn, void **data); -FPtrList *_pacman_list_reverse(FPtrList *list); - -#ifdef __cplusplus -} -#endif -#endif /* _PACMAN_LIST_H */ - -/* vim: set ts=2 sw=2 noet: */ _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
