diff options
author | Aaron Griffin <aaron@archlinux.org> | 2007-01-19 09:28:44 +0000 |
---|---|---|
committer | Aaron Griffin <aaron@archlinux.org> | 2007-01-19 09:28:44 +0000 |
commit | 616701726425417989ef1dca145b805deae6fe93 (patch) | |
tree | 2da68e080703c61a2c2116c0346b2dd58025015f /src/pacman/util.c | |
parent | 6d6ab5ed188d98fa057dbe2c83e8ce5126854426 (diff) | |
download | pacman-616701726425417989ef1dca145b805deae6fe93.tar.xz |
Preliminary checkin for alpm_list conversion
* renamed pmlist_t -> alpm_list_t
* made alpm_list_t a public type (alpm_list.h header)
* removed additional storage for registered DBs in pacman source
* some code cleanup
* removed duplicate (pm)list_display functions from pacman source
* misc code cleanup
Diffstat (limited to 'src/pacman/util.c')
-rw-r--r-- | src/pacman/util.c | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/src/pacman/util.c b/src/pacman/util.c index 406583d3..b3a595be 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -41,9 +41,10 @@ #include <limits.h> /* PATH_MAX */ #endif +#include <alpm.h> +#include <alpm_list.h> /* pacman */ #include "util.h" -#include "list.h" #include "conf.h" #include "log.h" @@ -196,22 +197,22 @@ void indentprint(const char *str, unsigned int indent) /* Condense a list of strings into one long (space-delimited) string */ -char *buildstring(list_t *strlist) +char *buildstring(alpm_list_t *strlist) { char *str; size_t size = 1; - list_t *lp; + alpm_list_t *i; - for(lp = strlist; lp; lp = lp->next) { - size += strlen(lp->data) + 1; + for(i = strlist; i; i = alpm_list_next(i)) { + size += strlen(alpm_list_getdata(i)) + 1; } str = (char *)malloc(size); if(str == NULL) { ERR(NL, _("failed to allocate %d bytes\n"), size); } str[0] = '\0'; - for(lp = strlist; lp; lp = lp->next) { - strcat(str, lp->data); + for(i = strlist; i; i = alpm_list_next(i)) { + strcat(str, alpm_list_getdata(i)); strcat(str, " "); } /* shave off the last space */ @@ -254,4 +255,34 @@ char *strtrim(char *str) return str; } +void list_display(const char *title, alpm_list_t *list) +{ + alpm_list_t *i; + int cols, len; + + len = strlen(title); + printf("%s ", title); + + if(list) { + for(i = list, cols = len; i; i = alpm_list_next(i)) { + char *str = alpm_list_getdata(i); + int s = strlen(str)+1; + unsigned int maxcols = getcols(); + if(s + cols >= maxcols) { + int i; + cols = len; + printf("\n"); + for (i = 0; i < len+1; ++i) { + printf(" "); + } + } + printf("%s ", str); + cols += s; + } + printf("\n"); + } else { + printf(_("None\n")); + } +} + /* vim: set ts=2 sw=2 noet: */ |