FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux Pacman Development

 
 
LinkBack Thread Tools
 
Old 02-20-2011, 12:42 PM
Jakob Gruber
 
Default 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>
---
src/pacman/util.c | 53 ++++++++++++++++++++++++++++-------------------------
1 files changed, 28 insertions(+), 25 deletions(-)

diff --git a/src/pacman/util.c b/src/pacman/util.c
index 8903d61..f1f2f26 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -498,10 +498,26 @@ void list_display_linebreak(const char *title, const alpm_list_t *list)
}
}
}
+
+/* returns package info as a string */
+static char *create_list_element(pmpkg_t *pkg)
+{
+ char *ret, *size;
+ const char *pkgstr = config->showsize ? "%s-%s [%s]" : "%s-%s";
+
+ size = size_to_human_string_mb(alpm_pkg_get_size(pkg));
+ pm_asprintf(&ret, pkgstr, alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg),
+ size);
+ free(size);
+
+ return ret;
+}
+
/* prepare a list of pkgs to display */
void display_targets(const alpm_list_t *pkgs, int install)
{
char *str, *size;
+ const char *title;
const alpm_list_t *i;
off_t isize = 0, dlsize = 0;
alpm_list_t *targets = NULL;
@@ -510,34 +526,24 @@ void display_targets(const alpm_list_t *pkgs, int install)
return;
}

- printf("
");
+ title = install ? _("Targets (%d):") : _("Remove (%d):");
+
for(i = pkgs; i; i = alpm_list_next(i)) {
pmpkg_t *pkg = alpm_list_getdata(i);

- if(install) {
- dlsize += alpm_pkg_download_size(pkg);
- }
+ dlsize += alpm_pkg_download_size(pkg);
isize += alpm_pkg_get_isize(pkg);

- /* print the package size with the output if ShowSize option set */
- if(config->showsize) {
- size = size_to_human_string_mb(alpm_pkg_get_size(pkg));
- pm_asprintf(&str, "%s-%s [%s]", alpm_pkg_get_name(pkg),
- alpm_pkg_get_version(pkg), size);
- free(size);
- } else {
- pm_asprintf(&str, "%s-%s", alpm_pkg_get_name(pkg),
- alpm_pkg_get_version(pkg));
- }
- targets = alpm_list_add(targets, str);
+ targets = alpm_list_add(targets, create_list_element(pkg));
}

- if(install) {
- pm_asprintf(&str, _("Targets (%d):"), alpm_list_count(targets));
- list_display(str, targets);
- free(str);
- printf("
");
+ pm_asprintf(&str, title, alpm_list_count(pkgs));
+
+ printf("
");
+ list_display(str, targets);
+ printf("
");

+ if(install) {
size = size_to_human_string_mb(dlsize);
printf(_("Total Download Size: %s
"), size);
free(size);
@@ -547,16 +553,13 @@ void display_targets(const alpm_list_t *pkgs, int install)
free(size);
}
} else {
- pm_asprintf(&str, _("Remove (%d):"), alpm_list_count(targets));
- list_display(str, targets);
- free(str);
- printf("
");
-
size = size_to_human_string_mb(isize);
printf(_("Total Removed Size: %s
"), size);
free(size);
}

+out:
+ free(str);
FREELIST(targets);
}

--
1.7.4.1


--------------080202080603090300060904
Content-Type: text/plain;
name="0006-New-VerbosePkgLists-option.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="0006-New-VerbosePkgLists-option.patch"
 
Old 02-21-2011, 06:02 PM
Jakob Gruber
 
Default 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>
---
src/pacman/util.c | 53 ++++++++++++++++++++++++++++-------------------------
1 files changed, 28 insertions(+), 25 deletions(-)

diff --git a/src/pacman/util.c b/src/pacman/util.c
index 8903d61..85d2d8c 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -498,10 +498,26 @@ void list_display_linebreak(const char *title, const alpm_list_t *list)
}
}
}
+
+/* returns package info as a string */
+static char *create_list_element(pmpkg_t *pkg)
+{
+ char *ret, *size;
+ const char *pkgstr = config->showsize ? "%s-%s [%s]" : "%s-%s";
+
+ size = size_to_human_string_mb(alpm_pkg_get_size(pkg));
+ pm_asprintf(&ret, pkgstr, alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg),
+ size);
+ free(size);
+
+ return ret;
+}
+
/* prepare a list of pkgs to display */
void display_targets(const alpm_list_t *pkgs, int install)
{
char *str, *size;
+ const char *title;
const alpm_list_t *i;
off_t isize = 0, dlsize = 0;
alpm_list_t *targets = NULL;
@@ -510,34 +526,24 @@ void display_targets(const alpm_list_t *pkgs, int install)
return;
}

- printf("
");
+ title = install ? _("Targets (%d):") : _("Remove (%d):");
+
for(i = pkgs; i; i = alpm_list_next(i)) {
pmpkg_t *pkg = alpm_list_getdata(i);

- if(install) {
- dlsize += alpm_pkg_download_size(pkg);
- }
+ dlsize += alpm_pkg_download_size(pkg);
isize += alpm_pkg_get_isize(pkg);

- /* print the package size with the output if ShowSize option set */
- if(config->showsize) {
- size = size_to_human_string_mb(alpm_pkg_get_size(pkg));
- pm_asprintf(&str, "%s-%s [%s]", alpm_pkg_get_name(pkg),
- alpm_pkg_get_version(pkg), size);
- free(size);
- } else {
- pm_asprintf(&str, "%s-%s", alpm_pkg_get_name(pkg),
- alpm_pkg_get_version(pkg));
- }
- targets = alpm_list_add(targets, str);
+ targets = alpm_list_add(targets, create_list_element(pkg));
}

- if(install) {
- pm_asprintf(&str, _("Targets (%d):"), alpm_list_count(targets));
- list_display(str, targets);
- free(str);
- printf("
");
+ pm_asprintf(&str, title, alpm_list_count(targets));
+
+ printf("
");
+ list_display(str, targets);
+ printf("
");

+ if(install) {
size = size_to_human_string_mb(dlsize);
printf(_("Total Download Size: %s
"), size);
free(size);
@@ -547,16 +553,13 @@ void display_targets(const alpm_list_t *pkgs, int install)
free(size);
}
} else {
- pm_asprintf(&str, _("Remove (%d):"), alpm_list_count(targets));
- list_display(str, targets);
- free(str);
- printf("
");
-
size = size_to_human_string_mb(isize);
printf(_("Total Removed Size: %s
"), size);
free(size);
}

+out:
+ free(str);
FREELIST(targets);
}

--
1.7.4.1
 
Old 02-28-2011, 03:40 PM
Jakob Gruber
 
Default 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>
---
src/pacman/util.c | 48 ++++++++++++++++++++++++++----------------------
1 files changed, 26 insertions(+), 22 deletions(-)

diff --git a/src/pacman/util.c b/src/pacman/util.c
index 23b95c9..ba64a77 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -498,11 +498,27 @@ void list_display_linebreak(const char *title, const alpm_list_t *list)
}
}
}
+
+/* returns package info as a string */
+static char *create_list_element(pmpkg_t *pkg)
+{
+ char *ret;
+ const char *label;
+ double size;
+ const char *pkgstr = config->showsize ? "%s-%s [%.2f %s]" : "%s-%s";
+
+ size = humanize_size(alpm_pkg_get_size(pkg), 0, 1, &label);
+ pm_asprintf(&ret, pkgstr, alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg),
+ size, label);
+
+ return(ret);
+}
+
/* prepare a list of pkgs to display */
void display_targets(const alpm_list_t *pkgs, int install)
{
char *str;
- const char *label;
+ const char *title, *label;
double size;
const alpm_list_t *i;
off_t isize = 0, dlsize = 0;
@@ -512,7 +528,6 @@ void display_targets(const alpm_list_t *pkgs, int install)
return;
}

- printf("
");
for(i = pkgs; i; i = alpm_list_next(i)) {
pmpkg_t *pkg = alpm_list_getdata(i);

@@ -521,24 +536,17 @@ void display_targets(const alpm_list_t *pkgs, int install)
}
isize += alpm_pkg_get_isize(pkg);

- /* print the package size with the output if ShowSize option set */
- if(config->showsize) {
- size = humanize_size(alpm_pkg_get_size(pkg), 0, 1, &label);
- pm_asprintf(&str, "%s-%s [%.2f %s]", alpm_pkg_get_name(pkg),
- alpm_pkg_get_version(pkg), size, label);
- } else {
- pm_asprintf(&str, "%s-%s", alpm_pkg_get_name(pkg),
- alpm_pkg_get_version(pkg));
- }
- targets = alpm_list_add(targets, str);
+ targets = alpm_list_add(targets, create_list_element(pkg));
}

- if(install) {
- pm_asprintf(&str, _("Targets (%d):"), alpm_list_count(targets));
- list_display(str, targets);
- free(str);
- printf("
");
+ title = install ? _("Targets (%d):") : _("Remove (%d):");
+ pm_asprintf(&str, title, alpm_list_count(pkgs));
+
+ printf("
");
+ list_display(str, targets);
+ printf("
");

+ if(install) {
size = humanize_size(dlsize, 'M', 1, &label);
printf(_("Total Download Size: %.2f %s
"), size, label);
if(!(config->flags & PM_TRANS_FLAG_DOWNLOADONLY)) {
@@ -546,15 +554,11 @@ void display_targets(const alpm_list_t *pkgs, int install)
printf(_("Total Installed Size: %.2f %s
"), size, label);
}
} else {
- pm_asprintf(&str, _("Remove (%d):"), alpm_list_count(targets));
- list_display(str, targets);
- free(str);
- printf("
");
-
size = humanize_size(isize, 'M', 1, &label);
printf(_("Total Removed Size: %.2f %s
"), size, label);
}

+ free(str);
FREELIST(targets);
}

--
1.7.4.1
 

Thread Tools




All times are GMT. The time now is 07:26 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org