From: "Mike Frysinger" <vapier@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage-utils:master commit in: /, libq/
Date: Mon, 10 Mar 2014 06:00:04 +0000 (UTC) [thread overview]
Message-ID: <1394399244.a235b67877128a5ab23388cabb0a31bf3502094e.vapier@gentoo> (raw)
commit: a235b67877128a5ab23388cabb0a31bf3502094e
Author: Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Sun Mar 9 21:07:24 2014 +0000
Commit: Mike Frysinger <vapier <AT> gentoo <DOT> 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 <locale.h>
# include <libintl.h>
# 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);
next reply other threads:[~2014-03-10 6:00 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-10 6:00 Mike Frysinger [this message]
-- strict thread matches above, loose matches on Subject: below --
2024-01-02 7:57 [gentoo-commits] proj/portage-utils:master commit in: /, libq/ Fabian Groffen
2020-05-16 18:27 Fabian Groffen
2020-01-05 16:08 Fabian Groffen
2020-01-04 19:48 Fabian Groffen
2020-01-01 17:54 Fabian Groffen
2019-11-15 13:52 Fabian Groffen
2019-07-14 13:09 Fabian Groffen
2019-05-07 6:19 Fabian Groffen
2019-05-06 17:33 Fabian Groffen
2019-05-02 15:48 Fabian Groffen
2018-05-18 16:58 Fabian Groffen
2016-12-29 2:25 Mike Frysinger
2016-12-29 2:25 Mike Frysinger
2016-02-14 1:26 Mike Frysinger
2016-02-14 1:26 Mike Frysinger
2015-11-28 2:44 Mike Frysinger
2015-11-28 2:44 Mike Frysinger
2015-02-24 1:26 Mike Frysinger
2014-03-21 5:32 Mike Frysinger
2014-03-10 8:45 Mike Frysinger
2014-03-08 5:51 Mike Frysinger
2014-03-08 5:51 Mike Frysinger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1394399244.a235b67877128a5ab23388cabb0a31bf3502094e.vapier@gentoo \
--to=vapier@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox