commit: 44b67c2d685a763c3f8aee1ecffc8d3f5ababe4c Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> AuthorDate: Sun Jul 14 11:55:07 2019 +0000 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> 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 <grobian <AT> 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<arg>\fR, which is a regular expression, before calculating size. .TP +\fB\-F\fR \fI<arg>\fR, \fB\-\-format\fR \fI<arg>\fR +Print matched atom using given format string. +.TP \fB\-\-root\fR \fI<arg>\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);