Refactor display_targets for readability

Row handling is moved to its own function in preparation for verbose
package lists.

Signed-off-by: Jakob Gruber <jakob.gruber@gmail.com>
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Jakob Gruber 2011-02-20 14:42:05 +01:00 committed by Dan McGee
parent ecf15be0a7
commit c3f3d0b81a

View file

@ -518,11 +518,12 @@ void list_display_linebreak(const char *title, const alpm_list_t *list)
} }
} }
} }
/* prepare a list of pkgs to display */ /* prepare a list of pkgs to display */
void display_targets(const alpm_list_t *pkgs, int install) void display_targets(const alpm_list_t *pkgs, int install)
{ {
char *str; char *str;
const char *label; const char *title, *label;
double size; double size;
const alpm_list_t *i; const alpm_list_t *i;
off_t isize = 0, dlsize = 0; off_t isize = 0, dlsize = 0;
@ -532,7 +533,6 @@ void display_targets(const alpm_list_t *pkgs, int install)
return; return;
} }
printf("\n");
for(i = pkgs; i; i = alpm_list_next(i)) { for(i = pkgs; i; i = alpm_list_next(i)) {
pmpkg_t *pkg = alpm_list_getdata(i); pmpkg_t *pkg = alpm_list_getdata(i);
@ -546,12 +546,14 @@ void display_targets(const alpm_list_t *pkgs, int install)
targets = alpm_list_add(targets, str); targets = alpm_list_add(targets, str);
} }
if(install) { title = install ? _("Targets (%d):") : _("Remove (%d):");
pm_asprintf(&str, _("Targets (%d):"), alpm_list_count(targets)); pm_asprintf(&str, title, alpm_list_count(pkgs));
printf("\n");
list_display(str, targets); list_display(str, targets);
free(str);
printf("\n"); printf("\n");
if(install) {
size = humanize_size(dlsize, 'M', 1, &label); size = humanize_size(dlsize, 'M', 1, &label);
printf(_("Total Download Size: %.2f %s\n"), size, label); printf(_("Total Download Size: %.2f %s\n"), size, label);
if(!(config->flags & PM_TRANS_FLAG_DOWNLOADONLY)) { if(!(config->flags & PM_TRANS_FLAG_DOWNLOADONLY)) {
@ -559,15 +561,11 @@ void display_targets(const alpm_list_t *pkgs, int install)
printf(_("Total Installed Size: %.2f %s\n"), size, label); printf(_("Total Installed Size: %.2f %s\n"), size, label);
} }
} else { } else {
pm_asprintf(&str, _("Remove (%d):"), alpm_list_count(targets));
list_display(str, targets);
free(str);
printf("\n");
size = humanize_size(isize, 'M', 1, &label); size = humanize_size(isize, 'M', 1, &label);
printf(_("Total Removed Size: %.2f %s\n"), size, label); printf(_("Total Removed Size: %.2f %s\n"), size, label);
} }
free(str);
FREELIST(targets); FREELIST(targets);
} }