From e27a8c9ae323c275b0c3503d6a6ea18b639f4dc6 Mon Sep 17 00:00:00 2001 From: Nagy Gabor Date: Thu, 31 Jul 2008 15:58:25 +0200 Subject: Add new list_display_linebreak function list_display puts several members on the same line, which is not appropriate for optdepends: Optdepends: foo: feature1 bar: feature2 baz: feature3 The new list_display_linebreak function puts every member on its own line, which is much better with optdepends: Optdepends: foo: feature1 bar: feature2 baz: feature3 Signed-off-by: Nagy Gabor [Xav: implement this new behavior as a new function rather than as a parameter of list_display] Signed-off-by: Xavier Chantry Signed-off-by: Dan McGee --- src/pacman/package.c | 2 +- src/pacman/util.c | 58 ++++++++++++++++++++++++++++++++-------------------- src/pacman/util.h | 1 + 3 files changed, 38 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/pacman/package.c b/src/pacman/package.c index 87ffd985..fddce94a 100644 --- a/src/pacman/package.c +++ b/src/pacman/package.c @@ -95,7 +95,7 @@ void dump_pkg_full(pmpkg_t *pkg, int level) list_display(_("Groups :"), alpm_pkg_get_groups(pkg)); list_display(_("Provides :"), alpm_pkg_get_provides(pkg)); list_display(_("Depends On :"), depstrings); - list_display(_("Optional Deps :"), alpm_pkg_get_optdepends(pkg)); + list_display_linebreak(_("Optional Deps :"), alpm_pkg_get_optdepends(pkg)); /* Only applicable if installed */ if(level > 0) { list_display(_("Required By :"), requiredby); diff --git a/src/pacman/util.c b/src/pacman/util.c index 43835047..1a74c9ea 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -461,38 +461,27 @@ void string_display(const char *title, const char *string) void list_display(const char *title, const alpm_list_t *list) { const alpm_list_t *i; - int cols, len; - wchar_t *wcstr; + int cols, len = 0; if(title) { - /* len goes from # bytes -> # chars -> # cols */ - len = strlen(title) + 1; - wcstr = calloc(len, sizeof(wchar_t)); - len = mbstowcs(wcstr, title, len); - len = wcswidth(wcstr, len); - free(wcstr); + len = string_length(title) + 1; printf("%s ", title); - } else { - len = 0; } - if(list) { + if(!list) { + printf(_("None\n")); + } else { for(i = list, cols = len; i; i = alpm_list_next(i)) { char *str = alpm_list_getdata(i); - /* s goes from # bytes -> # chars -> # cols */ - int s = strlen(str) + 1; - wcstr = calloc(s, sizeof(wchar_t)); - s = mbstowcs(wcstr, str, s); - s = wcswidth(wcstr, s); - free(wcstr); + int s = string_length(str); /* two additional spaces are added to the length */ s += 2; int maxcols = getcols(); - if(s + cols >= maxcols) { - int i; + if(s + cols > maxcols) { + int j; cols = len; printf("\n"); - for (i = 0; i <= len; ++i) { + for (j = 1; j <= len; j++) { printf(" "); } } @@ -500,11 +489,36 @@ void list_display(const char *title, const alpm_list_t *list) cols += s; } printf("\n"); - } else { - printf(_("None\n")); } } +void list_display_linebreak(const char *title, const alpm_list_t *list) +{ + const alpm_list_t *i; + int len = 0; + + if(title) { + len = string_length(title) + 1; + printf("%s ", title); + } + + if(!list) { + printf(_("None\n")); + } else { + /* Print the first element */ + indentprint((const char *) alpm_list_getdata(list), len); + printf("\n"); + /* Print the rest */ + for(i = alpm_list_next(list); i; i = alpm_list_next(i)) { + int j; + for(j = 1; j <= len; j++) { + printf(" "); + } + indentprint((const char *) alpm_list_getdata(i), len); + printf("\n"); + } + } +} /* prepare a list of pkgs to display */ void display_targets(const alpm_list_t *pkgs, int install) { diff --git a/src/pacman/util.h b/src/pacman/util.h index 2ddc1b52..209b2424 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -51,6 +51,7 @@ char *strreplace(const char *str, const char *needle, const char *replace); alpm_list_t *strsplit(const char *str, const char splitchar); void string_display(const char *title, const char *string); void list_display(const char *title, const alpm_list_t *list); +void list_display_linebreak(const char *title, const alpm_list_t *list); void display_targets(const alpm_list_t *pkgs, int install); void display_synctargets(const alpm_list_t *syncpkgs); int yesno(short preset, char *fmt, ...); -- cgit v1.2.3-24-g4f1b