Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=c02e4e2255082e8e4c34f9c5eeac9e1efb844da8
commit c02e4e2255082e8e4c34f9c5eeac9e1efb844da8 Author: Michel Hermier <[email protected]> Date: Thu Oct 31 11:52:46 2013 +0100 libpacman: Split stringlist helpers out of list implementation. diff --git a/lib/libpacman/Makefile.am b/lib/libpacman/Makefile.am index f11aee1..e1c00f1 100644 --- a/lib/libpacman/Makefile.am +++ b/lib/libpacman/Makefile.am @@ -13,9 +13,9 @@ HASH_TARGETS = \ hash/sha1.c UTIL_TARGETS = \ + util/list.c \ util/log.c \ - util/logger.c \ - util/list.c + util/stringlist.c TARGETS = \ $(HASH_TARGETS) \ diff --git a/lib/libpacman/add.c b/lib/libpacman/add.c index 953e046..0ed49d6 100644 --- a/lib/libpacman/add.c +++ b/lib/libpacman/add.c @@ -46,6 +46,7 @@ #include "hash/sha1.h" #include "util/list.h" #include "util/log.h" +#include "util/stringlist.h" #include "trans.h" #include "util.h" #include "error.h" diff --git a/lib/libpacman/cache.c b/lib/libpacman/cache.c index aac5364..e27d2c3 100644 --- a/lib/libpacman/cache.c +++ b/lib/libpacman/cache.c @@ -35,6 +35,7 @@ #include "util/list.h" #include "util/log.h" +#include "util/stringlist.h" #include "pacman.h" #include "util.h" #include "package.h" diff --git a/lib/libpacman/conflict.c b/lib/libpacman/conflict.c index d190f22..c376274 100644 --- a/lib/libpacman/conflict.c +++ b/lib/libpacman/conflict.c @@ -40,6 +40,7 @@ #include "util/list.h" #include "util/log.h" +#include "util/stringlist.h" #include "util.h" #include "error.h" #include "cache.h" diff --git a/lib/libpacman/deps.c b/lib/libpacman/deps.c index 4c19890..149349a 100644 --- a/lib/libpacman/deps.c +++ b/lib/libpacman/deps.c @@ -35,6 +35,7 @@ #include "util/list.h" #include "util/log.h" +#include "util/stringlist.h" #include "util.h" #include "error.h" #include "package.h" diff --git a/lib/libpacman/package.c b/lib/libpacman/package.c index c548ecd..b1517e7 100644 --- a/lib/libpacman/package.c +++ b/lib/libpacman/package.c @@ -37,6 +37,7 @@ #include "util/list.h" #include "util/log.h" +#include "util/stringlist.h" #include "util.h" #include "error.h" #include "db.h" diff --git a/lib/libpacman/pacman.c b/lib/libpacman/pacman.c index ae80091..07302df 100644 --- a/lib/libpacman/pacman.c +++ b/lib/libpacman/pacman.c @@ -44,6 +44,7 @@ #include "hash/sha1.h" #include "util/list.h" #include "util/log.h" +#include "util/stringlist.h" #include "error.h" #include "deps.h" #include "versioncmp.h" diff --git a/lib/libpacman/remove.c b/lib/libpacman/remove.c index c765670..7f95ea8 100644 --- a/lib/libpacman/remove.c +++ b/lib/libpacman/remove.c @@ -45,6 +45,7 @@ #include "util/list.h" #include "util/log.h" +#include "util/stringlist.h" #include "trans.h" #include "util.h" #include "error.h" diff --git a/lib/libpacman/server.c b/lib/libpacman/server.c index 68ac9ed..3087f2c 100644 --- a/lib/libpacman/server.c +++ b/lib/libpacman/server.c @@ -37,6 +37,7 @@ #include "util/list.h" #include "util/log.h" +#include "util/stringlist.h" #include "error.h" #include "pacman.h" #include "util.h" diff --git a/lib/libpacman/sync.c b/lib/libpacman/sync.c index fbfbd52..63374e5 100644 --- a/lib/libpacman/sync.c +++ b/lib/libpacman/sync.c @@ -41,6 +41,7 @@ #include "hash/sha1.h" #include "util/list.h" #include "util/log.h" +#include "util/stringlist.h" #include "error.h" #include "package.h" #include "db.h" diff --git a/lib/libpacman/trans.c b/lib/libpacman/trans.c index bfd5bb2..8b3023a 100644 --- a/lib/libpacman/trans.c +++ b/lib/libpacman/trans.c @@ -33,6 +33,7 @@ #include "util/list.h" #include "util/log.h" +#include "util/stringlist.h" #include "error.h" #include "package.h" #include "util.h" diff --git a/lib/libpacman/trans_sysupgrade.c b/lib/libpacman/trans_sysupgrade.c index 40902e4..5ed110e 100644 --- a/lib/libpacman/trans_sysupgrade.c +++ b/lib/libpacman/trans_sysupgrade.c @@ -40,6 +40,7 @@ #include "util/list.h" #include "util/log.h" +#include "util/stringlist.h" #include "error.h" #include "package.h" #include "db.h" diff --git a/lib/libpacman/util/list.c b/lib/libpacman/util/list.c index 71e22f1..78dd692 100644 --- a/lib/libpacman/util/list.c +++ b/lib/libpacman/util/list.c @@ -21,11 +21,12 @@ #include "config.h" #include <stdlib.h> -#include <string.h> #include <stdio.h> #include <assert.h> + /* pacman-g2 */ #include "list.h" + #include "util.h" pmlist_t *_pacman_list_new() @@ -208,20 +209,6 @@ int _pacman_list_is_in(void *needle, pmlist_t *haystack) return(0); } -/* Test for existence of a string in a pmlist_t - */ -int _pacman_list_is_strin(const char *needle, pmlist_t *haystack) -{ - pmlist_t *lp; - - for(lp = haystack; lp; lp = lp->next) { - if(lp->data && !strcmp(lp->data, needle)) { - return(1); - } - } - return(0); -} - pmlist_t *_pacman_list_last(pmlist_t *list) { if(list == NULL) { @@ -233,24 +220,6 @@ pmlist_t *_pacman_list_last(pmlist_t *list) return(list->last); } -/* Filter out any duplicate strings in a list. - * - * Not the most efficient way, but simple to implement -- we assemble - * a new list, using is_in() to check for dupes at each iteration. - * - */ -pmlist_t *_pacman_list_remove_dupes(pmlist_t *list) -{ - pmlist_t *i, *newlist = NULL; - - for(i = list; i; i = i->next) { - if(!_pacman_list_is_strin(i->data, newlist)) { - newlist = _pacman_list_add(newlist, strdup(i->data)); - } - } - return newlist; -} - /* Reverse the order of a list * * The caller is responsible for freeing the old list @@ -270,16 +239,4 @@ pmlist_t *_pacman_list_reverse(pmlist_t *list) return(newlist); } -pmlist_t *_pacman_list_strdup(pmlist_t *list) -{ - pmlist_t *newlist = NULL; - pmlist_t *lp; - - for(lp = list; lp; lp = lp->next) { - newlist = _pacman_list_add(newlist, strdup(lp->data)); - } - - return(newlist); -} - /* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libpacman/util/list.h b/lib/libpacman/util/list.h index ca736a7..6188fb0 100644 --- a/lib/libpacman/util/list.h +++ b/lib/libpacman/util/list.h @@ -46,11 +46,8 @@ pmlist_t *_pacman_list_add_sorted(pmlist_t *list, void *data, _pacman_fn_cmp fn) pmlist_t *_pacman_list_remove(pmlist_t *haystack, void *needle, _pacman_fn_cmp fn, void **data); int _pacman_list_count(pmlist_t *list); int _pacman_list_is_in(void *needle, pmlist_t *haystack); -int _pacman_list_is_strin(const char *needle, pmlist_t *haystack); pmlist_t *_pacman_list_last(pmlist_t *list); -pmlist_t *_pacman_list_remove_dupes(pmlist_t *list); pmlist_t *_pacman_list_reverse(pmlist_t *list); -pmlist_t *_pacman_list_strdup(pmlist_t *list); #endif /* _PACMAN_LIST_H */ diff --git a/lib/libpacman/util/log.c b/lib/libpacman/util/log.c index cb873b3..0c7d6db 100644 --- a/lib/libpacman/util/log.c +++ b/lib/libpacman/util/log.c @@ -27,7 +27,7 @@ /* pacman-g2 */ #include "log.h" -#include "pacman.h" +#include "util.h" /* Internal library log mechanism */ pacman_cb_log pm_logcb = NULL; diff --git a/lib/libpacman/util/stringlist.c b/lib/libpacman/util/stringlist.c new file mode 100644 index 0000000..ca158b2 --- /dev/null +++ b/lib/libpacman/util/stringlist.c @@ -0,0 +1,77 @@ +/* + * stringlist.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 <string.h> +#include <stdio.h> +#include <assert.h> + +/* pacman-g2 */ +#include "stringlist.h" + +#include "util.h" + +/* Test for existence of a string in a pmlist_t + */ +int _pacman_list_is_strin(const char *needle, pmlist_t *haystack) +{ + pmlist_t *lp; + + for(lp = haystack; lp; lp = lp->next) { + if(lp->data && !strcmp(lp->data, needle)) { + return(1); + } + } + return(0); +} + +/* Filter out any duplicate strings in a list. + * + * Not the most efficient way, but simple to implement -- we assemble + * a new list, using is_in() to check for dupes at each iteration. + * + */ +pmlist_t *_pacman_list_remove_dupes(pmlist_t *list) +{ + pmlist_t *i, *newlist = NULL; + + for(i = list; i; i = i->next) { + if(!_pacman_list_is_strin(i->data, newlist)) { + newlist = _pacman_list_add(newlist, strdup(i->data)); + } + } + return newlist; +} + +pmlist_t *_pacman_list_strdup(pmlist_t *list) +{ + pmlist_t *newlist = NULL; + pmlist_t *lp; + + for(lp = list; lp; lp = lp->next) { + newlist = _pacman_list_add(newlist, strdup(lp->data)); + } + + return(newlist); +} + +/* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libpacman/util/stringlist.h b/lib/libpacman/util/stringlist.h new file mode 100644 index 0000000..f95b5b7 --- /dev/null +++ b/lib/libpacman/util/stringlist.h @@ -0,0 +1,32 @@ +/* + * stringlist.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_STRINGLIST_H +#define _PACMAN_STRINGLIST_H + +#include "list.h" + +int _pacman_list_is_strin(const char *needle, pmlist_t *haystack); +pmlist_t *_pacman_list_remove_dupes(pmlist_t *list); +pmlist_t *_pacman_list_strdup(pmlist_t *list); + +#endif /* _PACMAN_STRINGLIST_H */ + +/* vim: set ts=2 sw=2 noet: */ _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
