From 0ee3ce70a88a42387d19f0d58901fda21b0161b7 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Wed, 24 Aug 2011 22:13:26 -0500 Subject: Remove short/long label distinction We only used short labels in one place, and the short label is always the first character of the long label anyway. Signed-off-by: Dan McGee --- src/pacman/callback.c | 8 ++++---- src/pacman/package.c | 4 ++-- src/pacman/util.c | 22 +++++++++------------- src/pacman/util.h | 2 +- 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 63f7b559..04b3a527 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -663,12 +663,12 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total) } - rate_human = humanize_size((off_t)rate, '\0', 0, &rate_label); - xfered_human = humanize_size(xfered, '\0', 1, &xfered_label); + rate_human = humanize_size((off_t)rate, '\0', &rate_label); + xfered_human = humanize_size(xfered, '\0', &xfered_label); printf(" %ls%-*s ", wcfname, padwid, ""); - printf("%6.1f %3s %4.f%s/s ", - xfered_human, xfered_label, rate_human, rate_label); + printf("%6.1f %3s %4.f%c/s ", + xfered_human, xfered_label, rate_human, rate_label[0]); if(eta_h == 0) { printf("%02u:%02u", eta_m, eta_s); } else if(eta_h < 100) { diff --git a/src/pacman/package.c b/src/pacman/package.c index 7fe33a9f..80c6bf2f 100644 --- a/src/pacman/package.c +++ b/src/pacman/package.c @@ -120,14 +120,14 @@ void dump_pkg_full(alpm_pkg_t *pkg, enum pkg_from from, int extra) deplist_display(_("Conflicts With :"), alpm_pkg_get_conflicts(pkg)); deplist_display(_("Replaces :"), alpm_pkg_get_replaces(pkg)); - size = humanize_size(alpm_pkg_get_size(pkg), 'K', 1, &label); + size = humanize_size(alpm_pkg_get_size(pkg), 'K', &label); if(from == PKG_FROM_SYNCDB) { printf(_("Download Size : %6.2f %s\n"), size, label); } else if(from == PKG_FROM_FILE) { printf(_("Compressed Size: %6.2f %s\n"), size, label); } - size = humanize_size(alpm_pkg_get_isize(pkg), 'K', 1, &label); + size = humanize_size(alpm_pkg_get_isize(pkg), 'K', &label); printf(_("Installed Size : %6.2f %s\n"), size, label); string_display(_("Packager :"), alpm_pkg_get_packager(pkg)); diff --git a/src/pacman/util.c b/src/pacman/util.c index fbc51eba..2de4bd44 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -775,7 +775,7 @@ static alpm_list_t *create_verbose_row(alpm_pkg_t *pkg, int install) ret = alpm_list_add(ret, str); /* and size */ - size = humanize_size(alpm_pkg_get_size(pkg), 'M', 1, &label); + size = humanize_size(alpm_pkg_get_size(pkg), 'M', &label); pm_asprintf(&str, "%.2f %s", size, label); ret = alpm_list_add(ret, str); @@ -838,19 +838,19 @@ void display_targets(const alpm_list_t *pkgs, int install) printf("\n"); if(install) { - size = humanize_size(dlsize, 'M', 1, &label); + size = humanize_size(dlsize, 'M', &label); printf(_("Total Download Size: %.2f %s\n"), size, label); if(!(config->flags & ALPM_TRANS_FLAG_DOWNLOADONLY)) { - size = humanize_size(isize, 'M', 1, &label); + size = humanize_size(isize, 'M', &label); printf(_("Total Installed Size: %.2f %s\n"), size, label); /* only show this net value if different from raw installed size */ if(rsize > 0) { - size = humanize_size(isize - rsize, 'M', 1, &label); + size = humanize_size(isize - rsize, 'M', &label); printf(_("Net Upgrade Size: %.2f %s\n"), size, label); } } } else { - size = humanize_size(isize, 'M', 1, &label); + size = humanize_size(isize, 'M', &label); printf(_("Total Removed Size: %.2f %s\n"), size, label); } @@ -913,21 +913,17 @@ static char *pkg_get_location(alpm_pkg_t *pkg) * * @return the size in the appropriate unit */ -double humanize_size(off_t bytes, const char target_unit, int long_labels, - const char **label) +double humanize_size(off_t bytes, const char target_unit, const char **label) { - static const char *shortlabels[] = {"B", "K", "M", "G", - "T", "P", "E", "Z", "Y"}; - static const char *longlabels[] = {"B", "KiB", "MiB", "GiB", + static const char *labels[] = {"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"}; - static const int unitcount = sizeof(shortlabels) / sizeof(shortlabels[0]); + static const int unitcount = sizeof(labels) / sizeof(labels[0]); - const char **labels = long_labels ? longlabels : shortlabels; double val = (double)bytes; int index; for(index = 0; index < unitcount - 1; index++) { - if(target_unit != '\0' && shortlabels[index][0] == target_unit) { + if(target_unit != '\0' && labels[index][0] == target_unit) { break; } else if(target_unit == '\0' && val <= 2048.0 && val >= -2048.0) { break; diff --git a/src/pacman/util.h b/src/pacman/util.h index ee3dbd11..f9f1485f 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -53,7 +53,7 @@ char *strtrim(char *str); 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); -double humanize_size(off_t bytes, const char target_unit, int long_labels, const char **label); +double humanize_size(off_t bytes, const char target_unit, const char **label); int table_display(const char *title, const alpm_list_t *header, const alpm_list_t *rows); void list_display(const char *title, const alpm_list_t *list); void list_display_linebreak(const char *title, const alpm_list_t *list); -- cgit v1.2.3-24-g4f1b