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 72DCE138334 for ; Sun, 14 Jul 2019 13:09:48 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id E6805E08AA; Sun, 14 Jul 2019 13:09:46 +0000 (UTC) Received: from smtp.gentoo.org (dev.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 B25ACE08A2 for ; Sun, 14 Jul 2019 13:09:46 +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 A388A347A91 for ; Sun, 14 Jul 2019 13:09:45 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 4A5E56F1 for ; Sun, 14 Jul 2019 13:09:44 +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: <1563105307.44b67c2d685a763c3f8aee1ecffc8d3f5ababe4c.grobian@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: /, man/ X-VCS-Repository: proj/portage-utils X-VCS-Files: man/qsize.1 qsize.c X-VCS-Directories: / man/ X-VCS-Committer: grobian X-VCS-Committer-Name: Fabian Groffen X-VCS-Revision: 44b67c2d685a763c3f8aee1ecffc8d3f5ababe4c X-VCS-Branch: master Date: Sun, 14 Jul 2019 13:09:44 +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-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: eaf5b331-9b5d-4980-b69a-ca7de2cd0fb9 X-Archives-Hash: 7b7fee7dc90f09060020d2c0671e54c3 commit: 44b67c2d685a763c3f8aee1ecffc8d3f5ababe4c Author: Fabian Groffen gentoo org> AuthorDate: Sun Jul 14 11:55:07 2019 +0000 Commit: Fabian Groffen gentoo org> CommitDate: Sun Jul 14 11:55:07 2019 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=44b67c2d qsize: add -F argument, changed default format to match other applets Signed-off-by: Fabian Groffen gentoo.org> man/qsize.1 | 3 +++ qsize.c | 36 +++++++++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/man/qsize.1 b/man/qsize.1 index 3a359e4..df85970 100644 --- a/man/qsize.1 +++ b/man/qsize.1 @@ -33,6 +33,9 @@ Display all sizes in bytes. Filter out entries matching \fI\fR, which is a regular expression, before calculating size. .TP +\fB\-F\fR \fI\fR, \fB\-\-format\fR \fI\fR +Print matched atom using given format string. +.TP \fB\-\-root\fR \fI\fR Set the ROOT env var. .TP diff --git a/qsize.c b/qsize.c index 10aadc8..1f1dfc9 100644 --- a/qsize.c +++ b/qsize.c @@ -55,7 +55,7 @@ #include "xarray.h" #include "xregex.h" -#define QSIZE_FLAGS "fsSmkbi:" COMMON_FLAGS +#define QSIZE_FLAGS "fsSmkbi:F:" COMMON_FLAGS static struct option const qsize_long_opts[] = { {"filesystem", no_argument, NULL, 'f'}, {"sum", no_argument, NULL, 's'}, @@ -64,6 +64,7 @@ static struct option const qsize_long_opts[] = { {"kilobytes", no_argument, NULL, 'k'}, {"bytes", no_argument, NULL, 'b'}, {"ignore", a_argument, NULL, 'i'}, + {"format", a_argument, NULL, 'F'}, COMMON_LONG_OPTS }; static const char * const qsize_opts_help[] = { @@ -74,6 +75,7 @@ static const char * const qsize_opts_help[] = { "Display all sizes in kilobytes", "Display all sizes in bytes", "Ignore regexp string", + "Print matched atom using given format string", COMMON_OPTS_HELP }; #define qsize_usage(ret) usage(ret, QSIZE_FLAGS, qsize_long_opts, qsize_opts_help, NULL, lookup_applet_idx("qsize")) @@ -88,6 +90,8 @@ struct qsize_opt_state { size_t disp_units; const char *str_disp_units; array_t *ignore_regexp; + const char *fmt; + bool need_full_atom:1; size_t buflen; char *buf; @@ -160,9 +164,9 @@ qsize_cb(tree_pkg_ctx *pkg_ctx, void *priv) state->num_all_ignored += num_ignored; if (!state->summary_only) { - atom = tree_get_atom(pkg_ctx, 0); + atom = tree_get_atom(pkg_ctx, state->need_full_atom); printf("%s: %'zu files, %'zu non-files, ", - atom_format("%[CATEGORY]%[PF]", atom), + atom_format(state->fmt, atom), num_files, num_nonfiles); if (num_ignored) printf("%'zu names-ignored, ", num_ignored); @@ -195,17 +199,24 @@ int qsize_main(int argc, char **argv) .num_all_files = 0, .num_all_nonfiles = 0, .num_all_ignored = 0, + .need_full_atom = false, + .fmt = NULL, }; while ((ret = GETOPT_LONG(QSIZE, qsize, "")) != -1) { switch (ret) { COMMON_GETOPTS_CASES(qsize) - case 'f': state.fs_size = 1; break; - case 's': state.summary = 1; break; - case 'S': state.summary = state.summary_only = 1; break; - case 'm': state.disp_units = MEGABYTE; state.str_disp_units = "MiB"; break; - case 'k': state.disp_units = KILOBYTE; state.str_disp_units = "KiB"; break; - case 'b': state.disp_units = 1; state.str_disp_units = "bytes"; break; + case 'f': state.fs_size = 1; break; + case 's': state.summary = 1; break; + case 'S': state.summary = state.summary_only = 1; break; + case 'm': state.disp_units = MEGABYTE; + state.str_disp_units = "MiB"; break; + case 'k': state.disp_units = KILOBYTE; + state.str_disp_units = "KiB"; break; + case 'b': state.disp_units = 1; + state.str_disp_units = "bytes"; break; + case 'F': state.fmt = optarg; + state.need_full_atom = true; break; case 'i': { regex_t regex; xregcomp(®ex, optarg, REG_EXTENDED|REG_NOSUB); @@ -225,6 +236,13 @@ int qsize_main(int argc, char **argv) xarraypush_ptr(state.atoms, atom); } + if (state.fmt == NULL) { + if (verbose) + state.fmt = "%[CATEGORY]%[PF]"; + else + state.fmt = "%[CATEGORY]%[PN]"; + } + state.buflen = _Q_PATH_MAX; state.buf = xmalloc(state.buflen);