From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id C8FEA1393EA for ; Mon, 10 Mar 2014 06:00:10 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id E557AE0AD6; Mon, 10 Mar 2014 06:00:08 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 07452E0AE1 for ; Mon, 10 Mar 2014 06:00:07 +0000 (UTC) Received: from spoonbill.gentoo.org (spoonbill.gentoo.org [81.93.255.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id EE8D433F883 for ; Mon, 10 Mar 2014 06:00:05 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by spoonbill.gentoo.org (Postfix) with ESMTP id 624F1188E9 for ; Mon, 10 Mar 2014 06:00:04 +0000 (UTC) From: "Mike Frysinger" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" Message-ID: <1394399244.a235b67877128a5ab23388cabb0a31bf3502094e.vapier@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: /, libq/ X-VCS-Repository: proj/portage-utils X-VCS-Files: Makefile libq/human_readable.c libq/i18n.h main.c qmerge.c qsize.c X-VCS-Directories: / libq/ X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: a235b67877128a5ab23388cabb0a31bf3502094e X-VCS-Branch: master Date: Mon, 10 Mar 2014 06:00:04 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 7be96efd-e62b-4465-b3df-6e49def3aa58 X-Archives-Hash: 4332a8ad7f9035f878d88d84503f9dae commit: a235b67877128a5ab23388cabb0a31bf3502094e Author: Mike Frysinger gentoo org> AuthorDate: Sun Mar 9 21:07:24 2014 +0000 Commit: Mike Frysinger gentoo org> CommitDate: Sun Mar 9 21:07:24 2014 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage-utils.git;a=commit;h=a235b678 use localized number formats NLS becomes a proper compile time option and we use that to print numbers in a more natural format. If people want raw format for scripts, you can set LC_ALL=C. URL: https://bugs.gentoo.org/503646 --- Makefile | 2 ++ libq/human_readable.c | 6 +++--- libq/i18n.h | 4 +++- main.c | 3 +-- qmerge.c | 2 +- qsize.c | 18 ++++++++++-------- 6 files changed, 20 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 2889fe2..d202f54 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ check_gcc=$(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; \ then echo "$(1)"; else echo "$(2)"; fi) +istrue = $(if $(filter 1 yes true on,$(strip $1)),1,0) #################################################### WFLAGS := -Wall -Wunused -Wimplicit -Wshadow -Wformat=2 \ @@ -18,6 +19,7 @@ WFLAGS := -Wall -Wunused -Wimplicit -Wshadow -Wformat=2 \ CFLAGS ?= -O2 -g -pipe CFLAGS += -std=gnu99 CPPFLAGS ?= +CPPFLAGS += -DENABLE_NLS=$(call istrue,$(NLS)) #CFLAGS += -DEBUG -g #CFLAGS += -Os -DOPTIMIZE_FOR_SIZE=2 -falign-functions=2 -falign-jumps=2 -falign-labels=2 -falign-loops=2 #LDFLAGS := -pie diff --git a/libq/human_readable.c b/libq/human_readable.c index bdef428..3a8aa34 100644 --- a/libq/human_readable.c +++ b/libq/human_readable.c @@ -38,8 +38,8 @@ const char *make_human_readable_str(unsigned long long size, { /* The code will adjust for additional (appended) units. */ static const char zero_and_units[] = { '0', 0, 'k', 'M', 'G', 'T' }; - static const char fmt[] = "%Lu"; - static const char fmt_tenths[] = "%Lu.%d%c"; + static const char fmt[] = "%'Lu"; + static const char fmt_tenths[] = "%'Lu%s%d%c"; static char str[21]; /* Sufficient for 64 bit unsigned integers. */ @@ -85,7 +85,7 @@ const char *make_human_readable_str(unsigned long long size, } /* If f==fmt then 'frac' and 'u' are ignored. */ - snprintf(str, sizeof(str), f, val, frac, *u); + snprintf(str, sizeof(str), f, val, decimal_point, frac, *u); return str; } diff --git a/libq/i18n.h b/libq/i18n.h index d26713c..50f36ea 100644 --- a/libq/i18n.h +++ b/libq/i18n.h @@ -1,15 +1,17 @@ #ifndef _I18N_H #define _I18N_H -#ifdef ENABLE_NLS +#if ENABLE_NLS # include # include # define _(String) gettext (String) +# define decimal_point localeconv()->decimal_point #else # define _(String) (String) # define setlocale(x,y) # define bindtextdomain(x,y) # define textdomain(x) +# define decimal_point "." #endif #endif diff --git a/main.c b/main.c index 2fd242f..bb510a8 100644 --- a/main.c +++ b/main.c @@ -1293,11 +1293,10 @@ int main(int argc, char **argv) IF_DEBUG(init_coredumps()); argv0 = argv[0]; -#ifdef ENABLE_NLS /* never tested */ setlocale(LC_ALL, ""); bindtextdomain(argv0, CONFIG_EPREFIX "usr/share/locale"); textdomain(argv0); -#endif + #if 1 if (fstat(fileno(stdout), &st) != -1) if (!isatty(fileno(stdout))) diff --git a/qmerge.c b/qmerge.c index 3aab0ce..572365e 100644 --- a/qmerge.c +++ b/qmerge.c @@ -1425,7 +1425,7 @@ print_Pkg(int full, struct pkg_t *pkg) printf("%s%s/%s%s%s%s%s%s\n", BOLD, pkg->CATEGORY, BLUE, pkg->PF, NORM, !quiet ? " [" : "", !quiet ? make_human_readable_str(pkg->SIZE, 1, KILOBYTE) : "", - !quiet ? "KB]" : ""); + !quiet ? "KiB]" : ""); if (full == 0) return; diff --git a/qsize.c b/qsize.c index 3cecccb..83ad8b1 100644 --- a/qsize.c +++ b/qsize.c @@ -62,8 +62,8 @@ int qsize_main(int argc, char **argv) case 'a': search_all = 1; break; case 's': summary = 1; break; case 'S': summary = summary_only = 1; break; - case 'm': disp_units = MEGABYTE; str_disp_units = "MB"; break; - case 'k': disp_units = KILOBYTE; str_disp_units = "KB"; break; + case 'm': disp_units = MEGABYTE; str_disp_units = "MiB"; break; + case 'k': disp_units = KILOBYTE; str_disp_units = "KiB"; break; case 'b': disp_units = 1; str_disp_units = "bytes"; break; case 'i': ignore_regexp = add_set(optarg, optarg, ignore_regexp); break; } @@ -139,19 +139,20 @@ int qsize_main(int argc, char **argv) num_all_ignored += num_ignored; if (!summary_only) { - printf("%s%s/%s%s%s: %lu files, %lu non-files, ", BOLD, + printf("%s%s/%s%s%s: %'lu files, %'lu non-files, ", BOLD, catname, BLUE, pkgname, NORM, (unsigned long)num_files, (unsigned long)num_nonfiles); if (num_ignored) - printf("%lu names-ignored, ", (unsigned long)num_ignored); + printf("%'lu names-ignored, ", (unsigned long)num_ignored); if (disp_units) printf("%s %s\n", make_human_readable_str(num_bytes, 1, disp_units), str_disp_units); else - printf("%lu.%lu KB\n", + printf("%'lu%s%lu KiB\n", (unsigned long)(num_bytes / KILOBYTE), + decimal_point, (unsigned long)(((num_bytes%KILOBYTE)*1000)/KILOBYTE)); } @@ -161,18 +162,19 @@ int qsize_main(int argc, char **argv) } if (summary) { - printf(" %sTotals%s: %lu files, %lu non-files, ", BOLD, NORM, + printf(" %sTotals%s: %'lu files, %'lu non-files, ", BOLD, NORM, (unsigned long)num_all_files, (unsigned long)num_all_nonfiles); if (num_all_ignored) - printf("%lu names-ignored, ", (unsigned long)num_all_ignored); + printf("%'lu names-ignored, ", (unsigned long)num_all_ignored); if (disp_units) printf("%s %s\n", make_human_readable_str(num_all_bytes, 1, disp_units), str_disp_units); else - printf("%lu.%lu MB\n", + printf("%'lu%s%lu MiB\n", (unsigned long)(num_all_bytes / MEGABYTE), + decimal_point, (unsigned long)(((num_all_bytes%MEGABYTE)*1000)/MEGABYTE)); } free_sets(ignore_regexp);