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

commit 8456d4e55af16fe613c9e8f1951f8caad5dbb930
Author: Michel Hermier <[email protected]>
Date:   Thu May 9 16:49:40 2013 +0200

pacman-g2: libflib'ify custom list implementation.

diff --git a/src/pacman-g2/list.c b/src/pacman-g2/list.c
index 56cffe6..732cc98 100644
--- a/src/pacman-g2/list.c
+++ b/src/pacman-g2/list.c
@@ -30,75 +30,6 @@

extern int maxcols;

-static list_t *list_last(list_t *list);
-
-list_t *list_new()
-{
-       list_t *list = NULL;
-
-       list = (list_t *)malloc(sizeof(list_t));
-       if(list == NULL) {
-               return(NULL);
-       }
-       list->data = NULL;
-       list->next = NULL;
-       return(list);
-}
-
-void list_free(list_t *list)
-{
-       list_t *ptr, *it = list;
-
-       while(it) {
-               ptr = it->next;
-               free(it->data);
-               free(it);
-               it = ptr;
-       }
-       return;
-}
-
-list_t *list_add(list_t *list, void *data)
-{
-       list_t *ptr, *lp;
-
-       ptr = list;
-       if(ptr == NULL) {
-               ptr = list_new();
-       }
-
-       lp = list_last(ptr);
-       if(lp == ptr && lp->data == NULL) {
-               /* nada */
-       } else {
-               lp->next = list_new();
-               if(lp->next == NULL) {
-                       return(NULL);
-               }
-               lp = lp->next;
-       }
-       lp->data = data;
-       return(ptr);
-}
-
-int list_count(list_t *list)
-{
-       int i;
-       list_t *lp;
-
-       for(lp = list, i = 0; lp; lp = lp->next, i++);
-
-       return(i);
-}
-
-static list_t *list_last(list_t *list)
-{
-       list_t *ptr;
-
-       for(ptr = list; ptr && ptr->next; ptr = ptr->next);
-       return(ptr);
-}
-
/* Test for existence of a string in a list_t
*/
int list_is_strin(char *needle, list_t *haystack)
@@ -144,54 +75,4 @@ void list_display(const char *title, list_t *list)
}
}

-void PM_LIST_display(const char *title, PM_LIST *list)
-{
-       PM_LIST *lp;
-       int cols, len;
-
-       len = strlen(title);
-       printf("%s ", title);
-
-       if(list) {
-               for(lp = list, cols = len; lp; lp = pacman_list_next(lp)) {
-                       int s = strlen(pacman_list_getdata(lp))+1;
-                       if(s+cols >= maxcols) {
-                               int i;
-                               cols = len;
-                               printf("\n");
-                               for (i = 0; i < len+1; i++) {
-                                       printf(" ");
-                               }
-                       }
-                       printf("%s ", (char *)pacman_list_getdata(lp));
-                       cols += s;
-               }
-               printf("\n");
-       } else {
-               printf(_("None\n"));
-       }
-}
-
-/* Filter out any duplicate strings in a PM_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.
- *
- * This function takes a PM_LIST* and returns a list_t*
- *
- */
-list_t *PM_LIST_remove_dupes(PM_LIST *list)
-{
-       PM_LIST *i;
-       list_t *newlist = NULL;
-
-       for(i = pacman_list_first(list); i; i = pacman_list_next(i)) {
-               char *data = pacman_list_getdata(i);
-               if(!list_is_strin(data, newlist)) {
-                       newlist = list_add(newlist, strdup(data));
-               }
-       }
-       return newlist;
-}
-
/* vim: set ts=2 sw=2 noet: */
diff --git a/src/pacman-g2/list.h b/src/pacman-g2/list.h
index d71f4b5..eef48c0 100644
--- a/src/pacman-g2/list.h
+++ b/src/pacman-g2/list.h
@@ -23,31 +23,18 @@

#include <pacman.h>

+#include "flist.h"
+
/* Chained list struct */
-typedef struct __list_t {
-       void *data;
-       struct __list_t *next;
-} list_t;
+typedef FList list_t;

-#define FREELIST(p) do { if(p) { list_free(p); p = NULL; } } while(0)
-#define FREELISTPTR(p) do { \
-       list_t *q; \
-       for(q = p; q; q = q->next) { \
-               q->data = NULL; \
-       } \
-       FREELIST(p); \
-} while(0)
+#define FREELIST(p) do { if(p) { f_list_delete (p, (FVisitorFunc)free, NULL); 
p = NULL; } } while(0)
+#define FREELISTPTR(p) do { if(p) { f_list_delete (p, NULL, NULL); p = NULL; } 
} while (0)

-list_t *list_new(void);
-void list_free(list_t *list);
-list_t *list_add(list_t *list, void *data);
-int list_count(list_t *list);
+#define list_add f_list_append
int list_is_strin(char *needle, list_t *haystack);
void list_display(const char *title, list_t *list);

-void PM_LIST_display(const char *title, PM_LIST *list);
-list_t *PM_LIST_remove_dupes(PM_LIST *list);
-
#endif /* _PM_LIST_H */

/* vim: set ts=2 sw=2 noet: */
diff --git a/src/pacman-g2/package.c b/src/pacman-g2/package.c
index 5b9ea42..bb1289b 100644
--- a/src/pacman-g2/package.c
+++ b/src/pacman-g2/package.c
@@ -50,11 +50,11 @@ void dump_pkg_full(PM_PKG *pkg, int level)
printf(_("Name           : %s\n"), (char *)pacman_pkg_getinfo(pkg, 
PM_PKG_NAME));
printf(_("Version        : %s\n"), (char *)pacman_pkg_getinfo(pkg, 
PM_PKG_VERSION));

-       PM_LIST_display(_("Groups         :"), pacman_pkg_getinfo(pkg, 
PM_PKG_GROUPS));
+       list_display(_("Groups         :"), pacman_pkg_getinfo(pkg, 
PM_PKG_GROUPS));

printf(_("Packager       : %s\n"), (char *)pacman_pkg_getinfo(pkg, 
PM_PKG_PACKAGER));
printf("URL            : %s\n", (char *)pacman_pkg_getinfo(pkg, PM_PKG_URL));
-       PM_LIST_display(_("License        :"), pacman_pkg_getinfo(pkg, 
PM_PKG_LICENSE));
+       list_display(_("License        :"), pacman_pkg_getinfo(pkg, 
PM_PKG_LICENSE));
printf(_("Architecture   : %s\n"), (char *)pacman_pkg_getinfo(pkg, 
PM_PKG_ARCH));
printf(_("Size           : %ld\n"), (long int)pacman_pkg_getinfo(pkg, 
PM_PKG_SIZE));

@@ -80,11 +80,11 @@ void dump_pkg_full(PM_PKG *pkg, int level)
break;
}

-       PM_LIST_display(_("Provides       :"), pacman_pkg_getinfo(pkg, 
PM_PKG_PROVIDES));
-       PM_LIST_display(_("Depends On     :"), pacman_pkg_getinfo(pkg, 
PM_PKG_DEPENDS));
-       PM_LIST_display(_("Removes        :"), pacman_pkg_getinfo(pkg, 
PM_PKG_REMOVES));
-       PM_LIST_display(_("Required By    :"), pacman_pkg_getinfo(pkg, 
PM_PKG_REQUIREDBY));
-       PM_LIST_display(_("Conflicts With :"), pacman_pkg_getinfo(pkg, 
PM_PKG_CONFLICTS));
+       list_display(_("Provides       :"), pacman_pkg_getinfo(pkg, 
PM_PKG_PROVIDES));
+       list_display(_("Depends On     :"), pacman_pkg_getinfo(pkg, 
PM_PKG_DEPENDS));
+       list_display(_("Removes        :"), pacman_pkg_getinfo(pkg, 
PM_PKG_REMOVES));
+       list_display(_("Required By    :"), pacman_pkg_getinfo(pkg, 
PM_PKG_REQUIREDBY));
+       list_display(_("Conflicts With :"), pacman_pkg_getinfo(pkg, 
PM_PKG_CONFLICTS));

printf(_("Description    : "));
indentprint(pacman_pkg_getinfo(pkg, PM_PKG_DESC), 17);
@@ -145,12 +145,12 @@ void dump_pkg_sync(PM_PKG *pkg, char *treename)
printf(_("Name              : %s\n"), (char *)pacman_pkg_getinfo(pkg, 
PM_PKG_NAME));
printf(_("Version           : %s\n"), (char *)pacman_pkg_getinfo(pkg, 
PM_PKG_VERSION));

-       PM_LIST_display(_("Groups            :"), pacman_pkg_getinfo(pkg, 
PM_PKG_GROUPS));
-       PM_LIST_display(_("Provides          :"), pacman_pkg_getinfo(pkg, 
PM_PKG_PROVIDES));
-       PM_LIST_display(_("Depends On        :"), pacman_pkg_getinfo(pkg, 
PM_PKG_DEPENDS));
-       PM_LIST_display(_("Removes           :"), pacman_pkg_getinfo(pkg, 
PM_PKG_REMOVES));
-       PM_LIST_display(_("Conflicts With    :"), pacman_pkg_getinfo(pkg, 
PM_PKG_CONFLICTS));
-       PM_LIST_display(_("Replaces          :"), pacman_pkg_getinfo(pkg, 
PM_PKG_REPLACES));
+       list_display(_("Groups            :"), pacman_pkg_getinfo(pkg, 
PM_PKG_GROUPS));
+       list_display(_("Provides          :"), pacman_pkg_getinfo(pkg, 
PM_PKG_PROVIDES));
+       list_display(_("Depends On        :"), pacman_pkg_getinfo(pkg, 
PM_PKG_DEPENDS));
+       list_display(_("Removes           :"), pacman_pkg_getinfo(pkg, 
PM_PKG_REMOVES));
+       list_display(_("Conflicts With    :"), pacman_pkg_getinfo(pkg, 
PM_PKG_CONFLICTS));
+       list_display(_("Replaces          :"), pacman_pkg_getinfo(pkg, 
PM_PKG_REPLACES));

printf(_("Size (compressed) : %ld\n"), (long)pacman_pkg_getinfo(pkg, 
PM_PKG_SIZE));
printf(_("Size (installed)  : %ld\n"), (long)pacman_pkg_getinfo(pkg, 
PM_PKG_USIZE));
diff --git a/src/pacman-g2/pacman-g2.c b/src/pacman-g2/pacman-g2.c
index 4f7d33d..dd5fab2 100644
--- a/src/pacman-g2/pacman-g2.c
+++ b/src/pacman-g2/pacman-g2.c
@@ -638,7 +638,7 @@ int main(int argc, char *argv[])
cleanup(1);
}

-       if(list_count(pm_targets) == 0 && !(config->op == PM_OP_QUERY || 
(config->op == PM_OP_SYNC
+       if (f_list_count(pm_targets) == 0 && !(config->op == PM_OP_QUERY || 
(config->op == PM_OP_SYNC
&& (config->op_s_sync || config->op_s_upgrade || config->op_s_clean || 
config->group
|| config->op_q_list)) || config->op == PM_OP_PS)) {
ERR(NL, _("no targets specified (use -h for help)\n"));
diff --git a/src/pacman-g2/ps.c b/src/pacman-g2/ps.c
index fb2e6d0..23a3218 100644
--- a/src/pacman-g2/ps.c
+++ b/src/pacman-g2/ps.c
@@ -34,6 +34,8 @@
#include "conf.h"
#include "ps.h"

+#include "flist.h"
+
extern config_t *config;

static int start_lsof(FILE** childout, pid_t* childpid, int silent)
@@ -109,7 +111,7 @@ static int ps_free(ps_t *ps)
static list_t* add_or_free(list_t* l, ps_t* ps)
{
if (ps) {
-               if (list_count(ps->files) > 0) {
+               if (f_list_count (ps->files) > 0) {
l = list_add(l, ps);
} else
ps_free(ps);
@@ -145,7 +147,7 @@ static list_t* ps_parse(FILE *fp)
{
char buf[PATH_MAX+1], *ptr;
ps_t* ps = NULL;
-       list_t* ret = list_new();
+       list_t* ret = f_list_new ();

while(!feof(fp)) {
if(fgets(buf, PATH_MAX, fp) == NULL)
diff --git a/src/pacman-g2/query.c b/src/pacman-g2/query.c
index c5483ee..3e8ae76 100644
--- a/src/pacman-g2/query.c
+++ b/src/pacman-g2/query.c
@@ -84,7 +84,7 @@ int querypkg(list_t *targets)
}

if(config->op_q_foreign) {
-               if(pmc_syncs == NULL || !list_count(pmc_syncs)) {
+               if (f_list_count (pmc_syncs) == 0) {
ERR(NL, _("no usable package repositories configured.\n"));
return(1);
}
diff --git a/src/pacman-g2/remove.c b/src/pacman-g2/remove.c
index 7e0e737..b6f4055 100644
--- a/src/pacman-g2/remove.c
+++ b/src/pacman-g2/remove.c
@@ -62,7 +62,7 @@ int removepkg(list_t *targets)
pkgnames = pacman_grp_getinfo(grp, PM_GRP_PKGNAMES);

MSG(NL, _(":: group %s:\n"), pacman_grp_getinfo(grp, PM_GRP_NAME));
-                       PM_LIST_display("   ", pkgnames);
+                       list_display("   ", pkgnames);
all = yesno(_("    Remove whole content? [Y/n] "));
for(lp = pacman_list_first(pkgnames); lp; lp = pacman_list_next(lp)) {
if(all || yesno(_(":: Remove %s from group %s? [Y/n] "), (char 
*)pacman_list_getdata(lp), i->data)) {
diff --git a/src/pacman-g2/sync.c b/src/pacman-g2/sync.c
index 910a820..90dc812 100644
--- a/src/pacman-g2/sync.c
+++ b/src/pacman-g2/sync.c
@@ -49,6 +49,8 @@
#include "sync.h"
#include "conf.h"

+#include "fstringlist.h"
+
extern PM_DB *db_local;

extern config_t *config;
@@ -134,7 +136,7 @@ static int sync_group(int level, list_t *syncs, list_t 
*targets)

if(grp) {
MSG(NL, "%s\n", (char *)pacman_grp_getinfo(grp, PM_GRP_NAME));
-                                       PM_LIST_display("   ", 
pacman_grp_getinfo(grp, PM_GRP_PKGNAMES));
+                                       list_display("   ", 
pacman_grp_getinfo(grp, PM_GRP_PKGNAMES));
found = 1;
}
}
@@ -153,7 +155,7 @@ static int sync_group(int level, list_t *syncs, list_t 
*targets)

MSG(NL, "%s\n", (char *)pacman_grp_getinfo(grp, PM_GRP_NAME));
if(grp && level > 1) {
-                                       PM_LIST_display("   ", 
pacman_grp_getinfo(grp, PM_GRP_PKGNAMES));
+                                       list_display("   ", 
pacman_grp_getinfo(grp, PM_GRP_PKGNAMES));
}
}
}
@@ -261,7 +263,7 @@ int syncpkg(list_t *targets)
list_t *i;
PM_LIST *packages, *data, *lp;

-       if(pmc_syncs == NULL || !list_count(pmc_syncs)) {
+       if (f_list_count (pmc_syncs) == 0) {
ERR(NL, _("no usable package repositories configured.\n"));
return(1);
}
@@ -343,7 +345,7 @@ int syncpkg(list_t *targets)
for(lp = pacman_list_first(data); lp; lp = pacman_list_next(lp)) {
PM_SYNCPKG *ps = pacman_list_getdata(lp);
PM_PKG *spkg = pacman_sync_getinfo(ps, PM_SYNC_PKG);
-                       if(!strcmp("pacman-g2", pacman_pkg_getinfo(spkg, 
PM_PKG_NAME)) && pacman_list_count(data) > 1) {
+                       if (!strcmp("pacman-g2", pacman_pkg_getinfo(spkg, 
PM_PKG_NAME)) && f_list_count (data) > 1) {
MSG(NL, _("\n:: pacman-g2 has detected a newer version of the \"pacman-g2\" 
package.\n"));
MSG(NL, _(":: It is recommended that you allow pacman-g2 to upgrade itself\n"));
MSG(NL, _(":: first, then you can re-run the operation with the newer 
version.\n"));
@@ -400,7 +402,7 @@ int syncpkg(list_t *targets)
pmpkgs = pacman_grp_getinfo(grp, PM_GRP_PKGNAMES);
/* remove dupe entries in case a package exists in multiple repos */
/*   (the dupe function takes a PM_LIST* and returns a list_t*) */
-                                               pkgs = 
PM_LIST_remove_dupes(pmpkgs);
+                                               pkgs = f_stringlist_uniques 
(pmpkgs);
list_display("   ", pkgs);
if(yesno(_(":: Install whole content? [Y/n] "))) {
for(k = pkgs; k; k = k->next) {
@@ -414,7 +416,7 @@ int syncpkg(list_t *targets)
}
}
}
-                                               FREELIST(pkgs);
+                                               FREELISTPTR(pkgs);
}
}
/* targ is not a group, see if it's a regex */
_______________________________________________
Frugalware-git mailing list
[email protected]
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to