From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 0E9C91382C5 for ; Tue, 3 Apr 2018 13:39:42 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 4962BE0BFE; Tue, 3 Apr 2018 13:39:41 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 272DAE0BFE for ; Tue, 3 Apr 2018 13:39:41 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 16CEF335CEE for ; Tue, 3 Apr 2018 13:39:40 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id AD3D1275 for ; Tue, 3 Apr 2018 13:39:38 +0000 (UTC) From: "Fabian Groffen" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Fabian Groffen" Message-ID: <1522761930.d01affcd8541a539a7e5b329efef1cc49f31569f.grobian@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: / X-VCS-Repository: proj/portage-utils X-VCS-Files: qsize.c X-VCS-Directories: / X-VCS-Committer: grobian X-VCS-Committer-Name: Fabian Groffen X-VCS-Revision: d01affcd8541a539a7e5b329efef1cc49f31569f X-VCS-Branch: master Date: Tue, 3 Apr 2018 13:39:38 +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: dae247f2-5189-46d1-b8ef-287c0fd67011 X-Archives-Hash: 0e42088896d80adb14a1dd8410139541 commit: d01affcd8541a539a7e5b329efef1cc49f31569f Author: Fabian Groffen gentoo org> AuthorDate: Tue Apr 3 13:25:30 2018 +0000 Commit: Fabian Groffen gentoo org> CommitDate: Tue Apr 3 13:25:30 2018 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=d01affcd qsize: use make_human_readable_str to format sizes by default This way, sizes are by default converted to the unit that matches the quantity of the value. This behaviour can be overridden by the -b, -k and -m options for constant values. Simplifies code, and makes it easier to grasp for humans. qsize.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/qsize.c b/qsize.c index 9cd66cf..c485aa6 100644 --- a/qsize.c +++ b/qsize.c @@ -1,5 +1,5 @@ /* - * Copyright 2005-2014 Gentoo Foundation + * Copyright 2005-2018 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2005-2010 Ned Ludd - @@ -120,15 +120,9 @@ qsize_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv) num_files, num_nonfiles); if (num_ignored) printf("%'zu names-ignored, ", num_ignored); - if (state->disp_units) - printf("%s %s\n", - make_human_readable_str(num_bytes, 1, state->disp_units), - state->str_disp_units); - else - printf("%'"PRIu64"%s%"PRIu64" KiB\n", - num_bytes / KILOBYTE, - decimal_point, - ((num_bytes % KILOBYTE) * 1000) / KILOBYTE); + printf("%s %s\n", + make_human_readable_str(num_bytes, 1, state->disp_units), + state->disp_units ? state->str_disp_units : ""); } return EXIT_SUCCESS; @@ -194,15 +188,10 @@ int qsize_main(int argc, char **argv) state.num_all_files, state.num_all_nonfiles); if (state.num_all_ignored) printf("%'zu names-ignored, ", state.num_all_ignored); - if (state.disp_units) - printf("%s %s\n", - make_human_readable_str(state.num_all_bytes, 1, state.disp_units), - state.str_disp_units); - else - printf("%'"PRIu64"%s%"PRIu64" MiB\n", - state.num_all_bytes / MEGABYTE, - decimal_point, - ((state.num_all_bytes % MEGABYTE) * 1000) / MEGABYTE); + printf("%s %s\n", + make_human_readable_str( + state.num_all_bytes, 1, state.disp_units), + state.disp_units ? state.str_disp_units : ""); } array_for_each(state.atoms, i, atom)